From kevlo at FreeBSD.org Mon Dec 1 02:04:39 2008 From: kevlo at FreeBSD.org (Kevin Lo) Date: Mon Dec 1 02:04:51 2008 Subject: svn commit: r185511 - head/sys/dev/usb Message-ID: <200812011004.mB1A4dus019336@svn.freebsd.org> Author: kevlo Date: Mon Dec 1 10:04:39 2008 New Revision: 185511 URL: http://svn.freebsd.org/changeset/base/185511 Log: The Netgear WG111v2 USB dongle contains a RTL8187 chip, not a GW3887 chip. Obtained from: OpenBSD Modified: head/sys/dev/usb/if_upgt.c Modified: head/sys/dev/usb/if_upgt.c ============================================================================== --- head/sys/dev/usb/if_upgt.c Mon Dec 1 07:13:52 2008 (r185510) +++ head/sys/dev/usb/if_upgt.c Mon Dec 1 10:04:39 2008 (r185511) @@ -194,7 +194,6 @@ static const struct usb_devno upgt_devs_ { USB_VENDOR_GLOBESPAN, USB_PRODUCT_GLOBESPAN_PRISM_GT_1 }, { USB_VENDOR_GLOBESPAN, USB_PRODUCT_GLOBESPAN_PRISM_GT_2 }, { USB_VENDOR_INTERSIL, USB_PRODUCT_INTERSIL_PRISM_GT }, - { USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_WG111V2_2 }, { USB_VENDOR_SMC, USB_PRODUCT_SMC_2862WG }, { USB_VENDOR_WISTRONNEWEB, USB_PRODUCT_WISTRONNEWEB_UR045G }, { USB_VENDOR_XYRATEX, USB_PRODUCT_XYRATEX_PRISM_GT_1 }, From kevlo at FreeBSD.org Mon Dec 1 02:05:34 2008 From: kevlo at FreeBSD.org (Kevin Lo) Date: Mon Dec 1 02:05:41 2008 Subject: svn commit: r185512 - head/share/man/man4 Message-ID: <200812011005.mB1A5YNl019393@svn.freebsd.org> Author: kevlo Date: Mon Dec 1 10:05:34 2008 New Revision: 185512 URL: http://svn.freebsd.org/changeset/base/185512 Log: Remove The Netgear WG111v2 support Modified: head/share/man/man4/upgt.4 Modified: head/share/man/man4/upgt.4 ============================================================================== --- head/share/man/man4/upgt.4 Mon Dec 1 10:04:39 2008 (r185511) +++ head/share/man/man4/upgt.4 Mon Dec 1 10:05:34 2008 (r185512) @@ -168,8 +168,6 @@ Gigaset USB Adapter 54 .It Inventel UR045G .It -Netgear WG111v2 -.It SMC EZ ConnectG SMC2862W-G .It Sagem XG703A From stas at FreeBSD.org Mon Dec 1 02:16:25 2008 From: stas at FreeBSD.org (Stanislav Sedov) Date: Mon Dec 1 02:16:32 2008 Subject: svn commit: r185513 - in head/sys/arm: at91 mv sa11x0 xscale/i80321 xscale/i8134x xscale/ixp425 xscale/pxa Message-ID: <200812011016.mB1AGPAZ019666@svn.freebsd.org> Author: stas Date: Mon Dec 1 10:16:25 2008 New Revision: 185513 URL: http://svn.freebsd.org/changeset/base/185513 Log: - Fix spelling error in comments. PR: arm/128891 Submitted by: Pavel Pankov Approved by: kib (mentor) Modified: head/sys/arm/at91/at91_machdep.c head/sys/arm/mv/mv_machdep.c head/sys/arm/sa11x0/assabet_machdep.c head/sys/arm/xscale/i80321/ep80219_machdep.c head/sys/arm/xscale/i80321/iq31244_machdep.c head/sys/arm/xscale/i8134x/crb_machdep.c head/sys/arm/xscale/ixp425/avila_machdep.c head/sys/arm/xscale/pxa/pxa_machdep.c Modified: head/sys/arm/at91/at91_machdep.c ============================================================================== --- head/sys/arm/at91/at91_machdep.c Mon Dec 1 10:05:34 2008 (r185512) +++ head/sys/arm/at91/at91_machdep.c Mon Dec 1 10:16:25 2008 (r185513) @@ -341,7 +341,7 @@ initarm(void *arg, void *arg2) * but since we are boot strapping the addresses used for the read * may have just been remapped and thus the cache could be out * of sync. A re-clean after the switch will cure this. - * After booting there are no gross reloations of the kernel thus + * After booting there are no gross relocations of the kernel thus * this problem will not occur after initarm(). */ cpu_idcache_wbinv_all(); Modified: head/sys/arm/mv/mv_machdep.c ============================================================================== --- head/sys/arm/mv/mv_machdep.c Mon Dec 1 10:05:34 2008 (r185512) +++ head/sys/arm/mv/mv_machdep.c Mon Dec 1 10:16:25 2008 (r185513) @@ -579,7 +579,7 @@ initarm(void *mdp, void *unused __unused * but since we are boot strapping the addresses used for the read * may have just been remapped and thus the cache could be out * of sync. A re-clean after the switch will cure this. - * After booting there are no gross reloations of the kernel thus + * After booting there are no gross relocations of the kernel thus * this problem will not occur after initarm(). */ cpu_idcache_wbinv_all(); Modified: head/sys/arm/sa11x0/assabet_machdep.c ============================================================================== --- head/sys/arm/sa11x0/assabet_machdep.c Mon Dec 1 10:05:34 2008 (r185512) +++ head/sys/arm/sa11x0/assabet_machdep.c Mon Dec 1 10:16:25 2008 (r185513) @@ -375,7 +375,7 @@ initarm(void *arg, void *arg2) * but since we are boot strapping the addresses used for the read * may have just been remapped and thus the cache could be out * of sync. A re-clean after the switch will cure this. - * After booting there are no gross reloations of the kernel thus + * After booting there are no gross relocations of the kernel thus * this problem will not occur after initarm(). */ cpu_idcache_wbinv_all(); Modified: head/sys/arm/xscale/i80321/ep80219_machdep.c ============================================================================== --- head/sys/arm/xscale/i80321/ep80219_machdep.c Mon Dec 1 10:05:34 2008 (r185512) +++ head/sys/arm/xscale/i80321/ep80219_machdep.c Mon Dec 1 10:16:25 2008 (r185513) @@ -352,7 +352,7 @@ initarm(void *arg, void *arg2) * but since we are boot strapping the addresses used for the read * may have just been remapped and thus the cache could be out * of sync. A re-clean after the switch will cure this. - * After booting there are no gross reloations of the kernel thus + * After booting there are no gross relocations of the kernel thus * this problem will not occur after initarm(). */ cpu_idcache_wbinv_all(); Modified: head/sys/arm/xscale/i80321/iq31244_machdep.c ============================================================================== --- head/sys/arm/xscale/i80321/iq31244_machdep.c Mon Dec 1 10:05:34 2008 (r185512) +++ head/sys/arm/xscale/i80321/iq31244_machdep.c Mon Dec 1 10:16:25 2008 (r185513) @@ -350,7 +350,7 @@ initarm(void *arg, void *arg2) * but since we are boot strapping the addresses used for the read * may have just been remapped and thus the cache could be out * of sync. A re-clean after the switch will cure this. - * After booting there are no gross reloations of the kernel thus + * After booting there are no gross relocations of the kernel thus * this problem will not occur after initarm(). */ cpu_idcache_wbinv_all(); Modified: head/sys/arm/xscale/i8134x/crb_machdep.c ============================================================================== --- head/sys/arm/xscale/i8134x/crb_machdep.c Mon Dec 1 10:05:34 2008 (r185512) +++ head/sys/arm/xscale/i8134x/crb_machdep.c Mon Dec 1 10:16:25 2008 (r185513) @@ -332,7 +332,7 @@ initarm(void *arg, void *arg2) * but since we are boot strapping the addresses used for the read * may have just been remapped and thus the cache could be out * of sync. A re-clean after the switch will cure this. - * After booting there are no gross reloations of the kernel thus + * After booting there are no gross relocations of the kernel thus * this problem will not occur after initarm(). */ cpu_idcache_wbinv_all(); Modified: head/sys/arm/xscale/ixp425/avila_machdep.c ============================================================================== --- head/sys/arm/xscale/ixp425/avila_machdep.c Mon Dec 1 10:05:34 2008 (r185512) +++ head/sys/arm/xscale/ixp425/avila_machdep.c Mon Dec 1 10:16:25 2008 (r185513) @@ -418,7 +418,7 @@ initarm(void *arg, void *arg2) * but since we are boot strapping the addresses used for the read * may have just been remapped and thus the cache could be out * of sync. A re-clean after the switch will cure this. - * After booting there are no gross reloations of the kernel thus + * After booting there are no gross relocations of the kernel thus * this problem will not occur after initarm(). */ cpu_idcache_wbinv_all(); Modified: head/sys/arm/xscale/pxa/pxa_machdep.c ============================================================================== --- head/sys/arm/xscale/pxa/pxa_machdep.c Mon Dec 1 10:05:34 2008 (r185512) +++ head/sys/arm/xscale/pxa/pxa_machdep.c Mon Dec 1 10:16:25 2008 (r185513) @@ -330,7 +330,7 @@ initarm(void *arg, void *arg2) * but since we are boot strapping the addresses used for the read * may have just been remapped and thus the cache could be out * of sync. A re-clean after the switch will cure this. - * After booting there are no gross reloations of the kernel thus + * After booting there are no gross relocations of the kernel thus * this problem will not occur after initarm(). */ cpu_idcache_wbinv_all(); From jasone at FreeBSD.org Mon Dec 1 02:20:59 2008 From: jasone at FreeBSD.org (Jason Evans) Date: Mon Dec 1 02:21:10 2008 Subject: svn commit: r185514 - head/lib/libc/stdlib Message-ID: <200812011020.mB1AKxwK019797@svn.freebsd.org> Author: jasone Date: Mon Dec 1 10:20:59 2008 New Revision: 185514 URL: http://svn.freebsd.org/changeset/base/185514 Log: Fix a lock order reversal bug that could cause deadlock during fork(2). Reported by: kib Modified: head/lib/libc/stdlib/malloc.c Modified: head/lib/libc/stdlib/malloc.c ============================================================================== --- head/lib/libc/stdlib/malloc.c Mon Dec 1 10:16:25 2008 (r185513) +++ head/lib/libc/stdlib/malloc.c Mon Dec 1 10:20:59 2008 (r185514) @@ -5515,16 +5515,41 @@ _malloc_thread_cleanup(void) void _malloc_prefork(void) { - unsigned i; + bool again; + unsigned i, j; + arena_t *larenas[narenas], *tarenas[narenas]; /* Acquire all mutexes in a safe order. */ - malloc_spin_lock(&arenas_lock); - for (i = 0; i < narenas; i++) { - if (arenas[i] != NULL) - malloc_spin_lock(&arenas[i]->lock); - } - malloc_spin_unlock(&arenas_lock); + /* + * arenas_lock must be acquired after all of the arena mutexes, in + * order to avoid potential deadlock with arena_lock_balance[_hard](). + * Since arenas_lock protects the arenas array, the following code has + * to race with arenas_extend() callers until it succeeds in locking + * all arenas before locking arenas_lock. + */ + memset(larenas, 0, sizeof(arena_t *) * narenas); + do { + again = false; + + malloc_spin_lock(&arenas_lock); + for (i = 0; i < narenas; i++) { + if (arenas[i] != larenas[i]) { + memcpy(tarenas, arenas, sizeof(arena_t *) * + narenas); + malloc_spin_unlock(&arenas_lock); + for (j = 0; j < narenas; j++) { + if (larenas[j] != tarenas[j]) { + larenas[j] = tarenas[j]; + malloc_spin_lock( + &larenas[j]->lock); + } + } + again = true; + break; + } + } + } while (again); malloc_mutex_lock(&base_mtx); @@ -5539,6 +5564,7 @@ void _malloc_postfork(void) { unsigned i; + arena_t *larenas[narenas]; /* Release all mutexes, now that fork() has completed. */ @@ -5550,12 +5576,12 @@ _malloc_postfork(void) malloc_mutex_unlock(&base_mtx); - malloc_spin_lock(&arenas_lock); + memcpy(larenas, arenas, sizeof(arena_t *) * narenas); + malloc_spin_unlock(&arenas_lock); for (i = 0; i < narenas; i++) { - if (arenas[i] != NULL) - malloc_spin_unlock(&arenas[i]->lock); + if (larenas[i] != NULL) + malloc_spin_unlock(&larenas[i]->lock); } - malloc_spin_unlock(&arenas_lock); } /* From des at des.no Mon Dec 1 03:21:09 2008 From: des at des.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Mon Dec 1 03:21:21 2008 Subject: svn commit: r184509 - head/share/man/man9 In-Reply-To: <20081201104920.4b001553.stas@FreeBSD.org> (Stanislav Sedov's message of "Mon, 1 Dec 2008 10:49:20 +0300") References: <200810311447.m9VElFtp083250@svn.freebsd.org> <20081101212937.D12448@delplex.bde.org> <20081201104920.4b001553.stas@FreeBSD.org> Message-ID: <864p1orvj0.fsf@ds4.des.no> Stanislav Sedov writes: > What is the benefit of using a single error exit code which theoretically > can't say anything about the type of the error instead of probably cryptic > set of documented error coded that could be later decrypted and analyzed > at least? For me the code using named error codes looks much cleaner, and > as all exit codes >0 threated as error, it seems that using sysexits codes > should not hurt. Do we totally againast them from now, or these exit codes > still could be used? sysexits is actually nothing more than the documented exit codes for sendmail(8). Practically nothing else uses them, except procmail scripts, postfix filters and similar where you need to know if sendmail (or another MTA's drop-in replacement) succeeded - and even those usually only check for 75 (EX_TEMPFAIL). I think we have one or two utilities with documented exit codes other than 0 and 1. Everything else just returns "0 on success, and >0 if an error occurs"; we even have an mdoc macro (.Ex -std) for that exact phrase. DES -- Dag-Erling Sm?rgrav - des@des.no From des at des.no Mon Dec 1 03:25:07 2008 From: des at des.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Mon Dec 1 03:25:18 2008 Subject: svn commit: r185499 - head In-Reply-To: <49338E98.7020104@freebsd.org> (Tim Kientzle's message of "Sun, 30 Nov 2008 23:13:28 -0800") References: <200812010045.mB10jpmX007146@svn.freebsd.org> <49338E98.7020104@freebsd.org> Message-ID: <863ah8rvcd.fsf@ds4.des.no> Tim Kientzle writes: > Alfred Perlstein writes: > > Log: > > Provide a 'tinderbox' target that compiles enough of FreeBSD that > > a developer can rest reasonably assured that the tinderbox will not > > be broken. This target leverages most of 'universe' but will exit > > non-zero and output a summary at the end. > > "make tinderbox" > Excellent! I really don't see the point, especially now that 'make universe' will issue a warning on stdout for every build that fails. As I've tried to explain to Alfred, the tinderbox does nothing magical, and nothing that isn't already covered by 'make universe'. I also asked him to discuss any changes with Poul-Henning before committing them. > I seem to recall that the "real" tinderbox uses some slightly > different build options from "make universe." No, it doesn't. You can check for yourself - the complete command line and environment are included in the log file. From the latest amd64 build: TB --- 2008-12-01 07:01:04 - building world TB --- 2008-12-01 07:01:04 - MAKEOBJDIRPREFIX=/obj TB --- 2008-12-01 07:01:04 - PATH=/usr/bin:/usr/sbin:/bin:/sbin TB --- 2008-12-01 07:01:04 - TARGET=amd64 TB --- 2008-12-01 07:01:04 - TARGET_ARCH=amd64 TB --- 2008-12-01 07:01:04 - TZ=UTC TB --- 2008-12-01 07:01:04 - __MAKE_CONF=/dev/null TB --- 2008-12-01 07:01:04 - cd /src TB --- 2008-12-01 07:01:04 - /usr/bin/make -B buildworld DES -- Dag-Erling Sm?rgrav - des@des.no From alfred at freebsd.org Mon Dec 1 05:25:55 2008 From: alfred at freebsd.org (Alfred Perlstein) Date: Mon Dec 1 05:26:01 2008 Subject: svn commit: r185499 - head In-Reply-To: <863ah8rvcd.fsf@ds4.des.no> References: <200812010045.mB10jpmX007146@svn.freebsd.org> <49338E98.7020104@freebsd.org> <863ah8rvcd.fsf@ds4.des.no> Message-ID: <20081201132554.GD27096@elvis.mu.org> * Dag-Erling Sm??rgrav [081201 03:25] wrote: > Tim Kientzle writes: > > Alfred Perlstein writes: > > > Log: > > > Provide a 'tinderbox' target that compiles enough of FreeBSD that > > > a developer can rest reasonably assured that the tinderbox will not > > > be broken. This target leverages most of 'universe' but will exit > > > non-zero and output a summary at the end. > > > "make tinderbox" > > Excellent! > > I really don't see the point, especially now that 'make universe' will > issue a warning on stdout for every build that fails. As I've tried to > explain to Alfred, the tinderbox does nothing magical, and nothing that > isn't already covered by 'make universe'. I also asked him to discuss > any changes with Poul-Henning before committing them. I'll summarize the changes here: Problems with make universe: 1) Make universe returns success on failure. 2) Make universe outputs the following on failure: -------------------------------------------------------------- make universe completed on `LC_ALL=C date`" (started ${STARTTIME})" -------------------------------------------------------------- This basically means you can't chain 'make universe' into something like "make tinderbox || (echo oops | mail -s tinderbox failed...)". The summary at the end "completed" is very misleading. The tinderbox target differs as follows: It returns an error if it fails. It outputs a summary of the failures at the end. The name reflects what its for. ("what the heck is a universe?") If you strongly believe that a target should return "true" on failure and/or output "i worked" on failure then I'm not sure how to approach that mindset, maybe you can help me understand where you're coming from on that? Where is the utility in it? Is there something I'm missing? thanks, -Alfred From alfred at freebsd.org Mon Dec 1 05:33:15 2008 From: alfred at freebsd.org (Alfred Perlstein) Date: Mon Dec 1 05:33:27 2008 Subject: svn commit: r185499 - head In-Reply-To: <49338E98.7020104@freebsd.org> References: <200812010045.mB10jpmX007146@svn.freebsd.org> <49338E98.7020104@freebsd.org> Message-ID: <20081201133315.GE27096@elvis.mu.org> * Tim Kientzle [081130 23:13] wrote: > Alfred Perlstein wrote: > >Author: alfred > >Date: Mon Dec 1 00:45:51 2008 > >New Revision: 185499 > >URL: http://svn.freebsd.org/changeset/base/185499 > > > >Log: > > Provide a 'tinderbox' target that compiles enough of FreeBSD that > > a developer can rest reasonably assured that the tinderbox will not > > be broken. This target leverages most of 'universe' but will exit > > non-zero and output a summary at the end. > > > > "make tinderbox" > > Excellent! > > I seem to recall that the "real" tinderbox uses > some slightly different build options from > "make universe." > > It would be nice to reconcile that. I'm hoping that DES will be forthcoming if such discrepancies exist so that we can reconcile them. Right now, from what I understand, he says that this is close enough to a tinderbox run to be useful. The only thing I didn't like was that it picks up all kernels sitting in my source tree. I should probably fix the 'tinderbox' target not to pick up my own kernels. Let me know what you think about that. -- - Alfred Perlstein From des at des.no Mon Dec 1 05:35:05 2008 From: des at des.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Mon Dec 1 05:35:17 2008 Subject: svn commit: r185499 - head In-Reply-To: <20081201132554.GD27096@elvis.mu.org> (Alfred Perlstein's message of "Mon, 1 Dec 2008 05:25:54 -0800") References: <200812010045.mB10jpmX007146@svn.freebsd.org> <49338E98.7020104@freebsd.org> <863ah8rvcd.fsf@ds4.des.no> <20081201132554.GD27096@elvis.mu.org> Message-ID: <863ah8qarb.fsf@ds4.des.no> Alfred Perlstein writes: > If you strongly believe that a target should return "true" on failure > and/or output "i worked" on failure I don't, and I don't understand why you think I do. I have stated very clearly that I don't like the universe target. > then I'm not sure how to approach > that mindset, maybe you can help me understand where you're coming from > on that? Where is the utility in it? Is there something I'm missing? You'll have to ask Poul-Henning, who wrote the universe target in the first place. DES -- Dag-Erling Sm?rgrav - des@des.no From phk at phk.freebsd.dk Mon Dec 1 05:40:34 2008 From: phk at phk.freebsd.dk (Poul-Henning Kamp) Date: Mon Dec 1 05:40:41 2008 Subject: svn commit: r185499 - head In-Reply-To: Your message of "Mon, 01 Dec 2008 14:35:04 +0100." <863ah8qarb.fsf@ds4.des.no> Message-ID: <83764.1228138832@critter.freebsd.dk> In message <863ah8qarb.fsf@ds4.des.no>, =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= wr ites: >Alfred Perlstein writes: >> If you strongly believe that a target should return "true" on failure >> and/or output "i worked" on failure > >I don't, and I don't understand why you think I do. I have stated very >clearly that I don't like the universe target. I don't mind the universe target failing with the aggregate status code at the end, I have said that repeatedly. But I don't want it to stop working until it has tried compiling as much as possible. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. From phk at phk.freebsd.dk Mon Dec 1 05:58:07 2008 From: phk at phk.freebsd.dk (Poul-Henning Kamp) Date: Mon Dec 1 05:58:17 2008 Subject: svn commit: r185499 - head In-Reply-To: Your message of "Mon, 01 Dec 2008 05:25:54 PST." <20081201132554.GD27096@elvis.mu.org> Message-ID: <83595.1228138025@critter.freebsd.dk> In message <20081201132554.GD27096@elvis.mu.org>, Alfred Perlstein writes: > The name reflects what its for. ("what the heck is a universe?") Something that contains all worlds. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. From bz at zabbadoz.net Mon Dec 1 06:13:07 2008 From: bz at zabbadoz.net (Bjoern A. Zeeb) Date: Mon Dec 1 06:13:19 2008 Subject: svn commit: r185499 - head In-Reply-To: <83764.1228138832@critter.freebsd.dk> References: <83764.1228138832@critter.freebsd.dk> Message-ID: <20081201134712.R80401@maildrop.int.zabbadoz.net> On Mon, 1 Dec 2008, Poul-Henning Kamp wrote: > In message <863ah8qarb.fsf@ds4.des.no>, =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= wr > ites: >> Alfred Perlstein writes: >>> If you strongly believe that a target should return "true" on failure >>> and/or output "i worked" on failure >> >> I don't, and I don't understand why you think I do. I have stated very >> clearly that I don't like the universe target. > > I don't mind the universe target failing with the aggregate status code > at the end, I have said that repeatedly. > > But I don't want it to stop working until it has tried compiling > as much as possible. so in case anyone with enough make foo can tell me why the initial echo "0" is not always (especially on a 2nd and further make universe run) executed, here's the patch for this: http://people.freebsd.org/~bz/make-universe.diff I especially had problems when I did make universe; rm _.*; make universe. When it comes to giving the tail of the build errors, I think it's really not usefull for several reasons: 1) if you have lots of build failures you lose the summary and the overview the next morning you resume your screen. 2) is it really make -jN clean? What does make do if there are less less jobs than told to do parallel builds for a universe? Once it starts to subdivide the jobs your build error is somewhere in your log but not necessarily at the end. If you want email notifications etc. go to projcvs and checkout the real tinderbox instead of overloading our base /Makefile. /bz -- Bjoern A. Zeeb Stop bit received. Insert coin for new game. From kensmith at FreeBSD.org Mon Dec 1 06:15:11 2008 From: kensmith at FreeBSD.org (Ken Smith) Date: Mon Dec 1 06:15:17 2008 Subject: svn commit: r185515 - head/sys/amd64 Message-ID: <200812011415.mB1EFAWl026943@svn.freebsd.org> Author: kensmith Date: Mon Dec 1 14:15:10 2008 New Revision: 185515 URL: http://svn.freebsd.org/changeset/base/185515 Log: Adjustments to make a tags file a bit more suitable to amd64. Reviewed by: peter Modified: head/sys/amd64/Makefile Modified: head/sys/amd64/Makefile ============================================================================== --- head/sys/amd64/Makefile Mon Dec 1 10:20:59 2008 (r185514) +++ head/sys/amd64/Makefile Mon Dec 1 14:15:10 2008 (r185515) @@ -1,39 +1,38 @@ # $FreeBSD$ # @(#)Makefile 8.1 (Berkeley) 6/11/93 -# Makefile for i386 links, tags file +# Makefile for amd64 links, tags file # SYS is normally set in Make.tags.inc -# SYS=/sys -SYS=/nsys +SYS=/sys -TAGDIR= i386 +TAGDIR= amd64 .include "../kern/Make.tags.inc" all: @echo "make links or tags only" -# Directories in which to place i386 tags links -DI386= apm i386 ibcs2 include isa linux +# Directories in which to place amd64 tags links +DAMD64= acpica amd64 ia32 include isa linux32 pci links:: -for i in ${COMMDIR1}; do \ (cd $$i && { rm -f tags; ln -s ../${TAGDIR}/tags tags; }) done -for i in ${COMMDIR2}; do \ (cd $$i && { rm -f tags; ln -s ../../${TAGDIR}/tags tags; }) done - -for i in ${DI386}; do \ + -for i in ${DAMD64}; do \ (cd $$i && { rm -f tags; ln -s ../tags tags; }) done -SI386= ${SYS}/i386/apm/*.[ch] \ - ${SYS}/i386/i386/*.[ch] ${SYS}/i386/ibcs2/*.[ch] \ - ${SYS}/i386/include/*.[ch] ${SYS}/i386/isa/*.[ch] \ - ${SYS}/i386/linux/*.[ch] -AI386= ${SYS}/i386/i386/*.s +SAMD64= ${SYS}/amd64/acpica/*.[ch] \ + ${SYS}/amd64/amd64/*.[ch] ${SYS}/amd64/ia32/*.[ch] \ + ${SYS}/amd64/include/*.[ch] ${SYS}/amd64/isa/*.[ch] \ + ${SYS}/amd64/linux32/*.[ch] ${SYS}/amd64/pci/*.[ch] +AAMD64= ${SYS}/amd64/amd64/*.S tags:: - -ctags -wdt ${COMM} ${SI386} - egrep "^ENTRY(.*)|^ALTENTRY(.*)" ${AI386} | \ + -ctags -wdt ${COMM} ${SAMD64} + egrep "^ENTRY(.*)|^ALTENTRY(.*)" ${AAMD64} | \ sed "s;\([^:]*\):\([^(]*\)(\([^, )]*\)\(.*\);\3 \1 /^\2(\3\4$$/;" \ >> tags sort -o tags tags From ru at FreeBSD.org Mon Dec 1 06:33:35 2008 From: ru at FreeBSD.org (Ruslan Ermilov) Date: Mon Dec 1 06:33:42 2008 Subject: svn commit: r185516 - head/lib/libc/stdio Message-ID: <200812011433.mB1EXYDD027385@svn.freebsd.org> Author: ru Date: Mon Dec 1 14:33:34 2008 New Revision: 185516 URL: http://svn.freebsd.org/changeset/base/185516 Log: Fix fread() to return a correct value on platforms where sizeof(int) != sizeof(size_t), i.e. on all 64-bit platforms. Reported by: Andrey V. Elsukov MFC after: 3 days Modified: head/lib/libc/stdio/fread.c Modified: head/lib/libc/stdio/fread.c ============================================================================== --- head/lib/libc/stdio/fread.c Mon Dec 1 14:15:10 2008 (r185515) +++ head/lib/libc/stdio/fread.c Mon Dec 1 14:33:34 2008 (r185516) @@ -50,7 +50,7 @@ __FBSDID("$FreeBSD$"); size_t fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict fp) { - int ret; + size_t ret; FLOCKFILE(fp); ret = __fread(buf, size, count, fp); From kensmith at FreeBSD.org Mon Dec 1 06:34:44 2008 From: kensmith at FreeBSD.org (Ken Smith) Date: Mon Dec 1 06:34:50 2008 Subject: svn commit: r185517 - head/sys/kern Message-ID: <200812011434.mB1EYgVb027454@svn.freebsd.org> Author: kensmith Date: Mon Dec 1 14:34:42 2008 New Revision: 185517 URL: http://svn.freebsd.org/changeset/base/185517 Log: Catch up with the disappearance of sys/dev/hfa. Modified: head/sys/kern/Make.tags.inc Modified: head/sys/kern/Make.tags.inc ============================================================================== --- head/sys/kern/Make.tags.inc Mon Dec 1 14:33:34 2008 (r185516) +++ head/sys/kern/Make.tags.inc Mon Dec 1 14:34:42 2008 (r185517) @@ -16,7 +16,6 @@ COMM= ${SYS}/dev/advansys/*.[ch] \ ${SYS}/dev/buslogic/*.[ch] \ ${SYS}/dev/dpt/*.[ch] \ ${SYS}/dev/en/*.[ch] \ - ${SYS}/dev/hfa/*.[ch] \ ${SYS}/dev/iicbus/*.[ch] \ ${SYS}/dev/isp/*.[ch] \ ${SYS}/dev/pdq/*.[ch] \ From ivoras at FreeBSD.org Mon Dec 1 07:02:01 2008 From: ivoras at FreeBSD.org (Ivan Voras) Date: Mon Dec 1 07:02:08 2008 Subject: svn commit: r185518 - head/sys/geom Message-ID: <200812011502.mB1F20Zi028195@svn.freebsd.org> Author: ivoras Date: Mon Dec 1 15:02:00 2008 New Revision: 185518 URL: http://svn.freebsd.org/changeset/base/185518 Log: Trivial patch to show on which geom has the error been detected. Submitted by: Rick C. Petty Approved by: gnn (mentor) MFC after: 1 month Modified: head/sys/geom/geom_bsd.c Modified: head/sys/geom/geom_bsd.c ============================================================================== --- head/sys/geom/geom_bsd.c Mon Dec 1 14:34:42 2008 (r185517) +++ head/sys/geom/geom_bsd.c Mon Dec 1 15:02:00 2008 (r185518) @@ -136,7 +136,8 @@ g_bsd_modify(struct g_geom *gp, u_char * } if (rawoffset != 0 && (off_t)rawoffset != ms->mbroffset) - printf("WARNING: Expected rawoffset %jd, found %jd\n", + printf("WARNING: %s expected rawoffset %jd, found %jd\n", + gp->name, (intmax_t)ms->mbroffset/dl.d_secsize, (intmax_t)rawoffset/dl.d_secsize); From keramida at FreeBSD.org Mon Dec 1 07:27:02 2008 From: keramida at FreeBSD.org (Giorgos Keramidas) Date: Mon Dec 1 07:27:13 2008 Subject: svn commit: r185519 - head/lib/libc/gen Message-ID: <200812011527.mB1FR1Hh028955@svn.freebsd.org> Author: keramida (doc committer) Date: Mon Dec 1 15:27:00 2008 New Revision: 185519 URL: http://svn.freebsd.org/changeset/base/185519 Log: The times(3) function returns the number of CLK_TCKs since the startup time of FreeBSD, not since the UNIX Epoch. PR: docs/122359 Submitted by: Viktor Štujber MFC after: 1 week Modified: head/lib/libc/gen/times.3 Modified: head/lib/libc/gen/times.3 ============================================================================== --- head/lib/libc/gen/times.3 Mon Dec 1 15:02:00 2008 (r185518) +++ head/lib/libc/gen/times.3 Mon Dec 1 15:27:00 2008 (r185519) @@ -28,7 +28,7 @@ .\" @(#)times.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd June 4, 1993 +.Dd December 1, 2008 .Dt TIMES 3 .Os .Sh NAME @@ -52,9 +52,13 @@ The .Fn times function returns the value of time in .Dv CLK_TCK Ns 's -of a second since -0 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated Universal -Time. +of a second since the system startup time. +The current value of +.Dv CLK_TCK , +the frequency of the statistics clock in ticks per second, may be +obtained through the +.Xr sysconf 3 +interface. .Pp It also fills in the structure pointed to by .Fa tp @@ -131,6 +135,7 @@ and .Xr getrusage 2 , .Xr gettimeofday 2 , .Xr wait 2 , +.Xr sysconf 3 , .Xr clocks 7 .Sh STANDARDS The From sam at FreeBSD.org Mon Dec 1 08:43:09 2008 From: sam at FreeBSD.org (Sam Leffler) Date: Mon Dec 1 08:43:20 2008 Subject: svn commit: r185521 - head/sys/dev/ath/ath_hal Message-ID: <200812011643.mB1Gh8o9030874@svn.freebsd.org> Author: sam Date: Mon Dec 1 16:43:08 2008 New Revision: 185521 URL: http://svn.freebsd.org/changeset/base/185521 Log: import ath hal Added: head/sys/dev/ath/ath_hal/ - copied from r185520, projects/ath_hal/ From sam at FreeBSD.org Mon Dec 1 08:53:03 2008 From: sam at FreeBSD.org (Sam Leffler) Date: Mon Dec 1 08:53:21 2008 Subject: svn commit: r185522 - in head: . share/man/man4 sys/amd64/conf sys/arm/conf sys/conf sys/contrib/dev/ath sys/dev/ath sys/dev/ath/ath_rate/amrr sys/dev/ath/ath_rate/onoe sys/dev/ath/ath_rate/sample ... Message-ID: <200812011653.mB1Gr2Dv031130@svn.freebsd.org> Author: sam Date: Mon Dec 1 16:53:01 2008 New Revision: 185522 URL: http://svn.freebsd.org/changeset/base/185522 Log: Switch to ath hal source code. Note this removes the ath_hal module; the ath module now brings in the hal support. Kernel config files are almost backwards compatible; supplying device ath_hal gives you the same chip support that the binary hal did but you must also include options AH_SUPPORT_AR5416 to enable the extended format descriptors used by 11n parts. It is now possible to control the chip support included in a build by specifying exactly which chips are to be supported in the config file; consult ath_hal(4) for information. Deleted: head/sys/contrib/dev/ath/ head/sys/modules/ath_hal/ Modified: head/UPDATING head/share/man/man4/ath_hal.4 head/sys/amd64/conf/GENERIC head/sys/amd64/conf/NOTES head/sys/arm/conf/AVILA head/sys/conf/files head/sys/conf/files.amd64 head/sys/conf/files.arm head/sys/conf/files.i386 head/sys/conf/files.mips head/sys/conf/files.pc98 head/sys/conf/files.powerpc head/sys/conf/files.sparc64 head/sys/conf/kern.pre.mk head/sys/conf/options head/sys/dev/ath/ah_osdep.c head/sys/dev/ath/ah_osdep.h head/sys/dev/ath/ath_rate/amrr/amrr.c head/sys/dev/ath/ath_rate/onoe/onoe.c head/sys/dev/ath/ath_rate/sample/sample.c head/sys/dev/ath/if_ath.c head/sys/dev/ath/if_ath_pci.c head/sys/dev/ath/if_athvar.h head/sys/i386/conf/GENERIC head/sys/i386/conf/NOTES head/sys/i386/conf/PAE head/sys/mips/conf/IDT head/sys/mips/conf/SENTRY5 head/sys/modules/Makefile head/sys/modules/ath/Makefile head/sys/modules/ath_rate_amrr/Makefile head/sys/modules/ath_rate_onoe/Makefile head/sys/modules/ath_rate_sample/Makefile head/sys/pc98/conf/GENERIC head/sys/pc98/conf/NOTES head/sys/sparc64/conf/GENERIC head/sys/sys/param.h Modified: head/UPDATING ============================================================================== --- head/UPDATING Mon Dec 1 16:43:08 2008 (r185521) +++ head/UPDATING Mon Dec 1 16:53:01 2008 (r185522) @@ -22,6 +22,21 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 8. to maximize performance. (To disable malloc debugging, run ln -s aj /etc/malloc.conf.) +20081130: + __FreeBSD_version 800057 marks the switchover from the + binary ath hal to source code. Users must add the line: + + options ATH_SUPPORT_AR5416 + + to their kernel config files when specifying: + + device ath_hal + + The ath_hal module no longer exists; the code is now compiled + together with the driver in the ath module. It is now + possible to tailor chip support (i.e. reduce the set of chips + and thereby the code size); consult ath_hal(4) for details. + 20081121: __FreeBSD_version 800054 adds memory barriers to , new interfaces to ifnet to facilitate Modified: head/share/man/man4/ath_hal.4 ============================================================================== --- head/share/man/man4/ath_hal.4 Mon Dec 1 16:43:08 2008 (r185521) +++ head/share/man/man4/ath_hal.4 Mon Dec 1 16:53:01 2008 (r185522) @@ -1,5 +1,5 @@ .\"- -.\" Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting +.\" Copyright (c) 2002-2008 Sam Leffler, Errno Consulting .\" All rights reserved. .\"" .\" Redistribution and use in source and binary forms, with or without @@ -12,9 +12,6 @@ .\" similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any .\" redistribution must be conditioned upon including a substantially .\" similar Disclaimer requirement for further binary redistribution. -.\" 3. Neither the names of the above-listed copyright holders nor the names -.\" of any contributors may be used to endorse or promote products derived -.\" from this software without specific prior written permission. .\" .\" NO WARRANTY .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS @@ -31,7 +28,7 @@ .\" .\" $FreeBSD$ .\"/ -.Dd August 26, 2004 +.Dd November 30, 2008 .Dt ATH_HAL 4 .Os .Sh NAME @@ -39,18 +36,44 @@ .Nd "Atheros Hardware Access Layer (HAL)" .Sh SYNOPSIS .Cd "device ath_hal" +.Cd "options AH_SUPPORT_AR5416" +or +.Cd "device ath_ar5210" +.Cd "device ath_ar5211" +.Cd "device ath_ar5212" +.Cd "device ath_rf2413" +.Cd "device ath_rf2417" +.Cd "device ath_rf2425" +.Cd "device ath_rf5111" +.Cd "device ath_rf5112" +.Cd "device ath_rf5413" +.Cd "device ath_ar5416" +.\".Cd "device ath_ar5312" +.\".Cd "device ath_rf2136" +.\".Cd "device ath_rf2137" +.Cd "device ath_ar9160" +.Cd "options AH_SUPPORT_AR5416" .Sh DESCRIPTION -The -.Nm -module provides hardware support for wireless network adapters based on -the Atheros AR5210, AR5211, and AR5212 chips. -This module is required by the +The hal provides hardware support for wireless network adapters based on +the Atheros AR5210, AR5211, AR5212, AR5416, and AR9160 chips. +This code is part of the .Xr ath 4 -driver. -.Pp -Devices supported by the +driver but configured separately to allow fine-grained control +over the set of chips supported. +Selecting .Nm -module come in either Cardbus or mini-PCI packages. +enables support for all PCI and Cardbus devices. +Note this includes AR5416 devices and must be accompanied by the +AH_SUPPORT_AR5416 +option to enable the extended hardware descriptor format used by +AR5416 and later devices. +.Pp +Devices supported come in either Cardbus or mini-PCI packages. +.Pp +Historically this code has been released in a binary-only form +and packaged as a separate module. +With the release of source code for the hal this is no longer true +and the code is tightly integrated with the driver. .Sh HARDWARE The following cards are among those supported by the .Nm @@ -105,16 +128,6 @@ The .Nm module first appeared in .Fx 5.2 . -.Sh CAVEATS -The -.Nm -module is constructed from a binary component and -operating system-dependent source code. -Redistribution and use in source and binary forms, without -modification, are permitted provided that the conditions -set forth in -.Pa sys/contrib/dev/ath/COPYRIGHT -are observed. .Sh BUGS See .Xr ath 4 Modified: head/sys/amd64/conf/GENERIC ============================================================================== --- head/sys/amd64/conf/GENERIC Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/amd64/conf/GENERIC Mon Dec 1 16:53:01 2008 (r185522) @@ -249,7 +249,8 @@ device wlan_tkip # 802.11 TKIP support device wlan_amrr # AMRR transmit rate control algorithm device an # Aironet 4500/4800 802.11 wireless NICs. device ath # Atheros pci/cardbus NIC's -device ath_hal # Atheros HAL (Hardware Access Layer) +device ath_hal # pci/cardbus chip support +options AH_SUPPORT_AR5416 # enable AR5416 tx/rx descriptors device ath_rate_sample # SampleRate tx rate control for ath device ral # Ralink Technology RT2500 wireless NICs. device wi # WaveLAN/Intersil/Symbol 802.11 wireless NICs. Modified: head/sys/amd64/conf/NOTES ============================================================================== --- head/sys/amd64/conf/NOTES Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/amd64/conf/NOTES Mon Dec 1 16:53:01 2008 (r185522) @@ -258,7 +258,6 @@ options DRM_DEBUG # Include debug print # Network interfaces: # -# ath: Atheros a/b/g WiFi adapters (requires ath_hal and wlan) # ed: Western Digital and SMC 80xx; Novell NE1000 and NE2000; 3Com 3C503 # HP PC Lan+, various PC Card devices # (requires miibus) @@ -284,12 +283,12 @@ device ral device ural device wpi -device ath -device ath_hal # Atheros HAL (includes binary component) -#device ath_rate_amrr # AMRR rate control for ath driver -#device ath_rate_onoe # Onoe rate control for ath driver -device ath_rate_sample # SampleRate rate control for the ath driver -#device wlan # 802.11 layer +device ath # Atheros pci/cardbus NIC's +device ath_hal # pci/cardbus chip support +options AH_SUPPORT_AR5416 # enable AR5416 tx/rx descriptors +device ath_rate_sample # SampleRate tx rate control for ath +#device ath_rate_amrr # AMRR rate control for ath driver +#device ath_rate_onoe # Onoe rate control for ath driver # #XXX this stores pointers in a 32bit field that is defined by the hardware Modified: head/sys/arm/conf/AVILA ============================================================================== --- head/sys/arm/conf/AVILA Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/arm/conf/AVILA Mon Dec 1 16:53:01 2008 (r185522) @@ -128,6 +128,7 @@ device wlan_tkip # 802.11 TKIP support device wlan_xauth device ath # Atheros pci/cardbus NIC's device ath_hal # Atheros HAL (Hardware Access Layer) +options AH_SUPPORT_AR5416 # enable AR5416 tx/rx descriptors device ath_rate_sample # SampleRate tx rate control for ath options ATH_DEBUG Modified: head/sys/conf/files ============================================================================== --- head/sys/conf/files Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/conf/files Mon Dec 1 16:53:01 2008 (r185522) @@ -503,18 +503,179 @@ dev/ata/atapi-fd.c optional atapifd dev/ata/atapi-tape.c optional atapist dev/ata/atapi-cam.c optional atapicam # -dev/ath/ah_osdep.c optional ath_hal \ +dev/ath/if_ath.c optional ath \ + compile-with "${NORMAL_C} -I$S/dev/ath" +dev/ath/if_ath_pci.c optional ath pci \ + compile-with "${NORMAL_C} -I$S/dev/ath" +dev/ath/ah_osdep.c optional ath \ + compile-with "${NORMAL_C} -I$S/dev/ath" +dev/ath/ath_hal/ah.c optional ath \ + compile-with "${NORMAL_C} -I$S/dev/ath" +dev/ath/ath_hal/ah_eeprom_v1.c optional ath_hal | ath_ar5210 \ + compile-with "${NORMAL_C} -I$S/dev/ath" +dev/ath/ath_hal/ah_eeprom_v3.c optional ath_hal | ath_ar5211 | ath_ar5212 \ compile-with "${NORMAL_C} -I$S/dev/ath" +dev/ath/ath_hal/ah_eeprom_v14.c optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath" +dev/ath/ath_hal/ah_regdomain.c optional ath \ + compile-with "${NORMAL_C} -I$S/dev/ath" +dev/ath/ath_hal/ar5210/ar5210_attach.c optional ath_hal | ath_ar5210 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5210/ar5210_beacon.c optional ath_hal | ath_ar5210 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5210/ar5210_interrupts.c optional ath_hal | ath_ar5210 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5210/ar5210_keycache.c optional ath_hal | ath_ar5210 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5210/ar5210_misc.c optional ath_hal | ath_ar5210 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5210/ar5210_phy.c optional ath_hal | ath_ar5210 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5210/ar5210_power.c optional ath_hal | ath_ar5210 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5210/ar5210_recv.c optional ath_hal | ath_ar5210 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5210/ar5210_reset.c optional ath_hal | ath_ar5210 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5210/ar5210_xmit.c optional ath_hal | ath_ar5210 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5211/ar5211_attach.c optional ath_hal | ath_ar5211 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5211/ar5211_beacon.c optional ath_hal | ath_ar5211 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5211/ar5211_interrupts.c optional ath_hal | ath_ar5211 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5211/ar5211_keycache.c optional ath_hal | ath_ar5211 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5211/ar5211_misc.c optional ath_hal | ath_ar5211 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5211/ar5211_phy.c optional ath_hal | ath_ar5211 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5211/ar5211_power.c optional ath_hal | ath_ar5211 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5211/ar5211_recv.c optional ath_hal | ath_ar5211 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5211/ar5211_reset.c optional ath_hal | ath_ar5211 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5211/ar5211_xmit.c optional ath_hal | ath_ar5211 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar5212_ani.c \ + optional ath_hal | ath_ar5212 | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar5212_attach.c \ + optional ath_hal | ath_ar5212 | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar5212_beacon.c \ + optional ath_hal | ath_ar5212 | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar5212_eeprom.c \ + optional ath_hal | ath_ar5212 | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar5212_gpio.c \ + optional ath_hal | ath_ar5212 | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar5212_interrupts.c \ + optional ath_hal | ath_ar5212 | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar5212_keycache.c \ + optional ath_hal | ath_ar5212 | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar5212_misc.c \ + optional ath_hal | ath_ar5212 | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar5212_phy.c \ + optional ath_hal | ath_ar5212 | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar5212_power.c \ + optional ath_hal | ath_ar5212 | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar5212_recv.c \ + optional ath_hal | ath_ar5212 | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar5212_reset.c \ + optional ath_hal | ath_ar5212 | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar5212_rfgain.c \ + optional ath_hal | ath_ar5212 | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar5212_xmit.c \ + optional ath_hal | ath_ar5212 | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar2316.c optional ath_rf2316 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar2317.c optional ath_rf2317 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar2413.c optional ath_hal | ath_rf2413 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar2425.c optional ath_hal | ath_rf2425 | ath_rf2417 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar5111.c optional ath_hal | ath_rf5111 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar5112.c optional ath_hal | ath_rf5112 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5212/ar5413.c optional ath_hal | ath_rf5413 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar2133.c optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar5416_ani.c \ + optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar5416_attach.c \ + optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar5416_beacon.c \ + optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar5416_cal.c \ + optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar5416_cal_iq.c \ + optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar5416_cal_adcgain.c \ + optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar5416_cal_adcdc.c \ + optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar5416_eeprom.c \ + optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar5416_gpio.c \ + optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar5416_interrupts.c \ + optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar5416_keycache.c \ + optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar5416_misc.c \ + optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar5416_phy.c \ + optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar5416_power.c \ + optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar5416_recv.c \ + optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar5416_reset.c \ + optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar5416_xmit.c \ + optional ath_hal | ath_ar5416 | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" +dev/ath/ath_hal/ar5416/ar9160_attach.c optional ath_hal | ath_ar9160 \ + compile-with "${NORMAL_C} -I$S/dev/ath -I$S/dev/ath/ath_hal" dev/ath/ath_rate/amrr/amrr.c optional ath_rate_amrr \ compile-with "${NORMAL_C} -I$S/dev/ath" dev/ath/ath_rate/onoe/onoe.c optional ath_rate_onoe \ compile-with "${NORMAL_C} -I$S/dev/ath" dev/ath/ath_rate/sample/sample.c optional ath_rate_sample \ compile-with "${NORMAL_C} -I$S/dev/ath" -dev/ath/if_ath.c optional ath \ - compile-with "${NORMAL_C} -I$S/dev/ath" -dev/ath/if_ath_pci.c optional ath pci \ - compile-with "${NORMAL_C} -I$S/dev/ath" dev/bce/if_bce.c optional bce dev/bfe/if_bfe.c optional bfe dev/bge/if_bge.c optional bge Modified: head/sys/conf/files.amd64 ============================================================================== --- head/sys/conf/files.amd64 Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/conf/files.amd64 Mon Dec 1 16:53:01 2008 (r185522) @@ -47,16 +47,6 @@ ukbdmap.h optional ukbd_dflt_keymap \ no-obj no-implicit-rule before-depend \ clean "ukbdmap.h" # -hal.o optional ath_hal \ - dependency "$S/contrib/dev/ath/public/x86_64-elf.hal.o.uu" \ - compile-with "uudecode < $S/contrib/dev/ath/public/x86_64-elf.hal.o.uu" \ - no-implicit-rule -opt_ah.h optional ath_hal \ - dependency "$S/contrib/dev/ath/public/x86_64-elf.opt_ah.h" \ - compile-with "rm -f opt_ah.h; cp $S/contrib/dev/ath/public/x86_64-elf.opt_ah.h opt_ah.h" \ - no-obj no-implicit-rule before-depend \ - clean "opt_ah.h" -# nvenetlib.o optional nve pci \ dependency "$S/contrib/dev/nve/amd64/nvenetlib.o.bz2.uu" \ compile-with "uudecode $S/contrib/dev/nve/amd64/nvenetlib.o.bz2.uu ; bzip2 -df nvenetlib.o.bz2" \ Modified: head/sys/conf/files.arm ============================================================================== --- head/sys/conf/files.arm Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/conf/files.arm Mon Dec 1 16:53:01 2008 (r185522) @@ -51,13 +51,6 @@ geom/geom_bsd.c optional geom_bsd geom/geom_bsd_enc.c optional geom_bsd geom/geom_mbr.c optional geom_mbr geom/geom_mbr_enc.c optional geom_mbr -hal.o optional ath_hal \ - compile-with "ATH_HAL_CPU=`echo ${CONF_CFLAGS}|sed 's/.*-mcpu=\([a-zA-Z0-9]*\).*/\1/'`; ATH_ENDIAN=`if (echo ${CC}|grep mbig-endian>/dev/null); then echo be; else echo le; fi;`; uudecode < $S/contrib/dev/ath/public/$$ATH_HAL_CPU-$$ATH_ENDIAN-elf.hal.o.uu" \ - no-implicit-rule -opt_ah.h optional ath_hal \ - compile-with "ATH_HAL_CPU=`echo ${CONF_CFLAGS}|sed 's/.*-mcpu=\([a-zA-Z0-9]*\).*/\1/'`; ATH_ENDIAN=`if (echo ${CC}|grep mbig-endian>/dev/null); then echo be; else echo le; fi;`; rm -f opt_ah.h; cp $S/contrib/dev/ath/public/$$ATH_HAL_CPU-$$ATH_ENDIAN-elf.opt_ah.h opt_ah.h" \ - no-obj no-implicit-rule before-depend \ - clean "opt_ah.h" libkern/arm/divsi3.S standard libkern/arm/ffs.S standard libkern/arm/muldi3.c standard Modified: head/sys/conf/files.i386 ============================================================================== --- head/sys/conf/files.i386 Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/conf/files.i386 Mon Dec 1 16:53:01 2008 (r185522) @@ -46,16 +46,6 @@ ukbdmap.h optional ukbd_dflt_keymap \ no-obj no-implicit-rule before-depend \ clean "ukbdmap.h" # -hal.o optional ath_hal \ - dependency "$S/contrib/dev/ath/public/i386-elf.hal.o.uu" \ - compile-with "uudecode < $S/contrib/dev/ath/public/i386-elf.hal.o.uu" \ - no-implicit-rule -opt_ah.h optional ath_hal \ - dependency "$S/contrib/dev/ath/public/i386-elf.opt_ah.h" \ - compile-with "rm -f opt_ah.h; cp $S/contrib/dev/ath/public/i386-elf.opt_ah.h opt_ah.h" \ - no-obj no-implicit-rule before-depend \ - clean "opt_ah.h" -# nvenetlib.o optional nve pci \ dependency "$S/contrib/dev/nve/i386/nvenetlib.o.bz2.uu" \ compile-with "uudecode $S/contrib/dev/nve/i386/nvenetlib.o.bz2.uu ; bzip2 -df nvenetlib.o.bz2" \ Modified: head/sys/conf/files.mips ============================================================================== --- head/sys/conf/files.mips Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/conf/files.mips Mon Dec 1 16:53:01 2008 (r185522) @@ -75,13 +75,6 @@ geom/geom_bsd.c optional geom_bsd geom/geom_bsd_enc.c optional geom_bsd geom/geom_mbr.c optional geom_mbr geom/geom_mbr_enc.c optional geom_mbr -hal.o optional ath_hal \ - compile-with "ATH_HAL_CPU=mips; ATH_ENDIAN=`if ([ x${TARGET_BIG_ENDIAN} = x ]); then echo le; else echo be; fi;`; uudecode < $S/contrib/dev/ath/public/$$ATH_HAL_CPU-$$ATH_ENDIAN-elf.hal.o.uu" \ - no-implicit-rule -opt_ah.h optional ath_hal \ - compile-with "ATH_HAL_CPU=mips; ATH_ENDIAN=`if ([ x${TARGET_BIG_ENDIAN} = x ]); then echo le; else echo be; fi;`; rm -f opt_ah.h; cp $S/contrib/dev/ath/public/$$ATH_HAL_CPU-$$ATH_ENDIAN-elf.opt_ah.h opt_ah.h" \ - no-obj no-implicit-rule before-depend \ - clean "opt_ah.h" libkern/ashldi3.c standard libkern/ashrdi3.c standard libkern/divdi3.c standard Modified: head/sys/conf/files.pc98 ============================================================================== --- head/sys/conf/files.pc98 Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/conf/files.pc98 Mon Dec 1 16:53:01 2008 (r185522) @@ -38,16 +38,6 @@ ukbdmap.h optional ukbd_dflt_keymap \ no-obj no-implicit-rule before-depend \ clean "ukbdmap.h" # -hal.o optional ath_hal \ - dependency "$S/contrib/dev/ath/public/i386-elf.hal.o.uu" \ - compile-with "uudecode < $S/contrib/dev/ath/public/i386-elf.hal.o.uu" \ - no-implicit-rule -opt_ah.h optional ath_hal \ - dependency "$S/contrib/dev/ath/public/i386-elf.opt_ah.h" \ - compile-with "rm -f opt_ah.h; cp $S/contrib/dev/ath/public/i386-elf.opt_ah.h opt_ah.h" \ - no-obj no-implicit-rule before-depend \ - clean "opt_ah.h" -# compat/linprocfs/linprocfs.c optional linprocfs compat/linsysfs/linsysfs.c optional linsysfs compat/linux/linux_emul.c optional compat_linux Modified: head/sys/conf/files.powerpc ============================================================================== --- head/sys/conf/files.powerpc Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/conf/files.powerpc Mon Dec 1 16:53:01 2008 (r185522) @@ -14,16 +14,6 @@ font.h optional sc \ no-obj no-implicit-rule before-depend \ clean "font.h ${SC_DFLT_FONT}-8x14 ${SC_DFLT_FONT}-8x16 ${SC_DFLT_FONT}-8x8" # -hal.o optional ath_hal \ - dependency "$S/contrib/dev/ath/public/powerpc-be-elf.hal.o.uu" \ - compile-with "uudecode < $S/contrib/dev/ath/public/powerpc-be-elf.hal.o.uu" \ - no-implicit-rule -opt_ah.h optional ath_hal \ - dependency "$S/contrib/dev/ath/public/powerpc-be-elf.opt_ah.h" \ - compile-with "rm -f opt_ah.h; cp $S/contrib/dev/ath/public/powerpc-be-elf.opt_ah.h opt_ah.h" \ - no-obj no-implicit-rule before-depend \ - clean "opt_ah.h" -# crypto/blowfish/bf_enc.c optional crypto | ipsec crypto/des/des_enc.c optional crypto | ipsec | netsmb Modified: head/sys/conf/files.sparc64 ============================================================================== --- head/sys/conf/files.sparc64 Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/conf/files.sparc64 Mon Dec 1 16:53:01 2008 (r185522) @@ -22,16 +22,6 @@ ukbdmap.h optional ukbd_dflt_keymap \ no-obj no-implicit-rule before-depend \ clean "ukbdmap.h" # -hal.o optional ath_hal \ - dependency "$S/contrib/dev/ath/public/sparc64-be-elf.hal.o.uu" \ - compile-with "uudecode < $S/contrib/dev/ath/public/sparc64-be-elf.hal.o.uu" \ - no-implicit-rule -opt_ah.h optional ath_hal \ - dependency "$S/contrib/dev/ath/public/sparc64-be-elf.opt_ah.h" \ - compile-with "rm -f opt_ah.h; cp $S/contrib/dev/ath/public/sparc64-be-elf.opt_ah.h opt_ah.h" \ - no-obj no-implicit-rule before-depend \ - clean "opt_ah.h" -# crypto/blowfish/bf_enc.c optional crypto | ipsec crypto/des/des_enc.c optional crypto | ipsec | netsmb dev/atkbdc/atkbd.c optional atkbd atkbdc Modified: head/sys/conf/kern.pre.mk ============================================================================== --- head/sys/conf/kern.pre.mk Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/conf/kern.pre.mk Mon Dec 1 16:53:01 2008 (r185522) @@ -66,8 +66,8 @@ INCLUDES+= -I$S/contrib/ipfilter # ... and the same for pf INCLUDES+= -I$S/contrib/pf -# ... and the same for Atheros HAL -INCLUDES+= -I$S/dev/ath +# ... and the same for ath +INCLUDES+= -I$S/dev/ath -I$S/dev/ath/ath_hal # ... and the same for the NgATM stuff INCLUDES+= -I$S/contrib/ngatm Modified: head/sys/conf/options ============================================================================== --- head/sys/conf/options Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/conf/options Mon Dec 1 16:53:01 2008 (r185522) @@ -740,6 +740,21 @@ ATH_RXBUF opt_ath.h ATH_DIAGAPI opt_ath.h ATH_TX99_DIAG opt_ath.h +# options for the Atheros hal +AH_SUPPORT_AR5416 opt_ah.h + +AH_DEBUG opt_ah.h +AH_ASSERT opt_ah.h +AH_DEBUG_ALQ opt_ah.h +AH_REGOPS_FUNC opt_ah.h +AH_WRITE_REGDOMAIN opt_ah.h +AH_DEBUG_COUNTRY opt_ah.h +AH_WRITE_EEPROM opt_ah.h +AH_PRIVATE_DIAG opt_ah.h +AH_NEED_DESC_SWAP opt_ah.h +AH_USE_INIPDGAIN opt_ah.h +AH_SUPPORT_11D opt_ah.h + # options for the Marvell 8335 wireless driver MALO_DEBUG opt_malo.h MALO_TXBUF opt_malo.h Modified: head/sys/dev/ath/ah_osdep.c ============================================================================== --- head/sys/dev/ath/ah_osdep.c Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/dev/ath/ah_osdep.c Mon Dec 1 16:53:01 2008 (r185522) @@ -43,7 +43,7 @@ #include /* XXX for ether_sprintf */ -#include +#include /* * WiSoC boards overload the bus tag with information about the @@ -56,7 +56,7 @@ #define BUSTAG(ah) \ ((bus_space_tag_t) ((struct ar531x_config *)((ah)->ah_st))->tag) #else -#define BUSTAG(ah) ((bus_space_tag_t) (ah)->ah_st) +#define BUSTAG(ah) ((ah)->ah_st) #endif extern void ath_hal_printf(struct ath_hal *, const char*, ...) @@ -90,9 +90,6 @@ SYSCTL_INT(_hw_ath_hal, OID_AUTO, debug, TUNABLE_INT("hw.ath.hal.debug", &ath_hal_debug); #endif /* AH_DEBUG */ -SYSCTL_STRING(_hw_ath_hal, OID_AUTO, version, CTLFLAG_RD, ath_hal_version, 0, - "Atheros HAL version"); - /* NB: these are deprecated; they exist for now for compatibility */ int ath_hal_dma_beacon_response_time = 2; /* in TU's */ SYSCTL_INT(_hw_ath_hal, OID_AUTO, dma_brt, CTLFLAG_RW, @@ -195,7 +192,7 @@ HALDEBUGn(struct ath_hal *ah, u_int leve */ #include #include -#include +#include static struct alq *ath_hal_alq; static int ath_hal_alq_emitdev; /* need to emit DEVICE record */ @@ -273,7 +270,7 @@ void ath_hal_reg_write(struct ath_hal *ah, u_int32_t reg, u_int32_t val) { bus_space_tag_t tag = BUSTAG(ah); - bus_space_handle_t h = (bus_space_handle_t) ah->ah_sh; + bus_space_handle_t h = ah->ah_sh; if (ath_hal_alq) { struct ale *ale = ath_hal_alq_get(ah); @@ -297,7 +294,7 @@ u_int32_t ath_hal_reg_read(struct ath_hal *ah, u_int32_t reg) { bus_space_tag_t tag = BUSTAG(ah); - bus_space_handle_t h = (bus_space_handle_t) ah->ah_sh; + bus_space_handle_t h = ah->ah_sh; u_int32_t val; #if _BYTE_ORDER == _BIG_ENDIAN @@ -349,7 +346,7 @@ void ath_hal_reg_write(struct ath_hal *ah, u_int32_t reg, u_int32_t val) { bus_space_tag_t tag = BUSTAG(ah); - bus_space_handle_t h = (bus_space_handle_t) ah->ah_sh; + bus_space_handle_t h = ah->ah_sh; #if _BYTE_ORDER == _BIG_ENDIAN if (reg >= 0x4000 && reg < 0x5000) @@ -363,7 +360,7 @@ u_int32_t ath_hal_reg_read(struct ath_hal *ah, u_int32_t reg) { bus_space_tag_t tag = BUSTAG(ah); - bus_space_handle_t h = (bus_space_handle_t) ah->ah_sh; + bus_space_handle_t h = ah->ah_sh; u_int32_t val; #if _BYTE_ORDER == _BIG_ENDIAN @@ -415,37 +412,3 @@ ath_hal_memcpy(void *dst, const void *sr { return memcpy(dst, src, n); } - -/* - * Module glue. - */ - -static int -ath_hal_modevent(module_t mod, int type, void *unused) -{ - const char *sep; - int i; - - switch (type) { - case MOD_LOAD: - printf("ath_hal: %s (", ath_hal_version); - sep = ""; - for (i = 0; ath_hal_buildopts[i] != NULL; i++) { - printf("%s%s", sep, ath_hal_buildopts[i]); - sep = ", "; - } - printf(")\n"); - return 0; - case MOD_UNLOAD: - return 0; - } - return EINVAL; -} - -static moduledata_t ath_hal_mod = { - "ath_hal", - ath_hal_modevent, - 0 -}; -DECLARE_MODULE(ath_hal, ath_hal_mod, SI_SUB_DRIVERS, SI_ORDER_ANY); -MODULE_VERSION(ath_hal, 1); Modified: head/sys/dev/ath/ah_osdep.h ============================================================================== --- head/sys/dev/ath/ah_osdep.h Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/dev/ath/ah_osdep.h Mon Dec 1 16:53:01 2008 (r185522) @@ -33,13 +33,29 @@ /* * Atheros Hardware Access Layer (HAL) OS Dependent Definitions. */ +#include #include #include #include +#include #include /* + * Bus i/o type definitions. + */ +typedef void *HAL_SOFTC; +typedef bus_space_tag_t HAL_BUS_TAG; +typedef bus_space_handle_t HAL_BUS_HANDLE; + +/* + * Linker set writearounds for chip and RF backend registration. + */ +#define OS_DATA_SET(set, item) DATA_SET(set, item) +#define OS_SET_DECLARE(set, ptype) SET_DECLARE(set, ptype) +#define OS_SET_FOREACH(pvar, set) SET_FOREACH(pvar, set) + +/* * Delay n microseconds. */ extern void ath_hal_delay(int); Modified: head/sys/dev/ath/ath_rate/amrr/amrr.c ============================================================================== --- head/sys/dev/ath/ath_rate/amrr/amrr.c Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/dev/ath/ath_rate/amrr/amrr.c Mon Dec 1 16:53:01 2008 (r185522) @@ -78,7 +78,7 @@ __FBSDID("$FreeBSD$"); #include #include -#include +#include static int ath_rateinterval = 1000; /* rate ctl interval (ms) */ static int ath_rate_max_success_threshold = 10; Modified: head/sys/dev/ath/ath_rate/onoe/onoe.c ============================================================================== --- head/sys/dev/ath/ath_rate/onoe/onoe.c Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/dev/ath/ath_rate/onoe/onoe.c Mon Dec 1 16:53:01 2008 (r185522) @@ -67,7 +67,7 @@ __FBSDID("$FreeBSD$"); #include #include -#include +#include /* * Default parameters for the rate control algorithm. These are Modified: head/sys/dev/ath/ath_rate/sample/sample.c ============================================================================== --- head/sys/dev/ath/ath_rate/sample/sample.c Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/dev/ath/ath_rate/sample/sample.c Mon Dec 1 16:53:01 2008 (r185522) @@ -75,7 +75,7 @@ __FBSDID("$FreeBSD$"); #include #include -#include +#include /* * This file is an implementation of the SampleRate algorithm @@ -1018,5 +1018,4 @@ static moduledata_t sample_mod = { }; DECLARE_MODULE(ath_rate, sample_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST); MODULE_VERSION(ath_rate, 1); -MODULE_DEPEND(ath_rate, ath_hal, 1, 1, 1); /* Atheros HAL */ MODULE_DEPEND(ath_rate, wlan, 1, 1, 1); Modified: head/sys/dev/ath/if_ath.c ============================================================================== --- head/sys/dev/ath/if_ath.c Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/dev/ath/if_ath.c Mon Dec 1 16:53:01 2008 (r185522) @@ -77,8 +77,7 @@ __FBSDID("$FreeBSD$"); #endif #include -#include -#include /* XXX for softled */ +#include /* XXX for softled */ #ifdef ATH_TX99_DIAG #include Modified: head/sys/dev/ath/if_ath_pci.c ============================================================================== --- head/sys/dev/ath/if_ath_pci.c Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/dev/ath/if_ath_pci.c Mon Dec 1 16:53:01 2008 (r185522) @@ -56,7 +56,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include #include @@ -254,6 +253,5 @@ static devclass_t ath_devclass; DRIVER_MODULE(if_ath, pci, ath_pci_driver, ath_devclass, 0, 0); DRIVER_MODULE(if_ath, cardbus, ath_pci_driver, ath_devclass, 0, 0); MODULE_VERSION(if_ath, 1); -MODULE_DEPEND(if_ath, ath_hal, 1, 1, 1); /* Atheros HAL */ MODULE_DEPEND(if_ath, wlan, 1, 1, 1); /* 802.11 media layer */ MODULE_DEPEND(if_ath, ath_rate, 1, 1, 1); /* rate control algorithm */ Modified: head/sys/dev/ath/if_athvar.h ============================================================================== --- head/sys/dev/ath/if_athvar.h Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/dev/ath/if_athvar.h Mon Dec 1 16:53:01 2008 (r185522) @@ -35,8 +35,8 @@ #ifndef _DEV_ATH_ATHVAR_H #define _DEV_ATH_ATHVAR_H -#include -#include +#include +#include #include #include #include Modified: head/sys/i386/conf/GENERIC ============================================================================== --- head/sys/i386/conf/GENERIC Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/i386/conf/GENERIC Mon Dec 1 16:53:01 2008 (r185522) @@ -264,10 +264,11 @@ device wlan_tkip # 802.11 TKIP support device wlan_amrr # AMRR transmit rate control algorithm device an # Aironet 4500/4800 802.11 wireless NICs. device ath # Atheros pci/cardbus NIC's -device ath_hal # Atheros HAL (Hardware Access Layer) +device ath_hal # pci/cardbus chip support +options AH_SUPPORT_AR5416 # enable AR5416 tx/rx descriptors device ath_rate_sample # SampleRate tx rate control for ath device ral # Ralink Technology RT2500 wireless NICs. -device wi # WaveLAN/Intersil/Symbol 802.11 wireless NICs. +#device wi # WaveLAN/Intersil/Symbol 802.11 wireless NICs. #device wl # Older non 802.11 Wavelan wireless NIC. # Pseudo devices. Modified: head/sys/i386/conf/NOTES ============================================================================== --- head/sys/i386/conf/NOTES Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/i386/conf/NOTES Mon Dec 1 16:53:01 2008 (r185522) @@ -565,6 +565,20 @@ hint.ar.0.at="isa" hint.ar.0.port="0x300" hint.ar.0.irq="10" hint.ar.0.maddr="0xd0000" +device ath # Atheros pci/cardbus NIC's +device ath_hal # pci/cardbus chip support +#device ath_ar5210 # AR5210 chips +#device ath_ar5211 # AR5211 chips +#device ath_ar5212 # AR5212 chips +#device ath_rf2413 +#device ath_rf2417 +#device ath_rf2425 +#device ath_rf5111 +#device ath_rf5112 +#device ath_rf5413 +#device ath_ar5416 # AR5416 chips +options AH_SUPPORT_AR5416 # enable AR5416 tx/rx descriptors +device ath_rate_sample # SampleRate tx rate control for ath device ce device cp device cs @@ -617,13 +631,6 @@ options WLCACHE # enables the signal-s options WLDEBUG # enables verbose debugging output device wpi -device ath -device ath_hal # Atheros HAL (includes binary component) -#device ath_rate_amrr # AMRR rate control for ath driver -#device ath_rate_onoe # Onoe rate control for ath driver -device ath_rate_sample # SampleRate rate control for the ath driver -#device wlan # 802.11 layer - # # ATA raid adapters # Modified: head/sys/i386/conf/PAE ============================================================================== --- head/sys/i386/conf/PAE Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/i386/conf/PAE Mon Dec 1 16:53:01 2008 (r185522) @@ -78,7 +78,7 @@ nodevice xe nodevice an nodevice ath # Atheros pci/cardbus NIC's -nodevice ath_hal # Atheros HAL (Hardware Access Layer) +nodevice ath_hal nodevice ath_rate_sample # SampleRate tx rate control for ath nodevice ral nodevice wi Modified: head/sys/mips/conf/IDT ============================================================================== --- head/sys/mips/conf/IDT Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/mips/conf/IDT Mon Dec 1 16:53:01 2008 (r185522) @@ -44,7 +44,8 @@ device wlan # 802.11 support device wlan_wep # 802.11 WEP support device wlan_tkip # 802.11 TKIP support device ath # Atheros pci/cardbus NIC's -device ath_hal # Atheros HAL (Hardware Access Layer) +device ath_hal # pci/cardbus chip support +options AH_SUPPORT_AR5416 # enable AR5416 tx/rx descriptors device ath_rate_sample # SampleRate tx rate control for ath options ATH_DEBUG Modified: head/sys/mips/conf/SENTRY5 ============================================================================== --- head/sys/mips/conf/SENTRY5 Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/mips/conf/SENTRY5 Mon Dec 1 16:53:01 2008 (r185522) @@ -79,7 +79,8 @@ device miibus # attachments # pci devices # notyet: #device ath # in pci slot -#device ath_hal # in pci slot +#device ath_hal # pci chip support +#options AH_SUPPORT_AR5416 # enable AR5416 tx/rx descriptors device usb # USB Bus (required) device uhci # UHCI PCI->USB interface Modified: head/sys/modules/Makefile ============================================================================== --- head/sys/modules/Makefile Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/modules/Makefile Mon Dec 1 16:53:01 2008 (r185522) @@ -29,11 +29,10 @@ SUBDIR= ${_3dfx} \ ${_asmc} \ ${_asr} \ ata \ - ${_ath} \ - ${_ath_hal} \ - ${_ath_rate_amrr} \ - ${_ath_rate_onoe} \ - ${_ath_rate_sample} \ + ath \ + ath_rate_amrr \ + ath_rate_onoe \ + ath_rate_sample \ aue \ ${_auxio} \ axe \ @@ -376,11 +375,6 @@ _aout= aout _apm= apm _ar= ar _arcnet= arcnet -_ath= ath -_ath_hal= ath_hal -_ath_rate_amrr= ath_rate_amrr -_ath_rate_onoe= ath_rate_onoe -_ath_rate_sample=ath_rate_sample _bktr= bktr _cardbus= cardbus _cbb= cbb @@ -513,11 +507,6 @@ _agp= agp _an= an _arcmsr= arcmsr _asmc= asmc -_ath= ath -_ath_hal= ath_hal -_ath_rate_amrr= ath_rate_amrr -_ath_rate_onoe= ath_rate_onoe -_ath_rate_sample=ath_rate_sample _cardbus= cardbus _cbb= cbb _cmx= cmx @@ -625,11 +614,6 @@ _xe= xe .if ${MACHINE_ARCH} == "powerpc" _an= an -_ath= ath -_ath_hal= ath_hal -_ath_rate_amrr= ath_rate_amrr -_ath_rate_onoe= ath_rate_onoe -_ath_rate_sample=ath_rate_sample _bm= bm _nvram= powermac_nvram _smbfs= smbfs @@ -637,11 +621,6 @@ _upgt= upgt .endif .if ${MACHINE_ARCH} == "sparc64" -_ath= ath -_ath_hal= ath_hal -_ath_rate_amrr= ath_rate_amrr -_ath_rate_onoe= ath_rate_onoe -_ath_rate_sample=ath_rate_sample _auxio= auxio _em= em _i2c= i2c Modified: head/sys/modules/ath/Makefile ============================================================================== --- head/sys/modules/ath/Makefile Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/modules/ath/Makefile Mon Dec 1 16:53:01 2008 (r185522) @@ -1,5 +1,5 @@ # -# Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting +# Copyright (c) 2002-2008 Sam Leffler, Errno Consulting # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -12,13 +12,6 @@ # similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any # redistribution must be conditioned upon including a substantially # similar Disclaimer requirement for further binary redistribution. -# 3. Neither the names of the above-listed copyright holders nor the names -# of any contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# Alternatively, this software may be distributed under the terms of the -# GNU General Public License ("GPL") version 2 as published by the Free -# Software Foundation. # # NO WARRANTY # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS @@ -36,30 +29,48 @@ # $FreeBSD$ # -.PATH: ${.CURDIR}/../../dev/ath +.PATH: ${.CURDIR}/../../dev/ath \ + ${.CURDIR}/../../dev/ath/ath_hal \ + ${.CURDIR}/../../dev/ath/ath_hal/ar5210 \ + ${.CURDIR}/../../dev/ath/ath_hal/ar5211 \ + ${.CURDIR}/../../dev/ath/ath_hal/ar5212 \ + ${.CURDIR}/../../dev/ath/ath_hal/ar5416 + +AR5210_SRCS=ah_eeprom_v1.c \ + ar5210_attach.c ar5210_beacon.c ar5210_interrupts.c \ + ar5210_keycache.c ar5210_misc.c ar5210_phy.c ar5210_power.c \ + ar5210_recv.c ar5210_reset.c ar5210_xmit.c +AR5211_SRCS=ar5211_attach.c ar5211_beacon.c ar5211_interrupts.c \ + ar5211_keycache.c ar5211_misc.c ar5211_phy.c ar5211_power.c \ + ar5211_recv.c ar5211_reset.c ar5211_xmit.c +AR5212_SRCS=ar5212_ani.c ar5212_attach.c ar5212_beacon.c ar5212_eeprom.c \ + ar5212_gpio.c ar5212_interrupts.c ar5212_keycache.c ar5212_misc.c \ + ar5212_phy.c ar5212_power.c ar5212_recv.c ar5212_reset.c \ + ar5212_rfgain.c ar5212_xmit.c \ + ar2413.c ar2425.c ar5111.c ar5112.c ar5413.c +AR5416_SRCS=ah_eeprom_v14.c \ + ar5416_ani.c ar5416_attach.c ar5416_beacon.c ar5416_cal.c \ + ar5416_cal_iq.c ar5416_cal_adcgain.c ar5416_cal_adcdc.c \ + ar5416_eeprom.c ar5416_gpio.c ar5416_interrupts.c ar5416_keycache.c \ + ar5416_misc.c ar5416_phy.c ar5416_power.c ar5416_recv.c \ + ar5416_reset.c ar5416_xmit.c \ + ar2133.c +AR9160_SRCS=ar9160_attach.c KMOD= if_ath SRCS= if_ath.c if_ath_pci.c -SRCS+= device_if.h bus_if.h pci_if.h opt_inet.h opt_ath.h opt_ah.h - -HAL= ${.CURDIR}/../../contrib/dev/ath -CFLAGS+= -I. -I${.CURDIR}/../../dev/ath -I${HAL} - -opt_ath.h: - echo > $@ +# NB: v3 eeprom support used by both AR5211 and AR5212; just include it +SRCS+= ah_osdep.c ah.c ah_regdomain.c ah_eeprom_v3.c +SRCS+= ${AR5210_SRCS} +SRCS+= ${AR5211_SRCS} +SRCS+= ${AR5212_SRCS} +SRCS+= ${AR5416_SRCS} +SRCS+= ${AR9160_SRCS} +SRCS+= device_if.h bus_if.h pci_if.h opt_inet.h opt_route.h opt_ath.h opt_ah.h -# patch for hal naming difference -.if ${MACHINE_ARCH} == "amd64" -ATH_MODULE_ARCH=x86_64 -.elif ${MACHINE_ARCH} == "sparc64" -ATH_MODULE_ARCH=sparc64-be -.elif ${MACHINE_ARCH} == "powerpc" -ATH_MODULE_ARCH=powerpc-be -.else -ATH_MODULE_ARCH=${MACHINE_ARCH} -.endif +CFLAGS+= -I. -I${.CURDIR}/../../dev/ath -I${.CURDIR}/../../dev/ath/ath_hal -opt_ah.h: ${HAL}/public/${ATH_MODULE_ARCH}-elf.opt_ah.h - cp ${HAL}/public/${ATH_MODULE_ARCH}-elf.opt_ah.h ${.TARGET} +opt_ah.h: + echo '#define AH_SUPPORT_AR5416 1' > $@ .include Modified: head/sys/modules/ath_rate_amrr/Makefile ============================================================================== --- head/sys/modules/ath_rate_amrr/Makefile Mon Dec 1 16:43:08 2008 (r185521) +++ head/sys/modules/ath_rate_amrr/Makefile Mon Dec 1 16:53:01 2008 (r185522) @@ -1,5 +1,5 @@ *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From skv at FreeBSD.org Mon Dec 1 09:39:35 2008 From: skv at FreeBSD.org (Sergey Skvortsov) Date: Mon Dec 1 09:39:46 2008 Subject: svn commit: r185525 - head/usr.sbin/cron/crontab Message-ID: <200812011739.mB1HdZmx032265@svn.freebsd.org> Author: skv (ports committer) Date: Mon Dec 1 17:39:34 2008 New Revision: 185525 URL: http://svn.freebsd.org/changeset/base/185525 Log: Fix typo. Approved by: ru Modified: head/usr.sbin/cron/crontab/crontab.5 Modified: head/usr.sbin/cron/crontab/crontab.5 ============================================================================== --- head/usr.sbin/cron/crontab/crontab.5 Mon Dec 1 17:29:41 2008 (r185524) +++ head/usr.sbin/cron/crontab/crontab.5 Mon Dec 1 17:39:34 2008 (r185525) @@ -118,7 +118,7 @@ is defined (and non-empty), mail is sent to the user so named. .Ev MAILTO may also be used to direct mail to multiple recipients -by seperating recipient users with a comma. +by separating recipient users with a comma. If .Ev MAILTO is defined but empty (MAILTO=""), no From mav at FreeBSD.org Mon Dec 1 09:45:57 2008 From: mav at FreeBSD.org (Alexander Motin) Date: Mon Dec 1 09:46:09 2008 Subject: svn commit: r185527 - head/sys/dev/sdhci Message-ID: <200812011745.mB1HjuMG032510@svn.freebsd.org> Author: mav Date: Mon Dec 1 17:45:56 2008 New Revision: 185527 URL: http://svn.freebsd.org/changeset/base/185527 Log: Add controller suspend/resume support. To be able to correctly suspend/resume with card inserted, respective support should be also implemented at mmc and mmcsd layers. Modified: head/sys/dev/sdhci/sdhci.c Modified: head/sys/dev/sdhci/sdhci.c ============================================================================== --- head/sys/dev/sdhci/sdhci.c Mon Dec 1 17:40:57 2008 (r185526) +++ head/sys/dev/sdhci/sdhci.c Mon Dec 1 17:45:56 2008 (r185527) @@ -802,6 +802,31 @@ sdhci_detach(device_t dev) } static int +sdhci_suspend(device_t dev) +{ + struct sdhci_softc *sc = device_get_softc(dev); + int i, err; + + err = bus_generic_suspend(dev); + if (err) + return (err); + for (i = 0; i < sc->num_slots; i++) + sdhci_reset(&sc->slots[i], SDHCI_RESET_ALL); + return (0); +} + +static int +sdhci_resume(device_t dev) +{ + struct sdhci_softc *sc = device_get_softc(dev); + int i; + + for (i = 0; i < sc->num_slots; i++) + sdhci_init(&sc->slots[i]); + return (bus_generic_resume(dev)); +} + +static int sdhci_update_ios(device_t brdev, device_t reqdev) { struct sdhci_slot *slot = device_get_ivars(reqdev); @@ -1508,6 +1533,8 @@ static device_method_t sdhci_methods[] = DEVMETHOD(device_probe, sdhci_probe), DEVMETHOD(device_attach, sdhci_attach), DEVMETHOD(device_detach, sdhci_detach), + DEVMETHOD(device_suspend, sdhci_suspend), + DEVMETHOD(device_resume, sdhci_resume), /* Bus interface */ DEVMETHOD(bus_read_ivar, sdhci_read_ivar), From jhb at freebsd.org Mon Dec 1 11:32:34 2008 From: jhb at freebsd.org (John Baldwin) Date: Mon Dec 1 11:32:41 2008 Subject: svn commit: r185170 - head/sys/ufs/ufs In-Reply-To: <200811221311.mAMDBBU8018510@svn.freebsd.org> References: <200811221311.mAMDBBU8018510@svn.freebsd.org> Message-ID: <200812011336.37636.jhb@freebsd.org> On Saturday 22 November 2008 08:11:11 am Konstantin Belousov wrote: > Author: kib > Date: Sat Nov 22 13:11:11 2008 > New Revision: 185170 > URL: http://svn.freebsd.org/changeset/base/185170 > > Log: > Busy ufs filesystem around block of code that does ".." lookup. Since > mnt_lock is before lock of any vnode on the mp, it uses LK_NOWAIT. Since > MNTK_UNMOUNT may be transient, pdp lock is dropped when vfs_busy() > failed, and operation is retried after some time. This way, ffs_vget() > is not called on the mp that may be in the process of being destroyed by > unmount. > > Check for the VI_DOOMED flag on pdp after its lock is reacquired, to > better detect some situations where directory containing ".." > entry is removed during the lookup. I'm not really sure it matters if the parent directory goes away because it will have deadfs vops so any subsequent operations will already fail, yes? Also, do you really need to grab the VI_LOCK just to check VI_DOOMED? Other places in the kernel check that flag while holding the vnode lock w/o acquiring the interlock. Since you are just doing a single atomic read the interlock doesn't actually close any races anyway. I think it just adds overhead. > Reviewed by: tegge, attilio (previous version) > Tested by: pho > MFC after: 1 month > > Modified: > head/sys/ufs/ufs/ufs_lookup.c > > Modified: head/sys/ufs/ufs/ufs_lookup.c > ============================================================================== > --- head/sys/ufs/ufs/ufs_lookup.c Sat Nov 22 12:36:15 2008 (r185169) > +++ head/sys/ufs/ufs/ufs_lookup.c Sat Nov 22 13:11:11 2008 (r185170) > @@ -157,6 +157,8 @@ ufs_lookup(ap) > int nameiop = cnp->cn_nameiop; > ino_t ino; > int ltype; > + int pdoomed; > + struct mount *mp; > > bp = NULL; > slotoffset = -1; > @@ -578,9 +580,32 @@ found: > pdp = vdp; > if (flags & ISDOTDOT) { > ltype = VOP_ISLOCKED(pdp); > + mp = pdp->v_mount; > + for (;;) { > + error = vfs_busy(mp, MBF_NOWAIT); > + if (error == 0) > + break; > + VOP_UNLOCK(pdp, 0); > + pause("ufs_dd", 1); > + vn_lock(pdp, ltype | LK_RETRY); > + VI_LOCK(pdp); > + pdoomed = pdp->v_iflag & VI_DOOMED; > + VI_UNLOCK(pdp); > + if (pdoomed) > + return (ENOENT); > + } > VOP_UNLOCK(pdp, 0); /* race to get the inode */ > - error = VFS_VGET(pdp->v_mount, ino, cnp->cn_lkflags, &tdp); > + error = VFS_VGET(mp, ino, cnp->cn_lkflags, &tdp); > + vfs_unbusy(mp); > vn_lock(pdp, ltype | LK_RETRY); > + VI_LOCK(pdp); > + pdoomed = pdp->v_iflag & VI_DOOMED; > + VI_UNLOCK(pdp); > + if (pdoomed) { > + if (error == 0) > + vput(tdp); > + error = ENOENT; > + } > if (error) > return (error); > *vpp = tdp; > -- John Baldwin From jhb at freebsd.org Mon Dec 1 11:32:40 2008 From: jhb at freebsd.org (John Baldwin) Date: Mon Dec 1 11:33:07 2008 Subject: svn commit: r185339 - head/sys/boot/i386/boot0 In-Reply-To: <200811261801.mAQI1LRp062260@svn.freebsd.org> References: <200811261801.mAQI1LRp062260@svn.freebsd.org> Message-ID: <200812011358.15430.jhb@freebsd.org> On Wednesday 26 November 2008 01:01:21 pm Luigi Rizzo wrote: > Author: luigi > Date: Wed Nov 26 18:01:21 2008 > New Revision: 185339 > URL: http://svn.freebsd.org/changeset/base/185339 > > Log: > Pass the pointer to the selected partition in %si to the next stage > boot code. The bug was introduced in rev.1.13, and went unnoticed > because FreeBSD's boot1 does not use it, but other systems might. > > (I have been struggling for almost a full day trying to figure out > why a syslinux'ed partition would not boot when started with the > FreeBSD /boot/boot0, only to realize that the bug was ours!) > > The space for the two extra bytes (push %si and pop %si) is reclaimed > by removing an extra CRLF that is printed before booting. > > The bug is not a major one but if there is time it might be a good > thing to merge it into the upcoming releases. Note that there is nothing (no standard, etc.) that requires any MBR boot loader to pass anything besides %dl (boot device ID) to other loaders. However, we did used to do this and had an 'XXX: what does %si carry?' comment that 1.13 removed. I would suggest adding a more expanded comment about '%si' in the block comment above this code where the old 'XXX' comment was detailing why %si is preserved. -- John Baldwin From jhb at freebsd.org Mon Dec 1 11:32:47 2008 From: jhb at freebsd.org (John Baldwin) Date: Mon Dec 1 11:33:07 2008 Subject: svn commit: r185162 - in head: . sys/amd64/include sys/arm/include sys/conf sys/dev/bce sys/dev/cxgb sys/dev/cxgb/sys sys/dev/cxgb/ulp/iw_cxgb sys/dev/mxge sys/dev/nxge sys/i386/include sys/i386/in... In-Reply-To: <20081123154138.GS6408@deviant.kiev.zoral.com.ua> References: <200811220555.mAM5tuIJ007781@svn.freebsd.org> <3c1674c90811221651u338294frcdbd99b386733851@mail.gmail.com> <20081123154138.GS6408@deviant.kiev.zoral.com.ua> Message-ID: <200812011407.06563.jhb@freebsd.org> On Sunday 23 November 2008 10:41:38 am Kostik Belousov wrote: > On Sun, Nov 23, 2008 at 12:51:58AM +0000, Kip Macy wrote: > > On Sat, Nov 22, 2008 at 11:08 PM, Scott Long wrote: > > > Kostik Belousov wrote: > > >> > > >> On Sat, Nov 22, 2008 at 03:05:22PM -0700, Scott Long wrote: > > >>> > > >>> A neat hack would be for the kernel linker to scan the text and do a > > >>> drop-in replacement of the opcode that is appropriate for the platform. > > >>> I can't see how a CPU_XXX definition would work because it's just a > > >>> compile time construct, one that can be included with any kernel > > >>> compile. > > >> > > >> Yes, it is possible to do that. Less drastic change is to directly > > >> check features. I moved slow code to separate section to eliminate > > >> unconditional jump in fast path. > > >> Only compile-tested. > > >> > > > > > > As long as it works, I think it's a step in the right direction; I'm > > > assuming that cpu_feature is a symbol filled in at runtime and not a > > > macro for the cpuid instruction, right? > > > > > > Scott > > > > > > > i386/include/md_var.h: > > <..> > > extern u_int cpu_exthigh; > > extern u_int cpu_feature; > > extern u_int cpu_feature2; > > extern u_int amd_feature; > > extern u_int amd_feature2; > > <...> > > > > I'm not thrilled with it, but we can revisit the issue if it makes a > > measurable difference on someone's workload. > > Below is the updated patch. It includes changes made after private comments > by bde@ and uses symbolic definitions for the bits in the features words. > I thought about accessing a per-CPU word for serialized instruction in the > slow path, but decided that it does not beneficial.\ Is the branch really better than just doing what the atomic operations for mutexes, etc. do and just use 'lock addl $0,%esp' for a barrier in all cases on i386 and only bother with using the fancier instructions on amd64? Even amd64 doesn't use *fence yet for the atomic ops actually. I have had a patch to use it for years, but during testing there was no discernable difference between the existing 'lock addl' approach vs '*fence'. I'd much rather just use 486 code for all i386 machines than add a branch, esp. if the "optimization" the branch is doing isn't an actual optimization. -- John Baldwin From kan at FreeBSD.org Mon Dec 1 13:00:25 2008 From: kan at FreeBSD.org (Alexander Kabaev) Date: Mon Dec 1 13:00:36 2008 Subject: svn commit: r185531 - head/lib/libthr/thread Message-ID: <200812012100.mB1L0Pec037142@svn.freebsd.org> Author: kan Date: Mon Dec 1 21:00:25 2008 New Revision: 185531 URL: http://svn.freebsd.org/changeset/base/185531 Log: Invoke _rtld_atfork_post earlier, before we reinitialize rtld locks by switching into single-thread mode. libthr ignores broken use of lock bitmaps used by default rtld locking implementation, this in turn turns lock handoff in _rtld_thread_init into NOP. This in turn makes child processes of forked multi-threaded programs to run with _thr_signal_block still in effect, with most signals blocked. Reported by: phk, kib Modified: head/lib/libthr/thread/thr_fork.c Modified: head/lib/libthr/thread/thr_fork.c ============================================================================== --- head/lib/libthr/thread/thr_fork.c Mon Dec 1 20:33:22 2008 (r185530) +++ head/lib/libthr/thread/thr_fork.c Mon Dec 1 21:00:25 2008 (r185531) @@ -158,6 +158,9 @@ _fork(void) /* clear other threads locked us. */ _thr_umutex_init(&curthread->lock); _thr_umutex_init(&_thr_atfork_lock); + + if (unlock_malloc) + _rtld_atfork_post(rtld_locks); _thr_setthreaded(0); /* reinitialize libc spinlocks. */ @@ -170,10 +173,8 @@ _fork(void) /* Ready to continue, unblock signals. */ _thr_signal_unblock(curthread); - if (unlock_malloc) { - _rtld_atfork_post(rtld_locks); + if (unlock_malloc) _malloc_postfork(); - } /* Run down atfork child handlers. */ TAILQ_FOREACH(af, &_thr_atfork_list, qe) { From brueffer at FreeBSD.org Mon Dec 1 13:15:04 2008 From: brueffer at FreeBSD.org (Christian Brueffer) Date: Mon Dec 1 13:15:10 2008 Subject: svn commit: r185532 - head/release/doc/en_US.ISO8859-1/hardware Message-ID: <200812012115.mB1LF4ps037501@svn.freebsd.org> Author: brueffer Date: Mon Dec 1 21:15:04 2008 New Revision: 185532 URL: http://svn.freebsd.org/changeset/base/185532 Log: Add ixgbe(4) and upgt(4). Modified: head/release/doc/en_US.ISO8859-1/hardware/article.sgml Modified: head/release/doc/en_US.ISO8859-1/hardware/article.sgml ============================================================================== --- head/release/doc/en_US.ISO8859-1/hardware/article.sgml Mon Dec 1 21:00:25 2008 (r185531) +++ head/release/doc/en_US.ISO8859-1/hardware/article.sgml Mon Dec 1 21:15:04 2008 (r185532) @@ -712,6 +712,8 @@ &hwlist.ixgb; + &hwlist.ixgbe; + &hwlist.jme; &hwlist.kue; @@ -838,6 +840,8 @@ &hwlist.rum; + &hwlist.upgt; + &hwlist.ural; [&arch.amd64;, &arch.i386;, &arch.pc98;] Lucent From kostikbel at gmail.com Mon Dec 1 13:32:23 2008 From: kostikbel at gmail.com (Kostik Belousov) Date: Mon Dec 1 13:32:35 2008 Subject: svn commit: r185170 - head/sys/ufs/ufs In-Reply-To: <200812011336.37636.jhb@freebsd.org> References: <200811221311.mAMDBBU8018510@svn.freebsd.org> <200812011336.37636.jhb@freebsd.org> Message-ID: <20081201213217.GR3045@deviant.kiev.zoral.com.ua> On Mon, Dec 01, 2008 at 01:36:36PM -0500, John Baldwin wrote: > On Saturday 22 November 2008 08:11:11 am Konstantin Belousov wrote: > > Author: kib > > Date: Sat Nov 22 13:11:11 2008 > > New Revision: 185170 > > URL: http://svn.freebsd.org/changeset/base/185170 > > > > Log: > > Busy ufs filesystem around block of code that does ".." lookup. Since > > mnt_lock is before lock of any vnode on the mp, it uses LK_NOWAIT. Since > > MNTK_UNMOUNT may be transient, pdp lock is dropped when vfs_busy() > > failed, and operation is retried after some time. This way, ffs_vget() > > is not called on the mp that may be in the process of being destroyed by > > unmount. > > > > Check for the VI_DOOMED flag on pdp after its lock is reacquired, to > > better detect some situations where directory containing ".." > > entry is removed during the lookup. > > I'm not really sure it matters if the parent directory goes away because it > will have deadfs vops so any subsequent operations will already fail, yes? Operations will fail. There is another race with parent directory being removed while pdp is unlocked. This can creep without tripping over deadfs operations for pdp. As Tor noted, the race may be considered as a security issue, allowing to escape the chroot. Check for reclamation cannot catch a move of pdp, this is why I specified the check as partial measure. > > Also, do you really need to grab the VI_LOCK just to check VI_DOOMED? Other > places in the kernel check that flag while holding the vnode lock w/o > acquiring the interlock. Since you are just doing a single atomic read the > interlock doesn't actually close any races anyway. I think it just adds > overhead. Yes, VI_DOOMED is set when both lock and interlock is held. I will remove interlock around the check. > > > Reviewed by: tegge, attilio (previous version) > > Tested by: pho > > MFC after: 1 month > > > > Modified: > > head/sys/ufs/ufs/ufs_lookup.c > > > > Modified: head/sys/ufs/ufs/ufs_lookup.c > > > ============================================================================== > > --- head/sys/ufs/ufs/ufs_lookup.c Sat Nov 22 12:36:15 2008 (r185169) > > +++ head/sys/ufs/ufs/ufs_lookup.c Sat Nov 22 13:11:11 2008 (r185170) > > @@ -157,6 +157,8 @@ ufs_lookup(ap) > > int nameiop = cnp->cn_nameiop; > > ino_t ino; > > int ltype; > > + int pdoomed; > > + struct mount *mp; > > > > bp = NULL; > > slotoffset = -1; > > @@ -578,9 +580,32 @@ found: > > pdp = vdp; > > if (flags & ISDOTDOT) { > > ltype = VOP_ISLOCKED(pdp); > > + mp = pdp->v_mount; > > + for (;;) { > > + error = vfs_busy(mp, MBF_NOWAIT); > > + if (error == 0) > > + break; > > + VOP_UNLOCK(pdp, 0); > > + pause("ufs_dd", 1); > > + vn_lock(pdp, ltype | LK_RETRY); > > + VI_LOCK(pdp); > > + pdoomed = pdp->v_iflag & VI_DOOMED; > > + VI_UNLOCK(pdp); > > + if (pdoomed) > > + return (ENOENT); > > + } > > VOP_UNLOCK(pdp, 0); /* race to get the inode */ > > - error = VFS_VGET(pdp->v_mount, ino, cnp->cn_lkflags, &tdp); > > + error = VFS_VGET(mp, ino, cnp->cn_lkflags, &tdp); > > + vfs_unbusy(mp); > > vn_lock(pdp, ltype | LK_RETRY); > > + VI_LOCK(pdp); > > + pdoomed = pdp->v_iflag & VI_DOOMED; > > + VI_UNLOCK(pdp); > > + if (pdoomed) { > > + if (error == 0) > > + vput(tdp); > > + error = ENOENT; > > + } > > if (error) > > return (error); > > *vpp = tdp; > > > > > > -- > John Baldwin -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 195 bytes Desc: not available Url : http://lists.freebsd.org/pipermail/svn-src-head/attachments/20081201/509bc803/attachment.pgp From kostikbel at gmail.com Mon Dec 1 13:42:25 2008 From: kostikbel at gmail.com (Kostik Belousov) Date: Mon Dec 1 13:42:38 2008 Subject: svn commit: r185162 - in head: . sys/amd64/include sys/arm/include sys/conf sys/dev/bce sys/dev/cxgb sys/dev/cxgb/sys sys/dev/cxgb/ulp/iw_cxgb sys/dev/mxge sys/dev/nxge sys/i386/include sys/i386/in... In-Reply-To: <200812011407.06563.jhb@freebsd.org> References: <200811220555.mAM5tuIJ007781@svn.freebsd.org> <3c1674c90811221651u338294frcdbd99b386733851@mail.gmail.com> <20081123154138.GS6408@deviant.kiev.zoral.com.ua> <200812011407.06563.jhb@freebsd.org> Message-ID: <20081201214217.GS3045@deviant.kiev.zoral.com.ua> On Mon, Dec 01, 2008 at 02:07:06PM -0500, John Baldwin wrote: > On Sunday 23 November 2008 10:41:38 am Kostik Belousov wrote: > > On Sun, Nov 23, 2008 at 12:51:58AM +0000, Kip Macy wrote: > > > On Sat, Nov 22, 2008 at 11:08 PM, Scott Long wrote: > > > > Kostik Belousov wrote: > > > >> > > > >> On Sat, Nov 22, 2008 at 03:05:22PM -0700, Scott Long wrote: > > > >>> > > > >>> A neat hack would be for the kernel linker to scan the text and do a > > > >>> drop-in replacement of the opcode that is appropriate for the > platform. > > > >>> I can't see how a CPU_XXX definition would work because it's just a > > > >>> compile time construct, one that can be included with any kernel > > > >>> compile. > > > >> > > > >> Yes, it is possible to do that. Less drastic change is to directly > > > >> check features. I moved slow code to separate section to eliminate > > > >> unconditional jump in fast path. > > > >> Only compile-tested. > > > >> > > > > > > > > As long as it works, I think it's a step in the right direction; I'm > > > > assuming that cpu_feature is a symbol filled in at runtime and not a > > > > macro for the cpuid instruction, right? > > > > > > > > Scott > > > > > > > > > > i386/include/md_var.h: > > > <..> > > > extern u_int cpu_exthigh; > > > extern u_int cpu_feature; > > > extern u_int cpu_feature2; > > > extern u_int amd_feature; > > > extern u_int amd_feature2; > > > <...> > > > > > > I'm not thrilled with it, but we can revisit the issue if it makes a > > > measurable difference on someone's workload. > > > > Below is the updated patch. It includes changes made after private comments > > by bde@ and uses symbolic definitions for the bits in the features words. > > I thought about accessing a per-CPU word for serialized instruction in the > > slow path, but decided that it does not beneficial.\ > > Is the branch really better than just doing what the atomic operations for > mutexes, etc. do and just use 'lock addl $0,%esp' for a barrier in all cases > on i386 and only bother with using the fancier instructions on amd64? Even > amd64 doesn't use *fence yet for the atomic ops actually. I have had a patch > to use it for years, but during testing there was no discernable difference > between the existing 'lock addl' approach vs '*fence'. I'd much rather just > use 486 code for all i386 machines than add a branch, esp. if > the "optimization" the branch is doing isn't an actual optimization. I do not insist. The branch is done only for arches that has no fence instructions. The section for the slow code is put after the main text, that should, according to Intel documentation, be predicted as not taken for the first execution. For reference, below is the latest version of the patch. I postponed the commit, in particular, because it touches ixgb, and Jack did not responded. diff --git a/sys/conf/ldscript.i386 b/sys/conf/ldscript.i386 index a94f32f..49d9636 100644 --- a/sys/conf/ldscript.i386 +++ b/sys/conf/ldscript.i386 @@ -45,6 +45,7 @@ SECTIONS .text : { *(.text) + *(.text.offpath) *(.stub) /* .gnu.warning sections are handled specially by elf32.em. */ *(.gnu.warning) diff --git a/sys/dev/iir/iir.c b/sys/dev/iir/iir.c index cbcb449..a01b685 100644 --- a/sys/dev/iir/iir.c +++ b/sys/dev/iir/iir.c @@ -403,7 +403,7 @@ iir_init(struct gdt_softc *gdt) gdt->oem_name[7]='\0'; } else { /* Old method, based on PCI ID */ - if (gdt->sc_vendor == INTEL_VENDOR_ID) + if (gdt->sc_vendor == INTEL_VENDOR_ID_IIR) strcpy(gdt->oem_name,"Intel "); else strcpy(gdt->oem_name,"ICP "); @@ -1447,7 +1447,7 @@ iir_action( struct cam_sim *sim, union ccb *ccb ) (bus == gdt->sc_virt_bus ? 127 : gdt->sc_bus_id[bus]); cpi->base_transfer_speed = 3300; strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); - if (gdt->sc_vendor == INTEL_VENDOR_ID) + if (gdt->sc_vendor == INTEL_VENDOR_ID_IIR) strncpy(cpi->hba_vid, "Intel Corp.", HBA_IDLEN); else strncpy(cpi->hba_vid, "ICP vortex ", HBA_IDLEN); diff --git a/sys/dev/iir/iir.h b/sys/dev/iir/iir.h index dca493d..dbae7d2 100644 --- a/sys/dev/iir/iir.h +++ b/sys/dev/iir/iir.h @@ -63,7 +63,7 @@ #define GDT_DEVICE_ID_MAX 0x2ff #define GDT_DEVICE_ID_NEWRX 0x300 -#define INTEL_VENDOR_ID 0x8086 +#define INTEL_VENDOR_ID_IIR 0x8086 #define INTEL_DEVICE_ID_IIR 0x600 #define GDT_MAXBUS 6 /* XXX Why not 5? */ diff --git a/sys/dev/iir/iir_ctrl.c b/sys/dev/iir/iir_ctrl.c index e5fbac9..2af2aad 100644 --- a/sys/dev/iir/iir_ctrl.c +++ b/sys/dev/iir/iir_ctrl.c @@ -278,7 +278,7 @@ iir_ioctl(struct cdev *dev, u_long cmd, caddr_t cmdarg, int flags, d_thread_t * return (ENXIO); /* only RP controllers */ p->ext_type = 0x6000 | gdt->sc_device; - if (gdt->sc_vendor == INTEL_VENDOR_ID) { + if (gdt->sc_vendor == INTEL_VENDOR_ID_IIR) { p->oem_id = OEM_ID_INTEL; p->type = 0xfd; /* new -> subdevice into ext_type */ diff --git a/sys/dev/iir/iir_pci.c b/sys/dev/iir/iir_pci.c index 528b7d7..0f420a1 100644 --- a/sys/dev/iir/iir_pci.c +++ b/sys/dev/iir/iir_pci.c @@ -164,7 +164,7 @@ MODULE_DEPEND(iir, cam, 1, 1, 1); static int iir_pci_probe(device_t dev) { - if (pci_get_vendor(dev) == INTEL_VENDOR_ID && + if (pci_get_vendor(dev) == INTEL_VENDOR_ID_IIR && pci_get_device(dev) == INTEL_DEVICE_ID_IIR) { device_set_desc(dev, "Intel Integrated RAID Controller"); return (BUS_PROBE_DEFAULT); diff --git a/sys/dev/ixgb/if_ixgb.c b/sys/dev/ixgb/if_ixgb.c index c1d6858..df2f51a 100644 --- a/sys/dev/ixgb/if_ixgb.c +++ b/sys/dev/ixgb/if_ixgb.c @@ -72,8 +72,8 @@ char ixgb_copyright[] = "Copyright (c) 2001-2004 Intel Corporation."; static ixgb_vendor_info_t ixgb_vendor_info_array[] = { /* Intel(R) PRO/10000 Network Connection */ - {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX, PCI_ANY_ID, PCI_ANY_ID, 0}, - {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_SR, PCI_ANY_ID, PCI_ANY_ID, 0}, + {INTEL_VENDOR_ID_IXGB, IXGB_DEVICE_ID_82597EX, PCI_ANY_ID, PCI_ANY_ID, 0}, + {INTEL_VENDOR_ID_IXGB, IXGB_DEVICE_ID_82597EX_SR, PCI_ANY_ID, PCI_ANY_ID, 0}, /* required last entry */ {0, 0, 0, 0, 0} }; diff --git a/sys/dev/ixgb/ixgb_ids.h b/sys/dev/ixgb/ixgb_ids.h index a224f63..aa7dab8 100644 --- a/sys/dev/ixgb/ixgb_ids.h +++ b/sys/dev/ixgb/ixgb_ids.h @@ -40,7 +40,7 @@ ** The Device and Vendor IDs for 10 Gigabit MACs **********************************************************************/ -#define INTEL_VENDOR_ID 0x8086 +#define INTEL_VENDOR_ID_IXGB 0x8086 #define INTEL_SUBVENDOR_ID 0x8086 diff --git a/sys/i386/include/atomic.h b/sys/i386/include/atomic.h index f6bcf0c..dbdc945 100644 --- a/sys/i386/include/atomic.h +++ b/sys/i386/include/atomic.h @@ -32,21 +32,47 @@ #error this file needs sys/cdefs.h as a prerequisite #endif - -#if defined(I686_CPU) -#define mb() __asm__ __volatile__ ("mfence;": : :"memory") -#define wmb() __asm__ __volatile__ ("sfence;": : :"memory") -#define rmb() __asm__ __volatile__ ("lfence;": : :"memory") -#else -/* - * do we need a serializing instruction? - */ -#define mb() -#define wmb() -#define rmb() +#if defined(_KERNEL) +#include +#include +#define mb() __asm __volatile( \ + "testl %0,cpu_feature \n\ + je 2f \n\ + mfence \n\ +1: \n\ + .section .text.offpath \n\ +2: lock \n\ + addl $0,cpu_feature \n\ + jmp 1b \n\ + .text \n\ +" \ + : : "i"(CPUID_SSE2) : "memory") +#define wmb() __asm __volatile( \ + "testl %0,cpu_feature \n\ + je 2f \n\ + sfence \n\ +1: \n\ + .section .text.offpath \n\ +2: lock \n\ + addl $0,cpu_feature \n\ + jmp 1b \n\ + .text \n\ +" \ + : : "i"(CPUID_XMM) : "memory") +#define rmb() __asm __volatile( \ + "testl %0,cpu_feature \n\ + je 2f \n\ + lfence \n\ +1: \n\ + .section .text.offpath \n\ +2: lock \n\ + addl $0,cpu_feature \n\ + jmp 1b \n\ + .text \n\ +" \ + : : "i"(CPUID_SSE2) : "memory") #endif - /* * Various simple operations on memory, each of which is atomic in the * presence of interrupts and multiple processors. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 195 bytes Desc: not available Url : http://lists.freebsd.org/pipermail/svn-src-head/attachments/20081201/b038063e/attachment-0001.pgp From attilio at freebsd.org Mon Dec 1 14:22:23 2008 From: attilio at freebsd.org (Attilio Rao) Date: Mon Dec 1 14:22:58 2008 Subject: svn commit: r185162 - in head: . sys/amd64/include sys/arm/include sys/conf sys/dev/bce sys/dev/cxgb sys/dev/cxgb/sys sys/dev/cxgb/ulp/iw_cxgb sys/dev/mxge sys/dev/nxge sys/i386/include sys/i386/in... In-Reply-To: <200812011407.06563.jhb@freebsd.org> References: <200811220555.mAM5tuIJ007781@svn.freebsd.org> <3c1674c90811221651u338294frcdbd99b386733851@mail.gmail.com> <20081123154138.GS6408@deviant.kiev.zoral.com.ua> <200812011407.06563.jhb@freebsd.org> Message-ID: <3bbf2fe10812011422x27b007fdp13c5dbbb1cfb557e@mail.gmail.com> 2008/12/1, John Baldwin : > On Sunday 23 November 2008 10:41:38 am Kostik Belousov wrote: > > On Sun, Nov 23, 2008 at 12:51:58AM +0000, Kip Macy wrote: > > > On Sat, Nov 22, 2008 at 11:08 PM, Scott Long wrote: > > > > Kostik Belousov wrote: > > > >> > > > >> On Sat, Nov 22, 2008 at 03:05:22PM -0700, Scott Long wrote: > > > >>> > > > >>> A neat hack would be for the kernel linker to scan the text and do a > > > >>> drop-in replacement of the opcode that is appropriate for the > platform. > > > >>> I can't see how a CPU_XXX definition would work because it's just a > > > >>> compile time construct, one that can be included with any kernel > > > >>> compile. > > > >> > > > >> Yes, it is possible to do that. Less drastic change is to directly > > > >> check features. I moved slow code to separate section to eliminate > > > >> unconditional jump in fast path. > > > >> Only compile-tested. > > > >> > > > > > > > > As long as it works, I think it's a step in the right direction; I'm > > > > assuming that cpu_feature is a symbol filled in at runtime and not a > > > > macro for the cpuid instruction, right? > > > > > > > > Scott > > > > > > > > > > i386/include/md_var.h: > > > <..> > > > extern u_int cpu_exthigh; > > > extern u_int cpu_feature; > > > extern u_int cpu_feature2; > > > extern u_int amd_feature; > > > extern u_int amd_feature2; > > > <...> > > > > > > I'm not thrilled with it, but we can revisit the issue if it makes a > > > measurable difference on someone's workload. > > > > Below is the updated patch. It includes changes made after private comments > > by bde@ and uses symbolic definitions for the bits in the features words. > > I thought about accessing a per-CPU word for serialized instruction in the > > > slow path, but decided that it does not beneficial.\ > > Is the branch really better than just doing what the atomic operations for > mutexes, etc. do and just use 'lock addl $0,%esp' for a barrier in all cases > on i386 and only bother with using the fancier instructions on amd64? Even > amd64 doesn't use *fence yet for the atomic ops actually. I have had a patch > to use it for years, but during testing there was no discernable difference > between the existing 'lock addl' approach vs '*fence'. I'd much rather just > use 486 code for all i386 machines than add a branch, esp. if > the "optimization" the branch is doing isn't an actual optimization. This is exactly what I suggest in private and I'm supportive with this. Attilio -- Peace can only be achieved by understanding - A. Einstein From kan at FreeBSD.org Mon Dec 1 14:33:51 2008 From: kan at FreeBSD.org (Alexander Kabaev) Date: Mon Dec 1 14:34:03 2008 Subject: svn commit: r185533 - head/sys/kern Message-ID: <200812012233.mB1MXojv039186@svn.freebsd.org> Author: kan Date: Mon Dec 1 22:33:50 2008 New Revision: 185533 URL: http://svn.freebsd.org/changeset/base/185533 Log: Shared memory objects that have size which is not necessarily equal to exact multiple of system page size should still be allowed to be mapped in their entirety to match the regular vnode backed file behavior. Reported by: ed Reviewed by: jhb Modified: head/sys/kern/uipc_shm.c Modified: head/sys/kern/uipc_shm.c ============================================================================== --- head/sys/kern/uipc_shm.c Mon Dec 1 21:15:04 2008 (r185532) +++ head/sys/kern/uipc_shm.c Mon Dec 1 22:33:50 2008 (r185533) @@ -605,7 +605,8 @@ shm_mmap(struct shmfd *shmfd, vm_size_t * XXXRW: This validation is probably insufficient, and subject to * sign errors. It should be fixed. */ - if (foff >= shmfd->shm_size || foff + objsize > shmfd->shm_size) + if (foff >= shmfd->shm_size || + foff + objsize > round_page(shmfd->shm_size)) return (EINVAL); mtx_lock(&shm_timestamp_lock); From sam at FreeBSD.org Mon Dec 1 15:09:58 2008 From: sam at FreeBSD.org (Sam Leffler) Date: Mon Dec 1 15:10:10 2008 Subject: svn commit: r185534 - head Message-ID: <200812012309.mB1N9wBF039940@svn.freebsd.org> Author: sam Date: Mon Dec 1 23:09:58 2008 New Revision: 185534 URL: http://svn.freebsd.org/changeset/base/185534 Log: correct typo Submitted by: Ole Vole Modified: head/UPDATING Modified: head/UPDATING ============================================================================== --- head/UPDATING Mon Dec 1 22:33:50 2008 (r185533) +++ head/UPDATING Mon Dec 1 23:09:58 2008 (r185534) @@ -26,7 +26,7 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 8. __FreeBSD_version 800057 marks the switchover from the binary ath hal to source code. Users must add the line: - options ATH_SUPPORT_AR5416 + options AH_SUPPORT_AR5416 to their kernel config files when specifying: From kmacy at FreeBSD.org Mon Dec 1 16:39:51 2008 From: kmacy at FreeBSD.org (Kip Macy) Date: Mon Dec 1 16:40:02 2008 Subject: svn commit: r185535 - head/sys/dev/cxgb/sys Message-ID: <200812020039.mB20do9W041856@svn.freebsd.org> Author: kmacy Date: Tue Dec 2 00:39:50 2008 New Revision: 185535 URL: http://svn.freebsd.org/changeset/base/185535 Log: integrate use after free fixes from private branch Found by: kkenn@ Modified: head/sys/dev/cxgb/sys/uipc_mvec.c Modified: head/sys/dev/cxgb/sys/uipc_mvec.c ============================================================================== --- head/sys/dev/cxgb/sys/uipc_mvec.c Mon Dec 1 23:09:58 2008 (r185534) +++ head/sys/dev/cxgb/sys/uipc_mvec.c Tue Dec 2 00:39:50 2008 (r185535) @@ -1,6 +1,6 @@ /************************************************************************** * - * Copyright (c) 2007, Kip Macy kmacy@freebsd.org + * Copyright (c) 2007-2008, Kip Macy kmacy@freebsd.org * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -78,7 +78,6 @@ mi_init(void) return; else mi_inited++; - zone_miovec = uma_zcreate("MBUF IOVEC", MIOVBYTES, NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_MAXBUCKET); @@ -127,6 +126,8 @@ _mcl_collapse_mbuf(struct mbuf_iovec *mi mi->mi_tso_segsz = m->m_pkthdr.tso_segsz; #ifdef IFNET_MULTIQ mi->mi_rss_hash = m->m_pkthdr.rss_hash; + if(!SLIST_EMPTY(&m->m_pkthdr.tags)) + m_tag_delete_chain(m, NULL); #endif } if (m->m_type != MT_DATA) { @@ -147,13 +148,21 @@ _mcl_collapse_mbuf(struct mbuf_iovec *mi mi->mi_type = m->m_ext.ext_type; mi->mi_size = m->m_ext.ext_size; mi->mi_refcnt = m->m_ext.ref_cnt; - mi->mi_mbuf = m; + if (m->m_ext.ext_type == EXT_PACKET) { + mi->mi_mbuf = m; +#ifdef INVARIANTS + cxgb_pack_outstanding++; +#endif + } } else { mi->mi_base = (caddr_t)m; mi->mi_data = m->m_data; mi->mi_size = MSIZE; mi->mi_type = EXT_MBUF; mi->mi_refcnt = NULL; +#ifdef INVARIANTS + cxgb_mbufs_outstanding++; +#endif } KASSERT(mi->mi_len != 0, ("miov has len 0")); KASSERT(mi->mi_type > 0, ("mi_type is invalid")); @@ -193,15 +202,9 @@ busdma_map_sg_collapse(struct mbuf **m, struct mbuf *marray[TX_MAX_SEGS]; int i, type, seg_count, defragged = 0, err = 0; struct mbuf_vec *mv; - int skipped, freed, outstanding, pack_outstanding, mbuf_outstanding; - - + int skipped, freed; KASSERT(n->m_pkthdr.len, ("packet has zero header len")); - - if (n->m_flags & M_PKTHDR && !SLIST_EMPTY(&n->m_pkthdr.tags)) - m_tag_delete_chain(n, NULL); - if (n->m_pkthdr.len <= PIO_LEN) return (0); retry: @@ -209,14 +212,9 @@ retry: if (n->m_next == NULL) { busdma_map_mbuf_fast(n, segs); *nsegs = 1; - if ((n->m_flags & M_EXT) && - (n->m_ext.ext_type == EXT_PACKET)) - cxgb_pack_outstanding++; - else if ((n->m_flags & M_NOFREE) == 0) - cxgb_mbufs_outstanding++; return (0); } - skipped = freed = outstanding = pack_outstanding = mbuf_outstanding = 0; + skipped = freed = 0; while (n && seg_count < TX_MAX_SEGS) { marray[seg_count] = n; @@ -274,11 +272,9 @@ retry: if (n->m_len == 0) /* do nothing - free if mbuf or cluster */; else if ((n->m_flags & M_EXT) == 0) { - mbuf_outstanding++; goto skip; } else if ((n->m_flags & M_EXT) && (n->m_ext.ext_type == EXT_PACKET)) { - pack_outstanding++; goto skip; } else if (n->m_flags & M_NOFREE) goto skip; @@ -293,15 +289,11 @@ retry: /* * is an immediate mbuf or is from the packet zone */ - mhead = n->m_next; - n->m_next = NULL; - n = mhead; + n = n->m_next; } *nsegs = seg_count; *m = m0; DPRINTF("pktlen=%d m0=%p *m=%p m=%p\n", m0->m_pkthdr.len, m0, *m, m); - cxgb_mbufs_outstanding += mbuf_outstanding; - cxgb_pack_outstanding += pack_outstanding; return (0); err_out: m_freem(*m); @@ -310,41 +302,34 @@ err_out: } int -busdma_map_sg_vec(struct mbuf **m, struct mbuf **mret, bus_dma_segment_t *segs, int count) +busdma_map_sg_vec(struct mbuf **m, struct mbuf **mret, + bus_dma_segment_t *segs, int pkt_count) { struct mbuf *m0, **mp; struct mbuf_iovec *mi; struct mbuf_vec *mv; - int i; - - if (count > MAX_MIOVEC_IOV) { - if ((m0 = uma_zalloc_arg(zone_clust, NULL, M_NOWAIT)) == NULL) - return (ENOMEM); - m0->m_type = EXT_CLIOVEC; - } else { - if ((m0 = uma_zalloc_arg(zone_miovec, NULL, M_NOWAIT)) == NULL) - return (ENOMEM); - m0->m_type = EXT_IOVEC; - } + int i, type; + + if ((m0 = mcl_alloc(pkt_count, &type)) == NULL) + return (ENOMEM); - m0->m_flags = 0; - m0->m_pkthdr.len = m0->m_len = (*m)->m_len; /* not the real length but needs to be non-zero */ + memcpy(m0, *m, sizeof(struct m_hdr) + + sizeof(struct pkthdr)); + m0->m_type = type; mv = mtomv(m0); - mv->mv_count = count; + mv->mv_count = pkt_count; mv->mv_first = 0; - for (mp = m, i = 0, mi = mv->mv_vec; i < count; mp++, segs++, mi++, i++) { - if ((*mp)->m_flags & M_PKTHDR && !SLIST_EMPTY(&(*mp)->m_pkthdr.tags)) - m_tag_delete_chain(*mp, NULL); + for (mp = m, i = 0, mi = mv->mv_vec; i < pkt_count; + mp++, segs++, mi++, i++) { busdma_map_mbuf_fast(*mp, segs); _mcl_collapse_mbuf(mi, *mp); KASSERT(mi->mi_len, ("empty packet")); } - for (mp = m, i = 0; i < count; i++, mp++) { - (*mp)->m_next = (*mp)->m_nextpkt = NULL; - if (((*mp)->m_flags & (M_EXT|M_NOFREE)) == M_EXT) { + for (mp = m, i = 0; i < pkt_count; i++, mp++) { + if ((((*mp)->m_flags & (M_EXT|M_NOFREE)) == M_EXT) + && ((*mp)->m_ext.ext_type != EXT_PACKET)) { (*mp)->m_flags &= ~M_EXT; - cxgb_mbufs_outstanding--; m_free(*mp); } } @@ -359,17 +344,28 @@ mb_free_ext_fast(struct mbuf_iovec *mi, int dofree; caddr_t cl; - if (type == EXT_PACKET) { + cl = mi->mi_base; + switch (type) { + case EXT_PACKET: +#ifdef INVARIANTS cxgb_pack_outstanding--; +#endif m_free(mi->mi_mbuf); return; + case EXT_MBUF: + KASSERT((mi->mi_flags & M_NOFREE) == 0, ("no free set on mbuf")); +#ifdef INVARIANTS + cxgb_mbufs_outstanding--; +#endif + m_free_fast((struct mbuf *)cl); + return; + default: + break; } /* Account for lazy ref count assign. */ dofree = (mi->mi_refcnt == NULL); if (dofree == 0) { - KASSERT(mi->mi_type != EXT_MBUF, - ("refcnt must be null for mbuf")); if (*(mi->mi_refcnt) == 1 || atomic_fetchadd_int(mi->mi_refcnt, -1) == 1) dofree = 1; @@ -377,13 +373,7 @@ mb_free_ext_fast(struct mbuf_iovec *mi, if (dofree == 0) return; - cl = mi->mi_base; switch (type) { - case EXT_MBUF: - KASSERT((mi->mi_flags & M_NOFREE) == 0, ("no free set on mbuf")); - cxgb_mbufs_outstanding--; - m_free_fast((struct mbuf *)cl); - break; case EXT_CLUSTER: cxgb_cache_put(zone_clust, cl); break; From kmacy at FreeBSD.org Mon Dec 1 16:48:08 2008 From: kmacy at FreeBSD.org (Kip Macy) Date: Mon Dec 1 16:48:20 2008 Subject: svn commit: r185536 - head/sys/dev/cxgb/sys Message-ID: <200812020048.mB20m8Gw042049@svn.freebsd.org> Author: kmacy Date: Tue Dec 2 00:48:08 2008 New Revision: 185536 URL: http://svn.freebsd.org/changeset/base/185536 Log: - fix multiqueue conditional - don't leak mbuf tags in the non-conditional case Found by: Navdeep Parhar Modified: head/sys/dev/cxgb/sys/uipc_mvec.c Modified: head/sys/dev/cxgb/sys/uipc_mvec.c ============================================================================== --- head/sys/dev/cxgb/sys/uipc_mvec.c Tue Dec 2 00:39:50 2008 (r185535) +++ head/sys/dev/cxgb/sys/uipc_mvec.c Tue Dec 2 00:48:08 2008 (r185536) @@ -124,11 +124,11 @@ _mcl_collapse_mbuf(struct mbuf_iovec *mi if (m->m_flags & M_PKTHDR) { mi->mi_ether_vtag = m->m_pkthdr.ether_vtag; mi->mi_tso_segsz = m->m_pkthdr.tso_segsz; -#ifdef IFNET_MULTIQ +#ifdef IFNET_MULTIQUEUE mi->mi_rss_hash = m->m_pkthdr.rss_hash; +#endif if(!SLIST_EMPTY(&m->m_pkthdr.tags)) m_tag_delete_chain(m, NULL); -#endif } if (m->m_type != MT_DATA) { mi->mi_data = NULL; From kmacy at FreeBSD.org Mon Dec 1 16:51:56 2008 From: kmacy at FreeBSD.org (Kip Macy) Date: Mon Dec 1 16:52:05 2008 Subject: svn commit: r185537 - head/sys/dev/cxgb/sys Message-ID: <200812020051.mB20puVd042159@svn.freebsd.org> Author: kmacy Date: Tue Dec 2 00:51:56 2008 New Revision: 185537 URL: http://svn.freebsd.org/changeset/base/185537 Log: The pkthdr field is flowid not rss_hash Modified: head/sys/dev/cxgb/sys/uipc_mvec.c Modified: head/sys/dev/cxgb/sys/uipc_mvec.c ============================================================================== --- head/sys/dev/cxgb/sys/uipc_mvec.c Tue Dec 2 00:48:08 2008 (r185536) +++ head/sys/dev/cxgb/sys/uipc_mvec.c Tue Dec 2 00:51:56 2008 (r185537) @@ -125,7 +125,7 @@ _mcl_collapse_mbuf(struct mbuf_iovec *mi mi->mi_ether_vtag = m->m_pkthdr.ether_vtag; mi->mi_tso_segsz = m->m_pkthdr.tso_segsz; #ifdef IFNET_MULTIQUEUE - mi->mi_rss_hash = m->m_pkthdr.rss_hash; + mi->mi_rss_hash = m->m_pkthdr.flowid; #endif if(!SLIST_EMPTY(&m->m_pkthdr.tags)) m_tag_delete_chain(m, NULL); From yongari at FreeBSD.org Mon Dec 1 18:12:35 2008 From: yongari at FreeBSD.org (Pyun YongHyeon) Date: Mon Dec 1 18:12:51 2008 Subject: svn commit: r185538 - head/sys/dev/fxp Message-ID: <200812020212.mB22CY5e045211@svn.freebsd.org> Author: yongari Date: Tue Dec 2 02:12:34 2008 New Revision: 185538 URL: http://svn.freebsd.org/changeset/base/185538 Log: Make sure to clear PMDR register by writing back power management events. Just reading PMDR register was not enough to have fxp(4) immuninize against received magic packets during system boot. Tested by: Alexey Shuvaev < shuvaev <> physik DOT uni-wuerzburg DOT de > Modified: head/sys/dev/fxp/if_fxp.c Modified: head/sys/dev/fxp/if_fxp.c ============================================================================== --- head/sys/dev/fxp/if_fxp.c Tue Dec 2 00:51:56 2008 (r185537) +++ head/sys/dev/fxp/if_fxp.c Tue Dec 2 02:12:34 2008 (r185538) @@ -857,7 +857,7 @@ fxp_attach(device_t dev) if ((sc->flags & FXP_FLAG_WOLCAP) != 0) { FXP_LOCK(sc); /* Clear wakeup events. */ - CSR_READ_1(sc, FXP_CSR_PMDR); + CSR_WRITE_1(sc, FXP_CSR_PMDR, CSR_READ_1(sc, FXP_CSR_PMDR)); fxp_init_body(sc); fxp_stop(sc); FXP_UNLOCK(sc); @@ -1050,10 +1050,9 @@ fxp_resume(device_t dev) /* Disable PME and clear PME status. */ pmstat &= ~PCIM_PSTAT_PMEENABLE; pci_write_config(sc->dev, pmc + PCIR_POWER_STATUS, pmstat, 2); - if ((sc->flags & FXP_FLAG_WOLCAP) != 0) { - /* Clear wakeup events. */ - CSR_READ_1(sc, FXP_CSR_PMDR); - } + if ((sc->flags & FXP_FLAG_WOLCAP) != 0) + CSR_WRITE_1(sc, FXP_CSR_PMDR, + CSR_READ_1(sc, FXP_CSR_PMDR)); } CSR_WRITE_4(sc, FXP_CSR_PORT, FXP_PORT_SELECTIVE_RESET); From peter at FreeBSD.org Mon Dec 1 18:26:15 2008 From: peter at FreeBSD.org (Peter Wemm) Date: Mon Dec 1 18:26:22 2008 Subject: svn commit: r185539 - in head/sys: arm/at91 dev/mn kern security/mac security/mac_bsdextended Message-ID: <200812020226.mB22QFtl045542@svn.freebsd.org> Author: peter Date: Tue Dec 2 02:26:15 2008 New Revision: 185539 URL: http://svn.freebsd.org/changeset/base/185539 Log: Delete a bunch of empty mergeinfo records caused by local copies. Modified: head/sys/arm/at91/at91_machdep.c (props changed) head/sys/arm/at91/board_bwct.c (props changed) head/sys/arm/at91/board_hl200.c (props changed) head/sys/arm/at91/board_kb920x.c (props changed) head/sys/arm/at91/board_tsc4370.c (props changed) head/sys/arm/at91/std.bwct (props changed) head/sys/arm/at91/std.hl200 (props changed) head/sys/arm/at91/std.tsc4370 (props changed) head/sys/dev/mn/if_mn.c (props changed) head/sys/kern/kern_cons.c (props changed) head/sys/security/mac/mac_cred.c (props changed) head/sys/security/mac_bsdextended/ugidfw_system.c (props changed) head/sys/security/mac_bsdextended/ugidfw_vnode.c (props changed) From yongari at FreeBSD.org Mon Dec 1 18:30:13 2008 From: yongari at FreeBSD.org (Pyun YongHyeon) Date: Mon Dec 1 18:30:25 2008 Subject: svn commit: r185540 - head/sys/dev/fxp Message-ID: <200812020230.mB22UCUs045672@svn.freebsd.org> Author: yongari Date: Tue Dec 2 02:30:12 2008 New Revision: 185540 URL: http://svn.freebsd.org/changeset/base/185540 Log: Add VLAN hardware tag insertion/stripping support. Tx/Rx checksum offload for VLAN frames are also supported. The VLAN hardware assistance is available only on 82550/82551 based controllers. While I'm here change the confusing name of bit1 in byte 22 of configuration block to vlan_drop_en. The bit controls whether hardware strips VLAN tagged frame or not. Special thanks to wpaul who sent valuable VLAN related information to me. Tested on: i386, sparc64 Modified: head/sys/dev/fxp/if_fxp.c head/sys/dev/fxp/if_fxpreg.h Modified: head/sys/dev/fxp/if_fxp.c ============================================================================== --- head/sys/dev/fxp/if_fxp.c Tue Dec 2 02:26:15 2008 (r185539) +++ head/sys/dev/fxp/if_fxp.c Tue Dec 2 02:30:12 2008 (r185540) @@ -830,6 +830,12 @@ fxp_attach(device_t dev) ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header); ifp->if_capabilities |= IFCAP_VLAN_MTU; ifp->if_capenable |= IFCAP_VLAN_MTU; /* the hw bits already set */ + if ((sc->flags & FXP_FLAG_EXT_RFA) != 0) { + ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING | + IFCAP_VLAN_HWCSUM; + ifp->if_capenable |= IFCAP_VLAN_HWTAGGING | + IFCAP_VLAN_HWCSUM; + } /* * Let the system queue as many packets as we have available @@ -1554,6 +1560,12 @@ fxp_encap(struct fxp_softc *sc, struct m FXP_IPCB_TCP_PACKET | FXP_IPCB_TCPUDP_CHECKSUM_ENABLE; } + /* Configure VLAN hardware tag insertion. */ + if ((m->m_flags & M_VLANTAG) != 0) { + cbp->ipcb_vlan_id = htons(m->m_pkthdr.ether_vtag); + txp->tx_cb->ipcb_ip_activation_high |= + FXP_IPCB_INSERTVLAN_ENABLE; + } txp->tx_mbuf = m; txp->tx_cb->cb_status = 0; @@ -1913,6 +1925,12 @@ fxp_intr_body(struct fxp_softc *sc, stru /* Do IP checksum checking. */ if ((ifp->if_capenable & IFCAP_RXCSUM) != 0) fxp_rxcsum(sc, ifp, m, status, total_len); + if ((ifp->if_capenable & IFCAP_VLAN_HWTAGGING) != 0 && + (status & FXP_RFA_STATUS_VLAN) != 0) { + m->m_pkthdr.ether_vtag = + ntohs(rfa->rfax_vlan_id); + m->m_flags |= M_VLANTAG; + } /* * Drop locks before calling if_input() since it * may re-enter fxp_start() in the netisr case. @@ -2284,6 +2302,8 @@ fxp_init_body(struct fxp_softc *sc) cbp->multi_ia = 0; /* (don't) accept multiple IAs */ cbp->mc_all = sc->flags & FXP_FLAG_ALL_MCAST ? 1 : 0; cbp->gamla_rx = sc->flags & FXP_FLAG_EXT_RFA ? 1 : 0; + cbp->vlan_strip_en = ((sc->flags & FXP_FLAG_EXT_RFA) != 0 && + (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) != 0) ? 1 : 0; if (sc->tunable_noflow || sc->revision == FXP_REV_82557) { /* @@ -2763,9 +2783,15 @@ fxp_ioctl(struct ifnet *ifp, u_long comm if (ifp->if_flags & IFF_UP) reinit++; } - if (reinit > 0) + if ((mask & IFCAP_VLAN_HWTAGGING) != 0 && + (ifp->if_capabilities & IFCAP_VLAN_HWTAGGING) != 0) { + ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING; + reinit++; + } + if (reinit > 0 && ifp->if_flags & IFF_UP) fxp_init_body(sc); FXP_UNLOCK(sc); + VLAN_CAPABILITIES(ifp); break; default: Modified: head/sys/dev/fxp/if_fxpreg.h ============================================================================== --- head/sys/dev/fxp/if_fxpreg.h Tue Dec 2 02:26:15 2008 (r185539) +++ head/sys/dev/fxp/if_fxpreg.h Tue Dec 2 02:30:12 2008 (r185540) @@ -224,7 +224,7 @@ struct fxp_cb_config { /* Bytes 22 - 31 -- i82550 only */ u_int __FXP_BITFIELD3(gamla_rx:1, - vlan_drop_en:1, + vlan_strip_en:1, :6); uint8_t pad[9]; }; @@ -377,6 +377,7 @@ struct fxp_rfa { #define FXP_RFA_STATUS_RNR 0x0200 /* no resources */ #define FXP_RFA_STATUS_ALIGN 0x0400 /* alignment error */ #define FXP_RFA_STATUS_CRC 0x0800 /* CRC error */ +#define FXP_RFA_STATUS_VLAN 0x1000 /* VLAN tagged frame */ #define FXP_RFA_STATUS_OK 0x2000 /* packet received okay */ #define FXP_RFA_STATUS_C 0x8000 /* packet reception complete */ #define FXP_RFA_CONTROL_SF 0x08 /* simple/flexible memory mode */ From yongari at FreeBSD.org Mon Dec 1 19:39:35 2008 From: yongari at FreeBSD.org (Pyun YongHyeon) Date: Mon Dec 1 19:39:42 2008 Subject: svn commit: r185542 - in head/sys: dev/re pci Message-ID: <200812020339.mB23dZvD047351@svn.freebsd.org> Author: yongari Date: Tue Dec 2 03:39:34 2008 New Revision: 185542 URL: http://svn.freebsd.org/changeset/base/185542 Log: Add 8168D support. Submitted by: Andrew < andrewwtulloch <> gmail DOT com > Modified: head/sys/dev/re/if_re.c head/sys/pci/if_rlreg.h Modified: head/sys/dev/re/if_re.c ============================================================================== --- head/sys/dev/re/if_re.c Tue Dec 2 02:32:13 2008 (r185541) +++ head/sys/dev/re/if_re.c Tue Dec 2 03:39:34 2008 (r185542) @@ -172,7 +172,7 @@ static struct rl_type re_devs[] = { { RT_VENDORID, RT_DEVICEID_8101E, 0, "RealTek 8101E/8102E/8102EL PCIe 10/100baseTX" }, { RT_VENDORID, RT_DEVICEID_8168, 0, - "RealTek 8168/8168B/8168C/8168CP/8111B/8111C/8111CP PCIe " + "RealTek 8168/8168B/8168C/8168CP/8168D/8111B/8111C/8111CP PCIe " "Gigabit Ethernet" }, { RT_VENDORID, RT_DEVICEID_8169, 0, "RealTek 8169/8169S/8169SB(L)/8110S/8110SB(L) Gigabit Ethernet" }, @@ -213,6 +213,7 @@ static struct rl_hwrev re_hwrevs[] = { { RL_HWREV_8168C, RL_8169, "8168C/8111C"}, { RL_HWREV_8168C_SPIN2, RL_8169, "8168C/8111C"}, { RL_HWREV_8168CP, RL_8169, "8168CP/8111CP"}, + { RL_HWREV_8168D, RL_8169, "8168D"}, { 0, 0, NULL } }; @@ -1225,6 +1226,7 @@ re_attach(device_t dev) case RL_HWREV_8168C: case RL_HWREV_8168C_SPIN2: case RL_HWREV_8168CP: + case RL_HWREV_8168D: sc->rl_flags |= RL_FLAG_INVMAR | RL_FLAG_PHYWAKE | RL_FLAG_PAR | RL_FLAG_DESCV2 | RL_FLAG_MACSTAT; /* Modified: head/sys/pci/if_rlreg.h ============================================================================== --- head/sys/pci/if_rlreg.h Tue Dec 2 02:32:13 2008 (r185541) +++ head/sys/pci/if_rlreg.h Tue Dec 2 03:39:34 2008 (r185542) @@ -157,6 +157,7 @@ #define RL_HWREV_8169_8110SB 0x10000000 #define RL_HWREV_8169_8110SC 0x18000000 #define RL_HWREV_8102EL 0x24800000 +#define RL_HWREV_8168D 0x28000000 #define RL_HWREV_8168_SPIN1 0x30000000 #define RL_HWREV_8100E 0x30800000 #define RL_HWREV_8101E 0x34000000 From kmacy at FreeBSD.org Mon Dec 1 19:58:10 2008 From: kmacy at FreeBSD.org (Kip Macy) Date: Mon Dec 1 19:58:22 2008 Subject: svn commit: r185543 - head/sys/sys Message-ID: <200812020358.mB23wAtL047722@svn.freebsd.org> Author: kmacy Date: Tue Dec 2 03:58:10 2008 New Revision: 185543 URL: http://svn.freebsd.org/changeset/base/185543 Log: return ENOBUFS when ring is full Modified: head/sys/sys/buf_ring.h Modified: head/sys/sys/buf_ring.h ============================================================================== --- head/sys/sys/buf_ring.h Tue Dec 2 03:39:34 2008 (r185542) +++ head/sys/sys/buf_ring.h Tue Dec 2 03:58:10 2008 (r185543) @@ -92,7 +92,7 @@ buf_ring_enqueue(struct buf_ring *br, vo if (prod_next == cons_tail) { critical_exit(); - return (ENOSPC); + return (ENOBUFS); } success = atomic_cmpset_int(&br->br_prod_head, prod_head, From ps at FreeBSD.org Mon Dec 1 20:45:34 2008 From: ps at FreeBSD.org (Paul Saab) Date: Mon Dec 1 20:45:45 2008 Subject: svn commit: r185544 - head/sys/modules/ae Message-ID: <200812020445.mB24jXaS048636@svn.freebsd.org> Author: ps Date: Tue Dec 2 04:45:33 2008 New Revision: 185544 URL: http://svn.freebsd.org/changeset/base/185544 Log: Fix world by including opt_route.h Modified: head/sys/modules/ae/Makefile Modified: head/sys/modules/ae/Makefile ============================================================================== --- head/sys/modules/ae/Makefile Tue Dec 2 03:58:10 2008 (r185543) +++ head/sys/modules/ae/Makefile Tue Dec 2 04:45:33 2008 (r185544) @@ -3,6 +3,6 @@ .PATH: ${.CURDIR}/../../dev/ae KMOD= if_ae -SRCS= if_ae.c device_if.h bus_if.h pci_if.h miibus_if.h +SRCS= if_ae.c device_if.h bus_if.h pci_if.h miibus_if.h opt_route.h .include From imp at FreeBSD.org Mon Dec 1 20:54:31 2008 From: imp at FreeBSD.org (Warner Losh) Date: Mon Dec 1 20:54:42 2008 Subject: svn commit: r185545 - head/sys/dev/cardbus Message-ID: <200812020454.mB24sVNd048874@svn.freebsd.org> Author: imp Date: Tue Dec 2 04:54:31 2008 New Revision: 185545 URL: http://svn.freebsd.org/changeset/base/185545 Log: Don't call destroy_dev on the alias. This fixes half a dozen PRs I think. Modified: head/sys/dev/cardbus/cardbus_device.c head/sys/dev/cardbus/cardbusvar.h Modified: head/sys/dev/cardbus/cardbus_device.c ============================================================================== --- head/sys/dev/cardbus/cardbus_device.c Tue Dec 2 04:45:33 2008 (r185544) +++ head/sys/dev/cardbus/cardbus_device.c Tue Dec 2 04:54:31 2008 (r185545) @@ -112,15 +112,15 @@ cardbus_device_create(struct cardbus_sof device_t parent, device_t child) { uint32_t minor; + int unit; cardbus_device_buffer_cis(parent, child, &devi->sc_cis); minor = (device_get_unit(sc->sc_dev) << 8) + devi->pci.cfg.func; + unit = device_get_unit(sc->sc_dev); devi->sc_cisdev = make_dev(&cardbus_cdevsw, minor, 0, 0, 0666, - "cardbus%d.%d.cis", device_get_unit(sc->sc_dev), - devi->pci.cfg.func); + "cardbus%d.%d.cis", unit, devi->pci.cfg.func); if (devi->pci.cfg.func == 0) - devi->sc_cisdev_compat = make_dev_alias(devi->sc_cisdev, - "cardbus%d.cis", device_get_unit(sc->sc_dev)); + make_dev_alias(devi->sc_cisdev, "cardbus%d.cis", unit); devi->sc_cisdev->si_drv1 = devi; return (0); } @@ -130,8 +130,6 @@ cardbus_device_destroy(struct cardbus_de { if (devi->sc_cisdev) destroy_dev(devi->sc_cisdev); - if (devi->sc_cisdev_compat) - destroy_dev(devi->sc_cisdev_compat); return (0); } Modified: head/sys/dev/cardbus/cardbusvar.h ============================================================================== --- head/sys/dev/cardbus/cardbusvar.h Tue Dec 2 04:45:33 2008 (r185544) +++ head/sys/dev/cardbus/cardbusvar.h Tue Dec 2 04:54:31 2008 (r185545) @@ -60,7 +60,6 @@ struct cardbus_devinfo } funce; uint32_t fepresent; /* bit mask of funce values present */ struct cdev *sc_cisdev; - struct cdev *sc_cisdev_compat; struct cis_buffer sc_cis; }; From imp at bsdimp.com Mon Dec 1 21:05:56 2008 From: imp at bsdimp.com (M. Warner Losh) Date: Mon Dec 1 21:06:01 2008 Subject: svn commit: r185499 - head In-Reply-To: <20081201132554.GD27096@elvis.mu.org> References: <49338E98.7020104@freebsd.org> <863ah8rvcd.fsf@ds4.des.no> <20081201132554.GD27096@elvis.mu.org> Message-ID: <20081201.220256.-399281305.imp@bsdimp.com> I thought the consensus was for universe to build *ALL* targets and then fail if ONE or MORE of the targets failed. I thought there was no consensus at all for a new target. Warner From imp at bsdimp.com Mon Dec 1 21:09:33 2008 From: imp at bsdimp.com (M. Warner Losh) Date: Mon Dec 1 21:09:45 2008 Subject: svn commit: r185539 - in head/sys: arm/at91 dev/mn kern security/mac security/mac_bsdextended In-Reply-To: <200812020226.mB22QFtl045542@svn.freebsd.org> References: <200812020226.mB22QFtl045542@svn.freebsd.org> Message-ID: <20081201.220808.1649770636.imp@bsdimp.com> In message: <200812020226.mB22QFtl045542@svn.freebsd.org> Peter Wemm writes: : Author: peter : Date: Tue Dec 2 02:26:15 2008 : New Revision: 185539 : URL: http://svn.freebsd.org/changeset/base/185539 : : Log: : Delete a bunch of empty mergeinfo records caused by local copies. : : Modified: : head/sys/arm/at91/at91_machdep.c (props changed) : head/sys/arm/at91/board_bwct.c (props changed) : head/sys/arm/at91/board_hl200.c (props changed) : head/sys/arm/at91/board_kb920x.c (props changed) : head/sys/arm/at91/board_tsc4370.c (props changed) : head/sys/arm/at91/std.bwct (props changed) : head/sys/arm/at91/std.hl200 (props changed) : head/sys/arm/at91/std.tsc4370 (props changed) : head/sys/dev/mn/if_mn.c (props changed) : head/sys/kern/kern_cons.c (props changed) : head/sys/security/mac/mac_cred.c (props changed) : head/sys/security/mac_bsdextended/ugidfw_system.c (props changed) : head/sys/security/mac_bsdextended/ugidfw_vnode.c (props changed) Is there some way the developer that does the copies can do this so you don't need to do this? Warner From imp at bsdimp.com Mon Dec 1 21:12:01 2008 From: imp at bsdimp.com (M. Warner Losh) Date: Mon Dec 1 21:12:09 2008 Subject: svn commit: r185499 - head In-Reply-To: <20081201132554.GD27096@elvis.mu.org> References: <49338E98.7020104@freebsd.org> <863ah8rvcd.fsf@ds4.des.no> <20081201132554.GD27096@elvis.mu.org> Message-ID: <20081201.221040.-1350500631.imp@bsdimp.com> In message: <20081201132554.GD27096@elvis.mu.org> Alfred Perlstein writes: : * Dag-Erling Sm??rgrav [081201 03:25] wrote: : > Tim Kientzle writes: : > > Alfred Perlstein writes: : > > > Log: : > > > Provide a 'tinderbox' target that compiles enough of FreeBSD that : > > > a developer can rest reasonably assured that the tinderbox will not : > > > be broken. This target leverages most of 'universe' but will exit : > > > non-zero and output a summary at the end. : > > > "make tinderbox" : > > Excellent! : > : > I really don't see the point, especially now that 'make universe' will : > issue a warning on stdout for every build that fails. As I've tried to : > explain to Alfred, the tinderbox does nothing magical, and nothing that : > isn't already covered by 'make universe'. I also asked him to discuss : > any changes with Poul-Henning before committing them. : : I'll summarize the changes here: : : Problems with make universe: : 1) Make universe returns success on failure. : 2) Make universe outputs the following on failure: : -------------------------------------------------------------- : make universe completed on `LC_ALL=C date`" : (started ${STARTTIME})" : -------------------------------------------------------------- : : This basically means you can't chain 'make universe' into something : like "make tinderbox || (echo oops | mail -s tinderbox failed...)". : : The summary at the end "completed" is very misleading. : : The tinderbox target differs as follows: : : It returns an error if it fails. : It outputs a summary of the failures at the end. : The name reflects what its for. ("what the heck is a universe?") : : : If you strongly believe that a target should return "true" on failure : and/or output "i worked" on failure then I'm not sure how to approach : that mindset, maybe you can help me understand where you're coming from : on that? Where is the utility in it? Is there something I'm missing? I think you ignored the discussions that said that 'universe' should be modified to exit with an error when there was an error, but shouldn't bail out EARLY. There were even patches to do this. Based on that, why do something completely new and different? Warner From bzeeb-lists at lists.zabbadoz.net Mon Dec 1 22:50:08 2008 From: bzeeb-lists at lists.zabbadoz.net (Bjoern A. Zeeb) Date: Mon Dec 1 22:50:19 2008 Subject: svn commit: r185544 - head/sys/modules/ae In-Reply-To: <200812020445.mB24jXaS048636@svn.freebsd.org> References: <200812020445.mB24jXaS048636@svn.freebsd.org> Message-ID: <20081202064345.S80401@maildrop.int.zabbadoz.net> On Tue, 2 Dec 2008, Paul Saab wrote: > Author: ps > Date: Tue Dec 2 04:45:33 2008 > New Revision: 185544 > URL: http://svn.freebsd.org/changeset/base/185544 > > Log: > Fix world by including opt_route.h Where did world fail for you? I assume what failed was a single direct module build? Per discussion on current@ we are working on this but it's a long list of files with awkward dependencies to go through. If that was the only problem, the manual module build, please let me know so I can back this out again as soon as the vimage header files are untangled. > Modified: > head/sys/modules/ae/Makefile > > Modified: head/sys/modules/ae/Makefile > ============================================================================== > --- head/sys/modules/ae/Makefile Tue Dec 2 03:58:10 2008 (r185543) > +++ head/sys/modules/ae/Makefile Tue Dec 2 04:45:33 2008 (r185544) > @@ -3,6 +3,6 @@ > .PATH: ${.CURDIR}/../../dev/ae > > KMOD= if_ae > -SRCS= if_ae.c device_if.h bus_if.h pci_if.h miibus_if.h > +SRCS= if_ae.c device_if.h bus_if.h pci_if.h miibus_if.h opt_route.h > > .include > -- Bjoern A. Zeeb Stop bit received. Insert coin for new game. From peter at FreeBSD.org Mon Dec 1 22:50:27 2008 From: peter at FreeBSD.org (Peter Wemm) Date: Mon Dec 1 22:50:33 2008 Subject: svn commit: r185548 - in head: lib/libutil sys sys/contrib/pf sys/kern sys/sys usr.bin/procstat Message-ID: <200812020650.mB26oQVx051423@svn.freebsd.org> Author: peter Date: Tue Dec 2 06:50:26 2008 New Revision: 185548 URL: http://svn.freebsd.org/changeset/base/185548 Log: Merge user/peter/kinfo branch as of r185547 into head. This changes struct kinfo_filedesc and kinfo_vmentry such that they are same on both 32 and 64 bit platforms like i386/amd64 and won't require sysctl wrapping. Two new OIDs are assigned. The old ones are available under COMPAT_FREEBSD7 - but it isn't that simple. The superceded interface was never actually released on 7.x. The other main change is to pack the data passed to userland via the sysctl. kf_structsize and kve_structsize are reduced for the copyout. If you have a process with 100,000+ sockets open, the unpacked records require a 132MB+ copyout. With packing, it is "only" ~35MB. (Still seriously unpleasant, but not quite as devastating). A similar problem exists for the vmentry structure - have lots and lots of shared libraries and small mmaps and its copyout gets expensive too. My immediate problem is valgrind. It traditionally achieves this functionality by parsing procfs output, in a packed format. Secondly, when tracing 32 bit binaries on amd64 under valgrind, it uses a cross compiled 32 bit binary which ran directly into the differing data structures in 32 vs 64 bit mode. (valgrind uses this to track file descriptor operations and this therefore affected every single 32 bit binary) I've added two utility functions to libutil to unpack the structures into a fixed record length and to make it a little more convenient to use. Added: head/lib/libutil/kinfo_getfile.c - copied unchanged from r185545, user/peter/kinfo/lib/libutil/kinfo_getfile.c head/lib/libutil/kinfo_getvmmap.c - copied unchanged from r185545, user/peter/kinfo/lib/libutil/kinfo_getvmmap.c Modified: head/lib/libutil/ (props changed) head/lib/libutil/Makefile head/lib/libutil/libutil.h head/sys/ (props changed) head/sys/contrib/pf/ (props changed) head/sys/kern/kern_descrip.c head/sys/kern/kern_proc.c head/sys/sys/sysctl.h head/sys/sys/user.h head/usr.bin/procstat/ (props changed) head/usr.bin/procstat/Makefile head/usr.bin/procstat/procstat_files.c head/usr.bin/procstat/procstat_vm.c Modified: head/lib/libutil/Makefile ============================================================================== --- head/lib/libutil/Makefile Tue Dec 2 06:34:08 2008 (r185547) +++ head/lib/libutil/Makefile Tue Dec 2 06:50:26 2008 (r185548) @@ -9,7 +9,8 @@ LIB= util SHLIB_MAJOR= 7 SRCS= _secure_path.c auth.c expand_number.c flopen.c fparseln.c gr_util.c \ - hexdump.c humanize_number.c kld.c login.c login_auth.c login_cap.c \ + hexdump.c humanize_number.c kinfo_getfile.c kinfo_getvmmap.c kld.c \ + login.c login_auth.c login_cap.c \ login_class.c login_crypt.c login_ok.c login_times.c login_tty.c \ logout.c logwtmp.c pidfile.c property.c pty.c pw_util.c realhostname.c \ stub.c trimdomain.c uucplock.c Copied: head/lib/libutil/kinfo_getfile.c (from r185545, user/peter/kinfo/lib/libutil/kinfo_getfile.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libutil/kinfo_getfile.c Tue Dec 2 06:50:26 2008 (r185548, copy of r185545, user/peter/kinfo/lib/libutil/kinfo_getfile.c) @@ -0,0 +1,72 @@ +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include + +#include "libutil.h" + +struct kinfo_file * +kinfo_getfile(pid_t pid, int *cntp) +{ + int mib[4]; + int error; + int cnt; + size_t len; + char *buf, *bp, *eb; + struct kinfo_file *kif, *kp, *kf; + + len = 0; + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_FILEDESC; + mib[3] = pid; + + error = sysctl(mib, 4, NULL, &len, NULL, 0); + if (error) + return (0); + len = len * 4 / 3; + buf = malloc(len); + if (buf == NULL) + return (0); + error = sysctl(mib, 4, buf, &len, NULL, 0); + if (error) { + free(buf); + return (0); + } + /* Pass 1: count items */ + cnt = 0; + bp = buf; + eb = buf + len; + while (bp < eb) { + kf = (struct kinfo_file *)bp; + bp += kf->kf_structsize; + cnt++; + } + + kif = calloc(cnt, sizeof(*kif)); + if (kif == NULL) { + free(buf); + return (0); + } + bp = buf; + eb = buf + len; + kp = kif; + /* Pass 2: unpack */ + while (bp < eb) { + kf = (struct kinfo_file *)bp; + /* Copy/expand into pre-zeroed buffer */ + memcpy(kp, kf, kf->kf_structsize); + /* Advance to next packed record */ + bp += kf->kf_structsize; + /* Set field size to fixed length, advance */ + kp->kf_structsize = sizeof(*kp); + kp++; + } + free(buf); + *cntp = cnt; + return (kif); /* Caller must free() return value */ +} Copied: head/lib/libutil/kinfo_getvmmap.c (from r185545, user/peter/kinfo/lib/libutil/kinfo_getvmmap.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libutil/kinfo_getvmmap.c Tue Dec 2 06:50:26 2008 (r185548, copy of r185545, user/peter/kinfo/lib/libutil/kinfo_getvmmap.c) @@ -0,0 +1,72 @@ +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include + +#include "libutil.h" + +struct kinfo_vmentry * +kinfo_getvmmap(pid_t pid, int *cntp) +{ + int mib[4]; + int error; + int cnt; + size_t len; + char *buf, *bp, *eb; + struct kinfo_vmentry *kiv, *kp, *kv; + + len = 0; + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_VMMAP; + mib[3] = pid; + + error = sysctl(mib, 4, NULL, &len, NULL, 0); + if (error) + return (0); + len = len * 4 / 3; + buf = malloc(len); + if (buf == NULL) + return (0); + error = sysctl(mib, 4, buf, &len, NULL, 0); + if (error) { + free(buf); + return (0); + } + /* Pass 1: count items */ + cnt = 0; + bp = buf; + eb = buf + len; + while (bp < eb) { + kv = (struct kinfo_vmentry *)bp; + bp += kv->kve_structsize; + cnt++; + } + + kiv = calloc(cnt, sizeof(*kiv)); + if (kiv == NULL) { + free(buf); + return (0); + } + bp = buf; + eb = buf + len; + kp = kiv; + /* Pass 2: unpack */ + while (bp < eb) { + kv = (struct kinfo_vmentry *)bp; + /* Copy/expand into pre-zeroed buffer */ + memcpy(kp, kv, kv->kve_structsize); + /* Advance to next packed record */ + bp += kv->kve_structsize; + /* Set field size to fixed length, advance */ + kp->kve_structsize = sizeof(*kp); + kp++; + } + free(buf); + *cntp = cnt; + return (kiv); /* Caller must free() return value */ +} Modified: head/lib/libutil/libutil.h ============================================================================== --- head/lib/libutil/libutil.h Tue Dec 2 06:34:08 2008 (r185547) +++ head/lib/libutil/libutil.h Tue Dec 2 06:50:26 2008 (r185548) @@ -64,6 +64,8 @@ struct termios; struct winsize; struct utmp; struct in_addr; +struct kinfo_file; +struct kinfo_vmentry; __BEGIN_DECLS void clean_environment(const char * const *_white, @@ -100,6 +102,10 @@ int realhostname_sa(char *host, size_t h int kld_isloaded(const char *name); int kld_load(const char *name); +struct kinfo_file * + kinfo_getfile(pid_t _pid, int *_cntp); +struct kinfo_vmentry * + kinfo_getvmmap(pid_t _pid, int *_cntp); #ifdef _STDIO_H_ /* avoid adding new includes */ char *fparseln(FILE *, size_t *, size_t *, const char[3], int); Modified: head/sys/kern/kern_descrip.c ============================================================================== --- head/sys/kern/kern_descrip.c Tue Dec 2 06:34:08 2008 (r185547) +++ head/sys/kern/kern_descrip.c Tue Dec 2 06:50:26 2008 (r185548) @@ -2509,6 +2509,259 @@ sysctl_kern_file(SYSCTL_HANDLER_ARGS) SYSCTL_PROC(_kern, KERN_FILE, file, CTLTYPE_OPAQUE|CTLFLAG_RD, 0, 0, sysctl_kern_file, "S,xfile", "Entire file table"); +#ifdef KINFO_OFILE_SIZE +CTASSERT(sizeof(struct kinfo_ofile) == KINFO_OFILE_SIZE); +#endif + +#ifdef COMPAT_FREEBSD7 +static int +export_vnode_for_osysctl(struct vnode *vp, int type, + struct kinfo_ofile *kif, struct filedesc *fdp, struct sysctl_req *req) +{ + int error; + char *fullpath, *freepath; + int vfslocked; + + bzero(kif, sizeof(*kif)); + kif->kf_structsize = sizeof(*kif); + + vref(vp); + kif->kf_fd = type; + kif->kf_type = KF_TYPE_VNODE; + /* This function only handles directories. */ + KASSERT(vp->v_type == VDIR, ("export_vnode_for_osysctl: vnode not directory")); + kif->kf_vnode_type = KF_VTYPE_VDIR; + + /* + * This is not a true file descriptor, so we set a bogus refcount + * and offset to indicate these fields should be ignored. + */ + kif->kf_ref_count = -1; + kif->kf_offset = -1; + + freepath = NULL; + fullpath = "-"; + FILEDESC_SUNLOCK(fdp); + vn_fullpath(curthread, vp, &fullpath, &freepath); + vfslocked = VFS_LOCK_GIANT(vp->v_mount); + vrele(vp); + VFS_UNLOCK_GIANT(vfslocked); + strlcpy(kif->kf_path, fullpath, sizeof(kif->kf_path)); + if (freepath != NULL) + free(freepath, M_TEMP); + error = SYSCTL_OUT(req, kif, sizeof(*kif)); + FILEDESC_SLOCK(fdp); + return (error); +} + +/* + * Get per-process file descriptors for use by procstat(1), et al. + */ +static int +sysctl_kern_proc_ofiledesc(SYSCTL_HANDLER_ARGS) +{ + char *fullpath, *freepath; + struct kinfo_ofile *kif; + struct filedesc *fdp; + int error, i, *name; + struct socket *so; + struct vnode *vp; + struct file *fp; + struct proc *p; + struct tty *tp; + int vfslocked; + + name = (int *)arg1; + if ((p = pfind((pid_t)name[0])) == NULL) + return (ESRCH); + if ((error = p_candebug(curthread, p))) { + PROC_UNLOCK(p); + return (error); + } + fdp = fdhold(p); + PROC_UNLOCK(p); + if (fdp == NULL) + return (ENOENT); + kif = malloc(sizeof(*kif), M_TEMP, M_WAITOK); + FILEDESC_SLOCK(fdp); + if (fdp->fd_cdir != NULL) + export_vnode_for_osysctl(fdp->fd_cdir, KF_FD_TYPE_CWD, kif, + fdp, req); + if (fdp->fd_rdir != NULL) + export_vnode_for_osysctl(fdp->fd_rdir, KF_FD_TYPE_ROOT, kif, + fdp, req); + if (fdp->fd_jdir != NULL) + export_vnode_for_osysctl(fdp->fd_jdir, KF_FD_TYPE_JAIL, kif, + fdp, req); + for (i = 0; i < fdp->fd_nfiles; i++) { + if ((fp = fdp->fd_ofiles[i]) == NULL) + continue; + bzero(kif, sizeof(*kif)); + kif->kf_structsize = sizeof(*kif); + vp = NULL; + so = NULL; + tp = NULL; + kif->kf_fd = i; + switch (fp->f_type) { + case DTYPE_VNODE: + kif->kf_type = KF_TYPE_VNODE; + vp = fp->f_vnode; + break; + + case DTYPE_SOCKET: + kif->kf_type = KF_TYPE_SOCKET; + so = fp->f_data; + break; + + case DTYPE_PIPE: + kif->kf_type = KF_TYPE_PIPE; + break; + + case DTYPE_FIFO: + kif->kf_type = KF_TYPE_FIFO; + vp = fp->f_vnode; + vref(vp); + break; + + case DTYPE_KQUEUE: + kif->kf_type = KF_TYPE_KQUEUE; + break; + + case DTYPE_CRYPTO: + kif->kf_type = KF_TYPE_CRYPTO; + break; + + case DTYPE_MQUEUE: + kif->kf_type = KF_TYPE_MQUEUE; + break; + + case DTYPE_SHM: + kif->kf_type = KF_TYPE_SHM; + break; + + case DTYPE_SEM: + kif->kf_type = KF_TYPE_SEM; + break; + + case DTYPE_PTS: + kif->kf_type = KF_TYPE_PTS; + tp = fp->f_data; + break; + + default: + kif->kf_type = KF_TYPE_UNKNOWN; + break; + } + kif->kf_ref_count = fp->f_count; + if (fp->f_flag & FREAD) + kif->kf_flags |= KF_FLAG_READ; + if (fp->f_flag & FWRITE) + kif->kf_flags |= KF_FLAG_WRITE; + if (fp->f_flag & FAPPEND) + kif->kf_flags |= KF_FLAG_APPEND; + if (fp->f_flag & FASYNC) + kif->kf_flags |= KF_FLAG_ASYNC; + if (fp->f_flag & FFSYNC) + kif->kf_flags |= KF_FLAG_FSYNC; + if (fp->f_flag & FNONBLOCK) + kif->kf_flags |= KF_FLAG_NONBLOCK; + if (fp->f_flag & O_DIRECT) + kif->kf_flags |= KF_FLAG_DIRECT; + if (fp->f_flag & FHASLOCK) + kif->kf_flags |= KF_FLAG_HASLOCK; + kif->kf_offset = fp->f_offset; + if (vp != NULL) { + vref(vp); + switch (vp->v_type) { + case VNON: + kif->kf_vnode_type = KF_VTYPE_VNON; + break; + case VREG: + kif->kf_vnode_type = KF_VTYPE_VREG; + break; + case VDIR: + kif->kf_vnode_type = KF_VTYPE_VDIR; + break; + case VBLK: + kif->kf_vnode_type = KF_VTYPE_VBLK; + break; + case VCHR: + kif->kf_vnode_type = KF_VTYPE_VCHR; + break; + case VLNK: + kif->kf_vnode_type = KF_VTYPE_VLNK; + break; + case VSOCK: + kif->kf_vnode_type = KF_VTYPE_VSOCK; + break; + case VFIFO: + kif->kf_vnode_type = KF_VTYPE_VFIFO; + break; + case VBAD: + kif->kf_vnode_type = KF_VTYPE_VBAD; + break; + default: + kif->kf_vnode_type = KF_VTYPE_UNKNOWN; + break; + } + /* + * It is OK to drop the filedesc lock here as we will + * re-validate and re-evaluate its properties when + * the loop continues. + */ + freepath = NULL; + fullpath = "-"; + FILEDESC_SUNLOCK(fdp); + vn_fullpath(curthread, vp, &fullpath, &freepath); + vfslocked = VFS_LOCK_GIANT(vp->v_mount); + vrele(vp); + VFS_UNLOCK_GIANT(vfslocked); + strlcpy(kif->kf_path, fullpath, + sizeof(kif->kf_path)); + if (freepath != NULL) + free(freepath, M_TEMP); + FILEDESC_SLOCK(fdp); + } + if (so != NULL) { + struct sockaddr *sa; + + if (so->so_proto->pr_usrreqs->pru_sockaddr(so, &sa) + == 0 && sa->sa_len <= sizeof(kif->kf_sa_local)) { + bcopy(sa, &kif->kf_sa_local, sa->sa_len); + free(sa, M_SONAME); + } + if (so->so_proto->pr_usrreqs->pru_peeraddr(so, &sa) + == 00 && sa->sa_len <= sizeof(kif->kf_sa_peer)) { + bcopy(sa, &kif->kf_sa_peer, sa->sa_len); + free(sa, M_SONAME); + } + kif->kf_sock_domain = + so->so_proto->pr_domain->dom_family; + kif->kf_sock_type = so->so_type; + kif->kf_sock_protocol = so->so_proto->pr_protocol; + } + if (tp != NULL) { + strlcpy(kif->kf_path, tty_devname(tp), + sizeof(kif->kf_path)); + } + error = SYSCTL_OUT(req, kif, sizeof(*kif)); + if (error) + break; + } + FILEDESC_SUNLOCK(fdp); + fddrop(fdp); + free(kif, M_TEMP); + return (0); +} + +static SYSCTL_NODE(_kern_proc, KERN_PROC_OFILEDESC, ofiledesc, CTLFLAG_RD, + sysctl_kern_proc_ofiledesc, "Process ofiledesc entries"); +#endif /* COMPAT_FREEBSD7 */ + +#ifdef KINFO_FILE_SIZE +CTASSERT(sizeof(struct kinfo_file) == KINFO_FILE_SIZE); +#endif + static int export_vnode_for_sysctl(struct vnode *vp, int type, struct kinfo_file *kif, struct filedesc *fdp, struct sysctl_req *req) @@ -2518,7 +2771,6 @@ export_vnode_for_sysctl(struct vnode *vp int vfslocked; bzero(kif, sizeof(*kif)); - kif->kf_structsize = sizeof(*kif); vref(vp); kif->kf_fd = type; @@ -2544,7 +2796,11 @@ export_vnode_for_sysctl(struct vnode *vp strlcpy(kif->kf_path, fullpath, sizeof(kif->kf_path)); if (freepath != NULL) free(freepath, M_TEMP); - error = SYSCTL_OUT(req, kif, sizeof(*kif)); + /* Pack record size down */ + kif->kf_structsize = offsetof(struct kinfo_file, kf_path) + + strlen(kif->kf_path) + 1; + kif->kf_structsize = roundup(kif->kf_structsize, sizeof(uint64_t)); + error = SYSCTL_OUT(req, kif, kif->kf_structsize); FILEDESC_SLOCK(fdp); return (error); } @@ -2592,7 +2848,6 @@ sysctl_kern_proc_filedesc(SYSCTL_HANDLER if ((fp = fdp->fd_ofiles[i]) == NULL) continue; bzero(kif, sizeof(*kif)); - kif->kf_structsize = sizeof(*kif); vp = NULL; so = NULL; tp = NULL; @@ -2739,7 +2994,12 @@ sysctl_kern_proc_filedesc(SYSCTL_HANDLER strlcpy(kif->kf_path, tty_devname(tp), sizeof(kif->kf_path)); } - error = SYSCTL_OUT(req, kif, sizeof(*kif)); + /* Pack record size down */ + kif->kf_structsize = offsetof(struct kinfo_file, kf_path) + + strlen(kif->kf_path) + 1; + kif->kf_structsize = roundup(kif->kf_structsize, + sizeof(uint64_t)); + error = SYSCTL_OUT(req, kif, kif->kf_structsize); if (error) break; } Modified: head/sys/kern/kern_proc.c ============================================================================== --- head/sys/kern/kern_proc.c Tue Dec 2 06:34:08 2008 (r185547) +++ head/sys/kern/kern_proc.c Tue Dec 2 06:50:26 2008 (r185548) @@ -32,6 +32,7 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_compat.h" #include "opt_ddb.h" #include "opt_kdtrace.h" #include "opt_ktrace.h" @@ -1337,13 +1338,18 @@ sysctl_kern_proc_sv_name(SYSCTL_HANDLER_ return (sysctl_handle_string(oidp, sv_name, 0, req)); } +#ifdef KINFO_OVMENTRY_SIZE +CTASSERT(sizeof(struct kinfo_ovmentry) == KINFO_OVMENTRY_SIZE); +#endif + +#ifdef COMPAT_FREEBSD7 static int -sysctl_kern_proc_vmmap(SYSCTL_HANDLER_ARGS) +sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_ARGS) { vm_map_entry_t entry, tmp_entry; unsigned int last_timestamp; char *fullpath, *freepath; - struct kinfo_vmentry *kve; + struct kinfo_ovmentry *kve; struct vattr va; struct ucred *cred; int error, *name; @@ -1497,6 +1503,176 @@ sysctl_kern_proc_vmmap(SYSCTL_HANDLER_AR free(kve, M_TEMP); return (error); } +#endif /* COMPAT_FREEBSD7 */ + +#ifdef KINFO_VMENTRY_SIZE +CTASSERT(sizeof(struct kinfo_vmentry) == KINFO_VMENTRY_SIZE); +#endif + +static int +sysctl_kern_proc_vmmap(SYSCTL_HANDLER_ARGS) +{ + vm_map_entry_t entry, tmp_entry; + unsigned int last_timestamp; + char *fullpath, *freepath; + struct kinfo_vmentry *kve; + struct vattr va; + struct ucred *cred; + int error, *name; + struct vnode *vp; + struct proc *p; + vm_map_t map; + + name = (int *)arg1; + if ((p = pfind((pid_t)name[0])) == NULL) + return (ESRCH); + if (p->p_flag & P_WEXIT) { + PROC_UNLOCK(p); + return (ESRCH); + } + if ((error = p_candebug(curthread, p))) { + PROC_UNLOCK(p); + return (error); + } + _PHOLD(p); + PROC_UNLOCK(p); + + kve = malloc(sizeof(*kve), M_TEMP, M_WAITOK); + + map = &p->p_vmspace->vm_map; /* XXXRW: More locking required? */ + vm_map_lock_read(map); + for (entry = map->header.next; entry != &map->header; + entry = entry->next) { + vm_object_t obj, tobj, lobj; + vm_offset_t addr; + int vfslocked; + + if (entry->eflags & MAP_ENTRY_IS_SUB_MAP) + continue; + + bzero(kve, sizeof(*kve)); + + kve->kve_private_resident = 0; + obj = entry->object.vm_object; + if (obj != NULL) { + VM_OBJECT_LOCK(obj); + if (obj->shadow_count == 1) + kve->kve_private_resident = + obj->resident_page_count; + } + kve->kve_resident = 0; + addr = entry->start; + while (addr < entry->end) { + if (pmap_extract(map->pmap, addr)) + kve->kve_resident++; + addr += PAGE_SIZE; + } + + for (lobj = tobj = obj; tobj; tobj = tobj->backing_object) { + if (tobj != obj) + VM_OBJECT_LOCK(tobj); + if (lobj != obj) + VM_OBJECT_UNLOCK(lobj); + lobj = tobj; + } + + kve->kve_fileid = 0; + kve->kve_fsid = 0; + freepath = NULL; + fullpath = ""; + if (lobj) { + vp = NULL; + switch(lobj->type) { + case OBJT_DEFAULT: + kve->kve_type = KVME_TYPE_DEFAULT; + break; + case OBJT_VNODE: + kve->kve_type = KVME_TYPE_VNODE; + vp = lobj->handle; + vref(vp); + break; + case OBJT_SWAP: + kve->kve_type = KVME_TYPE_SWAP; + break; + case OBJT_DEVICE: + kve->kve_type = KVME_TYPE_DEVICE; + break; + case OBJT_PHYS: + kve->kve_type = KVME_TYPE_PHYS; + break; + case OBJT_DEAD: + kve->kve_type = KVME_TYPE_DEAD; + break; + default: + kve->kve_type = KVME_TYPE_UNKNOWN; + break; + } + if (lobj != obj) + VM_OBJECT_UNLOCK(lobj); + + kve->kve_ref_count = obj->ref_count; + kve->kve_shadow_count = obj->shadow_count; + VM_OBJECT_UNLOCK(obj); + if (vp != NULL) { + vn_fullpath(curthread, vp, &fullpath, + &freepath); + cred = curthread->td_ucred; + vfslocked = VFS_LOCK_GIANT(vp->v_mount); + vn_lock(vp, LK_SHARED | LK_RETRY); + if (VOP_GETATTR(vp, &va, cred) == 0) { + kve->kve_fileid = va.va_fileid; + kve->kve_fsid = va.va_fsid; + } + vput(vp); + VFS_UNLOCK_GIANT(vfslocked); + } + } else { + kve->kve_type = KVME_TYPE_NONE; + kve->kve_ref_count = 0; + kve->kve_shadow_count = 0; + } + + kve->kve_start = entry->start; + kve->kve_end = entry->end; + kve->kve_offset = entry->offset; + + if (entry->protection & VM_PROT_READ) + kve->kve_protection |= KVME_PROT_READ; + if (entry->protection & VM_PROT_WRITE) + kve->kve_protection |= KVME_PROT_WRITE; + if (entry->protection & VM_PROT_EXECUTE) + kve->kve_protection |= KVME_PROT_EXEC; + + if (entry->eflags & MAP_ENTRY_COW) + kve->kve_flags |= KVME_FLAG_COW; + if (entry->eflags & MAP_ENTRY_NEEDS_COPY) + kve->kve_flags |= KVME_FLAG_NEEDS_COPY; + + strlcpy(kve->kve_path, fullpath, sizeof(kve->kve_path)); + if (freepath != NULL) + free(freepath, M_TEMP); + + last_timestamp = map->timestamp; + vm_map_unlock_read(map); + /* Pack record size down */ + kve->kve_structsize = offsetof(struct kinfo_vmentry, kve_path) + + strlen(kve->kve_path) + 1; + kve->kve_structsize = roundup(kve->kve_structsize, + sizeof(uint64_t)); + error = SYSCTL_OUT(req, kve, kve->kve_structsize); + vm_map_lock_read(map); + if (error) + break; + if (last_timestamp + 1 != map->timestamp) { + vm_map_lookup_entry(map, addr - 1, &tmp_entry); + entry = tmp_entry; + } + } + vm_map_unlock_read(map); + PRELE(p); + free(kve, M_TEMP); + return (error); +} #if defined(STACK) || defined(DDB) static int @@ -1669,6 +1845,11 @@ static SYSCTL_NODE(_kern_proc, (KERN_PRO static SYSCTL_NODE(_kern_proc, (KERN_PROC_PROC | KERN_PROC_INC_THREAD), proc_td, CTLFLAG_RD, sysctl_kern_proc, "Return process table, no threads"); +#ifdef COMPAT_FREEBSD7 +static SYSCTL_NODE(_kern_proc, KERN_PROC_OVMMAP, ovmmap, CTLFLAG_RD, + sysctl_kern_proc_ovmmap, "Old Process vm map entries"); +#endif + static SYSCTL_NODE(_kern_proc, KERN_PROC_VMMAP, vmmap, CTLFLAG_RD, sysctl_kern_proc_vmmap, "Process vm map entries"); Modified: head/sys/sys/sysctl.h ============================================================================== --- head/sys/sys/sysctl.h Tue Dec 2 06:34:08 2008 (r185547) +++ head/sys/sys/sysctl.h Tue Dec 2 06:50:26 2008 (r185548) @@ -540,13 +540,16 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_e #define KERN_PROC_RGID 10 /* by real group id */ #define KERN_PROC_GID 11 /* by effective group id */ #define KERN_PROC_PATHNAME 12 /* path to executable */ -#define KERN_PROC_VMMAP 13 /* VM map entries for process */ -#define KERN_PROC_FILEDESC 14 /* File descriptors for process */ +#define KERN_PROC_OVMMAP 13 /* Old VM map entries for process */ +#define KERN_PROC_OFILEDESC 14 /* Old file descriptors for process */ #define KERN_PROC_KSTACK 15 /* Kernel stacks for process */ #define KERN_PROC_INC_THREAD 0x10 /* * modifier for pid, pgrp, tty, * uid, ruid, gid, rgid and proc + * This effectively uses 16-31 */ +#define KERN_PROC_VMMAP 32 /* VM map entries for process */ +#define KERN_PROC_FILEDESC 33 /* File descriptors for process */ /* * KERN_IPC identifiers Modified: head/sys/sys/user.h ============================================================================== --- head/sys/sys/user.h Tue Dec 2 06:34:08 2008 (r185547) +++ head/sys/sys/user.h Tue Dec 2 06:50:26 2008 (r185548) @@ -277,20 +277,55 @@ struct user { #define KF_FLAG_DIRECT 0x00000040 #define KF_FLAG_HASLOCK 0x00000080 -struct kinfo_file { +/* + * Old format. Has variable hidden padding due to alignment. + * This is a compatability hack for pre-build 7.1 packages. + */ +#if defined(__amd64__) +#define KINFO_OFILE_SIZE 1328 +#endif +#if defined(__i386__) +#define KINFO_OFILE_SIZE 1324 +#endif + +struct kinfo_ofile { int kf_structsize; /* Size of kinfo_file. */ int kf_type; /* Descriptor type. */ int kf_fd; /* Array index. */ int kf_ref_count; /* Reference count. */ int kf_flags; /* Flags. */ + /* XXX Hidden alignment padding here on amd64 */ off_t kf_offset; /* Seek location. */ int kf_vnode_type; /* Vnode type. */ int kf_sock_domain; /* Socket domain. */ int kf_sock_type; /* Socket type. */ int kf_sock_protocol; /* Socket protocol. */ - char kf_path[PATH_MAX]; /* Path to file, if any. */ + char kf_path[PATH_MAX]; /* Path to file, if any. */ + struct sockaddr_storage kf_sa_local; /* Socket address. */ + struct sockaddr_storage kf_sa_peer; /* Peer address. */ +}; + +#if defined(__amd64__) || defined(__i386__) +#define KINFO_FILE_SIZE 1392 +#endif + +struct kinfo_file { + int kf_structsize; /* Variable size of record. */ + int kf_type; /* Descriptor type. */ + int kf_fd; /* Array index. */ + int kf_ref_count; /* Reference count. */ + int kf_flags; /* Flags. */ + int _kf_pad0; /* Round to 64 bit alignment */ + uint64_t kf_offset; /* Seek location. */ + int kf_vnode_type; /* Vnode type. */ + int kf_sock_domain; /* Socket domain. */ + int kf_sock_type; /* Socket type. */ + int kf_sock_protocol; /* Socket protocol. */ struct sockaddr_storage kf_sa_local; /* Socket address. */ struct sockaddr_storage kf_sa_peer; /* Peer address. */ + int _kf_ispare[16]; /* Space for more stuff. */ + /* Truncated before copyout in sysctl */ + char kf_path[PATH_MAX]; /* Path to file, if any. */ }; /* @@ -313,11 +348,18 @@ struct kinfo_file { #define KVME_FLAG_COW 0x00000001 #define KVME_FLAG_NEEDS_COPY 0x00000002 -struct kinfo_vmentry { +#if defined(__amd64__) +#define KINFO_OVMENTRY_SIZE 1168 +#endif +#if defined(__i386__) +#define KINFO_OVMENTRY_SIZE 1128 +#endif + +struct kinfo_ovmentry { int kve_structsize; /* Size of kinfo_vmmapentry. */ int kve_type; /* Type of map entry. */ - void *kve_start; /* Starting pointer. */ - void *kve_end; /* Finishing pointer. */ + void *kve_start; /* Starting address. */ + void *kve_end; /* Finishing address. */ int kve_flags; /* Flags on map entry. */ int kve_resident; /* Number of resident pages. */ int kve_private_resident; /* Number of private pages. */ @@ -327,11 +369,35 @@ struct kinfo_vmentry { char kve_path[PATH_MAX]; /* Path to VM obj, if any. */ void *_kve_pspare[8]; /* Space for more stuff. */ off_t kve_offset; /* Mapping offset in object */ - uint64_t kve_fileid; /* inode number of vnode */ + uint64_t kve_fileid; /* inode number if vnode */ dev_t kve_fsid; /* dev_t of vnode location */ int _kve_ispare[3]; /* Space for more stuff. */ }; +#if defined(__amd64__) || defined(__i386__) +#define KINFO_VMENTRY_SIZE 1160 +#endif + +struct kinfo_vmentry { + int kve_structsize; /* Variable size of record. */ + int kve_type; /* Type of map entry. */ + uint64_t kve_start; /* Starting address. */ + uint64_t kve_end; /* Finishing address. */ + uint64_t kve_offset; /* Mapping offset in object */ + uint64_t kve_fileid; /* inode number if vnode */ + uint32_t kve_fsid; /* dev_t of vnode location */ + int kve_flags; /* Flags on map entry. */ + int kve_resident; /* Number of resident pages. */ + int kve_private_resident; /* Number of private pages. */ + int kve_protection; /* Protection bitmask. */ + int kve_ref_count; /* VM obj ref count. */ + int kve_shadow_count; /* VM obj shadow count. */ + int _kve_pad0; /* 64bit align next field */ + int _kve_ispare[16]; /* Space for more stuff. */ + /* Truncated before copyout in sysctl */ + char kve_path[PATH_MAX]; /* Path to VM obj, if any. */ +}; + /* * The KERN_PROC_KSTACK sysctl allows a process to dump the kernel stacks of * another process as a series of entries. Each stack is represented by a @@ -343,12 +409,15 @@ struct kinfo_vmentry { #define KKST_STATE_SWAPPED 1 /* Stack swapped out. */ #define KKST_STATE_RUNNING 2 /* Stack ephemeral. */ +#if defined(__amd64__) || defined(__i386__) +#define KINFO_KSTACK_SIZE 1096 +#endif + struct kinfo_kstack { lwpid_t kkst_tid; /* ID of thread. */ int kkst_state; /* Validity of stack. */ char kkst_trace[KKST_MAXLEN]; /* String representing stack. */ - void *_kkst_pspare[8]; /* Space for more stuff. */ - int _kkst_ispare[8]; /* Space for more stuff. */ + int _kkst_ispare[16]; /* Space for more stuff. */ }; #endif Modified: head/usr.bin/procstat/Makefile ============================================================================== --- head/usr.bin/procstat/Makefile Tue Dec 2 06:34:08 2008 (r185547) +++ head/usr.bin/procstat/Makefile Tue Dec 2 06:50:26 2008 (r185548) @@ -12,4 +12,8 @@ SRCS= procstat.c \ procstat_threads.c \ procstat_vm.c +LDADD+= -lutil +DPADD+= ${LIBUTIL} +WARNS?= 4 + .include Modified: head/usr.bin/procstat/procstat_files.c ============================================================================== --- head/usr.bin/procstat/procstat_files.c Tue Dec 2 06:34:08 2008 (r185547) +++ head/usr.bin/procstat/procstat_files.c Tue Dec 2 06:50:26 2008 (r185548) @@ -41,6 +41,7 @@ #include #include #include +#include #include "procstat.h" @@ -134,42 +135,18 @@ void procstat_files(pid_t pid, struct kinfo_proc *kipp) { struct kinfo_file *freep, *kif; - int error, name[4]; - unsigned int i; + int i, cnt; const char *str; - size_t len; if (!hflag) printf("%5s %-16s %4s %1s %1s %-8s %3s %7s %-3s %-12s\n", "PID", "COMM", "FD", "T", "V", "FLAGS", "REF", "OFFSET", "PRO", "NAME"); - name[0] = CTL_KERN; - name[1] = KERN_PROC; - name[2] = KERN_PROC_FILEDESC; - name[3] = pid; - - error = sysctl(name, 4, NULL, &len, NULL, 0); - if (error < 0 && errno != ESRCH && errno != EPERM) { - warn("sysctl: kern.proc.filedesc: %d", pid); - return; - } - if (error < 0) - return; - - freep = kif = malloc(len); - if (kif == NULL) - err(-1, "malloc"); - - if (sysctl(name, 4, kif, &len, NULL, 0) < 0) { - warn("sysctl: kern.proc.filedesc %d", pid); - free(freep); - return; - } - - for (i = 0; i < len / sizeof(*kif); i++, kif++) { - if (kif->kf_structsize != sizeof(*kif)) - errx(-1, "kinfo_file mismatch"); + freep = kinfo_getfile(pid, &cnt); + for (i = 0; i < cnt; i++) { + kif = &freep[i]; + printf("%5d ", pid); printf("%-16s ", kipp->ki_comm); switch (kif->kf_fd) { Modified: head/usr.bin/procstat/procstat_vm.c ============================================================================== --- head/usr.bin/procstat/procstat_vm.c Tue Dec 2 06:34:08 2008 (r185547) +++ head/usr.bin/procstat/procstat_vm.c Tue Dec 2 06:50:26 2008 (r185548) @@ -34,6 +34,7 @@ #include #include #include +#include #include "procstat.h" @@ -41,10 +42,9 @@ void procstat_vm(pid_t pid, struct kinfo_proc *kipp __unused) { struct kinfo_vmentry *freep, *kve; - int error, name[4], ptrwidth; - unsigned int i; + int ptrwidth; + int i, cnt; const char *str; - size_t len; ptrwidth = 2*sizeof(void *) + 2; if (!hflag) @@ -52,38 +52,9 @@ procstat_vm(pid_t pid, struct kinfo_proc "PID", ptrwidth, "START", ptrwidth, "END", "PRT", "RES", "PRES", "REF", "SHD", "FL", "TP", "PATH"); - name[0] = CTL_KERN; - name[1] = KERN_PROC; - name[2] = KERN_PROC_VMMAP; - name[3] = pid; - - len = 0; - error = sysctl(name, 4, NULL, &len, NULL, 0); - if (error < 0 && errno != ESRCH && errno != EPERM) { - warn("sysctl: kern.proc.vmmap: %d", pid); - return; - } - if (error < 0) - return; - - /* - * Especially if running procstat -sv, we may need room for more - * mappings when printing than were present when we queried, so pad - * out the allocation a bit. - */ - len += sizeof(*kve) * 3; - freep = kve = malloc(len); - if (kve == NULL) - err(-1, "malloc"); - if (sysctl(name, 4, kve, &len, NULL, 0) < 0) { - warn("sysctl: kern.proc.vmmap: %d", pid); - free(freep); - return; - } - - for (i = 0; i < (len / sizeof(*kve)); i++, kve++) { - if (kve->kve_structsize != sizeof(*kve)) - errx(-1, "kinfo_vmentry structure mismatch"); + freep = kinfo_getvmmap(pid, &cnt); + for (i = 0; i < cnt; i++) { + kve = &freep[i]; printf("%5d ", pid); printf("%*p ", ptrwidth, kve->kve_start); *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From kmacy at FreeBSD.org Mon Dec 1 23:01:18 2008 From: kmacy at FreeBSD.org (Kip Macy) Date: Mon Dec 1 23:01:30 2008 Subject: svn commit: r185549 - head/sys/dev/cxgb Message-ID: <200812020701.mB271IWm051798@svn.freebsd.org> Author: kmacy Date: Tue Dec 2 07:01:18 2008 New Revision: 185549 URL: http://svn.freebsd.org/changeset/base/185549 Log: - fix bug where dnsperf would stop transmitting after a few seconds - break complex conditionals in to multiple lines to avoid wrapping - remove copious unused debug statements - be more aggressive about cleaning in the calling thread - eliminate usage of ENOSPC - increase number of iterations that cxgbsp can do - eliminate "initerr" usage to simplify ENOBUFS handling - when coalescing pass all packets to BPF - always set overrun if hardware queue is full Modified: head/sys/dev/cxgb/cxgb_multiq.c Modified: head/sys/dev/cxgb/cxgb_multiq.c ============================================================================== --- head/sys/dev/cxgb/cxgb_multiq.c Tue Dec 2 06:50:26 2008 (r185548) +++ head/sys/dev/cxgb/cxgb_multiq.c Tue Dec 2 07:01:18 2008 (r185549) @@ -128,7 +128,8 @@ cxgb_pcpu_enqueue_packet_(struct sge_qse txq->txq_drops++; m_freem(m); } - if (wakeup_tx_thread && ((txq->flags & TXQ_TRANSMITTING) == 0)) + if (wakeup_tx_thread && !err && + ((txq->flags & TXQ_TRANSMITTING) == 0)) wakeup(qs); return (err); @@ -195,7 +196,6 @@ cxgb_dequeue_packet(struct sge_txq *txq, return (0); if (txq->immpkt != NULL) { - DPRINTF("immediate packet\n"); m_vec[0] = txq->immpkt; txq->immpkt = NULL; return (1); @@ -209,8 +209,10 @@ cxgb_dequeue_packet(struct sge_txq *txq, count = 1; m_vec[0] = m; - if (m->m_pkthdr.tso_segsz > 0 || m->m_pkthdr.len > TX_WR_SIZE_MAX || - m->m_next != NULL || (coalesce_tx_enable == 0)) { + if (m->m_pkthdr.tso_segsz > 0 || + m->m_pkthdr.len > TX_WR_SIZE_MAX || + m->m_next != NULL || + (coalesce_tx_enable == 0)) { return (count); } @@ -218,8 +220,9 @@ cxgb_dequeue_packet(struct sge_txq *txq, for (m = buf_ring_peek(txq->txq_mr); m != NULL; m = buf_ring_peek(txq->txq_mr)) { - if (m->m_pkthdr.tso_segsz > 0 || - size + m->m_pkthdr.len > TX_WR_SIZE_MAX || m->m_next != NULL) + if (m->m_pkthdr.tso_segsz > 0 + || size + m->m_pkthdr.len > TX_WR_SIZE_MAX + || m->m_next != NULL) break; m0 = buf_ring_dequeue_sc(txq->txq_mr); @@ -315,39 +318,30 @@ cxgb_pcpu_start_(struct sge_qset *qs, st immpkt = NULL; } - if (initerr && initerr != ENOBUFS) { - if (cxgb_debug) - log(LOG_WARNING, "cxgb link down\n"); + if (initerr) { if (immpkt) m_freem(immpkt); + if (initerr == ENOBUFS && !tx_flush) + wakeup(qs); return (initerr); } if ((tx_flush && (desc_reclaimable(txq) > 0)) || - (desc_reclaimable(txq) > (TX_ETH_Q_SIZE>>1))) { - int reclaimed = 0; - - if (cxgb_debug) { - device_printf(qs->port->adapter->dev, - "cpuid=%d curcpu=%d reclaimable=%d txq=%p txq->cidx=%d txq->pidx=%d ", - qs->qs_cpuid, curcpu, desc_reclaimable(txq), - txq, txq->cidx, txq->pidx); - } - reclaimed = cxgb_pcpu_reclaim_tx(txq); - if (cxgb_debug) - printf("reclaimed=%d\n", reclaimed); + (desc_reclaimable(txq) > (TX_ETH_Q_SIZE>>3))) { + cxgb_pcpu_reclaim_tx(txq); } stopped = isset(&qs->txq_stopped, TXQ_ETH); - flush = (((!buf_ring_empty(txq->txq_mr) || (!IFQ_DRV_IS_EMPTY(&pi->ifp->if_snd))) && !stopped) || txq->immpkt); + flush = (( +#ifdef IFNET_MULTIQUEUE + !buf_ring_empty(txq->txq_mr) +#else + !IFQ_DRV_IS_EMPTY(&pi->ifp->if_snd) +#endif + && !stopped) || txq->immpkt); max_desc = tx_flush ? TX_ETH_Q_SIZE : TX_START_MAX_DESC; - - if (cxgb_debug) - DPRINTF("stopped=%d flush=%d max_desc=%d\n", - stopped, flush, max_desc); - err = flush ? cxgb_tx(qs, max_desc) : ENOSPC; - + err = flush ? cxgb_tx(qs, max_desc) : 0; if ((tx_flush && flush && err == 0) && (!buf_ring_empty(txq->txq_mr) || @@ -359,16 +353,13 @@ cxgb_pcpu_start_(struct sge_qset *qs, st sched_prio(td, PRI_MIN_TIMESHARE); thread_unlock(td); } - if (i > 50) { - if (cxgb_debug) - device_printf(qs->port->adapter->dev, + if (i > 200) { + device_printf(qs->port->adapter->dev, "exceeded max enqueue tries\n"); return (EBUSY); } goto retry; } - err = (initerr != 0) ? initerr : err; - return (err); } @@ -391,32 +382,22 @@ cxgb_pcpu_transmit(struct ifnet *ifp, st if (immpkt && (immpkt->m_pkthdr.flowid != 0)) { cookie = immpkt->m_pkthdr.flowid; qidx = cxgb_pcpu_cookie_to_qidx(pi, cookie); - DPRINTF("hash=0x%x qidx=%d cpu=%d\n", immpkt->m_pkthdr.flowid, qidx, curcpu); qs = &pi->adapter->sge.qs[qidx]; } else #endif qs = &pi->adapter->sge.qs[pi->first_qset]; txq = &qs->txq[TXQ_ETH]; - if (((sc->tunq_coalesce == 0) || (buf_ring_count(txq->txq_mr) >= TX_WR_COUNT_MAX) || (coalesce_tx_enable == 0)) && mtx_trylock(&txq->lock)) { - if (cxgb_debug) - printf("doing immediate transmit\n"); - txq->flags |= TXQ_TRANSMITTING; err = cxgb_pcpu_start_(qs, immpkt, FALSE); txq->flags &= ~TXQ_TRANSMITTING; - resid = (buf_ring_count(txq->txq_mr) > 64) || (desc_reclaimable(txq) > 64); mtx_unlock(&txq->lock); - } else if (immpkt) { - if (cxgb_debug) - printf("deferred coalesce=%jx ring_count=%d mtx_owned=%d\n", - sc->tunq_coalesce, buf_ring_count(txq->txq_mr), mtx_owned(&txq->lock)); - err = cxgb_pcpu_enqueue_packet_(qs, immpkt); - } - return ((err == ENOSPC) ? 0 : err); + } else if (immpkt) + return (cxgb_pcpu_enqueue_packet_(qs, immpkt)); + return ((err == EBUSY) ? 0 : err); } void @@ -624,29 +605,23 @@ cxgb_tx(struct sge_qset *qs, uint32_t tx txq = &qs->txq[TXQ_ETH]; ifp = qs->port->ifp; in_use_init = txq->in_use; - err = 0; - - for (i = 0; i < TX_WR_COUNT_MAX; i++) - m_vec[i] = NULL; + count = err = 0; mtx_assert(&txq->lock, MA_OWNED); while ((txq->in_use - in_use_init < txmax) && (txq->size > txq->in_use + TX_MAX_DESC)) { check_pkt_coalesce(qs); count = cxgb_dequeue_packet(txq, m_vec); - if (count == 0) { - err = ENOSPC; + if (count == 0) break; - } - ETHER_BPF_MTAP(ifp, m_vec[0]); + for (i = 0; i < count; i++) + ETHER_BPF_MTAP(ifp, m_vec[i]); if ((err = t3_encap(qs, m_vec, count)) != 0) break; txq->txq_enqueued += count; - m_vec[0] = NULL; } - if ((err == 0) && (txq->size <= txq->in_use + TX_MAX_DESC)) { - err = ENOBUFS; + if (txq->size <= txq->in_use + TX_MAX_DESC) { txq_fills++; setbit(&qs->txq_stopped, TXQ_ETH); } From peter at wemm.org Mon Dec 1 23:22:45 2008 From: peter at wemm.org (Peter Wemm) Date: Mon Dec 1 23:22:51 2008 Subject: svn commit: r185539 - in head/sys: arm/at91 dev/mn kern security/mac security/mac_bsdextended In-Reply-To: <20081201.220808.1649770636.imp@bsdimp.com> References: <200812020226.mB22QFtl045542@svn.freebsd.org> <20081201.220808.1649770636.imp@bsdimp.com> Message-ID: On Mon, Dec 1, 2008 at 9:08 PM, M. Warner Losh wrote: > In message: <200812020226.mB22QFtl045542@svn.freebsd.org> > Peter Wemm writes: > : Author: peter > : Date: Tue Dec 2 02:26:15 2008 > : New Revision: 185539 > : URL: http://svn.freebsd.org/changeset/base/185539 > : > : Log: > : Delete a bunch of empty mergeinfo records caused by local copies. > : > : Modified: > : head/sys/arm/at91/at91_machdep.c (props changed) > : head/sys/arm/at91/board_bwct.c (props changed) > : head/sys/arm/at91/board_hl200.c (props changed) > : head/sys/arm/at91/board_kb920x.c (props changed) > : head/sys/arm/at91/board_tsc4370.c (props changed) > : head/sys/arm/at91/std.bwct (props changed) > : head/sys/arm/at91/std.hl200 (props changed) > : head/sys/arm/at91/std.tsc4370 (props changed) > : head/sys/dev/mn/if_mn.c (props changed) > : head/sys/kern/kern_cons.c (props changed) > : head/sys/security/mac/mac_cred.c (props changed) > : head/sys/security/mac_bsdextended/ugidfw_system.c (props changed) > : head/sys/security/mac_bsdextended/ugidfw_vnode.c (props changed) > > Is there some way the developer that does the copies can do this so > you don't need to do this? Yes. It sounds strange, but specify a full repo-relative path. instead of: $ cd head/sys/kern $ svn cp kern_tty.c kern_cons.c $ ..stuff.. $ svn commit you should do this: $ cd head/sys/kern $ svn cp $REPO/head/sys/kern/kern_tty.c kern_cons.c $ ..stuff.. $ svn commit The difference is that in the second form the command can chase inherited mergeinfo around wherever it may lead and make sure that side effects are accounted for. In the first form, the command doesn't have access to mergeinfo inheritance info so it has to make an empty 'I have no idea!' mergeinfo to block any inheritance that *might* be there. -- Peter Wemm - peter@wemm.org; peter@FreeBSD.org; peter@yahoo-inc.com; KI6FJV "All of this is for nothing if we don't go to the stars" - JMS/B5 "If Java had true garbage collection, most programs would delete themselves upon execution." -- Robert Sewell From peter at FreeBSD.org Tue Dec 2 02:10:51 2008 From: peter at FreeBSD.org (Peter Wemm) Date: Tue Dec 2 02:10:57 2008 Subject: svn commit: r185553 - head/lib/libutil Message-ID: <200812021010.mB2AAowJ055809@svn.freebsd.org> Author: peter Date: Tue Dec 2 10:10:50 2008 New Revision: 185553 URL: http://svn.freebsd.org/changeset/base/185553 Log: Attempt a quick bandaid for arm build breakage. I went to the trouble of maintaining alignment, but I'm not sure how to tell gcc this. Modified: head/lib/libutil/kinfo_getfile.c head/lib/libutil/kinfo_getvmmap.c Modified: head/lib/libutil/kinfo_getfile.c ============================================================================== --- head/lib/libutil/kinfo_getfile.c Tue Dec 2 08:23:45 2008 (r185552) +++ head/lib/libutil/kinfo_getfile.c Tue Dec 2 10:10:50 2008 (r185553) @@ -42,7 +42,7 @@ kinfo_getfile(pid_t pid, int *cntp) bp = buf; eb = buf + len; while (bp < eb) { - kf = (struct kinfo_file *)bp; + kf = (struct kinfo_file *)(uintptr_t)bp; bp += kf->kf_structsize; cnt++; } @@ -57,7 +57,7 @@ kinfo_getfile(pid_t pid, int *cntp) kp = kif; /* Pass 2: unpack */ while (bp < eb) { - kf = (struct kinfo_file *)bp; + kf = (struct kinfo_file *)(uintptr_t)bp; /* Copy/expand into pre-zeroed buffer */ memcpy(kp, kf, kf->kf_structsize); /* Advance to next packed record */ Modified: head/lib/libutil/kinfo_getvmmap.c ============================================================================== --- head/lib/libutil/kinfo_getvmmap.c Tue Dec 2 08:23:45 2008 (r185552) +++ head/lib/libutil/kinfo_getvmmap.c Tue Dec 2 10:10:50 2008 (r185553) @@ -42,7 +42,7 @@ kinfo_getvmmap(pid_t pid, int *cntp) bp = buf; eb = buf + len; while (bp < eb) { - kv = (struct kinfo_vmentry *)bp; + kv = (struct kinfo_vmentry *)(uintptr_t)bp; bp += kv->kve_structsize; cnt++; } @@ -57,7 +57,7 @@ kinfo_getvmmap(pid_t pid, int *cntp) kp = kiv; /* Pass 2: unpack */ while (bp < eb) { - kv = (struct kinfo_vmentry *)bp; + kv = (struct kinfo_vmentry *)(uintptr_t)bp; /* Copy/expand into pre-zeroed buffer */ memcpy(kp, kv, kv->kve_structsize); /* Advance to next packed record */ From peter at FreeBSD.org Tue Dec 2 02:39:47 2008 From: peter at FreeBSD.org (Peter Wemm) Date: Tue Dec 2 02:39:59 2008 Subject: svn commit: r185554 - head/sys/sys Message-ID: <200812021039.mB2AdlAt056450@svn.freebsd.org> Author: peter Date: Tue Dec 2 10:39:47 2008 New Revision: 185554 URL: http://svn.freebsd.org/changeset/base/185554 Log: kf_offset was supposed to be signed. Modified: head/sys/sys/user.h Modified: head/sys/sys/user.h ============================================================================== --- head/sys/sys/user.h Tue Dec 2 10:10:50 2008 (r185553) +++ head/sys/sys/user.h Tue Dec 2 10:39:47 2008 (r185554) @@ -316,7 +316,7 @@ struct kinfo_file { int kf_ref_count; /* Reference count. */ int kf_flags; /* Flags. */ int _kf_pad0; /* Round to 64 bit alignment */ - uint64_t kf_offset; /* Seek location. */ + int64_t kf_offset; /* Seek location. */ int kf_vnode_type; /* Vnode type. */ int kf_sock_domain; /* Socket domain. */ int kf_sock_type; /* Socket type. */ From jkoshy at FreeBSD.org Tue Dec 2 02:46:36 2008 From: jkoshy at FreeBSD.org (Joseph Koshy) Date: Tue Dec 2 02:46:47 2008 Subject: svn commit: r185555 - head/sys/dev/hwpmc Message-ID: <200812021046.mB2AkZFo056617@svn.freebsd.org> Author: jkoshy Date: Tue Dec 2 10:46:35 2008 New Revision: 185555 URL: http://svn.freebsd.org/changeset/base/185555 Log: - Efficiency tweak: when checking for PMC overflows, only go to hardware for PMCs that have been configured for sampling. - Bug fix: acknowledge PMC hardware overflows irrespective of the the (software) PMC's state. Modified: head/sys/dev/hwpmc/hwpmc_amd.c head/sys/dev/hwpmc/hwpmc_ppro.c Modified: head/sys/dev/hwpmc/hwpmc_amd.c ============================================================================== --- head/sys/dev/hwpmc/hwpmc_amd.c Tue Dec 2 10:39:47 2008 (r185554) +++ head/sys/dev/hwpmc/hwpmc_amd.c Tue Dec 2 10:46:35 2008 (r185555) @@ -632,7 +632,6 @@ amd_intr(int cpu, struct trapframe *tf) uint32_t config, evsel, perfctr; struct pmc *pm; struct amd_cpu *pac; - struct pmc_hw *phw; pmc_value_t v; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), @@ -660,21 +659,19 @@ amd_intr(int cpu, struct trapframe *tf) for (i = 0; retval == 0 && i < AMD_NPMCS; i++) { - if (!AMD_PMC_HAS_OVERFLOWED(i)) - continue; - - phw = &pac->pc_amdpmcs[i]; - - KASSERT(phw != NULL, ("[amd,%d] null PHW pointer", __LINE__)); - - if ((pm = phw->phw_pmc) == NULL || - pm->pm_state != PMC_STATE_RUNNING || + if ((pm = pac->pc_amdpmcs[i].phw_pmc) == NULL || !PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) { continue; } + if (!AMD_PMC_HAS_OVERFLOWED(i)) + continue; + retval = 1; /* Found an interrupting PMC. */ + if (pm->pm_state != PMC_STATE_RUNNING) + continue; + /* Stop the PMC, reload count. */ evsel = AMD_PMC_EVSEL_0 + i; perfctr = AMD_PMC_PERFCTR_0 + i; Modified: head/sys/dev/hwpmc/hwpmc_ppro.c ============================================================================== --- head/sys/dev/hwpmc/hwpmc_ppro.c Tue Dec 2 10:39:47 2008 (r185554) +++ head/sys/dev/hwpmc/hwpmc_ppro.c Tue Dec 2 10:46:35 2008 (r185555) @@ -688,17 +688,19 @@ p6_intr(int cpu, struct trapframe *tf) for (ri = 0; ri < P6_NPMCS; ri++) { - if (!P6_PMC_HAS_OVERFLOWED(ri)) - continue; - if ((pm = pc->pc_p6pmcs[ri].phw_pmc) == NULL || - pm->pm_state != PMC_STATE_RUNNING || !PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) { continue; } + if (!P6_PMC_HAS_OVERFLOWED(ri)) + continue; + retval = 1; + if (pm->pm_state != PMC_STATE_RUNNING) + continue; + error = pmc_process_interrupt(cpu, pm, tf, TRAPF_USERMODE(tf)); if (error) From kib at FreeBSD.org Tue Dec 2 03:12:51 2008 From: kib at FreeBSD.org (Konstantin Belousov) Date: Tue Dec 2 03:13:02 2008 Subject: svn commit: r185556 - head/sys/ufs/ufs Message-ID: <200812021112.mB2BCpWH058555@svn.freebsd.org> Author: kib Date: Tue Dec 2 11:12:50 2008 New Revision: 185556 URL: http://svn.freebsd.org/changeset/base/185556 Log: Do not lock vnode interlock around reading of v_iflag to check VI_DOOMED. Read of the pointer is atomic, and flag cannot be set while vnode lock is held. Requested by: jhb MFC after: 1 month Modified: head/sys/ufs/ufs/ufs_lookup.c Modified: head/sys/ufs/ufs/ufs_lookup.c ============================================================================== --- head/sys/ufs/ufs/ufs_lookup.c Tue Dec 2 10:46:35 2008 (r185555) +++ head/sys/ufs/ufs/ufs_lookup.c Tue Dec 2 11:12:50 2008 (r185556) @@ -157,7 +157,6 @@ ufs_lookup(ap) int nameiop = cnp->cn_nameiop; ino_t ino; int ltype; - int pdoomed; struct mount *mp; bp = NULL; @@ -588,20 +587,14 @@ found: VOP_UNLOCK(pdp, 0); pause("ufs_dd", 1); vn_lock(pdp, ltype | LK_RETRY); - VI_LOCK(pdp); - pdoomed = pdp->v_iflag & VI_DOOMED; - VI_UNLOCK(pdp); - if (pdoomed) + if (pdp->v_iflag & VI_DOOMED) return (ENOENT); } VOP_UNLOCK(pdp, 0); /* race to get the inode */ error = VFS_VGET(mp, ino, cnp->cn_lkflags, &tdp); vfs_unbusy(mp); vn_lock(pdp, ltype | LK_RETRY); - VI_LOCK(pdp); - pdoomed = pdp->v_iflag & VI_DOOMED; - VI_UNLOCK(pdp); - if (pdoomed) { + if (pdp->v_iflag & VI_DOOMED) { if (error == 0) vput(tdp); error = ENOENT; From kib at FreeBSD.org Tue Dec 2 03:14:17 2008 From: kib at FreeBSD.org (Konstantin Belousov) Date: Tue Dec 2 03:14:23 2008 Subject: svn commit: r185557 - head/sys/kern Message-ID: <200812021114.mB2BEHB3058629@svn.freebsd.org> Author: kib Date: Tue Dec 2 11:14:16 2008 New Revision: 185557 URL: http://svn.freebsd.org/changeset/base/185557 Log: Shared lookup makes it possible to create several negative cache entries for one name. Then, creating inode with that name would remove one entry, leaving others dormant. Reclaiming the vnode would uncover negative entries, causing false return of ENOENT from the calls like stat, that do not create inode. Prevent creation of the duplicated negative entries. Reported and debugged with: pho Reviewed by: jhb X-MFC: after shared lookup changes Modified: head/sys/kern/vfs_cache.c Modified: head/sys/kern/vfs_cache.c ============================================================================== --- head/sys/kern/vfs_cache.c Tue Dec 2 11:12:50 2008 (r185556) +++ head/sys/kern/vfs_cache.c Tue Dec 2 11:14:16 2008 (r185557) @@ -474,7 +474,7 @@ cache_enter(dvp, vp, cnp) struct vnode *vp; struct componentname *cnp; { - struct namecache *ncp; + struct namecache *ncp, *n2; struct nchashhead *ncpp; u_int32_t hash; int hold; @@ -530,8 +530,6 @@ cache_enter(dvp, vp, cnp) * name. */ if (vp) { - struct namecache *n2; - TAILQ_FOREACH(n2, &vp->v_cache_dst, nc_dst) { if (n2->nc_dvp == dvp && n2->nc_nlen == cnp->cn_namelen && @@ -541,7 +539,16 @@ cache_enter(dvp, vp, cnp) return; } } - } + } else { + TAILQ_FOREACH(n2, &ncneg, nc_dst) { + if (n2->nc_nlen == cnp->cn_namelen && + !bcmp(n2->nc_name, cnp->cn_nameptr, n2->nc_nlen)) { + CACHE_UNLOCK(); + cache_free(ncp); + return; + } + } + } numcache++; if (!vp) { From kib at FreeBSD.org Tue Dec 2 03:58:32 2008 From: kib at FreeBSD.org (Konstantin Belousov) Date: Tue Dec 2 03:58:44 2008 Subject: svn commit: r185558 - in head: lib/libthr/thread libexec/rtld-elf Message-ID: <200812021158.mB2BwW5g059495@svn.freebsd.org> Author: kib Date: Tue Dec 2 11:58:31 2008 New Revision: 185558 URL: http://svn.freebsd.org/changeset/base/185558 Log: Provide custom simple allocator for rtld locks in libthr. The allocator does not use any external symbols, thus avoiding possible recursion into rtld to resolve symbols, when called. Reviewed by: kan, davidxu Tested by: rink MFC after: 1 month Modified: head/lib/libthr/thread/thr_fork.c head/lib/libthr/thread/thr_rtld.c head/libexec/rtld-elf/rtld_lock.h Modified: head/lib/libthr/thread/thr_fork.c ============================================================================== --- head/lib/libthr/thread/thr_fork.c Tue Dec 2 11:14:16 2008 (r185557) +++ head/lib/libthr/thread/thr_fork.c Tue Dec 2 11:58:31 2008 (r185558) @@ -106,7 +106,7 @@ _fork(void) pid_t ret; int errsave; int unlock_malloc; - int rtld_locks[16]; + int rtld_locks[MAX_RTLD_LOCKS]; if (!_thr_is_inited()) return (__sys_fork()); Modified: head/lib/libthr/thread/thr_rtld.c ============================================================================== --- head/lib/libthr/thread/thr_rtld.c Tue Dec 2 11:14:16 2008 (r185557) +++ head/lib/libthr/thread/thr_rtld.c Tue Dec 2 11:58:31 2008 (r185558) @@ -50,42 +50,42 @@ static int _thr_rtld_set_flag(int); static void _thr_rtld_wlock_acquire(void *); struct rtld_lock { - struct urwlock lock; - void *base; + struct urwlock lock; + char _pad[CACHE_LINE_SIZE - sizeof(struct urwlock)]; }; +static struct rtld_lock lock_place[MAX_RTLD_LOCKS] __aligned(CACHE_LINE_SIZE); +static int busy_places; + static void * _thr_rtld_lock_create(void) { - void *base; - char *p; - uintptr_t r; - struct rtld_lock *l; - size_t size; - - size = CACHE_LINE_SIZE; - while (size < sizeof(struct rtld_lock)) - size <<= 1; - base = calloc(1, size); - p = (char *)base; - if ((uintptr_t)p % CACHE_LINE_SIZE != 0) { - free(base); - base = calloc(1, size + CACHE_LINE_SIZE); - p = (char *)base; - if ((r = (uintptr_t)p % CACHE_LINE_SIZE) != 0) - p += CACHE_LINE_SIZE - r; + int locki; + struct rtld_lock *l; + static const char fail[] = "_thr_rtld_lock_create failed\n"; + + for (locki = 0; locki < MAX_RTLD_LOCKS; locki++) { + if ((busy_places & (1 << locki)) == 0) + break; } - l = (struct rtld_lock *)p; + if (locki == MAX_RTLD_LOCKS) { + write(2, fail, sizeof(fail) - 1); + return (NULL); + } + busy_places |= (1 << locki); + + l = &lock_place[locki]; l->lock.rw_flags = URWLOCK_PREFER_READER; - l->base = base; return (l); } static void _thr_rtld_lock_destroy(void *lock) { - struct rtld_lock *l = (struct rtld_lock *)lock; - free(l->base); + int locki; + + locki = (struct rtld_lock *)lock - &lock_place[0]; + busy_places &= ~(1 << locki); } #define SAVE_ERRNO() { \ Modified: head/libexec/rtld-elf/rtld_lock.h ============================================================================== --- head/libexec/rtld-elf/rtld_lock.h Tue Dec 2 11:14:16 2008 (r185557) +++ head/libexec/rtld-elf/rtld_lock.h Tue Dec 2 11:58:31 2008 (r185558) @@ -29,6 +29,7 @@ #define _RTLD_LOCK_H_ #define RTLI_VERSION 0x01 +#define MAX_RTLD_LOCKS 8 struct RtldLockInfo { From des at des.no Tue Dec 2 04:55:11 2008 From: des at des.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Tue Dec 2 04:56:54 2008 Subject: svn commit: r185553 - head/lib/libutil In-Reply-To: <200812021010.mB2AAowJ055809@svn.freebsd.org> (Peter Wemm's message of "Tue, 2 Dec 2008 10:10:50 +0000 (UTC)") References: <200812021010.mB2AAowJ055809@svn.freebsd.org> Message-ID: <86r64q4tzl.fsf@ds4.des.no> Peter Wemm writes: > Log: > Attempt a quick bandaid for arm build breakage. I went to the trouble of > maintaining alignment, but I'm not sure how to tell gcc this. There's no good way to do this. In an ideal world, you could add an assertion that the offset is a multiple of __alignof__(struct kinfo_foo), and gcc would understand, but I don't think that works in practice. Coverity will probably complain about this as well, but hopefully the cast will pacify it like it pacifies gcc. In pw_util and gr_util, scf@ and I solved a similar issue by using a wrapper struct, but that wouldn't work here. DES -- Dag-Erling Sm?rgrav - des@des.no From brde at optusnet.com.au Tue Dec 2 05:10:00 2008 From: brde at optusnet.com.au (Bruce Evans) Date: Tue Dec 2 05:10:06 2008 Subject: svn commit: r185162 - in head: . sys/amd64/include sys/arm/include sys/conf sys/dev/bce sys/dev/cxgb sys/dev/cxgb/sys sys/dev/cxgb/ulp/iw_cxgb sys/dev/mxge sys/dev/nxge sys/i386/include sys/i386/in... In-Reply-To: <20081201214217.GS3045@deviant.kiev.zoral.com.ua> References: <200811220555.mAM5tuIJ007781@svn.freebsd.org> <3c1674c90811221651u338294frcdbd99b386733851@mail.gmail.com> <20081123154138.GS6408@deviant.kiev.zoral.com.ua> <200812011407.06563.jhb@freebsd.org> <20081201214217.GS3045@deviant.kiev.zoral.com.ua> Message-ID: <20081202232222.N1514@besplex.bde.org> On Mon, 1 Dec 2008, Kostik Belousov wrote: > On Mon, Dec 01, 2008 at 02:07:06PM -0500, John Baldwin wrote: >> On Sunday 23 November 2008 10:41:38 am Kostik Belousov wrote: >>> Below is the updated patch. It includes changes made after private comments >>> by bde@ and uses symbolic definitions for the bits in the features words. >>> I thought about accessing a per-CPU word for serialized instruction in the >>> slow path, but decided that it does not beneficial.\ >> >> Is the branch really better than just doing what the atomic operations for >> mutexes, etc. do and just use 'lock addl $0,%esp' for a barrier in all cases >> on i386 and only bother with using the fancier instructions on amd64? Even >> amd64 doesn't use *fence yet for the atomic ops actually. I have had a patch >> to use it for years, but during testing there was no discernable difference >> between the existing 'lock addl' approach vs '*fence'. I'd much rather just >> use 486 code for all i386 machines than add a branch, esp. if >> the "optimization" the branch is doing isn't an actual optimization. Hmm. > I do not insist. The branch is done only for arches that has no fence > instructions. The section for the slow code is put after the main text, > that should, according to Intel documentation, be predicted as not taken > for the first execution. > > For reference, below is the latest version of the patch. I postponed > the commit, in particular, because it touches ixgb, and Jack did > not responded. > ... > diff --git a/sys/i386/include/atomic.h b/sys/i386/include/atomic.h > index f6bcf0c..dbdc945 100644 > --- a/sys/i386/include/atomic.h > +++ b/sys/i386/include/atomic.h > @@ -32,21 +32,47 @@ > #error this file needs sys/cdefs.h as a prerequisite > #endif > > - > -#if defined(I686_CPU) > -#define mb() __asm__ __volatile__ ("mfence;": : :"memory") > -#define wmb() __asm__ __volatile__ ("sfence;": : :"memory") > -#define rmb() __asm__ __volatile__ ("lfence;": : :"memory") > -#else > -/* > - * do we need a serializing instruction? > - */ > -#define mb() > -#define wmb() > -#define rmb() > +#if defined(_KERNEL) Still have this style bug (if defined() instead of ifdef). > +#include Namespace pollution. This should be unnecessary because it is an error to include (or ) directly, at least in the kernel. The correct include is which supplies pollution by and and lots more as standard. There is included before . This order would now be wrong if you have added a dependency of on , but I can't see such a dependency... > +#include ... now I see it -- it is because is broken and has a dependency on . is supposed to contain only #define's for special registers, but it has 2 inline functions that use functions from , without even using #defines for the special registers that they use. Normally can be included without worrying about this dependency, thanks to the standard pollution, but now the standard pollution is broken. Namespace pollution. This is almost necessary for CPUID_* (it would be necessary if these macros were inlines, but with macros only files that use the macros would need the include and there might be few enough of them for this to be done for each, or could do it (ugh) and hthe order doesn't matter. Another advantage of 'lock addl' is that CPUID_* are not needed. Atomic ops would need the same treatment if they used *fence. > +#define mb() __asm __volatile( \ > + "testl %0,cpu_feature \n\ > + je 2f \n\ > + mfence \n\ > +1: \n\ Still have this style bug (no empty line before label that is not fallen into). I wasn't going to care about this, but then decided that the non-fall-through here is especially non-obvious. > + .section .text.offpath \n\ > +2: lock \n\ Still have this style bug (label on same line as instruction). > + addl $0,cpu_feature \n\ I wonder if adding to (%esp) is faster. It is at least smaller. > + jmp 1b \n\ Missing empty line as above. > + .text \n\ > +" \ > + : : "i"(CPUID_SSE2) : "memory") Missing space after "i" here and elsewhere. Bruce From brde at optusnet.com.au Tue Dec 2 05:28:11 2008 From: brde at optusnet.com.au (Bruce Evans) Date: Tue Dec 2 05:28:17 2008 Subject: svn commit: r185362 - head/share/man/man9 In-Reply-To: References: <200811270842.mAR8gwi3080974@svn.freebsd.org> Message-ID: <20081203001117.P1758@besplex.bde.org> On Sun, 30 Nov 2008, Sean C. Farley wrote: > On Thu, 27 Nov 2008, Robert Watson wrote: > >> Log: >> Revert r184509: don't encourage the use of sysexits.h with err() and >> errx(),, as there seems to be a general preference against this >> practice. > > *snip* > >> if ((four = malloc(sizeof(struct foo))) == NULL) >> - err(EX_OSERR, NULL); >> + err(1, (char *)NULL); >> if ((six = (int *)overflow()) == NULL) >> - errx(EX_DATAERR, "number overflowed"); >> + errx(1, "number overflowed"); > > Out of curiosity, why not EXIT_FAILURE instead of 1, at least in > situations where including stdlib.h is allowed? Is it because > EXIT_FAILURE is only required to be non-zero and not necessarily 1? It is because KNF doesn't use EXIT_FAILURE, and style(9) is primarily to document what KNF does and not to change it. Another bug in r184509 is that it didn't just encourage use of sysexits.h but required it, by removing all examples of non-use of sysexits.h. A non-example rule in style.9 still requires use of sysexits.h for all nonzero exits, but is obviously wrong since it is inconsistent with the 2 examples shown in the above diff. Bruce From ganbold at FreeBSD.org Tue Dec 2 06:19:54 2008 From: ganbold at FreeBSD.org (Ganbold Tsagaankhuu) Date: Tue Dec 2 06:20:06 2008 Subject: svn commit: r185561 - head/sys/amd64/amd64 Message-ID: <200812021419.mB2EJrTd062613@svn.freebsd.org> Author: ganbold (doc committer) Date: Tue Dec 2 14:19:53 2008 New Revision: 185561 URL: http://svn.freebsd.org/changeset/base/185561 Log: Remove unused variable. Found with: Coverity Prevent(tm) CID: 3685 Approved by: jhb Modified: head/sys/amd64/amd64/intr_machdep.c Modified: head/sys/amd64/amd64/intr_machdep.c ============================================================================== --- head/sys/amd64/amd64/intr_machdep.c Tue Dec 2 13:36:38 2008 (r185560) +++ head/sys/amd64/amd64/intr_machdep.c Tue Dec 2 14:19:53 2008 (r185561) @@ -239,11 +239,8 @@ void intr_execute_handlers(struct intsrc *isrc, struct trapframe *frame) { struct intr_event *ie; - struct thread *td; int vector; - td = curthread; - /* * We count software interrupts when we process them. The * code here follows previous practice, but there's an From luigi at FreeBSD.org Tue Dec 2 06:57:49 2008 From: luigi at FreeBSD.org (Luigi Rizzo) Date: Tue Dec 2 06:57:56 2008 Subject: svn commit: r185562 - head/sys/boot/i386/boot0 Message-ID: <200812021457.mB2Evmha063418@svn.freebsd.org> Author: luigi Date: Tue Dec 2 14:57:48 2008 New Revision: 185562 URL: http://svn.freebsd.org/changeset/base/185562 Log: This commits brings in a lot of documentation and some enhancement of the boot0.S code, with a number of compile-time selectable options, the most interesting one being the ability to select PXE booting. The code is completely compatible with the previous one, and with the boot0cfg program. Even the actual code is largely unmodified, with only minor rearrangements or fixes to make room for the new features. The behaviour of the standard build differs from the previous version in the following, minor things: + 'noupdate' is the default, which means the code does not write back the selection to disk. You can enable the feature at runtime with boot0cfg, or changing the flags in the Makefile. + a drive number of 0x00 (floppy, or USB in floppy emulation) is now accepted as valid. Previously, it was overridden with 0x80, meaning that the partition table coming from the media was used to access sectors on a possibly different media. You can revert to the previous mode building with -DCHECK_DRIVE, and you can always use the 'setdrv' option in boot0cfg + certain FAT or NTFS partitions are listed as WIN instead of DOS. + the 'bel' character on a bad selection is replaced by a '#' to make it clear that the system is not hang even if the machine does not have a speaker. This can be reverted back at compile time, or at runtime with an upcoming boot0cfg option. Additional features are available as compile time options, and may be become the default if deemed useful. In particular: + INT18/PXE boot (make -DPXE) This option enables booting through INT 18h (which on certain BIOSes can be hooked to PXE) by pressing F6. There is unfortunately no room to print the additional menu option. Also, to make room for the code, the 'Default: ' string is changed to 'Boot: ' + print current drive number (make -DTEST) Prints a line indicating the current drive number. This is useful to figure out what is going on for machines/bioses which remap drives in sometimes surprising ways. + disable numeric keys in console mode (make -DONLY_F_KEYS) Not really a significant option, but it is needed to make room for the -DTEST mode. + disable floppy support (make -DCHECK_DRIVE) Revert to the old behaviour of only accepting 0x80 and above as valid drive numbers. MFC after: 6 weeks Modified: head/sys/boot/i386/boot0/Makefile head/sys/boot/i386/boot0/boot0.S Modified: head/sys/boot/i386/boot0/Makefile ============================================================================== --- head/sys/boot/i386/boot0/Makefile Tue Dec 2 14:19:53 2008 (r185561) +++ head/sys/boot/i386/boot0/Makefile Tue Dec 2 14:57:48 2008 (r185562) @@ -6,11 +6,29 @@ BINMODE=${NOBINMODE} NO_MAN= SRCS= ${PROG}.S -# The default set of flags compiled into boot0. This enables update (writing -# the modified boot0 back to disk after running so that the selection made is -# saved), packet mode (detect and use the BIOS EDD extensions if we try to -# boot past the 1024 cylinder liimt), and booting from all valid slices. -BOOT_BOOT0_FLAGS?= 0x8f +# Additional options that you can specify with make OPTS="..." +# (these only apply to boot0.S) +# +# -DSIO do I/O using COM1: +# -DPXE fallback to INT18/PXE with F6 +# -DCHECK_DRIVE enable checking drive number +# -DONLY_F_KEYS accept only Fx keys in console +# -DTEST print drive number on entry +# +CFLAGS += ${OPTS} + +# Flags used in the boot0.S code: +# 0x0f all valid partitions enabled. +# 0x80 'packet', use BIOS EDD (LBA) extensions instead of CHS +# to read from disk. boot0.S does not check that the extensions +# are supported, but all modern BIOSes should have them. +# 0x40 'noupdate', disable writing boot0 back to disk so that +# the current selection is not preserved across reboots. +# 0x20 'setdrv', override the drive number supplied by the bios +# with the one in the boot sector. + +# Default boot flags: +BOOT_BOOT0_FLAGS?= 0xcf # The number of timer ticks to wait for a keypress before assuming the default # selection. Since there are 18.2 ticks per second, the default value of Modified: head/sys/boot/i386/boot0/boot0.S ============================================================================== --- head/sys/boot/i386/boot0/boot0.S Tue Dec 2 14:19:53 2008 (r185561) +++ head/sys/boot/i386/boot0/boot0.S Tue Dec 2 14:57:48 2008 (r185562) @@ -1,4 +1,5 @@ /* + * Copyright (c) 2008 Luigi Rizzo (mostly documentation) * Copyright (c) 2002 Bruce M. Simpson * Copyright (c) 1998 Robert Nordier * All rights reserved. @@ -16,50 +17,158 @@ * $FreeBSD$ */ -/* A 512-byte boot manager. */ -#ifdef SIO -/* ... using a serial console on COM1. */ +/* build options: */ +#ifdef SIO /* use serial console on COM1. */ #endif +#ifdef PXE /* enable PXE/INT18 booting with F6 */ +#endif + +#ifdef CHECK_DRIVE /* make sure we boot from a HD. */ +#endif + +#ifdef ONLY_F_KEYS /* Only F1..F6, no digits on console */ +#endif + +#ifdef TEST /* enable some test code */ +#ifndef ONLY_F_KEYS +#define ONLY_F_KEYS /* make room for the test code */ +#endif +#endif + +/* + * Note - this code uses many tricks to save space and fit in one sector. + * This includes using side effects of certain instructions, reusing + * register values from previous operations, etc. + * Be extremely careful when changing the code, even for simple things. + */ + +/* + * BOOT BLOCK STRUCTURE + * + * This code implements a Master Boot Record (MBR) for an Intel/PC disk. + * It is 512 bytes long and it is normally loaded by the BIOS (or another + * bootloader) at 0:0x7c00. This code depends on %cs:%ip being 0:0x7c00 + * + * The initial chunk of instructions is used as a signature by external + * tools (e.g. boot0cfg) which can manipulate the block itself. + * + * The area at offset 0x1b2 contains a magic string ('Drive '), also + * used as a signature to detect the block, and some variables that can + * be updated by boot0cfg (and optionally written back to the disk). + * These variables control the operation of the bootloader itself, + * e.g. which partitions to enable, the timeout, the use of LBA + * (called 'packet') or CHS mode, whether to force a drive number, + * and whether to write back the user's selection back to disk. + * + * As in every Master Boot Record, the partition table is at 0x1be, + * made of four 16-byte entries each containing: + * + * OFF SIZE DESCRIPTION + * 0 1 status (0x80: bootable, 0: non bootable) + * 1 3 start sector CHS + * 8:head, 6:sector, 2:cyl bit 9..8, 8:cyl bit 7..0 + * 4 1 partition type + * 5 3 end sector CHS + * 8 4 LBA of first sector + * 12 4 partition size in sectors + * + * and followed by the two bytes 0x55, 0xAA (MBR signature). + */ + + +/* + * BOOT BLOCK OPERATION + * + * On entry, the registers contain the following values: + * + * %cs:%ip 0:0x7c00 + * %dl drive number (0x80, 0x81, ... ) + * %si pointer to the partition table from which we were loaded. + * Some boot code (e.g. syslinux) use this info to relocate + * themselves, so we want to pass a valid one to the next stage. + * NOTE: the use of %is is not a standard. + * + * This boot block first relocates itself at a different address (0:0x600), + * to free the space at 0:0x7c00 for the next stage boot block. + * + * It then initializes some memory at 0:0x800 and above (pointed by %bp) + * to store the original drive number (%dl) passed to us, and to construct a + * fake partition entry. The latter is used by the disk I/O routine and, + * in some cases, passed in %si to the next stage boot code. + * + * The variables at 0x1b2 are accessed as negative offsets from %bp. + * + * After the relocation, the code scans the partition table printing + * out enabled partition or disks, and waits for user input. + * + * When a partition is selected, or a timeout expires, the currently + * selected partition is used to load the next stage boot code, + * %dl and %si are set appropriately as when we were called, and + * control is transferred to the newly loaded code at 0:0x7c00. + */ + +/* + * CONSTANTS + * + * NHRDRV is the address in segment 0 where the BIOS writes the + * total number of hard disks in the system. + * LOAD is the original load address and cannot be changed. + * ORIGIN is the relocation address. If you change it, you also need + * to change the value passed to the linker in the Makefile + * PRT_OFF is the location of the partition table (from the MBR standard). + * B0_OFF is the location of the data area, known to boot0cfg so + * it cannot be changed. + * MAGIC is the signature of a boot block. + */ + .set NHRDRV,0x475 # Number of hard drives .set ORIGIN,0x600 # Execution address - .set FAKE,0x800 # Partition entry .set LOAD,0x7c00 # Load address .set PRT_OFF,0x1be # Partition table - - .set TBL0SZ,0x3 # Table 0 size - .set TBL1SZ,0xa # Table 1 size + .set B0_OFF,0x1b2 # Offset of boot0 data .set MAGIC,0xaa55 # Magic: bootable - .set B0MAGIC,0xbb66 # Identification .set KEY_ENTER,0x1c # Enter key scan code .set KEY_F1,0x3b # F1 key scan code .set KEY_1,0x02 # #1 key scan code - .set ASCII_BEL,0x07 # ASCII code for + .set ASCII_BEL,'#' # ASCII code for .set ASCII_CR,0x0D # ASCII code for /* - * Addresses in the sector of embedded data values. - * Accessed with negative offsets from the end of the relocated sector (%ebp). - */ - .set _NXTDRV,-0x48 # Next drive - .set _OPT,-0x47 # Default option - .set _SETDRV,-0x46 # Drive to force - .set _FLAGS,-0x45 # Flags - .set _TICKS,-0x44 # Timeout ticks - .set _FAKE,0x0 # Fake partition entry - .set _MNUOPT,0xc # Menu options + * Offsets of variables in the block at B0_OFF, and in the volatile + * data area, computed as displacement from %bp. + * We need to define them as constant as the assembler cannot + * compute them in its single pass. + */ + .set _NXTDRV, -0x48 # Next drive + .set _OPT, -0x47 # Default option + .set _SETDRV, -0x46 # Drive to force + .set _FLAGS, -0x45 # Flags + .set SETDRV, 0x20 # the 'setdrv' flag + .set NOUPDATE, 0x40 # the 'noupdate' flag + .set USEPACKET, 0x80 # the 'packet' flag + .set _TICKS, -0x44 # Timeout ticks + .set _FAKE,0x0 # Fake partition table + .set _MNUOPT, 0x10 # Saved menu entries + .set TLEN, (desc_ofs - bootable_ids) # size of bootable ids .globl start # Entry point .code16 # This runs in real mode /* + * MAIN ENTRY POINT * Initialise segments and registers to known values. * segments start at 0. * The stack is immediately below the address we were loaded to. + * NOTE: the initial section of the code (up to movw $LOAD,%sp) + * is used by boot0cfg, together with the 'Drive ' string and + * the 0x55, 0xaa at the end, as an identifier for version 1.0 + * of the boot code. Do not change it. + * In version 1.0 the parameter table (_NEXTDRV etc) is at 0x1b9 */ start: cld # String ops inc xorw %ax,%ax # Zero @@ -68,257 +177,318 @@ start: cld # String ops inc movw %ax,%ss # Set up movw $LOAD,%sp # stack -/* - * Copy this code to the address it was linked for - */ + /* + * Copy this code to the address it was linked for, 0x600 by default. + */ movw %sp,%si # Source movw $start,%di # Destination movw $0x100,%cx # Word count rep # Relocate movsw # code -/* - * Set address for variable space beyond code, and clear it. - * Notice that this is also used to point to the values embedded in the block, - * by using negative offsets. - */ + /* + * After the code, (i.e. at %di+0, 0x800) create a partition entry, + * initialized to LBA 0 / CHS 0:0:1. + * Set %bp to point to the partition and also, with negative offsets, + * to the variables embedded in the bootblock (nextdrv and so on). + */ movw %di,%bp # Address variables movb $0x8,%cl # Words to clear rep # Zero stosw # them -/* - * Relocate to the new copy of the code. - */ - incb -0xe(%di) # Sector number - jmp main-LOAD+ORIGIN # To relocated code + incb -0xe(%di) # Set the S field to 1 + + jmp main-LOAD+ORIGIN # Jump to relocated code main: #if defined(SIO) && COMSPEED != 0 -/* - * Initialize the serial port. bioscom preserves the driver number in DX. - */ + /* + * Init the serial port. bioscom preserves the driver number in DX. + */ movw $COMSPEED,%ax # defined by Makefile callw bioscom #endif -/* - * Check what flags were loaded with us, specifically if a predefined drive - * number should be used. If what the bios gives us is bad, use the '0' in - * the block instead. - */ - testb $0x20,_FLAGS(%bp) # Set drive number? - jnz main.1 # Yes + + /* + * If the 'setdrv' flag is set in the boot sector, use the drive + * number from the boot sector at 'setdrv_num'. + * Optionally, do the same if the BIOS gives us an invalid number + * (note though that the override prevents booting from a floppy + * or a ZIP/flash drive in floppy emulation). + * The test costs 4 bytes of code so it is disabled by default. + */ + testb $SETDRV,_FLAGS(%bp) # Set drive number? +#ifndef CHECK_DRIVE /* disable drive checks */ + jz save_curdrive # no, use the default +#else + jnz disable_update # Yes testb %dl,%dl # Drive number valid? - js main.2 # Possibly (0x80 set) -/* - * Only update the boot-sector when there is a valid drive number or - * the drive number is set manually. - */ - orb $0x40,_FLAGS(%bp) # Disable updates -main.1: movb _SETDRV(%bp),%dl # Drive number to use -/* - * Whatever we decided to use, now store it into the fake - * partition entry that lives in the data space above us. - */ -main.2: movb %dl,_FAKE(%bp) # Save drive number - callw putn # To new line - pushw %dx # Save drive number -/* - * Start out with a pointer to the 4th byte of the first table entry - * so that after 4 iterations it's beyond the end of the sector - * and beyond a 256 byte boundary and has overflowed 8 bits (see next comment). - * Remember that the table starts 2 bytes earlier than you would expect - * as the bootable flag is after it in the block. - */ + js save_curdrive # Possibly (0x80 set) +#endif + /* + * Disable updates if the drive number is forced. + */ +disable_update: orb $NOUPDATE,_FLAGS(%bp) # Disable updates + movb _SETDRV(%bp),%dl # Use stored drive number + + /* + * Whatever drive we decided to use, store it at (%bp). The byte + * is normally used for the state of the partition (0x80 or 0x00), + * but we abuse it as it is very convenient to access at offset 0. + * The value is read back after 'check_selection' + */ +save_curdrive: movb %dl, (%bp) # Save drive number + pushw %dx # Also in the stack +#ifdef TEST /* test code, print internal bios drive */ + rolb $1, %dl + movw $drive, %si + call putkey +#endif + callw putn # Print a newline + /* + * Start out with a pointer to the 4th byte of the first table entry + * so that after 4 iterations it's beyond the end of the sector + * and beyond a 256 byte boundary. We use the latter trick to check for + * end of the loop without using an extra register (see start.5). + */ movw $(partbl+0x4),%bx # Partition table (+4) xorw %dx,%dx # Item number -/* - * Loop around on the partition table, printing values until we - * pass a 256 byte boundary. The end of loop test is at main.5. - */ -main.3: movb %ch,-0x4(%bx) # Zero active flag (ch == 0) + + /* + * Loop around on the partition table, printing values until we + * pass a 256 byte boundary. + */ +read_entry: movb %ch,-0x4(%bx) # Zero active flag (ch == 0) btw %dx,_FLAGS(%bp) # Entry enabled? - jnc main.5 # No -/* - * If any of the entries in the table are the same as the 'type' in the slice - * table entry, then this is an empty or non bootable partition. Skip it. - */ + jnc next_entry # No + /* + * Lookup type in the 'non_bootable_ids' table, skip matching entries. + * This is implemented is by setting %di to the start of the + * exclude table, and %cl to the length of the table itself. After the + * 'repne scasb' the zero flag is set if we found a match. + * If not, %di points to the beginning of the 'valid' types, + * which is what we need for the next check. + */ movb (%bx),%al # Load type - movw $tables,%di # Lookup tables - movb $TBL0SZ,%cl # Number of entries + movw $non_bootable_ids,%di # Lookup tables + movb $(bootable_ids-non_bootable_ids),%cl # length repne # Exclude scasb # partition? - je main.5 # Yes -/* - * Now scan the table of known types - */ - movb $TBL1SZ+1,%cl # Number of entries + je next_entry # Yes, ignore it + /* + * Now scan the table of bootable ids, which starts at %di and has + * length TLEN. On a match, %di points to the element following the + * match; the corresponding offset to the description is $(TLEN-1) + * bytes ahead. If we don't find a match, we hit the 'unknown' entry. + */ + movb $(TLEN),%cl # Number of entries repne # Locate scasb # type -/* - * Get the matching element in the next array. - */ - addw $TBL1SZ-1, %di # Adjust + /* + * Get the matching element in the next array. + * The byte at $(TLEN-1)(%di) contains the offset of the description + * string from %di, so we add the number and print the string. + */ + addw $(TLEN-1), %di # Adjust movb (%di),%cl # Partition addw %cx,%di # description callw putx # Display it -main.5: incw %dx # Next item + +next_entry: incw %dx # Next item addb $0x10,%bl # Next entry - jnc main.3 # Till done -/* - * Passed a 256 byte boundary; the table is finished. - * Add one to the drive number and check it is valid. - */ + jnc read_entry # Till done + /* + * We are past a 256 byte boundary: the partition table is finished. + * Add one to the drive number and check it is valid. + * Note that if we started from a floppy, %dl was 0 so we still + * get an entry for the next drive, which is the first Hard Disk. + */ popw %ax # Drive number subb $0x80-0x1,%al # Does next cmpb NHRDRV,%al # drive exist? (from BIOS?) - jb main.6 # Yes -/* - * If this is the only drive, don't display it as an option. - */ + jb print_drive # Yes + /* + * If this is the only drive, don't display it as an option. + */ decw %ax # Already drive 0? - jz main.7 # Yes -/* - * If it was illegal or we cycled through them, go back to drive 0. - */ + jz print_prompt # Yes + /* + * If it was illegal or we cycled through them, go back to drive 0. + */ xorb %al,%al # Drive 0 -/* - * Whatever drive we selected, make it an ascii digit and save it back to the - * "next drive" location in the loaded block in case we want to save it later - * for next time. This also is part of the printed drive string so add 0x80 - * to indicate end of string. - */ -main.6: addb $'0'|0x80,%al # Save next + /* + * Whatever drive we selected, make it an ascii digit and save it + * back to the "nxtdrv" location in case we want to save it to disk. + * This digit is also part of the printed drive string, so add 0x80 + * to indicate end of string. + */ +print_drive: addb $'0'|0x80,%al # Save next movb %al,_NXTDRV(%bp) # drive number movw $drive,%di # Display callw putx # item -/* - * Now that we've printed the drive (if we needed to), display a prompt. - */ -main.7: movw $prompt,%si # Display + /* + * Menu is complete, display a prompt followed by current selection. + * 'decw %si' makes the register point to the space after 'Default: ' + * so we do not see an extra CRLF on the screen. + */ +print_prompt: movw $prompt,%si # Display callw putstr # prompt movb _OPT(%bp),%dl # Display decw %si # default callw putkey # key - jmp main.7_1 # Skip beep -/* - * Users's last try was bad, beep in displeasure. - */ -main.10: movb $ASCII_BEL,%al # Signal - callw putchr # beep! + jmp start_input # Skip beep + /* - * Start of input loop. Take note of time + * Here we have the code waiting for user input or a timeout. */ -main.7_1: xorb %ah,%ah # BIOS: Get +beep: movb $ASCII_BEL,%al # Input error, print or beep + callw putchr + +start_input: + /* + * Actual Start of input loop. Take note of time + */ + xorb %ah,%ah # BIOS: Get int $0x1a # system time movw %dx,%di # Ticks when addw _TICKS(%bp),%di # timeout -/* - * Busy loop, looking for keystrokes but keeping one eye on the time. - */ -main.8: +read_key: + /* + * Busy loop, looking for keystrokes but keeping one eye on the time. + */ #ifndef SIO movb $0x1,%ah # BIOS: Check int $0x16 # for keypress - jnz main.11 # Have one #else /* SIO */ movb $0x03,%ah # BIOS: Read COM call bioscom testb $0x01,%ah # Check line status - jnz main.11 # (bit 1 indicates input) + # (bit 1 indicates input) #endif /* SIO */ - xorb %ah,%ah # BIOS: Get - int $0x1a # system time + jnz got_key # Have input + xorb %ah,%ah # BIOS: int 0x1a, 00 + int $0x1a # get system time cmpw %di,%dx # Timeout? - jb main.8 # No -/* - * If timed out or defaulting, come here. - */ -main.9: movb _OPT(%bp),%al # Load default - jmp main.12 # Join common code -/* - * Get the keystroke. - */ -main.11: + jb read_key # No + + /* + * Timed out or default selection + */ +use_default: movb _OPT(%bp),%al # Load default + jmp check_selection # Join common code + + /* + * Get the keystroke. + * ENTER or CR confirm the current selection (same as a timeout). + * Otherwise convert F1..F6 (or '1'..'6') to 0..5 and check if the + * selection is valid. + * The SIO code uses ascii chars, the console code uses scancodes. + */ +got_key: #ifndef SIO - xorb %ah,%ah # BIOS: Get - int $0x16 # keypress - movb %ah,%al # Scan code + xorb %ah,%ah # BIOS: int 0x16, 00 + int $0x16 # get keypress + movb %ah,%al # move scan code to %al + cmpb $KEY_ENTER,%al #else movb $0x02,%ah # BIOS: Receive call bioscom + cmpb $ASCII_CR,%al #endif -/* - * If it's CR act as if timed out. - */ -#ifndef SIO - cmpb $KEY_ENTER,%al # Enter pressed? -#else - cmpb $ASCII_CR,%al # Enter pressed? -#endif - je main.9 # Yes -/* - * Otherwise check if legal. If not ask again. - */ -#ifndef SIO - subb $KEY_F1,%al # Less F1 scan code - cmpb $0x4,%al # F1..F5? - jna main.12 # Yes + je use_default # enter -> default + /* + * Check if the key is acceptable, and loop back if not. + * The console (non-SIO) code looks at scancodes and accepts + * both F1..F6 and 1..6 (the latter costs 6 bytes of code), + * relying on the fact that F1..F6 have higher scancodes than 1..6 + * The SIO code only takes 1..6 + */ +#ifdef SIO /* SIO mode, use ascii values */ + subb $'1',%al # Subtract '1' ascii code +#else /* console mode -- use scancodes */ + subb $KEY_F1,%al /* Subtract F1 scan code */ +#if !defined(ONLY_F_KEYS) + cmpb $0x5,%al # F1..F6 + jna 3f # Yes subb $(KEY_1 - KEY_F1),%al # Less #1 scan code -#else - subb $'1',%al # Less '1' ascii character -#endif - cmpb $0x4,%al # #1..#5? - ja main.10 # No -/* - * We have a selection. If it's a bad selection go back to complain. - * The bits in MNUOPT were set when the options were printed. - * Anything not printed is not an option. - */ -main.12: cbtw # Option - btw %ax,_MNUOPT(%bp) # enabled? - jnc main.10 # No -/* - * Save the info in the original tables - * for rewriting to the disk. - */ + 3: +#endif /* ONLY_F_KEYS */ +#endif /* SIO */ + cmpb $0x5,%al # F1..F6 or 1..6 ? +#ifdef PXE /* enable PXE/INT18 using F6 */ + jne 1f; + int $0x18 # found F6, try INT18 + 1: +#endif /* PXE */ + jae beep # Not in F1..F5, beep + +check_selection: + /* + * We have a selection. If it's a bad selection go back to complain. + * The bits in MNUOPT were set when the options were printed. + * Anything not printed is not an option. + */ + cbtw # Extend (%ah=0 used later) + btw %ax,_MNUOPT(%bp) # Option enabled? + jnc beep # No + /* + * Save the info in the original tables + * for rewriting to the disk. + */ movb %al,_OPT(%bp) # Save option - movw $FAKE,%si # Partition for write - movb (%si),%dl # Drive number + + /* + * Make %si and %bx point to the fake partition at LBA 0 (CHS 0:0:1). + * Because the correct address is already in %bp, just use it. + * Set %dl with the drive number saved in byte 0. + * If we have pressed F5 or 5, then this is a good, fake value + * to present to the next stage boot code. + */ + movw %bp,%si # Partition for write + movb (%si),%dl # Drive number, saved above movw %si,%bx # Partition for read cmpb $0x4,%al # F5/#5 pressed? - pushf # Save - je main.13 # Yes + pushf # Save results for later + je 1f # Yes, F5 + + /* + * F1..F4 was pressed, so make %bx point to the currently + * selected partition, and leave the drive number unchanged. + */ shlb $0x4,%al # Point to addw $partbl,%ax # selected xchgw %bx,%ax # partition movb $0x80,(%bx) # Flag active -/* - * If not asked to do a write-back (flags 0x40) don't do one. - */ -main.13: pushw %bx # Save - testb $0x40,_FLAGS(%bp) # No updates? - jnz main.14 # Yes + /* + * If not asked to do a write-back (flags 0x40) don't do one. + * Around the call, save the partition pointer to %bx and + * restore to %si which is where the next stage expects it. + */ + 1: pushw %bx # Save + testb $NOUPDATE,_FLAGS(%bp) # No updates? + jnz 2f # skip update movw $start,%bx # Data to write movb $0x3,%ah # Write sector callw intx13 # to disk -main.14: popw %si # Restore - popf # Restore -/* - * If going to next drive, replace drive with selected one. - * Remember to un-ascii it. Hey 0x80 is already set, cool! - */ - jne main.15 # If not F5/#5 + 2: popw %si # Restore + + /* + * If going to next drive, replace drive with selected one. + * Remember to un-ascii it. Hey 0x80 is already set, cool! + */ + popf # Restore %al test results + jne 3f # If not F5/#5 movb _NXTDRV(%bp),%dl # Next drive subb $'0',%dl # number -/* - * Load selected bootsector to the LOAD location in RAM. - * If it fails to read or isn't marked bootable, treat it as a bad selection. - */ -main.15: movw $LOAD,%bx # Address for read + /* + * Load selected bootsector to the LOAD location in RAM. If read + * fails or there is no 0x55aa marker, treat it as a bad selection. + */ + 3: movw $LOAD,%bx # Address for read movb $0x2,%ah # Read sector callw intx13 # from disk - jc main.10 # If error + jc beep # If error cmpw $MAGIC,0x1fe(%bx) # Bootable? - jne main.10 # No + jne beep # No pushw %si # Save ptr to selected part. callw putn # Leave some space popw %si # Restore, next stage uses it @@ -326,6 +496,14 @@ main.15: movw $LOAD,%bx # Address for /* * Display routines + * putkey prints the option selected in %dl (F1..F5 or 1..5) followed by + * the string at %si + * putx: print the option in %dl followed by the string at %di + * also record the drive as valid. + * puts: print the string at %si followed by a crlf + * putn: print a crlf + * putstr: print the string at %si + * putchr: print the char in al */ putkey: #ifndef SIO @@ -337,8 +515,9 @@ putkey: jmp putstr.1 # Display the rest /* - * Display the option and note that it is a valid option. - * That last point is a bit tricky.. + * Display the option and record the drive as valid in the options. + * That last point is done using the btsw instruction which does + * a test and set. We don't care for the test part. */ putx: btsw %dx,_MNUOPT(%bp) # Enable menu option movw $item,%si # Display @@ -356,34 +535,43 @@ putstr.1: callw putchr # Display char jmp putstr # Continue putstr.2: andb $~0x80,%al # Clear MSB -#ifndef SIO putchr: +#ifndef SIO pushw %bx # Save movw $0x7,%bx # Page:attribute movb $0xe,%ah # BIOS: Display int $0x10 # character popw %bx # Restore - retw # To caller #else /* SIO */ -putchr: movb $0x01,%ah # BIOS: Send bioscom: pushw %dx # Save xorw %dx,%dx # Use COM1 int $0x14 # Character popw %dx # Restore - retw # To caller #endif /* SIO */ + retw # To caller /* One-sector disk I/O routine */ -intx13: movb 0x1(%si),%dh # Load head +/* + * %dl: drive, %si partition entry, %es:%bx transfer buffer. + * Load the CHS values and possibly the LBA address from the block + * at %si, and use the appropriate method to load the sector. + * Don't use packet mode for a floppy. + */ +intx13: # Prepare CHS parameters + movb 0x1(%si),%dh # Load head movw 0x2(%si),%cx # Load cylinder:sector movb $0x1,%al # Sector count pushw %si # Save movw %sp,%di # Save - testb $0x80,_FLAGS(%bp) # Use packet interface? - jz intx13.1 # No +#ifndef CHECK_DRIVE /* floppy support */ + testb %dl, %dl # is this a floppy ? + jz 1f # Yes, use CHS mode +#endif + testb $USEPACKET,_FLAGS(%bp) # Use packet interface? + jz 1f # No pushl $0x0 # Set the pushl 0x8(%si) # LBA address pushw %es # Set the transfer @@ -393,73 +581,95 @@ intx13: movb 0x1(%si),%dh # Load head movw %sp,%si # Packet pointer decw %ax # Verify off orb $0x40,%ah # Use disk packet -intx13.1: int $0x13 # BIOS: Disk I/O + 1: int $0x13 # BIOS: Disk I/O movw %di,%sp # Restore popw %si # Restore retw # To caller -/* Menu strings */ - +/* + * Various menu strings. 'item' goes after 'prompt' to save space. + * Also use shorter versions to make room for the PXE/INT18 code. + */ +#ifdef PXE +prompt: .ascii "\nBoot:" +item: .ascii " "; .byte ' '|0x80 +#else +prompt: .ascii "\nDefault:" item: .ascii " "; .byte ' '|0x80 -prompt: .ascii "\nDefault:"; .byte ' '|0x80 +#endif crlf: .ascii "\r"; .byte '\n'|0x80 /* Partition type tables */ -tables: -/* - * These entries identify invalid or NON BOOT types and partitions. - */ +non_bootable_ids: + /* + * These entries identify invalid or NON BOOT types and partitions. + * 0: empty, 5: DOS3 ext. partition, 0xf: WIN95 ext partition + */ .byte 0x0, 0x5, 0xf -/* - * These values indicate bootable types we know the names of. - */ +bootable_ids: + /* + * These values indicate bootable types we know the names of. + * 1: FAT12, 4: FAT16 <32M, 6: FAT16 > 32M, 7: NTFS + * 0xb: FAT32, 0xc: FAT32-LBA, 0xe: FAT16-LBA, + * 0x83: linux, 0xa5: FreeBSD, 0xa6: netbsd, 0xa9:openbsd + */ .byte 0x1, 0x6, 0x7, 0xb, 0xc, 0xe, 0x83 - .byte 0xa5, 0xa6, 0xa9 -/* - * These are offsets that match the known names above and point to the strings - * that will be printed. os_misc will be used if the search of the above table - * runs over. - */ - .byte os_dos-. # DOS - .byte os_dos-. # DOS - .byte os_dos-. # Windows - .byte os_dos-. # Windows - .byte os_dos-. # Windows - .byte os_dos-. # Windows - .byte os_linux-. # Linux - .byte os_freebsd-. # FreeBSD - .byte os_bsd-. # OpenBSD - .byte os_bsd-. # NetBSD + .byte 0xa5, 0xa6, 0xa9, 0x4 +desc_ofs: + /* + * Offsets that match the known types above, used to point to the + * actual partition name. The last entry must point to os_misc, + * which is used for non-matching names. + */ + .byte os_dos-. # 1, DOS + .byte os_dos-. # 6, DOS/WIN + .byte os_win-. # 7, Windows + .byte os_win-. # 11, Windows + .byte os_win-. # 12, Windows + .byte os_win-. # 14, Windows + .byte os_linux-. # 131, Linux + .byte os_freebsd-. # 165, FreeBSD + .byte os_bsd-. # 166, OpenBSD + .byte os_bsd-. # 169, NetBSD + .byte os_dos-. # 4, DOS .byte os_misc-. # Unknown -/* - * And here are the strings themselves. 0x80 or'd into a byte indicates - * the end of the string. (not so great for Russians but...) - */ -os_misc: .ascii "?"; .byte '?'|0x80 -os_dos: .ascii "DO"; .byte 'S'|0x80 + + /* + * And here are the strings themselves. The last byte of + * the string has bit 7 set. + */ +os_misc: .byte '?'|0x80 +os_dos: +#if !defined(TEST) /* DOS string only if room */ + .ascii "DO"; .byte 'S'|0x80 +#endif +os_win: .ascii "WI"; .byte 'N'|0x80 os_linux: .ascii "Linu"; .byte 'x'|0x80 os_freebsd: .ascii "Free" os_bsd: .ascii "BS"; .byte 'D'|0x80 - .org PRT_OFF-0xe,0x90 - - .word B0MAGIC # Magic number - + .org B0_OFF,0x90 /* - * These values are sometimes changed before writing back to the drive + * The boot0 version 1.0 parameter table. + * Do not move it nor change the "Drive " string, boot0cfg + * uses its offset and content to identify the boot sector. + * The other fields are sometimes changed before writing back to the drive * Be especially careful that nxtdrv: must come after drive:, as it * is part of the same string. */ drive: .ascii "Drive " nxtdrv: .byte 0x0 # Next drive number opt: .byte 0x0 # Option -setdrv: .byte 0x80 # Drive to force +setdrv_num: .byte 0x80 # Drive to force flags: .byte FLAGS # Flags ticks: .word TICKS # Delay + .org PRT_OFF /* * Here is the 64 byte partition table that fdisk would fiddle with. */ partbl: .fill 0x40,0x1,0x0 # Partition table .word MAGIC # Magic number + .org 0x200 # again, safety check +endblock: From peter at FreeBSD.org Tue Dec 2 07:08:33 2008 From: peter at FreeBSD.org (Peter Wemm) Date: Tue Dec 2 07:08:40 2008 Subject: svn commit: r185563 - head/usr.bin/procstat Message-ID: <200812021508.mB2F8X76063721@svn.freebsd.org> Author: peter Date: Tue Dec 2 15:08:33 2008 New Revision: 185563 URL: http://svn.freebsd.org/changeset/base/185563 Log: Update format string for kve_start/end. Modified: head/usr.bin/procstat/procstat_vm.c Modified: head/usr.bin/procstat/procstat_vm.c ============================================================================== --- head/usr.bin/procstat/procstat_vm.c Tue Dec 2 14:57:48 2008 (r185562) +++ head/usr.bin/procstat/procstat_vm.c Tue Dec 2 15:08:33 2008 (r185563) @@ -34,6 +34,7 @@ #include #include #include +#include #include #include "procstat.h" @@ -56,8 +57,8 @@ procstat_vm(pid_t pid, struct kinfo_proc for (i = 0; i < cnt; i++) { kve = &freep[i]; printf("%5d ", pid); - printf("%*p ", ptrwidth, kve->kve_start); - printf("%*p ", ptrwidth, kve->kve_end); + printf("%#*jx ", ptrwidth, (uintmax_t)kve->kve_start); + printf("%#*jx ", ptrwidth, (uintmax_t)kve->kve_end); printf("%s", kve->kve_protection & KVME_PROT_READ ? "r" : "-"); printf("%s", kve->kve_protection & KVME_PROT_WRITE ? "w" : "-"); printf("%s ", kve->kve_protection & KVME_PROT_EXEC ? "x" : "-"); From peter at wemm.org Tue Dec 2 07:21:26 2008 From: peter at wemm.org (Peter Wemm) Date: Tue Dec 2 07:21:38 2008 Subject: svn commit: r185563 - head/usr.bin/procstat In-Reply-To: <200812021508.mB2F8X76063721@svn.freebsd.org> References: <200812021508.mB2F8X76063721@svn.freebsd.org> Message-ID: On Tue, Dec 2, 2008 at 7:08 AM, Peter Wemm wrote: > Log: > Update format string for kve_start/end. I'm sorry everyone. This was really poor form. Lesson's I've learned: 1) When you test build, make sure you use the source tree that you actually applied the patches to. 2) Testing individual components of a change in isolation doesn't always catch that. (eg: the procstat change didn't cause a problem without the update in /usr/include) 3) I need some bandages for my foot. -Peter -- Peter Wemm - peter@wemm.org; peter@FreeBSD.org; peter@yahoo-inc.com; KI6FJV "All of this is for nothing if we don't go to the stars" - JMS/B5 "If Java had true garbage collection, most programs would delete themselves upon execution." -- Robert Sewell From des at des.no Tue Dec 2 07:25:20 2008 From: des at des.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Tue Dec 2 07:25:31 2008 Subject: svn commit: r185563 - head/usr.bin/procstat In-Reply-To: (Peter Wemm's message of "Tue, 2 Dec 2008 07:21:24 -0800") References: <200812021508.mB2F8X76063721@svn.freebsd.org> Message-ID: <861vwq4n1d.fsf@ds4.des.no> "Peter Wemm" writes: > 3) I need some bandages for my foot. I thought feet were rwatson's specialty, and yours was screen doors? *ducks* *runs* DES -- Dag-Erling Sm?rgrav - des@des.no From gnn at FreeBSD.org Tue Dec 2 07:42:48 2008 From: gnn at FreeBSD.org (George V. Neville-Neil) Date: Tue Dec 2 07:42:59 2008 Subject: svn commit: r185564 - head/sys/dev/cxgb/common Message-ID: <200812021542.mB2FglPS064504@svn.freebsd.org> Author: gnn Date: Tue Dec 2 15:42:47 2008 New Revision: 185564 URL: http://svn.freebsd.org/changeset/base/185564 Log: Bug fix from Chelsio which addresses the issue of the device resetting when it sees only received packets. In some cases where a device only recieves data it mistakenly thinks that its transmitting side is broken and resets the device. Obtained from: Chelsio Inc. MFC after: 3 days Modified: head/sys/dev/cxgb/common/cxgb_xgmac.c Modified: head/sys/dev/cxgb/common/cxgb_xgmac.c ============================================================================== --- head/sys/dev/cxgb/common/cxgb_xgmac.c Tue Dec 2 15:08:33 2008 (r185563) +++ head/sys/dev/cxgb/common/cxgb_xgmac.c Tue Dec 2 15:42:47 2008 (r185564) @@ -633,20 +633,15 @@ int t3b2_mac_watchdog_task(struct cmac * adapter_t *adap = mac->adapter; struct mac_stats *s = &mac->stats; unsigned int tx_mcnt = (unsigned int)s->tx_frames; - unsigned int rx_mcnt = (unsigned int)s->rx_frames; - unsigned int rx_xcnt; if (mac->multiport) { tx_mcnt = t3_read_reg(adap, A_XGM_STAT_TX_FRAME_LOW); - rx_mcnt = t3_read_reg(adap, A_XGM_STAT_RX_FRAMES_LOW); } else { tx_mcnt = (unsigned int)s->tx_frames; - rx_mcnt = (unsigned int)s->rx_frames; } status = 0; tx_xcnt = 1; /* By default tx_xcnt is making progress*/ tx_tcnt = mac->tx_tcnt; /* If tx_mcnt is progressing ignore tx_tcnt*/ - rx_xcnt = 1; /* By default rx_xcnt is making progress*/ if (tx_mcnt == mac->tx_mcnt && mac->rx_pause == s->rx_pause) { tx_xcnt = (G_TXSPI4SOPCNT(t3_read_reg(adap, A_XGM_TX_SPI4_SOP_EOP_CNT + @@ -657,11 +652,11 @@ int t3b2_mac_watchdog_task(struct cmac * tx_tcnt = (G_TXDROPCNTCH0RCVD(t3_read_reg(adap, A_TP_PIO_DATA))); } else { - goto rxcheck; + goto out; } } else { mac->toggle_cnt = 0; - goto rxcheck; + goto out; } if ((tx_tcnt != mac->tx_tcnt) && (mac->tx_xcnt == 0)) { @@ -674,22 +669,6 @@ int t3b2_mac_watchdog_task(struct cmac * } } else { mac->toggle_cnt = 0; - goto rxcheck; - } - -rxcheck: - if (rx_mcnt != mac->rx_mcnt) { - rx_xcnt = (G_TXSPI4SOPCNT(t3_read_reg(adap, - A_XGM_RX_SPI4_SOP_EOP_CNT + - mac->offset))) + - (s->rx_fifo_ovfl - mac->rx_ocnt); - mac->rx_ocnt = s->rx_fifo_ovfl; - } else - goto out; - - if (mac->rx_mcnt != s->rx_frames && rx_xcnt == 0 && mac->rx_xcnt == 0) { - if (!mac->multiport) - status = 2; goto out; } @@ -697,8 +676,6 @@ out: mac->tx_tcnt = tx_tcnt; mac->tx_xcnt = tx_xcnt; mac->tx_mcnt = s->tx_frames; - mac->rx_xcnt = rx_xcnt; - mac->rx_mcnt = s->rx_frames; mac->rx_pause = s->rx_pause; if (status == 1) { t3_write_reg(adap, A_XGM_TX_CTRL + mac->offset, 0); From kensmith at FreeBSD.org Tue Dec 2 08:46:01 2008 From: kensmith at FreeBSD.org (Ken Smith) Date: Tue Dec 2 08:46:13 2008 Subject: svn commit: r185565 - head/etc Message-ID: <200812021646.mB2Gk1Xj065909@svn.freebsd.org> Author: kensmith Date: Tue Dec 2 16:46:01 2008 New Revision: 185565 URL: http://svn.freebsd.org/changeset/base/185565 Log: The slip.log file got removed along with the MPSAFE tty work. If slip does ever come back it's probably best if its log file be something that gets added if the user decided they want to run slip instead of having it here unconditionally. Modified: head/etc/newsyslog.conf Modified: head/etc/newsyslog.conf ============================================================================== --- head/etc/newsyslog.conf Tue Dec 2 15:42:47 2008 (r185564) +++ head/etc/newsyslog.conf Tue Dec 2 16:46:01 2008 (r185565) @@ -33,7 +33,6 @@ /var/log/ppp.log root:network 640 3 100 * JC /var/log/security 600 10 100 * JC /var/log/sendmail.st 640 10 * 168 B -/var/log/slip.log root:network 640 3 100 * J /var/log/weekly.log 640 5 1 $W6D0 JN /var/log/wtmp 644 3 * @01T05 B /var/log/xferlog 600 7 100 * JC From sam at freebsd.org Tue Dec 2 08:57:19 2008 From: sam at freebsd.org (Sam Leffler) Date: Tue Dec 2 08:57:30 2008 Subject: svn commit: r185544 - head/sys/modules/ae In-Reply-To: <20081202064345.S80401@maildrop.int.zabbadoz.net> References: <200812020445.mB24jXaS048636@svn.freebsd.org> <20081202064345.S80401@maildrop.int.zabbadoz.net> Message-ID: <493568EE.20609@freebsd.org> Bjoern A. Zeeb wrote: > On Tue, 2 Dec 2008, Paul Saab wrote: > >> Author: ps >> Date: Tue Dec 2 04:45:33 2008 >> New Revision: 185544 >> URL: http://svn.freebsd.org/changeset/base/185544 >> >> Log: >> Fix world by including opt_route.h > > Where did world fail for you? > > I assume what failed was a single direct module build? Per discussion > on current@ we are working on this but it's a long list of files with > awkward dependencies to go through. > > If that was the only problem, the manual module build, please let me > know so I can back this out again as soon as the vimage header files > are untangled. Note I added explicit opt_route.h to all the ath-related modules because I hit problems too. I must've missed the discussion on current@. Sam From bz at FreeBSD.org Tue Dec 2 09:15:09 2008 From: bz at FreeBSD.org (Bjoern A. Zeeb) Date: Tue Dec 2 09:15:21 2008 Subject: svn commit: r185544 - head/sys/modules/ae In-Reply-To: <493568EE.20609@freebsd.org> References: <200812020445.mB24jXaS048636@svn.freebsd.org> <20081202064345.S80401@maildrop.int.zabbadoz.net> <493568EE.20609@freebsd.org> Message-ID: <20081202170528.S80401@maildrop.int.zabbadoz.net> On Tue, 2 Dec 2008, Sam Leffler wrote: Hi, > Bjoern A. Zeeb wrote: >> On Tue, 2 Dec 2008, Paul Saab wrote: >> >>> Author: ps >>> Date: Tue Dec 2 04:45:33 2008 >>> New Revision: 185544 >>> URL: http://svn.freebsd.org/changeset/base/185544 >>> >>> Log: >>> Fix world by including opt_route.h >> >> Where did world fail for you? >> >> I assume what failed was a single direct module build? Per discussion >> on current@ we are working on this but it's a long list of files with >> awkward dependencies to go through. >> >> If that was the only problem, the manual module build, please let me >> know so I can back this out again as soon as the vimage header files >> are untangled. > Note I added explicit opt_route.h to all the ath-related modules because I > hit problems too. I must've missed the discussion on current@. No problem and thanks for the note. I have removed them all and then readded the ones still (really) needed. The universe that is currently building doesn't have them in ath*/Makefiles and ae/Makefile anymore. Did a make depend in sys/modules/ and after the initial untangling we are down from ~390 to 14 modules still inlcuding vnet.h and thus depending on opt_route.h A veriosn of the patch is here: http://people.freebsd.org/~bz/20081202-v-h-06.diff There is more cleanup to follow afterwards. I also found quite a few other spots going through more >100 files... but that's initally unrelated and in my general "INET cleanup" pigeonhole. /bz -- Bjoern A. Zeeb Stop bit received. Insert coin for new game. From kensmith at FreeBSD.org Tue Dec 2 10:13:30 2008 From: kensmith at FreeBSD.org (Ken Smith) Date: Tue Dec 2 10:13:37 2008 Subject: svn commit: r185566 - head/etc Message-ID: <200812021813.mB2IDTig067634@svn.freebsd.org> Author: kensmith Date: Tue Dec 2 18:13:29 2008 New Revision: 185566 URL: http://svn.freebsd.org/changeset/base/185566 Log: Remove slip.log. Slip got removed as part of the MPSAFE tty work. If it does come back it would probably be better if users who were interested in slip added appropriate lines instead of this being here unconditionally. Reminded by: tut nhamon com ua Modified: head/etc/syslog.conf Modified: head/etc/syslog.conf ============================================================================== --- head/etc/syslog.conf Tue Dec 2 16:46:01 2008 (r185565) +++ head/etc/syslog.conf Tue Dec 2 18:13:29 2008 (r185566) @@ -26,7 +26,5 @@ cron.* /var/log/cron # news.crit /var/log/news/news.crit # news.err /var/log/news/news.err # news.notice /var/log/news/news.notice -!startslip -*.* /var/log/slip.log !ppp *.* /var/log/ppp.log From ed at FreeBSD.org Tue Dec 2 11:09:09 2008 From: ed at FreeBSD.org (Ed Schouten) Date: Tue Dec 2 11:09:27 2008 Subject: svn commit: r185567 - in head/sys: amd64/conf i386/conf ia64/conf pc98/conf powerpc/conf sparc64/conf sun4v/conf Message-ID: <200812021909.mB2J98SL068818@svn.freebsd.org> Author: ed Date: Tue Dec 2 19:09:08 2008 New Revision: 185567 URL: http://svn.freebsd.org/changeset/base/185567 Log: Remove "[KEEP THIS!]" from COMPAT_43TTY. It's not really that important. Sgtty is a programming interface that has been replaced by termios over the years. In June we already removed , which exposes the ioctl()'s that are implemented by this interface. The importance of this flag is overrated right now. Modified: head/sys/amd64/conf/GENERIC head/sys/i386/conf/GENERIC head/sys/i386/conf/XEN head/sys/ia64/conf/GENERIC head/sys/pc98/conf/GENERIC head/sys/powerpc/conf/GENERIC head/sys/sparc64/conf/GENERIC head/sys/sun4v/conf/GENERIC Modified: head/sys/amd64/conf/GENERIC ============================================================================== --- head/sys/amd64/conf/GENERIC Tue Dec 2 18:13:29 2008 (r185566) +++ head/sys/amd64/conf/GENERIC Tue Dec 2 19:09:08 2008 (r185567) @@ -48,7 +48,7 @@ options PROCFS # Process filesystem ( options PSEUDOFS # Pseudo-filesystem framework options GEOM_PART_GPT # GUID Partition Tables. options GEOM_LABEL # Provides labelization -options COMPAT_43TTY # BSD 4.3 TTY compat [KEEP THIS!] +options COMPAT_43TTY # BSD 4.3 TTY compat (sgtty) options COMPAT_IA32 # Compatible with i386 binaries options COMPAT_FREEBSD4 # Compatible with FreeBSD4 options COMPAT_FREEBSD5 # Compatible with FreeBSD5 Modified: head/sys/i386/conf/GENERIC ============================================================================== --- head/sys/i386/conf/GENERIC Tue Dec 2 18:13:29 2008 (r185566) +++ head/sys/i386/conf/GENERIC Tue Dec 2 19:09:08 2008 (r185567) @@ -49,7 +49,7 @@ options PROCFS # Process filesystem ( options PSEUDOFS # Pseudo-filesystem framework options GEOM_PART_GPT # GUID Partition Tables. options GEOM_LABEL # Provides labelization -options COMPAT_43TTY # BSD 4.3 TTY compat [KEEP THIS!] +options COMPAT_43TTY # BSD 4.3 TTY compat (sgtty) options COMPAT_FREEBSD4 # Compatible with FreeBSD4 options COMPAT_FREEBSD5 # Compatible with FreeBSD5 options COMPAT_FREEBSD6 # Compatible with FreeBSD6 Modified: head/sys/i386/conf/XEN ============================================================================== --- head/sys/i386/conf/XEN Tue Dec 2 18:13:29 2008 (r185566) +++ head/sys/i386/conf/XEN Tue Dec 2 19:09:08 2008 (r185567) @@ -31,7 +31,7 @@ options PROCFS # Process filesystem ( options PSEUDOFS # Pseudo-filesystem framework options GEOM_PART_GPT # GUID Partition Tables. options GEOM_LABEL # Provides labelization -options COMPAT_43TTY # BSD 4.3 TTY compat [KEEP THIS!] +options COMPAT_43TTY # BSD 4.3 TTY compat (sgtty) options COMPAT_FREEBSD4 # Compatible with FreeBSD4 options COMPAT_FREEBSD5 # Compatible with FreeBSD5 options COMPAT_FREEBSD6 # Compatible with FreeBSD6 Modified: head/sys/ia64/conf/GENERIC ============================================================================== --- head/sys/ia64/conf/GENERIC Tue Dec 2 18:13:29 2008 (r185566) +++ head/sys/ia64/conf/GENERIC Tue Dec 2 19:09:08 2008 (r185567) @@ -27,7 +27,7 @@ makeoptions DEBUG=-g # Build kernel with options AUDIT # Security event auditing options CD9660 # ISO 9660 Filesystem -options COMPAT_43TTY # BSD 4.3 TTY compat [KEEP THIS!] +options COMPAT_43TTY # BSD 4.3 TTY compat (sgtty) options COMPAT_FREEBSD6 # Compatible with FreeBSD6 options COMPAT_FREEBSD7 # Compatible with FreeBSD7 options DDB # Support DDB Modified: head/sys/pc98/conf/GENERIC ============================================================================== --- head/sys/pc98/conf/GENERIC Tue Dec 2 18:13:29 2008 (r185566) +++ head/sys/pc98/conf/GENERIC Tue Dec 2 19:09:08 2008 (r185567) @@ -49,7 +49,7 @@ options PROCFS # Process filesystem ( options PSEUDOFS # Pseudo-filesystem framework options GEOM_PART_GPT # GUID Partition Tables. options GEOM_LABEL # Provides labelization -options COMPAT_43TTY # BSD 4.3 TTY compat [KEEP THIS!] +options COMPAT_43TTY # BSD 4.3 TTY compat (sgtty) options COMPAT_FREEBSD4 # Compatible with FreeBSD4 options COMPAT_FREEBSD5 # Compatible with FreeBSD5 options COMPAT_FREEBSD6 # Compatible with FreeBSD6 Modified: head/sys/powerpc/conf/GENERIC ============================================================================== --- head/sys/powerpc/conf/GENERIC Tue Dec 2 18:13:29 2008 (r185566) +++ head/sys/powerpc/conf/GENERIC Tue Dec 2 19:09:08 2008 (r185567) @@ -50,7 +50,7 @@ options PROCFS #Process filesystem (r options PSEUDOFS #Pseudo-filesystem framework options GEOM_PART_GPT #GUID Partition Tables. options GEOM_LABEL #Provides labelization -options COMPAT_43TTY #BSD 4.3 TTY compat [KEEP THIS!] +options COMPAT_43TTY #BSD 4.3 TTY compat (sgtty) options COMPAT_FREEBSD4 #Keep this for a while options COMPAT_FREEBSD5 #Compatible with FreeBSD5 options COMPAT_FREEBSD6 #Compatible with FreeBSD6 Modified: head/sys/sparc64/conf/GENERIC ============================================================================== --- head/sys/sparc64/conf/GENERIC Tue Dec 2 18:13:29 2008 (r185566) +++ head/sys/sparc64/conf/GENERIC Tue Dec 2 19:09:08 2008 (r185567) @@ -52,7 +52,7 @@ options PROCFS # Process filesystem ( options PSEUDOFS # Pseudo-filesystem framework options GEOM_PART_GPT # GUID Partition Tables. options GEOM_LABEL # Provides labelization -options COMPAT_43TTY # BSD 4.3 TTY compat [KEEP THIS!] +options COMPAT_43TTY # BSD 4.3 TTY compat (sgtty) options COMPAT_FREEBSD5 # Compatible with FreeBSD5 options COMPAT_FREEBSD6 # Compatible with FreeBSD6 options COMPAT_FREEBSD7 # Compatible with FreeBSD7 Modified: head/sys/sun4v/conf/GENERIC ============================================================================== --- head/sys/sun4v/conf/GENERIC Tue Dec 2 18:13:29 2008 (r185566) +++ head/sys/sun4v/conf/GENERIC Tue Dec 2 19:09:08 2008 (r185567) @@ -51,8 +51,8 @@ options PROCFS # Process filesystem ( options PSEUDOFS # Pseudo-filesystem framework options GEOM_PART_GPT # GUID Partition Tables. options GEOM_LABEL # Provides labelization -options COMPAT_43 # Compatible with BSD 4.3 [KEEP THIS!] -options COMPAT_43TTY # BSD 4.3 TTY compat [KEEP THIS!] +options COMPAT_43 # Compatible with BSD 4.3 (sgtty) +options COMPAT_43TTY # BSD 4.3 TTY compat (sgtty) options COMPAT_FREEBSD5 # Compatible with FreeBSD5 options SCSI_DELAY=5000 # Delay (in ms) before probing SCSI options KTRACE # ktrace(1) support From phk at FreeBSD.org Tue Dec 2 11:49:41 2008 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue Dec 2 11:49:53 2008 Subject: svn commit: r185568 - head/lib/libmd Message-ID: <200812021949.mB2JnfZr069753@svn.freebsd.org> Author: phk Date: Tue Dec 2 19:49:41 2008 New Revision: 185568 URL: http://svn.freebsd.org/changeset/base/185568 Log: Make the "test" target test the compiled version, instead of the installed version of the md library. Modified: head/lib/libmd/Makefile Modified: head/lib/libmd/Makefile ============================================================================== --- head/lib/libmd/Makefile Tue Dec 2 19:09:08 2008 (r185567) +++ head/lib/libmd/Makefile Tue Dec 2 19:49:41 2008 (r185568) @@ -169,27 +169,27 @@ rmd160.ref: test: md2.ref md4.ref md5.ref sha0.ref rmd160.ref sha1.ref sha256.ref @${ECHO} if any of these test fail, the code produces wrong results @${ECHO} and should NOT be used. - ${CC} ${CFLAGS} ${LDFLAGS} -DMD=2 -o mddriver ${.CURDIR}/mddriver.c -L. -lmd + ${CC} ${CFLAGS} ${LDFLAGS} -DMD=2 -o mddriver ${.CURDIR}/mddriver.c ./libmd.a ./mddriver | cmp md2.ref - @${ECHO} MD2 passed test - ${CC} ${CFLAGS} ${LDFLAGS} -DMD=4 -o mddriver ${.CURDIR}/mddriver.c -L. -lmd + ${CC} ${CFLAGS} ${LDFLAGS} -DMD=4 -o mddriver ${.CURDIR}/mddriver.c libmd.a ./mddriver | cmp md4.ref - @${ECHO} MD4 passed test - ${CC} ${CFLAGS} ${LDFLAGS} -DMD=5 -o mddriver ${.CURDIR}/mddriver.c -L. -lmd + ${CC} ${CFLAGS} ${LDFLAGS} -DMD=5 -o mddriver ${.CURDIR}/mddriver.c libmd.a ./mddriver | cmp md5.ref - @${ECHO} MD5 passed test -rm -f mddriver - ${CC} ${CFLAGS} ${LDFLAGS} -o rmddriver ${.CURDIR}/rmddriver.c -L. -lmd + ${CC} ${CFLAGS} ${LDFLAGS} -o rmddriver ${.CURDIR}/rmddriver.c libmd.a ./rmddriver | cmp rmd160.ref - @${ECHO} RIPEMD160 passed test -rm -f rmddriver - ${CC} ${CFLAGS} ${LDFLAGS} -DSHA=0 -o shadriver ${.CURDIR}/shadriver.c -L. -lmd + ${CC} ${CFLAGS} ${LDFLAGS} -DSHA=0 -o shadriver ${.CURDIR}/shadriver.c libmd.a ./shadriver | cmp sha0.ref - @${ECHO} SHA-0 passed test - ${CC} ${CFLAGS} ${LDFLAGS} -DSHA=1 -o shadriver ${.CURDIR}/shadriver.c -L. -lmd + ${CC} ${CFLAGS} ${LDFLAGS} -DSHA=1 -o shadriver ${.CURDIR}/shadriver.c libmd.a ./shadriver | cmp sha1.ref - @${ECHO} SHA-1 passed test - ${CC} ${CFLAGS} ${LDFLAGS} -DSHA=256 -o shadriver ${.CURDIR}/shadriver.c -L. -lmd + ${CC} ${CFLAGS} ${LDFLAGS} -DSHA=256 -o shadriver ${.CURDIR}/shadriver.c libmd.a ./shadriver | cmp sha256.ref - @${ECHO} SHA-256 passed test -rm -f shadriver From jhb at freebsd.org Tue Dec 2 13:15:02 2008 From: jhb at freebsd.org (John Baldwin) Date: Tue Dec 2 13:15:17 2008 Subject: svn commit: r185557 - head/sys/kern In-Reply-To: <200812021114.mB2BEHB3058629@svn.freebsd.org> References: <200812021114.mB2BEHB3058629@svn.freebsd.org> Message-ID: <200812021419.37380.jhb@freebsd.org> On Tuesday 02 December 2008 06:14:17 am Konstantin Belousov wrote: > Author: kib > Date: Tue Dec 2 11:14:16 2008 > New Revision: 185557 > URL: http://svn.freebsd.org/changeset/base/185557 > > Log: > Shared lookup makes it possible to create several negative cache > entries for one name. Then, creating inode with that name would remove > one entry, leaving others dormant. Reclaiming the vnode would uncover > negative entries, causing false return of ENOENT from the calls like > stat, that do not create inode. > > Prevent creation of the duplicated negative entries. > > Reported and debugged with: pho > Reviewed by: jhb > X-MFC: after shared lookup changes Actually, the NFS client code already supports shared lookups in 6.x+, so I would suggest MFC'ing this in a week or so to both 6.x and 7.x. -- John Baldwin From jhb at freebsd.org Tue Dec 2 13:15:09 2008 From: jhb at freebsd.org (John Baldwin) Date: Tue Dec 2 13:15:28 2008 Subject: svn commit: r185562 - head/sys/boot/i386/boot0 In-Reply-To: <200812021457.mB2Evmha063418@svn.freebsd.org> References: <200812021457.mB2Evmha063418@svn.freebsd.org> Message-ID: <200812021425.00173.jhb@freebsd.org> On Tuesday 02 December 2008 09:57:48 am Luigi Rizzo wrote: > Author: luigi > Date: Tue Dec 2 14:57:48 2008 > New Revision: 185562 > URL: http://svn.freebsd.org/changeset/base/185562 > > Log: > This commits brings in a lot of documentation and some enhancement > of the boot0.S code, with a number of compile-time selectable options, > the most interesting one being the ability to select PXE booting. > > The code is completely compatible with the previous one, and with > the boot0cfg program. Even the actual code is largely unmodified, > with only minor rearrangements or fixes to make room for the new > features. > > The behaviour of the standard build differs from the previous > version in the following, minor things: > > + 'noupdate' is the default, which means the code does not > write back the selection to disk. You can enable the feature > at runtime with boot0cfg, or changing the flags in the Makefile. > > + a drive number of 0x00 (floppy, or USB in floppy emulation) is > now accepted as valid. Previously, it was overridden with 0x80, > meaning that the partition table coming from the media was > used to access sectors on a possibly different media. > You can revert to the previous mode building with -DCHECK_DRIVE, > and you can always use the 'setdrv' option in boot0cfg I would flip this back to the original default. This was there to workaround certain broken BIOSes that incorrectly specified a drive of 0x00 when you booted from the hard drive (at least according to the comments). On such systems they will now fail to boot. MBR's aren't really supported on floppies, so you shouldn't ever have a legitmate %dl of 0x00. In the rare case that you do you could use the 'setdrv' option to boot0cfg. -- John Baldwin From bz at FreeBSD.org Tue Dec 2 13:37:33 2008 From: bz at FreeBSD.org (Bjoern A. Zeeb) Date: Tue Dec 2 13:37:48 2008 Subject: svn commit: r185571 - in head/sys: compat/linprocfs compat/linux compat/svr4 contrib/altq/altq contrib/ipfilter/netinet contrib/pf/net contrib/rdma dev/cxgb/ulp/iw_cxgb dev/cxgb/ulp/tom kern module... Message-ID: <200812022137.mB2LbSDN072024@svn.freebsd.org> Author: bz Date: Tue Dec 2 21:37:28 2008 New Revision: 185571 URL: http://svn.freebsd.org/changeset/base/185571 Log: Rather than using hidden includes (with cicular dependencies), directly include only the header files needed. This reduces the unneeded spamming of various headers into lots of files. For now, this leaves us with very few modules including vnet.h and thus needing to depend on opt_route.h. Reviewed by: brooks, gnn, des, zec, imp Sponsored by: The FreeBSD Foundation Modified: head/sys/compat/linprocfs/linprocfs.c head/sys/compat/linux/linux_ioctl.c head/sys/compat/linux/linux_socket.c head/sys/compat/svr4/svr4_sockio.c head/sys/contrib/altq/altq/altq_subr.c head/sys/contrib/ipfilter/netinet/ip_fil_freebsd.c head/sys/contrib/ipfilter/netinet/mlfk_ipl.c head/sys/contrib/pf/net/pf.c head/sys/contrib/pf/net/pf_if.c head/sys/contrib/pf/net/pf_ioctl.c head/sys/contrib/pf/net/pf_subr.c head/sys/contrib/rdma/rdma_cma.c head/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb.c head/sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c head/sys/kern/kern_poll.c head/sys/kern/kern_uuid.c head/sys/modules/ae/Makefile head/sys/modules/ath/Makefile head/sys/modules/ath_rate_amrr/Makefile head/sys/modules/ath_rate_onoe/Makefile head/sys/modules/ath_rate_sample/Makefile head/sys/modules/bridgestp/Makefile head/sys/modules/cxgb/iw_cxgb/Makefile head/sys/modules/if_ef/Makefile head/sys/modules/if_vlan/Makefile head/sys/modules/ip_mroute_mod/Makefile head/sys/modules/ipfw/Makefile head/sys/modules/linprocfs/Makefile head/sys/modules/linux/Makefile head/sys/modules/netgraph/atm/atm/Makefile head/sys/modules/netgraph/ether/Makefile head/sys/modules/netgraph/gif/Makefile head/sys/modules/nfsclient/Makefile head/sys/modules/pf/Makefile head/sys/modules/wlan/Makefile head/sys/net/bridgestp.c head/sys/net/if.c head/sys/net/if_bridge.c head/sys/net/if_ef.c head/sys/net/if_ethersubr.c head/sys/net/if_faith.c head/sys/net/if_gre.c head/sys/net/if_loop.c head/sys/net/if_mib.c head/sys/net/if_spppsubr.c head/sys/net/if_stf.c head/sys/net/if_var.h head/sys/net/if_vlan.c head/sys/net/raw_cb.c head/sys/net/raw_usrreq.c head/sys/net/route.c head/sys/net/rtsock.c head/sys/net80211/ieee80211_ddb.c head/sys/netgraph/atm/ng_atm.c head/sys/netgraph/ng_eiface.c head/sys/netgraph/ng_ether.c head/sys/netgraph/ng_gif.c head/sys/netinet/if_ether.c head/sys/netinet/igmp.c head/sys/netinet/in.c head/sys/netinet/in.h head/sys/netinet/in_gif.c head/sys/netinet/in_mcast.c head/sys/netinet/in_pcb.c head/sys/netinet/in_rmx.c head/sys/netinet/ip6.h head/sys/netinet/ip_carp.c head/sys/netinet/ip_divert.c head/sys/netinet/ip_fastfwd.c head/sys/netinet/ip_fw2.c head/sys/netinet/ip_icmp.c head/sys/netinet/ip_id.c head/sys/netinet/ip_input.c head/sys/netinet/ip_ipsec.c head/sys/netinet/ip_mroute.c head/sys/netinet/ip_options.c head/sys/netinet/ip_output.c head/sys/netinet/raw_ip.c head/sys/netinet/sctp_os_bsd.h head/sys/netinet/tcp_hostcache.c head/sys/netinet/tcp_input.c head/sys/netinet/tcp_offload.c head/sys/netinet/tcp_output.c head/sys/netinet/tcp_reass.c head/sys/netinet/tcp_sack.c head/sys/netinet/tcp_subr.c head/sys/netinet/tcp_syncache.c head/sys/netinet/tcp_timer.c head/sys/netinet/tcp_timewait.c head/sys/netinet/tcp_usrreq.c head/sys/netinet/udp_usrreq.c head/sys/netinet/vinet.h head/sys/netinet6/dest6.c head/sys/netinet6/frag6.c head/sys/netinet6/icmp6.c head/sys/netinet6/in6.c head/sys/netinet6/in6_gif.c head/sys/netinet6/in6_ifattach.c head/sys/netinet6/in6_pcb.c head/sys/netinet6/in6_proto.c head/sys/netinet6/in6_rmx.c head/sys/netinet6/in6_src.c head/sys/netinet6/ip6_forward.c head/sys/netinet6/ip6_input.c head/sys/netinet6/ip6_ipsec.c head/sys/netinet6/ip6_mroute.c head/sys/netinet6/ip6_output.c head/sys/netinet6/mld6.c head/sys/netinet6/nd6.c head/sys/netinet6/nd6_nbr.c head/sys/netinet6/nd6_rtr.c head/sys/netinet6/raw_ip6.c head/sys/netinet6/route6.c head/sys/netinet6/scope6.c head/sys/netinet6/udp6_usrreq.c head/sys/netinet6/vinet6.h head/sys/netipsec/ipsec_input.c head/sys/netipsec/ipsec_output.c head/sys/netipsec/key.c head/sys/netipsec/keysock.c head/sys/netipsec/vipsec.h head/sys/netipsec/xform_ipip.c head/sys/nfsclient/bootp_subr.c head/sys/nfsclient/nfs_diskless.c head/sys/nfsclient/nfs_vnops.c Modified: head/sys/compat/linprocfs/linprocfs.c ============================================================================== --- head/sys/compat/linprocfs/linprocfs.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/compat/linprocfs/linprocfs.c Tue Dec 2 21:37:28 2008 (r185571) @@ -76,6 +76,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include Modified: head/sys/compat/linux/linux_ioctl.c ============================================================================== --- head/sys/compat/linux/linux_ioctl.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/compat/linux/linux_ioctl.c Tue Dec 2 21:37:28 2008 (r185571) @@ -63,6 +63,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef COMPAT_LINUX32 #include Modified: head/sys/compat/linux/linux_socket.c ============================================================================== --- head/sys/compat/linux/linux_socket.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/compat/linux/linux_socket.c Tue Dec 2 21:37:28 2008 (r185571) @@ -52,12 +52,15 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include #ifdef INET6 #include #include +#include +#include #endif #ifdef COMPAT_LINUX32 Modified: head/sys/compat/svr4/svr4_sockio.c ============================================================================== --- head/sys/compat/svr4/svr4_sockio.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/compat/svr4/svr4_sockio.c Tue Dec 2 21:37:28 2008 (r185571) @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include Modified: head/sys/contrib/altq/altq/altq_subr.c ============================================================================== --- head/sys/contrib/altq/altq/altq_subr.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/contrib/altq/altq/altq_subr.c Tue Dec 2 21:37:28 2008 (r185571) @@ -51,6 +51,7 @@ #include #include #include +#include #include #include Modified: head/sys/contrib/ipfilter/netinet/ip_fil_freebsd.c ============================================================================== --- head/sys/contrib/ipfilter/netinet/ip_fil_freebsd.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/contrib/ipfilter/netinet/ip_fil_freebsd.c Tue Dec 2 21:37:28 2008 (r185571) @@ -112,6 +112,9 @@ static const char rcsid[] = "@(#)$Id: ip #include "netinet/ip_scan.h" #endif #include "netinet/ip_pool.h" +#if defined(__FreeBSD_version) && (__FreeBSD_version >= 800056) +# include +#endif #if defined(__FreeBSD_version) && (__FreeBSD_version >= 300000) # include #endif Modified: head/sys/contrib/ipfilter/netinet/mlfk_ipl.c ============================================================================== --- head/sys/contrib/ipfilter/netinet/mlfk_ipl.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/contrib/ipfilter/netinet/mlfk_ipl.c Tue Dec 2 21:37:28 2008 (r185571) @@ -43,9 +43,7 @@ static int sysctl_ipf_int ( SYSCTL_HANDL static int ipf_modload(void); static int ipf_modunload(void); -#if __FreeBSD_version < 800055 SYSCTL_DECL(_net_inet); -#endif #define SYSCTL_IPF(parent, nbr, name, access, ptr, val, descr) \ SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \ ptr, val, sysctl_ipf_int, "I", descr); Modified: head/sys/contrib/pf/net/pf.c ============================================================================== --- head/sys/contrib/pf/net/pf.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/contrib/pf/net/pf.c Tue Dec 2 21:37:28 2008 (r185571) @@ -120,6 +120,9 @@ __FBSDID("$FreeBSD$"); #include #include #include +#ifdef __FreeBSD__ +#include +#endif #ifndef __FreeBSD__ #include @@ -139,6 +142,7 @@ __FBSDID("$FreeBSD$"); #ifdef __FreeBSD__ #include #include +#include #endif #endif /* INET6 */ Modified: head/sys/contrib/pf/net/pf_if.c ============================================================================== --- head/sys/contrib/pf/net/pf_if.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/contrib/pf/net/pf_if.c Tue Dec 2 21:37:28 2008 (r185571) @@ -54,10 +54,15 @@ __FBSDID("$FreeBSD$"); #include #endif #include +#ifdef __FreeBSD__ #include +#endif #include #include +#ifdef __FreeBSD__ +#include +#endif #include #include Modified: head/sys/contrib/pf/net/pf_ioctl.c ============================================================================== --- head/sys/contrib/pf/net/pf_ioctl.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/contrib/pf/net/pf_ioctl.c Tue Dec 2 21:37:28 2008 (r185571) @@ -102,6 +102,9 @@ __FBSDID("$FreeBSD$"); #include #include #include +#ifdef __FreeBSD__ +#include +#endif #include #include Modified: head/sys/contrib/pf/net/pf_subr.c ============================================================================== --- head/sys/contrib/pf/net/pf_subr.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/contrib/pf/net/pf_subr.c Tue Dec 2 21:37:28 2008 (r185571) @@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include /* Modified: head/sys/contrib/rdma/rdma_cma.c ============================================================================== --- head/sys/contrib/rdma/rdma_cma.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/contrib/rdma/rdma_cma.c Tue Dec 2 21:37:28 2008 (r185571) @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include Modified: head/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb.c ============================================================================== --- head/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb.c Tue Dec 2 21:37:28 2008 (r185571) @@ -62,6 +62,9 @@ __FBSDID("$FreeBSD$"); #include #include +#if __FreeBSD_version >= 800056 +#include +#endif #include Modified: head/sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c ============================================================================== --- head/sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c Tue Dec 2 21:37:28 2008 (r185571) @@ -78,6 +78,9 @@ __FBSDID("$FreeBSD$"); #include #include #include +#if __FreeBSD_version >= 800056 +#include +#endif #include #include Modified: head/sys/kern/kern_poll.c ============================================================================== --- head/sys/kern/kern_poll.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/kern/kern_poll.c Tue Dec 2 21:37:28 2008 (r185571) @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include /* for IFF_* flags */ #include /* for NETISR_POLL */ +#include #include #include Modified: head/sys/kern/kern_uuid.c ============================================================================== --- head/sys/kern/kern_uuid.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/kern/kern_uuid.c Tue Dec 2 21:37:28 2008 (r185571) @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include /* * See also: Modified: head/sys/modules/ae/Makefile ============================================================================== --- head/sys/modules/ae/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/ae/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -3,6 +3,6 @@ .PATH: ${.CURDIR}/../../dev/ae KMOD= if_ae -SRCS= if_ae.c device_if.h bus_if.h pci_if.h miibus_if.h opt_route.h +SRCS= if_ae.c device_if.h bus_if.h pci_if.h miibus_if.h .include Modified: head/sys/modules/ath/Makefile ============================================================================== --- head/sys/modules/ath/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/ath/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -66,7 +66,7 @@ SRCS+= ${AR5211_SRCS} SRCS+= ${AR5212_SRCS} SRCS+= ${AR5416_SRCS} SRCS+= ${AR9160_SRCS} -SRCS+= device_if.h bus_if.h pci_if.h opt_inet.h opt_route.h opt_ath.h opt_ah.h +SRCS+= device_if.h bus_if.h pci_if.h opt_inet.h opt_ath.h opt_ah.h CFLAGS+= -I. -I${.CURDIR}/../../dev/ath -I${.CURDIR}/../../dev/ath/ath_hal Modified: head/sys/modules/ath_rate_amrr/Makefile ============================================================================== --- head/sys/modules/ath_rate_amrr/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/ath_rate_amrr/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -33,7 +33,7 @@ KMOD= ath_rate SRCS= amrr.c -SRCS+= device_if.h bus_if.h pci_if.h opt_inet.h opt_route.h opt_ah.h opt_wlan.h +SRCS+= device_if.h bus_if.h pci_if.h opt_inet.h opt_ah.h opt_wlan.h CFLAGS+= -I. -I${.CURDIR}/../../dev/ath -I${.CURDIR}/../../dev/ath/ath_hal Modified: head/sys/modules/ath_rate_onoe/Makefile ============================================================================== --- head/sys/modules/ath_rate_onoe/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/ath_rate_onoe/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -33,7 +33,7 @@ KMOD= ath_rate SRCS= onoe.c -SRCS+= device_if.h bus_if.h pci_if.h opt_inet.h opt_route.h opt_ah.h opt_wlan.h +SRCS+= device_if.h bus_if.h pci_if.h opt_inet.h opt_ah.h opt_wlan.h CFLAGS+= -I. -I${.CURDIR}/../../dev/ath -I${.CURDIR}/../../dev/ath/ath_hal Modified: head/sys/modules/ath_rate_sample/Makefile ============================================================================== --- head/sys/modules/ath_rate_sample/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/ath_rate_sample/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -33,7 +33,7 @@ KMOD= ath_rate SRCS= sample.c -SRCS+= device_if.h bus_if.h pci_if.h opt_inet.h opt_route.h opt_ah.h opt_wlan.h +SRCS+= device_if.h bus_if.h pci_if.h opt_inet.h opt_ah.h opt_wlan.h CFLAGS+= -I. -I${.CURDIR}/../../dev/ath -I${.CURDIR}/../../dev/ath/ath_hal Modified: head/sys/modules/bridgestp/Makefile ============================================================================== --- head/sys/modules/bridgestp/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/bridgestp/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -3,6 +3,6 @@ .PATH: ${.CURDIR}/../../net KMOD= bridgestp -SRCS= bridgestp.c +SRCS= bridgestp.c opt_route.h .include Modified: head/sys/modules/cxgb/iw_cxgb/Makefile ============================================================================== --- head/sys/modules/cxgb/iw_cxgb/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/cxgb/iw_cxgb/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -7,7 +7,8 @@ KMOD= iw_cxgb SRCS= iw_cxgb.c iw_cxgb_cm.c iw_cxgb_hal.c SRCS+= iw_cxgb_provider.c iw_cxgb_qp.c iw_cxgb_resource.c SRCS+= iw_cxgb_ev.c iw_cxgb_mem.c iw_cxgb_dbg.c iw_cxgb_cq.c -SRCS+= bus_if.h device_if.h opt_sched.h pci_if.h pcib_if.h opt_ktr.h opt_inet.h +SRCS+= bus_if.h device_if.h opt_sched.h pci_if.h pcib_if.h opt_ktr.h +SRCS+= opt_inet.h opt_route.h CFLAGS+= -g -I${CXGB} #CFLAGS+= -DDEBUG Modified: head/sys/modules/if_ef/Makefile ============================================================================== --- head/sys/modules/if_ef/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/if_ef/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -3,7 +3,7 @@ .PATH: ${.CURDIR}/../../net KMOD= if_ef -SRCS= if_ef.c opt_ipx.h opt_inet.h opt_ef.h +SRCS= if_ef.c opt_ipx.h opt_inet.h opt_ef.h opt_route.h .if defined(EFDEBUG) CFLAGS+= -DEF_DEBUG Modified: head/sys/modules/if_vlan/Makefile ============================================================================== --- head/sys/modules/if_vlan/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/if_vlan/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -4,6 +4,6 @@ KMOD= if_vlan SRCS= if_vlan.c -SRCS+= opt_inet.h opt_vlan.h +SRCS+= opt_inet.h opt_vlan.h opt_route.h .include Modified: head/sys/modules/ip_mroute_mod/Makefile ============================================================================== --- head/sys/modules/ip_mroute_mod/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/ip_mroute_mod/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -7,7 +7,7 @@ KMOD= ip_mroute SRCS= ip_mroute.c -SRCS+= opt_inet.h opt_mac.h opt_mrouting.h +SRCS+= opt_inet.h opt_mac.h opt_mrouting.h opt_route.h SRCS+= opt_inet6.h .if ${MK_INET6_SUPPORT} != "no" Modified: head/sys/modules/ipfw/Makefile ============================================================================== --- head/sys/modules/ipfw/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/ipfw/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -6,7 +6,7 @@ KMOD= ipfw SRCS= ip_fw2.c ip_fw_pfil.c -SRCS+= opt_inet6.h opt_ipsec.h opt_mac.h +SRCS+= opt_inet6.h opt_ipsec.h opt_mac.h opt_route.h CFLAGS+= -DIPFIREWALL CFLAGS+= -I${.CURDIR}/../../contrib/pf Modified: head/sys/modules/linprocfs/Makefile ============================================================================== --- head/sys/modules/linprocfs/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/linprocfs/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -5,7 +5,8 @@ KMOD= linprocfs SRCS= vnode_if.h \ linprocfs.c \ - opt_compat.h + opt_compat.h \ + opt_route.h .if ${MACHINE_ARCH} == "amd64" CFLAGS+=-DCOMPAT_LINUX32 Modified: head/sys/modules/linux/Makefile ============================================================================== --- head/sys/modules/linux/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/linux/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -13,7 +13,7 @@ SRCS= linux${SFX}_dummy.c linux_emul.c l linux${SFX}_machdep.c linux_mib.c linux_misc.c linux_signal.c \ linux_socket.c linux_stats.c linux_sysctl.c linux${SFX}_sysent.c \ linux${SFX}_sysvec.c linux_uid16.c linux_util.c linux_time.c \ - opt_inet6.h opt_mac.h opt_compat.h opt_posix.h vnode_if.h \ + opt_inet6.h opt_route.h opt_mac.h opt_compat.h opt_posix.h vnode_if.h \ device_if.h bus_if.h assym.s # XXX: for assym.s Modified: head/sys/modules/netgraph/atm/atm/Makefile ============================================================================== --- head/sys/modules/netgraph/atm/atm/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/netgraph/atm/atm/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -5,7 +5,7 @@ .PATH: ${.CURDIR}/../../../../netgraph/atm KMOD= ng_atm -SRCS= ng_atm.c +SRCS= ng_atm.c opt_route.h # CFLAGS+= -DNGATM_DEBUG .include Modified: head/sys/modules/netgraph/ether/Makefile ============================================================================== --- head/sys/modules/netgraph/ether/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/netgraph/ether/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -1,6 +1,6 @@ # $FreeBSD$ KMOD= ng_ether -SRCS= ng_ether.c +SRCS= ng_ether.c opt_route.h .include Modified: head/sys/modules/netgraph/gif/Makefile ============================================================================== --- head/sys/modules/netgraph/gif/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/netgraph/gif/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -1,7 +1,7 @@ # $FreeBSD$ KMOD= ng_gif -SRCS= ng_gif.c opt_inet.h opt_inet6.h +SRCS= ng_gif.c opt_inet.h opt_inet6.h opt_route.h .if !defined(KERNBUILDDIR) opt_inet.h: Modified: head/sys/modules/nfsclient/Makefile ============================================================================== --- head/sys/modules/nfsclient/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/nfsclient/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -10,7 +10,7 @@ SRCS= vnode_if.h \ opt_inet.h opt_nfs.h opt_bootp.h opt_nfsroot.h SRCS+= nfs4_dev.c nfs4_idmap.c nfs4_socket.c nfs4_subs.c \ nfs4_vfs_subs.c nfs4_vfsops.c nfs4_vn_subs.c nfs4_vnops.c -SRCS+= opt_inet6.h opt_kgssapi.h +SRCS+= opt_inet6.h opt_kgssapi.h opt_route.h # USE THE RPCCLNT: CFLAGS+= -DRPCCLNT_DEBUG Modified: head/sys/modules/pf/Makefile ============================================================================== --- head/sys/modules/pf/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/pf/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -9,7 +9,7 @@ KMOD= pf SRCS = pf.c pf_if.c pf_subr.c pf_osfp.c pf_ioctl.c pf_norm.c pf_table.c \ pf_ruleset.c \ in4_cksum.c \ - opt_pf.h opt_inet.h opt_inet6.h opt_bpf.h opt_mac.h + opt_pf.h opt_inet.h opt_inet6.h opt_bpf.h opt_mac.h opt_route.h CFLAGS+= -I${.CURDIR}/../../contrib/pf Modified: head/sys/modules/wlan/Makefile ============================================================================== --- head/sys/modules/wlan/Makefile Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/modules/wlan/Makefile Tue Dec 2 21:37:28 2008 (r185571) @@ -10,7 +10,8 @@ SRCS= ieee80211.c ieee80211_crypto.c iee ieee80211_regdomain.c ieee80211_ht.c \ ieee80211_adhoc.c ieee80211_hostap.c ieee80211_monitor.c \ ieee80211_sta.c ieee80211_wds.c ieee80211_ddb.c -SRCS+= bus_if.h device_if.h opt_inet.h opt_ipx.h opt_wlan.h opt_ddb.h +SRCS+= bus_if.h device_if.h opt_inet.h opt_ipx.h opt_wlan.h opt_ddb.h \ + opt_route.h .if !defined(KERNBUILDDIR) opt_wlan.h: Modified: head/sys/net/bridgestp.c ============================================================================== --- head/sys/net/bridgestp.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net/bridgestp.c Tue Dec 2 21:37:28 2008 (r185571) @@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include Modified: head/sys/net/if.c ============================================================================== --- head/sys/net/if.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net/if.c Tue Dec 2 21:37:28 2008 (r185571) @@ -67,6 +67,7 @@ #include #include #include +#include #if defined(INET) || defined(INET6) /*XXX*/ @@ -79,6 +80,7 @@ #endif #ifdef INET #include +#include #endif #ifdef DEV_CARP #include Modified: head/sys/net/if_bridge.c ============================================================================== --- head/sys/net/if_bridge.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net/if_bridge.c Tue Dec 2 21:37:28 2008 (r185571) @@ -115,9 +115,11 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef INET6 #include #include +#include #endif #ifdef DEV_CARP #include Modified: head/sys/net/if_ef.c ============================================================================== --- head/sys/net/if_ef.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net/if_ef.c Tue Dec 2 21:37:28 2008 (r185571) @@ -50,6 +50,7 @@ #include #include #include +#include #ifdef INET #include Modified: head/sys/net/if_ethersubr.c ============================================================================== --- head/sys/net/if_ethersubr.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net/if_ethersubr.c Tue Dec 2 21:37:28 2008 (r185571) @@ -63,6 +63,7 @@ #include #include #include +#include #if defined(INET) || defined(INET6) #include Modified: head/sys/net/if_faith.c ============================================================================== --- head/sys/net/if_faith.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net/if_faith.c Tue Dec 2 21:37:28 2008 (r185571) @@ -77,6 +77,7 @@ #include #include #include +#include #endif #define FAITHNAME "faith" Modified: head/sys/net/if_gre.c ============================================================================== --- head/sys/net/if_gre.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net/if_gre.c Tue Dec 2 21:37:28 2008 (r185571) @@ -79,6 +79,7 @@ #include #include #include +#include #else #error "Huh? if_gre without inet?" #endif Modified: head/sys/net/if_loop.c ============================================================================== --- head/sys/net/if_loop.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net/if_loop.c Tue Dec 2 21:37:28 2008 (r185571) @@ -57,6 +57,7 @@ #include #include #include +#include #ifdef INET #include Modified: head/sys/net/if_mib.c ============================================================================== --- head/sys/net/if_mib.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net/if_mib.c Tue Dec 2 21:37:28 2008 (r185571) @@ -38,6 +38,7 @@ #include #include +#include /* * A sysctl(3) MIB for generic interface information. This information Modified: head/sys/net/if_spppsubr.c ============================================================================== --- head/sys/net/if_spppsubr.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net/if_spppsubr.c Tue Dec 2 21:37:28 2008 (r185571) @@ -56,6 +56,7 @@ #ifdef INET #include #include +#include #endif #ifdef INET6 Modified: head/sys/net/if_stf.c ============================================================================== --- head/sys/net/if_stf.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net/if_stf.c Tue Dec 2 21:37:28 2008 (r185571) @@ -107,6 +107,7 @@ #include #include #include +#include #include #include Modified: head/sys/net/if_var.h ============================================================================== --- head/sys/net/if_var.h Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net/if_var.h Tue Dec 2 21:37:28 2008 (r185571) @@ -720,8 +720,6 @@ int ether_poll_register(poll_handler_ int ether_poll_deregister(struct ifnet *ifp); #endif /* DEVICE_POLLING */ -#include - #endif /* _KERNEL */ #endif /* !_NET_IF_VAR_H_ */ Modified: head/sys/net/if_vlan.c ============================================================================== --- head/sys/net/if_vlan.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net/if_vlan.c Tue Dec 2 21:37:28 2008 (r185571) @@ -64,6 +64,7 @@ #include #include #include +#include #define VLANNAME "vlan" #define VLAN_DEF_HWIDTH 4 Modified: head/sys/net/raw_cb.c ============================================================================== --- head/sys/net/raw_cb.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net/raw_cb.c Tue Dec 2 21:37:28 2008 (r185571) @@ -46,6 +46,7 @@ #include #include +#include /* * Routines to manage the raw protocol control blocks. Modified: head/sys/net/raw_usrreq.c ============================================================================== --- head/sys/net/raw_usrreq.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net/raw_usrreq.c Tue Dec 2 21:37:28 2008 (r185571) @@ -48,6 +48,7 @@ #include #include +#include MTX_SYSINIT(rawcb_mtx, &rawcb_mtx, "rawcb", MTX_DEF); Modified: head/sys/net/route.c ============================================================================== --- head/sys/net/route.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net/route.c Tue Dec 2 21:37:28 2008 (r185571) @@ -57,9 +57,11 @@ #ifdef RADIX_MPATH #include #endif +#include #include #include +#include #include Modified: head/sys/net/rtsock.c ============================================================================== --- head/sys/net/rtsock.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net/rtsock.c Tue Dec 2 21:37:28 2008 (r185571) @@ -54,6 +54,7 @@ #include #include #include +#include #include #ifdef INET6 Modified: head/sys/net80211/ieee80211_ddb.c ============================================================================== --- head/sys/net80211/ieee80211_ddb.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/net80211/ieee80211_ddb.c Tue Dec 2 21:37:28 2008 (r185571) @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include Modified: head/sys/netgraph/atm/ng_atm.c ============================================================================== --- head/sys/netgraph/atm/ng_atm.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netgraph/atm/ng_atm.c Tue Dec 2 21:37:28 2008 (r185571) @@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include Modified: head/sys/netgraph/ng_eiface.c ============================================================================== --- head/sys/netgraph/ng_eiface.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netgraph/ng_eiface.c Tue Dec 2 21:37:28 2008 (r185571) @@ -43,6 +43,7 @@ #include #include #include +#include #include #include Modified: head/sys/netgraph/ng_ether.c ============================================================================== --- head/sys/netgraph/ng_ether.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netgraph/ng_ether.c Tue Dec 2 21:37:28 2008 (r185571) @@ -63,6 +63,7 @@ #include #include #include +#include #include #include Modified: head/sys/netgraph/ng_gif.c ============================================================================== --- head/sys/netgraph/ng_gif.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netgraph/ng_gif.c Tue Dec 2 21:37:28 2008 (r185571) @@ -84,6 +84,7 @@ #include #include #include +#include #include #include Modified: head/sys/netinet/if_ether.c ============================================================================== --- head/sys/netinet/if_ether.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/if_ether.c Tue Dec 2 21:37:28 2008 (r185571) @@ -61,10 +61,12 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include +#include #include #include Modified: head/sys/netinet/igmp.c ============================================================================== --- head/sys/netinet/igmp.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/igmp.c Tue Dec 2 21:37:28 2008 (r185571) @@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -70,6 +71,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include Modified: head/sys/netinet/in.c ============================================================================== --- head/sys/netinet/in.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/in.c Tue Dec 2 21:37:28 2008 (r185571) @@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include static int in_mask2len(struct in_addr *); static void in_len2mask(struct in_addr *, int); Modified: head/sys/netinet/in.h ============================================================================== --- head/sys/netinet/in.h Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/in.h Tue Dec 2 21:37:28 2008 (r185571) @@ -743,8 +743,4 @@ void in_ifdetach(struct ifnet *); #undef __KAME_NETINET_IN_H_INCLUDED_ #endif -#ifdef _KERNEL -#include -#endif - #endif /* !_NETINET_IN_H_*/ Modified: head/sys/netinet/in_gif.c ============================================================================== --- head/sys/netinet/in_gif.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/in_gif.c Tue Dec 2 21:37:28 2008 (r185571) @@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef INET6 #include Modified: head/sys/netinet/in_mcast.c ============================================================================== --- head/sys/netinet/in_mcast.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/in_mcast.c Tue Dec 2 21:37:28 2008 (r185571) @@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -60,6 +61,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifndef __SOCKUNION_DECLARED union sockunion { Modified: head/sys/netinet/in_pcb.c ============================================================================== --- head/sys/netinet/in_pcb.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/in_pcb.c Tue Dec 2 21:37:28 2008 (r185571) @@ -71,9 +71,11 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef INET6 #include #include +#include #endif /* INET6 */ Modified: head/sys/netinet/in_rmx.c ============================================================================== --- head/sys/netinet/in_rmx.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/in_rmx.c Tue Dec 2 21:37:28 2008 (r185571) @@ -55,9 +55,12 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #include #include +#include extern int in_inithead(void **head, int off); Modified: head/sys/netinet/ip6.h ============================================================================== --- head/sys/netinet/ip6.h Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/ip6.h Tue Dec 2 21:37:28 2008 (r185571) @@ -347,8 +347,6 @@ do { \ } \ } while (/*CONSTCOND*/ 0) -#include - #endif /*_KERNEL*/ #endif /* not _NETINET_IP6_H_ */ Modified: head/sys/netinet/ip_carp.c ============================================================================== --- head/sys/netinet/ip_carp.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/ip_carp.c Tue Dec 2 21:37:28 2008 (r185571) @@ -74,6 +74,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #endif #ifdef INET6 @@ -82,6 +83,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #endif #include Modified: head/sys/netinet/ip_divert.c ============================================================================== --- head/sys/netinet/ip_divert.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/ip_divert.c Tue Dec 2 21:37:28 2008 (r185571) @@ -74,6 +74,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include Modified: head/sys/netinet/ip_fastfwd.c ============================================================================== --- head/sys/netinet/ip_fastfwd.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/ip_fastfwd.c Tue Dec 2 21:37:28 2008 (r185571) @@ -103,6 +103,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include Modified: head/sys/netinet/ip_fw2.c ============================================================================== --- head/sys/netinet/ip_fw2.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/ip_fw2.c Tue Dec 2 21:37:28 2008 (r185571) @@ -69,6 +69,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #define IPFW_INTERNAL /* Access to protected data structures in ip_fw.h. */ @@ -91,6 +92,8 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include + #include #include Modified: head/sys/netinet/ip_icmp.c ============================================================================== --- head/sys/netinet/ip_icmp.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/ip_icmp.c Tue Dec 2 21:37:28 2008 (r185571) @@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef IPSEC #include Modified: head/sys/netinet/ip_id.c ============================================================================== --- head/sys/netinet/ip_id.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/ip_id.c Tue Dec 2 21:37:28 2008 (r185571) @@ -104,6 +104,7 @@ static int sysctl_ip_id_change(SYSCTL_HA MTX_SYSINIT(ip_id_mtx, &ip_id_mtx, "ip_id_mtx", MTX_DEF); +SYSCTL_DECL(_net_inet_ip); SYSCTL_PROC(_net_inet_ip, OID_AUTO, random_id_period, CTLTYPE_INT|CTLFLAG_RW, &array_size, 0, sysctl_ip_id_change, "IU", "IP ID Array size"); SYSCTL_INT(_net_inet_ip, OID_AUTO, random_id_collisions, CTLFLAG_RD, Modified: head/sys/netinet/ip_input.c ============================================================================== --- head/sys/netinet/ip_input.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/ip_input.c Tue Dec 2 21:37:28 2008 (r185571) @@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -70,6 +71,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef DEV_CARP #include #endif Modified: head/sys/netinet/ip_ipsec.c ============================================================================== --- head/sys/netinet/ip_ipsec.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/ip_ipsec.c Tue Dec 2 21:37:28 2008 (r185571) @@ -55,6 +55,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include Modified: head/sys/netinet/ip_mroute.c ============================================================================== --- head/sys/netinet/ip_mroute.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/ip_mroute.c Tue Dec 2 21:37:28 2008 (r185571) @@ -96,6 +96,8 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include + #ifdef INET6 #include #include Modified: head/sys/netinet/ip_options.c ============================================================================== --- head/sys/netinet/ip_options.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/ip_options.c Tue Dec 2 21:37:28 2008 (r185571) @@ -63,6 +63,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include Modified: head/sys/netinet/ip_output.c ============================================================================== --- head/sys/netinet/ip_output.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/ip_output.c Tue Dec 2 21:37:28 2008 (r185571) @@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$"); #ifdef RADIX_MPATH #include #endif +#include #include #include @@ -67,6 +68,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef IPSEC #include Modified: head/sys/netinet/raw_ip.c ============================================================================== --- head/sys/netinet/raw_ip.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/raw_ip.c Tue Dec 2 21:37:28 2008 (r185571) @@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -69,6 +70,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #ifdef IPSEC #include Modified: head/sys/netinet/sctp_os_bsd.h ============================================================================== --- head/sys/netinet/sctp_os_bsd.h Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/sctp_os_bsd.h Tue Dec 2 21:37:28 2008 (r185571) @@ -77,7 +77,7 @@ __FBSDID("$FreeBSD$"); #include #include #include - +#include #ifdef IPSEC #include Modified: head/sys/netinet/tcp_hostcache.c ============================================================================== --- head/sys/netinet/tcp_hostcache.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/tcp_hostcache.c Tue Dec 2 21:37:28 2008 (r185571) @@ -92,6 +92,8 @@ __FBSDID("$FreeBSD$"); #endif #include #include +#include +#include #ifdef INET6 #include #endif Modified: head/sys/netinet/tcp_input.c ============================================================================== --- head/sys/netinet/tcp_input.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/tcp_input.c Tue Dec 2 21:37:28 2008 (r185571) @@ -87,6 +87,11 @@ __FBSDID("$FreeBSD$"); #ifdef TCPDEBUG #include #endif /* TCPDEBUG */ +#include + +#ifdef INET6 +#include +#endif #ifdef IPSEC #include Modified: head/sys/netinet/tcp_offload.c ============================================================================== --- head/sys/netinet/tcp_offload.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/tcp_offload.c Tue Dec 2 21:37:28 2008 (r185571) @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include uint32_t toedev_registration_count; Modified: head/sys/netinet/tcp_output.c ============================================================================== --- head/sys/netinet/tcp_output.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/tcp_output.c Tue Dec 2 21:37:28 2008 (r185571) @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -74,6 +75,7 @@ __FBSDID("$FreeBSD$"); #ifdef TCPDEBUG #include #endif +#include #ifdef IPSEC #include Modified: head/sys/netinet/tcp_reass.c ============================================================================== --- head/sys/netinet/tcp_reass.c Tue Dec 2 20:50:37 2008 (r185570) +++ head/sys/netinet/tcp_reass.c Tue Dec 2 21:37:28 2008 (r185571) @@ -73,6 +73,7 @@ __FBSDID("$FreeBSD$"); #ifdef TCPDEBUG #include #endif /* TCPDEBUG */ +#include #ifdef VIMAGE_GLOBALS static int tcp_reass_maxseg; Modified: head/sys/netinet/tcp_sack.c ============================================================================== --- head/sys/netinet/tcp_sack.c Tue Dec 2 20:50:37 2008 (r185570) *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From bz at FreeBSD.org Tue Dec 2 13:50:10 2008 From: bz at FreeBSD.org (Bjoern A. Zeeb) Date: Tue Dec 2 13:50:15 2008 Subject: svn commit: r185571 - in head/sys: compat/linprocfs compat/linux compat/svr4 contrib/altq/altq contrib/ipfilter/netinet contrib/pf/net contrib/rdma dev/cxgb/ulp/iw_cxgb dev/cxgb/ulp/tom kern module... In-Reply-To: <200812022137.mB2LbSDN072024@svn.freebsd.org> References: <200812022137.mB2LbSDN072024@svn.freebsd.org> Message-ID: <20081202213950.U80401@maildrop.int.zabbadoz.net> On Tue, 2 Dec 2008, Bjoern A. Zeeb wrote: Hi, > URL: http://svn.freebsd.org/changeset/base/185571 > > Log: > Rather than using hidden includes (with cicular dependencies), > directly include only the header files needed. This reduces the > unneeded spamming of various headers into lots of files. > > For now, this leaves us with very few modules including vnet.h > and thus needing to depend on opt_route.h. In case you are still seeing a problem building modules (related to all this) please let me know. I tried to catch as many as I could spot. As I said before there is more cleanup to follow the next days but I tried to keep as much of that out of this commit. /bz -- Bjoern A. Zeeb Stop bit received. Insert coin for new game. From rizzo at iet.unipi.it Tue Dec 2 14:00:12 2008 From: rizzo at iet.unipi.it (Luigi Rizzo) Date: Tue Dec 2 14:00:23 2008 Subject: svn commit: r185562 - head/sys/boot/i386/boot0 In-Reply-To: <200812021425.00173.jhb@freebsd.org> References: <200812021457.mB2Evmha063418@svn.freebsd.org> <200812021425.00173.jhb@freebsd.org> Message-ID: <20081202214821.GA65840@onelab2.iet.unipi.it> On Tue, Dec 02, 2008 at 02:24:58PM -0500, John Baldwin wrote: > On Tuesday 02 December 2008 09:57:48 am Luigi Rizzo wrote: ... > > + a drive number of 0x00 (floppy, or USB in floppy emulation) is > > now accepted as valid. Previously, it was overridden with 0x80, > > meaning that the partition table coming from the media was > > used to access sectors on a possibly different media. > > You can revert to the previous mode building with -DCHECK_DRIVE, > > and you can always use the 'setdrv' option in boot0cfg > > I would flip this back to the original default. This was there to workaround > certain broken BIOSes that incorrectly specified a drive of 0x00 when you > booted from the hard drive (at least according to the comments). On such i don't have strong opinions on this, but i would really like to see some evidence on how relevant the original logic (and the comments in the code on broken BIOSes) are nowadays. That code dates back to 1998. On the contrary, I can point to a very current and widespread case with AMI Bioses which, in the "Auto" emulation mode for USB device, use %dl=0 for devices under 500MB or so; in this case the original boot0 did the wrong thing, because overriding with 0x80 causes reading from the wrong device. Granted, boot0cfg options can fix things for both cases. It's all a matter of what is the most reasonable default. cheers luigi From jhb at freebsd.org Tue Dec 2 14:33:03 2008 From: jhb at freebsd.org (John Baldwin) Date: Tue Dec 2 14:33:14 2008 Subject: svn commit: r185562 - head/sys/boot/i386/boot0 In-Reply-To: <20081202214821.GA65840@onelab2.iet.unipi.it> References: <200812021457.mB2Evmha063418@svn.freebsd.org> <200812021425.00173.jhb@freebsd.org> <20081202214821.GA65840@onelab2.iet.unipi.it> Message-ID: <200812021718.20571.jhb@freebsd.org> On Tuesday 02 December 2008 04:48:21 pm Luigi Rizzo wrote: > On Tue, Dec 02, 2008 at 02:24:58PM -0500, John Baldwin wrote: > > On Tuesday 02 December 2008 09:57:48 am Luigi Rizzo wrote: > ... > > > + a drive number of 0x00 (floppy, or USB in floppy emulation) is > > > now accepted as valid. Previously, it was overridden with 0x80, > > > meaning that the partition table coming from the media was > > > used to access sectors on a possibly different media. > > > You can revert to the previous mode building with -DCHECK_DRIVE, > > > and you can always use the 'setdrv' option in boot0cfg > > > > I would flip this back to the original default. This was there to workaround > > certain broken BIOSes that incorrectly specified a drive of 0x00 when you > > booted from the hard drive (at least according to the comments). On such > > i don't have strong opinions on this, but i would really like to see some > evidence on how relevant the original logic (and the comments in the > code on broken BIOSes) are nowadays. That code dates back to 1998. > > On the contrary, I can point to a very current and widespread case with > AMI Bioses which, in the "Auto" emulation mode for USB device, use %dl=0 > for devices under 500MB or so; in this case the original boot0 did > the wrong thing, because overriding with 0x80 causes reading from the > wrong device. > > Granted, boot0cfg options can fix things for both cases. It's all a > matter of what is the most reasonable default. Agreed. I'm just very hesitant about changing the defaults of boot0 (or any of the boot code for that matter). -- John Baldwin From brueffer at FreeBSD.org Tue Dec 2 14:45:01 2008 From: brueffer at FreeBSD.org (Christian Brueffer) Date: Tue Dec 2 14:45:13 2008 Subject: svn commit: r185572 - head/share/man/man4 Message-ID: <200812022245.mB2Mj15l073600@svn.freebsd.org> Author: brueffer Date: Tue Dec 2 22:45:01 2008 New Revision: 185572 URL: http://svn.freebsd.org/changeset/base/185572 Log: Improve grammar. Submitted by: Ben Kaduk Modified: head/share/man/man4/upgt.4 Modified: head/share/man/man4/upgt.4 ============================================================================== --- head/share/man/man4/upgt.4 Tue Dec 2 21:37:28 2008 (r185571) +++ head/share/man/man4/upgt.4 Tue Dec 2 22:45:01 2008 (r185572) @@ -140,7 +140,7 @@ driver can be configured at runtime with .\"users have to download these files on their own. This driver requires the .Nm upgtfw -firmware be installed before it will work. +firmware to be installed before it will work. The firmware files are not publicly available. A package of the firmware which can be installed via .Xr pkg_add 1 From jhb at freebsd.org Tue Dec 2 15:04:04 2008 From: jhb at freebsd.org (John Baldwin) Date: Tue Dec 2 15:04:17 2008 Subject: svn commit: r185568 - head/lib/libmd In-Reply-To: <200812021949.mB2JnfZr069753@svn.freebsd.org> References: <200812021949.mB2JnfZr069753@svn.freebsd.org> Message-ID: <200812021803.46021.jhb@freebsd.org> On Tuesday 02 December 2008 02:49:41 pm Poul-Henning Kamp wrote: > Author: phk > Date: Tue Dec 2 19:49:41 2008 > New Revision: 185568 > URL: http://svn.freebsd.org/changeset/base/185568 > > Log: > Make the "test" target test the compiled version, instead of the > installed version of the md library. Perhaps use "${.OBJDIR}/libmd.a" rather than "./libmd.a" to be 'make obj' friendly (e.g. buildworld). You could even do something like this: .if exists(${.OBJDIR}/libmd.a) LIBMD= ${.OBJDIR}/libmd.a .else LIBMD= -lmd .endif so it falls back to the system library if you don't have one built (in case you want to test the system library for some reason). -- John Baldwin From rwatson at FreeBSD.org Tue Dec 2 15:26:44 2008 From: rwatson at FreeBSD.org (Robert Watson) Date: Tue Dec 2 15:26:53 2008 Subject: svn commit: r185573 - in head: contrib/openbsm contrib/openbsm/bin contrib/openbsm/bin/audit contrib/openbsm/bin/auditd contrib/openbsm/bin/auditfilterd contrib/openbsm/bin/auditreduce contrib/open... Message-ID: <200812022326.mB2NQheJ074455@svn.freebsd.org> Author: rwatson Date: Tue Dec 2 23:26:43 2008 New Revision: 185573 URL: http://svn.freebsd.org/changeset/base/185573 Log: Merge OpenBSM 1.1 alpha 2 from the OpenBSM vendor branch to head, both contrib/openbsm (svn merge) and sys/{bsm,security/audit} (manual merge). - Add OpenBSM contrib tree to include paths for audit(8) and auditd(8). - Merge support for new tokens, fixes to existing token generation to audit_bsm_token.c. - Synchronize bsm includes and definitions. OpenBSM history for imported revisions below for reference. MFC after: 1 month Sponsored by: Apple Inc. Obtained from: TrustedBSD Project -- OpenBSM 1.1 alpha 2 - Include files in OpenBSM are now broken out into two parts: library builds required solely for user space, and system includes, which may also be required for use in the kernels of systems integrating OpenBSM. Submitted by Stacey Son. - Configure option --with-native-includes allows forcing the use of native include for system includes, rather than the versions bundled with OpenBSM. This is intended specifically for platforms that ship OpenBSM, have adapted versions of the system includes in a kernel source tree, and will use the OpenBSM build infrastructure with an unmodified OpenBSM distribution, allowing the customized system includes to be used with the OpenBSM build. Submitted by Stacey Son. - Various strcpy()'s/strcat()'s have been changed to strlcpy()'s/strlcat()'s or asprintf(). Added compat/strlcpy.h for Linux. - Remove compatibility defines for old Darwin token constant names; now only BSM token names are provided and used. - Add support for extended header tokens, which contain space for information on the host generating the record. - Add support for setting extended host information in the kernel, which is used for setting host information in extended header tokens. The audit_control file now supports a "host" parameter which can be used by auditd to set the information; if not present, the kernel parameters won't be set and auditd uses unextended headers for records that it generates. OpenBSM 1.1 alpha 1 - Add option to auditreduce(1) which allows users to invert sense of matching, such that BSM records that do not match, are selected. - Fix bug in audit_write() where we commit an incomplete record in the event there is an error writing the subject token. This was submitted by Diego Giagio. - Build support for Mac OS X 10.5.1 submitted by Eric Hall. - Fix a bug which resulted in host XML attributes not being arguments so that const strings can be passed as arguments to tokens. This patch was submitted by Xin LI. - Modify the -m option so users can select more then one audit event. - For Mac OS X, added Mach IPC support for audit trigger messages. - Fixed a bug in getacna() which resulted in a locking problem on Mac OS X. - Added LOG_PERROR flag to openlog when -d option is used with auditd. - AUE events added for Mac OS X Leopard system calls. Added: head/contrib/openbsm/CREDITS - copied unchanged from r185494, vendor/openbsm/dist/CREDITS head/contrib/openbsm/INSTALL - copied unchanged from r185494, vendor/openbsm/dist/INSTALL head/contrib/openbsm/NEWS - copied unchanged from r185494, vendor/openbsm/dist/NEWS head/contrib/openbsm/bin/auditd/audit_triggers.defs - copied unchanged from r185494, vendor/openbsm/dist/bin/auditd/audit_triggers.defs head/contrib/openbsm/bin/auditd/auditd_control.defs - copied unchanged from r185494, vendor/openbsm/dist/bin/auditd/auditd_control.defs head/contrib/openbsm/compat/strlcpy.h - copied unchanged from r185494, vendor/openbsm/dist/compat/strlcpy.h head/contrib/openbsm/sys/ - copied from r185494, vendor/openbsm/dist/sys/ Deleted: head/contrib/openbsm/HISTORY Modified: head/contrib/openbsm/ (props changed) head/contrib/openbsm/LICENSE head/contrib/openbsm/Makefile.am head/contrib/openbsm/Makefile.in head/contrib/openbsm/README head/contrib/openbsm/TODO head/contrib/openbsm/VERSION head/contrib/openbsm/bin/Makefile.in head/contrib/openbsm/bin/audit/Makefile.am head/contrib/openbsm/bin/audit/Makefile.in head/contrib/openbsm/bin/audit/audit.8 head/contrib/openbsm/bin/audit/audit.c head/contrib/openbsm/bin/auditd/Makefile.am head/contrib/openbsm/bin/auditd/Makefile.in head/contrib/openbsm/bin/auditd/audit_warn.c head/contrib/openbsm/bin/auditd/auditd.8 head/contrib/openbsm/bin/auditd/auditd.c head/contrib/openbsm/bin/auditd/auditd.h head/contrib/openbsm/bin/auditfilterd/Makefile.am head/contrib/openbsm/bin/auditfilterd/Makefile.in head/contrib/openbsm/bin/auditfilterd/auditfilterd.c head/contrib/openbsm/bin/auditreduce/Makefile.am head/contrib/openbsm/bin/auditreduce/Makefile.in head/contrib/openbsm/bin/auditreduce/auditreduce.1 head/contrib/openbsm/bin/auditreduce/auditreduce.c head/contrib/openbsm/bin/auditreduce/auditreduce.h head/contrib/openbsm/bin/praudit/Makefile.am head/contrib/openbsm/bin/praudit/Makefile.in head/contrib/openbsm/bin/praudit/praudit.1 head/contrib/openbsm/bin/praudit/praudit.c head/contrib/openbsm/bsm/Makefile.am head/contrib/openbsm/bsm/Makefile.in head/contrib/openbsm/bsm/audit_uevents.h head/contrib/openbsm/bsm/libbsm.h head/contrib/openbsm/compat/clock_gettime.h head/contrib/openbsm/compat/strlcat.h head/contrib/openbsm/config/config.h head/contrib/openbsm/config/config.h.in head/contrib/openbsm/configure head/contrib/openbsm/configure.ac head/contrib/openbsm/etc/audit_event head/contrib/openbsm/libbsm/Makefile.am head/contrib/openbsm/libbsm/Makefile.in head/contrib/openbsm/libbsm/au_class.3 head/contrib/openbsm/libbsm/au_free_token.3 head/contrib/openbsm/libbsm/au_token.3 head/contrib/openbsm/libbsm/audit_submit.3 head/contrib/openbsm/libbsm/bsm_audit.c head/contrib/openbsm/libbsm/bsm_class.c head/contrib/openbsm/libbsm/bsm_control.c head/contrib/openbsm/libbsm/bsm_event.c head/contrib/openbsm/libbsm/bsm_flags.c head/contrib/openbsm/libbsm/bsm_io.c head/contrib/openbsm/libbsm/bsm_mask.c head/contrib/openbsm/libbsm/bsm_notify.c head/contrib/openbsm/libbsm/bsm_token.c head/contrib/openbsm/libbsm/bsm_user.c head/contrib/openbsm/libbsm/bsm_wrappers.c head/contrib/openbsm/man/Makefile.in head/contrib/openbsm/man/audit.2 head/contrib/openbsm/man/audit.log.5 head/contrib/openbsm/man/audit_class.5 head/contrib/openbsm/man/audit_control.5 head/contrib/openbsm/man/audit_event.5 head/contrib/openbsm/man/audit_user.5 head/contrib/openbsm/man/audit_warn.5 head/contrib/openbsm/man/auditctl.2 head/contrib/openbsm/man/auditon.2 head/contrib/openbsm/man/getaudit.2 head/contrib/openbsm/man/getauid.2 head/contrib/openbsm/man/setaudit.2 head/contrib/openbsm/man/setauid.2 head/contrib/openbsm/modules/Makefile.in head/contrib/openbsm/modules/auditfilter_noop/Makefile.am head/contrib/openbsm/modules/auditfilter_noop/Makefile.in head/contrib/openbsm/modules/auditfilter_noop/auditfilter_noop.c head/contrib/openbsm/test/Makefile.am head/contrib/openbsm/test/Makefile.in head/contrib/openbsm/test/bsm/Makefile.am head/contrib/openbsm/test/bsm/Makefile.in head/contrib/openbsm/tools/Makefile.am head/contrib/openbsm/tools/Makefile.in head/sys/bsm/audit.h head/sys/bsm/audit_internal.h head/sys/bsm/audit_kevents.h head/sys/bsm/audit_record.h head/sys/security/audit/audit_bsm_token.c head/usr.sbin/audit/Makefile head/usr.sbin/auditd/Makefile Copied: head/contrib/openbsm/CREDITS (from r185494, vendor/openbsm/dist/CREDITS) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/contrib/openbsm/CREDITS Tue Dec 2 23:26:43 2008 (r185573, copy of r185494, vendor/openbsm/dist/CREDITS) @@ -0,0 +1,33 @@ +OpenBSM Credits + +The following organizations and individuals have contributed substantially to +the development of OpenBSM: + + Apple Inc. + McAfee Research, McAfee, Inc. + SPARTA, Inc. + Robert Watson + Wayne Salamon + Suresh Krishnaswamy + Kevin Van Vechten + Tom Rhodes + Wojciech Koszek + Chunyang Yuan + Poul-Henning Kamp + Christian Brueffer + Olivier Houchard + Christian Peron + Martin Fong + Pawel Worach + Martin Englund + Ruslan Ermilov + Martin Voros + Diego Giagio + Alex Samorukov + Eric Hall + Xin LI + Stacey Son + +In addition, Coverity, Inc.'s Prevent(tm) static analysis tool and Gimpel +Software's FlexeLint tool were used to identify a number of bugs in the +OpenBSM implementation. Copied: head/contrib/openbsm/INSTALL (from r185494, vendor/openbsm/dist/INSTALL) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/contrib/openbsm/INSTALL Tue Dec 2 23:26:43 2008 (r185573, copy of r185494, vendor/openbsm/dist/INSTALL) @@ -0,0 +1,29 @@ +OpenBSM Build and Installation Instructions + +OpenBSM is currently built using autoconf and automake, which should allow +for building on a range of operating systems, including FreeBSD, Mac OS X, +and Linux. Depending on the availability of audit facilities in the +underlying operating system, some components that depend on kernel audit +support are built conditionally. Typically, build will be performed using: + + ./configure + make + +To install, use: + + make install + +You may wish to specify that the OpenBSM components not be installed in the +base system, rather in a specific directory. This may be done using the +--prefix argument to configure. If installing to a specific directory, +remember to update your library path so that running tools from that +directory the correct libbsm is used: + + ./configure --prefix=/home/rwatson/openbsm + make + make install + LD_LIBRARY_PATH=/home/rwatson/openbsm/libbsm ; export LD_LIBRARY_PATH + +You will need to manually propagate openbsm/etc/* into /etc/security on your +system; this is not done automatically so as to avoid disrupting the current +configuration. Currently, the locations of these files is not configurable. Modified: head/contrib/openbsm/LICENSE ============================================================================== --- head/contrib/openbsm/LICENSE Tue Dec 2 22:45:01 2008 (r185572) +++ head/contrib/openbsm/LICENSE Tue Dec 2 23:26:43 2008 (r185573) @@ -1,3 +1,5 @@ +OpenBSM Copyrights and Licensing + OpenBSM is covered by a number of copyrights, with licenses being either two or three clause BSD licenses. Individual file headers should be consulted for specific copyrights on specific components. The TrustedBSD Project would @@ -30,4 +32,4 @@ substantially similar licenses: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. -$P4: //depot/projects/trustedbsd/openbsm/LICENSE#4 $ +$P4: //depot/projects/trustedbsd/openbsm/LICENSE#5 $ Modified: head/contrib/openbsm/Makefile.am ============================================================================== --- head/contrib/openbsm/Makefile.am Tue Dec 2 22:45:01 2008 (r185572) +++ head/contrib/openbsm/Makefile.am Tue Dec 2 23:26:43 2008 (r185573) @@ -1,5 +1,5 @@ # -# $P4: //depot/projects/trustedbsd/openbsm/Makefile.am#2 $ +# $P4: //depot/projects/trustedbsd/openbsm/Makefile.am#3 $ # SUBDIRS = \ @@ -7,7 +7,8 @@ SUBDIRS = \ libbsm \ bin \ man \ - modules + modules \ + sys EXTRA_DIST = \ CHANGELOG \ Modified: head/contrib/openbsm/Makefile.in ============================================================================== --- head/contrib/openbsm/Makefile.in Tue Dec 2 22:45:01 2008 (r185572) +++ head/contrib/openbsm/Makefile.in Tue Dec 2 23:26:43 2008 (r185573) @@ -15,7 +15,7 @@ @SET_MAKE@ # -# $P4: //depot/projects/trustedbsd/openbsm/Makefile.in#5 $ +# $P4: //depot/projects/trustedbsd/openbsm/Makefile.in#8 $ # VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ @@ -38,7 +38,7 @@ host_triplet = @host@ subdir = . DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in $(top_srcdir)/config/config.h.in \ - $(top_srcdir)/configure TODO config/config.guess \ + $(top_srcdir)/configure INSTALL NEWS TODO config/config.guess \ config/config.sub config/depcomp config/install-sh \ config/ltmain.sh config/missing ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -116,6 +116,7 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ +MIG = @MIG@ MKDIR_P = @MKDIR_P@ OBJEXT = @OBJEXT@ PACKAGE = @PACKAGE@ @@ -187,7 +188,8 @@ SUBDIRS = \ libbsm \ bin \ man \ - modules + modules \ + sys EXTRA_DIST = \ CHANGELOG \ Copied: head/contrib/openbsm/NEWS (from r185494, vendor/openbsm/dist/NEWS) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/contrib/openbsm/NEWS Tue Dec 2 23:26:43 2008 (r185573, copy of r185494, vendor/openbsm/dist/NEWS) @@ -0,0 +1,351 @@ +OpenBSM Version History + +OpenBSM 1.1 alpha 2 + +- Include files in OpenBSM are now broken out into two parts: library builds + required solely for user space, and system includes, which may also be + required for use in the kernels of systems integrating OpenBSM. Submitted + by Stacey Son. +- Configure option --with-native-includes allows forcing the use of native + include for system includes, rather than the versions bundled with OpenBSM. + This is intended specifically for platforms that ship OpenBSM, have adapted + versions of the system includes in a kernel source tree, and will use the + OpenBSM build infrastructure with an unmodified OpenBSM distribution, + allowing the customized system includes to be used with the OpenBSM build. + Submitted by Stacey Son. +- Various strcpy()'s/strcat()'s have been changed to strlcpy()'s/strlcat()'s + or asprintf(). Added compat/strlcpy.h for Linux. +- Remove compatibility defines for old Darwin token constant names; now only + BSM token names are provided and used. +- Add support for extended header tokens, which contain space for information + on the host generating the record. +- Add support for setting extended host information in the kernel, which is + used for setting host information in extended header tokens. The + audit_control file now supports a "host" parameter which can be used by + auditd to set the information; if not present, the kernel parameters won't + be set and auditd uses unextended headers for records that it generates. + +OpenBSM 1.1 alpha 1 + +- Add option to auditreduce(1) which allows users to invert sense of + matching, such that BSM records that do not match, are selected. +- Fix bug in audit_write() where we commit an incomplete record in the + event there is an error writing the subject token. This was submitted + by Diego Giagio. +- Build support for Mac OS X 10.5.1 submitted by Eric Hall. +- Fix a bug which resulted in host XML attributes not being printed + while processing extended header tokens. This patch was submitted by + Martin Voros. +- Constification of function arguments so that const strings can be passed + as arguments to tokens. This patch was submitted by Xin LI. +- Modify the -m option so users can select more then one audit event. +- For Mac OS X, added Mach IPC support for audit trigger messages. +- Fixed a bug in getacna() which resulted in a locking problem on Mac OS X. +- Added LOG_PERROR flag to openlog when -d option is used with auditd. +- AUE events added for Mac OS X Leopard system calls. + +OpenBSM 1.0 + +- Fix bug in auditreduce(1) which resulted in a memory fault/crash when + the user specified an event name with -m. +- Remove AU_.* hard-coded audit class constants, as audit classes are now + entirely dynamically configured using /etc/security/audit_class. + +OpenBSM 1.0 alpha 15 + +- Fix bug when processing in_addr_ex tokens. +- Restore the behavior of printing the string/text specified while + auditing arg32 tokens. +- Synchronized audit event list to Solaris, picking up the *at(2) system call + definitions, now required for FreeBSD and Linux. Added additional events + for *at(2) system calls not present in Solaris. +- Bugs in auditreduce(1) fixed allowing partial date strings to be used in + filtering events. + +OpenBSM 1.0 alpha 14 + +- Fix endian issues when processing IPv6 addresses for extended subject + and process tokens. +- gcc41 warnings clean. +- Teach audit_submit(3) about getaudit_addr(2). +- Add support for zonename tokens. + +OpenBSM 1.0 alpha 13 + +- compat/clock_gettime.h now provides a compatibility implementation of + clock_gettime(), which fixes building on Mac OS X. +- Countless man page improvements, markup fixes, content fixs, etc. +- XML printing support via "praudit -x". +- audit.log.5 expanded to include additional BSM token types. +- Added encoding and decoding routines for process64_ex, process32_ex, + subject32_ex, header64, and attr64 tokens. +- Additional audit event identifiers for listen, mlockall/munlockall, + getpath, POSIX message queues, and mandatory access control. + +OpenBSM 1.0 alpha 12 + +- Correct bug in auditreduce which prevented the -c option from working + correctly when the user specifies to process successful or failed events. + The problem stemmed from not having access to the return token at the time + the initial preselection occurred, but now a second preselection process + occurs while processing the return token. +- getacfilesz(3) API added to read new audit_control(5) filesz setting, + which auditd(8) now sets the kernel audit trail rotation size to. +- auditreduce(1) now uses stdin if no file names are specified on the command + line; this was the documented behavior previously, but it was not + implemented. Be more specific in auditreduce(1)'s examples section about + what might be done with the output of auditreduce. +- Add audit_warn(5) closefile event so that administrators can hook + termination of an audit trail file. For example, this might be used to + compress the trail file after it is closed. +- auditreduce(1) now uses regular expressions for pathname matching. Users can + now supply one or more (comma delimited) regular expressions for searching + the pathnames. If one of the regular expressions is prefixed with a tilde + (~), and a path matches, it will be excluded from the search results. + +OpenBSM 1.0 alpha 11 + +- Reclassify certain read/write operations as having no class rather than the + fr/fw class; our default classes audit intent (open) not operations (read, + write). +- Introduce AUE_SYSCTL_WRITE event so that BSD/Darwin systems can audit reads + and writes of sysctls as separate events. Add additional kernel + environment and jail events for FreeBSD. +- Break AUDIT_TRIGGER_OPEN_NEW into two events, AUDIT_TRIGGER_ROTATE_USER + (issued by the user audit(8) tool) and AUDIT_TRIGGER_ROTATE_KERNEL (issued + by the kernel audit implementation) so that they can be distinguished. +- Disable rate limiting of rotate requests; as the kernel doesn't retransmit + a dropped request, the log file will otherwise grow indefinitely if the + trigger is dropped. +- Improve auditd debugging output. +- Fix a number of threading related bugs in audit_control file reading + routines. +- Add APIs au_poltostr() and au_strtopol() to convert between text + representations of audit_control policy flags and the flags passed to + auditon(A_SETPOLICY) and retrieved from auditon(A_GETPOLICY). +- Add API getacpol() to return the 'policy:' entry from audit_control, an + extension to the Solaris file format to allow specification of policy + persistent flags. +- Update audump to print the audit_control policy field. +- Update auditd to read the audit_control policy field and set the kernel + policy to match it when configuring/reconfiguring. Remove the -s and -h + arguments as these policies are now set via the configuration file. If a + policy line is not found in the configuration file, continue with the + current default of setting AUDIT_CNT. +- Fix bugs in the parsing of large execve(2) arguments and environmental + variable tokens; increase maximum parsed argument and variable count. +- configure now detects strlcat(), used by policy-related functions. +- Reference token and record sample files added to test tree. + +OpenBSM 1.0 alpha 10 + +- auditd now generates complete audit records for its events, as required for + application-submitted audit records in the FreeBSD kernel audit + implementation. + +OpenBSM 1.0 alpha 9 + +- Rename many OpenBSM-specific constants and API elements containing the + strings "BSM" and "bsm" to "AUDIT" and "audit", observing that this is true + for almost all existing constants and APIs. +- Instead of passing a per-instance cookie directly into all audit filter + APIs, pass in the audit filter daemon state pointer, which is then used by + the module using an audit_filter_{get,set}cookie() API. This will allow + future service APIs provided by the filter daemon to maintain their own + state -- for example, per-module preselection state. + +OpenBSM 1.0 alpha 8 + +- Correct typo in definition of AUR_INT. +- Adopt OpenSolaris constant values for AUDIT_* configuration flags. +- Arguments to au_to_exec_args() and au_to_exec_env() no longer const. +- Add kernel versions of au_to_exec_args() and au_to_exec_env(). +- Fix exec argument type that is printed for env strings from 'arg' to 'env'. +- New OpenBSM token version number assigned, constants added for other + commonly seen version numbers. +- OpenBSM-specific events assigned numbers in the 43xxx range to avoid future + collisions with Solaris. Darwin events renamed to AUE_DARWIN_foo, as they + are now deprecated numberings. +- autoconf now detects clock_gettime(), which is not available on Darwin. +- praudit output fixes relating to arg32 and arg64 tokens. +- Maximum record size updated to 64k-1 to match Solaris record size limit. +- Various style and comment cleanups in include files. + +OpenBSM 1.0 alpha 7 + +- Adopted Solaris-compatible format for subject32_ex and subject64_ex + tokens, which previously did not correctly implement variable length + address storage. +- Prefer inttypes.h to stdint.h; enhance queue.h detection to test for + TAILQ_FOREACH_SAFE(), which is present in recent BSD queue.h's, but not + older ones. OpenBSM now builds on some FreeBSD 4.x versions. +- New event types for extended attributes, ACLs, and scheduling. + +OpenBSM 1.0 alpha 6 + +- Use AU_TO_WRITE and AU_NO_TO_WRITE for the 'keep' argument to au_close(); + previously we used hard-coded 0 and 1 values. +- Add man page for au_open(), au_write(), au_close(), and + au_close_buffer(). +- Support a more complete range of data types for the arbitrary data token: + add AUR_CHAR (alias to AUR_BYTE), remove AUR_LONG, add AUR_INT32 (alias + to AUR_INT), add AUR_INT64. +- Add au_close_token(), which allows writing a single token_t to a memory + buffer. Not likely to be used much by applications, but useful for + writing test tools. +- Modify au_to_file() so that it accepts a timeval in user space, not just + kernel -- this is not a Solaris BSM API so can be modified without + causing compatibility issues. +- Define a new API, au_to_header32_tm(), which adds a struct timeval + argument to the ordinary au_to_header32(), which is now implemented by + wrapping au_to_header32_tm() and calling gettimeofday(). #ifndef KERNEL + the APIs that invoke gettimeofday(), rather than having a variable + definition. Don't try to retrieve time zone information using + gettimeofday(), as it's not needed, and introduces possible failure + modes. +- Don't perform byte order transformations on the addr/machine fields of + the terminal ID that appears in the process32/subject32 tokens. These + are assumed to be IP addresses, and as such, to be in network byte + order. +- Universally, APIs now assume that IP addresses and ports are provided + in network byte order. APIs now generally provide these types in + network byte order when decoding. +- Beginnings of an OpenBSM test framework can now be found in openbsm/test. + This code is not built or installed by default. +- auditd now assigns more appropriate syslog levels to its debugging and + error information. +- Support for audit filters introduced: audit filters are dynamically + loaded shared objects that run in the context of a new daemon, + auditfilterd. The daemon reads from an audit pipe and feeds both BSM and + parsed versions of records to shared objects using a module API. This + will provide a framework for the writing of intrusion detection services. +- New utility API, audit_submit(), added to capture common elements of audit + record submission for many applications. + +OpenBSM 1.0 alpha 5 + +- Update install notes to indicate /etc files are to be installed manually. +- On systems without LOG_SECURITY, use LOG_AUTH. +- Convert to autoconf/automake in order to move to a more portable (not + BSD-specific) build infrastructure, and more easy conditional building of + components. Currently, the primary feature loss is that automake does + not have native support for manual symlinks. This will be addressed in a + future OpenBSM release. +- Add compat/queue.h, to be used on systems dated BSD queue macro libraries + (as found on Linux). +- Rename CHANGELOG to HISTORY, as our change log doesn't follow some of the + existing conventions for a CHANGELOG. +- Some private data structures moved from audit.h to audit_internal.h to + prevent inappropriate use by applications and name space pollution. +- Improved detection and use of endian macros using autoconf. +- Avoid non-portable use of struct in6_addr, which is largely opaque. +- Avoid leaking BSD kernel socket related token code to user space in + bsm_token.c. +- Teach System V IPC calls to look for Linux naming variations for certain + struct ipc_perm fields. +- Test for audit system calls, and if not present, don't build + bsm_wrappers.c, bsm_notify.c, audit(8), and auditd(8), which rely on + those system calls. +- au_close() is not implemented on systems that don't have audit system + calls, but au_close_buffer() is. +- Work around missing BSDisms in bsm_wrapper.c. +- Fix nested includes so including libbsm.h in an application on Linux + picks up the necessary definitions. + +OpenBSM 1.0 alpha 4 + +- Remove "audit" user example from audit_user, as it's not present on most + systems. +- Add cannot_audit() function non-Darwin systems that wraps auditon(); + required by OpenSSH BSM support. Convert Darwin cannot_audit() into a + function rather than a macro. +- Library build fixed on Darwin following include file tweaks. The native + Darwin sys/audit.h conflicts with bsm/audit.h due to duplicate types, so + for now we force bsm_wrappers.c to not perform a nested include of + sys/audit.h. + +OpenBSM 1.0 alpha 3 + +- Man page formatting, cross reference, mlinks, and accuracy improvements. +- auditd and tools now compile and run on FreeBSD/arm. +- auditd will now fchown() the trail file to the audit review group, if + defined at compile-time. +- Added AUE_SYSARCH for FreeBSD. +- Definition of AUE_SETFSGID fixed for Linux. + +OpenBSM 1.0 alpha 2 + +- Man page formatting improvements. +- A number of new audit event identifiers for FreeBSD, Linux, and POSIX.1b + events. +- Remove 'tfm' class, unused in OpenBSM. + +OpenBSM 1.0 alpha 1 + +- Import of Darwin74 BSM drop +- Use 'syslog' for audit log warnings, rather than echoing to a file in + audit_warn. +- Compile using BSD make infrastructure. +- Integrate bsm/ include files from Darwin74 XNU drop into OpenBSM. +- Narrow set of symbols and defines that are exposed in user space: don't + compile in code relying on kernel-only types such as 'struct socket'. +- Add README, including basic build documentation. +- Compilation of Apple-specific notify and Machroutines now #ifdef __APPLE__. +- Staticize libbsm global variables to avoid leakage into applications. +- Add free_au_user_ent() so that au_user_ent's don't have to be leaked. +- Clean up bogus nul-termination checks in libbsm. +- Add libbsm API man pages: au_class.3 au_control.3 au_event.3 + au_free_token.3 au_io.3 au_mask.3 au_token.3 au_user.3 libbsm.3. +- Add man pages for BSM system calls: audit.2 auditctl.2 auditon.2 getaudit.2 + getauid.2 setaudit.2 setauid.2 +- Modify various libbsm interfaces to more consistently return 'errno' values + on failure. +- Break out au_close() into constituent parts, allowing records to be written + to memory as well as files. +- Prefix various defines with 'BSM_' to reduce name space pollution. +- Added audit_internal.h, which can be used by a kernel audit implementation + wanting to rely on libbsm components. +- Build with warnings, and eliminate warnings. +- Make libbsm endian-independent, storing and reading BSM are big endian + (network byte order) rather than native byte order. More consistently + print IP addresses using the IP address print routine. These changes + make use of sys/endian.h from *BSD; since this isn't present on Darwin, + add it to OpenBSM as compat/endian.h, which is used only on Darwin. +- Import of Darwin80 BSM drop, including 64-bit file IDs, better + documentation of private APIs, and bug fixes. +- White space cleanup. +- Add audit.log.5, a first cut at a man page documenting the BSM file format. +- Teach au_read_rec() to recognize stand-alone file tokens, which are present + at the beginning and end of Solaris audit trails. Technically, these + appear to violate the high level BSM spec, which suggests that all tokens + are present in records, but need to be supported. +- Implement HEADER64, ATTR64, SUBJECT64 token types, which make it possible + to run praudit(1) on basic Solaris BSM streams. +- Switched to Solaris spelling of token names; Darwin spellings are now + deprecated and will be removed in a future version of OpenBSM. +- Adopt Solaris model for representing IPv4 and IPv6 addresses. +- Prefer C99 types. +- Attempt to universally adopt the BSD style(9) coding style for + consistency. +- auditreduce(1) now has a usage message. +- Update support for auditctl(2) system call to support FreeBSD. +- Add support for /dev/audit as the trigger source on FreeBSD. +- Add additional event types for Darwin, FreeBSD, and Solaris. Annotate + conflicts (there are a few, unfortunately). Correct spellings, comment, + sort, etc. These include {get,set}res[ug]id(), sendfile(), lchflags(), + eaccess(), kqueue(), kevent(), poll(), lchmod(). +- Relicensed under a BSD license, many thanks to Apple, Inc! +- Many bug fixes, cleanups, thread safety in the class, control, event, + and user system audit databases. Annotate some persisting atomicity + bugs associated with the API and implementation. +- Add audump test tool. +- Adopt OpenSolaris BSM API memory semantics: caller allocates memory, + or static memory is returned for non-_r() versions of API calls. + _free() calls dropped as a result, and source code compatibility with + OpenSolaris improved significantly. +- Annotate BSM events with origin OS and compatibility information. +- auditd(8), audit(8) added to the OpenBSM distribution. auditd extended + to support reloading of kernel event table. +- Allow comments in /etc/security configuration files. + +$P4: //depot/projects/trustedbsd/openbsm/NEWS#9 $ Modified: head/contrib/openbsm/README ============================================================================== --- head/contrib/openbsm/README Tue Dec 2 22:45:01 2008 (r185572) +++ head/contrib/openbsm/README Tue Dec 2 23:26:43 2008 (r185573) @@ -1,4 +1,4 @@ -OpenBSM 1.0 +OpenBSM 1.1 alpha 1 Introduction @@ -16,12 +16,13 @@ may be found in the FreeBSD and Mac OS X OpenBSM consists of several directories: bin/ Audit-related command line tools - bsm/ System include files for BSM + bsm/ Library include files for BSM compat/ Compatibility code to build on various OS's etc/ Sample /etc/security configuration files libbsm/ Implementation of BSM library interfaces and man pages man/ System call and configuration file man pages modules/ Directory for auditfilterd module source + sys/ System include files for BSM test/ Test token sets and geneneration program tools/ Tool directory, including audump to dump databases @@ -34,66 +35,9 @@ The following programs are included with audump Debugging tool to parse and print audit databases praudit Tool to print audit trails - Building + Build and Installation -OpenBSM is currently built using autoconf and automake, which should allow -for building on a range of operating systems, including FreeBSD, Mac OS X, -and Linux. Depending on the availability of audit facilities in the -underlying operating system, some components that depend on kernel audit -support are built conditionally. Typically, build will be performed using: - - ./configure - make - -To install, use: - - make install - -You may wish to specify that the OpenBSM components not be installed in the -base system, rather in a specific directory. This may be done using the ---prefix argument to configure. If installing to a specific directory, -remember to update your library path so that running tools from that -directory the correct libbsm is used: - - ./configure --prefix=/home/rwatson/openbsm - make - make install - LD_LIBRARY_PATH=/home/rwatson/openbsm/libbsm ; export LD_LIBRARY_PATH - -You will need to manually propagate openbsm/etc/* into /etc on your system; -this is not done automatically so as to avoid disrupting the current -configuration. Currently, the locations of these files is not configurable. - - Credits - -The following organizations and individuals have contributed substantially to -the development of OpenBSM: - - Apple Computer, Inc. - McAfee Research, McAfee, Inc. - SPARTA, Inc. - Robert Watson - Wayne Salamon - Suresh Krishnaswamy - Kevin Van Vechten - Tom Rhodes - Wojciech Koszek - Chunyang Yuan - Poul-Henning Kamp - Christian Brueffer - Olivier Houchard - Christian Peron - Martin Fong - Pawel Worach - Martin Englund - Ruslan Ermilov - Martin Voros - Diego Giagio - Alex Samorukov - -In addition, Coverity, Inc.'s Prevent(tm) static analysis tool and Gimpel -Software's FlexeLint tool were used to identify a number of bugs in the -OpenBSM implementation. +Please see the file INSTALL for build and installation instructions. Contributions @@ -111,4 +55,4 @@ Information on TrustedBSD may be found o http://www.TrustedBSD.org/ -$P4: //depot/projects/trustedbsd/openbsm/README#24 $ +$P4: //depot/projects/trustedbsd/openbsm/README#32 $ Modified: head/contrib/openbsm/TODO ============================================================================== --- head/contrib/openbsm/TODO Tue Dec 2 22:45:01 2008 (r185572) +++ head/contrib/openbsm/TODO Tue Dec 2 23:26:43 2008 (r185573) @@ -1,5 +1,5 @@ -- Teach libbsm about any additional 64-bit token types that are present - in more recent Solaris versions. +OpenBSM TODO + - Build a regression test suite for libbsm that generates each token type and then compares the results with known good data. Make sure to test that things work properly with respect to endianness of the local @@ -18,5 +18,7 @@ trailer context. - Put hostname in trail file name. - Document audit_warn event arguments. +- Allow the path /etc/security to be configured at configure-time so that + alternative locations can be used. -$P4: //depot/projects/trustedbsd/openbsm/TODO#9 $ +$P4: //depot/projects/trustedbsd/openbsm/TODO#11 $ Modified: head/contrib/openbsm/VERSION ============================================================================== --- head/contrib/openbsm/VERSION Tue Dec 2 22:45:01 2008 (r185572) +++ head/contrib/openbsm/VERSION Tue Dec 2 23:26:43 2008 (r185573) @@ -1 +1 @@ -OPENBSM_1_0 +OPENBSM_1_1_ALPHA_2 Modified: head/contrib/openbsm/bin/Makefile.in ============================================================================== --- head/contrib/openbsm/bin/Makefile.in Tue Dec 2 22:45:01 2008 (r185572) +++ head/contrib/openbsm/bin/Makefile.in Tue Dec 2 23:26:43 2008 (r185573) @@ -15,7 +15,7 @@ @SET_MAKE@ # -# $P4: //depot/projects/trustedbsd/openbsm/bin/Makefile.in#5 $ +# $P4: //depot/projects/trustedbsd/openbsm/bin/Makefile.in#8 $ # VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ @@ -104,6 +104,7 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ +MIG = @MIG@ MKDIR_P = @MKDIR_P@ OBJEXT = @OBJEXT@ PACKAGE = @PACKAGE@ Modified: head/contrib/openbsm/bin/audit/Makefile.am ============================================================================== --- head/contrib/openbsm/bin/audit/Makefile.am Tue Dec 2 22:45:01 2008 (r185572) +++ head/contrib/openbsm/bin/audit/Makefile.am Tue Dec 2 23:26:43 2008 (r185573) @@ -1,10 +1,23 @@ # -# $P4: //depot/projects/trustedbsd/openbsm/bin/audit/Makefile.am#1 $ +# $P4: //depot/projects/trustedbsd/openbsm/bin/audit/Makefile.am#4 $ # -INCLUDES = -I$(top_srcdir) +if USE_NATIVE_INCLUDES +INCLUDES = -I$(top_builddir) -I$(top_srcdir) +else +INCLUDES = -I$(top_builddir) -I$(top_srcdir) -I$(top_srcdir)/sys +endif sbin_PROGRAMS = audit -audit_SOURCES = audit.c audit_LDADD = $(top_builddir)/libbsm/libbsm.la man8_MANS = audit.8 + +if USE_MACH_IPC +audit_SOURCES = auditd_control_user.c audit.c +CLEANFILES = auditd_control_user.c auditd_control_user.h + +auditd_control_user.c: $(top_srcdir)/bin/auditd/auditd_control.defs + $(MIG) -user auditd_control_user.c -header auditd_control_user.h -server /dev/null -sheader /dev/null $(top_srcdir)/bin/auditd/auditd_control.defs +else +audit_SOURCES = audit.c +endif Modified: head/contrib/openbsm/bin/audit/Makefile.in ============================================================================== --- head/contrib/openbsm/bin/audit/Makefile.in Tue Dec 2 22:45:01 2008 (r185572) +++ head/contrib/openbsm/bin/audit/Makefile.in Tue Dec 2 23:26:43 2008 (r185573) @@ -15,7 +15,7 @@ @SET_MAKE@ # -# $P4: //depot/projects/trustedbsd/openbsm/bin/audit/Makefile.in#4 $ +# $P4: //depot/projects/trustedbsd/openbsm/bin/audit/Makefile.in#9 $ # VPATH = @srcdir@ @@ -49,7 +49,10 @@ CONFIG_CLEAN_FILES = am__installdirs = "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(man8dir)" sbinPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(sbin_PROGRAMS) -am_audit_OBJECTS = audit.$(OBJEXT) +am__audit_SOURCES_DIST = audit.c auditd_control_user.c +@USE_MACH_IPC_FALSE@am_audit_OBJECTS = audit.$(OBJEXT) +@USE_MACH_IPC_TRUE@am_audit_OBJECTS = auditd_control_user.$(OBJEXT) \ +@USE_MACH_IPC_TRUE@ audit.$(OBJEXT) audit_OBJECTS = $(am_audit_OBJECTS) audit_DEPENDENCIES = $(top_builddir)/libbsm/libbsm.la DEFAULT_INCLUDES = -I. -I$(top_builddir)/config@am__isrc@ @@ -65,7 +68,7 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLF --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ SOURCES = $(audit_SOURCES) -DIST_SOURCES = $(audit_SOURCES) +DIST_SOURCES = $(am__audit_SOURCES_DIST) man8dir = $(mandir)/man8 NROFF = nroff MANS = $(man8_MANS) @@ -113,6 +116,7 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ +MIG = @MIG@ MKDIR_P = @MKDIR_P@ OBJEXT = @OBJEXT@ PACKAGE = @PACKAGE@ @@ -179,10 +183,13 @@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -INCLUDES = -I$(top_srcdir) -audit_SOURCES = audit.c +@USE_NATIVE_INCLUDES_FALSE@INCLUDES = -I$(top_builddir) -I$(top_srcdir) -I$(top_srcdir)/sys +@USE_NATIVE_INCLUDES_TRUE@INCLUDES = -I$(top_builddir) -I$(top_srcdir) audit_LDADD = $(top_builddir)/libbsm/libbsm.la man8_MANS = audit.8 +@USE_MACH_IPC_FALSE@audit_SOURCES = audit.c +@USE_MACH_IPC_TRUE@audit_SOURCES = auditd_control_user.c audit.c +@USE_MACH_IPC_TRUE@CLEANFILES = auditd_control_user.c auditd_control_user.h all: all-am .SUFFIXES: @@ -255,6 +262,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audit.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/auditd_control_user.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -426,6 +434,7 @@ install-strip: mostlyclean-generic: clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) @@ -511,6 +520,9 @@ uninstall-man: uninstall-man8 tags uninstall uninstall-am uninstall-man uninstall-man8 \ uninstall-sbinPROGRAMS + +@USE_MACH_IPC_TRUE@auditd_control_user.c: $(top_srcdir)/bin/auditd/auditd_control.defs +@USE_MACH_IPC_TRUE@ $(MIG) -user auditd_control_user.c -header auditd_control_user.h -server /dev/null -sheader /dev/null $(top_srcdir)/bin/auditd/auditd_control.defs # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: Modified: head/contrib/openbsm/bin/audit/audit.8 ============================================================================== --- head/contrib/openbsm/bin/audit/audit.8 Tue Dec 2 22:45:01 2008 (r185572) +++ head/contrib/openbsm/bin/audit/audit.8 Tue Dec 2 23:26:43 2008 (r185573) @@ -1,4 +1,4 @@ -.\" Copyright (c) 2004 Apple Computer, Inc. +.\" Copyright (c) 2004 Apple Inc. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -10,7 +10,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of +.\" 3. Neither the name of Apple Inc. ("Apple") nor the names of .\" its contributors may be used to endorse or promote products derived .\" from this software without specific prior written permission. .\" @@ -25,7 +25,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $P4: //depot/projects/trustedbsd/openbsm/bin/audit/audit.8#10 $ +.\" $P4: //depot/projects/trustedbsd/openbsm/bin/audit/audit.8#11 $ .\" .Dd October 2, 2006 .Dt AUDIT 8 Modified: head/contrib/openbsm/bin/audit/audit.c ============================================================================== --- head/contrib/openbsm/bin/audit/audit.c Tue Dec 2 22:45:01 2008 (r185572) +++ head/contrib/openbsm/bin/audit/audit.c Tue Dec 2 23:26:43 2008 (r185573) @@ -1,5 +1,5 @@ -/* - * Copyright (c) 2005 Apple Computer, Inc. +/*- + * Copyright (c) 2005-2008 Apple Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -11,7 +11,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * 3. Neither the name of Apple Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -26,7 +26,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $P4: //depot/projects/trustedbsd/openbsm/bin/audit/audit.c#8 $ + * $P4: //depot/projects/trustedbsd/openbsm/bin/audit/audit.c#11 $ */ /* * Program to trigger the audit daemon with a message that is either: @@ -37,7 +37,12 @@ */ #include +#include +#ifdef HAVE_FULL_QUEUE_H #include +#else /* !HAVE_FULL_QUEUE_H */ +#include +#endif /* !HAVE_FULL_QUEUE_H */ #include #include @@ -47,6 +52,58 @@ #include #include + +static int send_trigger(unsigned int); + +#ifdef USE_MACH_IPC +#include +#include +#include +#include +#include +#include +#include + +#include "auditd_control_user.h" + +static int +send_trigger(unsigned int trigger) +{ + mach_port_t serverPort; + kern_return_t error; + + error = host_get_audit_control_port(mach_host_self(), &serverPort); + if (error != KERN_SUCCESS) { + mach_error("Cannot get auditd_control Mach port: ", error); + return (-1); + } + + error = auditd_control(serverPort, trigger); + if (error != KERN_SUCCESS) { + mach_error("Error sending trigger: ", error); + return (-1); + } + + return (0); +} + +#else /* ! USE_MACH_IPC */ + +static int +send_trigger(unsigned int trigger) +{ + int error; + + error = auditon(A_SENDTRIGGER, &trigger, sizeof(trigger)); + if (error != 0) { + perror("Error sending trigger"); + return (-1); + } + + return (0); +} +#endif /* ! USE_MACH_IPC */ + static void usage(void) { @@ -88,11 +145,9 @@ main(int argc, char **argv) break; } } - if (auditon(A_SENDTRIGGER, &trigger, sizeof(trigger)) < 0) { - perror("Error sending trigger"); + if (send_trigger(trigger) < 0) exit(-1); - } else { - printf("Trigger sent.\n"); - exit (0); - } + + printf("Trigger sent.\n"); + exit (0); } Modified: head/contrib/openbsm/bin/auditd/Makefile.am ============================================================================== --- head/contrib/openbsm/bin/auditd/Makefile.am Tue Dec 2 22:45:01 2008 (r185572) +++ head/contrib/openbsm/bin/auditd/Makefile.am Tue Dec 2 23:26:43 2008 (r185573) @@ -1,10 +1,26 @@ # -# $P4: //depot/projects/trustedbsd/openbsm/bin/auditd/Makefile.am#1 $ +# $P4: //depot/projects/trustedbsd/openbsm/bin/auditd/Makefile.am#4 $ # -INCLUDES = -I$(top_srcdir) +if USE_NATIVE_INCLUDES +INCLUDES = -I$(top_builddir) -I$(top_srcdir) +else +INCLUDES = -I$(top_builddir) -I$(top_srcdir) -I$(top_srcdir)/sys +endif sbin_PROGRAMS = auditd -auditd_SOURCES = audit_warn.c auditd.c auditd_LDADD = $(top_builddir)/libbsm/libbsm.la man8_MANS = auditd.8 + +if USE_MACH_IPC +auditd_SOURCES = auditd_control_server.c audit_triggers_server.c audit_warn.c auditd.c +CLEANFILES = auditd_control_server.c auditd_control_server.h audit_triggers_server.c audit_triggers_server.h + +auditd_control_server.c: auditd_control.defs + $(MIG) -user /dev/null -header /dev/null -server auditd_control_server.c -sheader auditd_control_server.h $(top_srcdir)/bin/auditd/auditd_control.defs + +audit_triggers_server.c: audit_triggers.defs + $(MIG) -user /dev/null -header /dev/null -server audit_triggers_server.c -sheader audit_triggers_server.h $(top_srcdir)/bin/auditd/audit_triggers.defs +else +auditd_SOURCES = audit_warn.c auditd.c +endif Modified: head/contrib/openbsm/bin/auditd/Makefile.in ============================================================================== --- head/contrib/openbsm/bin/auditd/Makefile.in Tue Dec 2 22:45:01 2008 (r185572) +++ head/contrib/openbsm/bin/auditd/Makefile.in Tue Dec 2 23:26:43 2008 (r185573) @@ -15,7 +15,7 @@ @SET_MAKE@ # -# $P4: //depot/projects/trustedbsd/openbsm/bin/auditd/Makefile.in#4 $ +# $P4: //depot/projects/trustedbsd/openbsm/bin/auditd/Makefile.in#9 $ # VPATH = @srcdir@ @@ -49,7 +49,14 @@ CONFIG_CLEAN_FILES = am__installdirs = "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(man8dir)" sbinPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(sbin_PROGRAMS) -am_auditd_OBJECTS = audit_warn.$(OBJEXT) auditd.$(OBJEXT) +am__auditd_SOURCES_DIST = audit_warn.c auditd.c \ + auditd_control_server.c audit_triggers_server.c +@USE_MACH_IPC_FALSE@am_auditd_OBJECTS = audit_warn.$(OBJEXT) \ +@USE_MACH_IPC_FALSE@ auditd.$(OBJEXT) +@USE_MACH_IPC_TRUE@am_auditd_OBJECTS = \ +@USE_MACH_IPC_TRUE@ auditd_control_server.$(OBJEXT) \ +@USE_MACH_IPC_TRUE@ audit_triggers_server.$(OBJEXT) \ +@USE_MACH_IPC_TRUE@ audit_warn.$(OBJEXT) auditd.$(OBJEXT) auditd_OBJECTS = $(am_auditd_OBJECTS) auditd_DEPENDENCIES = $(top_builddir)/libbsm/libbsm.la DEFAULT_INCLUDES = -I. -I$(top_builddir)/config@am__isrc@ @@ -65,7 +72,7 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLF --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ SOURCES = $(auditd_SOURCES) -DIST_SOURCES = $(auditd_SOURCES) +DIST_SOURCES = $(am__auditd_SOURCES_DIST) man8dir = $(mandir)/man8 NROFF = nroff MANS = $(man8_MANS) @@ -113,6 +120,7 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ +MIG = @MIG@ MKDIR_P = @MKDIR_P@ OBJEXT = @OBJEXT@ PACKAGE = @PACKAGE@ @@ -179,10 +187,13 @@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -INCLUDES = -I$(top_srcdir) -auditd_SOURCES = audit_warn.c auditd.c +@USE_NATIVE_INCLUDES_FALSE@INCLUDES = -I$(top_builddir) -I$(top_srcdir) -I$(top_srcdir)/sys +@USE_NATIVE_INCLUDES_TRUE@INCLUDES = -I$(top_builddir) -I$(top_srcdir) auditd_LDADD = $(top_builddir)/libbsm/libbsm.la man8_MANS = auditd.8 +@USE_MACH_IPC_FALSE@auditd_SOURCES = audit_warn.c auditd.c +@USE_MACH_IPC_TRUE@auditd_SOURCES = auditd_control_server.c audit_triggers_server.c audit_warn.c auditd.c +@USE_MACH_IPC_TRUE@CLEANFILES = auditd_control_server.c auditd_control_server.h audit_triggers_server.c audit_triggers_server.h all: all-am .SUFFIXES: @@ -254,8 +265,10 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audit_triggers_server.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audit_warn.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/auditd.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/auditd_control_server.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -427,6 +440,7 @@ install-strip: mostlyclean-generic: clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) @@ -512,6 +526,12 @@ uninstall-man: uninstall-man8 tags uninstall uninstall-am uninstall-man uninstall-man8 \ *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From delphij at FreeBSD.org Tue Dec 2 17:48:19 2008 From: delphij at FreeBSD.org (Xin LI) Date: Tue Dec 2 17:48:31 2008 Subject: svn commit: r185574 - head/share/man/man4 Message-ID: <200812030148.mB31mJJD077415@svn.freebsd.org> Author: delphij Date: Wed Dec 3 01:48:19 2008 New Revision: 185574 URL: http://svn.freebsd.org/changeset/base/185574 Log: Update bce(4)'s hardware list to reflect the recent update to driver. MFC after: 3 days Modified: head/share/man/man4/bce.4 Modified: head/share/man/man4/bce.4 ============================================================================== --- head/share/man/man4/bce.4 Tue Dec 2 23:26:43 2008 (r185573) +++ head/share/man/man4/bce.4 Wed Dec 3 01:48:19 2008 (r185574) @@ -28,12 +28,12 @@ .\" .\" $FreeBSD$ .\" -.Dd June 24, 2007 +.Dd December 2, 2008 .Dt BCE 4 .Os .Sh NAME .Nm bce -.Nd "Broadcom NetXtreme II (BCM5706/BCM5708) PCI/PCIe Gigabit Ethernet adapter driver" +.Nd "Broadcom NetXtreme II (BCM5706/5708/5709/5716) PCI/PCIe Gigabit Ethernet adapter driver" .Sh SYNOPSIS To compile this driver into the kernel, place the following lines in your @@ -53,12 +53,13 @@ if_bce_load="YES" The .Nm driver supports Broadcom's NetXtreme II product family, including the -BCM5706 and BCM5708 Ethernet controllers. +BCM5706, BCM5708, BCM5709 and BCM5716 Ethernet controllers. .Pp The NetXtreme II product family is composed of various Converged NIC (or CNIC) Ethernet controllers which support a TCP Offload Engine (TOE), Remote DMA (RDMA), and iSCSI acceleration, in addition to standard L2 Ethernet traffic, all on the same controller. +.Pp The following features are supported in the .Nm driver under @@ -136,10 +137,26 @@ following: .Pp .Bl -bullet -compact .It +Broadcom NetXtreme II BCM5706 1000Base-SX +.It +Broadcom NetXtreme II BCM5706 1000Base-T +.It +Broadcom NetXtreme II BCM5708 1000Base-SX +.It +Broadcom NetXtreme II BCM5708 1000Base-T +.It +Broadcom NetXtreme II BCM5709 1000Base-SX +.It +Broadcom NetXtreme II BCM5709 1000Base-T +.It +Broadcom NetXtreme II BCM5716 1000Base-T +.It Dell PowerEdge 1950 integrated BCM5708 NIC .It Dell PowerEdge 2950 integrated BCM5708 NIC .It +HP NC370F Multifunction Gigabit Server Adapter +.It HP NC370T Multifunction Gigabit Server Adapter .It HP NC370i Multifunction Gigabit Server Adapter From yongari at FreeBSD.org Tue Dec 2 19:20:18 2008 From: yongari at FreeBSD.org (Pyun YongHyeon) Date: Tue Dec 2 19:20:31 2008 Subject: svn commit: r185575 - head/sys/pci Message-ID: <200812030320.mB33KIE6079468@svn.freebsd.org> Author: yongari Date: Wed Dec 3 03:20:18 2008 New Revision: 185575 URL: http://svn.freebsd.org/changeset/base/185575 Log: Update if_iqdrops instead of if_ierrors when m_devget(9) fails. Modified: head/sys/pci/if_rl.c Modified: head/sys/pci/if_rl.c ============================================================================== --- head/sys/pci/if_rl.c Wed Dec 3 01:48:19 2008 (r185574) +++ head/sys/pci/if_rl.c Wed Dec 3 03:20:18 2008 (r185575) @@ -1302,18 +1302,13 @@ rl_rxeof(struct rl_softc *sc) if (total_len > wrap) { m = m_devget(rxbufpos, total_len, RL_ETHER_ALIGN, ifp, NULL); - if (m == NULL) { - ifp->if_ierrors++; - } else { + if (m != NULL) m_copyback(m, wrap, total_len - wrap, sc->rl_cdata.rl_rx_buf); - } cur_rx = (total_len - wrap + ETHER_CRC_LEN); } else { m = m_devget(rxbufpos, total_len, RL_ETHER_ALIGN, ifp, NULL); - if (m == NULL) - ifp->if_ierrors++; cur_rx += total_len + 4 + ETHER_CRC_LEN; } @@ -1321,8 +1316,10 @@ rl_rxeof(struct rl_softc *sc) cur_rx = (cur_rx + 3) & ~3; CSR_WRITE_2(sc, RL_CURRXADDR, cur_rx - 16); - if (m == NULL) + if (m == NULL) { + ifp->if_iqdrops++; continue; + } ifp->if_ipackets++; RL_UNLOCK(sc); From yongari at FreeBSD.org Wed Dec 3 00:56:02 2008 From: yongari at FreeBSD.org (Pyun YongHyeon) Date: Wed Dec 3 00:56:13 2008 Subject: svn commit: r185576 - head/sys/dev/ale Message-ID: <200812030856.mB38u1SG086149@svn.freebsd.org> Author: yongari Date: Wed Dec 3 08:56:01 2008 New Revision: 185576 URL: http://svn.freebsd.org/changeset/base/185576 Log: Add some PHY magic to enable PHY hibernation and 1000baseT/10baseT power adjustment. This change is required to guarantee correct operation on certain switches. Submitted by: Jie Yang < Jie.Yang <> Atheros com > Modified: head/sys/dev/ale/if_ale.c Modified: head/sys/dev/ale/if_ale.c ============================================================================== --- head/sys/dev/ale/if_ale.c Wed Dec 3 03:20:18 2008 (r185575) +++ head/sys/dev/ale/if_ale.c Wed Dec 3 08:56:01 2008 (r185576) @@ -385,6 +385,39 @@ ale_phy_reset(struct ale_softc *sc) GPHY_CTRL_EXT_RESET | GPHY_CTRL_HIB_EN | GPHY_CTRL_HIB_PULSE | GPHY_CTRL_SEL_ANA_RESET | GPHY_CTRL_PHY_PLL_ON); DELAY(1000); + +#define ATPHY_DBG_ADDR 0x1D +#define ATPHY_DBG_DATA 0x1E + + /* Enable hibernation mode. */ + ale_miibus_writereg(sc->ale_dev, sc->ale_phyaddr, + ATPHY_DBG_ADDR, 0x0B); + ale_miibus_writereg(sc->ale_dev, sc->ale_phyaddr, + ATPHY_DBG_DATA, 0xBC00); + /* Set Class A/B for all modes. */ + ale_miibus_writereg(sc->ale_dev, sc->ale_phyaddr, + ATPHY_DBG_ADDR, 0x00); + ale_miibus_writereg(sc->ale_dev, sc->ale_phyaddr, + ATPHY_DBG_DATA, 0x02EF); + /* Enable 10BT power saving. */ + ale_miibus_writereg(sc->ale_dev, sc->ale_phyaddr, + ATPHY_DBG_ADDR, 0x12); + ale_miibus_writereg(sc->ale_dev, sc->ale_phyaddr, + ATPHY_DBG_DATA, 0x4C04); + /* Adjust 1000T power. */ + ale_miibus_writereg(sc->ale_dev, sc->ale_phyaddr, + ATPHY_DBG_ADDR, 0x04); + ale_miibus_writereg(sc->ale_dev, sc->ale_phyaddr, + ATPHY_DBG_ADDR, 0x8BBB); + /* 10BT center tap voltage. */ + ale_miibus_writereg(sc->ale_dev, sc->ale_phyaddr, + ATPHY_DBG_ADDR, 0x05); + ale_miibus_writereg(sc->ale_dev, sc->ale_phyaddr, + ATPHY_DBG_ADDR, 0x2C46); + +#undef ATPHY_DBG_ADDR +#undef ATPHY_DBG_DATA + DELAY(1000); } static int From yongari at FreeBSD.org Wed Dec 3 01:01:13 2008 From: yongari at FreeBSD.org (Pyun YongHyeon) Date: Wed Dec 3 01:01:19 2008 Subject: svn commit: r185577 - head/sys/dev/ale Message-ID: <200812030901.mB391DHK086295@svn.freebsd.org> Author: yongari Date: Wed Dec 3 09:01:12 2008 New Revision: 185577 URL: http://svn.freebsd.org/changeset/base/185577 Log: AR8113 also need to set DMA read burst value. This should fix occasional DMA read error seen on AR8113. Submitted by: Jie Yang < Jie.Yang <> Atheros com > Modified: head/sys/dev/ale/if_ale.c Modified: head/sys/dev/ale/if_ale.c ============================================================================== --- head/sys/dev/ale/if_ale.c Wed Dec 3 08:56:01 2008 (r185576) +++ head/sys/dev/ale/if_ale.c Wed Dec 3 09:01:12 2008 (r185577) @@ -2786,10 +2786,8 @@ ale_init_locked(struct ale_softc *sc) TX_JUMBO_THRESH_UNIT_SHIFT); } /* Configure TxQ. */ - reg = 0; - if ((sc->ale_flags & ALE_FLAG_JUMBO) != 0) - reg = (128 << (sc->ale_dma_rd_burst >> DMA_CFG_RD_BURST_SHIFT)) - << TXQ_CFG_TX_FIFO_BURST_SHIFT; + reg = (128 << (sc->ale_dma_rd_burst >> DMA_CFG_RD_BURST_SHIFT)) + << TXQ_CFG_TX_FIFO_BURST_SHIFT; reg |= (TXQ_CFG_TPD_BURST_DEFAULT << TXQ_CFG_TPD_BURST_SHIFT) & TXQ_CFG_TPD_BURST_MASK; CSR_WRITE_4(sc, ALE_TXQ_CFG, reg | TXQ_CFG_ENHANCED_MODE | TXQ_CFG_ENB); From luigi at FreeBSD.org Wed Dec 3 06:53:59 2008 From: luigi at FreeBSD.org (Luigi Rizzo) Date: Wed Dec 3 06:54:12 2008 Subject: svn commit: r185579 - in head: sys/boot/i386/boot0 usr.sbin/boot0cfg Message-ID: <200812031453.mB3Erx4I093690@svn.freebsd.org> Author: luigi Date: Wed Dec 3 14:53:59 2008 New Revision: 185579 URL: http://svn.freebsd.org/changeset/base/185579 Log: Another, hopefully final set of changes to boot0 and boot0cfg. boot0.S changes: + import a patch from Christoph Mallon to rearrange the various print functions and save another couple of bytes; + implement the suggestion in PR 70531 to enable booting from any valid partition because even the extended partitions that were previously in our kill list may contain a valid boot loader. This simplifies the code and saves some bytes; + followwing up PR 127764, implement conditional code to preserve the 'Volume ID' which might be used by other OS (NT, XP, Vista) and is located at offset 0x1b8. This requires a relocation of the parameter block within the boot sector -- there is no other possible workaround. To address this, boot0cfg has been updated to handle both versions of the boot code; + slightly rearrange the strings printed in the menus to make the code buildable with all options. Given the tight memory budget, this means that with certain options we need to shrink or remove certain labels. and especially: make -DVOLUME_LABEL -DPXE the default options. This means that the newly built boot0 block will preserve the Volume ID, and has the (hidden) option F6 to boot from INT18/PXE. I think the extra functionality is well worth the change. The most visible difference here is that the 'Default: ' string now becomes 'Boot: ' (it can be reverted to the old value but then we need to nuke 1/2 partition name or entries to make up for the extra room). boot0cfg changes: + modify the code to recognise the new boot0 structure (with the relocated options block to make room for the Volume id). + add two options, '-i xxxx-xxxx' to set the volume ID, -e c to modify the character printed in case of bad input PR: 127764 70531 Submitted by: Christoph Mallon (portions) MFC after: 4 weeks Modified: head/sys/boot/i386/boot0/Makefile head/sys/boot/i386/boot0/boot0.S head/usr.sbin/boot0cfg/boot0cfg.8 head/usr.sbin/boot0cfg/boot0cfg.c Modified: head/sys/boot/i386/boot0/Makefile ============================================================================== --- head/sys/boot/i386/boot0/Makefile Wed Dec 3 11:48:20 2008 (r185578) +++ head/sys/boot/i386/boot0/Makefile Wed Dec 3 14:53:59 2008 (r185579) @@ -9,12 +9,14 @@ SRCS= ${PROG}.S # Additional options that you can specify with make OPTS="..." # (these only apply to boot0.S) # +# -DVOLUME_SERIAL support volume serial number (NT, XP, Vista) # -DSIO do I/O using COM1: # -DPXE fallback to INT18/PXE with F6 # -DCHECK_DRIVE enable checking drive number # -DONLY_F_KEYS accept only Fx keys in console # -DTEST print drive number on entry # +OPTS ?= -DVOLUME_SERIAL -DPXE CFLAGS += ${OPTS} # Flags used in the boot0.S code: Modified: head/sys/boot/i386/boot0/boot0.S ============================================================================== --- head/sys/boot/i386/boot0/boot0.S Wed Dec 3 11:48:20 2008 (r185578) +++ head/sys/boot/i386/boot0/boot0.S Wed Dec 3 14:53:59 2008 (r185579) @@ -30,10 +30,16 @@ #ifdef ONLY_F_KEYS /* Only F1..F6, no digits on console */ #endif -#ifdef TEST /* enable some test code */ -#ifndef ONLY_F_KEYS -#define ONLY_F_KEYS /* make room for the test code */ +#ifdef VOLUME_SERIAL /* support Volume serial number */ +#define B0_BASE 0x1ae /* move the internal data area */ +#define SAVE_MEMORY +#else +#define B0_BASE 0x1b2 #endif + +#ifdef TEST /* enable some test code */ +#define SAVE_MEMORY +#define SAVE_MORE_MEMORY #endif /* @@ -118,7 +124,7 @@ * to change the value passed to the linker in the Makefile * PRT_OFF is the location of the partition table (from the MBR standard). * B0_OFF is the location of the data area, known to boot0cfg so - * it cannot be changed. + * it cannot be changed. Computed as a negative offset from 0x200 * MAGIC is the signature of a boot block. */ @@ -127,7 +133,7 @@ .set LOAD,0x7c00 # Load address .set PRT_OFF,0x1be # Partition table - .set B0_OFF,0x1b2 # Offset of boot0 data + .set B0_OFF,(B0_BASE-0x200) # Offset of boot0 data .set MAGIC,0xaa55 # Magic: bootable @@ -144,15 +150,16 @@ * We need to define them as constant as the assembler cannot * compute them in its single pass. */ - .set _NXTDRV, -0x48 # Next drive - .set _OPT, -0x47 # Default option - .set _SETDRV, -0x46 # Drive to force - .set _FLAGS, -0x45 # Flags + .set _NXTDRV, B0_OFF+6 # Next drive + .set _OPT, B0_OFF+7 # Default option + .set _SETDRV, B0_OFF+8 # Drive to force + .set _FLAGS, B0_OFF+9 # Flags .set SETDRV, 0x20 # the 'setdrv' flag .set NOUPDATE, 0x40 # the 'noupdate' flag .set USEPACKET, 0x80 # the 'packet' flag - .set _TICKS, -0x44 # Timeout ticks - .set _FAKE,0x0 # Fake partition table + + /* ticks is at a fixed position */ + .set _TICKS, (PRT_OFF - 0x200 - 2) # Timeout ticks .set _MNUOPT, 0x10 # Saved menu entries .set TLEN, (desc_ofs - bootable_ids) # size of bootable ids @@ -260,26 +267,16 @@ save_curdrive: movb %dl, (%bp) # Save read_entry: movb %ch,-0x4(%bx) # Zero active flag (ch == 0) btw %dx,_FLAGS(%bp) # Entry enabled? jnc next_entry # No - /* - * Lookup type in the 'non_bootable_ids' table, skip matching entries. - * This is implemented is by setting %di to the start of the - * exclude table, and %cl to the length of the table itself. After the - * 'repne scasb' the zero flag is set if we found a match. - * If not, %di points to the beginning of the 'valid' types, - * which is what we need for the next check. - */ movb (%bx),%al # Load type - movw $non_bootable_ids,%di # Lookup tables - movb $(bootable_ids-non_bootable_ids),%cl # length - repne # Exclude - scasb # partition? - je next_entry # Yes, ignore it + test %al, %al # skip empty partition + jz next_entry /* - * Now scan the table of bootable ids, which starts at %di and has + * Scan the table of bootable ids, which starts at %di and has * length TLEN. On a match, %di points to the element following the * match; the corresponding offset to the description is $(TLEN-1) * bytes ahead. If we don't find a match, we hit the 'unknown' entry. */ + movw $bootable_ids,%di # Lookup tables movb $(TLEN),%cl # Number of entries repne # Locate scasb # type @@ -500,19 +497,10 @@ check_selection: * the string at %si * putx: print the option in %dl followed by the string at %di * also record the drive as valid. - * puts: print the string at %si followed by a crlf * putn: print a crlf * putstr: print the string at %si * putchr: print the char in al */ -putkey: -#ifndef SIO - movb $'F',%al # Display - callw putchr # 'F' -#endif - movb $'1',%al # Prepare - addb %dl,%al # digit - jmp putstr.1 # Display the rest /* * Display the option and record the drive as valid in the options. @@ -523,17 +511,24 @@ putx: btsw %dx,_MNUOPT(%bp) # Enable m movw $item,%si # Display callw putkey # key movw %di,%si # Display the rest - -puts: callw putstr # Display string + callw putstr # Display string putn: movw $crlf,%si # To next line + jmp putstr +putkey: +#ifndef SIO + movb $'F',%al # Display + callw putchr # 'F' +#endif + movb $'1',%al # Prepare + addb %dl,%al # digit + +putstr.1: callw putchr # Display char putstr: lodsb # Get byte testb $0x80,%al # End of string? - jnz putstr.2 # Yes -putstr.1: callw putchr # Display char - jmp putstr # Continue -putstr.2: andb $~0x80,%al # Clear MSB + jz putstr.1 # No + andb $~0x80,%al # Clear MSB then print last putchr: #ifndef SIO @@ -601,38 +596,45 @@ crlf: .ascii "\r"; .byte '\n'|0x80 /* Partition type tables */ -non_bootable_ids: - /* - * These entries identify invalid or NON BOOT types and partitions. - * 0: empty, 5: DOS3 ext. partition, 0xf: WIN95 ext partition - */ - .byte 0x0, 0x5, 0xf bootable_ids: /* - * These values indicate bootable types we know the names of. - * 1: FAT12, 4: FAT16 <32M, 6: FAT16 > 32M, 7: NTFS - * 0xb: FAT32, 0xc: FAT32-LBA, 0xe: FAT16-LBA, - * 0x83: linux, 0xa5: FreeBSD, 0xa6: netbsd, 0xa9:openbsd - */ - .byte 0x1, 0x6, 0x7, 0xb, 0xc, 0xe, 0x83 - .byte 0xa5, 0xa6, 0xa9, 0x4 + * These values indicate bootable types we know about. + * Corresponding descriptions are at desc_ofs: + * Entries don't need to be sorted. + */ + .byte 0x1, 0x6, 0x7, 0xb, 0xc +#ifndef SAVE_MEMORY + .byte 0xe +#endif + .byte 0x83, 0xa5, 0xa6, 0xa9, 0x4 +#ifndef SAVE_MORE_MEMORY + .byte 0x5, 0xf +#endif + desc_ofs: /* * Offsets that match the known types above, used to point to the * actual partition name. The last entry must point to os_misc, * which is used for non-matching names. */ - .byte os_dos-. # 1, DOS - .byte os_dos-. # 6, DOS/WIN - .byte os_win-. # 7, Windows - .byte os_win-. # 11, Windows - .byte os_win-. # 12, Windows - .byte os_win-. # 14, Windows + .byte os_dos-. # 1, FAT12 DOS + .byte os_dos-. # 6, FAT16 <32M, DOS/WIN + .byte os_win-. # 7, FAT16 >=32M Windows + .byte os_win-. # 11, FAT32 + .byte os_win-. # 12, FAT32-LBA +#ifndef SAVE_MEMORY + .byte os_win-. # 14, FAT16-LBA +#endif .byte os_linux-. # 131, Linux .byte os_freebsd-. # 165, FreeBSD .byte os_bsd-. # 166, OpenBSD .byte os_bsd-. # 169, NetBSD - .byte os_dos-. # 4, DOS + .byte os_dos-. # 4, FAT16 < 32M +#ifndef SAVE_MORE_MEMORY + .byte os_ext-. # 5, DOS Ext + .byte os_ext-. # 15, DOS Ext-LBA +#endif + .byte os_misc-. # Unknown /* @@ -641,15 +643,18 @@ desc_ofs: */ os_misc: .byte '?'|0x80 os_dos: -#if !defined(TEST) /* DOS string only if room */ +#ifndef SAVE_MEMORY /* DOS string only if room */ .ascii "DO"; .byte 'S'|0x80 #endif os_win: .ascii "WI"; .byte 'N'|0x80 os_linux: .ascii "Linu"; .byte 'x'|0x80 os_freebsd: .ascii "Free" os_bsd: .ascii "BS"; .byte 'D'|0x80 +#ifndef SAVE_MORE_MEMORY +os_ext: .ascii "EX"; .byte 'T'|0x80 +#endif - .org B0_OFF,0x90 + .org (0x200 + B0_OFF),0x90 /* * The boot0 version 1.0 parameter table. * Do not move it nor change the "Drive " string, boot0cfg @@ -663,6 +668,9 @@ nxtdrv: .byte 0x0 # Next drive number opt: .byte 0x0 # Option setdrv_num: .byte 0x80 # Drive to force flags: .byte FLAGS # Flags +#ifdef VOLUME_SERIAL + .byte 0xa8,0xa8,0xa8,0xa8 # Volume Serial Number +#endif ticks: .word TICKS # Delay .org PRT_OFF Modified: head/usr.sbin/boot0cfg/boot0cfg.8 ============================================================================== --- head/usr.sbin/boot0cfg/boot0cfg.8 Wed Dec 3 11:48:20 2008 (r185578) +++ head/usr.sbin/boot0cfg/boot0cfg.8 Wed Dec 3 14:53:59 2008 (r185579) @@ -35,7 +35,9 @@ .Op Fl Bv .Op Fl b Ar boot0 .Op Fl d Ar drive +.Op Fl e Ar bell character .Op Fl f Ar file +.Op Fl i Ar volume-id .Op Fl m Ar mask .Op Fl o Ar options .Op Fl s Ar slice @@ -96,10 +98,17 @@ which contains the specified Typically this will be 0x80 for the first hard drive, 0x81 for the second hard drive, and so on; however any integer between 0 and 0xff is acceptable here. +.It Fl e Ar bell character +Set the character to be printed in case of input error. .It Fl f Ar file Specify that a backup copy of the preexisting MBR should be written to .Ar file . This file is created if it does not exist, and replaced if it does. +.It Fl i Ar volume-id +Specifies a volume-id (in the form XXXX-XXXX) to be saved at location +0x1b8 in the MBR. This information is sometimes used by NT, XP and Vista +to identify the disk drive. The option is only compatible with version 2.00 +of the 512-byte boot block. .It Fl m Ar mask Specify slices to be enabled/disabled, where .Ar mask Modified: head/usr.sbin/boot0cfg/boot0cfg.c ============================================================================== --- head/usr.sbin/boot0cfg/boot0cfg.c Wed Dec 3 11:48:20 2008 (r185578) +++ head/usr.sbin/boot0cfg/boot0cfg.c Wed Dec 3 14:53:59 2008 (r185579) @@ -1,4 +1,5 @@ /* + * Copyright (c) 2008 Luigi Rizzo * Copyright (c) 1999 Robert Nordier * All rights reserved. * @@ -44,13 +45,34 @@ __FBSDID("$FreeBSD$"); #define MBRSIZE 512 /* master boot record size */ -#define OFF_VERSION 0x1b0 /* offset: version number */ -#define OFF_OPT 0x1b9 /* offset: default boot option */ -#define OFF_DRIVE 0x1ba /* offset: setdrv drive */ -#define OFF_FLAGS 0x1bb /* offset: option flags */ -#define OFF_TICKS 0x1bc /* offset: clock ticks */ +#define OFF_VERSION 0x1b0 /* offset: version number, only boot0version */ +#define OFF_SERIAL 0x1b8 /* offset: volume serial number */ #define OFF_PTBL 0x1be /* offset: partition table */ #define OFF_MAGIC 0x1fe /* offset: magic number */ +/* + * Offsets to the parameters of the 512-byte boot block. + * For historical reasons they are set as macros + */ +struct opt_offsets { + int opt; + int drive; + int flags; + int ticks; +}; + +struct opt_offsets b0_ofs[] = { + { 0x0, 0x0, 0x0, 0x0 }, /* no boot block */ + { 0x1b9, 0x1ba, 0x1bb, 0x1bc }, /* original block */ + { 0x1b5, 0x1b6, 0x1b7, 0x1bc }, /* NT_SERIAL block */ +}; + +int b0_ver; /* boot block version set by boot0bs */ + +#define OFF_OPT (b0_ofs[b0_ver].opt) /* default boot option */ +#define OFF_DRIVE (b0_ofs[b0_ver].drive) /* setdrv drive */ +#define OFF_FLAGS (b0_ofs[b0_ver].flags) /* option flags */ +#define OFF_TICKS (b0_ofs[b0_ver].ticks) /* clock ticks */ + #define cv2(p) ((p)[0] | (p)[1] << 010) @@ -81,8 +103,12 @@ static int boot0version(const u_int8_t * static int boot0bs(const u_int8_t *); static void stropt(const char *, int *, int *); static int argtoi(const char *, int, int, int); +static int set_bell(u_int8_t *, int, int); static void usage(void); +unsigned vol_id[5]; /* 4 plus 1 for flag */ + +int v_flag; /* * Boot manager installation/configuration utility. */ @@ -93,9 +119,9 @@ main(int argc, char *argv[]) int boot0_size, mbr_size; const char *bpath, *fpath; char *disk; - int B_flag, v_flag, o_flag; + int B_flag, o_flag; int d_arg, m_arg, s_arg, t_arg; - int o_and, o_or; + int o_and, o_or, o_e = -1; int up, c; bpath = "/boot/boot0"; @@ -104,7 +130,7 @@ main(int argc, char *argv[]) d_arg = m_arg = s_arg = t_arg = -1; o_and = 0xff; o_or = 0; - while ((c = getopt(argc, argv, "Bvb:d:f:m:o:s:t:")) != -1) + while ((c = getopt(argc, argv, "Bvb:d:e:f:i:m:o:s:t:")) != -1) switch (c) { case 'B': B_flag = 1; @@ -118,9 +144,22 @@ main(int argc, char *argv[]) case 'd': d_arg = argtoi(optarg, 0, 0xff, 'd'); break; + case 'e': + if (optarg[0] == '0' && optarg[1] == 'x') + sscanf(optarg, "0x%02x", &o_e); + else + o_e = optarg[0]; + break; case 'f': fpath = optarg; break; + case 'i': + if (sscanf(optarg, "%02x%02x-%02x%02x", + vol_id, vol_id+1, vol_id+2, vol_id+3) == 4) + vol_id[4] = 1; + else + errx(1, "bad argument %s", optarg); + break; case 'm': m_arg = argtoi(optarg, 0, 0xf, 'm'); break; @@ -147,7 +186,10 @@ main(int argc, char *argv[]) up = B_flag || d_arg != -1 || m_arg != -1 || o_flag || s_arg != -1 || t_arg != -1; - /* open the disk and read in the existing mbr */ + /* open the disk and read in the existing mbr. Either here or + * when reading the block from disk, we do check for the version + * and abort if a suitable block is not found. + */ mbr_size = read_mbr(disk, &mbr, !B_flag); /* save the existing MBR if we are asked to do so */ @@ -164,6 +206,8 @@ main(int argc, char *argv[]) boot0_size = read_mbr(bpath, &boot0, 1); memcpy(boot0 + OFF_PTBL, mbr + OFF_PTBL, sizeof(struct dos_partition) * NDOSPART); + if (b0_ver == 2) /* volume serial number support */ + memcpy(boot0 + OFF_SERIAL, mbr + OFF_SERIAL, 4); } else { boot0 = mbr; boot0_size = mbr_size; @@ -191,6 +235,19 @@ main(int argc, char *argv[]) if (t_arg != -1) mk2(boot0 + OFF_TICKS, t_arg); + /* set the bell char */ + if (o_e != -1 && set_bell(boot0, o_e, 0) != -1) + up = 1; + + if (vol_id[4]) { + if (b0_ver != 2) + errx(1, "incompatible boot block, cannot set volume ID"); + boot0[OFF_SERIAL] = vol_id[0]; + boot0[OFF_SERIAL+1] = vol_id[1]; + boot0[OFF_SERIAL+2] = vol_id[2]; + boot0[OFF_SERIAL+3] = vol_id[3]; + up = 1; /* force update */ + } /* write the MBR back to disk */ if (up) write_mbr(disk, 0, boot0, boot0_size); @@ -208,6 +265,36 @@ main(int argc, char *argv[]) return 0; } +/* get or set the 'bell' character to be used in case of errors. + * Lookup for a certain code sequence, return -1 if not found. + */ +static int +set_bell(u_int8_t *mbr, int new_bell, int report) +{ + /* lookup sequence: 0x100 means skip, 0x200 means done */ + static unsigned seq[] = + { 0xb0, 0x100, 0xe8, 0x100, 0x100, 0x30, 0xe4, 0x200 }; + int ofs, i, c; + for (ofs = 0x60; ofs < 0x180; ofs++) { /* search range */ + if (mbr[ofs] != seq[0]) /* search initial pattern */ + continue; + for (i=0;; i++) { + if (seq[i] == 0x200) { /* found */ + c = mbr[ofs+1]; + if (!report) + mbr[ofs+1] = c = new_bell; + else + printf(" bell=%c (0x%x)", + (c >= ' ' && c < 0x7f) ? c : ' ', c); + return c; + } + if (seq[i] != 0x100 && seq[i] != mbr[ofs+i]) + break; + } + } + warn("bell not found"); + return -1; +} /* * Read in the MBR of the disk. If it is boot0, then use the version to * read in all of it if necessary. Use pointers to return a malloc'd @@ -218,6 +305,7 @@ read_mbr(const char *disk, u_int8_t **mb { u_int8_t buf[MBRSIZE]; int mbr_size, fd; + int ver; ssize_t n; if ((fd = open(disk, O_RDONLY)) == -1) @@ -229,7 +317,7 @@ read_mbr(const char *disk, u_int8_t **mb if (cv2(buf + OFF_MAGIC) != 0xaa55) errx(1, "%s: bad magic", disk); - if (!boot0bs(buf)) { + if (! (ver = boot0bs(buf))) { if (check_version) errx(1, "%s: unknown or incompatible boot code", disk); } else if (boot0version(buf) == 0x101) { @@ -338,9 +426,11 @@ display_mbr(u_int8_t *mbr) part[i].dp_size); printf("\n"); version = boot0version(mbr); - printf("version=%d.%d drive=0x%x mask=0x%x ticks=%u\noptions=", + printf("version=%d.%d drive=0x%x mask=0x%x ticks=%u", version >> 8, version & 0xff, mbr[OFF_DRIVE], mbr[OFF_FLAGS] & 0xf, cv2(mbr + OFF_TICKS)); + set_bell(mbr, 0, 1); + printf("\noptions="); for (i = 0; i < nopt; i++) { if (i) printf(","); @@ -349,6 +439,10 @@ display_mbr(u_int8_t *mbr) printf("%s", opttbl[i].tok); } printf("\n"); + if (b0_ver == 2) + printf("volume serial ID %02x%02x-%02x%02x\n", + mbr[OFF_SERIAL], mbr[OFF_SERIAL+1], + mbr[OFF_SERIAL+2], mbr[OFF_SERIAL+3]); printf("default_selection=F%d (", mbr[OFF_OPT] + 1); if (mbr[OFF_OPT] < 4) printf("Slice %d", mbr[OFF_OPT] + 1); @@ -364,16 +458,27 @@ display_mbr(u_int8_t *mbr) static int boot0version(const u_int8_t *bs) { - static u_int8_t idold[] = {0xfe, 0x45, 0xf2, 0xe9, 0x00, 0x8a}; - /* Check for old version, and return 0x100 if found. */ - if (memcmp(bs + 0x1c, idold, sizeof(idold)) == 0) - return 0x100; + int v = boot0bs(bs); + if (v != 0) + return v << 8; /* We have a newer boot0, so extract the version number and return it. */ return *(const int *)(bs + OFF_VERSION) & 0xffff; } +/* descriptor of a pattern to match. + * Start from the first entry trying to match the chunk of bytes, + * if you hit an entry with len=0 terminate the search and report + * off as the version. Otherwise skip to the next block after len=0 + * An entry with len=0, off=0 is the end marker. + */ +struct byte_pattern { + unsigned off; + unsigned len; + u_int8_t *key; +}; + /* * Decide if we have valid boot0 boot code by looking for * characteristic byte sequences at fixed offsets. @@ -381,23 +486,32 @@ boot0version(const u_int8_t *bs) static int boot0bs(const u_int8_t *bs) { + /* the initial code sequence */ static u_int8_t id0[] = {0xfc, 0x31, 0xc0, 0x8e, 0xc0, 0x8e, 0xd8, 0x8e, 0xd0, 0xbc, 0x00, 0x7c }; + /* the drive id */ static u_int8_t id1[] = {'D', 'r', 'i', 'v', 'e', ' '}; - static struct { - unsigned off; - unsigned len; - u_int8_t *key; - } ident[2] = { + static struct byte_pattern patterns[] = { {0x0, sizeof(id0), id0}, - {0x1b2, sizeof(id1), id1} + {0x1b2, sizeof(id1), id1}, + {1, 0, NULL}, + {0x0, sizeof(id0), id0}, /* version with NT support */ + {0x1ae, sizeof(id1), id1}, + {2, 0, NULL}, + {0, 0, NULL}, }; - unsigned int i; + struct byte_pattern *p = patterns; - for (i = 0; i < sizeof(ident) / sizeof(ident[0]); i++) - if (memcmp(bs + ident[i].off, ident[i].key, ident[i].len)) - return 0; - return 1; + for (; p->off || p->len; p++) { + if (p->len == 0) + break; + if (!memcmp(bs + p->off, p->key, p->len)) /* match */ + continue; + while (p->len) /* skip to next block */ + p++; + } + b0_ver = p->off; /* XXX ugly side effect */ + return p->off; } /* From jkoshy at FreeBSD.org Wed Dec 3 07:23:09 2008 From: jkoshy at FreeBSD.org (Joseph Koshy) Date: Wed Dec 3 07:23:15 2008 Subject: svn commit: r185582 - head/sys/dev/hwpmc Message-ID: <200812031523.mB3FN8w5094396@svn.freebsd.org> Author: jkoshy Date: Wed Dec 3 15:23:08 2008 New Revision: 185582 URL: http://svn.freebsd.org/changeset/base/185582 Log: Add aliases that map architectural event names to fixed function counters. Modified: head/sys/dev/hwpmc/pmc_events.h Modified: head/sys/dev/hwpmc/pmc_events.h ============================================================================== --- head/sys/dev/hwpmc/pmc_events.h Wed Dec 3 15:10:31 2008 (r185581) +++ head/sys/dev/hwpmc/pmc_events.h Wed Dec 3 15:23:08 2008 (r185582) @@ -426,6 +426,11 @@ __PMC_EV(IAF, CPU_CLK_UNHALTED_REF) #define PMC_EV_IAF_FIRST PMC_EV_IAF_INSTR_RETIRED_ANY #define PMC_EV_IAF_LAST PMC_EV_IAF_CPU_CLK_UNHALTED_REF +#define __PMC_EV_ALIAS_IAF() \ +__PMC_EV_ALIAS("instruction-retired", IAF_INSTR_RETIRED_ANY) \ +__PMC_EV_ALIAS("unhalted-core-cycles", IAF_CPU_CLK_UNHALTED_CORE) \ +__PMC_EV_ALIAS("unhalted-reference-cycles", IAF_CPU_CLK_UNHALTED_REF) + /* * Events supported by programmable function counters present in * Intel Atom, Core and Core2 CPUs, from the "Intel 64 and IA-32 From bz at FreeBSD.org Wed Dec 3 07:54:36 2008 From: bz at FreeBSD.org (Bjoern A. Zeeb) Date: Wed Dec 3 07:54:53 2008 Subject: svn commit: r185583 - head/sys/kern Message-ID: <200812031554.mB3Fsa7A095029@svn.freebsd.org> Author: bz Date: Wed Dec 3 15:54:35 2008 New Revision: 185583 URL: http://svn.freebsd.org/changeset/base/185583 Log: Fix a credential reference leak. [1] Close subtle but relatively unlikely race conditions when propagating the vnode write error to other active sessions tracing to the same vnode, without holding a reference on the vnode anymore. [2] PR: kern/126368 [1] Submitted by: rwatson [2] Reviewed by: kib, rwatson MFC after: 4 weeks Modified: head/sys/kern/kern_ktrace.c Modified: head/sys/kern/kern_ktrace.c ============================================================================== --- head/sys/kern/kern_ktrace.c Wed Dec 3 15:23:08 2008 (r185582) +++ head/sys/kern/kern_ktrace.c Wed Dec 3 15:54:35 2008 (r185583) @@ -907,12 +907,7 @@ ktr_writerequest(struct thread *td, stru */ mtx_lock(&ktrace_mtx); vp = td->td_proc->p_tracevp; - if (vp != NULL) - VREF(vp); cred = td->td_proc->p_tracecred; - if (cred != NULL) - crhold(cred); - mtx_unlock(&ktrace_mtx); /* * If vp is NULL, the vp has been cleared out from under this @@ -921,9 +916,13 @@ ktr_writerequest(struct thread *td, stru */ if (vp == NULL) { KASSERT(cred == NULL, ("ktr_writerequest: cred != NULL")); + mtx_unlock(&ktrace_mtx); return; } + VREF(vp); KASSERT(cred != NULL, ("ktr_writerequest: cred == NULL")); + crhold(cred); + mtx_unlock(&ktrace_mtx); kth = &req->ktr_header; datalen = data_lengths[(u_short)kth->ktr_type & ~KTR_DROP]; @@ -963,18 +962,26 @@ ktr_writerequest(struct thread *td, stru error = VOP_WRITE(vp, &auio, IO_UNIT | IO_APPEND, cred); VOP_UNLOCK(vp, 0); vn_finished_write(mp); - vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); - if (!error) + crfree(cred); + if (!error) { + vrele(vp); + VFS_UNLOCK_GIANT(vfslocked); return; + } + VFS_UNLOCK_GIANT(vfslocked); + /* * If error encountered, give up tracing on this vnode. We defer * all the vrele()'s on the vnode until after we are finished walking * the various lists to avoid needlessly holding locks. + * NB: at this point we still hold the vnode reference that must + * not go away as we need the valid vnode to compare with. Thus let + * vrele_count start at 1 and the reference will be freed + * by the loop at the end after our last use of vp. */ log(LOG_NOTICE, "ktrace write failed, errno %d, tracing stopped\n", error); - vrele_count = 0; + vrele_count = 1; /* * First, clear this vnode from being used by any processes in the * system. From ambrisko at FreeBSD.org Wed Dec 3 08:29:12 2008 From: ambrisko at FreeBSD.org (Doug Ambrisko) Date: Wed Dec 3 08:29:19 2008 Subject: svn commit: r185584 - head/sys/dev/mfi Message-ID: <200812031629.mB3GTCLU095801@svn.freebsd.org> Author: ambrisko Date: Wed Dec 3 16:29:12 2008 New Revision: 185584 URL: http://svn.freebsd.org/changeset/base/185584 Log: Change new card identification names. Submitted by: LSI MFC after: 3 days Modified: head/sys/dev/mfi/mfi_pci.c Modified: head/sys/dev/mfi/mfi_pci.c ============================================================================== --- head/sys/dev/mfi/mfi_pci.c Wed Dec 3 15:54:35 2008 (r185583) +++ head/sys/dev/mfi/mfi_pci.c Wed Dec 3 16:29:12 2008 (r185584) @@ -119,10 +119,10 @@ struct mfi_ident { {0x1028, 0x0015, 0xffff, 0xffff, MFI_FLAGS_1064R, "Dell PERC 5/i"}, {0x1000, 0x0060, 0x1028, 0xffff, MFI_FLAGS_1078, "Dell PERC 6"}, {0x1000, 0x0060, 0xffff, 0xffff, MFI_FLAGS_1078, "LSI MegaSAS 1078"}, - {0x1000, 0x0079, 0x1028, 0x1f15, MFI_FLAGS_GEN2, "Dell PERC 607E Adapter"}, - {0x1000, 0x0079, 0x1028, 0x1f16, MFI_FLAGS_GEN2, "Dell PERC 607I Adapter"}, - {0x1000, 0x0079, 0x1028, 0x1f17, MFI_FLAGS_GEN2, "Dell PERC 607I Integrated"}, - {0x1000, 0x0079, 0x1028, 0x1f18, MFI_FLAGS_GEN2, "Dell PERC 607I Modular"}, + {0x1000, 0x0079, 0x1028, 0x1f15, MFI_FLAGS_GEN2, "Dell PERC H800 Adapter"}, + {0x1000, 0x0079, 0x1028, 0x1f16, MFI_FLAGS_GEN2, "Dell PERC H700 Adapter"}, + {0x1000, 0x0079, 0x1028, 0x1f17, MFI_FLAGS_GEN2, "Dell PERC H700 Integrated"}, + {0x1000, 0x0079, 0x1028, 0x1f18, MFI_FLAGS_GEN2, "Dell PERC H700 Modular"}, {0x1000, 0x0078, 0xffff, 0xffff, MFI_FLAGS_GEN2, "LSI MegaSAS Gen2"}, {0x1000, 0x0079, 0xffff, 0xffff, MFI_FLAGS_GEN2, "LSI MegaSAS Gen2"}, {0x1000, 0x007c, 0xffff, 0xffff, MFI_FLAGS_1078, "LSI MegaSAS 1078"}, From jkoshy at FreeBSD.org Wed Dec 3 09:30:36 2008 From: jkoshy at FreeBSD.org (Joseph Koshy) Date: Wed Dec 3 09:30:48 2008 Subject: svn commit: r185585 - in head: lib/libpmc sys/dev/hwpmc Message-ID: <200812031730.mB3HUabM096968@svn.freebsd.org> Author: jkoshy Date: Wed Dec 3 17:30:36 2008 New Revision: 185585 URL: http://svn.freebsd.org/changeset/base/185585 Log: Fixes for Core2 Extreme support. Submitted by: "Artem Belevich" Modified: head/lib/libpmc/libpmc.c head/sys/dev/hwpmc/hwpmc_core.c head/sys/dev/hwpmc/hwpmc_intel.c Modified: head/lib/libpmc/libpmc.c ============================================================================== --- head/lib/libpmc/libpmc.c Wed Dec 3 16:29:12 2008 (r185584) +++ head/lib/libpmc/libpmc.c Wed Dec 3 17:30:36 2008 (r185585) @@ -603,7 +603,8 @@ iap_allocate_pmc(enum pmc_event pe, char if (n != 1) return (-1); } else if (cpu_info.pm_cputype == PMC_CPU_INTEL_ATOM || - cpu_info.pm_cputype == PMC_CPU_INTEL_CORE2) { + cpu_info.pm_cputype == PMC_CPU_INTEL_CORE2 || + cpu_info.pm_cputype == PMC_CPU_INTEL_CORE2EXTREME) { if (KWMATCH(p, IAP_KW_SNOOPRESPONSE)) { n = pmc_parse_mask(iap_snoopresponse_mask, p, &evmask); @@ -2273,6 +2274,7 @@ pmc_event_names_of_class(enum pmc_class count = PMC_EVENT_TABLE_SIZE(core); break; case PMC_CPU_INTEL_CORE2: + case PMC_CPU_INTEL_CORE2EXTREME: ev = core2_event_table; count = PMC_EVENT_TABLE_SIZE(core2); break; @@ -2455,6 +2457,7 @@ pmc_init(void) pmc_class_table[n] = &core_class_table_descr; break; case PMC_CPU_INTEL_CORE2: + case PMC_CPU_INTEL_CORE2EXTREME: PMC_MDEP_INIT(core2); pmc_class_table[n++] = &iaf_class_table_descr; pmc_class_table[n] = &core2_class_table_descr; @@ -2553,6 +2556,7 @@ _pmc_name_of_event(enum pmc_event pe, en evfence = core_event_table + PMC_EVENT_TABLE_SIZE(core); break; case PMC_CPU_INTEL_CORE2: + case PMC_CPU_INTEL_CORE2EXTREME: ev = core2_event_table; evfence = core2_event_table + PMC_EVENT_TABLE_SIZE(core2); break; Modified: head/sys/dev/hwpmc/hwpmc_core.c ============================================================================== --- head/sys/dev/hwpmc/hwpmc_core.c Wed Dec 3 16:29:12 2008 (r185584) +++ head/sys/dev/hwpmc/hwpmc_core.c Wed Dec 3 17:30:36 2008 (r185585) @@ -527,8 +527,8 @@ struct iap_event_descr { }; #define IAP_F_CC (1 << 0) /* CPU: Core */ -#define IAP_F_CC2 (1 << 1) /* CPU: Core2 */ -#define IAP_F_CC2E (1 << 2) /* CPU: Core2 Extreme */ +#define IAP_F_CC2 (1 << 1) /* CPU: Core2 family */ +#define IAP_F_CC2E (1 << 2) /* CPU: Core2 Extreme only */ #define IAP_F_CA (1 << 3) /* CPU: Atom */ #define IAP_F_FM (1 << 4) /* Fixed mask */ @@ -1111,7 +1111,7 @@ iap_allocate_pmc(int cpu, int ri, struct cpuflag = IAP_F_CC2; break; case PMC_CPU_INTEL_CORE2EXTREME: - cpuflag = IAP_F_CC2E; + cpuflag = IAP_F_CC2 | IAP_F_CC2E; break; } Modified: head/sys/dev/hwpmc/hwpmc_intel.c ============================================================================== --- head/sys/dev/hwpmc/hwpmc_intel.c Wed Dec 3 16:29:12 2008 (r185584) +++ head/sys/dev/hwpmc/hwpmc_intel.c Wed Dec 3 17:30:36 2008 (r185585) @@ -168,6 +168,7 @@ pmc_intel_initialize(void) case PMC_CPU_INTEL_ATOM: case PMC_CPU_INTEL_CORE: case PMC_CPU_INTEL_CORE2: + case PMC_CPU_INTEL_CORE2EXTREME: error = pmc_core_initialize(pmc_mdep, ncpus); break; @@ -238,6 +239,7 @@ pmc_intel_finalize(struct pmc_mdep *md) case PMC_CPU_INTEL_ATOM: case PMC_CPU_INTEL_CORE: case PMC_CPU_INTEL_CORE2: + case PMC_CPU_INTEL_CORE2EXTREME: pmc_core_finalize(md); break; From kan at FreeBSD.org Wed Dec 3 09:54:10 2008 From: kan at FreeBSD.org (Alexander Kabaev) Date: Wed Dec 3 09:54:16 2008 Subject: svn commit: r185586 - head/sys/nfsserver Message-ID: <200812031754.mB3Hs9kU097435@svn.freebsd.org> Author: kan Date: Wed Dec 3 17:54:09 2008 New Revision: 185586 URL: http://svn.freebsd.org/changeset/base/185586 Log: Change nfsserver slightly so that it does not trip over the timestamp validation code on ZFS. Problem: when opening file with O_CREAT|O_EXCL NFS has to jump through extra hoops to ensure O_EXCL semantics. Namely, client supplies of 8 bytes (NFSX_V3CREATEVERF) bytes of verification data to uniquely identify this create request. Server then creates a new file with access mode 0, copies received 8 bytes into va_atime member of struct vattr and attempt to set the atime on file using VOP_SETATTR. If that succeeds, it fetches file attributes with VOP_GETATTR and verifies that atime timestamps match. If timestamps do not match, NFS server concludes it has probbaly lost the race to another process creating the file with the same name and bails with EEXIST. This scheme works OK when exported FS is FFS, but if underlying filesystem is ZFS _and_ server is running 64bit kernel, it breaks down due to sanity checking in zfs_setattr function, which refuses to accept any timestamps which have tv_sec that cannot be represented as 32bit int. Since struct timespec fields are 64 bit integers on 64bit platforms and server just copies NFSX_V3CREATEVERF bytes info va_atime, all eight bytes supplied by client end up in va_atime.tv_sec, forcing it out of valid 32bit range. The solution this change implements is simple: it treats NFSX_V3CREATEVERF as two 32bit integers and unpacks them separately into va_atime.tv_sec and va_atime.tv_nsec respectively, thus guaranteeing that tv_sec remains in 32 bit range and ZFS remains happy. Reviewed by: kib Modified: head/sys/nfsserver/nfs_serv.c Modified: head/sys/nfsserver/nfs_serv.c ============================================================================== --- head/sys/nfsserver/nfs_serv.c Wed Dec 3 17:30:36 2008 (r185585) +++ head/sys/nfsserver/nfs_serv.c Wed Dec 3 17:54:09 2008 (r185586) @@ -1669,13 +1669,12 @@ nfsrv_create(struct nfsrv_descript *nfsd caddr_t bpos; int error = 0, rdev, len, tsize, dirfor_ret = 1, diraft_ret = 1; int v3 = (nfsd->nd_flag & ND_NFSV3), how, exclusive_flag = 0; - caddr_t cp; struct mbuf *mb, *mreq; struct vnode *dirp = NULL; nfsfh_t nfh; fhandle_t *fhp; u_quad_t tempsize; - u_char cverf[NFSX_V3CREATEVERF]; + struct timespec cverf; struct mount *mp = NULL; int tvfslocked; int vfslocked; @@ -1754,8 +1753,11 @@ nfsrv_create(struct nfsrv_descript *nfsd nfsm_srvsattr(vap); break; case NFSV3CREATE_EXCLUSIVE: - cp = nfsm_dissect_nonblock(caddr_t, NFSX_V3CREATEVERF); - bcopy(cp, cverf, NFSX_V3CREATEVERF); + tl = nfsm_dissect_nonblock(u_int32_t *, + NFSX_V3CREATEVERF); + /* Unique bytes, endianness is not important. */ + cverf.tv_sec = tl[0]; + cverf.tv_nsec = tl[1]; exclusive_flag = 1; break; }; @@ -1801,8 +1803,7 @@ nfsrv_create(struct nfsrv_descript *nfsd if (exclusive_flag) { exclusive_flag = 0; VATTR_NULL(vap); - bcopy(cverf, (caddr_t)&vap->va_atime, - NFSX_V3CREATEVERF); + vap->va_atime = cverf; error = VOP_SETATTR(nd.ni_vp, vap, cred); } @@ -1886,7 +1887,7 @@ nfsrv_create(struct nfsrv_descript *nfsd } if (v3) { if (exclusive_flag && !error && - bcmp(cverf, (caddr_t)&vap->va_atime, NFSX_V3CREATEVERF)) + bcmp(&cverf, &vap->va_atime, sizeof (cverf))) error = EEXIST; if (dirp == nd.ni_dvp) diraft_ret = VOP_GETATTR(dirp, &diraft, cred); From luigi at FreeBSD.org Wed Dec 3 10:22:37 2008 From: luigi at FreeBSD.org (Luigi Rizzo) Date: Wed Dec 3 10:22:43 2008 Subject: svn commit: r185587 - head/sbin/newfs_msdos Message-ID: <200812031822.mB3IMaFb098030@svn.freebsd.org> Author: luigi Date: Wed Dec 3 18:22:36 2008 New Revision: 185587 URL: http://svn.freebsd.org/changeset/base/185587 Log: Some useful operational extensions to newfs_msdos, especially when preparing images for emulators or flash devices: + option '-C size' to create the underlying image file with given size. Saves doing a 'dd' before, and especially it creates a sparse file + option '-@ offset' to build the FAT image at the specified offset in the image file or device; + make the cluster size adaptive on the filesystem size. Previously the default was 4k which is really unconvenient with large media; now it goes from 512 bytes to 32k depending on filesystem size (i still need to check whether it makes sense to go further up, to 64k or above); + fix default geometry when not specified on the command line, use 63 sectors/255 heads by default. Also trim the size so it exactly a multiple of a track, to avoid complaints in some filesystem code. + document all the above, plus some manual page clarifications. MFC after: 4 weeks Modified: head/sbin/newfs_msdos/newfs_msdos.8 head/sbin/newfs_msdos/newfs_msdos.c Modified: head/sbin/newfs_msdos/newfs_msdos.8 ============================================================================== --- head/sbin/newfs_msdos/newfs_msdos.8 Wed Dec 3 17:54:09 2008 (r185586) +++ head/sbin/newfs_msdos/newfs_msdos.8 Wed Dec 3 18:22:36 2008 (r185587) @@ -34,7 +34,9 @@ .Sh SYNOPSIS .Nm .Op Fl N +.Op Fl @ Ar offset .Op Fl B Ar boot +.Op Fl C Ar create-size .Op Fl F Ar FAT-type .Op Fl I Ar volid .Op Fl L Ar label @@ -59,7 +61,7 @@ .Sh DESCRIPTION The .Nm -utility creates a FAT12, FAT16, or FAT32 file system on device +utility creates a FAT12, FAT16, or FAT32 file system on device or file named .Ar special , using .Xr disktab 5 @@ -67,16 +69,39 @@ entry .Ar disktype to determine geometry, if required. .Pp +If +.Ar special +does not contain a +.Ar / , +it is assumed to be a device name and +.Ar /dev +is prepended to the name to construct the actual device name. +To work a file in the current directory use +.Ar ./filename +.Pp The options are as follow: .Bl -tag -width indent .It Fl N Do not create a file system: just print out parameters. +.It Fl @ Ar offset +Build the filesystem at the specified offset in bytes in the device or file. +A suffix s, k, m, g (lower or upper case) +appended to the offset specifies that the +number is in sectors, kilobytes, megabytes or gigabytes, respectively. .It Fl B Ar boot Get bootstrap from file. +.It Fl C Ar create-size +Create the image file with the specified size. A suffix character appended +to the size is interpreted as for the +.Fl @ +option. The file is created by truncating any existing file with the +same name, seeking just before the required size and writing +a single 0 byte. As a consequence, the space occupied on disk +may be smaller than the size specified as a parameter. .It Fl F Ar FAT-type FAT type (one of 12, 16, or 32). .It Fl I Ar volid -Volume ID. +Volume ID, a 32 bit number in decimal or hexadecimal (0x...) format. .It Fl L Ar label Volume label (up to 11 characters). The label should consist of @@ -99,6 +124,9 @@ acceptable number of sectors per cluster Sectors per cluster. Acceptable values are powers of 2 in the range 1 through 128. +If the block or cluster size are not specified, the code +uses a cluster between 512 bytes and 32K depending on +the filesystem size. .It Fl e Ar dirents Number of root directory entries (FAT12 and FAT16 only). .It Fl f Ar format @@ -132,6 +160,15 @@ File system size. Number of sectors per track. .El .Sh NOTES +If some parameters (e.g. size, number of sectors, etc.) are not specified +through options or disktype, the program tries to generate them +automatically. In particular, the size is determined as the +device or file size minus the offset specified with the +.Fl @ +option. When the geometry is not available, it is assumed to be +63 sectors, 255 heads. The size is then rounded to become +a multiple of the track size and avoid complaints by some filesystem code. +.Pp FAT file system parameters occupy a "Boot Sector BPB (BIOS Parameter Block)" in the first of the "reserved" sectors which precede the actual file system. @@ -167,20 +204,25 @@ The maximum file size is 4GB, even if th .Sh EXIT STATUS Exit status is 0 on success and 1 on error. .Sh EXAMPLES +Create a file system, using default parameters, on +.Pa /dev/ad0s1 : .Bd -literal -offset indent newfs_msdos /dev/ad0s1 .Ed .Pp -Create a file system, using default parameters, on -.Pa /dev/ad0s1 . +Create a standard 1.44M file system, with volume label +.Ar foo , +on +.Pa /dev/fd0 : .Bd -literal -offset indent newfs_msdos -f 1440 -L foo fd0 .Ed .Pp -Create a standard 1.44M file system, with volume label -.Ar foo , -on -.Pa /dev/fd0 . +Create a 30MB image file, with the FAT partition starting +63 sectors within the image file: +.Bd -literal -offset indent +newfs_msdos -C 30M -@63s ./somefile +.Ed .Sh SEE ALSO .Xr disktab 5 , .Xr disklabel 8 , Modified: head/sbin/newfs_msdos/newfs_msdos.c ============================================================================== --- head/sbin/newfs_msdos/newfs_msdos.c Wed Dec 3 17:54:09 2008 (r185586) +++ head/sbin/newfs_msdos/newfs_msdos.c Wed Dec 3 18:22:36 2008 (r185587) @@ -219,6 +219,7 @@ static void getdiskinfo(int, const char static void print_bpb(struct bpb *); static u_int ckgeom(const char *, u_int, const char *); static u_int argtou(const char *, u_int, u_int, const char *); +static off_t argtooff(const char *, const char *); static int oklabel(const char *); static void mklabel(u_int8_t *, const char *); static void setstr(u_int8_t *, const char *, size_t); @@ -230,7 +231,7 @@ static void usage(void); int main(int argc, char *argv[]) { - static char opts[] = "NB:F:I:L:O:S:a:b:c:e:f:h:i:k:m:n:o:r:s:u:"; + static char opts[] = "@:NB:C:F:I:L:O:S:a:b:c:e:f:h:i:k:m:n:o:r:s:u:"; static const char *opt_B, *opt_L, *opt_O, *opt_f; static u_int opt_F, opt_I, opt_S, opt_a, opt_b, opt_c, opt_e; static u_int opt_h, opt_i, opt_k, opt_m, opt_n, opt_o, opt_r; @@ -253,15 +254,22 @@ main(int argc, char *argv[]) time_t now; u_int fat, bss, rds, cls, dir, lsn, x, x1, x2; int ch, fd, fd1; + static off_t opt_create=0, opt_ofs=0; while ((ch = getopt(argc, argv, opts)) != -1) switch (ch) { + case '@': + opt_ofs = argtooff(optarg, "offset"); + break; case 'N': opt_N = 1; break; case 'B': opt_B = optarg; break; + case 'C': + opt_create = argtooff(optarg, "create size"); + break; case 'F': if (strcmp(optarg, "12") && strcmp(optarg, "16") && @@ -346,13 +354,27 @@ main(int argc, char *argv[]) err(1, NULL); } dtype = *argv; - if ((fd = open(fname, opt_N ? O_RDONLY : O_RDWR)) == -1 || + if (opt_create) { + off_t pos; + + if (opt_N) + errx(1, "create (-C) is incompatible with -N"); + fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0644); + if (fd == -1) + errx(1, "failed to create %s", fname); + pos = lseek(fd, opt_create - 1, SEEK_SET); + if (write(fd, "\0", 1) != 1) + errx(1, "failed to initialize %lld bytes", opt_create); + pos = lseek(fd, 0, SEEK_SET); + } else if ((fd = open(fname, opt_N ? O_RDONLY : O_RDWR)) == -1 || fstat(fd, &sb)) err(1, "%s", fname); if (!opt_N) check_mounted(fname, sb.st_mode); if (!S_ISCHR(sb.st_mode)) - warnx("warning: %s is not a character device", fname); + warnx("warning, %s is not a character device", fname); + if (opt_ofs && opt_ofs != lseek(fd, opt_ofs, SEEK_SET)) + errx(1, "cannot seek to %lld", opt_ofs); memset(&bpb, 0, sizeof(bpb)); if (opt_f) { getstdfmt(opt_f, &bpb); @@ -371,8 +393,29 @@ main(int argc, char *argv[]) bpb.bsec = opt_s; if (oflag) bpb.hid = opt_o; - if (!(opt_f || (opt_h && opt_u && opt_S && opt_s && oflag))) + if (!(opt_f || (opt_h && opt_u && opt_S && opt_s && oflag))) { + off_t delta; getdiskinfo(fd, fname, dtype, oflag, &bpb); + bpb.bsec -= (opt_ofs / bpb.bps); + delta = bpb.bsec % bpb.spt; + if (delta != 0) { + warnx("trim %d sectors to adjust to a multiple of %d", + (int)delta, bpb.spt); + bpb.bsec -= delta; + } + if (bpb.spc == 0) { /* set defaults */ + if (bpb.bsec <= 6000) /* about 3MB -> 512 bytes */ + bpb.spc = 1; + else if (bpb.bsec <= (1<<17)) /* 64M -> 4k */ + bpb.spc = 8; + else if (bpb.bsec <= (1<<19)) /* 256M -> 8k */ + bpb.spc = 16; + else if (bpb.bsec <= (1<<21)) /* 1G -> 16k */ + bpb.spc = 32; + else + bpb.spc = 64; /* otherwise 32k */ + } + } if (!powerof2(bpb.bps)) errx(1, "bytes/sector (%u) is not a power of 2", bpb.bps); if (bpb.bps < MINBPS) @@ -561,7 +604,7 @@ main(int argc, char *argv[]) fat == 32 && bpb.bkbs != MAXU16 && bss <= bpb.bkbs && x >= bpb.bkbs) { x -= bpb.bkbs; - if (!x && lseek(fd1, 0, SEEK_SET)) + if (!x && lseek(fd1, opt_ofs, SEEK_SET)) err(1, "%s", bname); } if (opt_B && x < bss) { @@ -728,14 +771,13 @@ getdiskinfo(int fd, const char *fname, c if (ioctl(fd, DIOCGMEDIASIZE, &ms) == -1) { struct stat st; - bzero(&st, sizeof(st)); if (fstat(fd, &st)) err(1, "Cannot get disk size"); /* create a fake geometry for a file image */ ms = st.st_size; dlp.d_secsize = 512; - dlp.d_nsectors = 64; - dlp.d_ntracks = 32; + dlp.d_nsectors = 63; + dlp.d_ntracks = 255; dlp.d_secperunit = ms / dlp.d_secsize; lp = &dlp; } else if (ioctl(fd, FD_GTYPE, &type) != -1) { @@ -833,6 +875,56 @@ argtou(const char *arg, u_int lo, u_int } /* + * Same for off_t, with optional skmgpP suffix + */ +static off_t +argtooff(const char *arg, const char *msg) +{ + char *s; + off_t x; + + x = strtoll(arg, &s, 0); + /* allow at most one extra char */ + if (errno || x < 0 || (s[0] && s[1]) ) + errx(1, "%s: bad %s", arg, msg); + if (*s) { /* the extra char is the multiplier */ + switch (*s) { + default: + errx(1, "%s: bad %s", arg, msg); + /* notreached */ + + case 's': /* sector */ + case 'S': + x <<= 9; /* times 512 */ + break; + + case 'k': /* kilobyte */ + case 'K': + x <<= 10; /* times 1024 */ + break; + + case 'm': /* megabyte */ + case 'M': + x <<= 20; /* times 1024*1024 */ + break; + + case 'g': /* gigabyte */ + case 'G': + x <<= 30; /* times 1024*1024*1024 */ + break; + + case 'p': /* partition start */ + case 'P': /* partition start */ + case 'l': /* partition length */ + case 'L': /* partition length */ + errx(1, "%s: not supported yet %s", arg, msg); + /* notreached */ + } + } + return x; +} + +/* * Check a volume label. */ static int From luigi at FreeBSD.org Wed Dec 3 10:37:00 2008 From: luigi at FreeBSD.org (Luigi Rizzo) Date: Wed Dec 3 10:37:06 2008 Subject: svn commit: r185588 - head/sbin/newfs Message-ID: <200812031837.mB3Ib0pb098329@svn.freebsd.org> Author: luigi Date: Wed Dec 3 18:36:59 2008 New Revision: 185588 URL: http://svn.freebsd.org/changeset/base/185588 Log: Enable operation of newfs on plain files, which is useful when you want to prepare disk images for emulators (though 'makefs' in port can do something similar). This relies on: + minor changes to pass the consistency checks even when working on a file; + an additional option, '-p partition' , to specify the disk partition to initialize; + some changes on the I/O routines to deal with partition offsets. The latter was a bit tricky to implement, see the details in newfs.h: in newfs, I/O is done through libufs which assumes that the file descriptor refers to the whole partition. Introducing support for the offset in libufs would require a non-backward compatible change in the library, to be dealt with a version bump or with symbol versioning. I felt both approaches to be overkill for this specific application, especially because there might be other changes to libufs that might become necessary in the near future. So I used the following trick: - read access is always done by calling bread() directly, so we just add the offset in the (few) places that call bread(); - write access is done through bwrite() and sbwrite(), which in turn calls bwrite(). To avoid rewriting sbwrite(), we supply our own version of bwrite() here, which takes precedence over the version in libufs. MFC after: 4 weeks Modified: head/sbin/newfs/Makefile head/sbin/newfs/mkfs.c head/sbin/newfs/newfs.8 head/sbin/newfs/newfs.c head/sbin/newfs/newfs.h Modified: head/sbin/newfs/Makefile ============================================================================== --- head/sbin/newfs/Makefile Wed Dec 3 18:22:36 2008 (r185587) +++ head/sbin/newfs/Makefile Wed Dec 3 18:36:59 2008 (r185588) @@ -1,10 +1,13 @@ # @(#)Makefile 8.2 (Berkeley) 3/27/94 # $FreeBSD$ +.PATH: ${.CURDIR}/../../sys/geom + PROG= newfs DPADD= ${LIBUFS} LDADD= -lufs -SRCS= newfs.c mkfs.c +SRCS= newfs.c mkfs.c geom_bsd_enc.c + WARNS?= 2 MAN= newfs.8 Modified: head/sbin/newfs/mkfs.c ============================================================================== --- head/sbin/newfs/mkfs.c Wed Dec 3 18:22:36 2008 (r185587) +++ head/sbin/newfs/mkfs.c Wed Dec 3 18:36:59 2008 (r185588) @@ -459,7 +459,7 @@ mkfs(struct partition *pp, char *fsys) * Wipe out old UFS1 superblock(s) if necessary. */ if (!Nflag && Oflag != 1) { - i = bread(&disk, SBLOCK_UFS1 / disk.d_bsize, chdummy, SBLOCKSIZE); + i = bread(&disk, part_ofs + SBLOCK_UFS1 / disk.d_bsize, chdummy, SBLOCKSIZE); if (i == -1) err(1, "can't read old UFS1 superblock: %s", disk.d_error); @@ -872,7 +872,7 @@ alloc(int size, int mode) { int i, d, blkno, frag; - bread(&disk, fsbtodb(&sblock, cgtod(&sblock, 0)), (char *)&acg, + bread(&disk, part_ofs + fsbtodb(&sblock, cgtod(&sblock, 0)), (char *)&acg, sblock.fs_cgsize); if (acg.cg_magic != CG_MAGIC) { printf("cg 0: bad magic number\n"); @@ -925,7 +925,7 @@ iput(union dinode *ip, ino_t ino) int c; c = ino_to_cg(&sblock, ino); - bread(&disk, fsbtodb(&sblock, cgtod(&sblock, 0)), (char *)&acg, + bread(&disk, part_ofs + fsbtodb(&sblock, cgtod(&sblock, 0)), (char *)&acg, sblock.fs_cgsize); if (acg.cg_magic != CG_MAGIC) { printf("cg 0: bad magic number\n"); @@ -942,7 +942,7 @@ iput(union dinode *ip, ino_t ino) exit(32); } d = fsbtodb(&sblock, ino_to_fsba(&sblock, ino)); - bread(&disk, d, (char *)iobuf, sblock.fs_bsize); + bread(&disk, part_ofs + d, (char *)iobuf, sblock.fs_bsize); if (sblock.fs_magic == FS_UFS1_MAGIC) ((struct ufs1_dinode *)iobuf)[ino_to_fsbo(&sblock, ino)] = ip->dp1; Modified: head/sbin/newfs/newfs.8 ============================================================================== --- head/sbin/newfs/newfs.8 Wed Dec 3 18:22:36 2008 (r185587) +++ head/sbin/newfs/newfs.8 Wed Dec 3 18:36:59 2008 (r185588) @@ -52,6 +52,7 @@ .Op Fl i Ar bytes .Op Fl m Ar free-space .Op Fl o Ar optimization +.Op Fl p Ar partition .Op Fl r Ar reserved .Op Fl s Ar size .Ar special @@ -201,6 +202,17 @@ the default is to optimize for See .Xr tunefs 8 for more details on how to set this option. +.It Fl p Ar partition +The partition name (a..h) you want to use in case the underlying image +is a file, so you don't have access to individual partitions through the +filesystem. +Can also be used with a device, e.g. +.Nm +.Fl p Ar f +.Ar /dev/da1s3 +is equivalent to +.Nm +.Ar /dev/da1s3f . .It Fl r Ar reserved The size, in sectors, of reserved space at the end of the partition specified in Modified: head/sbin/newfs/newfs.c ============================================================================== --- head/sbin/newfs/newfs.c Wed Dec 3 18:22:36 2008 (r185587) +++ head/sbin/newfs/newfs.c Wed Dec 3 18:36:59 2008 (r185588) @@ -139,6 +139,9 @@ u_char *volumelabel = NULL; /* volume la struct uufsd disk; /* libufs disk structure */ static char device[MAXPATHLEN]; +static u_char bootarea[BBSIZE]; +static int is_file; /* work on a file, not a device */ +static char *dkname; static char *disktype; static int unlabeled; @@ -147,6 +150,18 @@ static struct disklabel *getdisklabel(ch static void rewritelabel(char *s, struct disklabel *lp); static void usage(void); +ufs2_daddr_t part_ofs; /* partition offset in blocks, used with files */ + +/* + * need to replace the library's bwrite so that sbwrite uses this one + */ +ssize_t +bwrite(struct uufsd *disk, ufs2_daddr_t blockno, const void *data, size_t size) +{ + return pwrite(disk->d_fd, data, size, + (off_t)((part_ofs + blockno) * disk->d_bsize)); +} + int main(int argc, char *argv[]) { @@ -158,7 +173,9 @@ main(int argc, char *argv[]) intmax_t reserved; int ch, i; off_t mediasize; + char part_name; /* partition name, default to full disk */ + part_name = 'c'; reserved = 0; while ((ch = getopt(argc, argv, "EJL:NO:RS:T:UXa:b:c:d:e:f:g:h:i:lm:no:r:s:")) != -1) @@ -276,6 +293,11 @@ main(int argc, char *argv[]) *cp != '\0' || reserved < 0) errx(1, "%s: bad reserved size", optarg); break; + case 'p': + is_file = 1; + part_name = optarg[0]; + break; + case 's': errno = 0; fssize = strtoimax(optarg, &cp, 0); @@ -294,6 +316,8 @@ main(int argc, char *argv[]) usage(); special = argv[0]; + if (!special[0]) + err(1, "empty file/special name"); cp = strrchr(special, '/'); if (cp == 0) { /* @@ -303,7 +327,16 @@ main(int argc, char *argv[]) special = device; } - if (ufs_disk_fillout_blank(&disk, special) == -1 || + if (is_file) { + /* bypass ufs_disk_fillout_blank */ + bzero( &disk, sizeof(disk)); + disk.d_bsize = 1; + disk.d_name = special; + disk.d_fd = open(special, O_RDONLY); + if (disk.d_fd < 0 || + (!Nflag && ufs_disk_write(&disk) == -1)) + errx(1, "%s: ", special); + } else if (ufs_disk_fillout_blank(&disk, special) == -1 || (!Nflag && ufs_disk_write(&disk) == -1)) { if (disk.d_error != NULL) errx(1, "%s: %s", special, disk.d_error); @@ -312,22 +345,30 @@ main(int argc, char *argv[]) } if (fstat(disk.d_fd, &st) < 0) err(1, "%s", special); - if ((st.st_mode & S_IFMT) != S_IFCHR) - errx(1, "%s: not a character-special device", special); + if ((st.st_mode & S_IFMT) != S_IFCHR) { + warn("%s: not a character-special device", special); + is_file = 1; /* assume it is a file */ + dkname = special; + if (sectorsize == 0) + sectorsize = 512; + mediasize = st.st_size; + /* set fssize from the partition */ + } else { + part_name = special[strlen(special) - 1]; + if ((part_name < 'a' || part_name > 'h') && !isdigit(part_name)) + errx(1, "%s: can't figure out file system partition", + special); - if (sectorsize == 0) + if (sectorsize == 0) if (ioctl(disk.d_fd, DIOCGSECTORSIZE, §orsize) == -1) - sectorsize = 0; /* back out on error for safety */ - if (sectorsize && ioctl(disk.d_fd, DIOCGMEDIASIZE, &mediasize) != -1) + sectorsize = 0; /* back out on error for safety */ + if (sectorsize && ioctl(disk.d_fd, DIOCGMEDIASIZE, &mediasize) != -1) getfssize(&fssize, special, mediasize / sectorsize, reserved); + } pp = NULL; lp = getdisklabel(special); if (lp != NULL) { - cp = strchr(special, '\0'); - cp--; - if ((*cp < 'a' || *cp > 'h') && !isdigit(*cp)) - errx(1, "%s: can't figure out file system partition", - special); + cp = &part_name; if (isdigit(*cp)) pp = &lp->d_partitions[RAW_PART]; else @@ -346,6 +387,8 @@ main(int argc, char *argv[]) fsize = pp->p_fsize; if (bsize == 0) bsize = pp->p_frag * pp->p_fsize; + if (is_file) + part_ofs = pp->p_offset; } if (sectorsize <= 0) errx(1, "%s: no default sector size", special); @@ -414,6 +457,19 @@ getdisklabel(char *s) static struct disklabel lab; struct disklabel *lp; + if (is_file) { + if (read(disk.d_fd, bootarea, BBSIZE) != BBSIZE) + err(4, "cannot read bootarea"); + if (bsd_disklabel_le_dec( + bootarea + (0 /* labeloffset */ + + 1 /* labelsoffset */ * sectorsize), + &lab, MAXPARTITIONS)) + errx(1, "no valid label found"); + + lp = &lab; + return &lab; + } + if (ioctl(disk.d_fd, DIOCGDINFO, (char *)&lab) != -1) return (&lab); unlabeled++; @@ -432,6 +488,14 @@ rewritelabel(char *s, struct disklabel * return; lp->d_checksum = 0; lp->d_checksum = dkcksum(lp); + if (is_file) { + bsd_disklabel_le_enc(bootarea + 0 /* labeloffset */ + + 1 /* labelsoffset */ * sectorsize, lp); + lseek(disk.d_fd, 0, SEEK_SET); + if (write(disk.d_fd, bootarea, BBSIZE) != BBSIZE) + errx(1, "cannot write label"); + return; + } if (ioctl(disk.d_fd, DIOCWDINFO, (char *)lp) == -1) warn("ioctl (WDINFO): %s: can't rewrite disk label", s); } @@ -467,6 +531,7 @@ usage() fprintf(stderr, "\t-n do not create .snap directory\n"); fprintf(stderr, "\t-m minimum free space %%\n"); fprintf(stderr, "\t-o optimization preference (`space' or `time')\n"); + fprintf(stderr, "\t-p partition name (a..h)\n"); fprintf(stderr, "\t-r reserved sectors at the end of device\n"); fprintf(stderr, "\t-s file system size (sectors)\n"); exit(1); Modified: head/sbin/newfs/newfs.h ============================================================================== --- head/sbin/newfs/newfs.h Wed Dec 3 18:22:36 2008 (r185587) +++ head/sbin/newfs/newfs.h Wed Dec 3 18:36:59 2008 (r185588) @@ -70,4 +70,20 @@ extern int avgfilesperdir; /* expected n extern u_char *volumelabel; /* volume label for filesystem */ extern struct uufsd disk; /* libufs disk structure */ +/* + * To override a limitation in libufs, export the offset (in sectors) of the + * partition on the underlying media (file or disk). The value is used as + * an offset for all accesses to the media through bread(), which is only + * invoked directly in this program. + * For bwrite() we need a different approach, namely override the library + * version with one defined here. This is because bwrite() is called also + * by the library function sbwrite() which we cannot intercept nor want to + * rewrite. As a consequence, the internal version of bwrite() adds the + * partition offset itself when calling the underlying function, pwrite(). + * + * XXX This info really ought to go into the struct uufsd, at which point + * we can remove the above hack. + */ +extern ufs2_daddr_t part_ofs; /* partition offset in blocks */ + void mkfs (struct partition *, char *); From jhb at FreeBSD.org Wed Dec 3 10:45:39 2008 From: jhb at FreeBSD.org (John Baldwin) Date: Wed Dec 3 10:45:44 2008 Subject: svn commit: r185589 - head/sys/compat/freebsd32 Message-ID: <200812031845.mB3IjcZC098534@svn.freebsd.org> Author: jhb Date: Wed Dec 3 18:45:38 2008 New Revision: 185589 URL: http://svn.freebsd.org/changeset/base/185589 Log: When unloading a 32-bit system call module, restore the sysent vector in the 32-bit system call table instead of the main system call table. Modified: head/sys/compat/freebsd32/freebsd32_misc.c Modified: head/sys/compat/freebsd32/freebsd32_misc.c ============================================================================== --- head/sys/compat/freebsd32/freebsd32_misc.c Wed Dec 3 18:36:59 2008 (r185588) +++ head/sys/compat/freebsd32/freebsd32_misc.c Wed Dec 3 18:45:38 2008 (r185589) @@ -2774,7 +2774,7 @@ syscall32_module_handler(struct module * if (error) return (error); } - error = syscall_deregister(data->offset, &data->old_sysent); + error = syscall32_deregister(data->offset, &data->old_sysent); return (error); default: error = EOPNOTSUPP; From peterjeremy at optushome.com.au Wed Dec 3 11:17:56 2008 From: peterjeremy at optushome.com.au (Peter Jeremy) Date: Wed Dec 3 11:18:07 2008 Subject: svn commit: r185562 - head/sys/boot/i386/boot0 In-Reply-To: <200812021457.mB2Evmha063418@svn.freebsd.org> References: <200812021457.mB2Evmha063418@svn.freebsd.org> Message-ID: <20081203191752.GA58682@server.vk2pj.dyndns.org> On 2008-Dec-02 14:57:48 +0000, Luigi Rizzo wrote: >Log: > This commits brings in a lot of documentation and some enhancement > of the boot0.S code, with a number of compile-time selectable options, > the most interesting one being the ability to select PXE booting. Excellent. One typo I noticed: >+ * %si pointer to the partition table from which we were loaded. >+ * Some boot code (e.g. syslinux) use this info to relocate >+ * themselves, so we want to pass a valid one to the next stage. >+ * NOTE: the use of %is is not a standard. ^^^ should be %si. -- Peter Jeremy Please excuse any delays as the result of my ISP's inability to implement an MTA that is either RFC2821-compliant or matches their claimed behaviour. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 195 bytes Desc: not available Url : http://lists.freebsd.org/pipermail/svn-src-head/attachments/20081203/f84a9ac4/attachment.pgp From kostikbel at gmail.com Wed Dec 3 13:43:11 2008 From: kostikbel at gmail.com (Kostik Belousov) Date: Wed Dec 3 13:43:17 2008 Subject: svn commit: r185589 - head/sys/compat/freebsd32 In-Reply-To: <200812031845.mB3IjcZC098534@svn.freebsd.org> References: <200812031845.mB3IjcZC098534@svn.freebsd.org> Message-ID: <20081203214306.GC2401@deviant.kiev.zoral.com.ua> On Wed, Dec 03, 2008 at 06:45:38PM +0000, John Baldwin wrote: > Author: jhb > Date: Wed Dec 3 18:45:38 2008 > New Revision: 185589 > URL: http://svn.freebsd.org/changeset/base/185589 > > Log: > When unloading a 32-bit system call module, restore the sysent vector in > the 32-bit system call table instead of the main system call table. > > Modified: > head/sys/compat/freebsd32/freebsd32_misc.c > The module build glue is not committed into the svn, isn't it ? -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 195 bytes Desc: not available Url : http://lists.freebsd.org/pipermail/svn-src-head/attachments/20081203/4be221d0/attachment.pgp From delphij at FreeBSD.org Wed Dec 3 15:00:14 2008 From: delphij at FreeBSD.org (Xin LI) Date: Wed Dec 3 15:00:19 2008 Subject: svn commit: r185593 - head/sys/dev/bce Message-ID: <200812032300.mB3N0023003902@svn.freebsd.org> Author: delphij Date: Wed Dec 3 23:00:00 2008 New Revision: 185593 URL: http://svn.freebsd.org/changeset/base/185593 Log: Don't attempt to clear status updates if we did not do a link state change. As a side effect, this makes the excessive interrupts to disappear which has been observed as a regression in recent stable/7. Reported by: many (on -stable@) Reviewed by: davidch Modified: head/sys/dev/bce/if_bce.c Modified: head/sys/dev/bce/if_bce.c ============================================================================== --- head/sys/dev/bce/if_bce.c Wed Dec 3 22:47:33 2008 (r185592) +++ head/sys/dev/bce/if_bce.c Wed Dec 3 23:00:00 2008 (r185593) @@ -7030,13 +7030,14 @@ bce_intr(void *xsc) /* Was it a link change interrupt? */ if ((status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) != - (sc->status_block->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE)) + (sc->status_block->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE)) { bce_phy_intr(sc); - /* Clear any transient status updates during link state change. */ - REG_WR(sc, BCE_HC_COMMAND, - sc->hc_command | BCE_HC_COMMAND_COAL_NOW_WO_INT); - REG_RD(sc, BCE_HC_COMMAND); + /* Clear any transient status updates during link state change. */ + REG_WR(sc, BCE_HC_COMMAND, + sc->hc_command | BCE_HC_COMMAND_COAL_NOW_WO_INT); + REG_RD(sc, BCE_HC_COMMAND); + } /* If any other attention is asserted then the chip is toast. */ if (((status_attn_bits & ~STATUS_ATTN_BITS_LINK_STATE) != From mlaier at FreeBSD.org Wed Dec 3 15:00:58 2008 From: mlaier at FreeBSD.org (Max Laier) Date: Wed Dec 3 15:01:04 2008 Subject: svn commit: r185594 - head/sbin/newfs_msdos Message-ID: <200812032300.mB3N0vZW003970@svn.freebsd.org> Author: mlaier Date: Wed Dec 3 23:00:57 2008 New Revision: 185594 URL: http://svn.freebsd.org/changeset/base/185594 Log: Fix build - cast off_t to (intmax_t) for printing. Modified: head/sbin/newfs_msdos/newfs_msdos.c Modified: head/sbin/newfs_msdos/newfs_msdos.c ============================================================================== --- head/sbin/newfs_msdos/newfs_msdos.c Wed Dec 3 23:00:00 2008 (r185593) +++ head/sbin/newfs_msdos/newfs_msdos.c Wed Dec 3 23:00:57 2008 (r185594) @@ -42,6 +42,7 @@ static const char rcsid[] = #include #include #include +#include #include #include #include @@ -364,7 +365,7 @@ main(int argc, char *argv[]) errx(1, "failed to create %s", fname); pos = lseek(fd, opt_create - 1, SEEK_SET); if (write(fd, "\0", 1) != 1) - errx(1, "failed to initialize %lld bytes", opt_create); + errx(1, "failed to initialize %jd bytes", (intmax_t)opt_create); pos = lseek(fd, 0, SEEK_SET); } else if ((fd = open(fname, opt_N ? O_RDONLY : O_RDWR)) == -1 || fstat(fd, &sb)) @@ -374,7 +375,7 @@ main(int argc, char *argv[]) if (!S_ISCHR(sb.st_mode)) warnx("warning, %s is not a character device", fname); if (opt_ofs && opt_ofs != lseek(fd, opt_ofs, SEEK_SET)) - errx(1, "cannot seek to %lld", opt_ofs); + errx(1, "cannot seek to %jd", (intmax_t)opt_ofs); memset(&bpb, 0, sizeof(bpb)); if (opt_f) { getstdfmt(opt_f, &bpb); From max at love2party.net Wed Dec 3 15:09:33 2008 From: max at love2party.net (Max Laier) Date: Wed Dec 3 15:09:44 2008 Subject: svn commit: r185594 - head/sbin/newfs_msdos In-Reply-To: <200812032300.mB3N0vZW003970@svn.freebsd.org> References: <200812032300.mB3N0vZW003970@svn.freebsd.org> Message-ID: <200812040009.30837.max@love2party.net> On Thursday 04 December 2008 00:00:57 Max Laier wrote: > Author: mlaier > Date: Wed Dec 3 23:00:57 2008 > New Revision: 185594 > URL: http://svn.freebsd.org/changeset/base/185594 > > Log: > Fix build - cast off_t to (intmax_t) for printing. I'd really like to typedef the int64 types "long long" on all architectures :-\ It's a big POLA violation in my opinion and causes quite a bit of porting headache. Or at least let's fix printf to understand that "long" types on 64bit architectures can be printed with %ll. Since they are - in fact - 64bit wide. But I keep reiterating this point - I guess I still don't understand the exact reason why we can't just do that. -- /"\ Best regards, | mlaier@freebsd.org \ / Max Laier | ICQ #67774661 X http://pf4freebsd.love2party.net/ | mlaier@EFnet / \ ASCII Ribbon Campaign | Against HTML Mail and News From jhb at freebsd.org Wed Dec 3 15:20:55 2008 From: jhb at freebsd.org (John Baldwin) Date: Wed Dec 3 15:21:07 2008 Subject: svn commit: r185589 - head/sys/compat/freebsd32 In-Reply-To: <20081203214306.GC2401@deviant.kiev.zoral.com.ua> References: <200812031845.mB3IjcZC098534@svn.freebsd.org> <20081203214306.GC2401@deviant.kiev.zoral.com.ua> Message-ID: <200812031803.03650.jhb@freebsd.org> On Wednesday 03 December 2008 04:43:06 pm Kostik Belousov wrote: > On Wed, Dec 03, 2008 at 06:45:38PM +0000, John Baldwin wrote: > > Author: jhb > > Date: Wed Dec 3 18:45:38 2008 > > New Revision: 185589 > > URL: http://svn.freebsd.org/changeset/base/185589 > > > > Log: > > When unloading a 32-bit system call module, restore the sysent vector in > > the 32-bit system call table instead of the main system call table. > > > > Modified: > > head/sys/compat/freebsd32/freebsd32_misc.c > > > The module build glue is not committed into the svn, isn't it ? Err, it is. It's in freebsd32_util.h (SYSCALL32_MODULE, etc.). -- John Baldwin From yongari at FreeBSD.org Wed Dec 3 17:58:40 2008 From: yongari at FreeBSD.org (Pyun YongHyeon) Date: Wed Dec 3 17:58:53 2008 Subject: svn commit: r185596 - head/sys/dev/jme Message-ID: <200812040158.mB41wexs007260@svn.freebsd.org> Author: yongari Date: Thu Dec 4 01:58:40 2008 New Revision: 185596 URL: http://svn.freebsd.org/changeset/base/185596 Log: Add support for newer JMC250/JMC260 revisions. o Chip full mask revision 2 or later controllers have to set correct Tx MAC and Tx offload clock depending on negotiated link speed. o JMC260 chip full mask revision 2 has a silicon bug that can't handle 64bit DMA addressing. Add workaround to the bug by limiting DMA address space to be within 32bit. o Valid FIFO space of receive control and status register was changed on chip full mask revision 2 or later controllers. For these controllers, use default 16QW as it's supposed to be the safest value for maximum PCIe compatibility. JMicron confirmed performance will not be reduced even if the FIFO space is set to 16QW. o When interface is put into suspend/shutdown state, remove Tx MAC and Tx offload clock to save more power. We don't need Tx clock at all in this state. o Added new register definition for chip full mask revision 2 or later controllers. Thanks to JMicron for their continuous support of FreeBSD. Modified: head/sys/dev/jme/if_jme.c head/sys/dev/jme/if_jmereg.h head/sys/dev/jme/if_jmevar.h Modified: head/sys/dev/jme/if_jme.c ============================================================================== --- head/sys/dev/jme/if_jme.c Thu Dec 4 01:24:21 2008 (r185595) +++ head/sys/dev/jme/if_jme.c Thu Dec 4 01:58:40 2008 (r185596) @@ -651,6 +651,13 @@ jme_attach(device_t dev) goto fail; } + if (CHIPMODE_REVFM(sc->jme_chip_rev) >= 2) { + if ((sc->jme_rev & DEVICEID_JMC2XX_MASK) == DEVICEID_JMC260 && + CHIPMODE_REVFM(sc->jme_chip_rev) == 2) + sc->jme_flags |= JME_FLAG_DMA32BIT; + sc->jme_flags |= JME_FLAG_TXCLK; + } + /* Reset the ethernet controller. */ jme_reset(sc); @@ -1007,6 +1014,8 @@ jme_dma_alloc(struct jme_softc *sc) int error, i; lowaddr = BUS_SPACE_MAXADDR; + if ((sc->jme_flags & JME_FLAG_DMA32BIT) != 0) + lowaddr = BUS_SPACE_MAXADDR_32BIT; again: /* Create parent ring tag. */ @@ -1106,25 +1115,32 @@ again: } sc->jme_rdata.jme_rx_ring_paddr = ctx.jme_busaddr; - /* Tx/Rx descriptor queue should reside within 4GB boundary. */ - tx_ring_end = sc->jme_rdata.jme_tx_ring_paddr + JME_TX_RING_SIZE; - rx_ring_end = sc->jme_rdata.jme_rx_ring_paddr + JME_RX_RING_SIZE; - if ((JME_ADDR_HI(tx_ring_end) != - JME_ADDR_HI(sc->jme_rdata.jme_tx_ring_paddr)) || - (JME_ADDR_HI(rx_ring_end) != - JME_ADDR_HI(sc->jme_rdata.jme_rx_ring_paddr))) { - device_printf(sc->jme_dev, "4GB boundary crossed, " - "switching to 32bit DMA address mode.\n"); - jme_dma_free(sc); - /* Limit DMA address space to 32bit and try again. */ - lowaddr = BUS_SPACE_MAXADDR_32BIT; - goto again; + if (lowaddr != BUS_SPACE_MAXADDR_32BIT) { + /* Tx/Rx descriptor queue should reside within 4GB boundary. */ + tx_ring_end = sc->jme_rdata.jme_tx_ring_paddr + + JME_TX_RING_SIZE; + rx_ring_end = sc->jme_rdata.jme_rx_ring_paddr + + JME_RX_RING_SIZE; + if ((JME_ADDR_HI(tx_ring_end) != + JME_ADDR_HI(sc->jme_rdata.jme_tx_ring_paddr)) || + (JME_ADDR_HI(rx_ring_end) != + JME_ADDR_HI(sc->jme_rdata.jme_rx_ring_paddr))) { + device_printf(sc->jme_dev, "4GB boundary crossed, " + "switching to 32bit DMA address mode.\n"); + jme_dma_free(sc); + /* Limit DMA address space to 32bit and try again. */ + lowaddr = BUS_SPACE_MAXADDR_32BIT; + goto again; + } } + lowaddr = BUS_SPACE_MAXADDR; + if ((sc->jme_flags & JME_FLAG_DMA32BIT) != 0) + lowaddr = BUS_SPACE_MAXADDR_32BIT; /* Create parent buffer tag. */ error = bus_dma_tag_create(bus_get_dma_tag(sc->jme_dev),/* parent */ 1, 0, /* algnmnt, boundary */ - BUS_SPACE_MAXADDR, /* lowaddr */ + lowaddr, /* lowaddr */ BUS_SPACE_MAXADDR, /* highaddr */ NULL, NULL, /* filter, filterarg */ BUS_SPACE_MAXSIZE_32BIT, /* maxsize */ @@ -1445,6 +1461,11 @@ jme_setwol(struct jme_softc *sc) JME_LOCK_ASSERT(sc); if (pci_find_extcap(sc->jme_dev, PCIY_PMG, &pmc) != 0) { + /* Remove Tx MAC/offload clock to save more power. */ + if ((sc->jme_flags & JME_FLAG_TXCLK) != 0) + CSR_WRITE_4(sc, JME_GHC, CSR_READ_4(sc, JME_GHC) & + ~(GHC_TX_OFFLD_CLK_100 | GHC_TX_MAC_CLK_100 | + GHC_TX_OFFLD_CLK_1000 | GHC_TX_MAC_CLK_1000)); /* No PME capability, PHY power down. */ jme_miibus_writereg(sc->jme_dev, sc->jme_phyaddr, MII_BMCR, BMCR_PDOWN); @@ -1466,7 +1487,11 @@ jme_setwol(struct jme_softc *sc) CSR_WRITE_4(sc, JME_PMCS, pmcs); CSR_WRITE_4(sc, JME_GPREG0, gpr); - + /* Remove Tx MAC/offload clock to save more power. */ + if ((sc->jme_flags & JME_FLAG_TXCLK) != 0) + CSR_WRITE_4(sc, JME_GHC, CSR_READ_4(sc, JME_GHC) & + ~(GHC_TX_OFFLD_CLK_100 | GHC_TX_MAC_CLK_100 | + GHC_TX_OFFLD_CLK_1000 | GHC_TX_MAC_CLK_1000)); /* Request PME. */ pmstat = pci_read_config(sc->jme_dev, pmc + PCIR_POWER_STATUS, 2); pmstat &= ~(PCIM_PSTAT_PME | PCIM_PSTAT_PMEENABLE); @@ -1941,6 +1966,7 @@ jme_mac_config(struct jme_softc *sc) { struct mii_data *mii; uint32_t ghc, gpreg, rxmac, txmac, txpause; + uint32_t txclk; JME_LOCK_ASSERT(sc); @@ -1950,6 +1976,7 @@ jme_mac_config(struct jme_softc *sc) DELAY(10); CSR_WRITE_4(sc, JME_GHC, 0); ghc = 0; + txclk = 0; rxmac = CSR_READ_4(sc, JME_RXMAC); rxmac &= ~RXMAC_FC_ENB; txmac = CSR_READ_4(sc, JME_TXMAC); @@ -1982,14 +2009,17 @@ jme_mac_config(struct jme_softc *sc) switch (IFM_SUBTYPE(mii->mii_media_active)) { case IFM_10_T: ghc |= GHC_SPEED_10; + txclk |= GHC_TX_OFFLD_CLK_100 | GHC_TX_MAC_CLK_100; break; case IFM_100_TX: ghc |= GHC_SPEED_100; + txclk |= GHC_TX_OFFLD_CLK_100 | GHC_TX_MAC_CLK_100; break; case IFM_1000_T: if ((sc->jme_flags & JME_FLAG_FASTETH) != 0) break; ghc |= GHC_SPEED_1000; + txclk |= GHC_TX_OFFLD_CLK_1000 | GHC_TX_MAC_CLK_1000; if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) == 0) txmac |= TXMAC_CARRIER_EXT | TXMAC_FRAME_BURST; break; @@ -2019,6 +2049,8 @@ jme_mac_config(struct jme_softc *sc) 0x1B, 0x0004); } } + if ((sc->jme_flags & JME_FLAG_TXCLK) != 0) + ghc |= txclk; CSR_WRITE_4(sc, JME_GHC, ghc); CSR_WRITE_4(sc, JME_RXMAC, rxmac); CSR_WRITE_4(sc, JME_TXMAC, txmac); @@ -2637,13 +2669,19 @@ jme_init_locked(struct jme_softc *sc) * decrease FIFO threshold to reduce the FIFO overruns for * frames larger than 4000 bytes. * For best performance of standard MTU sized frames use - * maximum allowable FIFO threshold, 128QW. + * maximum allowable FIFO threshold, 128QW. Note these do + * not hold on chip full mask verion >=2. For these + * controllers 64QW and 128QW are not valid value. */ - if ((ifp->if_mtu + ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN + - ETHER_CRC_LEN) > JME_RX_FIFO_SIZE) + if (CHIPMODE_REVFM(sc->jme_chip_rev) >= 2) sc->jme_rxcsr |= RXCSR_FIFO_THRESH_16QW; - else - sc->jme_rxcsr |= RXCSR_FIFO_THRESH_128QW; + else { + if ((ifp->if_mtu + ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN + + ETHER_CRC_LEN) > JME_RX_FIFO_SIZE) + sc->jme_rxcsr |= RXCSR_FIFO_THRESH_16QW; + else + sc->jme_rxcsr |= RXCSR_FIFO_THRESH_128QW; + } sc->jme_rxcsr |= sc->jme_rx_dma_size | RXCSR_RXQ_N_SEL(RXCSR_RXQ0); sc->jme_rxcsr |= RXCSR_DESC_RT_CNT(RXCSR_DESC_RT_CNT_DEFAULT); sc->jme_rxcsr |= RXCSR_DESC_RT_GAP_256 & RXCSR_DESC_RT_GAP_MASK; Modified: head/sys/dev/jme/if_jmereg.h ============================================================================== --- head/sys/dev/jme/if_jmereg.h Thu Dec 4 01:24:21 2008 (r185595) +++ head/sys/dev/jme/if_jmereg.h Thu Dec 4 01:58:40 2008 (r185596) @@ -239,8 +239,8 @@ #define RXCSR_FIFO_FTHRESH_MASK 0x30000000 #define RXCSR_FIFO_THRESH_16QW 0x00000000 #define RXCSR_FIFO_THRESH_32QW 0x04000000 -#define RXCSR_FIFO_THRESH_64QW 0x08000000 -#define RXCSR_FIFO_THRESH_128QW 0x0C000000 +#define RXCSR_FIFO_THRESH_64QW 0x08000000 /* JMC250/JMC260 REVFM < 2 */ +#define RXCSR_FIFO_THRESH_128QW 0x0C000000 /* JMC250/JMC260 REVFM < 2 */ #define RXCSR_FIFO_THRESH_MASK 0x0C000000 #define RXCSR_DMA_SIZE_16 0x00000000 #define RXCSR_DMA_SIZE_32 0x01000000 @@ -357,6 +357,16 @@ #define JME_GHC 0x0054 #define GHC_LOOPBACK 0x80000000 #define GHC_RESET 0x40000000 +#define GHC_RX_DMA_PWR_DIS 0x04000000 /* JMC250 REVFM >= 2 */ +#define GHC_FIFO_RD_PWR_DIS 0x02000000 /* JMC250 REVFM >= 2 */ +#define GHC_FIFO_WR_PWR_DIS 0x01000000 /* JMC250 REVFM >= 2 */ +#define GHC_TX_OFFLD_CLK_100 0x00800000 /* JMC250/JMC260 REVFM >= 2 */ +#define GHC_TX_OFFLD_CLK_1000 0x00400000 /* JMC250/JMC260 REVFM >= 2 */ +#define GHC_TX_OFFLD_CLK_DIS 0x00000000 /* JMC250/JMC260 REVFM >= 2 */ +#define GHC_TX_MAC_CLK_100 0x00200000 /* JMC250/JMC260 REVFM >= 2 */ +#define GHC_TX_MAC_CLK_1000 0x00100000 /* JMC250/JMC260 REVFM >= 2 */ +#define GHC_TX_MAC_CLK_DIS 0x00000000 /* JMC250/JMC260 REVFM >= 2 */ +#define GHC_AUTO_PHY_STAT_DIS 0x00000080 /* JMC250/JMC260 REVFM >= 2 */ #define GHC_FULL_DUPLEX 0x00000040 #define GHC_SPEED_UNKNOWN 0x00000000 #define GHC_SPEED_10 0x00000010 @@ -755,6 +765,10 @@ #define CHIPMODE_MODE_128P_MAC 0x00000003 #define CHIPMODE_MODE_128P_DBG 0x00000002 #define CHIPMODE_MODE_128P_PHY 0x00000000 +/* Chip full mask revision. */ +#define CHIPMODE_REVFM(x) ((x) & 0x0F) +/* Chip ECO revision. */ +#define CHIPMODE_REVECO(x) (((x) >> 4) & 0x0F) /* Shadow status base address high/low. */ #define JME_SHBASE_ADDR_HI 0x0848 Modified: head/sys/dev/jme/if_jmevar.h ============================================================================== --- head/sys/dev/jme/if_jmevar.h Thu Dec 4 01:24:21 2008 (r185595) +++ head/sys/dev/jme/if_jmevar.h Thu Dec 4 01:58:40 2008 (r185596) @@ -181,6 +181,8 @@ struct jme_softc { #define JME_FLAG_PMCAP 0x0020 #define JME_FLAG_FASTETH 0x0040 #define JME_FLAG_NOJUMBO 0x0080 +#define JME_FLAG_TXCLK 0x0100 +#define JME_FLAG_DMA32BIT 0x0200 #define JME_FLAG_DETACH 0x4000 #define JME_FLAG_LINK 0x8000 From yongari at FreeBSD.org Wed Dec 3 18:16:55 2008 From: yongari at FreeBSD.org (Pyun YongHyeon) Date: Wed Dec 3 18:17:07 2008 Subject: svn commit: r185597 - head/sys/dev/jme Message-ID: <200812040216.mB42Gr1S007641@svn.freebsd.org> Author: yongari Date: Thu Dec 4 02:16:53 2008 New Revision: 185597 URL: http://svn.freebsd.org/changeset/base/185597 Log: Add HW MAC counter support for newer JMC250/JMC260 revisions. Modified: head/sys/dev/jme/if_jme.c head/sys/dev/jme/if_jmereg.h head/sys/dev/jme/if_jmevar.h Modified: head/sys/dev/jme/if_jme.c ============================================================================== --- head/sys/dev/jme/if_jme.c Thu Dec 4 01:58:40 2008 (r185596) +++ head/sys/dev/jme/if_jme.c Thu Dec 4 02:16:53 2008 (r185597) @@ -150,6 +150,9 @@ static void jme_init_ssb(struct jme_soft static int jme_newbuf(struct jme_softc *, struct jme_rxdesc *); static void jme_set_vlan(struct jme_softc *); static void jme_set_filter(struct jme_softc *); +static void jme_stats_clear(struct jme_softc *); +static void jme_stats_save(struct jme_softc *); +static void jme_stats_update(struct jme_softc *); static int sysctl_int_range(SYSCTL_HANDLER_ARGS, int, int); static int sysctl_hw_jme_tx_coal_to(SYSCTL_HANDLER_ARGS); static int sysctl_hw_jme_tx_coal_pkt(SYSCTL_HANDLER_ARGS); @@ -656,6 +659,7 @@ jme_attach(device_t dev) CHIPMODE_REVFM(sc->jme_chip_rev) == 2) sc->jme_flags |= JME_FLAG_DMA32BIT; sc->jme_flags |= JME_FLAG_TXCLK; + sc->jme_flags |= JME_FLAG_HWMIB; } /* Reset the ethernet controller. */ @@ -887,35 +891,41 @@ jme_detach(device_t dev) return (0); } +#define JME_SYSCTL_STAT_ADD32(c, h, n, p, d) \ + SYSCTL_ADD_UINT(c, h, OID_AUTO, n, CTLFLAG_RD, p, 0, d) + static void jme_sysctl_node(struct jme_softc *sc) { + struct sysctl_ctx_list *ctx; + struct sysctl_oid_list *child, *parent; + struct sysctl_oid *tree; + struct jme_hw_stats *stats; int error; - SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->jme_dev), - SYSCTL_CHILDREN(device_get_sysctl_tree(sc->jme_dev)), OID_AUTO, - "tx_coal_to", CTLTYPE_INT | CTLFLAG_RW, &sc->jme_tx_coal_to, - 0, sysctl_hw_jme_tx_coal_to, "I", "jme tx coalescing timeout"); - - SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->jme_dev), - SYSCTL_CHILDREN(device_get_sysctl_tree(sc->jme_dev)), OID_AUTO, - "tx_coal_pkt", CTLTYPE_INT | CTLFLAG_RW, &sc->jme_tx_coal_pkt, - 0, sysctl_hw_jme_tx_coal_pkt, "I", "jme tx coalescing packet"); - - SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->jme_dev), - SYSCTL_CHILDREN(device_get_sysctl_tree(sc->jme_dev)), OID_AUTO, - "rx_coal_to", CTLTYPE_INT | CTLFLAG_RW, &sc->jme_rx_coal_to, - 0, sysctl_hw_jme_rx_coal_to, "I", "jme rx coalescing timeout"); - - SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->jme_dev), - SYSCTL_CHILDREN(device_get_sysctl_tree(sc->jme_dev)), OID_AUTO, - "rx_coal_pkt", CTLTYPE_INT | CTLFLAG_RW, &sc->jme_rx_coal_pkt, - 0, sysctl_hw_jme_rx_coal_pkt, "I", "jme rx coalescing packet"); - - SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->jme_dev), - SYSCTL_CHILDREN(device_get_sysctl_tree(sc->jme_dev)), OID_AUTO, - "process_limit", CTLTYPE_INT | CTLFLAG_RW, &sc->jme_process_limit, - 0, sysctl_hw_jme_proc_limit, "I", + stats = &sc->jme_stats; + ctx = device_get_sysctl_ctx(sc->jme_dev); + child = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->jme_dev)); + + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "tx_coal_to", + CTLTYPE_INT | CTLFLAG_RW, &sc->jme_tx_coal_to, 0, + sysctl_hw_jme_tx_coal_to, "I", "jme tx coalescing timeout"); + + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "tx_coal_pkt", + CTLTYPE_INT | CTLFLAG_RW, &sc->jme_tx_coal_pkt, 0, + sysctl_hw_jme_tx_coal_pkt, "I", "jme tx coalescing packet"); + + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rx_coal_to", + CTLTYPE_INT | CTLFLAG_RW, &sc->jme_rx_coal_to, 0, + sysctl_hw_jme_rx_coal_to, "I", "jme rx coalescing timeout"); + + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rx_coal_pkt", + CTLTYPE_INT | CTLFLAG_RW, &sc->jme_rx_coal_pkt, 0, + sysctl_hw_jme_rx_coal_pkt, "I", "jme rx coalescing packet"); + + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "process_limit", + CTLTYPE_INT | CTLFLAG_RW, &sc->jme_process_limit, 0, + sysctl_hw_jme_proc_limit, "I", "max number of Rx events to process"); /* Pull in device tunables. */ @@ -984,8 +994,43 @@ jme_sysctl_node(struct jme_softc *sc) sc->jme_rx_coal_pkt = PCCRX_COAL_PKT_DEFAULT; } } + + if ((sc->jme_flags & JME_FLAG_HWMIB) == 0) + return; + + tree = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "stats", CTLFLAG_RD, + NULL, "JME statistics"); + parent = SYSCTL_CHILDREN(tree); + + /* Rx statistics. */ + tree = SYSCTL_ADD_NODE(ctx, parent, OID_AUTO, "rx", CTLFLAG_RD, + NULL, "Rx MAC statistics"); + child = SYSCTL_CHILDREN(tree); + JME_SYSCTL_STAT_ADD32(ctx, child, "good_frames", + &stats->rx_good_frames, "Good frames"); + JME_SYSCTL_STAT_ADD32(ctx, child, "crc_errs", + &stats->rx_crc_errs, "CRC errors"); + JME_SYSCTL_STAT_ADD32(ctx, child, "mii_errs", + &stats->rx_mii_errs, "MII errors"); + JME_SYSCTL_STAT_ADD32(ctx, child, "fifo_oflows", + &stats->rx_fifo_oflows, "FIFO overflows"); + JME_SYSCTL_STAT_ADD32(ctx, child, "desc_empty", + &stats->rx_desc_empty, "Descriptor empty"); + JME_SYSCTL_STAT_ADD32(ctx, child, "bad_frames", + &stats->rx_bad_frames, "Bad frames"); + + /* Tx statistics. */ + tree = SYSCTL_ADD_NODE(ctx, parent, OID_AUTO, "tx", CTLFLAG_RD, + NULL, "Tx MAC statistics"); + child = SYSCTL_CHILDREN(tree); + JME_SYSCTL_STAT_ADD32(ctx, child, "good_frames", + &stats->tx_good_frames, "Good frames"); + JME_SYSCTL_STAT_ADD32(ctx, child, "bad_frames", + &stats->tx_bad_frames, "Bad frames"); } +#undef JME_SYSCTL_STAT_ADD32 + struct jme_dmamap_arg { bus_addr_t jme_busaddr; }; @@ -2164,6 +2209,7 @@ jme_link_task(void *arg, int pending) /* Program MAC with resolved speed/duplex/flow-control. */ if ((sc->jme_flags & JME_FLAG_LINK) != 0) { jme_mac_config(sc); + jme_stats_clear(sc); CSR_WRITE_4(sc, JME_RXCSR, sc->jme_rxcsr); CSR_WRITE_4(sc, JME_TXCSR, sc->jme_txcsr); @@ -2553,6 +2599,7 @@ jme_tick(void *arg) * faster and limit the maximum delay to a hz. */ jme_txeof(sc); + jme_stats_update(sc); jme_watchdog(sc); callout_reset(&sc->jme_tick_ch, hz, jme_tick, sc); } @@ -2862,6 +2909,8 @@ jme_stop(struct jme_softc *sc) txd->tx_ndesc = 0; } } + jme_stats_update(sc); + jme_stats_save(sc); } static void @@ -3093,6 +3142,76 @@ jme_set_filter(struct jme_softc *sc) CSR_WRITE_4(sc, JME_RXMAC, rxcfg); } +static void +jme_stats_clear(struct jme_softc *sc) +{ + + JME_LOCK_ASSERT(sc); + + if ((sc->jme_flags & JME_FLAG_HWMIB) == 0) + return; + + /* Disable and clear counters. */ + CSR_WRITE_4(sc, JME_STATCSR, 0xFFFFFFFF); + /* Activate hw counters. */ + CSR_WRITE_4(sc, JME_STATCSR, 0); + CSR_READ_4(sc, JME_STATCSR); + bzero(&sc->jme_stats, sizeof(struct jme_hw_stats)); +} + +static void +jme_stats_save(struct jme_softc *sc) +{ + + JME_LOCK_ASSERT(sc); + + if ((sc->jme_flags & JME_FLAG_HWMIB) == 0) + return; + /* Save current counters. */ + bcopy(&sc->jme_stats, &sc->jme_ostats, sizeof(struct jme_hw_stats)); + /* Disable and clear counters. */ + CSR_WRITE_4(sc, JME_STATCSR, 0xFFFFFFFF); +} + +static void +jme_stats_update(struct jme_softc *sc) +{ + struct jme_hw_stats *stat, *ostat; + uint32_t reg; + + JME_LOCK_ASSERT(sc); + + if ((sc->jme_flags & JME_FLAG_HWMIB) == 0) + return; + stat = &sc->jme_stats; + ostat = &sc->jme_ostats; + stat->tx_good_frames = CSR_READ_4(sc, JME_STAT_TXGOOD); + stat->rx_good_frames = CSR_READ_4(sc, JME_STAT_RXGOOD); + reg = CSR_READ_4(sc, JME_STAT_CRCMII); + stat->rx_crc_errs = (reg & STAT_RX_CRC_ERR_MASK) >> + STAT_RX_CRC_ERR_SHIFT; + stat->rx_mii_errs = (reg & STAT_RX_MII_ERR_MASK) >> + STAT_RX_MII_ERR_SHIFT; + reg = CSR_READ_4(sc, JME_STAT_RXERR); + stat->rx_fifo_oflows = (reg & STAT_RXERR_OFLOW_MASK) >> + STAT_RXERR_OFLOW_SHIFT; + stat->rx_desc_empty = (reg & STAT_RXERR_MPTY_MASK) >> + STAT_RXERR_MPTY_SHIFT; + reg = CSR_READ_4(sc, JME_STAT_FAIL); + stat->rx_bad_frames = (reg & STAT_FAIL_RX_MASK) >> STAT_FAIL_RX_SHIFT; + stat->tx_bad_frames = (reg & STAT_FAIL_TX_MASK) >> STAT_FAIL_TX_SHIFT; + + /* Account for previous counters. */ + stat->rx_good_frames += ostat->rx_good_frames; + stat->rx_crc_errs += ostat->rx_crc_errs; + stat->rx_mii_errs += ostat->rx_mii_errs; + stat->rx_fifo_oflows += ostat->rx_fifo_oflows; + stat->rx_desc_empty += ostat->rx_desc_empty; + stat->rx_bad_frames += ostat->rx_bad_frames; + stat->tx_good_frames += ostat->tx_good_frames; + stat->tx_bad_frames += ostat->tx_bad_frames; +} + static int sysctl_int_range(SYSCTL_HANDLER_ARGS, int low, int high) { Modified: head/sys/dev/jme/if_jmereg.h ============================================================================== --- head/sys/dev/jme/if_jmereg.h Thu Dec 4 01:58:40 2008 (r185596) +++ head/sys/dev/jme/if_jmereg.h Thu Dec 4 02:16:53 2008 (r185597) @@ -199,6 +199,7 @@ #define TXMAC_IFG2_DEFAULT 0x40000000 #define TXMAC_IFG1_MASK 0x30000000 #define TXMAC_IFG1_DEFAULT 0x20000000 +#define TXMAC_PAUSE_CNT_MASK 0x00FF0000 #define TXMAC_THRESH_1_PKT 0x00000300 #define TXMAC_THRESH_1_2_PKT 0x00000200 #define TXMAC_THRESH_1_4_PKT 0x00000100 @@ -403,6 +404,44 @@ #define PMCS_MAGIC_FRAME_ENB 0x00000001 #define PMCS_WOL_ENB_MASK 0x0000FFFF +/* + * Statistic registers control and status. + * These statistics registers are valid only for JMC250/JMC260 REVFM >= 2. + */ +#define JME_STATCSR 0x0064 +#define STATCSR_RXMPT_DIS 0x00000080 +#define STATCSR_OFLOW_DIS 0x00000040 +#define STATCSR_MIIRXER_DIS 0x00000020 +#define STATCSR_CRCERR_DIS 0x00000010 +#define STATCSR_RXBAD_DIS 0x00000008 +#define STATCSR_RXGOOD_DIS 0x00000004 +#define STATCSR_TXBAD_DIS 0x00000002 +#define STATCSR_TXGOOD_DIS 0x00000001 + +#define JME_STAT_TXGOOD 0x0068 + +#define JME_STAT_RXGOOD 0x006C + +#define JME_STAT_CRCMII 0x0070 +#define STAT_RX_CRC_ERR_MASK 0xFFFF0000 +#define STAT_RX_MII_ERR_MASK 0x0000FFFF +#define STAT_RX_CRC_ERR_SHIFT 16 +#define STAT_RX_MII_ERR_SHIFT 0 + +#define JME_STAT_RXERR 0x0074 +#define STAT_RXERR_OFLOW_MASK 0xFFFF0000 +#define STAT_RXERR_MPTY_MASK 0x0000FFFF +#define STAT_RXERR_OFLOW_SHIFT 16 +#define STAT_RXERR_MPTY_SHIFT 0 + +#define JME_STAT_RESERVED1 0x0078 + +#define JME_STAT_FAIL 0x007C +#define STAT_FAIL_RX_MASK 0xFFFF0000 +#define STAT_FAIL_TX_MASK 0x0000FFFF +#define STAT_FAIL_RX_SHIFT 16 +#define STAT_FAIL_TX_SHIFT 0 + /* Giga PHY & EEPROM registers. */ #define JME_PHY_EEPROM_BASE_ADDR 0x0400 Modified: head/sys/dev/jme/if_jmevar.h ============================================================================== --- head/sys/dev/jme/if_jmevar.h Thu Dec 4 01:58:40 2008 (r185596) +++ head/sys/dev/jme/if_jmevar.h Thu Dec 4 02:16:53 2008 (r185597) @@ -154,6 +154,18 @@ struct jme_ring_data { (sizeof(struct jme_desc) * JME_RX_RING_CNT) #define JME_SSB_SIZE sizeof(struct jme_ssb) +/* Statistics counters. */ +struct jme_hw_stats { + uint32_t rx_good_frames; + uint32_t rx_crc_errs; + uint32_t rx_mii_errs; + uint32_t rx_fifo_oflows; + uint32_t rx_desc_empty; + uint32_t rx_bad_frames; + uint32_t tx_good_frames; + uint32_t tx_bad_frames; +}; + /* * Software state per device. */ @@ -183,9 +195,12 @@ struct jme_softc { #define JME_FLAG_NOJUMBO 0x0080 #define JME_FLAG_TXCLK 0x0100 #define JME_FLAG_DMA32BIT 0x0200 +#define JME_FLAG_HWMIB 0x0400 #define JME_FLAG_DETACH 0x4000 #define JME_FLAG_LINK 0x8000 + struct jme_hw_stats jme_ostats; + struct jme_hw_stats jme_stats; struct callout jme_tick_ch; struct jme_chain_data jme_cdata; struct jme_ring_data jme_rdata; From kmacy at FreeBSD.org Wed Dec 3 23:28:13 2008 From: kmacy at FreeBSD.org (Kip Macy) Date: Wed Dec 3 23:28:25 2008 Subject: svn commit: r185604 - head/sys/i386/xen Message-ID: <200812040728.mB47SDqL014168@svn.freebsd.org> Author: kmacy Date: Thu Dec 4 07:28:13 2008 New Revision: 185604 URL: http://svn.freebsd.org/changeset/base/185604 Log: fix initialization for case of normal kernbase remove unused shutdown code Modified: head/sys/i386/xen/xen_machdep.c Modified: head/sys/i386/xen/xen_machdep.c ============================================================================== --- head/sys/i386/xen/xen_machdep.c Thu Dec 4 05:19:49 2008 (r185603) +++ head/sys/i386/xen/xen_machdep.c Thu Dec 4 07:28:13 2008 (r185604) @@ -36,8 +36,10 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include +#include #include #include #include @@ -61,7 +63,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include @@ -851,6 +852,37 @@ initvalues(start_info_t *startinfo) xen_start_info = startinfo; xen_phys_machine = (xen_pfn_t *)startinfo->mfn_list; + IdlePTD = (pd_entry_t *)((uint8_t *)startinfo->pt_base + PAGE_SIZE); + l1_pages = 0; + +#ifdef PAE + l3_pages = 1; + l2_pages = 0; + IdlePDPT = (pd_entry_t *)startinfo->pt_base; + IdlePDPTma = xpmap_ptom(VTOP(startinfo->pt_base)); + for (i = (KERNBASE >> 30); + (i < 4) && (IdlePDPT[i] != 0); i++) + l2_pages++; + /* + * Note that only one page directory has been allocated at this point. + * Thus, if KERNBASE + */ + for (i = 0; i < l2_pages; i++) + IdlePTDma[i] = xpmap_ptom(VTOP(IdlePTD + i*PAGE_SIZE)); + + l2_pages = (l2_pages == 0) ? 1 : l2_pages; +#else + l3_pages = 0; + l2_pages = 1; +#endif + for (i = (((KERNBASE>>18) & PAGE_MASK)>>PAGE_SHIFT); + (i>PDRSHIFT)); i++) { + + if (IdlePTD[i] == 0) + break; + l1_pages++; + } + /* number of pages allocated after the pts + 1*/; cur_space = xen_start_info->pt_base + ((xen_start_info->nr_pt_frames) + 3 )*PAGE_SIZE; @@ -1123,220 +1155,6 @@ trap_info_t trap_table[] = { }; -static void -shutdown_handler(struct xenbus_watch *watch, - const char **vec, unsigned int len) -{ - char *str; - struct xenbus_transaction xbt; - int err, howto; - struct reboot_args uap; - - howto = 0; - - again: - err = xenbus_transaction_start(&xbt); - if (err) - return; - str = (char *)xenbus_read(xbt, "control", "shutdown", NULL); - /* Ignore read errors and empty reads. */ - if (XENBUS_IS_ERR_READ(str)) { - xenbus_transaction_end(xbt, 1); - return; - } - - xenbus_write(xbt, "control", "shutdown", ""); - - err = xenbus_transaction_end(xbt, 0); - if (err == EAGAIN) { - free(str, M_DEVBUF); - goto again; - } - - if (strcmp(str, "reboot") == 0) - howto = 0; - else if (strcmp(str, "poweroff") == 0) - howto |= (RB_POWEROFF | RB_HALT); - else if (strcmp(str, "halt") == 0) - howto |= RB_HALT; - else if (strcmp(str, "suspend") == 0) - howto = -1; - else { - printf("Ignoring shutdown request: %s\n", str); - goto done; - } -#ifdef notyet - if (howto == -1) { - do_suspend(NULL); - goto done; - } -#else - if (howto == -1) { - printf("suspend not currently supported\n"); - goto done; - } -#endif - uap.opt = howto; - reboot(curthread, &uap); - done: - free(str, M_DEVBUF); -} - -static struct xenbus_watch shutdown_watch = { - .node = "control/shutdown", - .callback = shutdown_handler -}; - - -void setup_shutdown_watcher(void *unused); - - -void -setup_shutdown_watcher(void *unused) -{ - if (register_xenbus_watch(&shutdown_watch)) - printf("Failed to set shutdown watcher\n"); -} - - -SYSINIT(shutdown, SI_SUB_RUN_SCHEDULER, SI_ORDER_ANY, setup_shutdown_watcher, NULL); - -#ifdef notyet - -static void -xen_suspend(void *ignore) -{ - int i, j, k, fpp; - - extern void time_resume(void); - extern unsigned long max_pfn; - extern unsigned long *pfn_to_mfn_frame_list_list; - extern unsigned long *pfn_to_mfn_frame_list[]; - -#ifdef CONFIG_SMP -#error "do_suspend must be run cpu 0 - need to create separate thread" - cpumask_t prev_online_cpus; - int vcpu_prepare(int vcpu); -#endif - - int err = 0; - - PANIC_IF(smp_processor_id() != 0); - -#if defined(CONFIG_SMP) && !defined(CONFIG_HOTPLUG_CPU) - if (num_online_cpus() > 1) { - printk(KERN_WARNING "Can't suspend SMP guests " - "without CONFIG_HOTPLUG_CPU\n"); - return -EOPNOTSUPP; - } -#endif - - xenbus_suspend(); - -#ifdef CONFIG_SMP - lock_cpu_hotplug(); - /* - * Take all other CPUs offline. We hold the hotplug semaphore to - * avoid other processes bringing up CPUs under our feet. - */ - cpus_clear(prev_online_cpus); - while (num_online_cpus() > 1) { - for_each_online_cpu(i) { - if (i == 0) - continue; - unlock_cpu_hotplug(); - err = cpu_down(i); - lock_cpu_hotplug(); - if (err != 0) { - printk(KERN_CRIT "Failed to take all CPUs " - "down: %d.\n", err); - goto out_reenable_cpus; - } - cpu_set(i, prev_online_cpus); - } - } -#endif /* CONFIG_SMP */ - - preempt_disable(); - - - __cli(); - preempt_enable(); -#ifdef SMP - unlock_cpu_hotplug(); -#endif - gnttab_suspend(); - - pmap_kremove(HYPERVISOR_shared_info); - - xen_start_info->store_mfn = mfn_to_pfn(xen_start_info->store_mfn); - xen_start_info->console.domU.mfn = mfn_to_pfn(xen_start_info->console.domU.mfn); - - /* - * We'll stop somewhere inside this hypercall. When it returns, - * we'll start resuming after the restore. - */ - HYPERVISOR_suspend(VTOMFN(xen_start_info)); - - pmap_kenter_ma(HYPERVISOR_shared_info, xen_start_info->shared_info); - set_fixmap(FIX_SHARED_INFO, xen_start_info->shared_info); - -#if 0 - memset(empty_zero_page, 0, PAGE_SIZE); -#endif - HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = - VTOMFN(pfn_to_mfn_frame_list_list); - - fpp = PAGE_SIZE/sizeof(unsigned long); - for (i = 0, j = 0, k = -1; i < max_pfn; i += fpp, j++) { - if ((j % fpp) == 0) { - k++; - pfn_to_mfn_frame_list_list[k] = - VTOMFN(pfn_to_mfn_frame_list[k]); - j = 0; - } - pfn_to_mfn_frame_list[k][j] = - VTOMFN(&phys_to_machine_mapping[i]); - } - HYPERVISOR_shared_info->arch.max_pfn = max_pfn; - - gnttab_resume(); - - irq_resume(); - - time_resume(); - - __sti(); - - xencons_resume(); - -#ifdef CONFIG_SMP - for_each_cpu(i) - vcpu_prepare(i); - -#endif - /* - * Only resume xenbus /after/ we've prepared our VCPUs; otherwise - * the VCPU hotplug callback can race with our vcpu_prepare - */ - xenbus_resume(); - -#ifdef CONFIG_SMP - out_reenable_cpus: - for_each_cpu_mask(i, prev_online_cpus) { - j = cpu_up(i); - if ((j != 0) && !cpu_online(i)) { - printk(KERN_CRIT "Failed to bring cpu " - "%d back up (%d).\n", - i, j); - err = j; - } - } -#endif - return err; -} - -#endif /* notyet */ /********** CODE WORTH KEEPING ABOVE HERE *****************/ void xen_failsafe_handler(void); From kmacy at FreeBSD.org Wed Dec 3 23:59:06 2008 From: kmacy at FreeBSD.org (Kip Macy) Date: Wed Dec 3 23:59:19 2008 Subject: svn commit: r185605 - in head/sys: conf dev/xen/blkfront dev/xen/netfront i386/include/xen i386/xen xen xen/xenbus Message-ID: <200812040759.mB47x5Pq014899@svn.freebsd.org> Author: kmacy Date: Thu Dec 4 07:59:05 2008 New Revision: 185605 URL: http://svn.freebsd.org/changeset/base/185605 Log: Integrate 185578 from dfr Use newbus to managed devices Added: head/sys/xen/xenbus/xenbus_if.m (contents, props changed) head/sys/xen/xenbus/xenbusvar.h (contents, props changed) Deleted: head/sys/i386/include/xen/xenbus.h Modified: head/sys/conf/files head/sys/dev/xen/blkfront/blkfront.c head/sys/dev/xen/blkfront/block.h head/sys/dev/xen/netfront/netfront.c head/sys/i386/xen/xen_machdep.c head/sys/xen/gnttab.c head/sys/xen/gnttab.h head/sys/xen/xenbus/xenbus_client.c head/sys/xen/xenbus/xenbus_comms.c head/sys/xen/xenbus/xenbus_comms.h head/sys/xen/xenbus/xenbus_dev.c head/sys/xen/xenbus/xenbus_probe.c head/sys/xen/xenbus/xenbus_probe_backend.c head/sys/xen/xenbus/xenbus_xs.c Modified: head/sys/conf/files ============================================================================== --- head/sys/conf/files Thu Dec 4 07:28:13 2008 (r185604) +++ head/sys/conf/files Thu Dec 4 07:59:05 2008 (r185605) @@ -2763,10 +2763,14 @@ xen/evtchn/evtchn_dev.c o xen/xenbus/xenbus_client.c optional xen xen/xenbus/xenbus_comms.c optional xen xen/xenbus/xenbus_dev.c optional xen +xen/xenbus/xenbus_if.m optional xen xen/xenbus/xenbus_probe.c optional xen -xen/xenbus/xenbus_probe_backend.c optional xen +#xen/xenbus/xenbus_probe_backend.c optional xen xen/xenbus/xenbus_xs.c optional xen dev/xen/console/console.c optional xen dev/xen/console/xencons_ring.c optional xen dev/xen/blkfront/blkfront.c optional xen dev/xen/netfront/netfront.c optional xen +#dev/xen/xenpci/xenpci.c optional xen +#xen/xenbus/xenbus_newbus.c optional xenhvm + Modified: head/sys/dev/xen/blkfront/blkfront.c ============================================================================== --- head/sys/dev/xen/blkfront/blkfront.c Thu Dec 4 07:28:13 2008 (r185604) +++ head/sys/dev/xen/blkfront/blkfront.c Thu Dec 4 07:59:05 2008 (r185605) @@ -43,9 +43,10 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include +#include +#include #include #include @@ -53,15 +54,17 @@ __FBSDID("$FreeBSD$"); #include +#include "xenbus_if.h" + #define ASSERT(S) KASSERT(S, (#S)) /* prototypes */ struct xb_softc; static void xb_startio(struct xb_softc *sc); -static void connect(struct blkfront_info *); -static void blkfront_closing(struct xenbus_device *); -static int blkfront_remove(struct xenbus_device *); -static int talk_to_backend(struct xenbus_device *, struct blkfront_info *); -static int setup_blkring(struct xenbus_device *, struct blkfront_info *); +static void connect(device_t, struct blkfront_info *); +static void blkfront_closing(device_t); +static int blkfront_detach(device_t); +static int talk_to_backend(device_t, struct blkfront_info *); +static int setup_blkring(device_t, struct blkfront_info *); static void blkif_int(void *); #if 0 static void blkif_restart_queue(void *arg); @@ -136,22 +139,95 @@ pfn_to_mfn(vm_paddr_t pfn) } +/* + * Translate Linux major/minor to an appropriate name and unit + * number. For HVM guests, this allows us to use the same drive names + * with blkfront as the emulated drives, easing transition slightly. + */ +static void +blkfront_vdevice_to_unit(int vdevice, int *unit, const char **name) +{ + static struct vdev_info { + int major; + int shift; + int base; + const char *name; + } info[] = { + {3, 6, 0, "ad"}, /* ide0 */ + {22, 6, 2, "ad"}, /* ide1 */ + {33, 6, 4, "ad"}, /* ide2 */ + {34, 6, 6, "ad"}, /* ide3 */ + {56, 6, 8, "ad"}, /* ide4 */ + {57, 6, 10, "ad"}, /* ide5 */ + {88, 6, 12, "ad"}, /* ide6 */ + {89, 6, 14, "ad"}, /* ide7 */ + {90, 6, 16, "ad"}, /* ide8 */ + {91, 6, 18, "ad"}, /* ide9 */ + + {8, 4, 0, "da"}, /* scsi disk0 */ + {65, 4, 16, "da"}, /* scsi disk1 */ + {66, 4, 32, "da"}, /* scsi disk2 */ + {67, 4, 48, "da"}, /* scsi disk3 */ + {68, 4, 64, "da"}, /* scsi disk4 */ + {69, 4, 80, "da"}, /* scsi disk5 */ + {70, 4, 96, "da"}, /* scsi disk6 */ + {71, 4, 112, "da"}, /* scsi disk7 */ + {128, 4, 128, "da"}, /* scsi disk8 */ + {129, 4, 144, "da"}, /* scsi disk9 */ + {130, 4, 160, "da"}, /* scsi disk10 */ + {131, 4, 176, "da"}, /* scsi disk11 */ + {132, 4, 192, "da"}, /* scsi disk12 */ + {133, 4, 208, "da"}, /* scsi disk13 */ + {134, 4, 224, "da"}, /* scsi disk14 */ + {135, 4, 240, "da"}, /* scsi disk15 */ + + {202, 4, 0, "xbd"}, /* xbd */ + + {0, 0, 0, NULL}, + }; + int major = vdevice >> 8; + int minor = vdevice & 0xff; + int i; + + if (vdevice & (1 << 28)) { + *unit = (vdevice & ((1 << 28) - 1)) >> 8; + *name = "xbd"; + } + + for (i = 0; info[i].major; i++) { + if (info[i].major == major) { + *unit = info[i].base + (minor >> info[i].shift); + *name = info[i].name; + return; + } + } + + *unit = minor >> 4; + *name = "xbd"; +} + int -xlvbd_add(blkif_sector_t capacity, int unit, uint16_t vdisk_info, uint16_t sector_size, - struct blkfront_info *info) +xlvbd_add(device_t dev, blkif_sector_t capacity, + int vdevice, uint16_t vdisk_info, uint16_t sector_size, + struct blkfront_info *info) { struct xb_softc *sc; - int error = 0; - int unitno = unit - 767; + int unit, error = 0; + const char *name; + + blkfront_vdevice_to_unit(vdevice, &unit, &name); sc = (struct xb_softc *)malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO); - sc->xb_unit = unitno; + sc->xb_unit = unit; sc->xb_info = info; info->sc = sc; + if (strcmp(name, "xbd")) + device_printf(dev, "attaching as %s%d\n", name, unit); + memset(&sc->xb_disk, 0, sizeof(sc->xb_disk)); sc->xb_disk = disk_alloc(); - sc->xb_disk->d_unit = unitno; + sc->xb_disk->d_unit = unit; sc->xb_disk->d_open = blkif_open; sc->xb_disk->d_close = blkif_close; sc->xb_disk->d_ioctl = blkif_ioctl; @@ -226,19 +302,33 @@ xb_strategy(struct bio *bp) return; } +static int +blkfront_probe(device_t dev) +{ + + if (!strcmp(xenbus_get_type(dev), "vbd")) { + device_set_desc(dev, "Virtual Block Device"); + device_quiet(dev); + return (0); + } -/* Setup supplies the backend dir, virtual device. + return (ENXIO); +} -We place an event channel and shared frame entries. -We watch backend to wait if it's ok. */ -static int blkfront_probe(struct xenbus_device *dev, - const struct xenbus_device_id *id) +/* + * Setup supplies the backend dir, virtual device. We place an event + * channel and shared frame entries. We watch backend to wait if it's + * ok. + */ +static int +blkfront_attach(device_t dev) { - int err, vdevice, i; + int err, vdevice, i, unit; struct blkfront_info *info; + const char *name; /* FIXME: Use dynamic device id if this is not set. */ - err = xenbus_scanf(XBT_NIL, dev->nodename, + err = xenbus_scanf(XBT_NIL, xenbus_get_node(dev), "virtual-device", "%i", &vdevice); if (err != 1) { xenbus_dev_fatal(dev, err, "reading virtual-device"); @@ -246,11 +336,11 @@ static int blkfront_probe(struct xenbus_ return (err); } - info = malloc(sizeof(*info), M_DEVBUF, M_NOWAIT|M_ZERO); - if (info == NULL) { - xenbus_dev_fatal(dev, ENOMEM, "allocating info structure"); - return ENOMEM; - } + blkfront_vdevice_to_unit(vdevice, &unit, &name); + if (!strcmp(name, "xbd")) + device_set_unit(dev, unit); + + info = device_get_softc(dev); /* * XXX debug only @@ -270,23 +360,20 @@ static int blkfront_probe(struct xenbus_ info->shadow[BLK_RING_SIZE-1].req.id = 0x0fffffff; /* Front end dir is a number, which is used as the id. */ - info->handle = strtoul(strrchr(dev->nodename,'/')+1, NULL, 0); - dev->dev_driver_data = info; + info->handle = strtoul(strrchr(xenbus_get_node(dev),'/')+1, NULL, 0); err = talk_to_backend(dev, info); if (err) { - free(info, M_DEVBUF); - dev->dev_driver_data = NULL; return err; } - return 0; + return (0); } - -static int blkfront_resume(struct xenbus_device *dev) +static int +blkfront_resume(device_t dev) { - struct blkfront_info *info = dev->dev_driver_data; + struct blkfront_info *info = device_get_softc(dev); int err; DPRINTK("blkfront_resume: %s\n", dev->nodename); @@ -301,8 +388,8 @@ static int blkfront_resume(struct xenbus } /* Common code used when first setting up, and when resuming. */ -static int talk_to_backend(struct xenbus_device *dev, - struct blkfront_info *info) +static int +talk_to_backend(device_t dev, struct blkfront_info *info) { const char *message = NULL; struct xenbus_transaction xbt; @@ -320,19 +407,24 @@ static int talk_to_backend(struct xenbus goto destroy_blkring; } - err = xenbus_printf(xbt, dev->nodename, + err = xenbus_printf(xbt, xenbus_get_node(dev), "ring-ref","%u", info->ring_ref); if (err) { message = "writing ring-ref"; goto abort_transaction; } - err = xenbus_printf(xbt, dev->nodename, + err = xenbus_printf(xbt, xenbus_get_node(dev), "event-channel", "%u", irq_to_evtchn_port(info->irq)); if (err) { message = "writing event-channel"; goto abort_transaction; } - + err = xenbus_printf(xbt, xenbus_get_node(dev), + "protocol", "%s", XEN_IO_PROTO_ABI_NATIVE); + if (err) { + message = "writing protocol"; + goto abort_transaction; + } err = xenbus_transaction_end(xbt, 0); if (err) { if (err == -EAGAIN) @@ -340,7 +432,7 @@ static int talk_to_backend(struct xenbus xenbus_dev_fatal(dev, err, "completing transaction"); goto destroy_blkring; } - xenbus_switch_state(dev, XenbusStateInitialised); + xenbus_set_state(dev, XenbusStateInitialised); return 0; @@ -355,7 +447,7 @@ static int talk_to_backend(struct xenbus } static int -setup_blkring(struct xenbus_device *dev, struct blkfront_info *info) +setup_blkring(device_t dev, struct blkfront_info *info) { blkif_sring_t *sring; int err; @@ -378,7 +470,7 @@ setup_blkring(struct xenbus_device *dev, } info->ring_ref = err; - err = bind_listening_port_to_irqhandler(dev->otherend_id, + err = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev), "xbd", (driver_intr_t *)blkif_int, info, INTR_TYPE_BIO | INTR_MPSAFE, NULL); if (err <= 0) { @@ -398,10 +490,10 @@ setup_blkring(struct xenbus_device *dev, /** * Callback received when the backend's state changes. */ -static void backend_changed(struct xenbus_device *dev, - XenbusState backend_state) +static void +blkfront_backend_changed(device_t dev, XenbusState backend_state) { - struct blkfront_info *info = dev->dev_driver_data; + struct blkfront_info *info = device_get_softc(dev); DPRINTK("blkfront:backend_changed.\n"); @@ -416,7 +508,7 @@ static void backend_changed(struct xenbu break; case XenbusStateConnected: - connect(info); + connect(dev, info); break; case XenbusStateClosing: @@ -447,7 +539,7 @@ static void backend_changed(struct xenbu ** the details about the physical device - #sectors, size, etc). */ static void -connect(struct blkfront_info *info) +connect(device_t dev, struct blkfront_info *info) { unsigned long sectors, sector_size; unsigned int binfo; @@ -457,28 +549,34 @@ connect(struct blkfront_info *info) (info->connected == BLKIF_STATE_SUSPENDED) ) return; - DPRINTK("blkfront.c:connect:%s.\n", info->xbdev->otherend); + DPRINTK("blkfront.c:connect:%s.\n", xenbus_get_otherend_path(dev)); - err = xenbus_gather(XBT_NIL, info->xbdev->otherend, + err = xenbus_gather(XBT_NIL, xenbus_get_otherend_path(dev), "sectors", "%lu", §ors, "info", "%u", &binfo, "sector-size", "%lu", §or_size, NULL); if (err) { - xenbus_dev_fatal(info->xbdev, err, - "reading backend fields at %s", - info->xbdev->otherend); + xenbus_dev_fatal(dev, err, + "reading backend fields at %s", + xenbus_get_otherend_path(dev)); return; } - err = xenbus_gather(XBT_NIL, info->xbdev->otherend, + err = xenbus_gather(XBT_NIL, xenbus_get_otherend_path(dev), "feature-barrier", "%lu", &info->feature_barrier, NULL); if (err) info->feature_barrier = 0; - xlvbd_add(sectors, info->vdevice, binfo, sector_size, info); + device_printf(dev, "%juMB <%s> at %s", + (uintmax_t) sectors / (1048576 / sector_size), + device_get_desc(dev), + xenbus_get_node(dev)); + bus_print_child_footer(device_get_parent(dev), dev); - (void)xenbus_switch_state(info->xbdev, XenbusStateConnected); + xlvbd_add(dev, sectors, info->vdevice, binfo, sector_size, info); + + (void)xenbus_set_state(dev, XenbusStateConnected); /* Kick pending requests. */ mtx_lock(&blkif_io_lock); @@ -498,11 +596,12 @@ connect(struct blkfront_info *info) * the backend. Once is this done, we can switch to Closed in * acknowledgement. */ -static void blkfront_closing(struct xenbus_device *dev) +static void +blkfront_closing(device_t dev) { - struct blkfront_info *info = dev->dev_driver_data; + struct blkfront_info *info = device_get_softc(dev); - DPRINTK("blkfront_closing: %s removed\n", dev->nodename); + DPRINTK("blkfront_closing: %s removed\n", xenbus_get_node(dev)); if (info->mi) { DPRINTK("Calling xlvbd_del\n"); @@ -510,20 +609,19 @@ static void blkfront_closing(struct xenb info->mi = NULL; } - xenbus_switch_state(dev, XenbusStateClosed); + xenbus_set_state(dev, XenbusStateClosed); } -static int blkfront_remove(struct xenbus_device *dev) +static int +blkfront_detach(device_t dev) { - struct blkfront_info *info = dev->dev_driver_data; + struct blkfront_info *info = device_get_softc(dev); - DPRINTK("blkfront_remove: %s removed\n", dev->nodename); + DPRINTK("blkfront_remove: %s removed\n", xenbus_get_node(dev)); blkif_free(info, 0); - free(info, M_DEVBUF); - return 0; } @@ -631,8 +729,9 @@ blkif_close(struct disk *dp) /* Check whether we have been instructed to close. We will have ignored this request initially, as the device was still mounted. */ - struct xenbus_device * dev = sc->xb_info->xbdev; - XenbusState state = xenbus_read_driver_state(dev->otherend); + device_t dev = sc->xb_info->xbdev; + XenbusState state = + xenbus_read_driver_state(xenbus_get_otherend_path(dev)); if (state == XenbusStateClosing) blkfront_closing(dev); @@ -731,7 +830,7 @@ static int blkif_queue_request(struct bi gnttab_grant_foreign_access_ref( ref, - info->xbdev->otherend_id, + xenbus_get_otherend_id(info->xbdev), buffer_ma >> PAGE_SHIFT, ring_req->operation & 1 ); /* ??? */ info->shadow[id].frame[ring_req->nr_segments] = @@ -952,7 +1051,7 @@ blkif_recover(struct blkfront_info *info for (j = 0; j < req->nr_segments; j++) gnttab_grant_foreign_access_ref( req->seg[j].gref, - info->xbdev->otherend_id, + xenbus_get_otherend_id(info->xbdev), pfn_to_mfn(info->shadow[req->id].frame[j]), 0 /* assume not readonly */); @@ -963,7 +1062,7 @@ blkif_recover(struct blkfront_info *info free(copy, M_DEVBUF); - xenbus_switch_state(info->xbdev, XenbusStateConnected); + xenbus_set_state(info->xbdev, XenbusStateConnected); /* Now safe for us to use the shared ring */ mtx_lock(&blkif_io_lock); @@ -979,48 +1078,30 @@ blkif_recover(struct blkfront_info *info mtx_unlock(&blkif_io_lock); } -static int -blkfront_is_ready(struct xenbus_device *dev) -{ - struct blkfront_info *info = dev->dev_driver_data; - - return info->is_ready; -} - -static struct xenbus_device_id blkfront_ids[] = { - { "vbd" }, - { "" } -}; - - -static struct xenbus_driver blkfront = { - .name = "vbd", - .ids = blkfront_ids, - .probe = blkfront_probe, - .remove = blkfront_remove, - .resume = blkfront_resume, - .otherend_changed = backend_changed, - .is_ready = blkfront_is_ready, -}; - - - -static void -xenbus_init(void) -{ - xenbus_register_frontend(&blkfront); -} +/* ** Driver registration ** */ +static device_method_t blkfront_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, blkfront_probe), + DEVMETHOD(device_attach, blkfront_attach), + DEVMETHOD(device_detach, blkfront_detach), + DEVMETHOD(device_shutdown, bus_generic_shutdown), + DEVMETHOD(device_suspend, bus_generic_suspend), + DEVMETHOD(device_resume, blkfront_resume), + + /* Xenbus interface */ + DEVMETHOD(xenbus_backend_changed, blkfront_backend_changed), + + { 0, 0 } +}; + +static driver_t blkfront_driver = { + "xbd", + blkfront_methods, + sizeof(struct blkfront_info), +}; +devclass_t blkfront_devclass; + +DRIVER_MODULE(xbd, xenbus, blkfront_driver, blkfront_devclass, 0, 0); MTX_SYSINIT(ioreq, &blkif_io_lock, "BIO LOCK", MTX_NOWITNESS); /* XXX how does one enroll a lock? */ -SYSINIT(xbdev, SI_SUB_PSEUDO, SI_ORDER_SECOND, xenbus_init, NULL); - -/* - * Local variables: - * mode: C - * c-set-style: "BSD" - * c-basic-offset: 8 - * tab-width: 4 - * indent-tabs-mode: t - * End: - */ Modified: head/sys/dev/xen/blkfront/block.h ============================================================================== --- head/sys/dev/xen/blkfront/block.h Thu Dec 4 07:28:13 2008 (r185604) +++ head/sys/dev/xen/blkfront/block.h Thu Dec 4 07:59:05 2008 (r185605) @@ -60,7 +60,7 @@ struct xb_softc { */ struct blkfront_info { - struct xenbus_device *xbdev; + device_t xbdev; dev_t dev; struct gendisk *gd; int vdevice; @@ -89,7 +89,7 @@ struct blkfront_info /* Note that xlvbd_add doesn't call add_disk for you: you're expected to call add_disk on info->gd once the disk is properly connected up. */ -int xlvbd_add(blkif_sector_t capacity, int device, +int xlvbd_add(device_t, blkif_sector_t capacity, int device, uint16_t vdisk_info, uint16_t sector_size, struct blkfront_info *info); void xlvbd_del(struct blkfront_info *info); Modified: head/sys/dev/xen/netfront/netfront.c ============================================================================== --- head/sys/dev/xen/netfront/netfront.c Thu Dec 4 07:28:13 2008 (r185604) +++ head/sys/dev/xen/netfront/netfront.c Thu Dec 4 07:59:05 2008 (r185605) @@ -25,6 +25,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -64,13 +65,14 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include #include #include +#include +#include "xenbus_if.h" #define GRANT_INVALID_REF 0 @@ -116,19 +118,19 @@ static void xn_watchdog(struct ifnet *); static void show_device(struct netfront_info *sc); #ifdef notyet -static void netfront_closing(struct xenbus_device *dev); +static void netfront_closing(device_t dev); #endif static void netif_free(struct netfront_info *info); -static int netfront_remove(struct xenbus_device *dev); +static int netfront_detach(device_t dev); -static int talk_to_backend(struct xenbus_device *dev, struct netfront_info *info); -static int create_netdev(struct xenbus_device *dev, struct ifnet **ifp); +static int talk_to_backend(device_t dev, struct netfront_info *info); +static int create_netdev(device_t dev); static void netif_disconnect_backend(struct netfront_info *info); -static int setup_device(struct xenbus_device *dev, struct netfront_info *info); +static int setup_device(device_t dev, struct netfront_info *info); static void end_access(int ref, void *page); /* Xenolinux helper functions */ -static int network_connect(struct ifnet *ifp); +int network_connect(struct netfront_info *); static void xn_free_rx_ring(struct netfront_info *); @@ -221,7 +223,7 @@ struct netfront_info { grant_ref_t grant_rx_ref[NET_TX_RING_SIZE + 1]; #define TX_MAX_TARGET min(NET_RX_RING_SIZE, 256) - struct xenbus_device *xbdev; + device_t xbdev; int tx_ring_ref; int rx_ring_ref; uint8_t mac[ETHER_ADDR_LEN]; @@ -327,7 +329,7 @@ xennet_get_rx_ref(struct netfront_info * #define WPRINTK(fmt, args...) \ printf("[XEN] " fmt, ##args) #define DPRINTK(fmt, args...) \ - printf("[XEN] " fmt, ##args) + printf("[XEN] %s: " fmt, __func__, ##args) static __inline struct mbuf* @@ -340,15 +342,15 @@ makembuf (struct mbuf *buf) if (! m) return 0; - M_MOVE_PKTHDR(m, buf); + M_MOVE_PKTHDR(m, buf); - m_cljget(m, M_DONTWAIT, MJUMPAGESIZE); + m_cljget(m, M_DONTWAIT, MJUMPAGESIZE); m->m_pkthdr.len = buf->m_pkthdr.len; m->m_len = buf->m_len; - m_copydata(buf, 0, buf->m_pkthdr.len, mtod(m,caddr_t) ); + m_copydata(buf, 0, buf->m_pkthdr.len, mtod(m,caddr_t) ); m->m_ext.ext_arg1 = (caddr_t *)(uintptr_t)(vtophys(mtod(m,caddr_t)) >> PAGE_SHIFT); - + return m; } @@ -359,12 +361,12 @@ makembuf (struct mbuf *buf) * Return 0 on success, or errno on error. */ static int -xen_net_read_mac(struct xenbus_device *dev, uint8_t mac[]) +xen_net_read_mac(device_t dev, uint8_t mac[]) { char *s; int i; char *e; - char *macstr = xenbus_read(XBT_NIL, dev->nodename, "mac", NULL); + char *macstr = xenbus_read(XBT_NIL, xenbus_get_node(dev), "mac", NULL); if (IS_ERR(macstr)) { return PTR_ERR(macstr); } @@ -388,23 +390,28 @@ xen_net_read_mac(struct xenbus_device *d * Connected state. */ static int -netfront_probe(struct xenbus_device *dev, const struct xenbus_device_id *id) +netfront_probe(device_t dev) { + + if (!strcmp(xenbus_get_type(dev), "vif")) { + device_set_desc(dev, "Virtual Network Interface"); + return (0); + } + + return (ENXIO); +} + +static int +netfront_attach(device_t dev) +{ int err; - struct ifnet *ifp; - struct netfront_info *info; - printf("netfront_probe() \n"); - - err = create_netdev(dev, &ifp); + err = create_netdev(dev); if (err) { xenbus_dev_fatal(dev, err, "creating netdev"); return err; } - info = ifp->if_softc; - dev->dev_driver_data = info; - return 0; } @@ -416,11 +423,11 @@ netfront_probe(struct xenbus_device *dev * rest of the kernel. */ static int -netfront_resume(struct xenbus_device *dev) +netfront_resume(device_t dev) { - struct netfront_info *info = dev->dev_driver_data; + struct netfront_info *info = device_get_softc(dev); - DPRINTK("%s\n", dev->nodename); + DPRINTK("%s\n", xenbus_get_node(dev)); netif_disconnect_backend(info); return (0); @@ -429,15 +436,16 @@ netfront_resume(struct xenbus_device *de /* Common code used when first setting up, and when resuming. */ static int -talk_to_backend(struct xenbus_device *dev, struct netfront_info *info) +talk_to_backend(device_t dev, struct netfront_info *info) { const char *message; struct xenbus_transaction xbt; + const char *node = xenbus_get_node(dev); int err; err = xen_net_read_mac(dev, info->mac); if (err) { - xenbus_dev_fatal(dev, err, "parsing %s/mac", dev->nodename); + xenbus_dev_fatal(dev, err, "parsing %s/mac", node); goto out; } @@ -452,47 +460,47 @@ talk_to_backend(struct xenbus_device *de xenbus_dev_fatal(dev, err, "starting transaction"); goto destroy_ring; } - err = xenbus_printf(xbt, dev->nodename, "tx-ring-ref","%u", + err = xenbus_printf(xbt, node, "tx-ring-ref","%u", info->tx_ring_ref); if (err) { message = "writing tx ring-ref"; goto abort_transaction; } - err = xenbus_printf(xbt, dev->nodename, "rx-ring-ref","%u", + err = xenbus_printf(xbt, node, "rx-ring-ref","%u", info->rx_ring_ref); if (err) { message = "writing rx ring-ref"; goto abort_transaction; } - err = xenbus_printf(xbt, dev->nodename, + err = xenbus_printf(xbt, node, "event-channel", "%u", irq_to_evtchn_port(info->irq)); if (err) { message = "writing event-channel"; goto abort_transaction; } - err = xenbus_printf(xbt, dev->nodename, "request-rx-copy", "%u", + err = xenbus_printf(xbt, node, "request-rx-copy", "%u", info->copying_receiver); if (err) { message = "writing request-rx-copy"; goto abort_transaction; } - err = xenbus_printf(xbt, dev->nodename, "feature-rx-notify", "%d", 1); + err = xenbus_printf(xbt, node, "feature-rx-notify", "%d", 1); if (err) { message = "writing feature-rx-notify"; goto abort_transaction; } - err = xenbus_printf(xbt, dev->nodename, "feature-no-csum-offload", "%d", 1); + err = xenbus_printf(xbt, node, "feature-no-csum-offload", "%d", 1); if (err) { message = "writing feature-no-csum-offload"; goto abort_transaction; } - err = xenbus_printf(xbt, dev->nodename, "feature-sg", "%d", 1); + err = xenbus_printf(xbt, node, "feature-sg", "%d", 1); if (err) { message = "writing feature-sg"; goto abort_transaction; } #ifdef HAVE_TSO - err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv4", "%d", 1); + err = xenbus_printf(xbt, node, "feature-gso-tcpv4", "%d", 1); if (err) { message = "writing feature-gso-tcpv4"; goto abort_transaction; @@ -520,7 +528,7 @@ talk_to_backend(struct xenbus_device *de static int -setup_device(struct xenbus_device *dev, struct netfront_info *info) +setup_device(device_t dev, struct netfront_info *info) { netif_tx_sring_t *txs; netif_rx_sring_t *rxs; @@ -563,9 +571,9 @@ setup_device(struct xenbus_device *dev, info->rx_ring_ref = err; #if 0 - network_connect(ifp); + network_connect(info); #endif - err = bind_listening_port_to_irqhandler(dev->otherend_id, + err = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev), "xn", xn_intr, info, INTR_TYPE_NET | INTR_MPSAFE, NULL); if (err <= 0) { @@ -588,14 +596,13 @@ setup_device(struct xenbus_device *dev, * Callback received when the backend's state changes. */ static void -backend_changed(struct xenbus_device *dev, - XenbusState backend_state) +netfront_backend_changed(device_t dev, XenbusState newstate) { - struct netfront_info *sc = dev->dev_driver_data; + struct netfront_info *sc = device_get_softc(dev); - DPRINTK("\n"); - - switch (backend_state) { + DPRINTK("newstate=%d\n", newstate); + + switch (newstate) { case XenbusStateInitialising: case XenbusStateInitialised: case XenbusStateConnected: @@ -603,19 +610,19 @@ backend_changed(struct xenbus_device *de case XenbusStateClosed: case XenbusStateReconfigured: case XenbusStateReconfiguring: - break; + break; case XenbusStateInitWait: - if (dev->state != XenbusStateInitialising) + if (xenbus_get_state(dev) != XenbusStateInitialising) break; - if (network_connect(sc->xn_ifp) != 0) + if (network_connect(sc) != 0) break; - xenbus_switch_state(dev, XenbusStateConnected); + xenbus_set_state(dev, XenbusStateConnected); #ifdef notyet (void)send_fake_arp(netdev); #endif - break; break; + break; case XenbusStateClosing: - xenbus_frontend_closed(dev); + xenbus_set_state(dev, XenbusStateClosed); break; } } @@ -674,7 +681,8 @@ netif_release_tx_bufs(struct netfront_in if (((u_long)m) < KERNBASE) continue; gnttab_grant_foreign_access_ref(np->grant_tx_ref[i], - np->xbdev->otherend_id, virt_to_mfn(mtod(m, vm_offset_t)), + xenbus_get_otherend_id(np->xbdev), + virt_to_mfn(mtod(m, vm_offset_t)), GNTMAP_readonly); gnttab_release_grant_reference(&np->gref_tx_head, np->grant_tx_ref[i]); @@ -687,6 +695,7 @@ netif_release_tx_bufs(struct netfront_in static void network_alloc_rx_buffers(struct netfront_info *sc) { + int otherend_id = xenbus_get_otherend_id(sc->xbdev); unsigned short id; struct mbuf *m_new; int i, batch_target, notify; @@ -768,7 +777,7 @@ refill: if (sc->copying_receiver == 0) { gnttab_grant_foreign_transfer_ref(ref, - sc->xbdev->otherend_id, pfn); + otherend_id, pfn); sc->rx_pfn_array[nr_flips] = PFNTOMFN(pfn); if (!xen_feature(XENFEAT_auto_translated_physmap)) { /* Remove this page before passing @@ -781,7 +790,7 @@ refill: nr_flips++; } else { gnttab_grant_foreign_access_ref(ref, - sc->xbdev->otherend_id, + otherend_id, PFNTOMFN(pfn), 0); } req->id = id; @@ -1298,6 +1307,7 @@ xn_tick(void *xsc) static void xn_start_locked(struct ifnet *ifp) { + int otherend_id; unsigned short id; struct mbuf *m_head, *new_m; struct netfront_info *sc; @@ -1308,6 +1318,7 @@ xn_start_locked(struct ifnet *ifp) int notify; sc = ifp->if_softc; + otherend_id = xenbus_get_otherend_id(sc->xbdev); tx_bytes = 0; if (!netfront_carrier_ok(sc)) @@ -1337,7 +1348,7 @@ xn_start_locked(struct ifnet *ifp) ref = gnttab_claim_grant_reference(&sc->gref_tx_head); KASSERT((short)ref >= 0, ("Negative ref")); mfn = virt_to_mfn(mtod(new_m, vm_offset_t)); - gnttab_grant_foreign_access_ref(ref, sc->xbdev->otherend_id, + gnttab_grant_foreign_access_ref(ref, otherend_id, mfn, GNTMAP_readonly); tx->gref = sc->grant_tx_ref[id] = ref; tx->size = new_m->m_pkthdr.len; @@ -1543,23 +1554,19 @@ xn_stop(struct netfront_info *sc) } /* START of Xenolinux helper functions adapted to FreeBSD */ -static int -network_connect(struct ifnet *ifp) +int +network_connect(struct netfront_info *np) { - struct netfront_info *np; int i, requeue_idx, err; grant_ref_t ref; netif_rx_request_t *req; u_int feature_rx_copy, feature_rx_flip; - printf("network_connect\n"); - - np = ifp->if_softc; - err = xenbus_scanf(XBT_NIL, np->xbdev->otherend, + err = xenbus_scanf(XBT_NIL, xenbus_get_otherend_path(np->xbdev), "feature-rx-copy", "%u", &feature_rx_copy); if (err != 1) feature_rx_copy = 0; - err = xenbus_scanf(XBT_NIL, np->xbdev->otherend, + err = xenbus_scanf(XBT_NIL, xenbus_get_otherend_path(np->xbdev), "feature-rx-flip", "%u", &feature_rx_flip); if (err != 1) feature_rx_flip = 1; @@ -1576,7 +1583,7 @@ network_connect(struct ifnet *ifp) /* Recovery procedure: */ err = talk_to_backend(np->xbdev, np); if (err) - return (err); + return (err); /* Step 1: Reinitialise variables. */ netif_release_tx_bufs(np); @@ -1594,11 +1601,11 @@ network_connect(struct ifnet *ifp) if (!np->copying_receiver) { gnttab_grant_foreign_transfer_ref(ref, - np->xbdev->otherend_id, + xenbus_get_otherend_id(np->xbdev), vtophys(mtod(m, vm_offset_t))); } else { gnttab_grant_foreign_access_ref(ref, - np->xbdev->otherend_id, + xenbus_get_otherend_id(np->xbdev), vtophys(mtod(m, vm_offset_t)), 0); } req->gref = ref; @@ -1625,7 +1632,6 @@ network_connect(struct ifnet *ifp) return (0); } - static void show_device(struct netfront_info *sc) { @@ -1645,25 +1651,18 @@ show_device(struct netfront_info *sc) #endif } -static int ifno = 0; - /** Create a network device. * @param handle device handle */ -static int -create_netdev(struct xenbus_device *dev, struct ifnet **ifpp) +int +create_netdev(device_t dev) { int i; struct netfront_info *np; int err; struct ifnet *ifp; - np = (struct netfront_info *)malloc(sizeof(struct netfront_info), - M_DEVBUF, M_NOWAIT); *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From alfred at freebsd.org Thu Dec 4 01:57:57 2008 From: alfred at freebsd.org (Alfred Perlstein) Date: Thu Dec 4 01:58:08 2008 Subject: svn commit: r185499 - head In-Reply-To: <20081201.221040.-1350500631.imp@bsdimp.com> References: <49338E98.7020104@freebsd.org> <863ah8rvcd.fsf@ds4.des.no> <20081201132554.GD27096@elvis.mu.org> <20081201.221040.-1350500631.imp@bsdimp.com> Message-ID: <20081204095756.GP27096@elvis.mu.org> * M. Warner Losh [081201 21:12] wrote: > In message: <20081201132554.GD27096@elvis.mu.org> > Alfred Perlstein writes: > : * Dag-Erling Sm??rgrav [081201 03:25] wrote: > : > Tim Kientzle writes: > : > > Alfred Perlstein writes: > : > > > Log: > : > > > Provide a 'tinderbox' target that compiles enough of FreeBSD that > : > > > a developer can rest reasonably assured that the tinderbox will not > : > > > be broken. This target leverages most of 'universe' but will exit > : > > > non-zero and output a summary at the end. > : > > > "make tinderbox" > : > > Excellent! > : > > : > I really don't see the point, especially now that 'make universe' will > : > issue a warning on stdout for every build that fails. As I've tried to > : > explain to Alfred, the tinderbox does nothing magical, and nothing that > : > isn't already covered by 'make universe'. I also asked him to discuss > : > any changes with Poul-Henning before committing them. > : > : I'll summarize the changes here: > : > : Problems with make universe: > : 1) Make universe returns success on failure. > : 2) Make universe outputs the following on failure: > : -------------------------------------------------------------- > : make universe completed on `LC_ALL=C date`" > : (started ${STARTTIME})" > : -------------------------------------------------------------- > : > : This basically means you can't chain 'make universe' into something > : like "make tinderbox || (echo oops | mail -s tinderbox failed...)". > : > : The summary at the end "completed" is very misleading. > : > : The tinderbox target differs as follows: > : > : It returns an error if it fails. > : It outputs a summary of the failures at the end. > : The name reflects what its for. ("what the heck is a universe?") > : > : > : If you strongly believe that a target should return "true" on failure > : and/or output "i worked" on failure then I'm not sure how to approach > : that mindset, maybe you can help me understand where you're coming from > : on that? Where is the utility in it? Is there something I'm missing? > > I think you ignored the discussions that said that 'universe' should > be modified to exit with an error when there was an error, but > shouldn't bail out EARLY. There were even patches to do this. Interesting, I didn't see them and they weren't committed. The owner/maintainer of universe hasn't really stepped up to provide anything and ask me "hey Alfred, would this be helpful?" and the owner/maintainer of tinderbox has not either. Mostly the two of them have told me "you do it, or shut up", so I did it. > Based on that, why do something completely new and different? New and different? What? Maybe you can explain to me what's so earth shattering new and different about having a make target behave like most any other sane make target and have a name that is self-documenting? There is a 'tinderbox' target, which is named so that when someone says "gee, I wonder how to satisfy the tinderbox" they do not need to read a wiki, blog, handbook, manpage, check IRC, news group or mailing list archive to figure out, they can just run it and get something that makes sense. Anyhow, I don't really care what's done so as long as there's a top level target that does what I just committed, so if someone wants to redo how I did what I did in order to get the exact same results they can be my guest. I would hope that they have better things to do though. -- - Alfred Perlstein From brde at optusnet.com.au Thu Dec 4 02:55:40 2008 From: brde at optusnet.com.au (Bruce Evans) Date: Thu Dec 4 02:55:57 2008 Subject: svn commit: r185594 - head/sbin/newfs_msdos In-Reply-To: <200812040009.30837.max@love2party.net> References: <200812032300.mB3N0vZW003970@svn.freebsd.org> <200812040009.30837.max@love2party.net> Message-ID: <20081204213600.G4414@delplex.bde.org> On Thu, 4 Dec 2008, Max Laier wrote: > On Thursday 04 December 2008 00:00:57 Max Laier wrote: >> Author: mlaier >> Date: Wed Dec 3 23:00:57 2008 >> New Revision: 185594 >> URL: http://svn.freebsd.org/changeset/base/185594 >> >> Log: >> Fix build - cast off_t to (intmax_t) for printing. intmax_t is declared in , but this patch gets it by including the full bloat of . However, is needed for a complete fix. Input of off_t's is still broken -- it uses strtoll(), but should use strtoimax() so as not to depend on the implementation of off_t and so as not to have style bugs (any use of long long). > I'd really like to typedef the int64 types "long long" on all architectures > :-\ It's a big POLA violation in my opinion and causes quite a bit of porting > headache. Or at least let's fix printf to understand that "long" types on > 64bit architectures can be printed with %ll. Since they are - in fact - 64bit > wide. > > But I keep reiterating this point - I guess I still don't understand the exact > reason why we can't just do that. This would break detection of the bug that you fixed. Printing off_t using either %ld or %lld is a bug, since off_t might not be either of long or long long. Having %ld (physically) incompatible with long long on 32-bit arches and %lld (only logically) incompatible with long long on 64-bit arches results in both errors being detected eventually. Bruce From kostikbel at gmail.com Thu Dec 4 03:10:46 2008 From: kostikbel at gmail.com (Kostik Belousov) Date: Thu Dec 4 03:10:58 2008 Subject: svn commit: r185589 - head/sys/compat/freebsd32 In-Reply-To: <200812031803.03650.jhb@freebsd.org> References: <200812031845.mB3IjcZC098534@svn.freebsd.org> <20081203214306.GC2401@deviant.kiev.zoral.com.ua> <200812031803.03650.jhb@freebsd.org> Message-ID: <20081204111041.GB2038@deviant.kiev.zoral.com.ua> On Wed, Dec 03, 2008 at 06:03:03PM -0500, John Baldwin wrote: > On Wednesday 03 December 2008 04:43:06 pm Kostik Belousov wrote: > > On Wed, Dec 03, 2008 at 06:45:38PM +0000, John Baldwin wrote: > > > Author: jhb > > > Date: Wed Dec 3 18:45:38 2008 > > > New Revision: 185589 > > > URL: http://svn.freebsd.org/changeset/base/185589 > > > > > > Log: > > > When unloading a 32-bit system call module, restore the sysent vector in > > > the 32-bit system call table instead of the main system call table. > > > > > > Modified: > > > head/sys/compat/freebsd32/freebsd32_misc.c > > > > > The module build glue is not committed into the svn, isn't it ? > > Err, it is. It's in freebsd32_util.h (SYSCALL32_MODULE, etc.). I saw that, I would call it initialization glue. I mean that freebsd32 cannot be _load_ as module. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 195 bytes Desc: not available Url : http://lists.freebsd.org/pipermail/svn-src-head/attachments/20081204/b9747c1c/attachment.pgp From des at des.no Thu Dec 4 04:42:28 2008 From: des at des.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Thu Dec 4 04:42:34 2008 Subject: svn commit: r185499 - head In-Reply-To: <20081204095756.GP27096@elvis.mu.org> (Alfred Perlstein's message of "Thu, 4 Dec 2008 01:57:56 -0800") References: <49338E98.7020104@freebsd.org> <863ah8rvcd.fsf@ds4.des.no> <20081201132554.GD27096@elvis.mu.org> <20081201.221040.-1350500631.imp@bsdimp.com> <20081204095756.GP27096@elvis.mu.org> Message-ID: <863ah4158t.fsf@ds4.des.no> Alfred Perlstein writes: > There is a 'tinderbox' target, which is named so that when someone > says "gee, I wonder how to satisfy the tinderbox" they do not need > to read a wiki, blog, handbook, manpage, check IRC, news group > or mailing list archive to figure out, they can just run it and > get something that makes sense. Please, let's not go there again. You know perfectly well that the tinderbox simply runs 'make buildworld'. It is no harder or easier to satisfy than our users. DES -- Dag-Erling Sm?rgrav - des@des.no From imp at FreeBSD.org Thu Dec 4 08:31:08 2008 From: imp at FreeBSD.org (Warner Losh) Date: Thu Dec 4 08:31:14 2008 Subject: svn commit: r185614 - head/sys/cddl/contrib/opensolaris/uts/common/sys Message-ID: <200812041631.mB4GV8P8026152@svn.freebsd.org> Author: imp Date: Thu Dec 4 16:31:08 2008 New Revision: 185614 URL: http://svn.freebsd.org/changeset/base/185614 Log: Put the MIPS support back in after it was removed in r185029. Modified: head/sys/cddl/contrib/opensolaris/uts/common/sys/isa_defs.h Modified: head/sys/cddl/contrib/opensolaris/uts/common/sys/isa_defs.h ============================================================================== --- head/sys/cddl/contrib/opensolaris/uts/common/sys/isa_defs.h Thu Dec 4 15:34:53 2008 (r185613) +++ head/sys/cddl/contrib/opensolaris/uts/common/sys/isa_defs.h Thu Dec 4 16:31:08 2008 (r185614) @@ -387,6 +387,49 @@ extern "C" { #define _DONT_USE_1275_GENERIC_NAMES #define _HAVE_CPUID_INSN +#elif defined(__mips__) + +/* + * Define the appropriate "processor characteristics" + */ +#define _STACK_GROWS_DOWNWARD +#define _LONG_LONG_LTOH +#define _BIT_FIELDS_LTOH +#define _IEEE_754 +#define _CHAR_IS_SIGNED +#define _BOOL_ALIGNMENT 1 +#define _CHAR_ALIGNMENT 1 +#define _SHORT_ALIGNMENT 2 +#define _INT_ALIGNMENT 4 +#define _FLOAT_ALIGNMENT 4 +#define _FLOAT_COMPLEX_ALIGNMENT 4 +#define _LONG_ALIGNMENT 4 +#define _LONG_LONG_ALIGNMENT 4 +#define _DOUBLE_ALIGNMENT 4 +#define _DOUBLE_COMPLEX_ALIGNMENT 4 +#define _LONG_DOUBLE_ALIGNMENT 4 +#define _LONG_DOUBLE_COMPLEX_ALIGNMENT 4 +#define _POINTER_ALIGNMENT 4 +#define _MAX_ALIGNMENT 4 +#define _ALIGNMENT_REQUIRED 0 + +#define _LONG_LONG_ALIGNMENT_32 _LONG_LONG_ALIGNMENT + +/* + * Define the appropriate "implementation choices". + */ +#define _ILP32 +#if !defined(_I32LPx) && defined(_KERNEL) +#define _I32LPx +#endif +#define _SUNOS_VTOC_16 +#define _DMA_USES_PHYSADDR +#define _FIRMWARE_NEEDS_FDISK +#define _PSM_MODULES +#define _RTC_CONFIG +#define _DONT_USE_1275_GENERIC_NAMES +#define _HAVE_CPUID_INSN + #elif defined(__powerpc__) /* From alfred at freebsd.org Thu Dec 4 08:35:43 2008 From: alfred at freebsd.org (Alfred Perlstein) Date: Thu Dec 4 08:35:54 2008 Subject: svn commit: r185499 - head In-Reply-To: <863ah4158t.fsf@ds4.des.no> References: <49338E98.7020104@freebsd.org> <863ah8rvcd.fsf@ds4.des.no> <20081201132554.GD27096@elvis.mu.org> <20081201.221040.-1350500631.imp@bsdimp.com> <20081204095756.GP27096@elvis.mu.org> <863ah4158t.fsf@ds4.des.no> Message-ID: <20081204163542.GQ27096@elvis.mu.org> * Dag-Erling Sm??rgrav [081204 04:42] wrote: > Alfred Perlstein writes: > > There is a 'tinderbox' target, which is named so that when someone > > says "gee, I wonder how to satisfy the tinderbox" they do not need > > to read a wiki, blog, handbook, manpage, check IRC, news group > > or mailing list archive to figure out, they can just run it and > > get something that makes sense. > > Please, let's not go there again. You know perfectly well that the > tinderbox simply runs 'make buildworld'. It is no harder or easier to > satisfy than our users. Really? So a person on a i386 platform that touches let's say src/sys/proc.h will have quality checked via "make buildworld" to the degree that they know it won't break all other platforms too? -- - Alfred Perlstein From imp at bsdimp.com Thu Dec 4 08:39:06 2008 From: imp at bsdimp.com (M. Warner Losh) Date: Thu Dec 4 08:39:18 2008 Subject: svn commit: r185499 - head In-Reply-To: <20081204095756.GP27096@elvis.mu.org> References: <20081201132554.GD27096@elvis.mu.org> <20081201.221040.-1350500631.imp@bsdimp.com> <20081204095756.GP27096@elvis.mu.org> Message-ID: <20081204.093642.778147376.imp@bsdimp.com> In message: <20081204095756.GP27096@elvis.mu.org> Alfred Perlstein writes: : * M. Warner Losh [081201 21:12] wrote: : > In message: <20081201132554.GD27096@elvis.mu.org> : > Alfred Perlstein writes: : > : * Dag-Erling Sm??rgrav [081201 03:25] wrote: : > : > Tim Kientzle writes: : > : > > Alfred Perlstein writes: : > : > > > Log: : > : > > > Provide a 'tinderbox' target that compiles enough of FreeBSD that : > : > > > a developer can rest reasonably assured that the tinderbox will not : > : > > > be broken. This target leverages most of 'universe' but will exit : > : > > > non-zero and output a summary at the end. : > : > > > "make tinderbox" : > : > > Excellent! : > : > : > : > I really don't see the point, especially now that 'make universe' will : > : > issue a warning on stdout for every build that fails. As I've tried to : > : > explain to Alfred, the tinderbox does nothing magical, and nothing that : > : > isn't already covered by 'make universe'. I also asked him to discuss : > : > any changes with Poul-Henning before committing them. : > : : > : I'll summarize the changes here: : > : : > : Problems with make universe: : > : 1) Make universe returns success on failure. : > : 2) Make universe outputs the following on failure: : > : -------------------------------------------------------------- : > : make universe completed on `LC_ALL=C date`" : > : (started ${STARTTIME})" : > : -------------------------------------------------------------- : > : : > : This basically means you can't chain 'make universe' into something : > : like "make tinderbox || (echo oops | mail -s tinderbox failed...)". : > : : > : The summary at the end "completed" is very misleading. : > : : > : The tinderbox target differs as follows: : > : : > : It returns an error if it fails. : > : It outputs a summary of the failures at the end. : > : The name reflects what its for. ("what the heck is a universe?") : > : : > : : > : If you strongly believe that a target should return "true" on failure : > : and/or output "i worked" on failure then I'm not sure how to approach : > : that mindset, maybe you can help me understand where you're coming from : > : on that? Where is the utility in it? Is there something I'm missing? : > : > I think you ignored the discussions that said that 'universe' should : > be modified to exit with an error when there was an error, but : > shouldn't bail out EARLY. There were even patches to do this. : : Interesting, I didn't see them and they weren't committed. : : The owner/maintainer of universe hasn't really stepped up to : provide anything and ask me "hey Alfred, would this be helpful?" : and the owner/maintainer of tinderbox has not either. : : Mostly the two of them have told me "you do it, or shut up", so I : did it. Except in public there were others involved that had also done it. : > Based on that, why do something completely new and different? : : New and different? What? : : Maybe you can explain to me what's so earth shattering new and : different about having a make target behave like most any other : sane make target and have a name that is self-documenting? It invents a completely new target to do what the originator of universe said was the right behavior for universe. bz had even posted patches to make universe work this way. : There is a 'tinderbox' target, which is named so that when someone : says "gee, I wonder how to satisfy the tinderbox" they do not need : to read a wiki, blog, handbook, manpage, check IRC, news group : or mailing list archive to figure out, they can just run it and : get something that makes sense. 'Tinderbox' makes no sense to me because the tinderbox that's run only does one architecture. Your 'tindrebox' target does all the architectures, which doesn't make any sense to me. : Anyhow, I don't really care what's done so as long as there's a : top level target that does what I just committed, so if someone wants : to redo how I did what I did in order to get the exact same results : they can be my guest. : : I would hope that they have better things to do though. Why duplicate a bunch of code in the toplevel makefile and make it even more complicated than it already is? That way leads to long-term problems... Warner From des at des.no Thu Dec 4 08:50:31 2008 From: des at des.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Thu Dec 4 08:50:43 2008 Subject: svn commit: r185435 - in head: lib/libc/sys lib/libkvm share/man/man4 sys/compat/freebsd32 sys/kern sys/net sys/netinet sys/netinet6 sys/security/mac_bsdextended sys/sys usr.bin/cpuset usr.sbin/jai... In-Reply-To: <200811291432.mATEWE2a053742@svn.freebsd.org> (Bjoern A. Zeeb's message of "Sat, 29 Nov 2008 14:32:14 +0000 (UTC)") References: <200811291432.mATEWE2a053742@svn.freebsd.org> Message-ID: <86skp3yje2.fsf@ds4.des.no> "Bjoern A. Zeeb" writes: > Jails can have an unrestricted (no duplicate protection, etc.) name > in addition to the hostname. The jail name cannot be changed from > within a jail and is considered to be used for management purposes > or as audit-token in the future. Is there a specific reason why we allow duplicates? DES -- Dag-Erling Sm?rgrav - des@des.no From des at des.no Thu Dec 4 08:56:11 2008 From: des at des.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Thu Dec 4 08:56:23 2008 Subject: svn commit: r185499 - head In-Reply-To: <20081204.093642.778147376.imp@bsdimp.com> (M. Warner Losh's message of "Thu, 04 Dec 2008 09:36:42 -0700 (MST)") References: <20081201132554.GD27096@elvis.mu.org> <20081201.221040.-1350500631.imp@bsdimp.com> <20081204095756.GP27096@elvis.mu.org> <20081204.093642.778147376.imp@bsdimp.com> Message-ID: <86oczryj4l.fsf@ds4.des.no> "M. Warner Losh" writes: > 'Tinderbox' makes no sense to me because the tinderbox that's run only > does one architecture. No, it runs 'make buildworld' for every supported architecture, for an appropriate definition of "supported". This is exactly what 'make universe' does, but the tinderbox has a lot of additional functionality related to scheduling, reporting, updating the source tree, selecting which kernels to build, cleaning the object directory ('rm -rf /usr/obj' or its moral equivalent is much faster than 'make cleandir'), etc. None of this changes how the actual build happens, though. DES -- Dag-Erling Sm?rgrav - des@des.no From alfred at freebsd.org Thu Dec 4 09:08:54 2008 From: alfred at freebsd.org (Alfred Perlstein) Date: Thu Dec 4 09:09:06 2008 Subject: svn commit: r185499 - head In-Reply-To: <20081204.093642.778147376.imp@bsdimp.com> References: <20081201132554.GD27096@elvis.mu.org> <20081201.221040.-1350500631.imp@bsdimp.com> <20081204095756.GP27096@elvis.mu.org> <20081204.093642.778147376.imp@bsdimp.com> Message-ID: <20081204170853.GR27096@elvis.mu.org> * M. Warner Losh [081204 08:39] wrote: > : > > : > I think you ignored the discussions that said that 'universe' should > : > be modified to exit with an error when there was an error, but > : > shouldn't bail out EARLY. There were even patches to do this. > : > : Interesting, I didn't see them and they weren't committed. > : > : The owner/maintainer of universe hasn't really stepped up to > : provide anything and ask me "hey Alfred, would this be helpful?" > : and the owner/maintainer of tinderbox has not either. > : > : Mostly the two of them have told me "you do it, or shut up", so I > : did it. > > Except in public there were others involved that had also done it. That's great, and the patches I saw posted didn't work. > : > Based on that, why do something completely new and different? > : > : New and different? What? > : > : Maybe you can explain to me what's so earth shattering new and > : different about having a make target behave like most any other > : sane make target and have a name that is self-documenting? > > It invents a completely new target to do what the originator of > universe said was the right behavior for universe. bz had even posted > patches to make universe work this way. 1) New target? - Yes, even an alias target is good if the name is self-documenting. 2) 'tinderbox' is bz's target, except (no offense to bz) mine works. > : There is a 'tinderbox' target, which is named so that when someone > : says "gee, I wonder how to satisfy the tinderbox" they do not need > : to read a wiki, blog, handbook, manpage, check IRC, news group > : or mailing list archive to figure out, they can just run it and > : get something that makes sense. > > 'Tinderbox' makes no sense to me because the tinderbox that's run only > does one architecture. Your 'tindrebox' target does all the > architectures, which doesn't make any sense to me. Really? Which arch does tinderbox check? I saw all this stuff going out that said: TB --- 2007-10-04 16:25:01 - tinderbox 2.3 running on freebsd-stable.sentex.ca TB --- 2007-10-04 16:25:01 - starting RELENG_6 tinderbox run for sparc64/sparc64 TB --- 2007-10-04 16:25:01 - cleaning the object tree TB --- 2007-10-04 16:25:37 - checking out the source tree TB --- 2007-10-04 16:25:37 - cd /tinderbox/RELENG_6/sparc64/sparc64 TB --- 2007-10-04 16:25:37 - /usr/bin/cvs -f -R -q -d/home/ncvs update -Pd -rRELENG_6 src TB --- 2007-06-05 21:49:46 - tinderbox 2.3 running on freebsd-stable.sentex.ca TB --- 2007-06-05 21:49:46 - starting RELENG_6 tinderbox run for i386/pc98 TB --- 2007-06-05 21:49:46 - cleaning the object tree TB --- 2007-06-05 21:50:54 - checking out the source tree TB --- 2007-06-05 21:50:54 - cd /tinderbox/RELENG_6/i386/pc98 TB --- 2007-06-05 21:50:54 - /usr/bin/cvs -f -R -q -d/home/ncvs update -Pd -rREL ENG_6 src Maybe this is old? It looks like tinderbox requires more than just i386... Here's a more recent one... : On Tuesday 04 November 2008, FreeBSD Tinderbox wrote: : > TB --- 2008-11-04 18:31:04 - tinderbox 2.3 running on : > freebsd-current.sentex.ca TB --- 2008-11-04 18:31:04 - starting HEAD : > tinderbox run for powerpc/powerpc TB --- 2008-11-04 18:31:04 - cleaning the : > object tree : > TB --- 2008-11-04 18:31:29 - cvsupping the source tree : > TB --- 2008-11-04 18:31:29 - /usr/bin/csup -r 3 -g -L 1 -h localhost -s : > /tinderbox/HEAD/powerpc/powerpc/supfile TB --- 2008-11-04 18:31:37 - : > building world (CFLAGS=-O -pipe) : > TB --- 2008-11-04 18:31:37 - cd /src : > TB --- 2008-11-04 18:31:37 - /usr/bin/make -B buildworld Are you sure tinderbox is only i386? I also have some mails from DES saying stuff like: [[ DES ]] > It's not mine, and Poul-Hennning has clearly stated that he doesn't want > it changed. I *have* provided a build-testing system that notifies you > of any breakage, and repeatedly encouraged people to use it instead of > 'make universe'. > > If you don't want to wait for 'make universe' or the tinderbox to > finish, there are other, faster ways of testing other architectures. > For instance, to verify that your code does not break sun4v: > > $ make toolchain TARGET=3Dsun4v > > This builds a cross-toolchain; you only need to do it once. > > $ make buildenv TARGET=3Dsun4v > > This will start a shell with the environment set up for a cross-build. > > $ cd where/my/code/is/located > $ make obj && make depend && make > > You only need to do 'make obj' once, but you have to re-run 'make > depend' any time you add or remove a source file or an #include > directive. > > If you're working on the kernel: > > $ make kernel-toolchain TARGET=3Dsun4v > > Again, you only need to do this once. Furthermore, kernel-toolchain is > a subset of toolchain, so you don't need to do the former if you've > already done the latter. > > $ make buildkernel TARGET=3Dsun4v KERNCONF=3DGENERIC > > (you can specify a customized config file instead of GENERIC, but make > sure it's in /sys/sun4v/conf) > > If what you're working on doesn't affect any modules, specify > -DNO_MODULES to speed things up. If something breaks and you need to > run it again, specify -DNO_KERNELCLEAN, and -DNO_KERNELDEPEND if you > haven't added or removed any source files or #include directives or > changed the config file. > : Anyhow, I don't really care what's done so as long as there's a > : top level target that does what I just committed, so if someone wants > : to redo how I did what I did in order to get the exact same results > : they can be my guest. > : > : I would hope that they have better things to do though. > > Why duplicate a bunch of code in the toplevel makefile and make it > even more complicated than it already is? That way leads to long-term > problems... It's not duplicated, it leverages the universe target by having a few ifdefs. Something I was nervous enough doing because I wasn't sure what phk was going to say about that. Anyhow, if someone wants to unifdef (or wants me to do it) such that what I've done becomes the tinderbox target and the same stuff is leveraged by "universe" (error exit + summary of failures at the end). I'm more than happy to do so. -- - Alfred Perlstein From des at des.no Thu Dec 4 09:25:46 2008 From: des at des.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Thu Dec 4 09:25:57 2008 Subject: svn commit: r185499 - head In-Reply-To: <20081204163542.GQ27096@elvis.mu.org> (Alfred Perlstein's message of "Thu, 4 Dec 2008 08:35:42 -0800") References: <49338E98.7020104@freebsd.org> <863ah8rvcd.fsf@ds4.des.no> <20081201132554.GD27096@elvis.mu.org> <20081201.221040.-1350500631.imp@bsdimp.com> <20081204095756.GP27096@elvis.mu.org> <863ah4158t.fsf@ds4.des.no> <20081204163542.GQ27096@elvis.mu.org> Message-ID: <86k5afyhrb.fsf@ds4.des.no> Alfred Perlstein writes: > Really? So a person on a i386 platform that touches let's say > src/sys/proc.h will have quality checked via "make buildworld" > to the degree that they know it won't break all other platforms > too? You are trying to turn this into a developers vs. tinderbox issue. It's not. The kind of mistakes that break the tinderbox directly affect users and other developers. If your changes affect MD code or relies on the size or endianness of specific types, you should cross-build to an architecture with different register width and endianness. I wish I didn't have to point this out; it should be obvious to anyone. After all, it's been almost ten years since we added our first non-i386 platform (alpha). I created the tinderbox precisely because obrien@ got mad at me for repeatedly breaking the alpha build. Most bit-width issues can be caught by cross-building to amd64 if you're working on i386, and to i386 if you're working on amd64. However, the most common bit-width-related mistake is to assume that various types (long, size_t, time_t etc) are the same size as int, so you are far less likely to break i386 (where they are) when working on amd64 (where they aren't) than the reverse. Endianness issues will usually only become apparent when you *run* the code, but they're usually a matter of network vs host order, and will therefore show up on both i386 and amd64. The final class of problems is those that arise from the use of MD interfaces that are implemented only on i386 and amd64. These two platforms are sufficiently similar that code written for one usually compiles and runs on the other, but it may not compile and run on, say, powerpc or sparc64. For instance, certain atomic operations are not implemented on arm (or weren't, the last time I looked). Therefore, you are probably better off cross-building to powerpc (32-bit big-endian) when working on amd64 (64-bit little-endian), and to sparc64 (64-bit big-endian) when working on i386 (32-bit little-endian). Cross-building is easy. It is described in build(7), which every committer should read. If anything in that man page is unclear, feel free to ask me, or ru@ if I'm unavailable - and to update the man page once you've been enlightened. DES -- Dag-Erling Sm?rgrav - des@des.no From alfred at freebsd.org Thu Dec 4 10:08:38 2008 From: alfred at freebsd.org (Alfred Perlstein) Date: Thu Dec 4 10:08:50 2008 Subject: svn commit: r185499 - head In-Reply-To: <86k5afyhrb.fsf@ds4.des.no> References: <49338E98.7020104@freebsd.org> <863ah8rvcd.fsf@ds4.des.no> <20081201132554.GD27096@elvis.mu.org> <20081201.221040.-1350500631.imp@bsdimp.com> <20081204095756.GP27096@elvis.mu.org> <863ah4158t.fsf@ds4.des.no> <20081204163542.GQ27096@elvis.mu.org> <86k5afyhrb.fsf@ds4.des.no> Message-ID: <20081204180837.GS27096@elvis.mu.org> * Dag-Erling Sm??rgrav [081204 09:25] wrote: > Alfred Perlstein writes: > > Really? So a person on a i386 platform that touches let's say > > src/sys/proc.h will have quality checked via "make buildworld" > > to the degree that they know it won't break all other platforms > > too? > > You are trying to turn this into a developers vs. tinderbox issue. It's > not. The kind of mistakes that break the tinderbox directly affect > users and other developers. No, I'm trying to get a simple target that makes sense that will prevent people from breaking tinderbox. (failing that then turning tinderbox off because it's too complex) There's a lot below that I won't really comment on because I understand most of it and the parts I don't, I honestly don't care to! Here's something to consider: Lets just say it takes a developer about an hour or two to be "enlightened" as to a new system instead of just being told "hey run this one liner", you've just soaked up $number_of_committers * $enlightenment_time man hours. How many hours of enlightenment do we have versus code? That and, since the process requires "enlightenment", you've caused that developer to "page out" whatever they had in their head to work on, _every time they commit_. Soooooo frustrating. This adds up to frustration, mistakes and missed productivity. And that is what I am trying to address. And I'm done too! -Alfred > > If your changes affect MD code or relies on the size or endianness of > specific types, you should cross-build to an architecture with different > register width and endianness. I wish I didn't have to point this out; > it should be obvious to anyone. After all, it's been almost ten years > since we added our first non-i386 platform (alpha). I created the > tinderbox precisely because obrien@ got mad at me for repeatedly > breaking the alpha build. > > Most bit-width issues can be caught by cross-building to amd64 if you're > working on i386, and to i386 if you're working on amd64. However, the > most common bit-width-related mistake is to assume that various types > (long, size_t, time_t etc) are the same size as int, so you are far less > likely to break i386 (where they are) when working on amd64 (where they > aren't) than the reverse. > > Endianness issues will usually only become apparent when you *run* the > code, but they're usually a matter of network vs host order, and will > therefore show up on both i386 and amd64. > > The final class of problems is those that arise from the use of MD > interfaces that are implemented only on i386 and amd64. These two > platforms are sufficiently similar that code written for one usually > compiles and runs on the other, but it may not compile and run on, say, > powerpc or sparc64. For instance, certain atomic operations are not > implemented on arm (or weren't, the last time I looked). Therefore, you > are probably better off cross-building to powerpc (32-bit big-endian) > when working on amd64 (64-bit little-endian), and to sparc64 (64-bit > big-endian) when working on i386 (32-bit little-endian). > > Cross-building is easy. It is described in build(7), which every > committer should read. If anything in that man page is unclear, feel > free to ask me, or ru@ if I'm unavailable - and to update the man page > once you've been enlightened. > > DES > -- > Dag-Erling Sm??rgrav - des@des.no -- - Alfred Perlstein From des at des.no Thu Dec 4 10:20:25 2008 From: des at des.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Thu Dec 4 10:20:36 2008 Subject: svn commit: r185499 - head In-Reply-To: <20081204180837.GS27096@elvis.mu.org> (Alfred Perlstein's message of "Thu, 4 Dec 2008 10:08:37 -0800") References: <49338E98.7020104@freebsd.org> <863ah8rvcd.fsf@ds4.des.no> <20081201132554.GD27096@elvis.mu.org> <20081201.221040.-1350500631.imp@bsdimp.com> <20081204095756.GP27096@elvis.mu.org> <863ah4158t.fsf@ds4.des.no> <20081204163542.GQ27096@elvis.mu.org> <86k5afyhrb.fsf@ds4.des.no> <20081204180837.GS27096@elvis.mu.org> Message-ID: <86vdtzx0ns.fsf@ds4.des.no> Alfred Perlstein writes: > No, I'm trying to get a simple target that makes sense that will > prevent people from breaking tinderbox. (failing that then turning > tinderbox off because it's too complex) Perhaps if you tell me what it is about the tinderbox that you don't understand, I could help you understand it. > Lets just say it takes a developer about an hour or two to be > "enlightened" as to a new system instead of just being told "hey > run this one liner", you've just soaked up $number_of_committers * > $enlightenment_time man hours. What is new about the build system? And why do you think it's a bad idea for committers to understand how it works? Do you really want to run an operating system written by people who do not understand how it is built? > That and, since the process requires "enlightenment", you've caused > that developer to "page out" whatever they had in their head to work > on, _every time they commit_. Soooooo frustrating. I wonder - does anybody else than you have that problem? Don't you think that once people understand how the build system works, they would be able to do this without much thought? As a bonus, they will also know how to rebuild just the parts they modified, instead of the entire tree, shaving hours off the edit-compile-test cycle. > And I'm done too! But in the process, you managed to piss off just about everybody who had an interest in the matter. DES -- Dag-Erling Sm?rgrav - des@des.no From bzeeb-lists at lists.zabbadoz.net Thu Dec 4 10:50:08 2008 From: bzeeb-lists at lists.zabbadoz.net (Bjoern A. Zeeb) Date: Thu Dec 4 10:50:14 2008 Subject: svn commit: r185435 - in head: lib/libc/sys lib/libkvm share/man/man4 sys/compat/freebsd32 sys/kern sys/net sys/netinet sys/netinet6 sys/security/mac_bsdextended sys/sys usr.bin/cpuset usr.sbin/jai... In-Reply-To: <86skp3yje2.fsf@ds4.des.no> References: <200811291432.mATEWE2a053742@svn.freebsd.org> <86skp3yje2.fsf@ds4.des.no> Message-ID: <20081204184332.C80401@maildrop.int.zabbadoz.net> On Thu, 4 Dec 2008, Dag-Erling Sm?rgrav wrote: > "Bjoern A. Zeeb" writes: >> Jails can have an unrestricted (no duplicate protection, etc.) name >> in addition to the hostname. The jail name cannot be changed from >> within a jail and is considered to be used for management purposes >> or as audit-token in the future. > > Is there a specific reason why we allow duplicates? Yes, so that people have a choice. You would have to take into account "DYING" jails with possibly duplicate names anyway. And it's a purely administrative name (cannot be changed from within the jail) so it's up to the administrator to have 2 "Customer Webserver" jails or a "Customer Webserver Tin" and a "Customer Webserver Box". BTW. in case people wonder how to set it (atm.) from rc.conf, you can use jail__flags. /bz -- Bjoern A. Zeeb Stop bit received. Insert coin for new game. From alfred at freebsd.org Thu Dec 4 11:48:14 2008 From: alfred at freebsd.org (Alfred Perlstein) Date: Thu Dec 4 11:48:32 2008 Subject: svn commit: r185499 - head In-Reply-To: <86vdtzx0ns.fsf@ds4.des.no> References: <49338E98.7020104@freebsd.org> <863ah8rvcd.fsf@ds4.des.no> <20081201132554.GD27096@elvis.mu.org> <20081201.221040.-1350500631.imp@bsdimp.com> <20081204095756.GP27096@elvis.mu.org> <863ah4158t.fsf@ds4.des.no> <20081204163542.GQ27096@elvis.mu.org> <86k5afyhrb.fsf@ds4.des.no> <20081204180837.GS27096@elvis.mu.org> <86vdtzx0ns.fsf@ds4.des.no> Message-ID: <20081204194813.GT27096@elvis.mu.org> * Dag-Erling Sm??rgrav [081204 10:21] wrote: > Alfred Perlstein writes: > > No, I'm trying to get a simple target that makes sense that will > > prevent people from breaking tinderbox. (failing that then turning > > tinderbox off because it's too complex) > > Perhaps if you tell me what it is about the tinderbox that you don't > understand, I could help you understand it. I think I have all I need right now. I was getting confused because I was being told by multiple confused developers that "tinderbox" was different things because it's complicated. We should probably review all these committers and paddle them or yank their commit bits for being stupid or something. > > Lets just say it takes a developer about an hour or two to be > > "enlightened" as to a new system instead of just being told "hey > > run this one liner", you've just soaked up $number_of_committers * > > $enlightenment_time man hours. > > What is new about the build system? And why do you think it's a bad > idea for committers to understand how it works? Do you really want to > run an operating system written by people who do not understand how it > is built? It should not be a requirement that a developer need to know all this stuff. And by stuff I mean "how to roll my own tinderbox". I do find it amusing that you're asserting that _I'm_ saying this when I'm the only one it appears that could fix this target. :) I'm more concerned about developing anything where I have to work with people that don't take input on issues, yell at people for not understanding complex systems and winge for god knows how long about a 20 line patch just because it wasn't exactly "how they would have done it"... WHEN IN FACT THEY REFUSED AND WOULD NOT HAVE "DONE IT". > > That and, since the process requires "enlightenment", you've caused > > that developer to "page out" whatever they had in their head to work > > on, _every time they commit_. Soooooo frustrating. > > I wonder - does anybody else than you have that problem? Don't you > think that once people understand how the build system works, they would > be able to do this without much thought? As a bonus, they will also > know how to rebuild just the parts they modified, instead of the entire > tree, shaving hours off the edit-compile-test cycle. Yes, that's great, but it should be optional. We shouldn't beat things into people. > > And I'm done too! > > But in the process, you managed to piss off just about everybody who had > an interest in the matter. That was your choice. So far I'm not aware of anyone that's quit freebsd in the past few years due to anything I've done. (really done now) :) -- - Alfred Perlstein From gnn at FreeBSD.org Thu Dec 4 12:32:53 2008 From: gnn at FreeBSD.org (George V. Neville-Neil) Date: Thu Dec 4 12:32:59 2008 Subject: svn commit: r185620 - head/sys/dev/cxgb/common Message-ID: <200812042032.mB4KWrBG033880@svn.freebsd.org> Author: gnn Date: Thu Dec 4 20:32:53 2008 New Revision: 185620 URL: http://svn.freebsd.org/changeset/base/185620 Log: Fix a bug with the ael1006 PHY. The bug shows up as persistent but incomplete packet loss, of between 10-30%. The fix is to put the PHY into and take it out of local loopback mode when resetting the interface. Obtained from: Chelsio Inc. MFC after: 3 days Modified: head/sys/dev/cxgb/common/cxgb_ael1002.c Modified: head/sys/dev/cxgb/common/cxgb_ael1002.c ============================================================================== --- head/sys/dev/cxgb/common/cxgb_ael1002.c Thu Dec 4 20:04:25 2008 (r185619) +++ head/sys/dev/cxgb/common/cxgb_ael1002.c Thu Dec 4 20:32:53 2008 (r185620) @@ -205,6 +205,16 @@ static int ael1006_reset(struct cphy *ph t3_write_reg(phy->adapter, A_T3DBG_GPIO_EN, gpio_out); msleep(125); t3_phy_reset(phy, MDIO_DEV_PMA_PMD, wait); + + /* Phy loopback work around for ael1006 */ + /* Soft reset phy by toggling loopback */ + msleep(125); + /* Put phy into local loopback */ + t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, MII_BMCR, 0, 1); + msleep(125); + /* Take phy out of local loopback */ + t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, MII_BMCR, 1, 0); + return 0; } From jhb at freebsd.org Thu Dec 4 13:24:47 2008 From: jhb at freebsd.org (John Baldwin) Date: Thu Dec 4 13:24:54 2008 Subject: svn commit: r185589 - head/sys/compat/freebsd32 In-Reply-To: <20081204111041.GB2038@deviant.kiev.zoral.com.ua> References: <200812031845.mB3IjcZC098534@svn.freebsd.org> <200812031803.03650.jhb@freebsd.org> <20081204111041.GB2038@deviant.kiev.zoral.com.ua> Message-ID: <200812041336.40739.jhb@freebsd.org> On Thursday 04 December 2008 06:10:41 am Kostik Belousov wrote: > On Wed, Dec 03, 2008 at 06:03:03PM -0500, John Baldwin wrote: > > On Wednesday 03 December 2008 04:43:06 pm Kostik Belousov wrote: > > > On Wed, Dec 03, 2008 at 06:45:38PM +0000, John Baldwin wrote: > > > > Author: jhb > > > > Date: Wed Dec 3 18:45:38 2008 > > > > New Revision: 185589 > > > > URL: http://svn.freebsd.org/changeset/base/185589 > > > > > > > > Log: > > > > When unloading a 32-bit system call module, restore the sysent vector in > > > > the 32-bit system call table instead of the main system call table. > > > > > > > > Modified: > > > > head/sys/compat/freebsd32/freebsd32_misc.c > > > > > > > The module build glue is not committed into the svn, isn't it ? > > > > Err, it is. It's in freebsd32_util.h (SYSCALL32_MODULE, etc.). > > I saw that, I would call it initialization glue. I mean that freebsd32 > cannot be _load_ as module. No, this is about having other modules contain 32-bit system calls. For example, I have patches to enable 32-bit compat system calls for VFS_AIO that live in aio.ko. -- John Baldwin From yanefbsd at gmail.com Thu Dec 4 13:35:09 2008 From: yanefbsd at gmail.com (Garrett Cooper) Date: Thu Dec 4 13:35:15 2008 Subject: svn commit: r185499 - head In-Reply-To: <20081204194813.GT27096@elvis.mu.org> References: <49338E98.7020104@freebsd.org> <20081201132554.GD27096@elvis.mu.org> <20081201.221040.-1350500631.imp@bsdimp.com> <20081204095756.GP27096@elvis.mu.org> <863ah4158t.fsf@ds4.des.no> <20081204163542.GQ27096@elvis.mu.org> <86k5afyhrb.fsf@ds4.des.no> <20081204180837.GS27096@elvis.mu.org> <86vdtzx0ns.fsf@ds4.des.no> <20081204194813.GT27096@elvis.mu.org> Message-ID: <7d6fde3d0812041335u3134209at5a5f792e56290399@mail.gmail.com> On Thu, Dec 4, 2008 at 11:48 AM, Alfred Perlstein wrote: > * Dag-Erling Sm??rgrav [081204 10:21] wrote: >> Alfred Perlstein writes: >> > No, I'm trying to get a simple target that makes sense that will >> > prevent people from breaking tinderbox. (failing that then turning >> > tinderbox off because it's too complex) >> >> Perhaps if you tell me what it is about the tinderbox that you don't >> understand, I could help you understand it. > > I think I have all I need right now. I was getting confused > because I was being told by multiple confused developers that > "tinderbox" was different things because it's complicated. > > We should probably review all these committers and paddle them > or yank their commit bits for being stupid or something. > >> > Lets just say it takes a developer about an hour or two to be >> > "enlightened" as to a new system instead of just being told "hey >> > run this one liner", you've just soaked up $number_of_committers * >> > $enlightenment_time man hours. >> >> What is new about the build system? And why do you think it's a bad >> idea for committers to understand how it works? Do you really want to >> run an operating system written by people who do not understand how it >> is built? > > It should not be a requirement that a developer need to know > all this stuff. And by stuff I mean "how to roll my own tinderbox". > > I do find it amusing that you're asserting that _I'm_ saying this > when I'm the only one it appears that could fix this target. :) > > I'm more concerned about developing anything where I have to work > with people that don't take input on issues, yell at people for not > understanding complex systems and winge for god knows how long about > a 20 line patch just because it wasn't exactly "how they would have > done it"... WHEN IN FACT THEY REFUSED AND WOULD NOT HAVE "DONE IT". > >> > That and, since the process requires "enlightenment", you've caused >> > that developer to "page out" whatever they had in their head to work >> > on, _every time they commit_. Soooooo frustrating. >> >> I wonder - does anybody else than you have that problem? Don't you >> think that once people understand how the build system works, they would >> be able to do this without much thought? As a bonus, they will also >> know how to rebuild just the parts they modified, instead of the entire >> tree, shaving hours off the edit-compile-test cycle. > > Yes, that's great, but it should be optional. We shouldn't beat > things into people. > >> > And I'm done too! >> >> But in the process, you managed to piss off just about everybody who had >> an interest in the matter. > > That was your choice. So far I'm not aware of anyone that's quit > freebsd in the past few years due to anything I've done. > > (really done now) :) > > -- > - Alfred Perlstein Don't mean to stir up the hornet's nest any further, but I wanted to help constructively with this `issue': 1. I can see the logic behind what Alfred's doing, and I agree with it 100% with the following `terms': a. For generic kernel / userland codebase changes, a `tinderbox' target like Alfred put in, would be best for determining issues over the entire system. b. For codebase changes that are target/arch specific or contain target-specific driver code (for instance a MIPS specific net driver), it wouldn't really make sense to run Alfred's tinderbox for everything. c. For commit and after a merge, Alfred's `tinderbox' target should be executed. 2. I honestly think that the tinderbox target should be renamed to tinderfarm though, because I see the argument that DES is noting, mostly because of continuity. I do think that keeping a tinderfarm build target within the make system would be beneficial though, as it would allow the tinderbox Perl script to shrink and DES and I would be able to work out an agreement for making a tinderbox (/ tinderfarm?) script to be used as an overall functional and regression testing framework. 3. Devs understanding how the build system works to the extent where they can dig up manpages and become more proficient if necessary is crucial. I've seen some very negative effects of using wrapper scripts to execute builds, and I'd rather we not go this route, if at all possible. However, having a more abbreviated way of expressing builds is nice though, because most folks maintain this logic in wrapper scripts in local workspaces, and this information quickly gets out of date as time progresses :). 3. As for the issue with make universe, isn't there an equivalent to :: in pmake like there is in gmake? Targets can fail to build, but at least it'll continue moving on, and if the output messages are proper, one can note: `blah target failed' *shrugs*, and keep on moving on. Most devs should be using a break on build error make mode, whereas overall tinderfarm executions on the freebsd project servers shouldn't fail, IMHO. Thoughts? -Garrett From imp at FreeBSD.org Thu Dec 4 20:43:26 2008 From: imp at FreeBSD.org (Warner Losh) Date: Thu Dec 4 20:43:38 2008 Subject: svn commit: r185622 - head/sys/dev/pccbb Message-ID: <200812050443.mB54hPs8043288@svn.freebsd.org> Author: imp Date: Fri Dec 5 04:43:25 2008 New Revision: 185622 URL: http://svn.freebsd.org/changeset/base/185622 Log: Implement a method described in NetBSD PR 36652 for coping with the BAD VCC bit. Modified: head/sys/dev/pccbb/pccbb.c Modified: head/sys/dev/pccbb/pccbb.c ============================================================================== --- head/sys/dev/pccbb/pccbb.c Fri Dec 5 00:01:34 2008 (r185621) +++ head/sys/dev/pccbb/pccbb.c Fri Dec 5 04:43:25 2008 (r185622) @@ -837,7 +837,18 @@ cbb_power(device_t brdev, int volts) } if (status & CBB_STATE_BAD_VCC_REQ) { device_printf(sc->dev, "Bad Vcc requested\n"); - /* XXX Do we want to do something to mitigate things here? */ + /* + * Turn off the power, and try again. Retrigger other + * active interrupts via force register. From NetBSD + * PR 36652, coded by me to description there. + */ + sock_ctrl &= ~CBB_SOCKET_CTRL_VCCMASK; + sock_ctrl &= ~CBB_SOCKET_CTRL_VPPMASK; + cbb_set(sc, CBB_SOCKET_CONTROL, sock_ctrl); + status &= ~CBB_STATE_BAD_VCC_REQ; + status &= ~CBB_STATE_DATA_LOST; + status |= CBB_FORCE_CV_TEST; + cbb_set(sc, CBB_SOCKET_FORCE, status); goto done; } if (sc->chipset == CB_TOPIC97) { From imp at FreeBSD.org Thu Dec 4 20:46:26 2008 From: imp at FreeBSD.org (Warner Losh) Date: Thu Dec 4 20:46:33 2008 Subject: svn commit: r185623 - head/sys/dev/pccbb Message-ID: <200812050446.mB54kQb0043401@svn.freebsd.org> Author: imp Date: Fri Dec 5 04:46:26 2008 New Revision: 185623 URL: http://svn.freebsd.org/changeset/base/185623 Log: Augment comments, and move things around a smidge. Modified: head/sys/dev/pccbb/pccbb.c Modified: head/sys/dev/pccbb/pccbb.c ============================================================================== --- head/sys/dev/pccbb/pccbb.c Fri Dec 5 04:43:25 2008 (r185622) +++ head/sys/dev/pccbb/pccbb.c Fri Dec 5 04:46:26 2008 (r185623) @@ -946,32 +946,32 @@ cbb_cardbus_reset(device_t brdev, device /* * Asserting reset for 20ms is necessary for most bridges. For some - * reason, the Ricoh RF5C47x bridges need it asserted for 400ms. + * reason, the Ricoh RF5C47x bridges need it asserted for 400ms. The + * root cause of this is unknown, and NetBSD does the same thing. */ delay = sc->chipset == CB_RF5C47X ? 400 : 20; PCI_MASK_CONFIG(brdev, CBBR_BRIDGECTRL, |CBBM_BRIDGECTRL_RESET, 2); pause("cbbP3", hz * delay / 1000); /* - * If a card exists and we're turning it on, take it out of reset. + * If a card exists and we're turning it on, take it out of reset. + * After clearing reset, wait up to 1.1s for the first configuration + * register (vendor/product) configuration register of device 0.0 to + * become != 0xffffffff. The PCMCIA PC Card Host System Specification + * says that when powering up the card, the PCI Spec v2.1 must be + * followed. In PCI spec v2.2 Table 4-6, Trhfa (Reset High to first + * Config Access) is at most 2^25 clocks, or just over 1s. Section + * 2.2.1 states any card not ready to participate in bus transactions + * must tristate its outputs. Therefore, any access to its + * configuration registers must be ignored. In that state, the config + * reg will read 0xffffffff. Section 6.2.1 states a vendor id of + * 0xffff is invalid, so this can never match a real card. Print a + * warning if it never returns a real id. The PCMCIA PC Card + * Electrical Spec Section 5.2.7.1 implies only device 0 is present on + * a cardbus bus, so that's the only register we check here. */ if (on && CBB_CARD_PRESENT(cbb_get(sc, CBB_SOCKET_STATE))) { /* - * After clearing reset, wait up to 1.1s for the first - * configuration register (vendor/product) configuration - * register of device 0.0 to become != 0xffffffff. The PCMCIA - * PC Card Host System Specification says that when powering - * up the card, the PCI Spec v2.1 must be followed. In PCI - * spec v2.2 Table 4-6, Trhfa (Reset High to first Config - * Access) is at most 2^25 clocks, or just over 1s. Section - * 2.2.1 states any card not ready to participate in bus - * transactions must tristate its outputs. Therefore, any - * access to its configuration registers must be ignored. In - * that state, the config reg will read 0xffffffff. Section - * 6.2.1 states a vendor id of 0xffff is invalid, so this can - * never match a real card. Print a warning if it never - * returns a real id. The PCMCIA PC Card Electrical Spec - * Section 5.2.7.1 implies only device 0. */ PCI_MASK_CONFIG(brdev, CBBR_BRIDGECTRL, &~CBBM_BRIDGECTRL_RESET, 2); From imp at FreeBSD.org Thu Dec 4 20:48:04 2008 From: imp at FreeBSD.org (Warner Losh) Date: Thu Dec 4 20:48:16 2008 Subject: svn commit: r185624 - head/sys/dev/pccbb Message-ID: <200812050448.mB54m4eL043465@svn.freebsd.org> Author: imp Date: Fri Dec 5 04:48:04 2008 New Revision: 185624 URL: http://svn.freebsd.org/changeset/base/185624 Log: Minor style nit. Modified: head/sys/dev/pccbb/pccbb.c Modified: head/sys/dev/pccbb/pccbb.c ============================================================================== --- head/sys/dev/pccbb/pccbb.c Fri Dec 5 04:46:26 2008 (r185623) +++ head/sys/dev/pccbb/pccbb.c Fri Dec 5 04:48:04 2008 (r185624) @@ -1045,8 +1045,8 @@ cbb_cardbus_mem_open(device_t brdev, int return (EINVAL); } - basereg = win*8 + CBBR_MEMBASE0; - limitreg = win*8 + CBBR_MEMLIMIT0; + basereg = win * 8 + CBBR_MEMBASE0; + limitreg = win * 8 + CBBR_MEMLIMIT0; pci_write_config(brdev, basereg, start, 4); pci_write_config(brdev, limitreg, end, 4); From imp at FreeBSD.org Thu Dec 4 21:20:08 2008 From: imp at FreeBSD.org (Warner Losh) Date: Thu Dec 4 21:20:21 2008 Subject: svn commit: r185625 - head/sys/dev/pccbb Message-ID: <200812050520.mB55K8kS044139@svn.freebsd.org> Author: imp Date: Fri Dec 5 05:20:08 2008 New Revision: 185625 URL: http://svn.freebsd.org/changeset/base/185625 Log: Move to using filter for the change interrupts. Also rework the power interrupt code to be more robust. I've been running these changes for over a year... With these changes, I don't see the ath card going into reset like the code in the tree. Modified: head/sys/dev/pccbb/pccbb.c head/sys/dev/pccbb/pccbb_pci.c head/sys/dev/pccbb/pccbbvar.h Modified: head/sys/dev/pccbb/pccbb.c ============================================================================== --- head/sys/dev/pccbb/pccbb.c Fri Dec 5 04:48:04 2008 (r185624) +++ head/sys/dev/pccbb/pccbb.c Fri Dec 5 05:20:08 2008 (r185625) @@ -344,7 +344,7 @@ cbb_detach(device_t brdev) sc->flags |= CBB_KTHREAD_DONE; while (sc->flags & CBB_KTHREAD_RUNNING) { DEVPRINTF((sc->dev, "Waiting for thread to die\n")); - cv_broadcast(&sc->cv); + wakeup(&sc->intrhand); msleep(sc->event_thread, &sc->mtx, PWAIT, "cbbun", 0); } mtx_unlock(&sc->mtx); @@ -353,8 +353,6 @@ cbb_detach(device_t brdev) bus_release_resource(brdev, SYS_RES_MEMORY, CBBR_SOCKBASE, sc->base_res); mtx_destroy(&sc->mtx); - cv_destroy(&sc->cv); - cv_destroy(&sc->powercv); return (0); } @@ -435,11 +433,8 @@ cbb_driver_added(device_t brdev, driver_ } free(devlist, M_TEMP); - if (wake > 0) { - mtx_lock(&sc->mtx); - cv_signal(&sc->cv); - mtx_unlock(&sc->mtx); - } + if (wake > 0) + wakeup(&sc->intrhand); } void @@ -519,12 +514,12 @@ cbb_event_thread(void *arg) * a chance to run. */ mtx_lock(&sc->mtx); - cbb_setb(sc, CBB_SOCKET_MASK, CBB_SOCKET_MASK_CD); - cv_wait(&sc->cv, &sc->mtx); + cbb_setb(sc, CBB_SOCKET_MASK, CBB_SOCKET_MASK_CD | CBB_SOCKET_MASK_CSTS); + msleep(&sc->intrhand, &sc->mtx, PZERO, "-", 0); err = 0; while (err != EWOULDBLOCK && (sc->flags & CBB_KTHREAD_DONE) == 0) - err = cv_timedwait(&sc->cv, &sc->mtx, hz / 4); + err = msleep(&sc->intrhand, &sc->mtx, PZERO, "-", hz / 5); } DEVPRINTF((sc->dev, "Thread terminating\n")); sc->flags &= ~CBB_KTHREAD_RUNNING; @@ -800,7 +795,7 @@ cbb_power(device_t brdev, int volts) sane = 10; while (!(cbb_get(sc, CBB_SOCKET_STATE) & CBB_STATE_POWER_CYCLE) && cnt == sc->powerintr && sane-- > 0) - cv_timedwait(&sc->powercv, &sc->mtx, hz / 20); + msleep(&sc->powerintr, &sc->mtx, PZERO, "-", hz / 20); mtx_unlock(&sc->mtx); /* * The TOPIC95B requires a little bit extra time to get @@ -1575,9 +1570,7 @@ cbb_resume(device_t self) cbb_setb(sc, CBB_SOCKET_MASK, CBB_SOCKET_MASK_CD); /* Signal the thread to wakeup. */ - mtx_lock(&sc->mtx); - cv_signal(&sc->cv); - mtx_unlock(&sc->mtx); + wakeup(&sc->intrhand); error = bus_generic_resume(self); Modified: head/sys/dev/pccbb/pccbb_pci.c ============================================================================== --- head/sys/dev/pccbb/pccbb_pci.c Fri Dec 5 04:48:04 2008 (r185624) +++ head/sys/dev/pccbb/pccbb_pci.c Fri Dec 5 05:20:08 2008 (r185625) @@ -117,7 +117,7 @@ __FBSDID("$FreeBSD$"); pci_read_config(DEV, REG, SIZE) MASK1) MASK2, SIZE) static void cbb_chipinit(struct cbb_softc *sc); -static void cbb_pci_intr(void *arg); +static int cbb_pci_filt(void *arg); static struct yenta_chipinfo { uint32_t yc_id; @@ -313,8 +313,6 @@ cbb_pci_attach(device_t brdev) parent = device_get_parent(brdev); mtx_init(&sc->mtx, device_get_nameunit(brdev), "cbb", MTX_DEF); - cv_init(&sc->cv, "cbb cv"); - cv_init(&sc->powercv, "cbb cv"); sc->chipset = cbb_chipset(pci_get_devid(brdev), NULL); sc->dev = brdev; sc->cbdev = NULL; @@ -332,7 +330,6 @@ cbb_pci_attach(device_t brdev) if (!sc->base_res) { device_printf(brdev, "Could not map register memory\n"); mtx_destroy(&sc->mtx); - cv_destroy(&sc->cv); return (ENOMEM); } else { DEVPRINTF((brdev, "Found memory at %08lx\n", @@ -416,7 +413,7 @@ cbb_pci_attach(device_t brdev) } if (bus_setup_intr(brdev, sc->irq_res, INTR_TYPE_AV | INTR_MPSAFE, - NULL, cbb_pci_intr, sc, &sc->intrhand)) { + cbb_pci_filt, NULL, sc, &sc->intrhand)) { device_printf(brdev, "couldn't establish interrupt\n"); goto err; } @@ -451,7 +448,6 @@ err: sc->base_res); } mtx_destroy(&sc->mtx); - cv_destroy(&sc->cv); return (ENOMEM); } @@ -686,11 +682,13 @@ cbb_pci_shutdown(device_t brdev) return (0); } -static void -cbb_pci_intr(void *arg) +#define DELTA (CBB_SOCKET_MASK_CD) +static int +cbb_pci_filt(void *arg) { struct cbb_softc *sc = arg; uint32_t sockevent; + int retval = FILTER_STRAY; /* * Read the socket event. Sometimes, the theory goes, the PCI @@ -705,9 +703,6 @@ cbb_pci_intr(void *arg) */ sockevent = cbb_get(sc, CBB_SOCKET_EVENT); if (sockevent != 0 && (sockevent & ~CBB_SOCKET_EVENT_VALID_MASK) == 0) { - /* ack the interrupt */ - cbb_set(sc, CBB_SOCKET_EVENT, sockevent); - /* * If anything has happened to the socket, we assume that * the card is no longer OK, and we shouldn't call its @@ -721,24 +716,24 @@ cbb_pci_intr(void *arg) * of the pccard software used a similar trick and achieved * excellent results. */ - if (sockevent & CBB_SOCKET_EVENT_CD) { - mtx_lock(&sc->mtx); - cbb_clrb(sc, CBB_SOCKET_MASK, CBB_SOCKET_MASK_CD); + if (sockevent & DELTA) { + cbb_clrb(sc, CBB_SOCKET_MASK, DELTA); + cbb_set(sc, CBB_SOCKET_EVENT, DELTA); sc->cardok = 0; cbb_disable_func_intr(sc); - cv_signal(&sc->cv); - mtx_unlock(&sc->mtx); + wakeup(&sc->intrhand); } /* * If we get a power interrupt, wakeup anybody that might * be waiting for one. */ if (sockevent & CBB_SOCKET_EVENT_POWER) { - mtx_lock(&sc->mtx); + cbb_clrb(sc, CBB_SOCKET_MASK, CBB_SOCKET_EVENT_POWER); + cbb_set(sc, CBB_SOCKET_EVENT, CBB_SOCKET_EVENT_POWER); sc->powerintr++; - cv_signal(&sc->powercv); - mtx_unlock(&sc->mtx); + wakeup((void *)&sc->powerintr); } + retval = FILTER_HANDLED; } /* * Some chips also require us to read the old ExCA registe for @@ -753,6 +748,7 @@ cbb_pci_intr(void *arg) * the event independent of the CBB_SOCKET_EVENT_CD above. */ exca_getb(&sc->exca[0], EXCA_CSC); + return retval; } /************************************************************************/ Modified: head/sys/dev/pccbb/pccbbvar.h ============================================================================== --- head/sys/dev/pccbb/pccbbvar.h Fri Dec 5 04:48:04 2008 (r185624) +++ head/sys/dev/pccbb/pccbbvar.h Fri Dec 5 05:20:08 2008 (r185625) @@ -67,8 +67,6 @@ struct cbb_softc { unsigned int secbus; unsigned int subbus; struct mtx mtx; - struct cv cv; - struct cv powercv; int cardok; u_int32_t flags; #define CBB_16BIT_CARD 0x20000000 @@ -89,7 +87,7 @@ struct cbb_softc { device_t cbdev; struct proc *event_thread; void (*chipinit)(struct cbb_softc *); - volatile int powerintr; + int powerintr; }; /* result of detect_card */ From des at des.no Fri Dec 5 01:13:26 2008 From: des at des.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Fri Dec 5 01:13:38 2008 Subject: svn commit: r185499 - head In-Reply-To: <7d6fde3d0812041335u3134209at5a5f792e56290399@mail.gmail.com> (Garrett Cooper's message of "Thu, 4 Dec 2008 13:35:08 -0800") References: <49338E98.7020104@freebsd.org> <20081201132554.GD27096@elvis.mu.org> <20081201.221040.-1350500631.imp@bsdimp.com> <20081204095756.GP27096@elvis.mu.org> <863ah4158t.fsf@ds4.des.no> <20081204163542.GQ27096@elvis.mu.org> <86k5afyhrb.fsf@ds4.des.no> <20081204180837.GS27096@elvis.mu.org> <86vdtzx0ns.fsf@ds4.des.no> <20081204194813.GT27096@elvis.mu.org> <7d6fde3d0812041335u3134209at5a5f792e56290399@mail.gmail.com> Message-ID: <86iqpzhtmz.fsf@ds4.des.no> "Garrett Cooper" writes: > [...] I honestly think that the tinderbox target should be renamed to > tinderfarm [...] Bikeshed. There is already a 'universe' target that does everything Alfred wants except exit 1 on error. At least one working patch was put forward (by bz@) to make it do that, and phk@ agreed that it was a sensible thing to do. There is no need for a new target, and if there were, calling it tinderwhatever would be misleading at best. > [...] I do think that keeping a tinderfarm build target within the > make system would be beneficial though, as it would allow the > tinderbox Perl script to shrink [...] No, it wouldn't. > 3. As for the issue with make universe, isn't there an equivalent to > :: in pmake like there is in gmake? Targets can fail to build, but at > least it'll continue moving on, and if the output messages are proper, > one can note: `blah target failed' *shrugs*, and keep on moving on. This is a non-issue; "continue moving on" is how 'make universe' has always worked, and I added 'blah target failed' a week ago. DES -- Dag-Erling Sm?rgrav - des@des.no From kib at FreeBSD.org Fri Dec 5 03:34:36 2008 From: kib at FreeBSD.org (Konstantin Belousov) Date: Fri Dec 5 03:34:48 2008 Subject: svn commit: r185634 - head/sys/amd64/amd64 Message-ID: <200812051134.mB5BYaXC053533@svn.freebsd.org> Author: kib Date: Fri Dec 5 11:34:36 2008 New Revision: 185634 URL: http://svn.freebsd.org/changeset/base/185634 Log: Improve db_backtrace() for compat ia32 on amd64. 32bit image enters the kernel via Xint0x80_syscall(). Submitted by: dchagin MFC after: 1 week Modified: head/sys/amd64/amd64/db_trace.c Modified: head/sys/amd64/amd64/db_trace.c ============================================================================== --- head/sys/amd64/amd64/db_trace.c Fri Dec 5 07:47:03 2008 (r185633) +++ head/sys/amd64/amd64/db_trace.c Fri Dec 5 11:34:36 2008 (r185634) @@ -27,6 +27,8 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_compat.h" + #include #include #include @@ -318,6 +320,10 @@ db_nextframe(struct amd64_frame **fp, db frame_type = INTERRUPT; else if (strcmp(name, "Xfast_syscall") == 0) frame_type = SYSCALL; +#ifdef COMPAT_IA32 + else if (strcmp(name, "Xint0x80_syscall") == 0) + frame_type = SYSCALL; +#endif /* XXX: These are interrupts with trap frames. */ else if (strcmp(name, "Xtimerint") == 0 || strcmp(name, "Xcpustop") == 0 || From jhb at FreeBSD.org Fri Dec 5 05:40:25 2008 From: jhb at FreeBSD.org (John Baldwin) Date: Fri Dec 5 05:40:32 2008 Subject: svn commit: r185635 - in head/sys: kern sys Message-ID: <200812051340.mB5DePgX055897@svn.freebsd.org> Author: jhb Date: Fri Dec 5 13:40:25 2008 New Revision: 185635 URL: http://svn.freebsd.org/changeset/base/185635 Log: - Invoke MOD_QUIESCE on all modules in a linker file (kld) before unloading any modules. As a result, if any module veto's an unload request via MOD_QUIESCE, the entire set of modules for that linker file will remain loaded and active now rather than leaving the kld in a weird state where some modules are loaded and some are unloaded. - This also moves the logic for handling the "forced" unload flag out of kern_module.c and into kern_linker.c which is a bit cleaner. - Add a module_name() routine that returns the name of a module and use that instead of printing pointer values in debug messages when a module fails MOD_QUIESCE or MOD_UNLOAD. MFC after: 1 month Modified: head/sys/kern/kern_linker.c head/sys/kern/kern_module.c head/sys/sys/module.h Modified: head/sys/kern/kern_linker.c ============================================================================== --- head/sys/kern/kern_linker.c Fri Dec 5 11:34:36 2008 (r185634) +++ head/sys/kern/kern_linker.c Fri Dec 5 13:40:25 2008 (r185635) @@ -587,7 +587,30 @@ linker_file_unload(linker_file_t file, i " informing modules\n")); /* - * Inform any modules associated with this file. + * Quiesce all the modules to give them a chance to veto the unload. + */ + MOD_SLOCK; + for (mod = TAILQ_FIRST(&file->modules); mod; + mod = module_getfnext(mod)) { + + error = module_quiesce(mod); + if (error != 0 && flags != LINKER_UNLOAD_FORCE) { + KLD_DPF(FILE, ("linker_file_unload: module %s" + " vetoed unload\n", module_getname(mod))); + /* + * XXX: Do we need to tell all the quiesced modules + * that they can resume work now via a new module + * event? + */ + MOD_SUNLOCK; + return (error); + } + } + MOD_SUNLOCK; + + /* + * Inform any modules associated with this file that they are + * being be unloaded. */ MOD_XLOCK; for (mod = TAILQ_FIRST(&file->modules); mod; mod = next) { @@ -597,9 +620,9 @@ linker_file_unload(linker_file_t file, i /* * Give the module a chance to veto the unload. */ - if ((error = module_unload(mod, flags)) != 0) { - KLD_DPF(FILE, ("linker_file_unload: module %p" - " vetoes unload\n", mod)); + if ((error = module_unload(mod)) != 0) { + KLD_DPF(FILE, ("linker_file_unload: module %s" + " failed unload\n", mod)); return (error); } MOD_XLOCK; Modified: head/sys/kern/kern_module.c ============================================================================== --- head/sys/kern/kern_module.c Fri Dec 5 11:34:36 2008 (r185634) +++ head/sys/kern/kern_module.c Fri Dec 5 13:40:25 2008 (r185635) @@ -196,9 +196,7 @@ module_release(module_t mod) TAILQ_REMOVE(&modules, mod, link); if (mod->file) TAILQ_REMOVE(&mod->file->modules, mod, flink); - MOD_XUNLOCK; free(mod, M_MODULE); - MOD_XLOCK; } } @@ -232,16 +230,25 @@ module_lookupbyid(int modid) } int -module_unload(module_t mod, int flags) +module_quiesce(module_t mod) { int error; mtx_lock(&Giant); error = MOD_EVENT(mod, MOD_QUIESCE); + mtx_unlock(&Giant); if (error == EOPNOTSUPP || error == EINVAL) error = 0; - if (error == 0 || flags == LINKER_UNLOAD_FORCE) - error = MOD_EVENT(mod, MOD_UNLOAD); + return (error); +} + +int +module_unload(module_t mod) +{ + int error; + + mtx_lock(&Giant); + error = MOD_EVENT(mod, MOD_UNLOAD); mtx_unlock(&Giant); return (error); } @@ -262,6 +269,14 @@ module_getfnext(module_t mod) return (TAILQ_NEXT(mod, flink)); } +const char * +module_getname(module_t mod) +{ + + MOD_LOCK_ASSERT; + return (mod->name); +} + void module_setspecific(module_t mod, modspecific_t *datap) { Modified: head/sys/sys/module.h ============================================================================== --- head/sys/sys/module.h Fri Dec 5 11:34:36 2008 (r185634) +++ head/sys/sys/module.h Fri Dec 5 13:40:25 2008 (r185635) @@ -154,11 +154,13 @@ void module_register_init(const void *); int module_register(const struct moduledata *, struct linker_file *); module_t module_lookupbyname(const char *); module_t module_lookupbyid(int); +int module_quiesce(module_t); void module_reference(module_t); void module_release(module_t); -int module_unload(module_t, int flags); +int module_unload(module_t); int module_getid(module_t); module_t module_getfnext(module_t); +const char * module_getname(module_t); void module_setspecific(module_t, modspecific_t *); struct linker_file *module_file(module_t); From glebius at FreeBSD.org Fri Dec 5 06:37:15 2008 From: glebius at FreeBSD.org (Gleb Smirnoff) Date: Fri Dec 5 06:37:26 2008 Subject: svn commit: r185636 - head/sys/netinet Message-ID: <200812051437.mB5EbEuk056991@svn.freebsd.org> Author: glebius Date: Fri Dec 5 14:37:14 2008 New Revision: 185636 URL: http://svn.freebsd.org/changeset/base/185636 Log: In a case of CARP status change run through the if_link_state_change() routine, so that devd(8) and others are notified about link state change. Modified: head/sys/netinet/ip_carp.c Modified: head/sys/netinet/ip_carp.c ============================================================================== --- head/sys/netinet/ip_carp.c Fri Dec 5 13:40:25 2008 (r185635) +++ head/sys/netinet/ip_carp.c Fri Dec 5 14:37:14 2008 (r185636) @@ -2148,6 +2148,7 @@ carp_output(struct ifnet *ifp, struct mb static void carp_set_state(struct carp_softc *sc, int state) { + int link_state; if (sc->sc_carpdev) CARP_SCLOCK_ASSERT(sc); @@ -2158,16 +2159,16 @@ carp_set_state(struct carp_softc *sc, in sc->sc_state = state; switch (state) { case BACKUP: - SC2IFP(sc)->if_link_state = LINK_STATE_DOWN; + link_state = LINK_STATE_DOWN; break; case MASTER: - SC2IFP(sc)->if_link_state = LINK_STATE_UP; + link_state = LINK_STATE_UP; break; default: - SC2IFP(sc)->if_link_state = LINK_STATE_UNKNOWN; + link_state = LINK_STATE_UNKNOWN; break; } - rt_ifmsg(SC2IFP(sc)); + if_link_state_change(SC2IFP(sc), link_state); } void From raj at FreeBSD.org Fri Dec 5 07:27:28 2008 From: raj at FreeBSD.org (Rafal Jaworowski) Date: Fri Dec 5 07:27:39 2008 Subject: svn commit: r185639 - head/sys/arm/mv Message-ID: <200812051527.mB5FRSn4058735@svn.freebsd.org> Author: raj Date: Fri Dec 5 15:27:28 2008 New Revision: 185639 URL: http://svn.freebsd.org/changeset/base/185639 Log: Fix configuration of the PCI bridge. This got omitted in the initial import of this code. Modified: head/sys/arm/mv/mv_pci.c Modified: head/sys/arm/mv/mv_pci.c ============================================================================== --- head/sys/arm/mv/mv_pci.c Fri Dec 5 15:26:19 2008 (r185638) +++ head/sys/arm/mv/mv_pci.c Fri Dec 5 15:27:28 2008 (r185639) @@ -598,6 +598,10 @@ pcib_mbus_init_bridge(struct pcib_mbus_s mem_limit = mem_base + sc->sc_info->op_mem_size - 1; /* Configure I/O decode registers */ + pcib_mbus_write_config(sc->sc_dev, bus, slot, func, PCIR_IOBASEL_1, + io_base >> 8, 1); + pcib_mbus_write_config(sc->sc_dev, bus, slot, func, PCIR_IOBASEH_1, + io_base >> 16, 2); pcib_mbus_write_config(sc->sc_dev, bus, slot, func, PCIR_IOLIMITL_1, io_limit >> 8, 1); pcib_mbus_write_config(sc->sc_dev, bus, slot, func, PCIR_IOLIMITH_1, From raj at FreeBSD.org Fri Dec 5 07:31:52 2008 From: raj at FreeBSD.org (Rafal Jaworowski) Date: Fri Dec 5 07:31:58 2008 Subject: svn commit: r185640 - head/sys/arm/mv/orion Message-ID: <200812051531.mB5FVp2V059443@svn.freebsd.org> Author: raj Date: Fri Dec 5 15:31:51 2008 New Revision: 185640 URL: http://svn.freebsd.org/changeset/base/185640 Log: Avoid confusion and adjust link address range of Marvell Orion kernel so it is the same as for Kirkwood and Discovery. Modified: head/sys/arm/mv/orion/std.db88f5xxx Modified: head/sys/arm/mv/orion/std.db88f5xxx ============================================================================== --- head/sys/arm/mv/orion/std.db88f5xxx Fri Dec 5 15:27:28 2008 (r185639) +++ head/sys/arm/mv/orion/std.db88f5xxx Fri Dec 5 15:31:51 2008 (r185640) @@ -3,11 +3,11 @@ include "../mv/std.mv" files "../mv/orion/files.db88f5xxx" -makeoptions KERNPHYSADDR=0x00400000 -makeoptions KERNVIRTADDR=0xc0400000 +makeoptions KERNPHYSADDR=0x00900000 +makeoptions KERNVIRTADDR=0xc0900000 -options KERNPHYSADDR=0x00400000 -options KERNVIRTADDR=0xc0400000 +options KERNPHYSADDR=0x00900000 +options KERNVIRTADDR=0xc0900000 options PHYSADDR=0x00000000 options PHYSMEM_SIZE=0x08000000 options STARTUP_PAGETABLE_ADDR=0x00100000 From pjd at FreeBSD.org Fri Dec 5 07:50:59 2008 From: pjd at FreeBSD.org (Pawel Jakub Dawidek) Date: Fri Dec 5 07:51:11 2008 Subject: svn commit: r185641 - head/lib/libc/string Message-ID: <200812051550.mB5FoxGg062499@svn.freebsd.org> Author: pjd Date: Fri Dec 5 15:50:59 2008 New Revision: 185641 URL: http://svn.freebsd.org/changeset/base/185641 Log: Add an easier example. Reviewed by: trasz Modified: head/lib/libc/string/strsep.3 Modified: head/lib/libc/string/strsep.3 ============================================================================== --- head/lib/libc/string/strsep.3 Fri Dec 5 15:31:51 2008 (r185640) +++ head/lib/libc/string/strsep.3 Fri Dec 5 15:50:59 2008 (r185641) @@ -31,7 +31,7 @@ .\" @(#)strsep.3 8.1 (Berkeley) 6/9/93 .\" $FreeBSD$ .\" -.Dd June 9, 1993 +.Dd December 5, 2008 .Dt STRSEP 3 .Os .Sh NAME @@ -81,6 +81,21 @@ returns .Sh EXAMPLES The following uses .Fn strsep +to parse a string, and prints each token in separate line: +.Bd -literal -offset indent +char *token, *string, *tofree; + +tofree = string = strdup("abc,def,ghi"); +assert(string != NULL); + +while ((token = strsep(&string, ",")) != NULL) + printf("%s\en", token); + +free(tofree); +.Ed +.Pp +The following uses +.Fn strsep to parse a string, containing tokens delimited by white space, into an argument vector: .Bd -literal -offset indent From jamie at gritton.org Fri Dec 5 08:00:53 2008 From: jamie at gritton.org (James Gritton) Date: Fri Dec 5 08:01:04 2008 Subject: svn commit: r185435 - in head: lib/libc/sys lib/libkvm share/man/man4 sys/compat/freebsd32 sys/kern sys/net sys/netinet sys/netinet6 sys/security/mac_bsdextended sys/sys usr.bin/cpuset usr.sbin/jai... In-Reply-To: <20081204184332.C80401@maildrop.int.zabbadoz.net> References: <200811291432.mATEWE2a053742@svn.freebsd.org> <86skp3yje2.fsf@ds4.des.no> <20081204184332.C80401@maildrop.int.zabbadoz.net> Message-ID: <4939482F.4040404@gritton.org> Bjoern A. Zeeb wrote: > On Thu, 4 Dec 2008, Dag-Erling Sm?rgrav wrote: >> "Bjoern A. Zeeb" writes: >>> Jails can have an unrestricted (no duplicate protection, etc.) name >>> in addition to the hostname. The jail name cannot be changed from >>> within a jail and is considered to be used for management purposes >>> or as audit-token in the future. >> >> Is there a specific reason why we allow duplicates? > > Yes, so that people have a choice. > > You would have to take into account "DYING" jails with possibly > duplicate names anyway. > > And it's a purely administrative name (cannot be changed from within > the jail) so it's up to the administrator to have 2 "Customer Webserver" > jails or a "Customer Webserver Tin" and a "Customer Webserver Box". > > BTW. in case people wonder how to set it (atm.) from rc.conf, you > can use jail__flags. My new (upcoming) jail framework patches also support names, but without allowing duplicates. This is necessary because jails can be looked up in the kernel by name as well as by ID. I handle the special case of "dying" jails, allowing a new jail to duplicate the name of one on the the way out. As far as people having a choice, I don't see any more reason to offer the choice of duplicate jail names than I do in offering duplicate login names. It just doesn't make sense in the context of what purpose I expect a name to serve. - Jamie From jhb at freebsd.org Fri Dec 5 08:43:12 2008 From: jhb at freebsd.org (John Baldwin) Date: Fri Dec 5 08:43:19 2008 Subject: svn commit: r185625 - head/sys/dev/pccbb In-Reply-To: <200812050520.mB55K8kS044139@svn.freebsd.org> References: <200812050520.mB55K8kS044139@svn.freebsd.org> Message-ID: <200812051122.18694.jhb@freebsd.org> On Friday 05 December 2008 12:20:08 am Warner Losh wrote: > Author: imp > Date: Fri Dec 5 05:20:08 2008 > New Revision: 185625 > URL: http://svn.freebsd.org/changeset/base/185625 > > Log: > Move to using filter for the change interrupts. Also rework the power > interrupt code to be more robust. I've been running these changes for > over a year... With these changes, I don't see the ath card going > into reset like the code in the tree. I would use '0' for the priority to msleep() instead of PZERO so that you just leave the priority alone and don't change it. -- John Baldwin From jhb at FreeBSD.org Fri Dec 5 08:47:31 2008 From: jhb at FreeBSD.org (John Baldwin) Date: Fri Dec 5 08:47:44 2008 Subject: svn commit: r185642 - head/sys/kern Message-ID: <200812051647.mB5GlVst067730@svn.freebsd.org> Author: jhb Date: Fri Dec 5 16:47:30 2008 New Revision: 185642 URL: http://svn.freebsd.org/changeset/base/185642 Log: When the SYSINIT() to load a module invokes the MOD_LOAD event successfully, move that module to the head of the associated linker file's list of modules. The end result is that once all the modules are loaded, they are sorted in the reverse of their load order. This causes the kernel linker to invoke the MOD_QUIESCE and MOD_UNLOAD events in the reverse of the order that MOD_LOAD was invoked. This means that the ordering of MOD_LOAD events that is set by the SI_* paramters to DECLARE_MODULE() are now honored in the same order they would be for SYSUNINIT() for the MOD_QUIESCE and MOD_UNLOAD events. MFC after: 1 month Modified: head/sys/kern/kern_module.c Modified: head/sys/kern/kern_module.c ============================================================================== --- head/sys/kern/kern_module.c Fri Dec 5 15:50:59 2008 (r185641) +++ head/sys/kern/kern_module.c Fri Dec 5 16:47:30 2008 (r185642) @@ -130,6 +130,21 @@ module_register_init(const void *arg) printf("module_register_init: MOD_LOAD (%s, %p, %p) error" " %d\n", data->name, (void *)data->evhand, data->priv, error); + } else { + MOD_XLOCK; + if (mod->file) { + /* + * Once a module is succesfully loaded, move + * it to the head of the module list for this + * linker file. This resorts the list so that + * when the kernel linker iterates over the + * modules to unload them, it will unload them + * in the reverse order they were loaded. + */ + TAILQ_REMOVE(&mod->file->modules, mod, flink); + TAILQ_INSERT_HEAD(&mod->file->modules, mod, flink); + } + MOD_XUNLOCK; } mtx_unlock(&Giant); } From luigi at FreeBSD.org Fri Dec 5 09:13:40 2008 From: luigi at FreeBSD.org (Luigi Rizzo) Date: Fri Dec 5 09:13:46 2008 Subject: svn commit: r185643 - head/lib/libstand Message-ID: <200812051713.mB5HDerC068258@svn.freebsd.org> Author: luigi Date: Fri Dec 5 17:13:40 2008 New Revision: 185643 URL: http://svn.freebsd.org/changeset/base/185643 Log: Some libstand/bootp.c extension (written by Danny Braniss, slightly revised/modified by me) to store dhcp options into kenv variables, so the information is available to the boot loader and can be used to customize the boot process. The change is totally unintrusive, essentially made of a single function to be called while parsing a dhcp response, and a couple of tables to classify options. The values extracted from dhcp options are stored in the kenv environment in one of these forms: + options whose name and type is known are saved as dhcp.name = value (string, or number/ip addresses lists) + unknown options are assumed to be strings and saved as dhcp.option-NNN = "value" + options listed as '__INDIR' and sent on the wire as e.g. option unknown-252 "some.name=the actual value" are saved as some.name = "the actual value" + options listed as '__ILIST' and sent on the wire as e.g. option unknown-249 "a.b=foo bar; c.d= 123; e.f=done" are saved as multiple values a.b="foo bar" c.d="123" e.f="done" As you can see there is quite a bit of flexibility on what can be passed to the loader or the kernel. For the time being the vendor-specific table is mostly disabled, because there is no standard set of options for FreeBSD, and I don't know all the pxe-specific vendor options. Also, applications using libstand may live in memory-constrained environments, so it makes sense to keep these tables as small as possible, especially considering that one can generate arbitrary name=value pairs using site-specific options of type __INDIR or __ILIST (there are 4 __ILIST and 5 __INDIR in the table, numbered 246..249 and 250..254). Actually, considering that probably 75% of the standard dhcp options are totally useless, it might make sense to remove them as well. Submitted by: Danny Braniss MFC after: 4 weeks Modified: head/lib/libstand/bootp.c Modified: head/lib/libstand/bootp.c ============================================================================== --- head/lib/libstand/bootp.c Fri Dec 5 16:47:30 2008 (r185642) +++ head/lib/libstand/bootp.c Fri Dec 5 17:13:40 2008 (r185643) @@ -47,6 +47,12 @@ __FBSDID("$FreeBSD$"); #define BOOTP_DEBUGxx #define SUPPORT_DHCP +#define DHCP_ENV_NOVENDOR 1 /* do not parse vendor options */ +#define DHCP_ENV_PXE 10 /* assume pxe vendor options */ +#define DHCP_ENV_FREEBSD 11 /* assume freebsd vendor options +/* set DHCP_ENV to one of the values above to export dhcp options to kenv */ +#define DHCP_ENV DHCP_ENV_NO_VENDOR + #include "stand.h" #include "net.h" #include "netif.h" @@ -72,6 +78,13 @@ static int vend_rfc1048(u_char *, u_int) static void vend_cmu(u_char *); #endif +#ifdef DHCP_ENV /* export the dhcp response to kenv */ +struct dhcp_opt; +static void setenv_(u_char *cp, u_char *ep, struct dhcp_opt *opts); +#else +#define setenv_(a, b, c) +#endif + #ifdef SUPPORT_DHCP static char expected_dhcpmsgtype = -1, dhcp_ok; struct in_addr dhcp_serverip; @@ -351,6 +364,8 @@ vend_rfc1048(cp, len) /* Step over magic cookie */ cp += sizeof(int); + setenv_(cp, ep, NULL); + while (cp < ep) { tag = *cp++; size = *cp++; @@ -412,3 +427,316 @@ vend_cmu(cp) } } #endif + +#ifdef DHCP_ENV +/* + * Parse DHCP options and store them into kenv variables. + * Original code from Danny Braniss, modifications by Luigi Rizzo. + * + * The parser is driven by tables which specify the type and name of + * each dhcp option and how it appears in kenv. + * The first entry in the list contains the prefix used to set the kenv + * name (including the . if needed), the last entry must have a 0 tag. + * Entries do not need to be sorted though it helps for readability. + * + * Certain vendor-specific tables can be enabled according to DHCP_ENV. + * Set it to 0 if you don't want any. + */ +enum opt_fmt { __NONE = 0, + __8 = 1, __16 = 2, __32 = 4, /* Unsigned fields, value=size */ + __IP, /* IPv4 address */ + __TXT, /* C string */ + __BYTES, /* byte sequence, printed %02x */ + __INDIR, /* name=value */ + __ILIST, /* name=value;name=value ... */ + __VE, /* vendor specific, recurse */ +}; + +struct dhcp_opt { + uint8_t tag; + uint8_t fmt; + const char *desc; +}; + +static struct dhcp_opt vndr_opt[] = { /* Vendor Specific Options */ +#if DHCP_ENV == DHCP_ENV_FREEBSD /* FreeBSD table in the original code */ + {0, 0, "FreeBSD"}, /* prefix */ + {1, __TXT, "kernel"}, + {2, __TXT, "kernelname"}, + {3, __TXT, "kernel_options"}, + {4, __IP, "usr-ip"}, + {5, __TXT, "conf-path"}, + {6, __TXT, "rc.conf0"}, + {7, __TXT, "rc.conf1"}, + {8, __TXT, "rc.conf2"}, + {9, __TXT, "rc.conf3"}, + {10, __TXT, "rc.conf4"}, + {11, __TXT, "rc.conf5"}, + {12, __TXT, "rc.conf6"}, + {13, __TXT, "rc.conf7"}, + {14, __TXT, "rc.conf8"}, + {15, __TXT, "rc.conf9"}, + + {20, __TXT, "boot.nfsroot.options"}, + + {245, __INDIR, ""}, + {246, __INDIR, ""}, + {247, __INDIR, ""}, + {248, __INDIR, ""}, + {249, __INDIR, ""}, + {250, __INDIR, ""}, + {251, __INDIR, ""}, + {252, __INDIR, ""}, + {253, __INDIR, ""}, + {254, __INDIR, ""}, + +#elif DHCP_ENV == DHCP_ENV_PXE /* some pxe options, RFC4578 */ + {0, 0, "pxe"}, /* prefix */ + {93, __16, "system-architecture"}, + {94, __BYTES, "network-interface"}, + {97, __BYTES, "machine-identifier"}, +#else /* default (empty) table */ + {0, 0, ""}, /* prefix */ +#endif + {0, __TXT, "%soption-%d"} +}; + +static struct dhcp_opt dhcp_opt[] = { + /* DHCP Option names, formats and codes, from RFC2132. */ + {0, 0, "dhcp."}, // prefix + {1, __IP, "subnet-mask"}, + {2, __32, "time-offset"}, /* this is signed */ + {3, __IP, "routers"}, + {4, __IP, "time-servers"}, + {5, __IP, "ien116-name-servers"}, + {6, __IP, "domain-name-servers"}, + {7, __IP, "log-servers"}, + {8, __IP, "cookie-servers"}, + {9, __IP, "lpr-servers"}, + {10, __IP, "impress-servers"}, + {11, __IP, "resource-location-servers"}, + {12, __TXT, "host-name"}, + {13, __16, "boot-size"}, + {14, __TXT, "merit-dump"}, + {15, __TXT, "domain-name"}, + {16, __IP, "swap-server"}, + {17, __TXT, "root-path"}, + {18, __TXT, "extensions-path"}, + {19, __8, "ip-forwarding"}, + {20, __8, "non-local-source-routing"}, + {21, __IP, "policy-filter"}, + {22, __16, "max-dgram-reassembly"}, + {23, __8, "default-ip-ttl"}, + {24, __32, "path-mtu-aging-timeout"}, + {25, __16, "path-mtu-plateau-table"}, + {26, __16, "interface-mtu"}, + {27, __8, "all-subnets-local"}, + {28, __IP, "broadcast-address"}, + {29, __8, "perform-mask-discovery"}, + {30, __8, "mask-supplier"}, + {31, __8, "perform-router-discovery"}, + {32, __IP, "router-solicitation-address"}, + {33, __IP, "static-routes"}, + {34, __8, "trailer-encapsulation"}, + {35, __32, "arp-cache-timeout"}, + {36, __8, "ieee802-3-encapsulation"}, + {37, __8, "default-tcp-ttl"}, + {38, __32, "tcp-keepalive-interval"}, + {39, __8, "tcp-keepalive-garbage"}, + {40, __TXT, "nis-domain"}, + {41, __IP, "nis-servers"}, + {42, __IP, "ntp-servers"}, + {43, __VE, "vendor-encapsulated-options"}, + {44, __IP, "netbios-name-servers"}, + {45, __IP, "netbios-dd-server"}, + {46, __8, "netbios-node-type"}, + {47, __TXT, "netbios-scope"}, + {48, __IP, "x-font-servers"}, + {49, __IP, "x-display-managers"}, + {50, __IP, "dhcp-requested-address"}, + {51, __32, "dhcp-lease-time"}, + {52, __8, "dhcp-option-overload"}, + {53, __8, "dhcp-message-type"}, + {54, __IP, "dhcp-server-identifier"}, + {55, __8, "dhcp-parameter-request-list"}, + {56, __TXT, "dhcp-message"}, + {57, __16, "dhcp-max-message-size"}, + {58, __32, "dhcp-renewal-time"}, + {59, __32, "dhcp-rebinding-time"}, + {60, __TXT, "vendor-class-identifier"}, + {61, __TXT, "dhcp-client-identifier"}, + {64, __TXT, "nisplus-domain"}, + {65, __IP, "nisplus-servers"}, + {66, __TXT, "tftp-server-name"}, + {67, __TXT, "bootfile-name"}, + {68, __IP, "mobile-ip-home-agent"}, + {69, __IP, "smtp-server"}, + {70, __IP, "pop-server"}, + {71, __IP, "nntp-server"}, + {72, __IP, "www-server"}, + {73, __IP, "finger-server"}, + {74, __IP, "irc-server"}, + {75, __IP, "streettalk-server"}, + {76, __IP, "streettalk-directory-assistance-server"}, + {77, __TXT, "user-class"}, + {85, __IP, "nds-servers"}, + {86, __TXT, "nds-tree-name"}, + {87, __TXT, "nds-context"}, + {210, __TXT, "authenticate"}, + + /* use the following entries for arbitrary variables */ + {246, __ILIST, ""}, + {247, __ILIST, ""}, + {248, __ILIST, ""}, + {249, __ILIST, ""}, + {250, __INDIR, ""}, + {251, __INDIR, ""}, + {252, __INDIR, ""}, + {253, __INDIR, ""}, + {254, __INDIR, ""}, + {0, __TXT, "%soption-%d"} +}; + +/* + * parse a dhcp response, set environment variables translating options + * names and values according to the tables above. Also set dhcp.tags + * to the list of selected tags. + */ +static void +setenv_(u_char *cp, u_char *ep, struct dhcp_opt *opts) +{ + u_char *ncp; + u_char tag; + char tags[512], *tp; /* the list of tags */ + +#define FLD_SEP ',' /* separator in list of elements */ + ncp = cp; + tp = tags; + if (opts == NULL) + opts = dhcp_opt; + + while (ncp < ep) { + unsigned int size; /* option size */ + char *vp, *endv, buf[256]; /* the value buffer */ + struct dhcp_opt *op; + + tag = *ncp++; /* extract tag and size */ + size = *ncp++; + cp = ncp; /* current payload */ + ncp += size; /* point to the next option */ + + if (tag == TAG_END) + break; + if (tag == 0) + continue; + + for (op = opts+1; op->tag && op->tag != tag; op++) + ; + /* if not found we end up on the default entry */ + + /* + * Copy data into the buffer. libstand does not have snprintf so we + * need to be careful with sprintf(). With strings, the source is + * always <256 char so shorter than the buffer so we are safe; with + * other arguments, the longest string is inet_ntoa which is 16 bytes + * so we make sure to have always enough room in the string before + * trying an sprint. + */ + vp = buf; + *vp = '\0'; + endv = buf + sizeof(buf) - 1 - 16; /* last valid write position */ + + switch(op->fmt) { + case __NONE: + break; /* should not happen */ + + case __VE: /* recurse, vendor specific */ + setenv_(cp, cp+size, vndr_opt); + break; + + case __IP: /* ip address */ + for (; size > 0 && vp < endv; size -= 4, cp += 4) { + struct in_addr in_ip; /* ip addresses */ + if (vp != buf) + *vp++ = FLD_SEP; + bcopy(cp, &in_ip.s_addr, sizeof(in_ip.s_addr)); + sprintf(vp, "%s", inet_ntoa(in_ip)); + vp += strlen(vp); + } + break; + + case __BYTES: /* opaque byte string */ + for (; size > 0 && vp < endv; size -= 1, cp += 1) { + sprintf(vp, "%02x", *cp); + vp += strlen(vp); + } + break; + + case __TXT: + bcopy(cp, buf, size); /* cannot overflow */ + buf[size] = 0; + break; + + case __32: + case __16: + case __8: /* op->fmt is also the length of each field */ + for (; size > 0 && vp < endv; size -= op->fmt, cp += op->fmt) { + uint32_t v; + if (op->fmt == __32) + v = (cp[0]<<24) + (cp[1]<<16) + (cp[2]<<8) + cp[3]; + else if (op->fmt == __16) + v = (cp[0]<<8) + cp[1]; + else + v = cp[0]; + if (vp != buf) + *vp++ = FLD_SEP; + sprintf(vp, "%u", v); + vp += strlen(vp); + } + break; + + case __INDIR: /* name=value */ + case __ILIST: /* name=value;name=value... */ + bcopy(cp, buf, size); /* cannot overflow */ + buf[size] = '\0'; + for (endv = buf; endv; endv = vp) { + u_char *s = NULL; /* semicolon ? */ + + /* skip leading whitespace */ + while (*endv && index(" \t\n\r", *endv)) + endv++; + vp = index(endv, '='); /* find name=value separator */ + if (!vp) + break; + *vp++ = 0; + if (op->fmt == __ILIST && (s = index(vp, ';'))) + *s++ = '\0'; + setenv(endv, vp, 1); + vp = s; /* prepare for next round */ + } + buf[0] = '\0'; /* option already done */ + } + + if (tp - tags < sizeof(tags) - 5) { /* add tag to the list */ + if (tp != tags) + *tp++ = FLD_SEP; + sprintf(tp, "%d", tag); + tp += strlen(tp); + } + if (buf[0]) { + char env[128]; /* the string name */ + + if (op->tag == 0) + sprintf(env, op->desc, opts[0].desc, tag); + else + sprintf(env, "%s%s", opts[0].desc, op->desc); + setenv(env, buf, 1); + } + } + if (tp != tags) { + char env[128]; /* the string name */ + sprintf(env, "%stags", opts[0].desc); + setenv(env, tags, 1); + } +} +#endif /* additional dhcp */ From julian at elischer.org Fri Dec 5 10:35:02 2008 From: julian at elischer.org (Julian Elischer) Date: Fri Dec 5 10:35:14 2008 Subject: svn commit: r185435 - in head: lib/libc/sys lib/libkvm share/man/man4 sys/compat/freebsd32 sys/kern sys/net sys/netinet sys/netinet6 sys/security/mac_bsdextended sys/sys usr.bin/cpuset usr.sbin/jai... In-Reply-To: <4939482F.4040404@gritton.org> References: <200811291432.mATEWE2a053742@svn.freebsd.org> <86skp3yje2.fsf@ds4.des.no> <20081204184332.C80401@maildrop.int.zabbadoz.net> <4939482F.4040404@gritton.org> Message-ID: <4939716A.3080103@elischer.org> James Gritton wrote: > Bjoern A. Zeeb wrote: >> On Thu, 4 Dec 2008, Dag-Erling Sm?rgrav wrote: >>> "Bjoern A. Zeeb" writes: >>>> Jails can have an unrestricted (no duplicate protection, etc.) name >>>> in addition to the hostname. The jail name cannot be changed from >>>> within a jail and is considered to be used for management purposes >>>> or as audit-token in the future. >>> >>> Is there a specific reason why we allow duplicates? >> >> Yes, so that people have a choice. >> >> You would have to take into account "DYING" jails with possibly >> duplicate names anyway. >> >> And it's a purely administrative name (cannot be changed from within >> the jail) so it's up to the administrator to have 2 "Customer Webserver" >> jails or a "Customer Webserver Tin" and a "Customer Webserver Box". >> >> BTW. in case people wonder how to set it (atm.) from rc.conf, you >> can use jail__flags. > > My new (upcoming) jail framework patches also support names, but without > allowing duplicates. This is necessary because jails can be looked up > in the kernel by name as well as by ID. I handle the special case of > "dying" jails, allowing a new jail to duplicate the name of one on the > the way out. > > As far as people having a choice, I don't see any more reason to offer > the choice of duplicate jail names than I do in offering duplicate login > names. It just doesn't make sense in the context of what purpose I > expect a name to serve. hierarchical names make this even less sensible, > > - Jamie From kib at FreeBSD.org Fri Dec 5 12:50:25 2008 From: kib at FreeBSD.org (Konstantin Belousov) Date: Fri Dec 5 12:50:32 2008 Subject: svn commit: r185647 - in head/sys: kern sys Message-ID: <200812052050.mB5KoOcV072648@svn.freebsd.org> Author: kib Date: Fri Dec 5 20:50:24 2008 New Revision: 185647 URL: http://svn.freebsd.org/changeset/base/185647 Log: Several threads in a process may do vfork() simultaneously. Then, all parent threads sleep on the parent' struct proc until corresponding child releases the vmspace. Each sleep is interlocked with proc mutex of the child, that triggers assertion in the sleepq_add(). The assertion requires that at any time, all simultaneous sleepers for the channel use the same interlock. Silent the assertion by using conditional variable allocated in the child. Broadcast the variable event on exec() and exit(). Since struct proc * sleep wait channel is overloaded for several unrelated events, I was unable to remove wakeups from the places where cv_broadcast() is added, except exec(). Reported and tested by: ganbold Suggested and reviewed by: jhb MFC after: 2 week Modified: head/sys/kern/kern_exec.c head/sys/kern/kern_exit.c head/sys/kern/kern_fork.c head/sys/kern/kern_proc.c head/sys/sys/proc.h Modified: head/sys/kern/kern_exec.c ============================================================================== --- head/sys/kern/kern_exec.c Fri Dec 5 20:40:02 2008 (r185646) +++ head/sys/kern/kern_exec.c Fri Dec 5 20:50:24 2008 (r185647) @@ -609,7 +609,7 @@ interpret: p->p_flag |= P_EXEC; if (p->p_pptr && (p->p_flag & P_PPWAIT)) { p->p_flag &= ~P_PPWAIT; - wakeup(p->p_pptr); + cv_broadcast(&p->p_pwait); } /* Modified: head/sys/kern/kern_exit.c ============================================================================== --- head/sys/kern/kern_exit.c Fri Dec 5 20:40:02 2008 (r185646) +++ head/sys/kern/kern_exit.c Fri Dec 5 20:50:24 2008 (r185647) @@ -543,6 +543,7 @@ exit1(struct thread *td, int rv) * proc lock. */ wakeup(p->p_pptr); + cv_broadcast(&p->p_pwait); sched_exit(p->p_pptr, td); PROC_SLOCK(p); p->p_state = PRS_ZOMBIE; @@ -774,6 +775,7 @@ loop: PROC_UNLOCK(p); tdsignal(t, NULL, SIGCHLD, p->p_ksi); wakeup(t); + cv_broadcast(&p->p_pwait); PROC_UNLOCK(t); sx_xunlock(&proctree_lock); return (0); Modified: head/sys/kern/kern_fork.c ============================================================================== --- head/sys/kern/kern_fork.c Fri Dec 5 20:40:02 2008 (r185646) +++ head/sys/kern/kern_fork.c Fri Dec 5 20:50:24 2008 (r185647) @@ -754,7 +754,7 @@ again: */ PROC_LOCK(p2); while (p2->p_flag & P_PPWAIT) - msleep(p1, &p2->p_mtx, PWAIT, "ppwait", 0); + cv_wait(&p2->p_pwait, &p2->p_mtx); PROC_UNLOCK(p2); /* Modified: head/sys/kern/kern_proc.c ============================================================================== --- head/sys/kern/kern_proc.c Fri Dec 5 20:40:02 2008 (r185646) +++ head/sys/kern/kern_proc.c Fri Dec 5 20:50:24 2008 (r185647) @@ -231,6 +231,7 @@ proc_init(void *mem, int size, int flags bzero(&p->p_mtx, sizeof(struct mtx)); mtx_init(&p->p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK); mtx_init(&p->p_slock, "process slock", NULL, MTX_SPIN | MTX_RECURSE); + cv_init(&p->p_pwait, "ppwait"); TAILQ_INIT(&p->p_threads); /* all threads in proc */ EVENTHANDLER_INVOKE(process_init, p); p->p_stats = pstats_alloc(); Modified: head/sys/sys/proc.h ============================================================================== --- head/sys/sys/proc.h Fri Dec 5 20:40:02 2008 (r185646) +++ head/sys/sys/proc.h Fri Dec 5 20:50:24 2008 (r185647) @@ -40,6 +40,7 @@ #include /* For struct callout. */ #include /* For struct klist. */ +#include #ifndef _KERNEL #include #endif @@ -540,6 +541,7 @@ struct proc { STAILQ_HEAD(, ktr_request) p_ktr; /* (o) KTR event queue. */ LIST_HEAD(, mqueue_notifier) p_mqnotifier; /* (c) mqueue notifiers.*/ struct kdtrace_proc *p_dtrace; /* (*) DTrace-specific data. */ + struct cv p_pwait; /* (*) wait cv for exit/exec */ }; #define p_session p_pgrp->pg_session From julian at elischer.org Fri Dec 5 12:54:42 2008 From: julian at elischer.org (Julian Elischer) Date: Fri Dec 5 12:54:48 2008 Subject: svn commit: r185647 - in head/sys: kern sys In-Reply-To: <200812052050.mB5KoOcV072648@svn.freebsd.org> References: <200812052050.mB5KoOcV072648@svn.freebsd.org> Message-ID: <49399510.2030104@elischer.org> Konstantin Belousov wrote: > Author: kib > Date: Fri Dec 5 20:50:24 2008 > New Revision: 185647 > URL: http://svn.freebsd.org/changeset/base/185647 > > Log: > Several threads in a process may do vfork() simultaneously. Then, all > parent threads sleep on the parent' struct proc until corresponding > child releases the vmspace. Each sleep is interlocked with proc mutex of > the child, that triggers assertion in the sleepq_add(). The assertion > requires that at any time, all simultaneous sleepers for the channel use > the same interlock. We DID have a thread_single() in the fork code so that only one thread would proceed through the fork itself at a time. However it was removed last year as it proved to be a problem in some cases. Maybe we need to look at replacing it in some way. > > Silent the assertion by using conditional variable allocated in the > child. Broadcast the variable event on exec() and exit(). > > Since struct proc * sleep wait channel is overloaded for several > unrelated events, I was unable to remove wakeups from the places where > cv_broadcast() is added, except exec(). > > Reported and tested by: ganbold > Suggested and reviewed by: jhb > MFC after: 2 week > > Modified: > head/sys/kern/kern_exec.c > head/sys/kern/kern_exit.c > head/sys/kern/kern_fork.c > head/sys/kern/kern_proc.c > head/sys/sys/proc.h > > Modified: head/sys/kern/kern_exec.c > ============================================================================== > --- head/sys/kern/kern_exec.c Fri Dec 5 20:40:02 2008 (r185646) > +++ head/sys/kern/kern_exec.c Fri Dec 5 20:50:24 2008 (r185647) > @@ -609,7 +609,7 @@ interpret: > p->p_flag |= P_EXEC; > if (p->p_pptr && (p->p_flag & P_PPWAIT)) { > p->p_flag &= ~P_PPWAIT; > - wakeup(p->p_pptr); > + cv_broadcast(&p->p_pwait); > } > > /* > > Modified: head/sys/kern/kern_exit.c > ============================================================================== > --- head/sys/kern/kern_exit.c Fri Dec 5 20:40:02 2008 (r185646) > +++ head/sys/kern/kern_exit.c Fri Dec 5 20:50:24 2008 (r185647) > @@ -543,6 +543,7 @@ exit1(struct thread *td, int rv) > * proc lock. > */ > wakeup(p->p_pptr); > + cv_broadcast(&p->p_pwait); > sched_exit(p->p_pptr, td); > PROC_SLOCK(p); > p->p_state = PRS_ZOMBIE; > @@ -774,6 +775,7 @@ loop: > PROC_UNLOCK(p); > tdsignal(t, NULL, SIGCHLD, p->p_ksi); > wakeup(t); > + cv_broadcast(&p->p_pwait); > PROC_UNLOCK(t); > sx_xunlock(&proctree_lock); > return (0); > > Modified: head/sys/kern/kern_fork.c > ============================================================================== > --- head/sys/kern/kern_fork.c Fri Dec 5 20:40:02 2008 (r185646) > +++ head/sys/kern/kern_fork.c Fri Dec 5 20:50:24 2008 (r185647) > @@ -754,7 +754,7 @@ again: > */ > PROC_LOCK(p2); > while (p2->p_flag & P_PPWAIT) > - msleep(p1, &p2->p_mtx, PWAIT, "ppwait", 0); > + cv_wait(&p2->p_pwait, &p2->p_mtx); > PROC_UNLOCK(p2); > > /* > > Modified: head/sys/kern/kern_proc.c > ============================================================================== > --- head/sys/kern/kern_proc.c Fri Dec 5 20:40:02 2008 (r185646) > +++ head/sys/kern/kern_proc.c Fri Dec 5 20:50:24 2008 (r185647) > @@ -231,6 +231,7 @@ proc_init(void *mem, int size, int flags > bzero(&p->p_mtx, sizeof(struct mtx)); > mtx_init(&p->p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK); > mtx_init(&p->p_slock, "process slock", NULL, MTX_SPIN | MTX_RECURSE); > + cv_init(&p->p_pwait, "ppwait"); > TAILQ_INIT(&p->p_threads); /* all threads in proc */ > EVENTHANDLER_INVOKE(process_init, p); > p->p_stats = pstats_alloc(); > > Modified: head/sys/sys/proc.h > ============================================================================== > --- head/sys/sys/proc.h Fri Dec 5 20:40:02 2008 (r185646) > +++ head/sys/sys/proc.h Fri Dec 5 20:50:24 2008 (r185647) > @@ -40,6 +40,7 @@ > > #include /* For struct callout. */ > #include /* For struct klist. */ > +#include > #ifndef _KERNEL > #include > #endif > @@ -540,6 +541,7 @@ struct proc { > STAILQ_HEAD(, ktr_request) p_ktr; /* (o) KTR event queue. */ > LIST_HEAD(, mqueue_notifier) p_mqnotifier; /* (c) mqueue notifiers.*/ > struct kdtrace_proc *p_dtrace; /* (*) DTrace-specific data. */ > + struct cv p_pwait; /* (*) wait cv for exit/exec */ > }; > > #define p_session p_pgrp->pg_session From kostikbel at gmail.com Fri Dec 5 13:03:57 2008 From: kostikbel at gmail.com (Kostik Belousov) Date: Fri Dec 5 13:04:08 2008 Subject: svn commit: r185647 - in head/sys: kern sys In-Reply-To: <49399510.2030104@elischer.org> References: <200812052050.mB5KoOcV072648@svn.freebsd.org> <49399510.2030104@elischer.org> Message-ID: <20081205210349.GQ2038@deviant.kiev.zoral.com.ua> On Fri, Dec 05, 2008 at 12:54:40PM -0800, Julian Elischer wrote: > Konstantin Belousov wrote: > >Author: kib > >Date: Fri Dec 5 20:50:24 2008 > >New Revision: 185647 > >URL: http://svn.freebsd.org/changeset/base/185647 > > > >Log: > > Several threads in a process may do vfork() simultaneously. Then, all > > parent threads sleep on the parent' struct proc until corresponding > > child releases the vmspace. Each sleep is interlocked with proc mutex of > > the child, that triggers assertion in the sleepq_add(). The assertion > > requires that at any time, all simultaneous sleepers for the channel use > > the same interlock. > > We DID have a thread_single() in the fork code so that > only one thread would proceed through the fork itself at a time. > However it was removed last year as it proved to be a problem in some > cases. Maybe we need to look at replacing it in some way. Yes, I know, and I considered restoring conditional single-threading for the vfork(). But it would immediately bring back all NFS client problems, associated with this (at least sleeping with vnode lock held and nfsbiod creation deadlocks). This is a second problem caused by removal of the single-threading. Nonetheless, I think that your change was right, and we shall just fix a corner cases. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 195 bytes Desc: not available Url : http://lists.freebsd.org/pipermail/svn-src-head/attachments/20081205/450e717a/attachment.pgp From kib at FreeBSD.org Fri Dec 5 13:17:54 2008 From: kib at FreeBSD.org (Konstantin Belousov) Date: Fri Dec 5 13:18:06 2008 Subject: svn commit: r185651 - head/sys/i386/include Message-ID: <200812052117.mB5LHshQ073411@svn.freebsd.org> Author: kib Date: Fri Dec 5 21:17:54 2008 New Revision: 185651 URL: http://svn.freebsd.org/changeset/base/185651 Log: Unconditionally use locked addition of zero to tip of the stack for memory barriers on i386. It works as a serialization instruction on all IA32 CPUs. Alternative solution of using {s,l,}fence requires run-time checking of the presense of the corresponding SSE or SSE2 extensions, and possible boot-time patching of the kernel text. Suggested by: many Modified: head/sys/i386/include/atomic.h Modified: head/sys/i386/include/atomic.h ============================================================================== --- head/sys/i386/include/atomic.h Fri Dec 5 21:17:19 2008 (r185650) +++ head/sys/i386/include/atomic.h Fri Dec 5 21:17:54 2008 (r185651) @@ -32,20 +32,9 @@ #error this file needs sys/cdefs.h as a prerequisite #endif - -#if defined(I686_CPU) -#define mb() __asm__ __volatile__ ("mfence;": : :"memory") -#define wmb() __asm__ __volatile__ ("sfence;": : :"memory") -#define rmb() __asm__ __volatile__ ("lfence;": : :"memory") -#else -/* - * do we need a serializing instruction? - */ -#define mb() -#define wmb() -#define rmb() -#endif - +#define mb() __asm __volatile("lock;addl $0,(%esp)") +#define wmb() __asm __volatile("lock;addl $0,(%esp)") +#define rmb() __asm __volatile("lock;addl $0,(%esp)") /* * Various simple operations on memory, each of which is atomic in the From jhb at FreeBSD.org Fri Dec 5 13:19:25 2008 From: jhb at FreeBSD.org (John Baldwin) Date: Fri Dec 5 13:19:39 2008 Subject: svn commit: r185652 - head/sys/libkern Message-ID: <200812052119.mB5LJPJp073491@svn.freebsd.org> Author: jhb Date: Fri Dec 5 21:19:24 2008 New Revision: 185652 URL: http://svn.freebsd.org/changeset/base/185652 Log: Add simple locking for the in-kernel iconv code. Translation operations do not need any locking. Opening and closing translators is serialized using an sx lock. Note: This depends on the earlier fix to kern_module.c to properly order MOD_UNLOAD events. MFC after: 2 months Modified: head/sys/libkern/iconv.c Modified: head/sys/libkern/iconv.c ============================================================================== --- head/sys/libkern/iconv.c Fri Dec 5 21:17:54 2008 (r185651) +++ head/sys/libkern/iconv.c Fri Dec 5 21:19:24 2008 (r185652) @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include "iconv_converter_if.h" @@ -52,6 +53,8 @@ MALLOC_DEFINE(M_ICONVDATA, "iconv_data", MODULE_VERSION(libiconv, 2); +static struct sx iconv_lock; + #ifdef notnow /* * iconv converter instance @@ -86,11 +89,16 @@ iconv_mod_unload(void) { struct iconv_cspair *csp; + sx_xlock(&iconv_lock); while ((csp = TAILQ_FIRST(&iconv_cslist)) != NULL) { if (csp->cp_refcount) return EBUSY; - iconv_unregister_cspair(csp); } + + while ((csp = TAILQ_FIRST(&iconv_cslist)) != NULL) + iconv_unregister_cspair(csp); + sx_xunlock(&iconv_lock); + sx_destroy(&iconv_lock); return 0; } @@ -102,6 +110,7 @@ iconv_mod_handler(module_t mod, int type switch (type) { case MOD_LOAD: error = 0; + sx_init(&iconv_lock, "iconv"); break; case MOD_UNLOAD: error = iconv_mod_unload(); @@ -311,7 +320,7 @@ iconv_sysctl_drvlist(SYSCTL_HANDLER_ARGS int error; error = 0; - + sx_slock(&iconv_lock); TAILQ_FOREACH(dcp, &iconv_converters, cc_link) { name = ICONV_CONVERTER_NAME(dcp); if (name == NULL) @@ -320,6 +329,7 @@ iconv_sysctl_drvlist(SYSCTL_HANDLER_ARGS if (error) break; } + sx_sunlock(&iconv_lock); if (error) return error; spc = 0; @@ -343,7 +353,7 @@ iconv_sysctl_cslist(SYSCTL_HANDLER_ARGS) error = 0; bzero(&csi, sizeof(csi)); csi.cs_version = ICONV_CSPAIR_INFO_VER; - + sx_slock(&iconv_lock); TAILQ_FOREACH(csp, &iconv_cslist, cp_link) { csi.cs_id = csp->cp_id; csi.cs_refcount = csp->cp_refcount; @@ -354,6 +364,7 @@ iconv_sysctl_cslist(SYSCTL_HANDLER_ARGS) if (error) break; } + sx_sunlock(&iconv_lock); return error; } @@ -387,9 +398,12 @@ iconv_sysctl_add(SYSCTL_HANDLER_ARGS) return EINVAL; if (iconv_lookupconv(din.ia_converter, &dcp) != 0) return EINVAL; + sx_xlock(&iconv_lock); error = iconv_register_cspair(din.ia_to, din.ia_from, dcp, NULL, &csp); - if (error) + if (error) { + sx_xunlock(&iconv_lock); return error; + } if (din.ia_datalen) { csp->cp_data = malloc(din.ia_datalen, M_ICONVDATA, M_WAITOK); error = copyin(din.ia_data, csp->cp_data, din.ia_datalen); @@ -400,10 +414,12 @@ iconv_sysctl_add(SYSCTL_HANDLER_ARGS) error = SYSCTL_OUT(req, &dout, sizeof(dout)); if (error) goto bad; + sx_xunlock(&iconv_lock); ICDEBUG("%s => %s, %d bytes\n",din.ia_from, din.ia_to, din.ia_datalen); return 0; bad: iconv_unregister_cspair(csp); + sx_xunlock(&iconv_lock); return error; } @@ -433,16 +449,22 @@ iconv_converter_handler(module_t mod, in switch (type) { case MOD_LOAD: + sx_xlock(&iconv_lock); error = iconv_register_converter(dcp); - if (error) + if (error) { + sx_xunlock(&iconv_lock); break; + } error = ICONV_CONVERTER_INIT(dcp); if (error) iconv_unregister_converter(dcp); + sx_xunlock(&iconv_lock); break; case MOD_UNLOAD: + sx_xlock(&iconv_lock); ICONV_CONVERTER_DONE(dcp); error = iconv_unregister_converter(dcp); + sx_xunlock(&iconv_lock); break; default: error = EINVAL; From gnn at FreeBSD.org Fri Dec 5 13:40:12 2008 From: gnn at FreeBSD.org (George V. Neville-Neil) Date: Fri Dec 5 13:40:18 2008 Subject: svn commit: r185655 - head/sys/dev/cxgb Message-ID: <200812052140.mB5LeCSG074056@svn.freebsd.org> Author: gnn Date: Fri Dec 5 21:40:11 2008 New Revision: 185655 URL: http://svn.freebsd.org/changeset/base/185655 Log: Re submit code to print the part and serial number for Chelsio cards. The original code was accidentally removed in another commit. MFC after: 1 day Modified: head/sys/dev/cxgb/cxgb_main.c Modified: head/sys/dev/cxgb/cxgb_main.c ============================================================================== --- head/sys/dev/cxgb/cxgb_main.c Fri Dec 5 21:32:30 2008 (r185654) +++ head/sys/dev/cxgb/cxgb_main.c Fri Dec 5 21:40:11 2008 (r185655) @@ -402,6 +402,8 @@ cxgb_controller_attach(device_t dev) int msi_needed, reg; #endif int must_load = 0; + char buf[80]; + sc = device_get_softc(dev); sc->dev = dev; sc->msi_count = 0; @@ -614,6 +616,11 @@ cxgb_controller_attach(device_t dev) G_FW_VERSION_MAJOR(vers), G_FW_VERSION_MINOR(vers), G_FW_VERSION_MICRO(vers)); + snprintf(buf, sizeof(buf), "%s\t E/C: %s S/N: %s", + ai->desc, + sc->params.vpd.ec, sc->params.vpd.sn); + device_set_desc_copy(dev, buf); + device_printf(sc->dev, "Firmware Version %s\n", &sc->fw_version[0]); callout_reset(&sc->cxgb_tick_ch, CXGB_TICKS(sc), cxgb_tick, sc); t3_add_attach_sysctls(sc); From schweikh at FreeBSD.org Fri Dec 5 14:04:53 2008 From: schweikh at FreeBSD.org (Jens Schweikhardt) Date: Fri Dec 5 14:04:59 2008 Subject: svn commit: r185656 - head/share/man/man7 Message-ID: <200812052204.mB5M4qlY074628@svn.freebsd.org> Author: schweikh Date: Fri Dec 5 22:04:52 2008 New Revision: 185656 URL: http://svn.freebsd.org/changeset/base/185656 Log: Correct a typo. Modified: head/share/man/man7/ports.7 Modified: head/share/man/man7/ports.7 ============================================================================== --- head/share/man/man7/ports.7 Fri Dec 5 21:40:11 2008 (r185655) +++ head/share/man/man7/ports.7 Fri Dec 5 22:04:52 2008 (r185656) @@ -322,7 +322,7 @@ To find ports that contain in either of the name, path, info fields, ignore the rest of the record. .Pp -By default the search is not case-nsensitive. +By default the search is not case-sensitive. In order to make it case-sensitive you can use the .Va icase variable: From rdivacky at FreeBSD.org Fri Dec 5 14:50:41 2008 From: rdivacky at FreeBSD.org (Roman Divacky) Date: Fri Dec 5 14:50:53 2008 Subject: svn commit: r185647 - in head/sys: kern sys In-Reply-To: <200812052050.mB5KoOcV072648@svn.freebsd.org> References: <200812052050.mB5KoOcV072648@svn.freebsd.org> Message-ID: <20081205224600.GA16948@freebsd.org> On Fri, Dec 05, 2008 at 08:50:24PM +0000, Konstantin Belousov wrote: > Author: kib > Date: Fri Dec 5 20:50:24 2008 > New Revision: 185647 > URL: http://svn.freebsd.org/changeset/base/185647 > > Log: > Several threads in a process may do vfork() simultaneously. Then, all > parent threads sleep on the parent' struct proc until corresponding > child releases the vmspace. Each sleep is interlocked with proc mutex of > the child, that triggers assertion in the sleepq_add(). The assertion > requires that at any time, all simultaneous sleepers for the channel use > the same interlock. > > Silent the assertion by using conditional variable allocated in the > child. Broadcast the variable event on exec() and exit(). > > Since struct proc * sleep wait channel is overloaded for several > unrelated events, I was unable to remove wakeups from the places where > cv_broadcast() is added, except exec(). are there any differences (performance etc.) in using condition variables instead of sleep/wakeup? From kostikbel at gmail.com Fri Dec 5 15:00:16 2008 From: kostikbel at gmail.com (Kostik Belousov) Date: Fri Dec 5 15:00:28 2008 Subject: svn commit: r185647 - in head/sys: kern sys In-Reply-To: <20081205224600.GA16948@freebsd.org> References: <200812052050.mB5KoOcV072648@svn.freebsd.org> <20081205224600.GA16948@freebsd.org> Message-ID: <20081205230002.GX2038@deviant.kiev.zoral.com.ua> On Fri, Dec 05, 2008 at 11:46:00PM +0100, Roman Divacky wrote: > On Fri, Dec 05, 2008 at 08:50:24PM +0000, Konstantin Belousov wrote: > > Author: kib > > Date: Fri Dec 5 20:50:24 2008 > > New Revision: 185647 > > URL: http://svn.freebsd.org/changeset/base/185647 > > > > Log: > > Several threads in a process may do vfork() simultaneously. Then, all > > parent threads sleep on the parent' struct proc until corresponding > > child releases the vmspace. Each sleep is interlocked with proc mutex of > > the child, that triggers assertion in the sleepq_add(). The assertion > > requires that at any time, all simultaneous sleepers for the channel use > > the same interlock. > > > > Silent the assertion by using conditional variable allocated in the > > child. Broadcast the variable event on exec() and exit(). > > > > Since struct proc * sleep wait channel is overloaded for several > > unrelated events, I was unable to remove wakeups from the places where > > cv_broadcast() is added, except exec(). > > are there any differences (performance etc.) in using condition variables > instead of sleep/wakeup? I do not think that there is any measurable difference. On the other hand, the patch makes struct proc bigger by int + pointer. This shall not be a problem too. Would I been able to convert _all_ uses of the struct proc * wait channel to cond vars operation, this may be measurable on some loads, since it would exclude spurious wakeups. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 195 bytes Desc: not available Url : http://lists.freebsd.org/pipermail/svn-src-head/attachments/20081205/a6f61ae1/attachment.pgp From mav at FreeBSD.org Fri Dec 5 17:31:08 2008 From: mav at FreeBSD.org (Alexander Motin) Date: Fri Dec 5 17:31:14 2008 Subject: svn commit: r185661 - head/sys/dev/sdhci Message-ID: <200812060131.mB61V7xX078929@svn.freebsd.org> Author: mav Date: Sat Dec 6 01:31:07 2008 New Revision: 185661 URL: http://svn.freebsd.org/changeset/base/185661 Log: Forget current bus power settings on full reset. Chip must be reconfigured. Do not issue command if there is no card, clock or power. Controller will not detect command timeout without clock active. Modified: head/sys/dev/sdhci/sdhci.c Modified: head/sys/dev/sdhci/sdhci.c ============================================================================== --- head/sys/dev/sdhci/sdhci.c Sat Dec 6 01:11:45 2008 (r185660) +++ head/sys/dev/sdhci/sdhci.c Sat Dec 6 01:31:07 2008 (r185661) @@ -301,8 +301,10 @@ sdhci_reset(struct sdhci_slot *slot, uin WR1(slot, SDHCI_SOFTWARE_RESET, mask); - if (mask & SDHCI_RESET_ALL) + if (mask & SDHCI_RESET_ALL) { slot->clock = 0; + slot->power = 0; + } /* Wait max 100 ms */ timeout = 100; @@ -904,8 +906,11 @@ sdhci_start_command(struct sdhci_slot *s /* Read controller present state. */ state = RD4(slot, SDHCI_PRESENT_STATE); - /* Do not issue command if there is no card. */ - if ((state & SDHCI_CARD_PRESENT) == 0) { + /* Do not issue command if there is no card, clock or power. + * Controller will not detect timeout without clock active. */ + if ((state & SDHCI_CARD_PRESENT) == 0 || + slot->power == 0 || + slot->clock == 0) { cmd->error = MMC_ERR_FAILED; slot->req = NULL; slot->curcmd = NULL; From ganbold at micom.mng.net Fri Dec 5 17:59:53 2008 From: ganbold at micom.mng.net (Ganbold) Date: Fri Dec 5 18:00:00 2008 Subject: svn commit: r185647 - in head/sys: kern sys In-Reply-To: <200812052050.mB5KoOcV072648@svn.freebsd.org> References: <200812052050.mB5KoOcV072648@svn.freebsd.org> Message-ID: <4939DC96.3040709@micom.mng.net> Konstantin Belousov wrote: > Author: kib > Date: Fri Dec 5 20:50:24 2008 > New Revision: 185647 > URL: http://svn.freebsd.org/changeset/base/185647 > > Log: > Several threads in a process may do vfork() simultaneously. Then, all > parent threads sleep on the parent' struct proc until corresponding > child releases the vmspace. Each sleep is interlocked with proc mutex of > the child, that triggers assertion in the sleepq_add(). The assertion > requires that at any time, all simultaneous sleepers for the channel use > the same interlock. > > Silent the assertion by using conditional variable allocated in the > child. Broadcast the variable event on exec() and exit(). > > Since struct proc * sleep wait channel is overloaded for several > unrelated events, I was unable to remove wakeups from the places where > cv_broadcast() is added, except exec(). > > Reported and tested by: ganbold > Suggested and reviewed by: jhb > MFC after: 2 week > Thanks a lot, Konstantin. Ganbold > Modified: > head/sys/kern/kern_exec.c > head/sys/kern/kern_exit.c > head/sys/kern/kern_fork.c > head/sys/kern/kern_proc.c > head/sys/sys/proc.h > > Modified: head/sys/kern/kern_exec.c > ============================================================================== > --- head/sys/kern/kern_exec.c Fri Dec 5 20:40:02 2008 (r185646) > +++ head/sys/kern/kern_exec.c Fri Dec 5 20:50:24 2008 (r185647) > @@ -609,7 +609,7 @@ interpret: > p->p_flag |= P_EXEC; > if (p->p_pptr && (p->p_flag & P_PPWAIT)) { > p->p_flag &= ~P_PPWAIT; > - wakeup(p->p_pptr); > + cv_broadcast(&p->p_pwait); > } > > /* > > Modified: head/sys/kern/kern_exit.c > ============================================================================== > --- head/sys/kern/kern_exit.c Fri Dec 5 20:40:02 2008 (r185646) > +++ head/sys/kern/kern_exit.c Fri Dec 5 20:50:24 2008 (r185647) > @@ -543,6 +543,7 @@ exit1(struct thread *td, int rv) > * proc lock. > */ > wakeup(p->p_pptr); > + cv_broadcast(&p->p_pwait); > sched_exit(p->p_pptr, td); > PROC_SLOCK(p); > p->p_state = PRS_ZOMBIE; > @@ -774,6 +775,7 @@ loop: > PROC_UNLOCK(p); > tdsignal(t, NULL, SIGCHLD, p->p_ksi); > wakeup(t); > + cv_broadcast(&p->p_pwait); > PROC_UNLOCK(t); > sx_xunlock(&proctree_lock); > return (0); > > Modified: head/sys/kern/kern_fork.c > ============================================================================== > --- head/sys/kern/kern_fork.c Fri Dec 5 20:40:02 2008 (r185646) > +++ head/sys/kern/kern_fork.c Fri Dec 5 20:50:24 2008 (r185647) > @@ -754,7 +754,7 @@ again: > */ > PROC_LOCK(p2); > while (p2->p_flag & P_PPWAIT) > - msleep(p1, &p2->p_mtx, PWAIT, "ppwait", 0); > + cv_wait(&p2->p_pwait, &p2->p_mtx); > PROC_UNLOCK(p2); > > /* > > Modified: head/sys/kern/kern_proc.c > ============================================================================== > --- head/sys/kern/kern_proc.c Fri Dec 5 20:40:02 2008 (r185646) > +++ head/sys/kern/kern_proc.c Fri Dec 5 20:50:24 2008 (r185647) > @@ -231,6 +231,7 @@ proc_init(void *mem, int size, int flags > bzero(&p->p_mtx, sizeof(struct mtx)); > mtx_init(&p->p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK); > mtx_init(&p->p_slock, "process slock", NULL, MTX_SPIN | MTX_RECURSE); > + cv_init(&p->p_pwait, "ppwait"); > TAILQ_INIT(&p->p_threads); /* all threads in proc */ > EVENTHANDLER_INVOKE(process_init, p); > p->p_stats = pstats_alloc(); > > Modified: head/sys/sys/proc.h > ============================================================================== > --- head/sys/sys/proc.h Fri Dec 5 20:40:02 2008 (r185646) > +++ head/sys/sys/proc.h Fri Dec 5 20:50:24 2008 (r185647) > @@ -40,6 +40,7 @@ > > #include /* For struct callout. */ > #include /* For struct klist. */ > +#include > #ifndef _KERNEL > #include > #endif > @@ -540,6 +541,7 @@ struct proc { > STAILQ_HEAD(, ktr_request) p_ktr; /* (o) KTR event queue. */ > LIST_HEAD(, mqueue_notifier) p_mqnotifier; /* (c) mqueue notifiers.*/ > struct kdtrace_proc *p_dtrace; /* (*) DTrace-specific data. */ > + struct cv p_pwait; /* (*) wait cv for exit/exec */ > }; > > #define p_session p_pgrp->pg_session > _______________________________________________ > svn-src-all@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/svn-src-all > To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org" > > > > -- If you teach your children to like computers and to know how to gamble then they'll always be interested in something and won't come to no real harm. From gnn at FreeBSD.org Fri Dec 5 18:10:53 2008 From: gnn at FreeBSD.org (George V. Neville-Neil) Date: Fri Dec 5 18:11:01 2008 Subject: svn commit: r185662 - in head/sys/dev/cxgb: . common Message-ID: <200812060210.mB62ArHr079732@svn.freebsd.org> Author: gnn Date: Sat Dec 6 02:10:53 2008 New Revision: 185662 URL: http://svn.freebsd.org/changeset/base/185662 Log: Bug fix to support N310 version of Chelsio cards (board ID 1088). Obtained from: Chelsio Inc. MFC after: 3 days Modified: head/sys/dev/cxgb/common/cxgb_t3_hw.c head/sys/dev/cxgb/cxgb_main.c Modified: head/sys/dev/cxgb/common/cxgb_t3_hw.c ============================================================================== --- head/sys/dev/cxgb/common/cxgb_t3_hw.c Sat Dec 6 01:31:07 2008 (r185661) +++ head/sys/dev/cxgb/common/cxgb_t3_hw.c Sat Dec 6 02:10:53 2008 (r185662) @@ -509,6 +509,12 @@ static struct adapter_info t3_adap_info[ F_GPIO6_OUT_VAL | F_GPIO7_OUT_VAL, { S_GPIO1, S_GPIO2, S_GPIO3, S_GPIO4 }, SUPPORTED_AUI, &mi1_mdio_ops, "Chelsio T304" }, + { 0 }, + { 1, 0, 0, 0, 0, + F_GPIO1_OEN | F_GPIO2_OEN | F_GPIO4_OEN | F_GPIO6_OEN | F_GPIO7_OEN | + F_GPIO10_OEN | F_GPIO1_OUT_VAL | F_GPIO6_OUT_VAL | F_GPIO10_OUT_VAL, + { S_GPIO9 }, SUPPORTED_10000baseT_Full | SUPPORTED_AUI, + &mi1_mdio_ext_ops, "Chelsio N310" } }; /* Modified: head/sys/dev/cxgb/cxgb_main.c ============================================================================== --- head/sys/dev/cxgb/cxgb_main.c Sat Dec 6 01:31:07 2008 (r185661) +++ head/sys/dev/cxgb/cxgb_main.c Sat Dec 6 02:10:53 2008 (r185662) @@ -281,6 +281,7 @@ struct cxgb_ident { {PCI_VENDOR_ID_CHELSIO, 0x0031, 3, "T3B20"}, {PCI_VENDOR_ID_CHELSIO, 0x0032, 1, "T3B02"}, {PCI_VENDOR_ID_CHELSIO, 0x0033, 4, "T3B04"}, + {PCI_VENDOR_ID_CHELSIO, 0x0035, 6, "N310E"}, {0, 0, 0, NULL} }; @@ -444,12 +445,14 @@ cxgb_controller_attach(device_t dev) return (ENXIO); } sc->udbs_rid = PCIR_BAR(2); - if ((sc->udbs_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, - &sc->udbs_rid, RF_ACTIVE)) == NULL) { + sc->udbs_res = NULL; + if (is_offload(sc) && + ((sc->udbs_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, + &sc->udbs_rid, RF_ACTIVE)) == NULL)) { device_printf(dev, "Cannot allocate BAR region 1\n"); error = ENXIO; goto out; - } + } snprintf(sc->lockbuf, ADAPTER_LOCK_NAME_LEN, "cxgb controller lock %d", device_get_unit(dev)); From kientzle at FreeBSD.org Fri Dec 5 21:52:02 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 21:52:09 2008 Subject: svn commit: r185664 - head/lib/libarchive Message-ID: <200812060552.mB65q160084189@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 05:52:01 2008 New Revision: 185664 URL: http://svn.freebsd.org/changeset/base/185664 Log: 2 is more portable than STDERR_FILENO Modified: head/lib/libarchive/archive_check_magic.c Modified: head/lib/libarchive/archive_check_magic.c ============================================================================== --- head/lib/libarchive/archive_check_magic.c Sat Dec 6 05:41:25 2008 (r185663) +++ head/lib/libarchive/archive_check_magic.c Sat Dec 6 05:52:01 2008 (r185664) @@ -46,7 +46,7 @@ __FBSDID("$FreeBSD$"); static void errmsg(const char *m) { - write(STDERR_FILENO, m, strlen(m)); + write(2, m, strlen(m)); } static void From kientzle at FreeBSD.org Fri Dec 5 21:53:05 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 21:53:13 2008 Subject: svn commit: r185665 - head/lib/libarchive Message-ID: <200812060553.mB65r5Ub084246@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 05:53:05 2008 New Revision: 185665 URL: http://svn.freebsd.org/changeset/base/185665 Log: Windows build now uses PLATFORM_CONFIG_H macro, so we can eliminate the special case for it. Modified: head/lib/libarchive/archive_platform.h Modified: head/lib/libarchive/archive_platform.h ============================================================================== --- head/lib/libarchive/archive_platform.h Sat Dec 6 05:52:01 2008 (r185664) +++ head/lib/libarchive/archive_platform.h Sat Dec 6 05:53:05 2008 (r185665) @@ -39,10 +39,7 @@ /* archive.h and archive_entry.h require this. */ #define __LIBARCHIVE_BUILD 1 -#ifdef _WIN32 -#include "config_windows.h" -#include "archive_windows.h" -#elif defined(PLATFORM_CONFIG_H) +#if defined(PLATFORM_CONFIG_H) /* Use hand-built config.h in environments that need it. */ #include PLATFORM_CONFIG_H #elif defined(HAVE_CONFIG_H) From kientzle at FreeBSD.org Fri Dec 5 21:55:47 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 21:55:58 2008 Subject: svn commit: r185666 - head/lib/libarchive Message-ID: <200812060555.mB65tl76084341@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 05:55:46 2008 New Revision: 185666 URL: http://svn.freebsd.org/changeset/base/185666 Log: Minor portability: Declare 'r' only within the conditional block where it's used; S_ISLNK is more portable than S_ISLINK. Modified: head/lib/libarchive/archive_write_disk.c Modified: head/lib/libarchive/archive_write_disk.c ============================================================================== --- head/lib/libarchive/archive_write_disk.c Sat Dec 6 05:53:05 2008 (r185665) +++ head/lib/libarchive/archive_write_disk.c Sat Dec 6 05:55:46 2008 (r185666) @@ -518,7 +518,6 @@ write_data_block(struct archive_write_di { ssize_t bytes_written = 0; ssize_t block_size = 0, bytes_to_write; - int r; if (a->filesize == 0 || a->fd < 0) { archive_set_error(&a->archive, 0, @@ -528,6 +527,7 @@ write_data_block(struct archive_write_di if (a->flags & ARCHIVE_EXTRACT_SPARSE) { #if HAVE_STRUCT_STAT_ST_BLKSIZE + int r; if ((r = _archive_write_disk_lazy_stat(a)) != ARCHIVE_OK) return (r); block_size = a->pst->st_blksize; @@ -1752,7 +1752,7 @@ set_time(int fd, int mode, const char *n (void)mtime_nsec; /* UNUSED */ times.actime = atime; times.modtime = mtime; - if (S_ISLINK(mode)) + if (S_ISLNK(mode)) return (ARCHIVE_OK); return (utime(name, ×)); } From kientzle at FreeBSD.org Fri Dec 5 21:56:44 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 21:56:55 2008 Subject: svn commit: r185667 - head/lib/libarchive Message-ID: <200812060556.mB65ui5s084395@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 05:56:43 2008 New Revision: 185667 URL: http://svn.freebsd.org/changeset/base/185667 Log: New internal archive_string_concat utility function. Modified: head/lib/libarchive/archive_string.c head/lib/libarchive/archive_string.h Modified: head/lib/libarchive/archive_string.c ============================================================================== --- head/lib/libarchive/archive_string.c Sat Dec 6 05:55:46 2008 (r185666) +++ head/lib/libarchive/archive_string.c Sat Dec 6 05:56:43 2008 (r185667) @@ -70,6 +70,18 @@ __archive_string_copy(struct archive_str } void +__archive_string_concat(struct archive_string *dest, struct archive_string *src) +{ + if (src->length > 0) { + if (__archive_string_ensure(dest, dest->length + src->length + 1) == NULL) + __archive_errx(1, "Out of memory"); + memcpy(dest->s + dest->length, src->s, src->length); + dest->length += src->length; + dest->s[dest->length] = 0; + } +} + +void __archive_string_free(struct archive_string *as) { as->length = 0; Modified: head/lib/libarchive/archive_string.h ============================================================================== --- head/lib/libarchive/archive_string.h Sat Dec 6 05:55:46 2008 (r185666) +++ head/lib/libarchive/archive_string.h Sat Dec 6 05:56:43 2008 (r185667) @@ -92,6 +92,12 @@ __archive_string_copy(struct archive_str #define archive_string_copy(dest, src) \ __archive_string_copy(dest, src) +/* Concatenate one archive_string to another */ +void +__archive_string_concat(struct archive_string *dest, struct archive_string *src); +#define archive_string_concat(dest, src) \ + __archive_string_concat(dest, src) + /* Ensure that the underlying buffer is at least as large as the request. */ struct archive_string * __archive_string_ensure(struct archive_string *, size_t); From kientzle at FreeBSD.org Fri Dec 5 21:58:25 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 21:58:36 2008 Subject: svn commit: r185668 - head/lib/libarchive/test Message-ID: <200812060558.mB65wPPq084462@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 05:58:24 2008 New Revision: 185668 URL: http://svn.freebsd.org/changeset/base/185668 Log: Recover from a test failure here. Modified: head/lib/libarchive/test/test_read_format_gtar_sparse.c Modified: head/lib/libarchive/test/test_read_format_gtar_sparse.c ============================================================================== --- head/lib/libarchive/test/test_read_format_gtar_sparse.c Sat Dec 6 05:56:43 2008 (r185667) +++ head/lib/libarchive/test/test_read_format_gtar_sparse.c Sat Dec 6 05:58:24 2008 (r185668) @@ -201,7 +201,10 @@ verify_archive_file(const char *name, st while (ac->filename != NULL) { struct contents *cts = ac->contents; - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); + if (!assertEqualIntA(a, 0, archive_read_next_header(a, &ae))) { + assert(0 == archive_read_finish(a)); + return; + } failure("Name mismatch in archive %s", name); assertEqualString(ac->filename, archive_entry_pathname(ae)); From kientzle at FreeBSD.org Fri Dec 5 21:59:47 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 21:59:53 2008 Subject: svn commit: r185669 - head/lib/libarchive/test Message-ID: <200812060559.mB65xkPc084520@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 05:59:46 2008 New Revision: 185669 URL: http://svn.freebsd.org/changeset/base/185669 Log: Better reporting of test failures. Modified: head/lib/libarchive/test/test_read_pax_truncated.c Modified: head/lib/libarchive/test/test_read_pax_truncated.c ============================================================================== --- head/lib/libarchive/test/test_read_pax_truncated.c Sat Dec 6 05:58:24 2008 (r185668) +++ head/lib/libarchive/test/test_read_pax_truncated.c Sat Dec 6 05:59:46 2008 (r185669) @@ -98,9 +98,13 @@ DEFINE_TEST(test_read_pax_truncated) * does not return an error if it can't consume * it.) */ if (i < 1536 + 512*((filedata_size + 511)/512) + 512) { - assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); + failure("i=%d minsize=%d", i, + 1536 + 512*((filedata_size + 511)/512) + 512); + assertEqualIntA(a, ARCHIVE_FATAL, + archive_read_next_header(a, &ae)); } else { - assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_EOF, + archive_read_next_header(a, &ae)); } wrap_up: assert(0 == archive_read_close(a)); @@ -141,9 +145,11 @@ DEFINE_TEST(test_read_pax_truncated) * does not return an error if it can't consume * it.) */ if (i < 1536 + 512*((filedata_size + 511)/512) + 512) { - assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_FATAL, + archive_read_next_header(a, &ae)); } else { - assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_EOF, + archive_read_next_header(a, &ae)); } wrap_up2: assert(0 == archive_read_close(a)); From kientzle at FreeBSD.org Fri Dec 5 22:00:52 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 22:01:04 2008 Subject: svn commit: r185670 - head/lib/libarchive/test Message-ID: <200812060600.mB660qUW084605@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 06:00:52 2008 New Revision: 185670 URL: http://svn.freebsd.org/changeset/base/185670 Log: Style improvements. Modified: head/lib/libarchive/test/test_read_format_cpio_bin_bz2.c Modified: head/lib/libarchive/test/test_read_format_cpio_bin_bz2.c ============================================================================== --- head/lib/libarchive/test/test_read_format_cpio_bin_bz2.c Sat Dec 6 05:59:46 2008 (r185669) +++ head/lib/libarchive/test/test_read_format_cpio_bin_bz2.c Sat Dec 6 06:00:52 2008 (r185670) @@ -37,10 +37,12 @@ DEFINE_TEST(test_read_format_cpio_bin_bz struct archive_entry *ae; struct archive *a; assert((a = archive_read_new()) != NULL); - assert(0 == archive_read_support_compression_all(a)); - assert(0 == archive_read_support_format_all(a)); - assert(0 == archive_read_open_memory(a, archive, sizeof(archive))); - assert(0 == archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assert(archive_compression(a) == ARCHIVE_COMPRESSION_BZIP2); assert(archive_format(a) == ARCHIVE_FORMAT_CPIO_BIN_LE); assert(0 == archive_read_close(a)); From kientzle at FreeBSD.org Fri Dec 5 22:01:50 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 22:02:02 2008 Subject: svn commit: r185671 - head/lib/libarchive/test Message-ID: <200812060601.mB661ogY084658@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 06:01:50 2008 New Revision: 185671 URL: http://svn.freebsd.org/changeset/base/185671 Log: Style: skipping() function correctly counts this as a skipped test. Modified: head/lib/libarchive/test/test_write_disk_perms.c Modified: head/lib/libarchive/test/test_write_disk_perms.c ============================================================================== --- head/lib/libarchive/test/test_write_disk_perms.c Sat Dec 6 06:00:52 2008 (r185670) +++ head/lib/libarchive/test/test_write_disk_perms.c Sat Dec 6 06:01:50 2008 (r185671) @@ -272,7 +272,7 @@ DEFINE_TEST(test_write_disk_perms) * Current user must belong to at least two groups or * else we can't test setting the GID to another group. */ - printf("Current user can't test gid restore: must belong to more than one group.\n"); + skipping("Current user can't test gid restore: must belong to more than one group."); } else { /* * Write a regular file with ARCHIVE_EXTRACT_PERM & SGID bit From kientzle at FreeBSD.org Fri Dec 5 22:02:27 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 22:02:37 2008 Subject: svn commit: r185672 - head/lib/libarchive/test Message-ID: <200812060602.mB662RoX084707@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 06:02:26 2008 New Revision: 185672 URL: http://svn.freebsd.org/changeset/base/185672 Log: Recover after test failure. Modified: head/lib/libarchive/test/test_write_format_cpio.c Modified: head/lib/libarchive/test/test_write_format_cpio.c ============================================================================== --- head/lib/libarchive/test/test_write_format_cpio.c Sat Dec 6 06:01:50 2008 (r185671) +++ head/lib/libarchive/test/test_write_format_cpio.c Sat Dec 6 06:02:26 2008 (r185672) @@ -134,7 +134,10 @@ test_format(int (*set_format)(struct arc assertA(0 == archive_read_support_compression_all(a)); assertA(0 == archive_read_open_memory(a, buff, used)); - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); + if (!assertEqualIntA(a, 0, archive_read_next_header(a, &ae))) { + archive_read_finish(a); + return; + } assertEqualInt(1, archive_entry_mtime(ae)); /* Not the same as above: cpio doesn't store hi-res times. */ From kientzle at FreeBSD.org Fri Dec 5 22:12:25 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 22:12:36 2008 Subject: svn commit: r185674 - head/lib/libarchive Message-ID: <200812060612.mB66COVb084955@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 06:12:24 2008 New Revision: 185674 URL: http://svn.freebsd.org/changeset/base/185674 Log: A couple of portability fixes from Joerg Sonnenberger Modified: head/lib/libarchive/archive_endian.h Modified: head/lib/libarchive/archive_endian.h ============================================================================== --- head/lib/libarchive/archive_endian.h Sat Dec 6 06:08:12 2008 (r185673) +++ head/lib/libarchive/archive_endian.h Sat Dec 6 06:12:24 2008 (r185674) @@ -35,14 +35,14 @@ #define ARCHIVE_ENDIAN_H_INCLUDED -/* Watcom C++ doesn't support 'inline' in C code. (For any version?) */ -#if defined( __WATCOMC__ ) - #define inline -#endif - -/* Visual C++ 6.0 doesn't support 'inline' in C code. (Does VC7? VC8?) */ -#if defined(_MSC_VER) - #define inline +/* + * Disabling inline keyword for compilers known to choke on it: + * - Watcom C++ in C code. (For any version?) + * - SGI MIPSpro + * - Microsoft Visual C++ 6.0 (supposedly newer versions too) + */ +#if defined(__WATCOMC__) || defined(__sgi) || defined(_MSC_VER) +#define inline #endif /* Alignment-agnostic encode/decode bytestream to/from little/big endian. */ From kientzle at FreeBSD.org Fri Dec 5 22:17:18 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 22:17:25 2008 Subject: svn commit: r185675 - head/lib/libarchive Message-ID: <200812060617.mB66HIY1085074@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 06:17:18 2008 New Revision: 185675 URL: http://svn.freebsd.org/changeset/base/185675 Log: Style fixes: * Wrap long declarations to fit 80 chars * #undef macros that shouldn't be exported * Organize the version-dependent conditionals a bit more consistently Speculative: * libarchive 3.0 will (eventually) use int64_t instead of off_t. This is an attempt to avoid some the headaches caused by Linux LFS. (I'll still have to do ugly things for the struct stat references in archive_entry.h, of course.) Modified: head/lib/libarchive/archive.h Modified: head/lib/libarchive/archive.h ============================================================================== --- head/lib/libarchive/archive.h Sat Dec 6 06:12:24 2008 (r185674) +++ head/lib/libarchive/archive.h Sat Dec 6 06:17:18 2008 (r185675) @@ -82,7 +82,6 @@ # define __LA_DECL #endif - #ifdef __cplusplus extern "C" { #endif @@ -114,13 +113,13 @@ extern "C" { * (ARCHIVE_API_VERSION * 1000000 + ARCHIVE_API_FEATURE * 1000) * #endif */ -#define ARCHIVE_VERSION_NUMBER 2005005 +#define ARCHIVE_VERSION_NUMBER 2005903 __LA_DECL int archive_version_number(void); /* * Textual name/version of the library, useful for version displays. */ -#define ARCHIVE_VERSION_STRING "libarchive 2.5.5" +#define ARCHIVE_VERSION_STRING "libarchive 2.5.903a" __LA_DECL const char * archive_version_string(void); #if ARCHIVE_VERSION_NUMBER < 3000000 @@ -185,20 +184,37 @@ struct archive_entry; */ /* Returns pointer and size of next block of data from archive. */ -typedef __LA_SSIZE_T archive_read_callback(struct archive *, void *_client_data, - const void **_buffer); +typedef __LA_SSIZE_T archive_read_callback(struct archive *, + void *_client_data, const void **_buffer); + /* Skips at most request bytes from archive and returns the skipped amount */ #if ARCHIVE_VERSION_NUMBER < 2000000 -typedef __LA_SSIZE_T archive_skip_callback(struct archive *, void *_client_data, - size_t request); +/* Libarchive 1.0 used ssize_t for the return, which is only 32 bits + * on most 32-bit platforms; not large enough. */ +typedef __LA_SSIZE_T archive_skip_callback(struct archive *, + void *_client_data, size_t request); +#elif ARCHIVE_VERSION_NUMBER < 3000000 +/* Libarchive 2.0 used off_t here, but that is a bad idea on Linux and a + * few other platforms where off_t varies with build settings. */ +typedef off_t archive_skip_callback(struct archive *, + void *_client_data, off_t request); #else -typedef off_t archive_skip_callback(struct archive *, void *_client_data, - off_t request); +/* Libarchive 3.0 uses int64_t here, which is actually guaranteed to be + * 64 bits on every platform. */ +typedef __LA_INT64_T archive_skip_callback(struct archive *, + void *_client_data, __LA_INT64_T request); #endif + /* Returns size actually written, zero on EOF, -1 on error. */ -typedef __LA_SSIZE_T archive_write_callback(struct archive *, void *_client_data, - const void *_buffer, size_t _length); +typedef __LA_SSIZE_T archive_write_callback(struct archive *, + void *_client_data, + const void *_buffer, size_t _length); + +#if ARCHIVE_VERSION_NUMBER < 3000000 +/* Open callback is actually never needed; remove it in libarchive 3.0. */ typedef int archive_open_callback(struct archive *, void *_client_data); +#endif + typedef int archive_close_callback(struct archive *, void *_client_data); /* @@ -209,6 +225,7 @@ typedef int archive_close_callback(struc #define ARCHIVE_COMPRESSION_BZIP2 2 #define ARCHIVE_COMPRESSION_COMPRESS 3 #define ARCHIVE_COMPRESSION_PROGRAM 4 +#define ARCHIVE_COMPRESSION_LZMA 5 /* * Codes returned by archive_format. @@ -333,15 +350,23 @@ __LA_DECL int archive_read_next_header __LA_DECL __LA_INT64_T archive_read_header_position(struct archive *); /* Read data from the body of an entry. Similar to read(2). */ -__LA_DECL __LA_SSIZE_T archive_read_data(struct archive *, void *, size_t); +__LA_DECL __LA_SSIZE_T archive_read_data(struct archive *, + void *, size_t); + /* * A zero-copy version of archive_read_data that also exposes the file offset * of each returned block. Note that the client has no way to specify * the desired size of the block. The API does guarantee that offsets will * be strictly increasing and that returned blocks will not overlap. */ +#if ARCHIVE_VERSION_NUMBER < 3000000 +__LA_DECL int archive_read_data_block(struct archive *a, + const void **buff, size_t *size, off_t *offset); +#else __LA_DECL int archive_read_data_block(struct archive *a, - const void **buff, size_t *size, off_t *offset); + const void **buff, size_t *size, + __LA_INT64_T *offset); +#endif /*- * Some convenience functions that are built on archive_read_data: @@ -350,8 +375,8 @@ __LA_DECL int archive_read_data_block( * 'into_fd': writes data to specified filedes */ __LA_DECL int archive_read_data_skip(struct archive *); -__LA_DECL int archive_read_data_into_buffer(struct archive *, void *buffer, - __LA_SSIZE_T len); +__LA_DECL int archive_read_data_into_buffer(struct archive *, + void *buffer, __LA_SSIZE_T len); __LA_DECL int archive_read_data_into_fd(struct archive *, int fd); /*- @@ -414,12 +439,11 @@ __LA_DECL void archive_read_extract_set __LA_DECL int archive_read_close(struct archive *); /* Release all resources and destroy the object. */ /* Note that archive_read_finish will call archive_read_close for you. */ -#if ARCHIVE_VERSION_NUMBER >= 2000000 -__LA_DECL int archive_read_finish(struct archive *); -#else -/* Temporarily allow library to compile with either 1.x or 2.0 API. */ +#if ARCHIVE_VERSION_NUMBER < 2000000 /* Erroneously declared to return void in libarchive 1.x */ __LA_DECL void archive_read_finish(struct archive *); +#else +__LA_DECL int archive_read_finish(struct archive *); #endif /*- @@ -491,22 +515,36 @@ __LA_DECL int archive_write_open_memor */ __LA_DECL int archive_write_header(struct archive *, struct archive_entry *); -#if ARCHIVE_VERSION_NUMBER >= 2000000 -__LA_DECL __LA_SSIZE_T archive_write_data(struct archive *, const void *, size_t); -#else -/* Temporarily allow library to compile with either 1.x or 2.0 API. */ +#if ARCHIVE_VERSION_NUMBER < 2000000 /* This was erroneously declared to return "int" in libarchive 1.x. */ -__LA_DECL int archive_write_data(struct archive *, const void *, size_t); +__LA_DECL int archive_write_data(struct archive *, + const void *, size_t); +#else +/* Libarchive 2.0 and later return ssize_t here. */ +__LA_DECL __LA_SSIZE_T archive_write_data(struct archive *, + const void *, size_t); +#endif + +#if ARCHIVE_VERSION_NUMBER < 3000000 +/* Libarchive 1.x and 2.x use off_t for the argument, but that's not + * stable on Linux. */ +__LA_DECL __LA_SSIZE_T archive_write_data_block(struct archive *, + const void *, size_t, off_t); +#else +/* Libarchive 3.0 uses explicit int64_t to ensure consistent 64-bit support. */ +__LA_DECL __LA_SSIZE_T archive_write_data_block(struct archive *, + const void *, size_t, __LA_INT64_T); #endif -__LA_DECL __LA_SSIZE_T archive_write_data_block(struct archive *, const void *, size_t, off_t); __LA_DECL int archive_write_finish_entry(struct archive *); __LA_DECL int archive_write_close(struct archive *); -#if ARCHIVE_VERSION_NUMBER >= 2000000 -__LA_DECL int archive_write_finish(struct archive *); -#else -/* Temporarily allow library to compile with either 1.x or 2.0 API. */ +#if ARCHIVE_VERSION_NUMBER < 2000000 /* Return value was incorrect in libarchive 1.x. */ __LA_DECL void archive_write_finish(struct archive *); +#else +/* Libarchive 2.x and later returns an error if this fails. */ +/* It can fail if the archive wasn't already closed, in which case + * archive_write_finish() will implicitly call archive_write_close(). */ +__LA_DECL int archive_write_finish(struct archive *); #endif /*- @@ -589,5 +627,9 @@ __LA_DECL void archive_copy_error(stru /* This is meaningless outside of this header. */ #undef __LA_DECL +#undef __LA_GID_T +#undef __LA_INT64_T +#undef __LA_SSIZE_T +#undef __LA_UID_T #endif /* !ARCHIVE_H_INCLUDED */ From kientzle at FreeBSD.org Fri Dec 5 22:18:47 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 22:18:58 2008 Subject: svn commit: r185676 - head/lib/libarchive Message-ID: <200812060618.mB66IkaG085202@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 06:18:46 2008 New Revision: 185676 URL: http://svn.freebsd.org/changeset/base/185676 Log: Structure declarations can't be dllexported. Modified: head/lib/libarchive/archive_entry.h Modified: head/lib/libarchive/archive_entry.h ============================================================================== --- head/lib/libarchive/archive_entry.h Sat Dec 6 06:17:18 2008 (r185675) +++ head/lib/libarchive/archive_entry.h Sat Dec 6 06:18:46 2008 (r185676) @@ -441,7 +441,7 @@ __LA_DECL int archive_entry_xattr_next(s * Note that archive_entry_size() is reset to zero if the file * body should not be written to the archive. Pay attention! */ -__LA_DECL struct archive_entry_linkresolver; +struct archive_entry_linkresolver; /* * There are three different strategies for marking hardlinks. From kientzle at FreeBSD.org Fri Dec 5 22:20:21 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 22:20:33 2008 Subject: svn commit: r185677 - head/lib/libarchive Message-ID: <200812060620.mB66KLpp085267@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 06:20:21 2008 New Revision: 185677 URL: http://svn.freebsd.org/changeset/base/185677 Log: Use GCC-specific dead function markers only when using GCC. Modified: head/lib/libarchive/archive_private.h Modified: head/lib/libarchive/archive_private.h ============================================================================== --- head/lib/libarchive/archive_private.h Sat Dec 6 06:18:46 2008 (r185676) +++ head/lib/libarchive/archive_private.h Sat Dec 6 06:20:21 2008 (r185677) @@ -31,6 +31,13 @@ #include "archive.h" #include "archive_string.h" +#if defined(__GNUC__) && (__GNUC__ > 2 || \ + (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) +#define __LA_DEAD __attribute__((__noreturn__)) +#else +#define __LA_DEAD +#endif + #define ARCHIVE_WRITE_MAGIC (0xb0c5c0deU) #define ARCHIVE_READ_MAGIC (0xdeb0c5U) #define ARCHIVE_WRITE_DISK_MAGIC (0xc001b0c5U) @@ -92,7 +99,7 @@ struct archive { void __archive_check_magic(struct archive *, unsigned int magic, unsigned int state, const char *func); -void __archive_errx(int retvalue, const char *msg) __dead2; +void __archive_errx(int retvalue, const char *msg) __LA_DEAD; #define err_combine(a,b) ((a) < (b) ? (a) : (b)) From kientzle at FreeBSD.org Fri Dec 5 22:23:37 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 22:23:43 2008 Subject: svn commit: r185678 - head/lib/libarchive Message-ID: <200812060623.mB66Nb3C085369@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 06:23:37 2008 New Revision: 185678 URL: http://svn.freebsd.org/changeset/base/185678 Log: Style: tabs after #define Modified: head/lib/libarchive/archive_private.h Modified: head/lib/libarchive/archive_private.h ============================================================================== --- head/lib/libarchive/archive_private.h Sat Dec 6 06:20:21 2008 (r185677) +++ head/lib/libarchive/archive_private.h Sat Dec 6 06:23:37 2008 (r185678) @@ -40,13 +40,13 @@ #define ARCHIVE_WRITE_MAGIC (0xb0c5c0deU) #define ARCHIVE_READ_MAGIC (0xdeb0c5U) -#define ARCHIVE_WRITE_DISK_MAGIC (0xc001b0c5U) +#define ARCHIVE_WRITE_DISK_MAGIC (0xc001b0c5U) #define ARCHIVE_STATE_ANY 0xFFFFU #define ARCHIVE_STATE_NEW 1U #define ARCHIVE_STATE_HEADER 2U #define ARCHIVE_STATE_DATA 4U -#define ARCHIVE_STATE_DATA_END 8U +#define ARCHIVE_STATE_DATA_END 8U #define ARCHIVE_STATE_EOF 0x10U #define ARCHIVE_STATE_CLOSED 0x20U #define ARCHIVE_STATE_FATAL 0x8000U From kientzle at FreeBSD.org Fri Dec 5 22:45:16 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 22:45:29 2008 Subject: svn commit: r185679 - head/lib/libarchive Message-ID: <200812060645.mB66jFQ7085836@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 06:45:15 2008 New Revision: 185679 URL: http://svn.freebsd.org/changeset/base/185679 Log: MfP4: Big read filter refactoring. This is an attempt to eliminate a lot of redundant code from the read ("decompression") filters by changing them to juggle arbitrary-sized blocks and consolidate reblocking code at a single point in archive_read.c. Along the way, I've changed the internal read/consume API used by the format handlers to a slightly different style originally suggested by des@. It does seem to simplify a lot of common cases. The most dramatic change is, of course, to archive_read_support_compression_none(), which has just evaporated into a no-op as the blocking code this used to hold has all been moved up a level. There's at least one more big round of refactoring yet to come before the individual filters are as straightforward as I think they should be... Modified: head/lib/libarchive/archive_read.c head/lib/libarchive/archive_read_private.h head/lib/libarchive/archive_read_support_compression_all.c head/lib/libarchive/archive_read_support_compression_bzip2.c head/lib/libarchive/archive_read_support_compression_compress.c head/lib/libarchive/archive_read_support_compression_gzip.c head/lib/libarchive/archive_read_support_compression_none.c head/lib/libarchive/archive_read_support_compression_program.c head/lib/libarchive/archive_read_support_format_ar.c head/lib/libarchive/archive_read_support_format_cpio.c head/lib/libarchive/archive_read_support_format_empty.c head/lib/libarchive/archive_read_support_format_iso9660.c head/lib/libarchive/archive_read_support_format_mtree.c head/lib/libarchive/archive_read_support_format_tar.c head/lib/libarchive/archive_read_support_format_zip.c Modified: head/lib/libarchive/archive_read.c ============================================================================== --- head/lib/libarchive/archive_read.c Sat Dec 6 06:23:37 2008 (r185678) +++ head/lib/libarchive/archive_read.c Sat Dec 6 06:45:15 2008 (r185679) @@ -53,9 +53,10 @@ __FBSDID("$FreeBSD$"); #include "archive_private.h" #include "archive_read_private.h" -static void choose_decompressor(struct archive_read *, const void*, size_t); +#define minimum(a, b) (a < b ? a : b) + +static int build_stream(struct archive_read *); static int choose_format(struct archive_read *); -static off_t dummy_skip(struct archive_read *, off_t); /* * Allocate, initialize and return a struct archive object. @@ -74,8 +75,15 @@ archive_read_new(void) a->archive.state = ARCHIVE_STATE_NEW; a->entry = archive_entry_new(); - /* We always support uncompressed archives. */ - archive_read_support_compression_none(&a->archive); + /* Initialize reblocking logic. */ + a->buffer_size = 64 * 1024; /* 64k */ + a->buffer = (char *)malloc(a->buffer_size); + a->next = a->buffer; + if (a->buffer == NULL) { + archive_entry_free(a->entry); + free(a); + return (NULL); + } return (&a->archive); } @@ -108,6 +116,33 @@ archive_read_open(struct archive *a, voi client_reader, NULL, client_closer); } +static ssize_t +client_read_proxy(struct archive_read_source *self, const void **buff) +{ + return (self->archive->client.reader)((struct archive *)self->archive, + self->data, buff); +} + +static int64_t +client_skip_proxy(struct archive_read_source *self, int64_t request) +{ + return (self->archive->client.skipper)((struct archive *)self->archive, + self->data, request); +} + +static int +client_close_proxy(struct archive_read_source *self) +{ + int r = ARCHIVE_OK; + + if (self->archive->client.closer != NULL) + r = (self->archive->client.closer)((struct archive *)self->archive, + self->data); + free(self); + return (r); +} + + int archive_read_open2(struct archive *_a, void *client_data, archive_open_callback *client_opener, @@ -116,28 +151,15 @@ archive_read_open2(struct archive *_a, v archive_close_callback *client_closer) { struct archive_read *a = (struct archive_read *)_a; - const void *buffer; - ssize_t bytes_read; int e; - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, "archive_read_open"); + __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, + "archive_read_open"); if (client_reader == NULL) __archive_errx(1, "No reader function provided to archive_read_open"); - /* - * Set these NULL initially. If the open or initial read fails, - * we'll leave them NULL to indicate that the file is invalid. - * (In particular, this helps ensure that the closer doesn't - * get called more than once.) - */ - a->client_opener = NULL; - a->client_reader = NULL; - a->client_skipper = NULL; - a->client_closer = NULL; - a->client_data = NULL; - /* Open data source. */ if (client_opener != NULL) { e =(client_opener)(&a->archive, client_data); @@ -149,129 +171,103 @@ archive_read_open2(struct archive *_a, v } } - /* Read first block now for compress format detection. */ - bytes_read = (client_reader)(&a->archive, client_data, &buffer); - - if (bytes_read < 0) { - /* If the first read fails, close before returning error. */ - if (client_closer) - (client_closer)(&a->archive, client_data); - /* client_reader should have already set error information. */ - return (ARCHIVE_FATAL); - } + /* Save the client functions and mock up the initial source. */ + a->client.opener = client_opener; /* Do we need to remember this? */ + a->client.reader = client_reader; + a->client.skipper = client_skipper; + a->client.closer = client_closer; + a->client.data = client_data; - /* Now that the client callbacks have worked, remember them. */ - a->client_opener = client_opener; /* Do we need to remember this? */ - a->client_reader = client_reader; - a->client_skipper = client_skipper; - a->client_closer = client_closer; - a->client_data = client_data; - - /* Select a decompression routine. */ - choose_decompressor(a, buffer, (size_t)bytes_read); - if (a->decompressor == NULL) - return (ARCHIVE_FATAL); + { + struct archive_read_source *source; - /* Initialize decompression routine with the first block of data. */ - e = (a->decompressor->init)(a, buffer, (size_t)bytes_read); + source = calloc(1, sizeof(*source)); + if (source == NULL) + return (ARCHIVE_FATAL); + source->reader = NULL; + source->upstream = NULL; + source->archive = a; + source->data = client_data; + source->read = client_read_proxy; + source->skip = client_skip_proxy; + source->close = client_close_proxy; + a->source = source; + } + + /* In case there's no filter. */ + a->archive.compression_code = ARCHIVE_COMPRESSION_NONE; + a->archive.compression_name = "none"; + /* Build out the input pipeline. */ + e = build_stream(a); if (e == ARCHIVE_OK) a->archive.state = ARCHIVE_STATE_HEADER; - /* - * If the decompressor didn't register a skip function, provide a - * dummy compression-layer skip function. - */ - if (a->decompressor->skip == NULL) - a->decompressor->skip = dummy_skip; - return (e); } /* - * Allow each registered decompression routine to bid on whether it - * wants to handle this stream. Return index of winning bidder. + * Allow each registered stream transform to bid on whether + * it wants to handle this stream. Repeat until we've finished + * building the pipeline. */ -static void -choose_decompressor(struct archive_read *a, - const void *buffer, size_t bytes_read) +static int +build_stream(struct archive_read *a) { - int decompression_slots, i, bid, best_bid; - struct decompressor_t *decompressor, *best_decompressor; + int number_readers, i, bid, best_bid; + struct archive_reader *reader, *best_reader; + struct archive_read_source *source; + const void *block; + ssize_t bytes_read; - decompression_slots = sizeof(a->decompressors) / - sizeof(a->decompressors[0]); + /* Read first block now for compress format detection. */ + bytes_read = (a->source->read)(a->source, &block); + if (bytes_read < 0) { + /* If the first read fails, close before returning error. */ + if (a->source->close != NULL) { + (a->source->close)(a->source); + a->source = NULL; + } + /* source->read should have already set error information. */ + return (ARCHIVE_FATAL); + } + + number_readers = sizeof(a->readers) / sizeof(a->readers[0]); best_bid = 0; - a->decompressor = NULL; - best_decompressor = NULL; + best_reader = NULL; - decompressor = a->decompressors; - for (i = 0; i < decompression_slots; i++) { - if (decompressor->bid) { - bid = (decompressor->bid)(buffer, bytes_read); - if (bid > best_bid || best_decompressor == NULL) { + reader = a->readers; + for (i = 0, reader = a->readers; i < number_readers; i++, reader++) { + if (reader->bid != NULL) { + bid = (reader->bid)(reader, block, bytes_read); + if (bid > best_bid) { best_bid = bid; - best_decompressor = decompressor; + best_reader = reader; } } - decompressor ++; } /* - * There were no bidders; this is a serious programmer error - * and demands a quick and definitive abort. - */ - if (best_decompressor == NULL) - __archive_errx(1, "No decompressors were registered; you " - "must call at least one " - "archive_read_support_compression_XXX function in order " - "to successfully read an archive."); - - /* - * There were bidders, but no non-zero bids; this means we can't - * support this stream. + * If we have a winner, it becomes the next stage in the pipeline. */ - if (best_bid < 1) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Unrecognized archive format"); - return; - } - - /* Record the best decompressor for this stream. */ - a->decompressor = best_decompressor; -} - -/* - * Dummy skip function, for use if the compression layer doesn't provide - * one: This code just reads data and discards it. - */ -static off_t -dummy_skip(struct archive_read * a, off_t request) -{ - const void * dummy_buffer; - ssize_t bytes_read; - off_t bytes_skipped; - - for (bytes_skipped = 0; request > 0;) { - bytes_read = (a->decompressor->read_ahead)(a, &dummy_buffer, 1); - if (bytes_read < 0) - return (bytes_read); - if (bytes_read == 0) { - /* Premature EOF. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Truncated input file (need to skip %jd bytes)", - (intmax_t)request); + if (best_reader != NULL) { + source = (best_reader->init)(a, best_reader, a->source, + block, bytes_read); + if (source == NULL) return (ARCHIVE_FATAL); - } - if (bytes_read > request) - bytes_read = (ssize_t)request; - (a->decompressor->consume)(a, (size_t)bytes_read); - request -= bytes_read; - bytes_skipped += bytes_read; + /* Record the best decompressor for this stream. */ + a->source = source; + /* Recurse to get next pipeline stage. */ + return (build_stream(a)); } - return (bytes_skipped); + /* Save first block of data. */ + a->client_buff = block; + a->client_total = bytes_read; + a->client_next = a->client_buff; + a->client_avail = a->client_total; + return (ARCHIVE_OK); } /* @@ -598,23 +594,24 @@ archive_read_close(struct archive *_a) /* TODO: Clean up the formatters. */ - /* Clean up the decompressors. */ - n = sizeof(a->decompressors)/sizeof(a->decompressors[0]); + /* Clean up the stream pipeline. */ + if (a->source != NULL) { + r1 = (a->source->close)(a->source); + if (r1 < r) + r = r1; + a->source = NULL; + } + + /* Release the reader objects. */ + n = sizeof(a->readers)/sizeof(a->readers[0]); for (i = 0; i < n; i++) { - if (a->decompressors[i].finish != NULL) { - r1 = (a->decompressors[i].finish)(a); + if (a->readers[i].free != NULL) { + r1 = (a->readers[i].free)(&a->readers[i]); if (r1 < r) r = r1; } } - /* Close the client stream. */ - if (a->client_closer != NULL) { - r1 = ((a->client_closer)(&a->archive, a->client_data)); - if (r1 < r) - r = r1; - } - return (r); } @@ -651,6 +648,7 @@ archive_read_finish(struct archive *_a) if (a->entry) archive_entry_free(a->entry); a->archive.magic = 0; + free(a->buffer); free(a); #if ARCHIVE_API_VERSION > 1 return (r); @@ -700,40 +698,350 @@ __archive_read_register_format(struct ar * Used internally by decompression routines to register their bid and * initialization functions. */ -struct decompressor_t * -__archive_read_register_compression(struct archive_read *a, - int (*bid)(const void *, size_t), - int (*init)(struct archive_read *, const void *, size_t)) +struct archive_reader * +__archive_read_get_reader(struct archive_read *a) { int i, number_slots; __archive_check_magic(&a->archive, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, - "__archive_read_register_compression"); + "__archive_read_get_reader"); - number_slots = sizeof(a->decompressors) / sizeof(a->decompressors[0]); + number_slots = sizeof(a->readers) / sizeof(a->readers[0]); for (i = 0; i < number_slots; i++) { - if (a->decompressors[i].bid == bid) - return (a->decompressors + i); - if (a->decompressors[i].bid == NULL) { - a->decompressors[i].bid = bid; - a->decompressors[i].init = init; - return (a->decompressors + i); - } + if (a->readers[i].bid == NULL) + return (a->readers + i); } __archive_errx(1, "Not enough slots for compression registration"); return (NULL); /* Never actually executed. */ } -/* used internally to simplify read-ahead */ +/* + * The next three functions comprise the peek/consume internal I/O + * system used by archive format readers. This system allows fairly + * flexible read-ahead and allows the I/O code to operate in a + * zero-copy manner most of the time. + * + * In the ideal case, block providers give the I/O code blocks of data + * and __archive_read_ahead() just returns pointers directly into + * those blocks. Then __archive_read_consume() just bumps those + * pointers. Only if your request would span blocks does the I/O + * layer use a copy buffer to provide you with a contiguous block of + * data. The __archive_read_skip() is an optimization; it scans ahead + * very quickly (it usually translates into a seek() operation if + * you're reading uncompressed disk files). + * + * A couple of useful idioms: + * * "I just want some data." Ask for 1 byte and pay attention to + * the "number of bytes available" from __archive_read_ahead(). + * You can consume more than you asked for; you just can't consume + * more than is available right now. If you consume everything that's + * immediately available, the next read_ahead() call will pull + * the next block. + * * "I want to output a large block of data." As above, ask for 1 byte, + * emit all that's available (up to whatever limit you have), then + * repeat until you're done. + * * "I want to peek ahead by a large amount." Ask for 4k or so, then + * double and repeat until you get an error or have enough. Note + * that the I/O layer will likely end up expanding its copy buffer + * to fit your request, so use this technique cautiously. This + * technique is used, for example, by some of the format tasting + * code that has uncertain look-ahead needs. + * + * TODO: Someday, provide a more generic __archive_read_seek() for + * those cases where it's useful. This is tricky because there are lots + * of cases where seek() is not available (reading gzip data from a + * network socket, for instance), so there needs to be a good way to + * communicate whether seek() is available and users of that interface + * need to use non-seeking strategies whenever seek() is not available. + */ + +/* + * Looks ahead in the input stream: + * * If 'avail' pointer is provided, that returns number of bytes available + * in the current buffer, which may be much larger than requested. + * * If end-of-file, *avail gets set to zero. + * * If error, *avail gets error code. + * * If request can be met, returns pointer to data, returns NULL + * if request is not met. + * + * Note: If you just want "some data", ask for 1 byte and pay attention + * to *avail, which will have the actual amount available. If you + * know exactly how many bytes you need, just ask for that and treat + * a NULL return as an error. + * + * Important: This does NOT move the file pointer. See + * __archive_read_consume() below. + */ + +/* + * This is tricky. We need to provide our clients with pointers to + * contiguous blocks of memory but we want to avoid copying whenever + * possible. + * + * Mostly, this code returns pointers directly into the block of data + * provided by the client_read routine. It can do this unless the + * request would split across blocks. In that case, we have to copy + * into an internal buffer to combine reads. + */ const void * -__archive_read_ahead(struct archive_read *a, size_t len) +__archive_read_ahead(struct archive_read *a, size_t min, ssize_t *avail) { - const void *h; + ssize_t bytes_read; + size_t tocopy; - if ((a->decompressor->read_ahead)(a, &h, len) < (ssize_t)len) + if (a->fatal) { + if (avail) + *avail = ARCHIVE_FATAL; return (NULL); - return (h); + } + + /* + * Keep pulling more data until we can satisfy the request. + */ + for (;;) { + + /* + * If we can satisfy from the copy buffer, we're done. + */ + if (a->avail >= min) { + if (avail != NULL) + *avail = a->avail; + return (a->next); + } + + /* + * We can satisfy directly from client buffer if everything + * currently in the copy buffer is still in the client buffer. + */ + if (a->client_total >= a->client_avail + a->avail + && a->client_avail + a->avail >= min) { + /* "Roll back" to client buffer. */ + a->client_avail += a->avail; + a->client_next -= a->avail; + /* Copy buffer is now empty. */ + a->avail = 0; + a->next = a->buffer; + /* Return data from client buffer. */ + if (avail != NULL) + *avail = a->client_avail; + return (a->client_next); + } + + /* Move data forward in copy buffer if necessary. */ + if (a->next > a->buffer && + a->next + min > a->buffer + a->buffer_size) { + if (a->avail > 0) + memmove(a->buffer, a->next, a->avail); + a->next = a->buffer; + } + + /* If we've used up the client data, get more. */ + if (a->client_avail <= 0) { + if (a->end_of_file) { + if (avail != NULL) + *avail = 0; + return (NULL); + } + bytes_read = (a->source->read)(a->source, + &a->client_buff); + if (bytes_read < 0) { /* Read error. */ + a->client_total = a->client_avail = 0; + a->client_next = a->client_buff = NULL; + a->fatal = 1; + if (avail != NULL) + *avail = ARCHIVE_FATAL; + return (NULL); + } + if (bytes_read == 0) { /* Premature end-of-file. */ + a->client_total = a->client_avail = 0; + a->client_next = a->client_buff = NULL; + a->end_of_file = 1; + /* Return whatever we do have. */ + if (avail != NULL) + *avail = a->avail; + return (NULL); + } + a->archive.raw_position += bytes_read; + a->client_total = bytes_read; + a->client_avail = a->client_total; + a->client_next = a->client_buff; + } + else + { + /* + * We can't satisfy the request from the copy + * buffer or the existing client data, so we + * need to copy more client data over to the + * copy buffer. + */ + + /* Ensure the buffer is big enough. */ + if (min > a->buffer_size) { + size_t s, t; + char *p; + + /* Double the buffer; watch for overflow. */ + s = t = a->buffer_size; + while (s < min) { + t *= 2; + if (t <= s) { /* Integer overflow! */ + archive_set_error(&a->archive, + ENOMEM, + "Unable to allocate copy buffer"); + a->fatal = 1; + if (avail != NULL) + *avail = ARCHIVE_FATAL; + return (NULL); + } + s = t; + } + /* Now s >= min, so allocate a new buffer. */ + p = (char *)malloc(s); + if (p == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Unable to allocate copy buffer"); + a->fatal = 1; + if (avail != NULL) + *avail = ARCHIVE_FATAL; + return (NULL); + } + /* Move data into newly-enlarged buffer. */ + if (a->avail > 0) + memmove(p, a->next, a->avail); + free(a->buffer); + a->next = a->buffer = p; + a->buffer_size = s; + } + + /* We can add client data to copy buffer. */ + /* First estimate: copy to fill rest of buffer. */ + tocopy = (a->buffer + a->buffer_size) + - (a->next + a->avail); + /* Don't waste time buffering more than we need to. */ + if (tocopy + a->avail > min) + tocopy = min - a->avail; + /* Don't copy more than is available. */ + if (tocopy > a->client_avail) + tocopy = a->client_avail; + + memcpy(a->next + a->avail, a->client_next, + tocopy); + /* Remove this data from client buffer. */ + a->client_next += tocopy; + a->client_avail -= tocopy; + /* add it to copy buffer. */ + a->avail += tocopy; + } + } +} + +/* + * Move the file pointer forward. This should be called after + * __archive_read_ahead() returns data to you. Don't try to move + * ahead by more than the amount of data available according to + * __archive_read_ahead(). + */ +/* + * Mark the appropriate data as used. Note that the request here will + * often be much smaller than the size of the previous read_ahead + * request. + */ +ssize_t +__archive_read_consume(struct archive_read *a, size_t request) +{ + if (a->avail > 0) { + /* Read came from copy buffer. */ + a->next += request; + a->avail -= request; + } else { + /* Read came from client buffer. */ + a->client_next += request; + a->client_avail -= request; + } + a->archive.file_position += request; + return (request); +} + +/* + * Move the file pointer ahead by an arbitrary amount. If you're + * reading uncompressed data from a disk file, this will actually + * translate into a seek() operation. Even in cases where seek() + * isn't feasible, this at least pushes the read-and-discard loop + * down closer to the data source. + */ +int64_t +__archive_read_skip(struct archive_read *a, int64_t request) +{ + off_t bytes_skipped, total_bytes_skipped = 0; + size_t min; + + if (a->fatal) + return (-1); + /* + * If there is data in the buffers already, use that first. + */ + if (a->avail > 0) { + min = minimum(request, (off_t)a->avail); + bytes_skipped = __archive_read_consume(a, min); + request -= bytes_skipped; + total_bytes_skipped += bytes_skipped; + } + if (a->client_avail > 0) { + min = minimum(request, (off_t)a->client_avail); + bytes_skipped = __archive_read_consume(a, min); + request -= bytes_skipped; + total_bytes_skipped += bytes_skipped; + } + if (request == 0) + return (total_bytes_skipped); + /* + * If a client_skipper was provided, try that first. + */ +#if ARCHIVE_API_VERSION < 2 + if ((a->source->skip != NULL) && (request < SSIZE_MAX)) { +#else + if (a->source->skip != NULL) { +#endif + bytes_skipped = (a->source->skip)(a->source, request); + if (bytes_skipped < 0) { /* error */ + a->client_total = a->client_avail = 0; + a->client_next = a->client_buff = NULL; + a->fatal = 1; + return (bytes_skipped); + } + total_bytes_skipped += bytes_skipped; + a->archive.file_position += bytes_skipped; + request -= bytes_skipped; + a->client_next = a->client_buff; + a->archive.raw_position += bytes_skipped; + a->client_avail = a->client_total = 0; + } + /* + * Note that client_skipper will usually not satisfy the + * full request (due to low-level blocking concerns), + * so even if client_skipper is provided, we may still + * have to use ordinary reads to finish out the request. + */ + while (request > 0) { + const void* dummy_buffer; + ssize_t bytes_read; + dummy_buffer = __archive_read_ahead(a, 1, &bytes_read); + if (bytes_read < 0) + return (bytes_read); + if (bytes_read == 0) { + /* We hit EOF before we satisfied the skip request. */ + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Truncated input file (need to skip %jd bytes)", + (intmax_t)request); + return (ARCHIVE_FATAL); + } + min = (size_t)(minimum(bytes_read, request)); + bytes_read = __archive_read_consume(a, min); + total_bytes_skipped += bytes_read; + request -= bytes_read; + } + return (total_bytes_skipped); } Modified: head/lib/libarchive/archive_read_private.h ============================================================================== --- head/lib/libarchive/archive_read_private.h Sat Dec 6 06:23:37 2008 (r185678) +++ head/lib/libarchive/archive_read_private.h Sat Dec 6 06:45:15 2008 (r185679) @@ -32,6 +32,75 @@ #include "archive_string.h" #include "archive_private.h" +struct archive_read; +struct archive_reader; +struct archive_read_source; + +/* + * A "reader" knows how to provide blocks. That can include something + * that reads blocks from disk or socket or a transformation layer + * that reads blocks from another source and transforms them. This + * includes decompression and decryption filters. + * + * How bidding works: + * * The bid manager reads the first block from the current source. + * * It shows that block to each registered bidder. + * * The winning bidder is initialized (with the block and information + * about the source) + * * The winning bidder becomes the new source and the process repeats + * This ends only when no reader provides a non-zero bid. + */ +struct archive_reader { + /* Configuration data for the reader. */ + void *data; + /* Bidder is handed the initial block from its source. */ + int (*bid)(struct archive_reader *, const void *buff, size_t); + /* Init() is given the archive, upstream source, and the initial + * block above. It returns a populated source structure. */ + struct archive_read_source *(*init)(struct archive_read *, + struct archive_reader *, struct archive_read_source *source, + const void *, size_t); + /* Release the reader and any configuration data it allocated. */ + int (*free)(struct archive_reader *); +}; + +/* + * A "source" is an instance of a reader. This structure is + * allocated and initialized by the init() method of a reader + * above. + */ +struct archive_read_source { + /* Essentially all sources will need these values, so + * just declare them here. */ + struct archive_reader *reader; /* Reader that I'm an instance of. */ + struct archive_read_source *upstream; /* Who I get blocks from. */ + struct archive_read *archive; /* associated archive. */ + /* Return next block. */ + ssize_t (*read)(struct archive_read_source *, const void **); + /* Skip forward this many bytes. */ + int64_t (*skip)(struct archive_read_source *self, int64_t request); + /* Close (recursively) and free(self). */ + int (*close)(struct archive_read_source *self); + /* My private data. */ + void *data; +}; + +/* + * The client source is almost the same as an internal source. + * + * TODO: Make archive_read_source and archive_read_client identical so + * that users of the library can easily register their own + * transformation filters. This will probably break the API/ABI and + * so should be deferred until libarchive 3.0. + */ +struct archive_read_client { + archive_open_callback *opener; + archive_read_callback *reader; + archive_skip_callback *skipper; + archive_close_callback *closer; + void *data; +}; + struct archive_read { struct archive archive; @@ -50,46 +119,30 @@ struct archive_read { off_t read_data_output_offset; size_t read_data_remaining; - /* Callbacks to open/read/write/close archive stream. */ - archive_open_callback *client_opener; - archive_read_callback *client_reader; - archive_skip_callback *client_skipper; - archive_close_callback *client_closer; - void *client_data; + /* Callbacks to open/read/write/close client archive stream. */ + struct archive_read_client client; + + /* Registered readers. */ + struct archive_reader readers[8]; + + /* Source */ + struct archive_read_source *source; /* File offset of beginning of most recently-read header. */ off_t header_position; - /* - * Decompressors have a very specific lifecycle: - * public setup function initializes a slot in this table - * 'config' holds minimal configuration data - * bid() examines a block of data and returns a bid [1] - * init() is called for successful bidder - * 'data' is initialized by init() - * read() returns a pointer to the next block of data - * consume() indicates how much data is used - * skip() ignores bytes of data - * finish() cleans up and frees 'data' and 'config' - * - * [1] General guideline: bid the number of bits that you actually - * test, e.g., 16 if you test a 2-byte magic value. - */ - struct decompressor_t { - void *config; - void *data; - int (*bid)(const void *buff, size_t); - int (*init)(struct archive_read *, - const void *buff, size_t); - int (*finish)(struct archive_read *); - ssize_t (*read_ahead)(struct archive_read *, - const void **, size_t); - ssize_t (*consume)(struct archive_read *, size_t); - off_t (*skip)(struct archive_read *, off_t); - } decompressors[4]; - /* Pointer to current decompressor. */ - struct decompressor_t *decompressor; + /* Used by reblocking logic. */ + char *buffer; + size_t buffer_size; + char *next; /* Current read location. */ + size_t avail; /* Bytes in my buffer. */ + const void *client_buff; /* Client buffer information. */ + size_t client_total; + const char *client_next; + size_t client_avail; + char end_of_file; + char fatal; /* * Format detection is mostly the same as compression @@ -124,12 +177,13 @@ int __archive_read_register_format(struc int (*read_data_skip)(struct archive_read *), int (*cleanup)(struct archive_read *)); -struct decompressor_t - *__archive_read_register_compression(struct archive_read *a, - int (*bid)(const void *, size_t), - int (*init)(struct archive_read *, const void *, size_t)); +struct archive_reader + *__archive_read_get_reader(struct archive_read *a); const void - *__archive_read_ahead(struct archive_read *, size_t); - + *__archive_read_ahead(struct archive_read *, size_t, ssize_t *); +ssize_t + __archive_read_consume(struct archive_read *, size_t); +int64_t + __archive_read_skip(struct archive_read *, int64_t); #endif Modified: head/lib/libarchive/archive_read_support_compression_all.c ============================================================================== --- head/lib/libarchive/archive_read_support_compression_all.c Sat Dec 6 06:23:37 2008 (r185678) +++ head/lib/libarchive/archive_read_support_compression_all.c Sat Dec 6 06:45:15 2008 (r185679) @@ -39,5 +39,11 @@ archive_read_support_compression_all(str #if HAVE_ZLIB_H archive_read_support_compression_gzip(a); #endif +#if HAVE_LZMADEC_H + /* LZMA bidding is subject to false positives because + * the LZMA file format has a very weak signature. It + * may not be feasible to include LZMA detection here. */ + /* archive_read_support_compression_lzma(a); */ +#endif return (ARCHIVE_OK); } Modified: head/lib/libarchive/archive_read_support_compression_bzip2.c ============================================================================== --- head/lib/libarchive/archive_read_support_compression_bzip2.c Sat Dec 6 06:23:37 2008 (r185678) +++ head/lib/libarchive/archive_read_support_compression_bzip2.c Sat Dec 6 06:45:15 2008 (r185679) @@ -51,30 +51,49 @@ __FBSDID("$FreeBSD$"); #if HAVE_BZLIB_H struct private_data { bz_stream stream; - char *uncompressed_buffer; - size_t uncompressed_buffer_size; - char *read_next; - int64_t total_out; + char *out_block; + size_t out_block_size; + char valid; /* True = decompressor is initialized */ char eof; /* True = found end of compressed data. */ }; -static int finish(struct archive_read *); -static ssize_t read_ahead(struct archive_read *, const void **, size_t); -static ssize_t read_consume(struct archive_read *, size_t); -static int drive_decompressor(struct archive_read *a, struct private_data *); +/* Bzip2 source */ +static ssize_t bzip2_source_read(struct archive_read_source *, const void **); +static int bzip2_source_close(struct archive_read_source *); #endif -/* These two functions are defined even if we lack the library. See below. */ -static int bid(const void *, size_t); -static int init(struct archive_read *, const void *, size_t); +/* + * Note that we can detect bzip2 archives even if we can't decompress + * them. (In fact, we like detecting them because we can give better + * error messages.) So the bid framework here gets compiled even + * if bzlib is unavailable. + */ +static int bzip2_reader_bid(struct archive_reader *, const void *, size_t); +static struct archive_read_source *bzip2_reader_init(struct archive_read *, + struct archive_reader *, struct archive_read_source *, + const void *, size_t); +static int bzip2_reader_free(struct archive_reader *); int archive_read_support_compression_bzip2(struct archive *_a) { struct archive_read *a = (struct archive_read *)_a; - if (__archive_read_register_compression(a, bid, init) != NULL) - return (ARCHIVE_OK); - return (ARCHIVE_FATAL); + struct archive_reader *reader = __archive_read_get_reader(a); + + if (reader == NULL) + return (ARCHIVE_FATAL); + + reader->data = NULL; + reader->bid = bzip2_reader_bid; + reader->init = bzip2_reader_init; + reader->free = bzip2_reader_free; + return (ARCHIVE_OK); +} + +static int +bzip2_reader_free(struct archive_reader *self){ + (void)self; /* UNUSED */ + return (ARCHIVE_OK); } /* @@ -85,11 +104,13 @@ archive_read_support_compression_bzip2(s * from verifying as much as we would like. */ static int -bid(const void *buff, size_t len) +bzip2_reader_bid(struct archive_reader *self, const void *buff, size_t len) { const unsigned char *buffer; int bits_checked; + (void)self; /* UNUSED */ + if (len < 1) return (0); @@ -150,16 +171,19 @@ bid(const void *buff, size_t len) * decompression. We can, however, still detect compressed archives * and emit a useful message. */ -static int -init(struct archive_read *a, const void *buff, size_t n) +static struct archive_read_source * +bzip2_reader_init(struct archive_read *a, struct archive_reader *reader, + struct archive_read_source *upstream, const void *buff, size_t n) { (void)a; /* UNUSED */ + (void)reader; /* UNUSED */ + (void)upstream; /* UNUSED */ (void)buff; /* UNUSED */ (void)n; /* UNUSED */ archive_set_error(&a->archive, -1, "This version of libarchive was compiled without bzip2 support"); - return (ARCHIVE_FATAL); + return (NULL); } @@ -168,37 +192,42 @@ init(struct archive_read *a, const void /* * Setup the callbacks. */ -static int -init(struct archive_read *a, const void *buff, size_t n) *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From kientzle at FreeBSD.org Fri Dec 5 22:50:10 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 22:50:16 2008 Subject: svn commit: r185680 - head/lib/libarchive Message-ID: <200812060650.mB66o991085967@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 06:50:09 2008 New Revision: 185680 URL: http://svn.freebsd.org/changeset/base/185680 Log: Conditionalize a bunch of debugging messages; this also eliminates what should be the only remaining stdio dependency. Modified: head/lib/libarchive/archive_read_support_format_iso9660.c Modified: head/lib/libarchive/archive_read_support_format_iso9660.c ============================================================================== --- head/lib/libarchive/archive_read_support_format_iso9660.c Sat Dec 6 06:45:15 2008 (r185679) +++ head/lib/libarchive/archive_read_support_format_iso9660.c Sat Dec 6 06:50:09 2008 (r185680) @@ -224,7 +224,9 @@ static int archive_read_format_iso9660_r static int archive_read_format_iso9660_read_header(struct archive_read *, struct archive_entry *); static const char *build_pathname(struct archive_string *, struct file_info *); +#ifdef DEBUG static void dump_isodirrec(FILE *, const unsigned char *isodirrec); +#endif static time_t time_from_tm(struct tm *); static time_t isodate17(const unsigned char *); static time_t isodate7(const unsigned char *); @@ -558,6 +560,7 @@ parse_file_info(struct iso9660 *iso9660, parse_rockridge(iso9660, file, rr_start, rr_end); } +#ifdef DEBUG /* DEBUGGING: Warn about attributes I don't yet fully support. */ if ((flags & ~0x02) != 0) { fprintf(stderr, "\n ** Unrecognized flag: "); @@ -580,6 +583,7 @@ parse_file_info(struct iso9660 *iso9660, dump_isodirrec(stderr, isodirrec); fprintf(stderr, "\n"); } +#endif return (file); } @@ -854,6 +858,7 @@ parse_rockridge(struct iso9660 *iso9660, default: /* The FALLTHROUGHs above leave us here for * any unsupported extension. */ +#ifdef DEBUG { const unsigned char *t; fprintf(stderr, "\nUnsupported RRIP extension for %s\n", file->name); @@ -862,6 +867,8 @@ parse_rockridge(struct iso9660 *iso9660, fprintf(stderr, " %02x", *t); fprintf(stderr, "\n"); } +#endif + break; } @@ -903,7 +910,7 @@ next_entry_seek(struct archive_read *a, /* CE area precedes actual file data? Ignore it. */ if (file->ce_offset > file->offset) { -fprintf(stderr, " *** Discarding CE data.\n"); + /* fprintf(stderr, " *** Discarding CE data.\n"); */ file->ce_offset = 0; file->ce_size = 0; } @@ -1078,6 +1085,7 @@ build_pathname(struct archive_string *as return (as->s); } +#ifdef DEBUG static void dump_isodirrec(FILE *out, const unsigned char *isodirrec) { @@ -1102,3 +1110,4 @@ dump_isodirrec(FILE *out, const unsigned fprintf(out, " `%.*s'", toi(isodirrec + DR_name_len_offset, DR_name_len_size), isodirrec + DR_name_offset); } +#endif From kientzle at FreeBSD.org Fri Dec 5 22:55:08 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 22:55:21 2008 Subject: svn commit: r185681 - head/lib/libarchive Message-ID: <200812060655.mB66t7Hv086102@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 06:55:07 2008 New Revision: 185681 URL: http://svn.freebsd.org/changeset/base/185681 Log: General improvements to Rockridge parsing and ISO9660 format detection. Modified: head/lib/libarchive/archive_read_support_format_iso9660.c Modified: head/lib/libarchive/archive_read_support_format_iso9660.c ============================================================================== --- head/lib/libarchive/archive_read_support_format_iso9660.c Sat Dec 6 06:50:09 2008 (r185680) +++ head/lib/libarchive/archive_read_support_format_iso9660.c Sat Dec 6 06:55:07 2008 (r185681) @@ -138,6 +138,15 @@ __FBSDID("$FreeBSD$"); #define PVD_reserved4_size 1 #define PVD_application_data_offset (PVD_reserved4_offset + PVD_reserved4_size) #define PVD_application_data_size 512 +#define PVD_reserved5_offset (PVD_application_data_offset + PVD_application_data_size) +#define PVD_reserved5_size (2048 - PVD_reserved5_offset) + +/* TODO: It would make future maintenance easier to just hardcode the + * above values. In particular, ECMA119 states the offsets as part of + * the standard. That would eliminate the need for the following check.*/ +#if PVD_reserved5_offset != 1395 +#error PVD offset and size definitions are wrong. +#endif /* Structure of an on-disk directory record. */ /* Note: ISO9660 stores each multi-byte integer twice, once in @@ -178,17 +187,20 @@ struct file_info { uint64_t size; /* File size in bytes. */ uint64_t ce_offset; /* Offset of CE */ uint64_t ce_size; /* Size of CE */ + time_t birthtime; /* File created time. */ time_t mtime; /* File last modified time. */ time_t atime; /* File last accessed time. */ - time_t ctime; /* File creation time. */ + time_t ctime; /* File attribute change time. */ uint64_t rdev; /* Device number */ mode_t mode; uid_t uid; gid_t gid; ino_t inode; int nlinks; - char *name; /* Null-terminated filename. */ + struct archive_string name; /* Pathname */ + char name_continues; /* Non-zero if name continues */ struct archive_string symlink; + char symlink_continues; /* Non-zero if link continues */ }; @@ -210,6 +222,7 @@ struct iso9660 { uint64_t current_position; ssize_t logical_block_size; + uint64_t volume_size; /* Total size of volume in bytes. */ off_t entry_sparse_offset; int64_t entry_bytes_remaining; @@ -224,7 +237,7 @@ static int archive_read_format_iso9660_r static int archive_read_format_iso9660_read_header(struct archive_read *, struct archive_entry *); static const char *build_pathname(struct archive_string *, struct file_info *); -#ifdef DEBUG +#if DEBUG static void dump_isodirrec(FILE *, const unsigned char *isodirrec); #endif static time_t time_from_tm(struct tm *); @@ -240,6 +253,12 @@ static struct file_info * static void parse_rockridge(struct iso9660 *iso9660, struct file_info *file, const unsigned char *start, const unsigned char *end); +static void parse_rockridge_NM1(struct file_info *, + const unsigned char *, int); +static void parse_rockridge_SL1(struct file_info *, + const unsigned char *, int); +static void parse_rockridge_TF1(struct file_info *, + const unsigned char *, int); static void release_file(struct iso9660 *, struct file_info *); static unsigned toi(const void *p, int n); @@ -316,13 +335,61 @@ static int isPVD(struct iso9660 *iso9660, const unsigned char *h) { struct file_info *file; + int i; + + /* Type of the Primary Volume Descriptor must be 1. */ + if (h[PVD_type_offset] != 1) + return (0); + + /* ID must be "CD001" */ + if (memcmp(h + PVD_id_offset, "CD001", 5) != 0) + return (0); - if (h[0] != 1) + /* PVD version must be 1. */ + if (h[PVD_version_offset] != 1) return (0); - if (memcmp(h+1, "CD001", 5) != 0) + + /* Reserved field must be 0. */ + if (h[PVD_reserved1_offset] != 0) return (0); + /* Reserved field must be 0. */ + for (i = 0; i < PVD_reserved2_size; ++i) + if (h[PVD_reserved2_offset + i] != 0) + return (0); + + /* Reserved field must be 0. */ + for (i = 0; i < PVD_reserved3_size; ++i) + if (h[PVD_reserved3_offset + i] != 0) + return (0); + + /* Logical block size must be > 0. */ + /* I've looked at Ecma 119 and can't find any stronger + * restriction on this field. */ iso9660->logical_block_size = toi(h + PVD_logical_block_size_offset, 2); + if (iso9660->logical_block_size <= 0) + return (0); + + iso9660->volume_size = iso9660->logical_block_size + * (uint64_t)toi(h + PVD_volume_space_size_offset, 4); + + /* File structure version must be 1 for ISO9660/ECMA119. */ + if (h[PVD_file_structure_version_offset] != 1) + return (0); + + + /* Reserved field must be 0. */ + for (i = 0; i < PVD_reserved4_size; ++i) + if (h[PVD_reserved4_offset + i] != 0) + return (0); + + /* Reserved field must be 0. */ + for (i = 0; i < PVD_reserved5_size; ++i) + if (h[PVD_reserved5_offset + i] != 0) + return (0); + + /* XXX TODO: Check other values for sanity; reject more + * malformed PVDs. XXX */ /* Store the root directory in the pending list. */ file = parse_file_info(iso9660, NULL, h + PVD_root_directory_record_offset); @@ -353,12 +420,22 @@ archive_read_format_iso9660_read_header( iso9660->entry_bytes_remaining = file->size; iso9660->entry_sparse_offset = 0; /* Offset for sparse-file-aware clients. */ + if (file->offset + file->size > iso9660->volume_size) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "File is beyond end-of-media: %s", file->name); + iso9660->entry_bytes_remaining = 0; + iso9660->entry_sparse_offset = 0; + release_file(iso9660, file); + return (ARCHIVE_WARN); + } + /* Set up the entry structure with information about this entry. */ archive_entry_set_mode(entry, file->mode); archive_entry_set_uid(entry, file->uid); archive_entry_set_gid(entry, file->gid); archive_entry_set_nlink(entry, file->nlinks); archive_entry_set_ino(entry, file->inode); + archive_entry_set_birthtime(entry, file->birthtime, 0); archive_entry_set_mtime(entry, file->mtime, 0); archive_entry_set_ctime(entry, file->ctime, 0); archive_entry_set_atime(entry, file->atime, 0); @@ -534,13 +611,7 @@ parse_file_info(struct iso9660 *iso9660, file->mtime = isodate7(isodirrec + DR_date_offset); file->ctime = file->atime = file->mtime; name_len = (size_t)*(const unsigned char *)(isodirrec + DR_name_len_offset); - file->name = (char *)malloc(name_len + 1); - if (file->name == NULL) { - free(file); - return (NULL); - } - memcpy(file->name, isodirrec + DR_name_offset, name_len); - file->name[name_len] = '\0'; + archive_strncpy(&file->name, isodirrec + DR_name_offset, name_len); flags = *(isodirrec + DR_flags_offset); if (flags & 0x02) file->mode = AE_IFDIR | 0700; @@ -560,7 +631,7 @@ parse_file_info(struct iso9660 *iso9660, parse_rockridge(iso9660, file, rr_start, rr_end); } -#ifdef DEBUG +#if DEBUG /* DEBUGGING: Warn about attributes I don't yet fully support. */ if ((flags & ~0x02) != 0) { fprintf(stderr, "\n ** Unrecognized flag: "); @@ -584,7 +655,6 @@ parse_file_info(struct iso9660 *iso9660, fprintf(stderr, "\n"); } #endif - return (file); } @@ -624,6 +694,7 @@ parse_rockridge(struct iso9660 *iso9660, while (p + 4 < end /* Enough space for another entry. */ && p[0] >= 'A' && p[0] <= 'Z' /* Sanity-check 1st char of name. */ && p[1] >= 'A' && p[1] <= 'Z' /* Sanity-check 2nd char of name. */ + && p[2] >= 4 /* Sanity-check length. */ && p + p[2] <= end) { /* Sanity-check length. */ const unsigned char *data = p + 4; int data_length = p[2] - 4; @@ -636,61 +707,54 @@ parse_rockridge(struct iso9660 *iso9660, */ switch(p[0]) { case 'C': - if (p[0] == 'C' && p[1] == 'E' && version == 1) { - /* - * CE extension comprises: - * 8 byte sector containing extension - * 8 byte offset w/in above sector - * 8 byte length of continuation - */ - file->ce_offset = toi(data, 4) - * iso9660->logical_block_size - + toi(data + 8, 4); - file->ce_size = toi(data + 16, 4); + if (p[0] == 'C' && p[1] == 'E') { + if (version == 1 && data_length == 24) { + /* + * CE extension comprises: + * 8 byte sector containing extension + * 8 byte offset w/in above sector + * 8 byte length of continuation + */ + file->ce_offset = (uint64_t)toi(data, 4) + * iso9660->logical_block_size + + toi(data + 8, 4); + file->ce_size = toi(data + 16, 4); + /* If the result is rediculous, + * ignore it. */ + if (file->ce_offset + file->ce_size + > iso9660->volume_size) { + file->ce_offset = 0; + file->ce_size = 0; + } + } break; } /* FALLTHROUGH */ case 'N': - if (p[0] == 'N' && p[1] == 'M' && version == 1 - && *data == 0) { - /* NM extension with flag byte == 0 */ - /* - * NM extension comprises: - * one byte flag - * rest is long name - */ - /* TODO: Obey flags. */ - char *old_name = file->name; - - data++; /* Skip flag byte. */ - data_length--; - file->name = (char *)malloc(data_length + 1); - if (file->name != NULL) { - free(old_name); - memcpy(file->name, data, data_length); - file->name[data_length] = '\0'; - } else - file->name = old_name; + if (p[0] == 'N' && p[1] == 'M') { + if (version == 1) + parse_rockridge_NM1(file, + data, data_length); break; } /* FALLTHROUGH */ case 'P': - if (p[0] == 'P' && p[1] == 'D' && version == 1) { + if (p[0] == 'P' && p[1] == 'D') { /* * PD extension is padding; * contents are always ignored. */ break; } - if (p[0] == 'P' && p[1] == 'N' && version == 1) { - if (data_length == 16) { + if (p[0] == 'P' && p[1] == 'N') { + if (version == 1 && data_length == 16) { file->rdev = toi(data,4); file->rdev <<= 32; file->rdev |= toi(data + 8, 4); } break; } - if (p[0] == 'P' && p[1] == 'X' && version == 1) { + if (p[0] == 'P' && p[1] == 'X') { /* * PX extension comprises: * 8 bytes for mode, @@ -699,12 +763,22 @@ parse_rockridge(struct iso9660 *iso9660, * 8 bytes for gid, * 8 bytes for inode. */ - if (data_length == 32) { - file->mode = toi(data, 4); - file->nlinks = toi(data + 8, 4); - file->uid = toi(data + 16, 4); - file->gid = toi(data + 24, 4); - file->inode = toi(data + 32, 4); + if (version == 1) { + if (data_length >= 8) + file->mode + = toi(data, 4); + if (data_length >= 16) + file->nlinks + = toi(data + 8, 4); + if (data_length >= 24) + file->uid + = toi(data + 16, 4); + if (data_length >= 32) + file->gid + = toi(data + 24, 4); + if (data_length >= 40) + file->inode + = toi(data + 32, 4); } break; } @@ -721,56 +795,14 @@ parse_rockridge(struct iso9660 *iso9660, } /* FALLTHROUGH */ case 'S': - if (p[0] == 'S' && p[1] == 'L' && version == 1 - && *data == 0) { - int cont = 1; - /* SL extension with flags == 0 */ - /* TODO: handle non-zero flag values. */ - data++; /* Skip flag byte. */ - data_length--; - while (data_length > 0) { - unsigned char flag = *data++; - unsigned char nlen = *data++; - data_length -= 2; - - if (cont == 0) - archive_strcat(&file->symlink, "/"); - cont = 0; - - switch(flag) { - case 0x01: /* Continue */ - archive_strncat(&file->symlink, - (const char *)data, nlen); - cont = 1; - break; - case 0x02: /* Current */ - archive_strcat(&file->symlink, "."); - break; - case 0x04: /* Parent */ - archive_strcat(&file->symlink, ".."); - break; - case 0x08: /* Root */ - case 0x10: /* Volume root */ - archive_string_empty(&file->symlink); - break; - case 0x20: /* Hostname */ - archive_strcat(&file->symlink, "hostname"); - break; - case 0: - archive_strncat(&file->symlink, - (const char *)data, nlen); - break; - default: - /* TODO: issue a warning ? */ - break; - } - data += nlen; - data_length -= nlen; - } + if (p[0] == 'S' && p[1] == 'L') { + if (version == 1) + parse_rockridge_SL1(file, + data, data_length); break; } if (p[0] == 'S' && p[1] == 'P' - && version == 1 && data_length == 7 + && version == 1 && data_length == 3 && data[0] == (unsigned char)'\xbe' && data[1] == (unsigned char)'\xef') { /* @@ -806,62 +838,20 @@ parse_rockridge(struct iso9660 *iso9660, return; } case 'T': - if (p[0] == 'T' && p[1] == 'F' && version == 1) { - char flag = data[0]; - /* - * TF extension comprises: - * one byte flag - * create time (optional) - * modify time (optional) - * access time (optional) - * attribute time (optional) - * Time format and presence of fields - * is controlled by flag bits. - */ - data++; - if (flag & 0x80) { - /* Use 17-byte time format. */ - if (flag & 1) /* Create time. */ - data += 17; - if (flag & 2) { /* Modify time. */ - file->mtime = isodate17(data); - data += 17; - } - if (flag & 4) { /* Access time. */ - file->atime = isodate17(data); - data += 17; - } - if (flag & 8) { /* Attribute time. */ - file->ctime = isodate17(data); - data += 17; - } - } else { - /* Use 7-byte time format. */ - if (flag & 1) /* Create time. */ - data += 7; - if (flag & 2) { /* Modify time. */ - file->mtime = isodate7(data); - data += 7; - } - if (flag & 4) { /* Access time. */ - file->atime = isodate7(data); - data += 7; - } - if (flag & 8) { /* Attribute time. */ - file->ctime = isodate7(data); - data += 7; - } - } + if (p[0] == 'T' && p[1] == 'F') { + if (version == 1) + parse_rockridge_TF1(file, + data, data_length); break; } /* FALLTHROUGH */ default: /* The FALLTHROUGHs above leave us here for * any unsupported extension. */ -#ifdef DEBUG +#if DEBUG { const unsigned char *t; - fprintf(stderr, "\nUnsupported RRIP extension for %s\n", file->name); + fprintf(stderr, "\nUnsupported RRIP extension for %s\n", file->name.s); fprintf(stderr, " %c%c(%d):", p[0], p[1], data_length); for (t = data; t < data + data_length && t < data + 16; t++) fprintf(stderr, " %02x", *t); @@ -878,14 +868,222 @@ parse_rockridge(struct iso9660 *iso9660, } static void +parse_rockridge_NM1(struct file_info *file, const unsigned char *data, + int data_length) +{ + if (!file->name_continues) + archive_string_empty(&file->name); + file->name_continues = 0; + if (data_length < 1) + return; + /* + * NM version 1 extension comprises: + * 1 byte flag, value is one of: + * = 0: remainder is name + * = 1: remainder is name, next NM entry continues name + * = 2: "." + * = 4: ".." + * = 32: Implementation specific + * All other values are reserved. + */ + switch(data[0]) { + case 0: + if (data_length < 2) + return; + archive_strncat(&file->name, data + 1, data_length - 1); + break; + case 1: + if (data_length < 2) + return; + archive_strncat(&file->name, data + 1, data_length - 1); + file->name_continues = 1; + break; + case 2: + archive_strcat(&file->name, "."); + break; + case 4: + archive_strcat(&file->name, ".."); + break; + default: + return; + } + +} + +static void +parse_rockridge_TF1(struct file_info *file, const unsigned char *data, + int data_length) +{ + char flag; + /* + * TF extension comprises: + * one byte flag + * create time (optional) + * modify time (optional) + * access time (optional) + * attribute time (optional) + * Time format and presence of fields + * is controlled by flag bits. + */ + if (data_length < 1) + return; + flag = data[0]; + ++data; + --data_length; + if (flag & 0x80) { + /* Use 17-byte time format. */ + if ((flag & 1) && data_length >= 17) { + /* Create time. */ + file->birthtime = isodate17(data); + data += 17; + data_length -= 17; + } + if ((flag & 2) && data_length >= 17) { + /* Modify time. */ + file->mtime = isodate17(data); + data += 17; + data_length -= 17; + } + if ((flag & 4) && data_length >= 17) { + /* Access time. */ + file->atime = isodate17(data); + data += 17; + data_length -= 17; + } + if ((flag & 8) && data_length >= 17) { + /* Attribute change time. */ + file->ctime = isodate17(data); + data += 17; + data_length -= 17; + } + } else { + /* Use 7-byte time format. */ + if ((flag & 1) && data_length >= 7) { + /* Create time. */ + file->birthtime = isodate17(data); + data += 7; + data_length -= 7; + } + if ((flag & 2) && data_length >= 7) { + /* Modify time. */ + file->mtime = isodate7(data); + data += 7; + data_length -= 7; + } + if ((flag & 4) && data_length >= 7) { + /* Access time. */ + file->atime = isodate7(data); + data += 7; + data_length -= 7; + } + if ((flag & 8) && data_length >= 7) { + /* Attribute change time. */ + file->ctime = isodate7(data); + data += 7; + data_length -= 7; + } + } +} + +static void +parse_rockridge_SL1(struct file_info *file, const unsigned char *data, + int data_length) +{ + int component_continues = 1; + + if (!file->symlink_continues) + archive_string_empty(&file->symlink); + else + archive_strcat(&file->symlink, "/"); + file->symlink_continues = 0; + + /* + * Defined flag values: + * 0: This is the last SL record for this symbolic link + * 1: this symbolic link field continues in next SL entry + * All other values are reserved. + */ + if (data_length < 1) + return; + switch(*data) { + case 0: + break; + case 1: + file->symlink_continues = 1; + break; + default: + return; + } + ++data; /* Skip flag byte. */ + --data_length; + + /* + * SL extension body stores "components". + * Basically, this is a complicated way of storing + * a POSIX path. It also interferes with using + * symlinks for storing non-path data. + * + * Each component is 2 bytes (flag and length) + * possibly followed by name data. + */ + while (data_length >= 2) { + unsigned char flag = *data++; + unsigned char nlen = *data++; + data_length -= 2; + + if (!component_continues) + archive_strcat(&file->symlink, "/"); + component_continues = 0; + + switch(flag) { + case 0: /* Usual case, this is text. */ + if (data_length < nlen) + return; + archive_strncat(&file->symlink, + (const char *)data, nlen); + break; + case 0x01: /* Text continues in next component. */ + if (data_length < nlen) + return; + archive_strncat(&file->symlink, + (const char *)data, nlen); + component_continues = 1; + break; + case 0x02: /* Current dir. */ + archive_strcat(&file->symlink, "."); + break; + case 0x04: /* Parent dir. */ + archive_strcat(&file->symlink, ".."); + break; + case 0x08: /* Root of filesystem. */ + archive_string_empty(&file->symlink); + archive_strcat(&file->symlink, "/"); + break; + case 0x10: /* Undefined (historically "volume root" */ + archive_string_empty(&file->symlink); + archive_strcat(&file->symlink, "ROOT"); + break; + case 0x20: /* Undefined (historically "hostname") */ + archive_strcat(&file->symlink, "hostname"); + break; + default: + /* TODO: issue a warning ? */ + return; + } + data += nlen; + data_length -= nlen; + } +} + + +static void release_file(struct iso9660 *iso9660, struct file_info *file) { struct file_info *parent; if (file->refcount == 0) { parent = file->parent; - if (file->name) - free(file->name); + archive_string_free(&file->name); archive_string_free(&file->symlink); free(file); if (parent != NULL) { @@ -1074,18 +1272,18 @@ time_from_tm(struct tm *t) static const char * build_pathname(struct archive_string *as, struct file_info *file) { - if (file->parent != NULL && file->parent->name[0] != '\0') { + if (file->parent != NULL && archive_strlen(&file->parent->name) > 0) { build_pathname(as, file->parent); archive_strcat(as, "/"); } - if (file->name[0] == '\0') + if (archive_strlen(&file->name) == 0) archive_strcat(as, "."); else - archive_strcat(as, file->name); + archive_string_concat(as, &file->name); return (as->s); } -#ifdef DEBUG +#if DEBUG static void dump_isodirrec(FILE *out, const unsigned char *isodirrec) { From kientzle at FreeBSD.org Fri Dec 5 22:57:46 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 22:57:52 2008 Subject: svn commit: r185682 - head/lib/libarchive Message-ID: <200812060657.mB66vjXM086176@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 06:57:45 2008 New Revision: 185682 URL: http://svn.freebsd.org/changeset/base/185682 Log: Strip ";1" and trailing "." from ISO9660 entries. This seems a better match for people's expectations. Modified: head/lib/libarchive/archive_read_support_format_iso9660.c Modified: head/lib/libarchive/archive_read_support_format_iso9660.c ============================================================================== --- head/lib/libarchive/archive_read_support_format_iso9660.c Sat Dec 6 06:55:07 2008 (r185681) +++ head/lib/libarchive/archive_read_support_format_iso9660.c Sat Dec 6 06:57:45 2008 (r185682) @@ -593,6 +593,8 @@ parse_file_info(struct iso9660 *iso9660, { struct file_info *file; size_t name_len; + const unsigned char *rr_start, *rr_end; + const char *p; int flags; /* TODO: Sanity check that name_len doesn't exceed length, etc. */ @@ -610,8 +612,23 @@ parse_file_info(struct iso9660 *iso9660, file->size = toi(isodirrec + DR_size_offset, DR_size_size); file->mtime = isodate7(isodirrec + DR_date_offset); file->ctime = file->atime = file->mtime; + name_len = (size_t)*(const unsigned char *)(isodirrec + DR_name_len_offset); - archive_strncpy(&file->name, isodirrec + DR_name_offset, name_len); + p = isodirrec + DR_name_offset; + /* Rockridge extensions (if any) follow name. Compute this + * before fidgeting the name_len below. */ + rr_start = p + name_len + (name_len & 1 ? 0 : 1) + iso9660->suspOffset; + rr_end = (const unsigned char *)isodirrec + + *(isodirrec + DR_length_offset); + + /* Chop off trailing ';1' from files. */ + if (name_len > 2 && p[name_len - 1] == '1' && p[name_len - 2] == ';') + name_len -= 2; + /* Chop off trailing '.' from filenames. */ + if (name_len > 1 && p[name_len - 1] == '.') + --name_len; + archive_strncpy(&file->name, p, name_len); + flags = *(isodirrec + DR_flags_offset); if (flags & 0x02) file->mode = AE_IFDIR | 0700; @@ -619,17 +636,7 @@ parse_file_info(struct iso9660 *iso9660, file->mode = AE_IFREG | 0400; /* Rockridge extensions overwrite information from above. */ - { - const unsigned char *rr_start, *rr_end; - rr_end = (const unsigned char *)isodirrec - + *(isodirrec + DR_length_offset); - rr_start = (const unsigned char *)(isodirrec + DR_name_offset - + name_len); - if ((name_len & 1) == 0) - rr_start++; - rr_start += iso9660->suspOffset; - parse_rockridge(iso9660, file, rr_start, rr_end); - } + parse_rockridge(iso9660, file, rr_start, rr_end); #if DEBUG /* DEBUGGING: Warn about attributes I don't yet fully support. */ @@ -690,6 +697,8 @@ parse_rockridge(struct iso9660 *iso9660, const unsigned char *p, const unsigned char *end) { (void)iso9660; /* UNUSED */ + file->name_continues = 0; + file->symlink_continues = 0; while (p + 4 < end /* Enough space for another entry. */ && p[0] >= 'A' && p[0] <= 'Z' /* Sanity-check 1st char of name. */ From kientzle at FreeBSD.org Fri Dec 5 23:08:09 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 23:08:23 2008 Subject: svn commit: r185683 - head/lib/libarchive/test Message-ID: <200812060708.mB6788wR086427@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 07:08:08 2008 New Revision: 185683 URL: http://svn.freebsd.org/changeset/base/185683 Log: New tests: * support for bzip2 file with multiple concatenated bzip2 streams * support for bzip2 file with junk after bzip2 stream * support for gzip file with junk after gzip stream * "fuzz" tester randomly modifies a bunch of input files in order to try to crash libarchive (this found an amusing hang in the ISO9660 code when trying to read images that advertised a zero blocksize). This test is implemented, but commented out for now: * support for gzip file with multiple concatenated gzip streams Added: head/lib/libarchive/test/test_compat_bzip2.c (contents, props changed) head/lib/libarchive/test/test_compat_bzip2_1.tbz.uu (contents, props changed) head/lib/libarchive/test/test_compat_bzip2_2.tbz.uu (contents, props changed) head/lib/libarchive/test/test_compat_gzip.c (contents, props changed) head/lib/libarchive/test/test_compat_gzip_1.tgz.uu (contents, props changed) head/lib/libarchive/test/test_compat_gzip_2.tgz.uu (contents, props changed) head/lib/libarchive/test/test_fuzz.c (contents, props changed) head/lib/libarchive/test/test_fuzz_1.iso.uu (contents, props changed) Modified: head/lib/libarchive/test/Makefile Modified: head/lib/libarchive/test/Makefile ============================================================================== --- head/lib/libarchive/test/Makefile Sat Dec 6 06:57:45 2008 (r185682) +++ head/lib/libarchive/test/Makefile Sat Dec 6 07:08:08 2008 (r185683) @@ -13,12 +13,15 @@ TESTS= \ test_acl_pax.c \ test_archive_api_feature.c \ test_bad_fd.c \ + test_compat_bzip2.c \ test_compat_gtar.c \ + test_compat_gzip.c \ test_compat_tar_hardlink.c \ test_compat_zip.c \ test_empty_write.c \ test_entry.c \ test_entry_strmode.c \ + test_fuzz.c \ test_link_resolver.c \ test_pax_filename_encoding.c \ test_read_compress_program.c \ Added: head/lib/libarchive/test/test_compat_bzip2.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libarchive/test/test_compat_bzip2.c Sat Dec 6 07:08:08 2008 (r185683) @@ -0,0 +1,89 @@ +/*- + * Copyright (c) 2003-2008 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +/* + * Verify our ability to read sample files compatibly with bunzip2. + * + * In particular: + * * bunzip2 will read multiple bzip2 streams, concatenating the output + * * bunzip2 will stop at the end of a stream if the following data + * doesn't start with a bzip2 signature. + */ + +/* + * All of the sample files have the same contents; they're just + * compressed in different ways. + */ +static void +compat_bzip2(const char *name) +{ + const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL }; + struct archive_entry *ae; + struct archive *a; + int i,r; + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + extract_reference_file(name); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); + + /* Read entries, match up names with list above. */ + for (i = 0; i < 6; ++i) { + r = archive_read_next_header(a, &ae); + failure("Could not read file %d (%s) from %s", i, n[i], name); + assertEqualIntA(a, ARCHIVE_OK, r); + if (r != ARCHIVE_OK) { + archive_read_finish(a); + return; + } + assertEqualString(n[i], archive_entry_pathname(ae)); + } + + /* Verify the end-of-archive. */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify that the format detection worked. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); + + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +#endif +} + + +DEFINE_TEST(test_compat_bzip2) +{ + compat_bzip2("test_compat_bzip2_1.tbz"); + compat_bzip2("test_compat_bzip2_2.tbz"); +} + + Added: head/lib/libarchive/test/test_compat_bzip2_1.tbz.uu ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libarchive/test/test_compat_bzip2_1.tbz.uu Sat Dec 6 07:08:08 2008 (r185683) @@ -0,0 +1,24 @@ +$FreeBSD$ + +begin 644 test_compat_bzip2_1.tbz +M0EIH.3%!62936;12^)(``#-;D=$00`!_@``!8RT>$`0`$```""``5#5/*'J> +MD#(&30_5!H4_5-ZH`T``327U4@&L('"(9-%8<7&$I,`:7FXH+*\GV#JF<`PK29-8'OPDG36S\7HR&C(T:/U0:$U'I +MJ!ZC0`#VECO\[$10H'-Z@F*:6A1$H$V("2G0Q(U0(8=(7AK$S04#!)RXOAP% +MP:D%#Q;NO)\4UL23'2[\7````6YC1 +M$$`$?X```6,M'A`$`!````@@`'4-4S*,U!HT!HT?J@T)E-I--!H`![60EIH.3%!629364RNM^,```#?L-$00`#_@`0```AG +M+1X0`!`$```((`!U#5-,:1IH`TT,1^J#)&H]3U`T``!CX[_.[`F40.64EC"D +M()+?KX6,VP?6Y;F%5$XR[Y/D#*9),K3^+N2*<*$@9@ +MX6(`0EIH.3%!62936>ZM4*4```);D-$00`#O@``(9ST>$`0```@@`'0:IFC2 +M&F@!B:/U0:$R&H:&@`"KS^U=Y`BC`#FY2*9-8%%&13E$@%8ZF(&J!##]!#E` +MKVL'2LUW2.*C08`$)::#DQ05DF +?4UDI/)=P````0!!```0`(``A`(*#%W)%.%"0*3R7<``` +` +end Added: head/lib/libarchive/test/test_compat_bzip2_2.tbz.uu ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libarchive/test/test_compat_bzip2_2.tbz.uu Sat Dec 6 07:08:08 2008 (r185683) @@ -0,0 +1,11 @@ +$FreeBSD$ + +begin 644 test_compat_bzip2_2.tbz +M0EIH.3%!629361HI1P<``4#;D-$00`#_@``)9RT>$`0``!@P`/@#&$Q,F`F` +M`,83$R8"8``1133"1/2-J-#$/U3@;XVF9V'`Y3882XA$*KO6\WTL`]QU&J"8 +M$-=*Q$\@=`=QJ,TQ;3UH,NPT$-(!"HV&!ZO5D&@P-1D&1@'L<8&209QV9'G` +MW&PRZ0Q(-BT%&DG*DE.!U*#J.P]*#%-P9G`W9+34:#S&M`;@^1R^![C]:Y)U +MDF9/(\AR/@?P@^@I_B[DBG"A(#12C@X!3;VUE(&UOV=QL!06ER26`1T2G9F:EY)54XJ +MN>9`/*(`IX<(2#/D&F@GC`(Z``#S57',@'E&`TT,$I!EQ +M#;031@$5`0`Q!<\4Z`,``!^+"`B8OB))``-T97-T+7-P;&ET+G1A$0!3@\1D&;,-=!.&`5D``#7L]HO +MZ`,``!^+"`B8OB))``-T97-T+7-P;&ET+G1A57',@'E&`TT,$I!ER#;031@$>``"Y*#OBZ`,``!^+"`B8 +MOB))``-T97-T+7-P;&ET+G1A@ALXPP`]CXF=Q&A<:-UX>EN)C5M,AL;P +MO@V[0A=_.E39F2.B'*.?5QX2?Z\?XGE&27)F]L0)V>E_'7YY07\>OZ)Y1W6Q\!-J3!?H^Z_J7TG]%_"QK0?\]4[/>HZS^_^T\! +M_;>@@OY[=N2]6E\!JOH/P])_2OC^-X'YOV]+_]97@*K^A4K_C/Y;P/S?MZ5_ +MZRM`7?]<^L?_OR8P_P,`].D%,XR2*0`<``!4:&ES(&ES('5N Author: kientzle Date: Sat Dec 6 07:15:42 2008 New Revision: 185684 URL: http://svn.freebsd.org/changeset/base/185684 Log: Make the GCC-specific __dead2 markers conditional on whether we're compiling under GCC. Modified: head/usr.bin/cpio/cpio.h head/usr.bin/cpio/cpio_platform.h Modified: head/usr.bin/cpio/cpio.h ============================================================================== --- head/usr.bin/cpio/cpio.h Sat Dec 6 07:08:08 2008 (r185683) +++ head/usr.bin/cpio/cpio.h Sat Dec 6 07:15:42 2008 (r185684) @@ -89,7 +89,7 @@ struct cpio { /* Name of this program; used in error reporting, initialized in main(). */ const char *cpio_progname; -void cpio_errc(int _eval, int _code, const char *fmt, ...) __dead2; +void cpio_errc(int _eval, int _code, const char *fmt, ...) __LA_DEAD; void cpio_warnc(int _code, const char *fmt, ...); int owner_parse(const char *, int *, int *); Modified: head/usr.bin/cpio/cpio_platform.h ============================================================================== --- head/usr.bin/cpio/cpio_platform.h Sat Dec 6 07:08:08 2008 (r185683) +++ head/usr.bin/cpio/cpio_platform.h Sat Dec 6 07:15:42 2008 (r185684) @@ -81,4 +81,12 @@ #endif #endif +/* How to mark functions that don't return. */ +#if defined(__GNUC__) && (__GNUC__ > 2 || \ + (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) +#define __LA_DEAD __attribute__((__noreturn__)) +#else +#define __LA_DEAD +#endif + #endif /* !CPIO_PLATFORM_H_INCLUDED */ From kientzle at FreeBSD.org Fri Dec 5 23:30:40 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 23:30:53 2008 Subject: svn commit: r185685 - head/usr.bin/cpio Message-ID: <200812060730.mB67Ue6H086932@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 07:30:40 2008 New Revision: 185685 URL: http://svn.freebsd.org/changeset/base/185685 Log: Custom command line parser for cpio; this is a little more code but should be a lot fewer cross-platform compatibility headaches. Modified: head/usr.bin/cpio/Makefile head/usr.bin/cpio/cmdline.c head/usr.bin/cpio/config_freebsd.h head/usr.bin/cpio/cpio.c head/usr.bin/cpio/cpio.h Modified: head/usr.bin/cpio/Makefile ============================================================================== --- head/usr.bin/cpio/Makefile Sat Dec 6 07:15:42 2008 (r185684) +++ head/usr.bin/cpio/Makefile Sat Dec 6 07:30:40 2008 (r185685) @@ -3,7 +3,7 @@ .include PROG= bsdcpio -BSDCPIO_VERSION_STRING=1.0.0 +BSDCPIO_VERSION_STRING=1.1.0 SRCS= cpio.c cmdline.c err.c matching.c pathmatch.c WARNS?= 6 DPADD= ${LIBARCHIVE} ${LIBZ} ${LIBBZ2} Modified: head/usr.bin/cpio/cmdline.c ============================================================================== --- head/usr.bin/cpio/cmdline.c Sat Dec 6 07:15:42 2008 (r185684) +++ head/usr.bin/cpio/cmdline.c Sat Dec 6 07:30:40 2008 (r185685) @@ -31,18 +31,6 @@ __FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include #endif -#ifdef HAVE_GETOPT_LONG -#include -#else -struct option { - const char *name; - int has_arg; - int *flag; - int val; -}; -#define no_argument 0 -#define required_argument 1 -#endif #ifdef HAVE_GRP_H #include #endif @@ -60,119 +48,215 @@ struct option { #include "cpio.h" /* - * - * Option parsing routines for bsdcpio. - * - */ - - -static const char *cpio_opts = "0AaBC:F:O:cdE:f:H:hijLlmopR:rtuvW:yZz"; - -/* - * On systems that lack getopt_long, long options can be specified - * using -W longopt and -W longopt=value, e.g. "-W version" is the - * same as "--version" and "-W format=ustar" is the same as "--format - * ustar". This does not rely the GNU getopt() "W;" extension, so - * should work correctly on any system with a POSIX-compliant - * getopt(). + * Short options for cpio. Please keep this sorted. */ +static const char *short_options = "0AaBC:F:O:cdE:f:H:hijLlmopR:rtuvW:yZz"; /* - * If you add anything, be very careful to keep this list properly - * sorted, as the -W logic below relies on it. + * Long options for cpio. Please keep this sorted. */ -static const struct option cpio_longopts[] = { - { "create", no_argument, NULL, 'o' }, - { "extract", no_argument, NULL, 'i' }, - { "file", required_argument, NULL, 'F' }, - { "format", required_argument, NULL, 'H' }, - { "help", no_argument, NULL, 'h' }, - { "insecure", no_argument, NULL, OPTION_INSECURE }, - { "link", no_argument, NULL, 'l' }, - { "list", no_argument, NULL, 't' }, - { "make-directories", no_argument, NULL, 'd' }, - { "no-preserve-owner", no_argument, NULL, OPTION_NO_PRESERVE_OWNER }, - { "null", no_argument, NULL, '0' }, - { "owner", required_argument, NULL, 'R' }, - { "pass-through", no_argument, NULL, 'p' }, - { "preserve-modification-time", no_argument, NULL, 'm' }, - { "quiet", no_argument, NULL, OPTION_QUIET }, - { "unconditional", no_argument, NULL, 'u' }, - { "verbose", no_argument, NULL, 'v' }, - { "version", no_argument, NULL, OPTION_VERSION }, - { NULL, 0, NULL, 0 } +static const struct option { + const char *name; + int required; /* 1 if this option requires an argument */ + int equivalent; /* Equivalent short option. */ +} cpio_longopts[] = { + { "create", 0, 'o' }, + { "extract", 0, 'i' }, + { "file", 1, 'F' }, + { "format", 1, 'H' }, + { "help", 0, 'h' }, + { "insecure", 0, OPTION_INSECURE }, + { "link", 0, 'l' }, + { "list", 0, 't' }, + { "make-directories", 0, 'd' }, + { "no-preserve-owner", 0, OPTION_NO_PRESERVE_OWNER }, + { "null", 0, '0' }, + { "owner", 1, 'R' }, + { "pass-through", 0, 'p' }, + { "preserve-modification-time", 0, 'm' }, + { "quiet", 0, OPTION_QUIET }, + { "unconditional", 0, 'u' }, + { "verbose", 0, 'v' }, + { "version", 0, OPTION_VERSION }, + { NULL, 0, 0 } }; /* - * Parse command-line options using system-provided getopt() or getopt_long(). - * If option is -W, then parse argument as a long option. + * I used to try to select platform-provided getopt() or + * getopt_long(), but that caused a lot of headaches. In particular, + * I couldn't consistently use long options in the test harness + * because not all platforms have getopt_long(). That in turn led to + * overuse of the -W hack in the test harness, which made it rough to + * run the test harness against GNU cpio. (I periodically run the + * test harness here against GNU cpio as a sanity-check. Yes, + * I've found a couple of bugs in GNU cpio that way.) */ int cpio_getopt(struct cpio *cpio) { - char *p, *q; - const struct option *option, *option2; - int opt; - int option_index; - size_t option_length; - - option_index = -1; - -#ifdef HAVE_GETOPT_LONG - opt = getopt_long(cpio->argc, cpio->argv, cpio_opts, - cpio_longopts, &option_index); -#else - opt = getopt(cpio->argc, cpio->argv, cpio_opts); -#endif + enum { state_start = 0, state_next_word, state_short, state_long }; + static int state = state_start; + static char *opt_word; + + const struct option *popt, *match = NULL, *match2 = NULL; + const char *p, *long_prefix = "--"; + size_t optlength; + int opt = '?'; + int required = 0; + + cpio->optarg = NULL; + + /* First time through, initialize everything. */ + if (state == state_start) { + /* Skip program name. */ + ++cpio->argv; + --cpio->argc; + state = state_next_word; + } - /* Support long options through -W longopt=value */ - if (opt == 'W') { - p = optarg; - q = strchr(optarg, '='); - if (q != NULL) { - option_length = (size_t)(q - p); - optarg = q + 1; + /* + * We're ready to look at the next word in argv. + */ + if (state == state_next_word) { + /* No more arguments, so no more options. */ + if (cpio->argv[0] == NULL) + return (-1); + /* Doesn't start with '-', so no more options. */ + if (cpio->argv[0][0] != '-') + return (-1); + /* "--" marks end of options; consume it and return. */ + if (strcmp(cpio->argv[0], "--") == 0) { + ++cpio->argv; + --cpio->argc; + return (-1); + } + /* Get next word for parsing. */ + opt_word = *cpio->argv++; + --cpio->argc; + if (opt_word[1] == '-') { + /* Set up long option parser. */ + state = state_long; + opt_word += 2; /* Skip leading '--' */ } else { - option_length = strlen(p); - optarg = NULL; + /* Set up short option parser. */ + state = state_short; + ++opt_word; /* Skip leading '-' */ } - option = cpio_longopts; - while (option->name != NULL && - (strlen(option->name) < option_length || - strncmp(p, option->name, option_length) != 0 )) { - option++; - } - - if (option->name != NULL) { - option2 = option; - opt = option->val; - - /* If the first match was exact, we're done. */ - if (strncmp(p, option->name, strlen(option->name)) == 0) { - while (option->name != NULL) - option++; + } + + /* + * We're parsing a group of POSIX-style single-character options. + */ + if (state == state_short) { + /* Peel next option off of a group of short options. */ + opt = *opt_word++; + if (opt == '\0') { + /* End of this group; recurse to get next option. */ + state = state_next_word; + return cpio_getopt(cpio); + } + + /* Does this option take an argument? */ + p = strchr(short_options, opt); + if (p == NULL) + return ('?'); + if (p[1] == ':') + required = 1; + + /* If it takes an argument, parse that. */ + if (required) { + /* If arg is run-in, opt_word already points to it. */ + if (opt_word[0] == '\0') { + /* Otherwise, pick up the next word. */ + opt_word = *cpio->argv; + if (opt_word == NULL) { + cpio_warnc(0, + "Option -%c requires an argument", + opt); + return ('?'); + } + ++cpio->argv; + --cpio->argc; + } + if (opt == 'W') { + state = state_long; + long_prefix = "-W "; /* For clearer errors. */ } else { - /* Check if there's another match. */ - option++; - while (option->name != NULL && - (strlen(option->name) < option_length || - strncmp(p, option->name, option_length) != 0)) { - option++; + state = state_next_word; + cpio->optarg = opt_word; + } + } + } + + /* We're reading a long option, including -W long=arg convention. */ + if (state == state_long) { + /* After this long option, we'll be starting a new word. */ + state = state_next_word; + + /* Option name ends at '=' if there is one. */ + p = strchr(opt_word, '='); + if (p != NULL) { + optlength = (size_t)(p - opt_word); + cpio->optarg = (char *)(uintptr_t)(p + 1); + } else { + optlength = strlen(opt_word); + } + + /* Search the table for an unambiguous match. */ + for (popt = cpio_longopts; popt->name != NULL; popt++) { + /* Short-circuit if first chars don't match. */ + if (popt->name[0] != opt_word[0]) + continue; + /* If option is a prefix of name in table, record it.*/ + if (strncmp(opt_word, popt->name, optlength) == 0) { + match2 = match; /* Record up to two matches. */ + match = popt; + /* If it's an exact match, we're done. */ + if (strlen(popt->name) == optlength) { + match2 = NULL; /* Forget the others. */ + break; } } - if (option->name != NULL) - cpio_errc(1, 0, - "Ambiguous option %s " - "(matches both %s and %s)", - p, option2->name, option->name); - - if (option2->has_arg == required_argument - && optarg == NULL) - cpio_errc(1, 0, - "Option \"%s\" requires argument", p); + } + + /* Fail if there wasn't a unique match. */ + if (match == NULL) { + cpio_warnc(0, + "Option %s%s is not supported", + long_prefix, opt_word); + return ('?'); + } + if (match2 != NULL) { + cpio_warnc(0, + "Ambiguous option %s%s (matches --%s and --%s)", + long_prefix, opt_word, match->name, match2->name); + return ('?'); + } + + /* We've found a unique match; does it need an argument? */ + if (match->required) { + /* Argument required: get next word if necessary. */ + if (cpio->optarg == NULL) { + cpio->optarg = *cpio->argv; + if (cpio->optarg == NULL) { + cpio_warnc(0, + "Option %s%s requires an argument", + long_prefix, match->name); + return ('?'); + } + ++cpio->argv; + --cpio->argc; + } } else { - opt = '?'; + /* Argument forbidden: fail if there is one. */ + if (cpio->optarg != NULL) { + cpio_warnc(0, + "Option %s%s does not allow an argument", + long_prefix, match->name); + return ('?'); + } } + return (match->equivalent); } return (opt); Modified: head/usr.bin/cpio/config_freebsd.h ============================================================================== --- head/usr.bin/cpio/config_freebsd.h Sat Dec 6 07:15:42 2008 (r185684) +++ head/usr.bin/cpio/config_freebsd.h Sat Dec 6 07:30:40 2008 (r185685) @@ -52,7 +52,6 @@ #define HAVE_FNM_LEADING_DIR 1 #define HAVE_FTRUNCATE 1 #define HAVE_FUTIMES 1 -#define HAVE_GETOPT_LONG 1 #undef HAVE_GETXATTR #define HAVE_GRP_H 1 #define HAVE_INTTYPES_H 1 Modified: head/usr.bin/cpio/cpio.c ============================================================================== --- head/usr.bin/cpio/cpio.c Sat Dec 6 07:15:42 2008 (r185684) +++ head/usr.bin/cpio/cpio.c Sat Dec 6 07:30:40 2008 (r185685) @@ -161,9 +161,9 @@ main(int argc, char *argv[]) cpio->bytes_per_block = 5120; break; case 'C': /* NetBSD/OpenBSD */ - cpio->bytes_per_block = atoi(optarg); + cpio->bytes_per_block = atoi(cpio->optarg); if (cpio->bytes_per_block <= 0) - cpio_errc(1, 0, "Invalid blocksize %s", optarg); + cpio_errc(1, 0, "Invalid blocksize %s", cpio->optarg); break; case 'c': /* POSIX 1997 */ cpio->format = "odc"; @@ -172,22 +172,22 @@ main(int argc, char *argv[]) cpio->extract_flags &= ~ARCHIVE_EXTRACT_NO_AUTODIR; break; case 'E': /* NetBSD/OpenBSD */ - include_from_file(cpio, optarg); + include_from_file(cpio, cpio->optarg); break; case 'F': /* NetBSD/OpenBSD/GNU cpio */ - cpio->filename = optarg; + cpio->filename = cpio->optarg; break; case 'f': /* POSIX 1997 */ - exclude(cpio, optarg); + exclude(cpio, cpio->optarg); break; case 'H': /* GNU cpio (also --format) */ - cpio->format = optarg; + cpio->format = cpio->optarg; break; case 'h': long_help(); break; case 'I': /* NetBSD/OpenBSD */ - cpio->filename = optarg; + cpio->filename = cpio->optarg; break; case 'i': /* POSIX 1997 */ cpio->mode = opt; @@ -209,7 +209,7 @@ main(int argc, char *argv[]) cpio->extract_flags &= ~ARCHIVE_EXTRACT_OWNER; break; case 'O': /* GNU cpio */ - cpio->filename = optarg; + cpio->filename = cpio->optarg; break; case 'o': /* POSIX 1997 */ cpio->mode = opt; @@ -222,7 +222,7 @@ main(int argc, char *argv[]) cpio->quiet = 1; break; case 'R': /* GNU cpio, also --owner */ - if (owner_parse(optarg, &uid, &gid)) + if (owner_parse(cpio->optarg, &uid, &gid)) usage(); if (uid != -1) cpio->uid_override = uid; @@ -269,9 +269,6 @@ main(int argc, char *argv[]) /* TODO: Sanity-check args, error out on nonsensical combinations. */ - cpio->argc -= optind; - cpio->argv += optind; - switch (cpio->mode) { case 'o': mode_out(cpio); @@ -314,11 +311,7 @@ usage(void) fprintf(stderr, " List: %s -it < archive\n", p); fprintf(stderr, " Extract: %s -i < archive\n", p); fprintf(stderr, " Create: %s -o < filenames > archive\n", p); -#ifdef HAVE_GETOPT_LONG fprintf(stderr, " Help: %s --help\n", p); -#else - fprintf(stderr, " Help: %s -h\n", p); -#endif exit(1); } Modified: head/usr.bin/cpio/cpio.h ============================================================================== --- head/usr.bin/cpio/cpio.h Sat Dec 6 07:15:42 2008 (r185684) +++ head/usr.bin/cpio/cpio.h Sat Dec 6 07:30:40 2008 (r185685) @@ -42,8 +42,11 @@ * functions. */ struct cpio { + /* Option parsing */ + const char *optarg; + /* Options */ - char *filename; + const char *filename; char mode; /* -i -o -p */ char compress; /* -j, -y, or -z */ const char *format; /* -H format */ From kientzle at FreeBSD.org Fri Dec 5 23:37:15 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 23:37:21 2008 Subject: svn commit: r185686 - head/usr.bin/tar Message-ID: <200812060737.mB67bEAT087091@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 07:37:14 2008 New Revision: 185686 URL: http://svn.freebsd.org/changeset/base/185686 Log: Only use GCC-specific __dead2 marker when building with GCC. Modified: head/usr.bin/tar/bsdtar.h head/usr.bin/tar/bsdtar_platform.h Modified: head/usr.bin/tar/bsdtar.h ============================================================================== --- head/usr.bin/tar/bsdtar.h Sat Dec 6 07:30:40 2008 (r185685) +++ head/usr.bin/tar/bsdtar.h Sat Dec 6 07:37:14 2008 (r185686) @@ -131,7 +131,7 @@ enum { void bsdtar_errc(struct bsdtar *, int _eval, int _code, - const char *fmt, ...) __dead2; + const char *fmt, ...) __LA_DEAD; int bsdtar_getopt(struct bsdtar *); void bsdtar_warnc(struct bsdtar *, int _code, const char *fmt, ...); void cleanup_exclusions(struct bsdtar *); Modified: head/usr.bin/tar/bsdtar_platform.h ============================================================================== --- head/usr.bin/tar/bsdtar_platform.h Sat Dec 6 07:30:40 2008 (r185685) +++ head/usr.bin/tar/bsdtar_platform.h Sat Dec 6 07:37:14 2008 (r185686) @@ -147,4 +147,14 @@ #endif #endif +/* How to mark functions that don't return. */ +/* This facilitates use of some newer static code analysis tools. */ +#undef __LA_DEAD +#if defined(__GNUC__) && (__GNUC__ > 2 || \ + (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) +#define __LA_DEAD __attribute__((__noreturn__)) +#else +#define __LA_DEAD +#endif + #endif /* !BSDTAR_PLATFORM_H_INCLUDED */ From kientzle at FreeBSD.org Fri Dec 5 23:37:56 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 23:38:08 2008 Subject: svn commit: r185687 - head/usr.bin/tar Message-ID: <200812060737.mB67btkO087137@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 07:37:55 2008 New Revision: 185687 URL: http://svn.freebsd.org/changeset/base/185687 Log: bsdtar always supports long options now, so we can remove a documentation disclaimer. Modified: head/usr.bin/tar/bsdtar.1 Modified: head/usr.bin/tar/bsdtar.1 ============================================================================== --- head/usr.bin/tar/bsdtar.1 Sat Dec 6 07:37:14 2008 (r185686) +++ head/usr.bin/tar/bsdtar.1 Sat Dec 6 07:37:55 2008 (r185687) @@ -607,8 +607,8 @@ and .Cm w options. .Pp -On systems that support getopt_long(), additional long options -are available to improve compatibility with other tar implementations. +Additional long options are provided to improve compatibility with other +tar implementations. .Sh SECURITY Certain security issues are common to many archiving programs, including .Nm . From kientzle at FreeBSD.org Fri Dec 5 23:38:14 2008 From: kientzle at FreeBSD.org (Tim Kientzle) Date: Fri Dec 5 23:38:25 2008 Subject: svn commit: r185688 - head/usr.bin/tar Message-ID: <200812060738.mB67cEFP087187@svn.freebsd.org> Author: kientzle Date: Sat Dec 6 07:38:14 2008 New Revision: 185688 URL: http://svn.freebsd.org/changeset/base/185688 Log: bsdtar is synced up with 2.5.903a Modified: head/usr.bin/tar/Makefile Modified: head/usr.bin/tar/Makefile ============================================================================== --- head/usr.bin/tar/Makefile Sat Dec 6 07:37:55 2008 (r185687) +++ head/usr.bin/tar/Makefile Sat Dec 6 07:38:14 2008 (r185688) @@ -1,7 +1,7 @@ # $FreeBSD$ PROG= bsdtar -BSDTAR_VERSION_STRING=2.5.5 +BSDTAR_VERSION_STRING=2.5.903a SRCS= bsdtar.c cmdline.c getdate.y matching.c read.c siginfo.c subst.c tree.c util.c write.c WARNS?= 5 DPADD= ${LIBARCHIVE} ${LIBBZ2} ${LIBZ} From kib at FreeBSD.org Sat Dec 6 01:28:46 2008 From: kib at FreeBSD.org (Konstantin Belousov) Date: Sat Dec 6 01:28:58 2008 Subject: svn commit: r185689 - head/lib/libc/string Message-ID: <200812060928.mB69SkOL089232@svn.freebsd.org> Author: kib Date: Sat Dec 6 09:28:46 2008 New Revision: 185689 URL: http://svn.freebsd.org/changeset/base/185689 Log: Order the str*.c files mostly alphabetical. Submitted by: Florian Smeets MFC after: 2 weeks Modified: head/lib/libc/string/Makefile.inc Modified: head/lib/libc/string/Makefile.inc ============================================================================== --- head/lib/libc/string/Makefile.inc Sat Dec 6 07:38:14 2008 (r185688) +++ head/lib/libc/string/Makefile.inc Sat Dec 6 09:28:46 2008 (r185689) @@ -9,9 +9,9 @@ CFLAGS+= -I${.CURDIR}/locale MISRCS+=bcmp.c bcopy.c bzero.c ffs.c ffsl.c ffsll.c fls.c flsl.c flsll.c \ index.c memccpy.c memchr.c memrchr.c memcmp.c \ memcpy.c memmem.c memmove.c memset.c rindex.c stpcpy.c strcasecmp.c \ - strcat.c strchr.c strcmp.c strcoll.c strcpy.c strcspn.c strdup.c \ - strerror.c strlcat.c strlcpy.c strlen.c strmode.c strncat.c strncmp.c \ - strncpy.c strcasestr.c strnstr.c \ + strcat.c strcasestr.c strchr.c strcmp.c strcoll.c strcpy.c strcspn.c \ + strdup.c strerror.c strlcat.c strlcpy.c strlen.c strmode.c strncat.c \ + strncmp.c strncpy.c strnstr.c \ strpbrk.c strrchr.c strsep.c strsignal.c strspn.c strstr.c strtok.c \ strxfrm.c swab.c wcscat.c wcschr.c wcscmp.c wcscoll.c wcscpy.c \ wcscspn.c wcsdup.c \ From kib at FreeBSD.org Sat Dec 6 01:37:54 2008 From: kib at FreeBSD.org (Konstantin Belousov) Date: Sat Dec 6 01:38:06 2008 Subject: svn commit: r185690 - head/lib/libc/string Message-ID: <200812060937.mB69bs2w089432@svn.freebsd.org> Author: kib Date: Sat Dec 6 09:37:54 2008 New Revision: 185690 URL: http://svn.freebsd.org/changeset/base/185690 Log: Import the strndup(3) function. Copyright attribution is kept the same as in original NetBSD source. Submitted by: Florian Smeets Obtained from: NetBSD MFC after: 2 weeks Added: head/lib/libc/string/strndup.c (contents, props changed) Modified: head/lib/libc/string/Makefile.inc head/lib/libc/string/Symbol.map head/lib/libc/string/strdup.3 Modified: head/lib/libc/string/Makefile.inc ============================================================================== --- head/lib/libc/string/Makefile.inc Sat Dec 6 09:28:46 2008 (r185689) +++ head/lib/libc/string/Makefile.inc Sat Dec 6 09:37:54 2008 (r185690) @@ -11,7 +11,7 @@ MISRCS+=bcmp.c bcopy.c bzero.c ffs.c ffs memcpy.c memmem.c memmove.c memset.c rindex.c stpcpy.c strcasecmp.c \ strcat.c strcasestr.c strchr.c strcmp.c strcoll.c strcpy.c strcspn.c \ strdup.c strerror.c strlcat.c strlcpy.c strlen.c strmode.c strncat.c \ - strncmp.c strncpy.c strnstr.c \ + strncmp.c strncpy.c strndup.c strnstr.c \ strpbrk.c strrchr.c strsep.c strsignal.c strspn.c strstr.c strtok.c \ strxfrm.c swab.c wcscat.c wcschr.c wcscmp.c wcscoll.c wcscpy.c \ wcscspn.c wcsdup.c \ @@ -47,6 +47,7 @@ MLINKS+=strcat.3 strncat.3 MLINKS+=strchr.3 strrchr.3 MLINKS+=strcmp.3 strncmp.3 MLINKS+=strcpy.3 stpcpy.3 +MLINKS+=strdup.3 strndup.3 MLINKS+=strcpy.3 strncpy.3 MLINKS+=strerror.3 perror.3 strerror.3 sys_errlist.3 strerror.3 sys_nerr.3 MLINKS+=strerror.3 strerror_r.3 Modified: head/lib/libc/string/Symbol.map ============================================================================== --- head/lib/libc/string/Symbol.map Sat Dec 6 09:28:46 2008 (r185689) +++ head/lib/libc/string/Symbol.map Sat Dec 6 09:37:54 2008 (r185690) @@ -81,6 +81,7 @@ FBSD_1.1 { ffsll; flsll; memrchr; + strndup; }; FBSDprivate_1.0 { Modified: head/lib/libc/string/strdup.3 ============================================================================== --- head/lib/libc/string/strdup.3 Sat Dec 6 09:28:46 2008 (r185689) +++ head/lib/libc/string/strdup.3 Sat Dec 6 09:37:54 2008 (r185690) @@ -28,11 +28,12 @@ .\" @(#)strdup.3 8.1 (Berkeley) 6/9/93 .\" $FreeBSD$ .\" -.Dd June 9, 1993 +.Dd Dec 5, 2008 .Dt STRDUP 3 .Os .Sh NAME -.Nm strdup +.Nm strdup , +.Nm strndup .Nd save a copy of a string .Sh LIBRARY .Lb libc @@ -40,6 +41,8 @@ .In string.h .Ft char * .Fn strdup "const char *str" +.Ft char * +.Fn strndup "const char *str" "size_t len" .Sh DESCRIPTION The .Fn strdup @@ -56,6 +59,16 @@ If insufficient memory is available, NUL .Va errno is set to .Er ENOMEM . +.Pp +The +.Fn strndup +function copies at most +.Fa len +characters from the string +.Fa str +always +.Dv NUL +terminating the copied string. .Sh SEE ALSO .Xr free 3 , .Xr malloc 3 @@ -64,3 +77,7 @@ The .Fn strdup function first appeared in .Bx 4.4 . +The +.Fn strndup +function was added in +.Fx 8.0 . Added: head/lib/libc/string/strndup.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libc/string/strndup.c Sat Dec 6 09:37:54 2008 (r185690) @@ -0,0 +1,53 @@ +/* $NetBSD: strndup.c,v 1.3 2007/01/14 23:41:24 cbiere Exp $ */ + +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +char * +strndup(const char *str, size_t n) +{ + size_t len; + char *copy; + + for (len = 0; len < n && str[len]; len++) + continue; + + if ((copy = malloc(len + 1)) == NULL) + return (NULL); + memcpy(copy, str, len); + copy[len] = '\0'; + return (copy); +} From brde at optusnet.com.au Sat Dec 6 02:34:24 2008 From: brde at optusnet.com.au (Bruce Evans) Date: Sat Dec 6 02:34:31 2008 Subject: svn commit: r185684 - head/usr.bin/cpio In-Reply-To: <200812060715.mB67FgVA086614@svn.freebsd.org> References: <200812060715.mB67FgVA086614@svn.freebsd.org> Message-ID: <20081206212307.X5659@delplex.bde.org> On Sat, 6 Dec 2008, Tim Kientzle wrote: > Log: > Make the GCC-specific __dead2 markers conditional on whether > we're compiling under GCC. These are FreeBSD-specific. __dead is 4.4BSD-specific, but hasn't done anything since gcc-1.x. Though I added __dead2 to support gcc-2 in 1994, 4.4BSD didn't have it, and NetBSD 4 years ago doesn't define it or otherwise support the noreturn attribute in . Bruce From danger at FreeBSD.org Sat Dec 6 03:21:11 2008 From: danger at FreeBSD.org (Daniel Gerzo) Date: Sat Dec 6 03:21:16 2008 Subject: svn commit: r185692 - head/sys/boot/common Message-ID: <200812061121.mB6BLAXT092549@svn.freebsd.org> Author: danger (doc committer) Date: Sat Dec 6 11:21:10 2008 New Revision: 185692 URL: http://svn.freebsd.org/changeset/base/185692 Log: - correct variable name PR: docs/129448 Submitted by: Kenyon Ralph MFC after: Revision 1.91 is merged Modified: head/sys/boot/common/loader.8 Modified: head/sys/boot/common/loader.8 ============================================================================== --- head/sys/boot/common/loader.8 Sat Dec 6 09:38:41 2008 (r185691) +++ head/sys/boot/common/loader.8 Sat Dec 6 11:21:10 2008 (r185692) @@ -454,7 +454,7 @@ if the script terminates with a non-zero or if a SIGTERM is delivered to the .Xr init 8 process (PID 1). -.It Va init_script +.It Va init_shell Defines the shell binary to be used for executing the various shell scripts. The default is .Dq Li /bin/sh . From trasz at FreeBSD.org Sat Dec 6 03:33:11 2008 From: trasz at FreeBSD.org (Edward Tomasz Napierala) Date: Sat Dec 6 03:33:17 2008 Subject: svn commit: r185693 - head/sys/geom/journal Message-ID: <200812061133.mB6BXA1S092810@svn.freebsd.org> Author: trasz Date: Sat Dec 6 11:33:10 2008 New Revision: 185693 URL: http://svn.freebsd.org/changeset/base/185693 Log: Make it possible to use gjournal for the root filesystem. Previously, an unclean shutdown would make it impossible to mount rootfs at boot. PR: kern/128529 Reviewed by: pjd Approved by: rwatson (mentor) Sponsored by: FreeBSD Foundation Modified: head/sys/geom/journal/g_journal.c head/sys/geom/journal/g_journal.h Modified: head/sys/geom/journal/g_journal.c ============================================================================== --- head/sys/geom/journal/g_journal.c Sat Dec 6 11:21:10 2008 (r185692) +++ head/sys/geom/journal/g_journal.c Sat Dec 6 11:33:10 2008 (r185693) @@ -2108,6 +2108,12 @@ g_journal_worker(void *arg) g_topology_unlock(); last_write = time_second; + if (sc->sc_rootmount != NULL) { + GJ_DEBUG(1, "root_mount_rel %p", sc->sc_rootmount); + root_mount_rel(sc->sc_rootmount); + sc->sc_rootmount = NULL; + } + for (;;) { /* Get first request from the queue. */ mtx_lock(&sc->sc_mtx); @@ -2304,6 +2310,9 @@ g_journal_create(struct g_class *mp, str sc->sc_inactive.jj_queue = NULL; sc->sc_active.jj_queue = NULL; + sc->sc_rootmount = root_mount_hold("GJOURNAL"); + GJ_DEBUG(1, "root_mount_hold %p", sc->sc_rootmount); + callout_init(&sc->sc_callout, CALLOUT_MPSAFE); if (md->md_type != GJ_TYPE_COMPLETE) { /* @@ -2434,6 +2443,13 @@ g_journal_destroy(struct g_journal_softc sc->sc_flags |= (GJF_DEVICE_DESTROY | GJF_DEVICE_CLEAN); g_topology_unlock(); + + if (sc->sc_rootmount != NULL) { + GJ_DEBUG(1, "root_mount_rel %p", sc->sc_rootmount); + root_mount_rel(sc->sc_rootmount); + sc->sc_rootmount = NULL; + } + callout_drain(&sc->sc_callout); mtx_lock(&sc->sc_mtx); wakeup(sc); Modified: head/sys/geom/journal/g_journal.h ============================================================================== --- head/sys/geom/journal/g_journal.h Sat Dec 6 11:21:10 2008 (r185692) +++ head/sys/geom/journal/g_journal.h Sat Dec 6 11:33:10 2008 (r185693) @@ -163,6 +163,8 @@ struct g_journal_softc { struct callout sc_callout; struct proc *sc_worker; + + struct root_hold_token *sc_rootmount; }; #define sc_dprovider sc_dconsumer->provider #define sc_jprovider sc_jconsumer->provider From rrs at FreeBSD.org Sat Dec 6 05:19:54 2008 From: rrs at FreeBSD.org (Randall Stewart) Date: Sat Dec 6 05:20:09 2008 Subject: svn commit: r185694 - in head/sys: netinet netinet6 Message-ID: <200812061319.mB6DJs0g094953@svn.freebsd.org> Author: rrs Date: Sat Dec 6 13:19:54 2008 New Revision: 185694 URL: http://svn.freebsd.org/changeset/base/185694 Log: Code from the hack-session known as the IETF (and a bit of debugging afterwards): - Fix protection code for notification generation. - Decouple associd from vtag - Allow vtags to have less strigent requirements in non-uniqueness. o don't pre-hash them when you issue one in a cookie. o Allow duplicates and use addresses and ports to discriminate amongst the duplicates during lookup. - Add support for the NAT draft draft-ietf-behave-sctpnat-00, this is still experimental and needs more extensive testing with the Jason Butt ipfw changes. - Support for the SENDER_DRY event to get DTLS in OpenSSL working with a set of patches from Michael Tuexen (hopefully heading to OpenSSL soon). - Update the support of SCTP-AUTH by Peter Lei. - Use macros for refcounting. - Fix MTU for UDP encapsulation. - Fix reporting back of unsent data. - Update assoc send counter handling to be consistent with endpoint sent counter. - Fix a bug in PR-SCTP. - Fix so we only send another FWD-TSN when a SACK arrives IF and only if the adv-peer-ack point progressed. However we still make sure a timer is running if we do have an adv_peer_ack point. - Fix PR-SCTP bug where chunks were retransmitted if they are sent unreliable but not abandoned yet. With the help of: Michael Teuxen and Peter Lei :-) MFC after: 4 weeks Modified: head/sys/netinet/sctp.h head/sys/netinet/sctp_asconf.c head/sys/netinet/sctp_asconf.h head/sys/netinet/sctp_auth.c head/sys/netinet/sctp_auth.h head/sys/netinet/sctp_constants.h head/sys/netinet/sctp_header.h head/sys/netinet/sctp_indata.c head/sys/netinet/sctp_indata.h head/sys/netinet/sctp_input.c head/sys/netinet/sctp_os_bsd.h head/sys/netinet/sctp_output.c head/sys/netinet/sctp_output.h head/sys/netinet/sctp_pcb.c head/sys/netinet/sctp_pcb.h head/sys/netinet/sctp_structs.h head/sys/netinet/sctp_sysctl.c head/sys/netinet/sctp_sysctl.h head/sys/netinet/sctp_timer.c head/sys/netinet/sctp_uio.h head/sys/netinet/sctp_usrreq.c head/sys/netinet/sctp_var.h head/sys/netinet/sctputil.c head/sys/netinet/sctputil.h head/sys/netinet6/sctp6_usrreq.c Modified: head/sys/netinet/sctp.h ============================================================================== --- head/sys/netinet/sctp.h Sat Dec 6 11:33:10 2008 (r185693) +++ head/sys/netinet/sctp.h Sat Dec 6 13:19:54 2008 (r185694) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -111,6 +111,7 @@ struct sctp_paramhdr { /* explict EOR signalling */ #define SCTP_EXPLICIT_EOR 0x0000001b #define SCTP_REUSE_PORT 0x0000001c /* rw */ +#define SCTP_AUTH_DEACTIVATE_KEY 0x0000001d /* * read-only options @@ -154,6 +155,8 @@ struct sctp_paramhdr { /* CMT ON/OFF socket option */ #define SCTP_CMT_ON_OFF 0x00001200 #define SCTP_CMT_USE_DAC 0x00001201 +/* EY - NR_SACK on/off socket option */ +#define SCTP_NR_SACK_ON_OFF 0x00001300 /* JRS - Pluggable Congestion Control Socket option */ #define SCTP_PLUGGABLE_CC 0x00001202 @@ -293,11 +296,15 @@ struct sctp_paramhdr { #define SCTP_CAUSE_PROTOCOL_VIOLATION 0x000d /* Error causes from RFC5061 */ -#define SCTP_CAUSE_DELETING_LAST_ADDR 0xa0 -#define SCTP_CAUSE_RESOURCE_SHORTAGE 0xa1 -#define SCTP_CAUSE_DELETING_SRC_ADDR 0xa2 -#define SCTP_CAUSE_ILLEGAL_ASCONF_ACK 0xa3 -#define SCTP_CAUSE_REQUEST_REFUSED 0xa4 +#define SCTP_CAUSE_DELETING_LAST_ADDR 0x00a0 +#define SCTP_CAUSE_RESOURCE_SHORTAGE 0x00a1 +#define SCTP_CAUSE_DELETING_SRC_ADDR 0x00a2 +#define SCTP_CAUSE_ILLEGAL_ASCONF_ACK 0x00a3 +#define SCTP_CAUSE_REQUEST_REFUSED 0x00a4 + +/* Error causes from nat-draft */ +#define SCTP_CAUSE_NAT_COLLIDING_STATE 0x00b0 +#define SCTP_CAUSE_NAT_MISSING_STATE 0x00b1 /* Error causes from RFC4895 */ #define SCTP_CAUSE_UNSUPPORTED_HMACID 0x0105 @@ -364,6 +371,8 @@ struct sctp_error_unrecognized_chunk { #define SCTP_SHUTDOWN_COMPLETE 0x0e /* RFC4895 */ #define SCTP_AUTHENTICATION 0x0f +/* EY nr_sack chunk id*/ +#define SCTP_NR_SELECTIVE_ACK 0x10 /************0x40 series ***********/ /************0x80 series ***********/ /* RFC5061 */ @@ -406,6 +415,9 @@ struct sctp_error_unrecognized_chunk { /* ECN Nonce: SACK Chunk Specific Flags */ #define SCTP_SACK_NONCE_SUM 0x01 +/* EY nr_sack all bit - All bit is the 2nd LSB of nr_sack chunk flags*/ +/* if All bit is set in an nr-sack chunk, then all nr gap acks gap acks*/ +#define SCTP_NR_SACK_ALL_BIT 0x02 /* CMT DAC algorithm SACK flag */ #define SCTP_SACK_CMT_DAC 0x80 @@ -467,6 +479,7 @@ struct sctp_error_unrecognized_chunk { #define SCTP_PCB_FLAGS_NEEDS_MAPPED_V4 0x00800000 #define SCTP_PCB_FLAGS_MULTIPLE_ASCONFS 0x01000000 #define SCTP_PCB_FLAGS_PORTREUSE 0x02000000 +#define SCTP_PCB_FLAGS_DRYEVNT 0x04000000 /*- * mobility_features parameters (by micchie).Note * these features are applied against the Modified: head/sys/netinet/sctp_asconf.c ============================================================================== --- head/sys/netinet/sctp_asconf.c Sat Dec 6 11:33:10 2008 (r185693) +++ head/sys/netinet/sctp_asconf.c Sat Dec 6 13:19:54 2008 (r185694) @@ -761,6 +761,9 @@ sctp_handle_asconf(struct mbuf *m, unsig m_result = sctp_process_asconf_set_primary(m, aph, stcb, error); break; + case SCTP_NAT_VTAGS: + SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: sees a NAT VTAG state parameter\n"); + break; case SCTP_SUCCESS_REPORT: /* not valid in an ASCONF chunk */ break; @@ -1349,6 +1352,7 @@ sctp_asconf_queue_mgmt(struct sctp_tcb * SCTPDBG(SCTP_DEBUG_ASCONF1, "asconf_queue_mgmt: failed to get memory!\n"); return (-1); } + aa->special_del = 0; /* fill in asconf address parameter fields */ /* top level elements are "networked" during send */ aa->ap.aph.ph.param_type = type; @@ -1555,6 +1559,7 @@ sctp_asconf_queue_sa_delete(struct sctp_ "sctp_asconf_queue_sa_delete: failed to get memory!\n"); return (-1); } + aa->special_del = 0; /* fill in asconf address parameter fields */ /* top level elements are "networked" during send */ aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS; @@ -2691,6 +2696,7 @@ sctp_compose_asconf(struct sctp_tcb *stc * case) */ if (lookup_used == 0 && + (aa->special_del == 0) && aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) { struct sctp_ipv6addr_param *lookup; uint16_t p_size, addr_size; @@ -3234,3 +3240,195 @@ sctp_addr_mgmt_ep_sa(struct sctp_inpcb * } return (0); } + +void +sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb, + struct sctp_nets *net) +{ + struct sctp_asconf_addr *aa; + struct sctp_ifa *sctp_ifap; + struct sctp_asconf_tag_param *vtag; + struct sockaddr_in *to; + +#ifdef INET6 + struct sockaddr_in6 *to6; + +#endif + if (net == NULL) { + SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing net\n"); + return; + } + if (stcb == NULL) { + SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing stcb\n"); + return; + } + /* + * Need to have in the asconf: - vtagparam(my_vtag/peer_vtag) - + * add(0.0.0.0) - del(0.0.0.0) - Any global addresses add(addr) + */ + SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), + SCTP_M_ASC_ADDR); + if (aa == NULL) { + /* didn't get memory */ + SCTPDBG(SCTP_DEBUG_ASCONF1, + "sctp_asconf_send_nat_state_update: failed to get memory!\n"); + return; + } + aa->special_del = 0; + /* fill in asconf address parameter fields */ + /* top level elements are "networked" during send */ + aa->ifa = NULL; + aa->sent = 0; /* clear sent flag */ + vtag = (struct sctp_asconf_tag_param *)&aa->ap.aph; + vtag->aph.ph.param_type = SCTP_NAT_VTAGS; + vtag->aph.ph.param_length = sizeof(struct sctp_asconf_tag_param); + vtag->local_vtag = htonl(stcb->asoc.my_vtag); + vtag->remote_vtag = htonl(stcb->asoc.peer_vtag); + TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); + + SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), + SCTP_M_ASC_ADDR); + if (aa == NULL) { + /* didn't get memory */ + SCTPDBG(SCTP_DEBUG_ASCONF1, + "sctp_asconf_send_nat_state_update: failed to get memory!\n"); + return; + } + memset(aa, 0, sizeof(struct sctp_asconf_addr)); + /* fill in asconf address parameter fields */ + /* ADD(0.0.0.0) */ + if (net->ro._l_addr.sa.sa_family == AF_INET) { + aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS; + aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param); + aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; + aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param); + /* No need to add an address, we are using 0.0.0.0 */ + TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); + } +#ifdef INET6 + else if (net->ro._l_addr.sa.sa_family == AF_INET6) { + aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS; + aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param); + aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; + aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param); + /* No need to add an address, we are using 0.0.0.0 */ + TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); + } +#endif /* INET6 */ + SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), + SCTP_M_ASC_ADDR); + if (aa == NULL) { + /* didn't get memory */ + SCTPDBG(SCTP_DEBUG_ASCONF1, + "sctp_asconf_send_nat_state_update: failed to get memory!\n"); + return; + } + memset(aa, 0, sizeof(struct sctp_asconf_addr)); + /* fill in asconf address parameter fields */ + /* ADD(0.0.0.0) */ + if (net->ro._l_addr.sa.sa_family == AF_INET) { + aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS; + aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param); + aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; + aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param); + /* No need to add an address, we are using 0.0.0.0 */ + TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); + } +#ifdef INET6 + else if (net->ro._l_addr.sa.sa_family == AF_INET6) { + aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS; + aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param); + aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; + aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param); + /* No need to add an address, we are using 0.0.0.0 */ + TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); + } +#endif /* INET6 */ + /* Now we must hunt the addresses and add all global addresses */ + if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { + struct sctp_vrf *vrf = NULL; + struct sctp_ifn *sctp_ifnp; + uint32_t vrf_id; + + vrf_id = stcb->sctp_ep->def_vrf_id; + vrf = sctp_find_vrf(vrf_id); + if (vrf == NULL) { + goto skip_rest; + } + SCTP_IPI_ADDR_RLOCK(); + LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) { + LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) { + if (sctp_ifap->address.sa.sa_family == AF_INET) { + to = &sctp_ifap->address.sin; + + if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) { + continue; + } + if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) { + continue; + } + } +#ifdef INET6 + else if (sctp_ifap->address.sa.sa_family == AF_INET6) { + to6 = &sctp_ifap->address.sin6; + if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) { + continue; + } + if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) { + continue; + } + } +#endif + sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS); + } + } + SCTP_IPI_ADDR_RUNLOCK(); + } else { + struct sctp_laddr *laddr; + + LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) { + if (laddr->ifa == NULL) { + continue; + } + if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) + /* + * Address being deleted by the system, dont + * list. + */ + continue; + if (laddr->action == SCTP_DEL_IP_ADDRESS) { + /* + * Address being deleted on this ep don't + * list. + */ + continue; + } + sctp_ifap = laddr->ifa; + if (sctp_ifap->address.sa.sa_family == AF_INET) { + to = &sctp_ifap->address.sin; + + if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) { + continue; + } + if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) { + continue; + } + } +#ifdef INET6 + else if (sctp_ifap->address.sa.sa_family == AF_INET6) { + to6 = &sctp_ifap->address.sin6; + if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) { + continue; + } + if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) { + continue; + } + } +#endif + sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS); + } + } +skip_rest: + /* Now we must send the asconf into the queue */ + sctp_send_asconf(stcb, net, 0); +} Modified: head/sys/netinet/sctp_asconf.h ============================================================================== --- head/sys/netinet/sctp_asconf.h Sat Dec 6 11:33:10 2008 (r185693) +++ head/sys/netinet/sctp_asconf.h Sat Dec 6 13:19:54 2008 (r185694) @@ -86,6 +86,10 @@ extern void extern void sctp_net_immediate_retrans(struct sctp_tcb *, struct sctp_nets *); +extern void +sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb, + struct sctp_nets *net); + extern int sctp_is_addr_pending(struct sctp_tcb *, struct sctp_ifa *); Modified: head/sys/netinet/sctp_auth.c ============================================================================== --- head/sys/netinet/sctp_auth.c Sat Dec 6 11:33:10 2008 (r185693) +++ head/sys/netinet/sctp_auth.c Sat Dec 6 13:19:54 2008 (r185694) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -359,9 +359,11 @@ sctp_set_key(uint8_t * key, uint32_t key return (new_key); } -/* +/*- * given two keys of variable size, compute which key is "larger/smaller" - * returns: 1 if key1 > key2 -1 if key1 < key2 0 if key1 = key2 + * returns: 1 if key1 > key2 + * -1 if key1 < key2 + * 0 if key1 = key2 */ static int sctp_compare_key(sctp_key_t * key1, sctp_key_t * key2) @@ -531,13 +533,18 @@ sctp_alloc_sharedkey(void) } new_key->keyid = 0; new_key->key = NULL; + new_key->refcount = 1; + new_key->deactivated = 0; return (new_key); } void sctp_free_sharedkey(sctp_sharedkey_t * skey) { - if (skey != NULL) { + if (skey == NULL) + return; + + if (SCTP_DECREMENT_AND_CHECK_REFCOUNT(&skey->refcount)) { if (skey->key != NULL) sctp_free_key(skey->key); SCTP_FREE(skey, SCTP_M_AUTH_KY); @@ -556,40 +563,93 @@ sctp_find_sharedkey(struct sctp_keyhead return (NULL); } -void +int sctp_insert_sharedkey(struct sctp_keyhead *shared_keys, sctp_sharedkey_t * new_skey) { sctp_sharedkey_t *skey; if ((shared_keys == NULL) || (new_skey == NULL)) - return; + return (EINVAL); /* insert into an empty list? */ if (SCTP_LIST_EMPTY(shared_keys)) { LIST_INSERT_HEAD(shared_keys, new_skey, next); - return; + return (0); } /* insert into the existing list, ordered by key id */ LIST_FOREACH(skey, shared_keys, next) { if (new_skey->keyid < skey->keyid) { /* insert it before here */ LIST_INSERT_BEFORE(skey, new_skey, next); - return; + return (0); } else if (new_skey->keyid == skey->keyid) { /* replace the existing key */ + /* verify this key *can* be replaced */ + if ((skey->deactivated) && (skey->refcount > 1)) { + SCTPDBG(SCTP_DEBUG_AUTH1, + "can't replace shared key id %u\n", + new_skey->keyid); + return (EBUSY); + } SCTPDBG(SCTP_DEBUG_AUTH1, "replacing shared key id %u\n", new_skey->keyid); LIST_INSERT_BEFORE(skey, new_skey, next); LIST_REMOVE(skey, next); sctp_free_sharedkey(skey); - return; + return (0); } if (LIST_NEXT(skey, next) == NULL) { /* belongs at the end of the list */ LIST_INSERT_AFTER(skey, new_skey, next); - return; + return (0); + } + } + /* shouldn't reach here */ + return (0); +} + +void +sctp_auth_key_acquire(struct sctp_tcb *stcb, uint16_t key_id) +{ + sctp_sharedkey_t *skey; + + /* find the shared key */ + skey = sctp_find_sharedkey(&stcb->asoc.shared_keys, key_id); + + /* bump the ref count */ + if (skey) { + atomic_add_int(&skey->refcount, 1); + SCTPDBG(SCTP_DEBUG_AUTH2, + "%s: stcb %p key %u refcount acquire to %d\n", + __FUNCTION__, stcb, key_id, skey->refcount); + } +} + +void +sctp_auth_key_release(struct sctp_tcb *stcb, uint16_t key_id) +{ + sctp_sharedkey_t *skey; + + /* find the shared key */ + skey = sctp_find_sharedkey(&stcb->asoc.shared_keys, key_id); + + /* decrement the ref count */ + if (skey) { + sctp_free_sharedkey(skey); + SCTPDBG(SCTP_DEBUG_AUTH2, + "%s: stcb %p key %u refcount release to %d\n", + __FUNCTION__, stcb, key_id, skey->refcount); + + /* see if a notification should be generated */ + if ((skey->refcount <= 1) && (skey->deactivated)) { + /* notify ULP that key is no longer used */ + sctp_ulp_notify(SCTP_NOTIFY_AUTH_FREE_KEY, stcb, + key_id, 0, SCTP_SO_NOT_LOCKED); + SCTPDBG(SCTP_DEBUG_AUTH2, + "%s: stcb %p key %u no longer used, %d\n", + __FUNCTION__, stcb, key_id, skey->refcount); } } } @@ -623,7 +683,7 @@ sctp_copy_skeylist(const struct sctp_key LIST_FOREACH(skey, src, next) { new_skey = sctp_copy_sharedkey(skey); if (new_skey != NULL) { - sctp_insert_sharedkey(dest, new_skey); + (void)sctp_insert_sharedkey(dest, new_skey); count++; } } @@ -727,9 +787,9 @@ sctp_default_supported_hmaclist(void) return (new_list); } -/* - * HMAC algos are listed in priority/preference order find the best HMAC id - * to use for the peer based on local support +/*- + * HMAC algos are listed in priority/preference order + * find the best HMAC id to use for the peer based on local support */ uint16_t sctp_negotiate_hmacid(sctp_hmaclist_t * peer, sctp_hmaclist_t * local) @@ -760,9 +820,9 @@ sctp_negotiate_hmacid(sctp_hmaclist_t * return (SCTP_AUTH_HMAC_ID_RSVD); } -/* - * serialize the HMAC algo list and return space used caller must guarantee - * ptr has appropriate space +/*- + * serialize the HMAC algo list and return space used + * caller must guarantee ptr has appropriate space */ int sctp_serialize_hmaclist(sctp_hmaclist_t * list, uint8_t * ptr) @@ -994,7 +1054,7 @@ sctp_hmac_final(uint16_t hmac_algo, sctp } /* end switch */ } -/* +/*- * Keyed-Hashing for Message Authentication: FIPS 198 (RFC 2104) * * Compute the HMAC digest using the desired hash key, text, and HMAC @@ -1142,9 +1202,10 @@ sctp_hmac_m(uint16_t hmac_algo, uint8_t return (digestlen); } -/* +/*- * verify the HMAC digest using the desired hash key, text, and HMAC - * algorithm. Returns -1 on error, 0 on success. + * algorithm. + * Returns -1 on error, 0 on success. */ int sctp_verify_hmac(uint16_t hmac_algo, uint8_t * key, uint32_t keylen, @@ -1263,10 +1324,10 @@ sctp_auth_is_supported_hmac(sctp_hmaclis } -/* - * clear any cached key(s) if they match the given key id on an association - * the cached key(s) will be recomputed and re-cached at next use. ASSUMES - * TCB_LOCK is already held +/*- + * clear any cached key(s) if they match the given key id on an association. + * the cached key(s) will be recomputed and re-cached at next use. + * ASSUMES TCB_LOCK is already held */ void sctp_clear_cachedkeys(struct sctp_tcb *stcb, uint16_t keyid) @@ -1284,9 +1345,10 @@ sctp_clear_cachedkeys(struct sctp_tcb *s } } -/* +/*- * clear any cached key(s) if they match the given key id for all assocs on - * an association ASSUMES INP_WLOCK is already held + * an endpoint. + * ASSUMES INP_WLOCK is already held */ void sctp_clear_cachedkeys_ep(struct sctp_inpcb *inp, uint16_t keyid) @@ -1304,8 +1366,9 @@ sctp_clear_cachedkeys_ep(struct sctp_inp } } -/* - * delete a shared key from an association ASSUMES TCB_LOCK is already held +/*- + * delete a shared key from an association + * ASSUMES TCB_LOCK is already held */ int sctp_delete_sharedkey(struct sctp_tcb *stcb, uint16_t keyid) @@ -1316,7 +1379,7 @@ sctp_delete_sharedkey(struct sctp_tcb *s return (-1); /* is the keyid the assoc active sending key */ - if (keyid == stcb->asoc.authinfo.assoc_keyid) + if (keyid == stcb->asoc.authinfo.active_keyid) return (-1); /* does the key exist? */ @@ -1324,6 +1387,10 @@ sctp_delete_sharedkey(struct sctp_tcb *s if (skey == NULL) return (-1); + /* are there other refcount holders on the key? */ + if (skey->refcount > 1) + return (-1); + /* remove it */ LIST_REMOVE(skey, next); sctp_free_sharedkey(skey); /* frees skey->key as well */ @@ -1333,35 +1400,29 @@ sctp_delete_sharedkey(struct sctp_tcb *s return (0); } -/* - * deletes a shared key from the endpoint ASSUMES INP_WLOCK is already held +/*- + * deletes a shared key from the endpoint + * ASSUMES INP_WLOCK is already held */ int sctp_delete_sharedkey_ep(struct sctp_inpcb *inp, uint16_t keyid) { sctp_sharedkey_t *skey; - struct sctp_tcb *stcb; if (inp == NULL) return (-1); - /* is the keyid the active sending key on the endpoint or any assoc */ + /* is the keyid the active sending key on the endpoint */ if (keyid == inp->sctp_ep.default_keyid) return (-1); - LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { - SCTP_TCB_LOCK(stcb); - if (keyid == stcb->asoc.authinfo.assoc_keyid) { - SCTP_TCB_UNLOCK(stcb); - return (-1); - } - SCTP_TCB_UNLOCK(stcb); - } /* does the key exist? */ skey = sctp_find_sharedkey(&inp->sctp_ep.shared_keys, keyid); if (skey == NULL) return (-1); + /* endpoint keys are not refcounted */ + /* remove it */ LIST_REMOVE(skey, next); sctp_free_sharedkey(skey); /* frees skey->key as well */ @@ -1371,60 +1432,36 @@ sctp_delete_sharedkey_ep(struct sctp_inp return (0); } -/* - * set the active key on an association ASSUME TCB_LOCK is already held +/*- + * set the active key on an association + * ASSUMES TCB_LOCK is already held */ int sctp_auth_setactivekey(struct sctp_tcb *stcb, uint16_t keyid) { sctp_sharedkey_t *skey = NULL; - sctp_key_t *key = NULL; - int using_ep_key = 0; /* find the key on the assoc */ skey = sctp_find_sharedkey(&stcb->asoc.shared_keys, keyid); if (skey == NULL) { - /* if not on the assoc, find the key on the endpoint */ - atomic_add_int(&stcb->asoc.refcnt, 1); - SCTP_TCB_UNLOCK(stcb); - SCTP_INP_RLOCK(stcb->sctp_ep); - SCTP_TCB_LOCK(stcb); - atomic_add_int(&stcb->asoc.refcnt, -1); - skey = sctp_find_sharedkey(&stcb->sctp_ep->sctp_ep.shared_keys, - keyid); - using_ep_key = 1; - } - if (skey == NULL) { /* that key doesn't exist */ - if (using_ep_key) { - SCTP_INP_RUNLOCK(stcb->sctp_ep); - } return (-1); } - /* get the shared key text */ - key = skey->key; - - /* free any existing cached key */ - if (stcb->asoc.authinfo.assoc_key != NULL) - sctp_free_key(stcb->asoc.authinfo.assoc_key); - /* compute a new assoc key and cache it */ - stcb->asoc.authinfo.assoc_key = - sctp_compute_hashkey(stcb->asoc.authinfo.random, - stcb->asoc.authinfo.peer_random, key); - stcb->asoc.authinfo.assoc_keyid = keyid; -#ifdef SCTP_DEBUG - if (SCTP_AUTH_DEBUG) - sctp_print_key(stcb->asoc.authinfo.assoc_key, "Assoc Key"); -#endif - - if (using_ep_key) { - SCTP_INP_RUNLOCK(stcb->sctp_ep); + if ((skey->deactivated) && (skey->refcount > 1)) { + /* can't reactivate a deactivated key with other refcounts */ + return (-1); } + /* set the (new) active key */ + stcb->asoc.authinfo.active_keyid = keyid; + /* reset the deactivated flag */ + skey->deactivated = 0; + return (0); } -/* - * set the active key on an endpoint ASSUMES INP_WLOCK is already held +/*- + * set the active key on an endpoint + * ASSUMES INP_WLOCK is already held */ int sctp_auth_setactivekey_ep(struct sctp_inpcb *inp, uint16_t keyid) @@ -1441,6 +1478,69 @@ sctp_auth_setactivekey_ep(struct sctp_in return (0); } +/*- + * deactivates a shared key from the association + * ASSUMES INP_WLOCK is already held + */ +int +sctp_deact_sharedkey(struct sctp_tcb *stcb, uint16_t keyid) +{ + sctp_sharedkey_t *skey; + + if (stcb == NULL) + return (-1); + + /* is the keyid the assoc active sending key */ + if (keyid == stcb->asoc.authinfo.active_keyid) + return (-1); + + /* does the key exist? */ + skey = sctp_find_sharedkey(&stcb->asoc.shared_keys, keyid); + if (skey == NULL) + return (-1); + + /* are there other refcount holders on the key? */ + if (skey->refcount == 1) { + /* no other users, send a notification for this key */ + sctp_ulp_notify(SCTP_NOTIFY_AUTH_FREE_KEY, stcb, keyid, 0, + SCTP_SO_LOCKED); + } + /* mark the key as deactivated */ + skey->deactivated = 1; + + return (0); +} + +/*- + * deactivates a shared key from the endpoint + * ASSUMES INP_WLOCK is already held + */ +int +sctp_deact_sharedkey_ep(struct sctp_inpcb *inp, uint16_t keyid) +{ + sctp_sharedkey_t *skey; + + if (inp == NULL) + return (-1); + + /* is the keyid the active sending key on the endpoint */ + if (keyid == inp->sctp_ep.default_keyid) + return (-1); + + /* does the key exist? */ + skey = sctp_find_sharedkey(&inp->sctp_ep.shared_keys, keyid); + if (skey == NULL) + return (-1); + + /* endpoint keys are not refcounted */ + + /* remove it */ + LIST_REMOVE(skey, next); + sctp_free_sharedkey(skey); /* frees skey->key as well */ + + return (0); +} + /* * get local authentication parameters from cookie (from INIT-ACK) */ @@ -1581,9 +1681,13 @@ sctp_auth_get_cookie_params(struct sctp_ /* negotiate what HMAC to use for the peer */ stcb->asoc.peer_hmac_id = sctp_negotiate_hmacid(stcb->asoc.peer_hmacs, stcb->asoc.local_hmacs); + /* copy defaults from the endpoint */ /* FIX ME: put in cookie? */ - stcb->asoc.authinfo.assoc_keyid = stcb->sctp_ep->sctp_ep.default_keyid; + stcb->asoc.authinfo.active_keyid = stcb->sctp_ep->sctp_ep.default_keyid; + /* copy out the shared key list (by reference) from the endpoint */ + (void)sctp_copy_skeylist(&stcb->sctp_ep->sctp_ep.shared_keys, + &stcb->asoc.shared_keys); } /* @@ -1591,7 +1695,7 @@ sctp_auth_get_cookie_params(struct sctp_ */ void sctp_fill_hmac_digest_m(struct mbuf *m, uint32_t auth_offset, - struct sctp_auth_chunk *auth, struct sctp_tcb *stcb) + struct sctp_auth_chunk *auth, struct sctp_tcb *stcb, uint16_t keyid) { uint32_t digestlen; sctp_sharedkey_t *skey; @@ -1603,15 +1707,15 @@ sctp_fill_hmac_digest_m(struct mbuf *m, /* zero the digest + chunk padding */ digestlen = sctp_get_hmac_digest_len(stcb->asoc.peer_hmac_id); bzero(auth->hmac, SCTP_SIZE32(digestlen)); - /* is an assoc key cached? */ - if (stcb->asoc.authinfo.assoc_key == NULL) { - skey = sctp_find_sharedkey(&stcb->asoc.shared_keys, - stcb->asoc.authinfo.assoc_keyid); - if (skey == NULL) { - /* not in the assoc list, so check the endpoint list */ - skey = sctp_find_sharedkey(&stcb->sctp_ep->sctp_ep.shared_keys, - stcb->asoc.authinfo.assoc_keyid); + + /* is the desired key cached? */ + if ((keyid != stcb->asoc.authinfo.assoc_keyid) || + (stcb->asoc.authinfo.assoc_key == NULL)) { + if (stcb->asoc.authinfo.assoc_key != NULL) { + /* free the old cached key */ + sctp_free_key(stcb->asoc.authinfo.assoc_key); } + skey = sctp_find_sharedkey(&stcb->asoc.shared_keys, keyid); /* the only way skey is NULL is if null key id 0 is used */ if (skey != NULL) key = skey->key; @@ -1621,6 +1725,7 @@ sctp_fill_hmac_digest_m(struct mbuf *m, stcb->asoc.authinfo.assoc_key = sctp_compute_hashkey(stcb->asoc.authinfo.random, stcb->asoc.authinfo.peer_random, key); + stcb->asoc.authinfo.assoc_keyid = keyid; SCTPDBG(SCTP_DEBUG_AUTH1, "caching key id %u\n", stcb->asoc.authinfo.assoc_keyid); #ifdef SCTP_DEBUG @@ -1630,11 +1735,10 @@ sctp_fill_hmac_digest_m(struct mbuf *m, #endif } /* set in the active key id */ - auth->shared_key_id = htons(stcb->asoc.authinfo.assoc_keyid); + auth->shared_key_id = htons(keyid); /* compute and fill in the digest */ - (void)sctp_compute_hmac_m(stcb->asoc.peer_hmac_id, - stcb->asoc.authinfo.assoc_key, + (void)sctp_compute_hmac_m(stcb->asoc.peer_hmac_id, stcb->asoc.authinfo.assoc_key, m, auth_offset, auth->hmac); } @@ -1671,9 +1775,11 @@ sctp_bzero_m(struct mbuf *m, uint32_t m_ } } -/* - * process the incoming Authentication chunk return codes: -1 on any - * authentication error 0 on authentication verification +/*- + * process the incoming Authentication chunk + * return codes: + * -1 on any authentication error + * 0 on authentication verification */ int sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *auth, @@ -1736,12 +1842,8 @@ sctp_handle_auth(struct sctp_tcb *stcb, if ((stcb->asoc.authinfo.recv_key == NULL) || (stcb->asoc.authinfo.recv_keyid != shared_key_id)) { /* find the shared key on the assoc first */ - skey = sctp_find_sharedkey(&stcb->asoc.shared_keys, shared_key_id); - if (skey == NULL) { - /* if not on the assoc, find it on the endpoint */ - skey = sctp_find_sharedkey(&stcb->sctp_ep->sctp_ep.shared_keys, - shared_key_id); - } + skey = sctp_find_sharedkey(&stcb->asoc.shared_keys, + shared_key_id); /* if the shared key isn't found, discard the chunk */ if (skey == NULL) { SCTP_STAT_INCR(sctps_recvivalkeyid); @@ -1758,7 +1860,8 @@ sctp_handle_auth(struct sctp_tcb *stcb, * *)stcb->asoc.authinfo.recv_keyid); */ sctp_notify_authentication(stcb, SCTP_AUTH_NEWKEY, - shared_key_id, stcb->asoc.authinfo.recv_keyid); + shared_key_id, stcb->asoc.authinfo.recv_keyid, + SCTP_SO_NOT_LOCKED); /* compute a new recv assoc key and cache it */ if (stcb->asoc.authinfo.recv_key != NULL) sctp_free_key(stcb->asoc.authinfo.recv_key); @@ -1801,7 +1904,11 @@ sctp_handle_auth(struct sctp_tcb *stcb, */ void sctp_notify_authentication(struct sctp_tcb *stcb, uint32_t indication, - uint16_t keyid, uint16_t alt_keyid) + uint16_t keyid, uint16_t alt_keyid, int so_locked +#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) + SCTP_UNUSED +#endif +) { struct mbuf *m_notify; struct sctp_authkey_event *auth; @@ -1851,11 +1958,11 @@ sctp_notify_authentication(struct sctp_t /* not that we need this */ control->tail_mbuf = m_notify; sctp_add_to_readq(stcb->sctp_ep, stcb, control, - &stcb->sctp_socket->so_rcv, 1, SCTP_SO_NOT_LOCKED); + &stcb->sctp_socket->so_rcv, 1, so_locked); } -/* +/*- * validates the AUTHentication related parameters in an INIT/INIT-ACK * Note: currently only used for INIT as INIT-ACK is handled inline * with sctp_load_addresses_from_init() @@ -2027,7 +2134,11 @@ sctp_initialize_auth_params(struct sctp_ } } /* copy defaults from the endpoint */ - stcb->asoc.authinfo.assoc_keyid = inp->sctp_ep.default_keyid; + stcb->asoc.authinfo.active_keyid = inp->sctp_ep.default_keyid; + + /* copy out the shared key list (by reference) from the endpoint */ + (void)sctp_copy_skeylist(&inp->sctp_ep.shared_keys, + &stcb->asoc.shared_keys); /* now set the concatenated key (random + chunks + hmacs) */ #ifdef SCTP_AUTH_DRAFT_04 @@ -2135,11 +2246,13 @@ sctp_test_hmac_sha1(void) uint32_t digestlen = 20; int failed = 0; - /* - * test_case = 1 key = - * 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b key_len = 20 - * data = "Hi There" data_len = 8 digest = - * 0xb617318655057264e28bc0b6fb378c8ef146be00 + /*- + * test_case = 1 + * key = 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b + * key_len = 20 + * data = "Hi There" + * data_len = 8 + * digest = 0xb617318655057264e28bc0b6fb378c8ef146be00 */ keylen = 20; memset(key, 0x0b, keylen); @@ -2150,10 +2263,13 @@ sctp_test_hmac_sha1(void) text, textlen, digest, digestlen) < 0) failed++; - /* - * test_case = 2 key = "Jefe" key_len = 4 data = - * "what do ya want for nothing?" data_len = 28 digest = - * 0xeffcdf6ae5eb2fa2d27416d5f184df9c259a7c79 + /*- + * test_case = 2 + * key = "Jefe" + * key_len = 4 + * data = "what do ya want for nothing?" + * data_len = 28 + * digest = 0xeffcdf6ae5eb2fa2d27416d5f184df9c259a7c79 */ keylen = 4; strcpy(key, "Jefe"); @@ -2164,11 +2280,13 @@ sctp_test_hmac_sha1(void) text, textlen, digest, digestlen) < 0) failed++; - /* - * test_case = 3 key = - * 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa key_len = 20 - * data = 0xdd repeated 50 times data_len = 50 digest - * = 0x125d7342b9ac11cd91a39af48aa17b4f63f175d3 + /*- + * test_case = 3 + * key = 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + * key_len = 20 + * data = 0xdd repeated 50 times + * data_len = 50 + * digest = 0x125d7342b9ac11cd91a39af48aa17b4f63f175d3 */ keylen = 20; memset(key, 0xaa, keylen); @@ -2179,11 +2297,13 @@ sctp_test_hmac_sha1(void) text, textlen, digest, digestlen) < 0) failed++; - /* - * test_case = 4 key = - * 0x0102030405060708090a0b0c0d0e0f10111213141516171819 key_len = 25 - * data = 0xcd repeated 50 times data_len = 50 digest - * = 0x4c9007f4026250c6bc8414f9bf50c86c2d7235da + /*- + * test_case = 4 + * key = 0x0102030405060708090a0b0c0d0e0f10111213141516171819 + * key_len = 25 + * data = 0xcd repeated 50 times + * data_len = 50 + * digest = 0x4c9007f4026250c6bc8414f9bf50c86c2d7235da */ keylen = 25; memcpy(key, "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19", keylen); @@ -2194,12 +2314,14 @@ sctp_test_hmac_sha1(void) text, textlen, digest, digestlen) < 0) failed++; - /* - * test_case = 5 key = - * 0x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c key_len = 20 - * data = "Test With Truncation" data_len = 20 digest - * = 0x4c1a03424b55e07fe7f27be1d58bb9324a9a5a04 digest-96 = *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From ganbold at FreeBSD.org Sat Dec 6 05:23:53 2008 From: ganbold at FreeBSD.org (Ganbold Tsagaankhuu) Date: Sat Dec 6 05:24:05 2008 Subject: svn commit: r185695 - head/tools/test/pthread_vfork Message-ID: <200812061323.mB6DNrL3095080@svn.freebsd.org> Author: ganbold (doc committer) Date: Sat Dec 6 13:23:53 2008 New Revision: 185695 URL: http://svn.freebsd.org/changeset/base/185695 Log: This is simple testing program for revision 185647. It invokes multiple parallel threads and each thread calls vfork() system call. Approved by: kib Added: head/tools/test/pthread_vfork/ head/tools/test/pthread_vfork/pthread_vfork_test.c (contents, props changed) Added: head/tools/test/pthread_vfork/pthread_vfork_test.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/test/pthread_vfork/pthread_vfork_test.c Sat Dec 6 13:23:53 2008 (r185695) @@ -0,0 +1,81 @@ +/*- + * Copyright (c) 2008 Ganbold Tsagaankhuu + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include + +#define NUM_THREADS 100 + +void * +vfork_test(void *threadid) +{ + pid_t pid; + + for (;;) { + pid = vfork(); + if (pid == 0) + _exit(0); + else if (pid == -1) + err(1, "Failed to vfork"); + } + return (NULL); +} + +/* + * This program invokes multiple threads and each thread calls + * vfork() system call. + */ +int +main(void) +{ + pthread_t threads[NUM_THREADS]; + struct sigaction reapchildren; + int rc, t; + + memset(&reapchildren, 0, sizeof(reapchildren)); + reapchildren.sa_handler = SIG_IGN; + + /* Automatically reap zombies. */ + if (sigaction(SIGCHLD, &reapchildren, NULL) == -1) + err(1, "Could not sigaction(SIGCHLD)"); + + for (t = 0; t < NUM_THREADS; t++) { + rc = pthread_create(&threads[t], NULL, vfork_test, (void *)t); + if (rc) + errc(1, rc, "pthread_create"); + } + return (0); +} From stas at FreeBSD.org Sat Dec 6 06:23:45 2008 From: stas at FreeBSD.org (Stanislav Sedov) Date: Sat Dec 6 06:24:13 2008 Subject: svn commit: r185707 - head/sys/dev/ae Message-ID: <200812061423.mB6ENjW4096783@svn.freebsd.org> Author: stas Date: Sat Dec 6 14:23:45 2008 New Revision: 185707 URL: http://svn.freebsd.org/changeset/base/185707 Log: - Eliminate unused variable. [1] - Check for runt frames entering the stack. [2] Suggested by: ganbold[1], yongari[2] Approved by: kib (mentor) MFC after: 2 weeks Modified: head/sys/dev/ae/if_ae.c Modified: head/sys/dev/ae/if_ae.c ============================================================================== --- head/sys/dev/ae/if_ae.c Sat Dec 6 14:20:04 2008 (r185706) +++ head/sys/dev/ae/if_ae.c Sat Dec 6 14:23:45 2008 (r185707) @@ -1105,12 +1105,9 @@ ae_dmamap_cb(void *arg, bus_dma_segment_ static int ae_alloc_rings(ae_softc_t *sc) { - bus_dma_tag_t bustag; bus_addr_t busaddr; int error; - bustag = bus_get_dma_tag(sc->dev); - /* * Create parent DMA tag. */ @@ -1903,8 +1900,8 @@ ae_rxeof(ae_softc_t *sc, ae_rxd_t *rxd) if_printf(ifp, "Rx interrupt occuried.\n"); #endif size = le16toh(rxd->len) - ETHER_CRC_LEN; - if (size < 0) { - if_printf(ifp, "Negative length packet received."); + if (size < (ETHER_MIN_LEN - ETHER_CRC_LEN - ETHER_VLAN_ENCAP_LEN)) { + if_printf(ifp, "Runt frame received."); return (EIO); } From ps at FreeBSD.org Sat Dec 6 06:45:05 2008 From: ps at FreeBSD.org (Paul Saab) Date: Sat Dec 6 06:45:16 2008 Subject: svn commit: r185711 - head/sys/boot/zfs Message-ID: <200812061445.mB6Ej3dh097523@svn.freebsd.org> Author: ps Date: Sat Dec 6 14:45:03 2008 New Revision: 185711 URL: http://svn.freebsd.org/changeset/base/185711 Log: Correct include path for i386 specific includes. This allows zfs to boot on systems where the loader is built on amd64 systems. Modified: head/sys/boot/zfs/Makefile Modified: head/sys/boot/zfs/Makefile ============================================================================== --- head/sys/boot/zfs/Makefile Sat Dec 6 14:42:36 2008 (r185710) +++ head/sys/boot/zfs/Makefile Sat Dec 6 14:45:03 2008 (r185711) @@ -29,7 +29,7 @@ CFLAGS+= -Wformat -Wall .if ${MACHINE_ARCH} == "amd64" CLEANFILES+= machine machine: - ln -sf ${.CURDIR}/../../../i386/include machine + ln -sf ${.CURDIR}/../../i386/include machine .endif .include From keramida at ceid.upatras.gr Sat Dec 6 06:55:32 2008 From: keramida at ceid.upatras.gr (Giorgos Keramidas) Date: Sat Dec 6 06:55:38 2008 Subject: svn commit: r185690 - head/lib/libc/string In-Reply-To: <200812060937.mB69bs2w089432@svn.freebsd.org> (Konstantin Belousov's message of "Sat, 6 Dec 2008 09:37:54 +0000 (UTC)") References: <200812060937.mB69bs2w089432@svn.freebsd.org> Message-ID: <87iqpxl5ev.fsf@kobe.laptop> On Sat, 6 Dec 2008 09:37:54 +0000 (UTC), Konstantin Belousov wrote: > Author: kib > Date: Sat Dec 6 09:37:54 2008 > New Revision: 185690 > URL: http://svn.freebsd.org/changeset/base/185690 > > Log: > Import the strndup(3) function. > Copyright attribution is kept the same as in original NetBSD source. Varnish has a mostly equivalent function with a slightly more "free" 2-clause BSD copyright: http://varnish.projects.linpro.no/browser/trunk/varnish-cache/lib/libvarnishcompat/strndup.c Maybe it's worth switching to that function, so we can remove the 4th clause some time later :) From csjp at FreeBSD.org Sat Dec 6 11:09:39 2008 From: csjp at FreeBSD.org (Christian S.J. Peron) Date: Sat Dec 6 11:09:45 2008 Subject: svn commit: r185713 - head/sys/netinet Message-ID: <200812061909.mB6J9dIv002688@svn.freebsd.org> Author: csjp Date: Sat Dec 6 19:09:38 2008 New Revision: 185713 URL: http://svn.freebsd.org/changeset/base/185713 Log: in_rtalloc1(9) returns a locked route, so make sure that we use RTFREE_LOCKED() here. This macro makes sure the reference count on the route is being managed properly. This elimates another case which results in the following message being printed to the console: rtfree: 0xc841ee88 has 1 refs Reviewed by: bz MFC after: 2 weeks Modified: head/sys/netinet/if_ether.c Modified: head/sys/netinet/if_ether.c ============================================================================== --- head/sys/netinet/if_ether.c Sat Dec 6 14:50:46 2008 (r185712) +++ head/sys/netinet/if_ether.c Sat Dec 6 19:09:38 2008 (r185713) @@ -924,12 +924,12 @@ reply: * over who claims what Ether address. */ if (rt->rt_ifp == ifp) { - rtfree(rt); + RTFREE_LOCKED(rt); goto drop; } (void)memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln); (void)memcpy(ar_sha(ah), enaddr, ah->ar_hln); - rtfree(rt); + RTFREE_LOCKED(rt); /* * Also check that the node which sent the ARP packet @@ -948,10 +948,10 @@ reply: " from %s via %s, expecting %s\n", inet_ntoa(isaddr), ifp->if_xname, rt->rt_ifp->if_xname); - rtfree(rt); + RTFREE_LOCKED(rt); goto drop; } - rtfree(rt); + RTFREE_LOCKED(rt); #ifdef DEBUG_PROXY printf("arp: proxying for %s\n", From keramida at FreeBSD.org Sat Dec 6 11:21:57 2008 From: keramida at FreeBSD.org (Giorgos Keramidas) Date: Sat Dec 6 11:22:03 2008 Subject: svn commit: r185714 - head/usr.bin/wc Message-ID: <200812061921.mB6JLu98002936@svn.freebsd.org> Author: keramida (doc committer) Date: Sat Dec 6 19:21:56 2008 New Revision: 185714 URL: http://svn.freebsd.org/changeset/base/185714 Log: Add a -L option to wc(1), for finger compatibility with the GNU wc utility. The -L option can be used to report the length of the longest line wc has seen in one or more files. It is disabled by default, and wc uses the standard `-lwc'. Submitted by: Sheldon Givens, sheldon at sigsegv.ca Reviewed by: kib MFC after: 1 week Modified: head/usr.bin/wc/wc.1 head/usr.bin/wc/wc.c Modified: head/usr.bin/wc/wc.1 ============================================================================== --- head/usr.bin/wc/wc.1 Sat Dec 6 19:09:38 2008 (r185713) +++ head/usr.bin/wc/wc.1 Sat Dec 6 19:21:56 2008 (r185714) @@ -35,7 +35,7 @@ .\" @(#)wc.1 8.2 (Berkeley) 4/19/94 .\" $FreeBSD$ .\" -.Dd February 23, 2005 +.Dd December 6, 2008 .Dt WC 1 .Os .Sh NAME @@ -43,7 +43,7 @@ .Nd word, line, character, and byte count .Sh SYNOPSIS .Nm -.Op Fl clmw +.Op Fl Lclmw .Op Ar .Sh DESCRIPTION The @@ -71,6 +71,15 @@ the last file. .Pp The following options are available: .Bl -tag -width indent +.It Fl L +The number of characters in the longest input line +is written to the standard output. +When more then one +.Ar file +argument is specified, the longest input line of +.Em all +files is reported as the value of the final +.Dq total . .It Fl c The number of bytes in each input file is written to the standard output. @@ -129,6 +138,10 @@ and as well as the totals for both: .Pp .Dl "wc -mlw report1 report2" +.Pp +Find the longest line in a list of files: +.Pp +.Dl "wc -L file1 file2 file3 | fgrep total" .Sh COMPATIBILITY Historically, the .Nm @@ -154,6 +167,16 @@ in terms of the .Xr iswspace 3 function, as required by .St -p1003.2 . +.Pp +The +.Fl L +option is a non-standard +.Fx +extension, compatible with the +.Fl L +option of the GNU +.Nm +utility. .Sh SEE ALSO .Xr iswspace 3 .Sh STANDARDS Modified: head/usr.bin/wc/wc.c ============================================================================== --- head/usr.bin/wc/wc.c Sat Dec 6 19:09:38 2008 (r185713) +++ head/usr.bin/wc/wc.c Sat Dec 6 19:21:56 2008 (r185714) @@ -62,8 +62,8 @@ __FBSDID("$FreeBSD$"); #include #include -uintmax_t tlinect, twordct, tcharct; -int doline, doword, dochar, domulti; +uintmax_t tlinect, twordct, tcharct, tlongline; +int doline, doword, dochar, domulti, dolongline; static int cnt(const char *); static void usage(void); @@ -75,7 +75,7 @@ main(int argc, char *argv[]) (void) setlocale(LC_CTYPE, ""); - while ((ch = getopt(argc, argv, "clmw")) != -1) + while ((ch = getopt(argc, argv, "clmwL")) != -1) switch((char)ch) { case 'l': doline = 1; @@ -87,6 +87,9 @@ main(int argc, char *argv[]) dochar = 1; domulti = 0; break; + case 'L': + dolongline = 1; + break; case 'm': domulti = 1; dochar = 0; @@ -99,7 +102,7 @@ main(int argc, char *argv[]) argc -= optind; /* Wc's flags are on by default. */ - if (doline + doword + dochar + domulti == 0) + if (doline + doword + dochar + domulti + dolongline == 0) doline = doword = dochar = 1; errors = 0; @@ -125,6 +128,8 @@ main(int argc, char *argv[]) (void)printf(" %7ju", twordct); if (dochar || domulti) (void)printf(" %7ju", tcharct); + if (dolongline) + (void)printf(" %7ju", tlongline); (void)printf(" total\n"); } exit(errors == 0 ? 0 : 1); @@ -134,7 +139,7 @@ static int cnt(const char *file) { struct stat sb; - uintmax_t linect, wordct, charct; + uintmax_t linect, wordct, charct, llct, tmpll; int fd, len, warned; size_t clen; short gotsp; @@ -143,7 +148,7 @@ cnt(const char *file) wchar_t wch; mbstate_t mbs; - linect = wordct = charct = 0; + linect = wordct = charct = llct = tmpll = 0; if (file == NULL) { file = "stdin"; fd = STDIN_FILENO; @@ -168,8 +173,13 @@ cnt(const char *file) } charct += len; for (p = buf; len--; ++p) - if (*p == '\n') + if (*p == '\n') { + if (tmpll > llct) + llct = tmpll; + tmpll = 0; ++linect; + } else + tmpll++; } tlinect += linect; (void)printf(" %7ju", linect); @@ -177,6 +187,11 @@ cnt(const char *file) tcharct += charct; (void)printf(" %7ju", charct); } + if (dolongline) { + if (llct > tlongline) + tlongline = llct; + (void)printf(" %7ju", tlongline); + } (void)close(fd); return (0); } @@ -229,10 +244,16 @@ word: gotsp = 1; else if (clen == 0) clen = 1; charct++; + if (wch != L'\n') + tmpll++; len -= clen; p += clen; - if (wch == L'\n') + if (wch == L'\n') { + if (tmpll > llct) + llct = tmpll; + tmpll = 0; ++linect; + } if (iswspace(wch)) gotsp = 1; else if (gotsp) { @@ -256,6 +277,11 @@ word: gotsp = 1; tcharct += charct; (void)printf(" %7ju", charct); } + if (dolongline) { + if (llct > tlongline) + tlongline = llct; + (void)printf(" %7ju", llct); + } (void)close(fd); return (0); } @@ -263,6 +289,6 @@ word: gotsp = 1; static void usage() { - (void)fprintf(stderr, "usage: wc [-clmw] [file ...]\n"); + (void)fprintf(stderr, "usage: wc [-Lclmw] [file ...]\n"); exit(1); } From alc at FreeBSD.org Sat Dec 6 11:37:53 2008 From: alc at FreeBSD.org (Alan Cox) Date: Sat Dec 6 11:38:04 2008 Subject: svn commit: r185715 - head/sys/amd64/amd64 Message-ID: <200812061937.mB6JbqAI003273@svn.freebsd.org> Author: alc Date: Sat Dec 6 19:37:52 2008 New Revision: 185715 URL: http://svn.freebsd.org/changeset/base/185715 Log: Change the default value for the flag enabling superpage mapping and promotion to "on". Reminded by: jhb Tested by: kris Modified: head/sys/amd64/amd64/pmap.c Modified: head/sys/amd64/amd64/pmap.c ============================================================================== --- head/sys/amd64/amd64/pmap.c Sat Dec 6 19:21:56 2008 (r185714) +++ head/sys/amd64/amd64/pmap.c Sat Dec 6 19:37:52 2008 (r185715) @@ -180,7 +180,7 @@ pt_entry_t pg_nx; SYSCTL_NODE(_vm, OID_AUTO, pmap, CTLFLAG_RD, 0, "VM/pmap parameters"); -static int pg_ps_enabled; +static int pg_ps_enabled = 1; SYSCTL_INT(_vm_pmap, OID_AUTO, pg_ps_enabled, CTLFLAG_RD, &pg_ps_enabled, 0, "Are large page mappings enabled?"); From thompsa at FreeBSD.org Sat Dec 6 13:19:27 2008 From: thompsa at FreeBSD.org (Andrew Thompson) Date: Sat Dec 6 13:19:39 2008 Subject: svn commit: r185719 - head/sys/dev/usb Message-ID: <200812062119.mB6LJRT9005366@svn.freebsd.org> Author: thompsa Date: Sat Dec 6 21:19:26 2008 New Revision: 185719 URL: http://svn.freebsd.org/changeset/base/185719 Log: The startall variable should default to zero, otherwise the vap is restarted everytime an ioctl happens. While I am here, limit the locking scope to SIOCSIFFLAGS. Modified: head/sys/dev/usb/if_ural.c Modified: head/sys/dev/usb/if_ural.c ============================================================================== --- head/sys/dev/usb/if_ural.c Sat Dec 6 20:49:08 2008 (r185718) +++ head/sys/dev/usb/if_ural.c Sat Dec 6 21:19:26 2008 (r185719) @@ -1544,11 +1544,11 @@ ural_ioctl(struct ifnet *ifp, u_long cmd struct ural_softc *sc = ifp->if_softc; struct ieee80211com *ic = ifp->if_l2com; struct ifreq *ifr = (struct ifreq *) data; - int error = 0, startall = 1; + int error = 0, startall = 0; - RAL_LOCK(sc); switch (cmd) { case SIOCSIFFLAGS: + RAL_LOCK(sc); if (ifp->if_flags & IFF_UP) { if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) { ural_init_locked(sc); @@ -1559,6 +1559,9 @@ ural_ioctl(struct ifnet *ifp, u_long cmd if (ifp->if_drv_flags & IFF_DRV_RUNNING) ural_stop(sc); } + RAL_UNLOCK(sc); + if (startall) + ieee80211_start_all(ic); break; case SIOCGIFMEDIA: case SIOCSIFMEDIA: @@ -1568,10 +1571,6 @@ ural_ioctl(struct ifnet *ifp, u_long cmd error = ether_ioctl(ifp, cmd, data); break; } - RAL_UNLOCK(sc); - - if (startall) - ieee80211_start_all(ic); return error; } From kib at FreeBSD.org Sat Dec 6 13:33:45 2008 From: kib at FreeBSD.org (Konstantin Belousov) Date: Sat Dec 6 13:33:51 2008 Subject: svn commit: r185720 - head/sys/i386/include Message-ID: <200812062133.mB6LXiUD005674@svn.freebsd.org> Author: kib Date: Sat Dec 6 21:33:44 2008 New Revision: 185720 URL: http://svn.freebsd.org/changeset/base/185720 Log: Restore memory clobber, to cause mb on the compiler level too. Use more sane formatting of the assembler. Pointed out by: bde Modified: head/sys/i386/include/atomic.h Modified: head/sys/i386/include/atomic.h ============================================================================== --- head/sys/i386/include/atomic.h Sat Dec 6 21:19:26 2008 (r185719) +++ head/sys/i386/include/atomic.h Sat Dec 6 21:33:44 2008 (r185720) @@ -32,9 +32,9 @@ #error this file needs sys/cdefs.h as a prerequisite #endif -#define mb() __asm __volatile("lock;addl $0,(%esp)") -#define wmb() __asm __volatile("lock;addl $0,(%esp)") -#define rmb() __asm __volatile("lock;addl $0,(%esp)") +#define mb() __asm __volatile("lock; addl $0,(%%esp)" : : : "memory") +#define wmb() __asm __volatile("lock; addl $0,(%%esp)" : : : "memory") +#define rmb() __asm __volatile("lock; addl $0,(%%esp)" : : : "memory") /* * Various simple operations on memory, each of which is atomic in the From mav at FreeBSD.org Sat Dec 6 13:41:28 2008 From: mav at FreeBSD.org (Alexander Motin) Date: Sat Dec 6 13:41:39 2008 Subject: svn commit: r185721 - head/sys/dev/mmc Message-ID: <200812062141.mB6LfRLm005830@svn.freebsd.org> Author: mav Date: Sat Dec 6 21:41:27 2008 New Revision: 185721 URL: http://svn.freebsd.org/changeset/base/185721 Log: Implement suspend/resume for mmc and mmcsd drivers. Now it is possible to suspend/resume with inserted and active card. To reinitialize card on resume and to detect card change while suspended, implement bus rescan routines. It can also be used by controllers without card presence detection signals or with multiple cards per slot support. While there, cleanup msleep() usage. We have no any rights to exit without "request done" signal from driver as it could lead to modify after free. Modified: head/sys/dev/mmc/mmc.c head/sys/dev/mmc/mmcsd.c Modified: head/sys/dev/mmc/mmc.c ============================================================================== --- head/sys/dev/mmc/mmc.c Sat Dec 6 21:33:44 2008 (r185720) +++ head/sys/dev/mmc/mmc.c Sat Dec 6 21:41:27 2008 (r185721) @@ -108,6 +108,8 @@ struct mmc_ivars { static int mmc_probe(device_t dev); static int mmc_attach(device_t dev); static int mmc_detach(device_t dev); +static int mmc_suspend(device_t dev); +static int mmc_resume(device_t dev); #define MMC_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) #define MMC_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) @@ -130,6 +132,8 @@ static int mmc_set_card_bus_width(struct static int mmc_app_send_scr(struct mmc_softc *sc, uint16_t rca, uint32_t *rawscr); static void mmc_app_decode_scr(uint32_t *raw_scr, struct mmc_scr *scr); static int mmc_send_ext_csd(struct mmc_softc *sc, uint8_t *rawextcsd); +static void mmc_scan(struct mmc_softc *sc); +static int mmc_delete_cards(struct mmc_softc *sc); static void mmc_ms_delay(int ms) @@ -166,29 +170,39 @@ static int mmc_detach(device_t dev) { struct mmc_softc *sc = device_get_softc(dev); - device_t *kids; - int i, nkid; + int err; - /* kill children [ph33r]. -sorbo */ - if (device_get_children(sc->dev, &kids, &nkid) != 0) - return (0); - for (i = 0; i < nkid; i++) { - device_t kid = kids[i]; - void *ivar = device_get_ivars(kid); - - device_detach(kid); - device_delete_child(sc->dev, kid); - free(ivar, M_DEVBUF); - } - free(kids, M_TEMP); + if ((err = mmc_delete_cards(sc)) != 0) + return (err); mmc_power_down(sc); - MMC_LOCK_DESTROY(sc); return (0); } static int +mmc_suspend(device_t dev) +{ + struct mmc_softc *sc = device_get_softc(dev); + int err; + + err = bus_generic_suspend(dev); + if (err) + return (err); + mmc_power_down(sc); + return (0); +} + +static int +mmc_resume(device_t dev) +{ + struct mmc_softc *sc = device_get_softc(dev); + + mmc_scan(sc); + return (bus_generic_resume(dev)); +} + +static int mmc_acquire_bus(device_t busdev, device_t dev) { struct mmc_softc *sc; @@ -265,12 +279,6 @@ mmc_release_bus(device_t busdev, device_ return (0); } -static void -mmc_rescan_cards(struct mmc_softc *sc) -{ - /* XXX: Look at the children and see if they respond to status */ -} - static uint32_t mmc_select_vdd(struct mmc_softc *sc, uint32_t ocr) { @@ -294,31 +302,25 @@ mmc_wakeup(struct mmc_request *req) { struct mmc_softc *sc; -/* printf("Wakeup for req %p done_data %p\n", req, req->done_data); */ sc = (struct mmc_softc *)req->done_data; MMC_LOCK(sc); req->flags |= MMC_REQ_DONE; - wakeup(req); MMC_UNLOCK(sc); + wakeup(req); } static int mmc_wait_for_req(struct mmc_softc *sc, struct mmc_request *req) { - int err; req->done = mmc_wakeup; req->done_data = sc; -/* printf("Submitting request %p sc %p\n", req, sc); */ MMCBR_REQUEST(device_get_parent(sc->dev), sc->dev, req); MMC_LOCK(sc); - do { - err = msleep(req, &sc->sc_mtx, PZERO | PCATCH, "mmcreq", - hz / 10); - } while (!(req->flags & MMC_REQ_DONE) && err == EAGAIN); -/* printf("Request %p done with error %d\n", req, err); */ + while ((req->flags & MMC_REQ_DONE) == 0) + msleep(req, &sc->sc_mtx, 0, "mmcreq", 0); MMC_UNLOCK(sc); - return (err); + return (0); } static int @@ -1060,25 +1062,41 @@ mmc_send_relative_addr(struct mmc_softc static void mmc_discover_cards(struct mmc_softc *sc) { - struct mmc_ivars *ivar; - int err; + struct mmc_ivars *ivar = NULL; + device_t *devlist; + int err, i, devcount, newcard; + uint32_t raw_cid[4]; uint32_t resp, sec_count; device_t child; uint16_t rca = 2; u_char switch_res[64]; while (1) { - ivar = malloc(sizeof(struct mmc_ivars), M_DEVBUF, - M_WAITOK | M_ZERO); - if (!ivar) - return; - err = mmc_all_send_cid(sc, ivar->raw_cid); + err = mmc_all_send_cid(sc, raw_cid); if (err == MMC_ERR_TIMEOUT) break; if (err != MMC_ERR_NONE) { device_printf(sc->dev, "Error reading CID %d\n", err); break; } + newcard = 1; + if ((err = device_get_children(sc->dev, &devlist, &devcount)) != 0) + return; + for (i = 0; i < devcount; i++) { + ivar = device_get_ivars(devlist[i]); + if (memcmp(ivar->raw_cid, raw_cid, sizeof(raw_cid)) == 0) { + newcard = 0; + break; + } + } + free(devlist, M_TEMP); + if (newcard) { + ivar = malloc(sizeof(struct mmc_ivars), M_DEVBUF, + M_WAITOK | M_ZERO); + if (!ivar) + return; + memcpy(ivar->raw_cid, raw_cid, sizeof(raw_cid)); + } if (mmcbr_get_ro(sc->dev)) ivar->read_only = 1; ivar->bus_width = bus_width_1; @@ -1121,9 +1139,11 @@ mmc_discover_cards(struct mmc_softc *sc) if ((mmcbr_get_caps(sc->dev) & MMC_CAP_4_BIT_DATA) && (ivar->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) ivar->bus_width = bus_width_4; - /* Add device. */ - child = device_add_child(sc->dev, NULL, -1); - device_set_ivars(child, ivar); + if (newcard) { + /* Add device. */ + child = device_add_child(sc->dev, NULL, -1); + device_set_ivars(child, ivar); + } return; } mmc_decode_cid_mmc(ivar->raw_cid, &ivar->cid); @@ -1174,11 +1194,50 @@ mmc_discover_cards(struct mmc_softc *sc) ivar->bus_width = bus_width_1; ivar->timing = bus_timing_normal; } - /* Add device. */ - child = device_add_child(sc->dev, NULL, -1); - device_set_ivars(child, ivar); + if (newcard) { + /* Add device. */ + child = device_add_child(sc->dev, NULL, -1); + device_set_ivars(child, ivar); + } } - free(ivar, M_DEVBUF); +} + +static void +mmc_rescan_cards(struct mmc_softc *sc) +{ + struct mmc_ivars *ivar = NULL; + device_t *devlist; + int err, i, devcount; + + if ((err = device_get_children(sc->dev, &devlist, &devcount)) != 0) + return; + for (i = 0; i < devcount; i++) { + ivar = device_get_ivars(devlist[i]); + if (mmc_select_card(sc, ivar->rca)) { + device_delete_child(sc->dev, devlist[i]); + free(ivar, M_DEVBUF); + } + } + free(devlist, M_TEMP); + mmc_select_card(sc, 0); +} + +static int +mmc_delete_cards(struct mmc_softc *sc) +{ + struct mmc_ivars *ivar; + device_t *devlist; + int err, i, devcount; + + if ((err = device_get_children(sc->dev, &devlist, &devcount)) != 0) + return (err); + for (i = 0; i < devcount; i++) { + ivar = device_get_ivars(devlist[i]); + device_delete_child(sc->dev, devlist[i]); + free(ivar, M_DEVBUF); + } + free(devlist, M_TEMP); + return (0); } static void @@ -1205,7 +1264,7 @@ mmc_go_discovery(struct mmc_softc *sc) */ mmcbr_set_mode(dev, mode_mmc); if (mmc_send_op_cond(sc, 0, &ocr) != MMC_ERR_NONE) - return; /* Failed both, punt! XXX powerdown? */ + ocr = 0; /* Failed both, powerdown. */ } mmcbr_set_ocr(dev, mmc_select_vdd(sc, ocr)); if (mmcbr_get_ocr(dev) != 0) @@ -1220,8 +1279,11 @@ mmc_go_discovery(struct mmc_softc *sc) * Make sure that we have a mutually agreeable voltage to at least * one card on the bus. */ - if (mmcbr_get_ocr(dev) == 0) + if (mmcbr_get_ocr(dev) == 0) { + mmc_delete_cards(sc); + mmc_power_down(sc); return; + } /* * Reselect the cards after we've idled them above. */ @@ -1232,6 +1294,7 @@ mmc_go_discovery(struct mmc_softc *sc) } else mmc_send_op_cond(sc, mmcbr_get_ocr(dev), NULL); mmc_discover_cards(sc); + mmc_rescan_cards(sc); mmcbr_set_bus_mode(dev, pushpull); mmcbr_update_ios(dev); @@ -1292,17 +1355,11 @@ mmc_calculate_clock(struct mmc_softc *sc static void mmc_scan(struct mmc_softc *sc) { - device_t dev; + device_t dev = sc->dev; - dev = sc->dev; mmc_acquire_bus(dev, dev); - - if (mmcbr_get_power_mode(dev) == power_on) - mmc_rescan_cards(sc); mmc_go_discovery(sc); - mmc_release_bus(dev, dev); - /* XXX probe/attach/detach children? */ } static int @@ -1374,6 +1431,8 @@ static device_method_t mmc_methods[] = { DEVMETHOD(device_probe, mmc_probe), DEVMETHOD(device_attach, mmc_attach), DEVMETHOD(device_detach, mmc_detach), + DEVMETHOD(device_suspend, mmc_suspend), + DEVMETHOD(device_resume, mmc_resume), /* Bus interface */ DEVMETHOD(bus_read_ivar, mmc_read_ivar), Modified: head/sys/dev/mmc/mmcsd.c ============================================================================== --- head/sys/dev/mmc/mmcsd.c Sat Dec 6 21:33:44 2008 (r185720) +++ head/sys/dev/mmc/mmcsd.c Sat Dec 6 21:41:27 2008 (r185721) @@ -79,6 +79,7 @@ struct mmcsd_softc { struct bio_queue_head bio_queue; daddr_t eblock, eend; /* Range remaining after the last erase. */ int running; + int suspend; }; /* bus entry points */ @@ -163,6 +164,7 @@ mmcsd_attach(device_t dev) bioq_init(&sc->bio_queue); sc->running = 1; + sc->suspend = 0; sc->eblock = sc->eend = 0; kproc_create(&mmcsd_task, sc, &sc->p, 0, 0, "task: mmc/sd card"); @@ -174,16 +176,16 @@ mmcsd_detach(device_t dev) { struct mmcsd_softc *sc = device_get_softc(dev); - /* kill thread */ MMCSD_LOCK(sc); - sc->running = 0; - wakeup(sc); - MMCSD_UNLOCK(sc); - - /* wait for thread to finish. XXX probably want timeout. -sorbo */ - MMCSD_LOCK(sc); - while (sc->running != -1) - msleep(sc, &sc->sc_mtx, PRIBIO, "detach", 0); + sc->suspend = 0; + if (sc->running > 0) { + /* kill thread */ + sc->running = 0; + wakeup(sc); + /* wait for thread to finish. */ + while (sc->running != -1) + msleep(sc, &sc->sc_mtx, 0, "detach", 0); + } MMCSD_UNLOCK(sc); /* Flush the request queue. */ @@ -197,6 +199,41 @@ mmcsd_detach(device_t dev) } static int +mmcsd_suspend(device_t dev) +{ + struct mmcsd_softc *sc = device_get_softc(dev); + + MMCSD_LOCK(sc); + sc->suspend = 1; + if (sc->running > 0) { + /* kill thread */ + sc->running = 0; + wakeup(sc); + /* wait for thread to finish. */ + while (sc->running != -1) + msleep(sc, &sc->sc_mtx, 0, "detach", 0); + } + MMCSD_UNLOCK(sc); + return (0); +} + +static int +mmcsd_resume(device_t dev) +{ + struct mmcsd_softc *sc = device_get_softc(dev); + + MMCSD_LOCK(sc); + sc->suspend = 0; + if (sc->running <= 0) { + sc->running = 1; + MMCSD_UNLOCK(sc); + kproc_create(&mmcsd_task, sc, &sc->p, 0, 0, "task: mmc/sd card"); + } else + MMCSD_UNLOCK(sc); + return (0); +} + +static int mmcsd_open(struct disk *dp) { return (0); @@ -215,10 +252,10 @@ mmcsd_strategy(struct bio *bp) sc = (struct mmcsd_softc *)bp->bio_disk->d_drv1; MMCSD_LOCK(sc); - if (sc->running > 0) { + if (sc->running > 0 || sc->suspend > 0) { bioq_disksort(&sc->bio_queue, bp); - wakeup(sc); MMCSD_UNLOCK(sc); + wakeup(sc); } else { MMCSD_UNLOCK(sc); biofinish(bp, NULL, ENXIO); @@ -428,8 +465,8 @@ mmcsd_task(void *arg) out: /* tell parent we're done */ sc->running = -1; - wakeup(sc); MMCSD_UNLOCK(sc); + wakeup(sc); kproc_exit(0); } @@ -458,6 +495,8 @@ static device_method_t mmcsd_methods[] = DEVMETHOD(device_probe, mmcsd_probe), DEVMETHOD(device_attach, mmcsd_attach), DEVMETHOD(device_detach, mmcsd_detach), + DEVMETHOD(device_suspend, mmcsd_suspend), + DEVMETHOD(device_resume, mmcsd_resume), {0, 0}, }; From mav at FreeBSD.org Sat Dec 6 13:52:32 2008 From: mav at FreeBSD.org (Alexander Motin) Date: Sat Dec 6 13:52:43 2008 Subject: svn commit: r185722 - head/sys/dev/sdhci Message-ID: <200812062152.mB6LqWW1006055@svn.freebsd.org> Author: mav Date: Sat Dec 6 21:52:32 2008 New Revision: 185722 URL: http://svn.freebsd.org/changeset/base/185722 Log: Cleanup msleep() arguments. Move wakeup() out of the lock. Modified: head/sys/dev/sdhci/sdhci.c Modified: head/sys/dev/sdhci/sdhci.c ============================================================================== --- head/sys/dev/sdhci/sdhci.c Sat Dec 6 21:41:27 2008 (r185721) +++ head/sys/dev/sdhci/sdhci.c Sat Dec 6 21:52:32 2008 (r185722) @@ -1207,7 +1207,7 @@ sdhci_acquire_host(device_t brdev, devic SDHCI_LOCK(slot); while (slot->bus_busy) - msleep(slot, &slot->mtx, PZERO, "sdhciah", hz / 5); + msleep(slot, &slot->mtx, 0, "sdhciah", 0); slot->bus_busy++; /* Activate led. */ WR1(slot, SDHCI_HOST_CONTROL, slot->hostctrl |= SDHCI_CTRL_LED); @@ -1224,8 +1224,8 @@ sdhci_release_host(device_t brdev, devic /* Deactivate led. */ WR1(slot, SDHCI_HOST_CONTROL, slot->hostctrl &= ~SDHCI_CTRL_LED); slot->bus_busy--; - wakeup(slot); SDHCI_UNLOCK(slot); + wakeup(slot); return (0); } From mav at FreeBSD.org Sat Dec 6 15:00:49 2008 From: mav at FreeBSD.org (Alexander Motin) Date: Sat Dec 6 15:01:00 2008 Subject: svn commit: r185723 - head/sys/netgraph Message-ID: <200812062300.mB6N0m6F007374@svn.freebsd.org> Author: mav Date: Sat Dec 6 23:00:48 2008 New Revision: 185723 URL: http://svn.freebsd.org/changeset/base/185723 Log: Carefully handle memory errors to keep peers compression/encryption state consistent. There are some cases reported where peers fatally getting out of sync without any visible reason. I hope this solve the problem. Modified: head/sys/netgraph/ng_mppc.c Modified: head/sys/netgraph/ng_mppc.c ============================================================================== --- head/sys/netgraph/ng_mppc.c Sat Dec 6 21:52:32 2008 (r185722) +++ head/sys/netgraph/ng_mppc.c Sat Dec 6 23:00:48 2008 (r185723) @@ -492,17 +492,18 @@ ng_mppc_compress(node_p node, struct mbu /* Work with contiguous regions of memory. */ inlen = m->m_pkthdr.len; inbuf = malloc(inlen, M_NETGRAPH_MPPC, M_NOWAIT); - if (inbuf == NULL) { - m_freem(m); - return (ENOMEM); - } + if (inbuf == NULL) + goto err1; m_copydata(m, 0, inlen, (caddr_t)inbuf); outlen = MPPC_MAX_BLOWUP(inlen); outbuf = malloc(outlen, M_NETGRAPH_MPPC, M_NOWAIT); if (outbuf == NULL) { - m_freem(m); free(inbuf, M_NETGRAPH_MPPC); +err1: + m_freem(m); + MPPC_InitCompressionHistory(d->history); + d->flushed = 1; return (ENOMEM); } @@ -538,8 +539,13 @@ ng_mppc_compress(node_p node, struct mbu free(outbuf, M_NETGRAPH_MPPC); /* Check m_devget() result. */ - if (m == NULL) + if (m == NULL) { + if (!d->flushed) { + MPPC_InitCompressionHistory(d->history); + d->flushed = 1; + } return (ENOMEM); + } } #endif @@ -551,6 +557,18 @@ ng_mppc_compress(node_p node, struct mbu /* Set header bits */ header |= MPPC_FLAG_ENCRYPTED; + /* We must own the mbuf chain exclusively to modify it. */ + m = m_unshare(m, M_DONTWAIT); + if (m == NULL) { + if (!d->flushed) { +#ifdef NETGRAPH_MPPC_COMPRESSION + MPPC_InitCompressionHistory(d->history); +#endif + d->flushed = 1; + } + return (ENOMEM); + } + /* Update key if it's time */ if ((d->cfg.bits & MPPE_STATELESS) != 0 || (d->cc & MPPE_UPDATE_MASK) == MPPE_UPDATE_FLAG) { @@ -562,11 +580,6 @@ ng_mppc_compress(node_p node, struct mbu rc4_init(&d->rc4, d->key, KEYLEN(d->cfg.bits)); } - /* We must own the mbuf chain exclusively to modify it. */ - m = m_unshare(m, M_DONTWAIT); - if (m == NULL) - return (ENOMEM); - /* Encrypt packet */ m1 = m; while (m1) { From nwhitehorn at FreeBSD.org Sat Dec 6 15:26:03 2008 From: nwhitehorn at FreeBSD.org (Nathan Whitehorn) Date: Sat Dec 6 15:26:17 2008 Subject: svn commit: r185724 - in head/sys: dev/adb powerpc/powermac Message-ID: <200812062326.mB6NQ39M007820@svn.freebsd.org> Author: nwhitehorn Date: Sat Dec 6 23:26:02 2008 New Revision: 185724 URL: http://svn.freebsd.org/changeset/base/185724 Log: Fix some nasty race conditions in the VIA-CUDA driver that ended up preventing my right mouse button and keyboard LEDs from working due to mangled configuration packets. Fixed several other races and associated problems in the main ADB stack that were exposed while fixing this. Modified: head/sys/dev/adb/adb.h head/sys/dev/adb/adb_bus.c head/sys/dev/adb/adb_kbd.c head/sys/dev/adb/adb_mouse.c head/sys/dev/adb/adbvar.h head/sys/powerpc/powermac/cuda.c head/sys/powerpc/powermac/cudavar.h Modified: head/sys/dev/adb/adb.h ============================================================================== --- head/sys/dev/adb/adb.h Sat Dec 6 23:00:48 2008 (r185723) +++ head/sys/dev/adb/adb.h Sat Dec 6 23:26:02 2008 (r185724) @@ -68,7 +68,7 @@ uint8_t adb_get_device_type(device_t dev uint8_t adb_get_device_handler(device_t dev); uint8_t adb_set_device_handler(device_t dev, uint8_t newhandler); -uint8_t adb_read_register(device_t dev, u_char reg, size_t *len, void *data); +size_t adb_read_register(device_t dev, u_char reg, void *data); /* Bits for implementing ADB host bus adapters */ extern devclass_t adb_devclass; Modified: head/sys/dev/adb/adb_bus.c ============================================================================== --- head/sys/dev/adb/adb_bus.c Sat Dec 6 23:00:48 2008 (r185723) +++ head/sys/dev/adb/adb_bus.c Sat Dec 6 23:26:02 2008 (r185724) @@ -48,7 +48,7 @@ static void adb_bus_enumerate(void *xdev static void adb_probe_nomatch(device_t dev, device_t child); static int adb_print_child(device_t dev, device_t child); -static int adb_send_raw_packet_sync(device_t dev, uint8_t to, uint8_t command, uint8_t reg, int len, u_char *data); +static int adb_send_raw_packet_sync(device_t dev, uint8_t to, uint8_t command, uint8_t reg, int len, u_char *data, u_char *reply); static char *adb_device_string[] = { "HOST", "dongle", "keyboard", "mouse", "tablet", "modem", "RESERVED", "misc" @@ -118,8 +118,7 @@ adb_bus_enumerate(void *xdev) sc->packet_reply = 0; sc->autopoll_mask = 0; - - mtx_init(&sc->sc_sync_mtx,"adbsyn",NULL,MTX_DEF | MTX_RECURSE); + sc->sync_packet = 0xffff; /* Initialize devinfo */ for (i = 0; i < 16; i++) { @@ -128,7 +127,7 @@ adb_bus_enumerate(void *xdev) } /* Reset ADB bus */ - adb_send_raw_packet_sync(dev,0,ADB_COMMAND_BUS_RESET,0,0,NULL); + adb_send_raw_packet_sync(dev,0,ADB_COMMAND_BUS_RESET,0,0,NULL,NULL); DELAY(1500); /* Enumerate bus */ @@ -140,7 +139,7 @@ adb_bus_enumerate(void *xdev) do { reply = adb_send_raw_packet_sync(dev,i, - ADB_COMMAND_TALK,3,0,NULL); + ADB_COMMAND_TALK,3,0,NULL,NULL); if (reply) { /* If we got a response, relocate to next_free */ @@ -150,10 +149,10 @@ adb_bus_enumerate(void *xdev) r3 |= 0x00fe; adb_send_raw_packet_sync(dev,i, ADB_COMMAND_LISTEN,3, - sizeof(uint16_t),(u_char *)(&r3)); + sizeof(uint16_t),(u_char *)(&r3),NULL); adb_send_raw_packet_sync(dev,next_free, - ADB_COMMAND_TALK,3,0,NULL); + ADB_COMMAND_TALK,3,0,NULL,NULL); sc->devinfo[next_free].default_address = i; if (first_relocated < 0) @@ -169,9 +168,9 @@ adb_bus_enumerate(void *xdev) adb_send_raw_packet_sync(dev,first_relocated, ADB_COMMAND_LISTEN,3, - sizeof(uint16_t),(u_char *)(&r3)); + sizeof(uint16_t),(u_char *)(&r3),NULL); adb_send_raw_packet_sync(dev,i, - ADB_COMMAND_TALK,3,0,NULL); + ADB_COMMAND_TALK,3,0,NULL,NULL); sc->devinfo[i].default_address = i; sc->devinfo[(int)(first_relocated)].default_address = 0; @@ -194,10 +193,6 @@ adb_bus_enumerate(void *xdev) static int adb_bus_detach(device_t dev) { - struct adb_softc *sc = device_get_softc(dev); - - mtx_destroy(&sc->sc_sync_mtx); - return (bus_generic_detach(dev)); } @@ -230,6 +225,7 @@ adb_receive_raw_packet(device_t dev, u_c if (sc->sync_packet == command) { memcpy(sc->syncreg,data,(len > 8) ? 8 : len); atomic_store_rel_int(&sc->packet_reply,len + 1); + wakeup(sc); } if (sc->children[addr] != NULL) { @@ -317,12 +313,12 @@ adb_get_device_handler(device_t dev) static int adb_send_raw_packet_sync(device_t dev, uint8_t to, uint8_t command, - uint8_t reg, int len, u_char *data) + uint8_t reg, int len, u_char *data, u_char *reply) { u_char command_byte = 0; struct adb_softc *sc; int result = -1; - int i = 0; + int i = 1; sc = device_get_softc(dev); @@ -331,7 +327,8 @@ adb_send_raw_packet_sync(device_t dev, u command_byte |= reg; /* Wait if someone else has a synchronous request pending */ - mtx_lock(&sc->sc_sync_mtx); + while (!atomic_cmpset_int(&sc->sync_packet, 0xffff, command_byte)) + tsleep(sc, 0, "ADB sync", hz/10); sc->packet_reply = 0; sc->sync_packet = command_byte; @@ -343,21 +340,27 @@ adb_send_raw_packet_sync(device_t dev, u * Maybe the command got lost? Try resending and polling the * controller. */ - if (i > 40) + if (i % 40 == 0) ADB_HB_SEND_RAW_PACKET(sc->parent, command_byte, len, data, 1); - DELAY(100); + tsleep(sc, 0, "ADB sync", hz/10); i++; } result = sc->packet_reply - 1; + if (reply != NULL && result > 0) + memcpy(reply,sc->syncreg,result); + /* Clear packet sync */ sc->packet_reply = 0; - sc->sync_packet = 0xffff; /* We can't match a 16 bit value */ - mtx_unlock(&sc->sc_sync_mtx); + /* + * We can't match a value beyond 8 bits, so set sync_packet to + * 0xffff to avoid collisions. + */ + atomic_set_int(&sc->sync_packet, 0xffff); return (result); } @@ -375,37 +378,27 @@ adb_set_device_handler(device_t dev, uin newr3 = dinfo->register3 & 0xff00; newr3 |= (uint16_t)(newhandler); + adb_send_raw_packet_sync(sc->sc_dev,dinfo->address, ADB_COMMAND_LISTEN, + 3, sizeof(uint16_t), (u_char *)(&newr3), NULL); adb_send_raw_packet_sync(sc->sc_dev,dinfo->address, - ADB_COMMAND_LISTEN, 3, sizeof(uint16_t), (u_char *)(&newr3)); - adb_send_raw_packet_sync(sc->sc_dev,dinfo->address, - ADB_COMMAND_TALK, 3, 0, NULL); + ADB_COMMAND_TALK, 3, 0, NULL, NULL); return (dinfo->handler_id); } -uint8_t -adb_read_register(device_t dev, u_char reg, - size_t *len, void *data) +size_t +adb_read_register(device_t dev, u_char reg, void *data) { struct adb_softc *sc; struct adb_devinfo *dinfo; - size_t orig_len; + size_t result; dinfo = device_get_ivars(dev); sc = device_get_softc(device_get_parent(dev)); - orig_len = *len; - - mtx_lock(&sc->sc_sync_mtx); - - *len = adb_send_raw_packet_sync(sc->sc_dev,dinfo->address, - ADB_COMMAND_TALK, reg, 0, NULL); + result = adb_send_raw_packet_sync(sc->sc_dev,dinfo->address, + ADB_COMMAND_TALK, reg, 0, NULL, data); - if (*len > 0) - memcpy(data,sc->syncreg,*len); - - mtx_unlock(&sc->sc_sync_mtx); - - return ((*len > 0) ? 0 : -1); + return (result); } Modified: head/sys/dev/adb/adb_kbd.c ============================================================================== --- head/sys/dev/adb/adb_kbd.c Sat Dec 6 23:00:48 2008 (r185723) +++ head/sys/dev/adb/adb_kbd.c Sat Dec 6 23:26:02 2008 (r185724) @@ -271,11 +271,12 @@ adb_kbd_attach(device_t dev) } #endif - adb_set_autopoll(dev,1); - - /* Check (asynchronously) if we can read out the LED state from + /* Check if we can read out the LED state from this keyboard by reading the key state register */ - adb_send_packet(dev,ADB_COMMAND_TALK,2,0,NULL); + if (adb_read_register(dev, 2, NULL) == 2) + sc->have_led_control = 1; + + adb_set_autopoll(dev,1); return (0); } @@ -323,11 +324,6 @@ adb_kbd_receive_packet(device_t dev, u_c if (command != ADB_COMMAND_TALK) return 0; - if (reg == 2 && len == 2) { - sc->have_led_control = 1; - return 0; - } - if (reg != 0 || len != 2) return (0); Modified: head/sys/dev/adb/adb_mouse.c ============================================================================== --- head/sys/dev/adb/adb_mouse.c Sat Dec 6 23:00:48 2008 (r185723) +++ head/sys/dev/adb/adb_mouse.c Sat Dec 6 23:26:02 2008 (r185724) @@ -181,7 +181,7 @@ adb_mouse_attach(device_t dev) sc->mode.resolution = 200; break; case 4: - adb_read_register(dev,1,&r1_len,r1); + r1_len = adb_read_register(dev,1,r1); if (r1_len < 8) break; Modified: head/sys/dev/adb/adbvar.h ============================================================================== --- head/sys/dev/adb/adbvar.h Sat Dec 6 23:00:48 2008 (r185723) +++ head/sys/dev/adb/adbvar.h Sat Dec 6 23:26:02 2008 (r185724) @@ -40,7 +40,6 @@ struct adb_softc { device_t parent; struct intr_config_hook enum_hook; - struct mtx sc_sync_mtx; volatile int sync_packet; volatile int packet_reply; Modified: head/sys/powerpc/powermac/cuda.c ============================================================================== --- head/sys/powerpc/powermac/cuda.c Sat Dec 6 23:00:48 2008 (r185723) +++ head/sys/powerpc/powermac/cuda.c Sat Dec 6 23:26:02 2008 (r185724) @@ -65,10 +65,12 @@ static int cuda_probe(device_t); static int cuda_attach(device_t); static int cuda_detach(device_t); -static u_int cuda_adb_send(device_t dev, u_char command_byte, int len, +static u_int cuda_adb_send(device_t dev, u_char command_byte, int len, u_char *data, u_char poll); -static u_int cuda_adb_autopoll(device_t dev, uint16_t mask); -static void cuda_poll(device_t dev); +static u_int cuda_adb_autopoll(device_t dev, uint16_t mask); +static void cuda_poll(device_t dev); +static void cuda_send_inbound(struct cuda_softc *sc); +static void cuda_send_outbound(struct cuda_softc *sc); static device_method_t cuda_methods[] = { /* Device interface */ @@ -102,6 +104,8 @@ static devclass_t cuda_devclass; DRIVER_MODULE(cuda, macio, cuda_driver, cuda_devclass, 0, 0); DRIVER_MODULE(adb, cuda, adb_driver, adb_devclass, 0, 0); +MALLOC_DEFINE(M_CUDA, "cuda", "CUDA packet queue"); + static void cuda_intr(void *arg); static uint8_t cuda_read_reg(struct cuda_softc *sc, u_int offset); static void cuda_write_reg(struct cuda_softc *sc, u_int offset, uint8_t value); @@ -170,9 +174,11 @@ cuda_attach(device_t dev) sc->sc_waiting = 0; sc->sc_polling = 0; sc->sc_state = CUDA_NOTREADY; - sc->sc_error = 0; sc->sc_autopoll = 0; + STAILQ_INIT(&sc->sc_inq); + STAILQ_INIT(&sc->sc_outq); + /* Init CUDA */ reg = cuda_read_reg(sc, vDirB); @@ -335,42 +341,126 @@ cuda_send(void *cookie, int poll, int le { struct cuda_softc *sc = cookie; device_t dev = sc->sc_dev; + struct cuda_packet *pkt; if (sc->sc_state == CUDA_NOTREADY) - return -1; + return (-1); mtx_lock(&sc->sc_mutex); - if (sc->sc_state != CUDA_IDLE) { - if (sc->sc_waiting == 0) { - sc->sc_waiting = 1; - } else { - mtx_unlock(&sc->sc_mutex); - return -1; - } + pkt = malloc(sizeof(struct cuda_packet), M_CUDA, M_WAITOK); + pkt->len = length - 1; + pkt->type = msg[0]; + memcpy(pkt->data, &msg[1], pkt->len); + + STAILQ_INSERT_TAIL(&sc->sc_outq, pkt, pkt_q); + + /* + * If we already are sending a packet, we should bail now that this + * one has been added to the queue. + */ + + if (sc->sc_waiting) { + mtx_unlock(&sc->sc_mutex); + return (0); } - sc->sc_error = 0; - memcpy(sc->sc_out, msg, length); - sc->sc_out_length = length; + cuda_send_outbound(sc); + mtx_unlock(&sc->sc_mutex); + + if (sc->sc_polling || poll || cold) + cuda_poll(dev); + + return (0); +} + +static void +cuda_send_outbound(struct cuda_softc *sc) +{ + struct cuda_packet *pkt; + + mtx_assert(&sc->sc_mutex, MA_OWNED); + + pkt = STAILQ_FIRST(&sc->sc_outq); + if (pkt == NULL) + return; + + sc->sc_out_length = pkt->len + 1; + memcpy(sc->sc_out, &pkt->type, pkt->len + 1); sc->sc_sent = 0; - if (sc->sc_waiting != 1) { - DELAY(150); + free(pkt, M_CUDA); + STAILQ_REMOVE_HEAD(&sc->sc_outq, pkt_q); + + sc->sc_waiting = 1; + + cuda_poll(sc->sc_dev); + + DELAY(150); + + if (sc->sc_state == CUDA_IDLE && !cuda_intr_state(sc)) { sc->sc_state = CUDA_OUT; cuda_out(sc); cuda_write_reg(sc, vSR, sc->sc_out[0]); cuda_ack_off(sc); cuda_tip(sc); } - sc->sc_waiting = 1; - mtx_unlock(&sc->sc_mutex); +} - if (sc->sc_polling || poll || cold) { - cuda_poll(dev); +static void +cuda_send_inbound(struct cuda_softc *sc) +{ + device_t dev; + struct cuda_packet *pkt; + + dev = sc->sc_dev; + + mtx_lock(&sc->sc_mutex); + + while ((pkt = STAILQ_FIRST(&sc->sc_inq)) != NULL) { + STAILQ_REMOVE_HEAD(&sc->sc_inq, pkt_q); + + mtx_unlock(&sc->sc_mutex); + + /* check if we have a handler for this message */ + switch (pkt->type) { + case CUDA_ADB: + if (pkt->len > 2) { + adb_receive_raw_packet(sc->adb_bus, + pkt->data[0],pkt->data[1], + pkt->len - 2,&pkt->data[2]); + } else { + adb_receive_raw_packet(sc->adb_bus, + pkt->data[0],pkt->data[1],0,NULL); + } + break; + case CUDA_PSEUDO: + mtx_lock(&sc->sc_mutex); + if (pkt->data[0] == CMD_AUTOPOLL) + sc->sc_autopoll = 1; + mtx_unlock(&sc->sc_mutex); + break; + case CUDA_ERROR: + /* + * CUDA will throw errors if we miss a race between + * sending and receiving packets. This is already + * handled when we abort packet output to handle + * this packet in cuda_intr(). Thus, we ignore + * these messages. + */ + break; + default: + device_printf(dev,"unknown CUDA command %d\n", + pkt->type); + break; + } + + free(pkt,M_CUDA); + + mtx_lock(&sc->sc_mutex); } - return 0; + mtx_unlock(&sc->sc_mutex); } static void @@ -382,8 +472,7 @@ cuda_poll(device_t dev) !sc->sc_waiting) return; - if ((cuda_read_reg(sc, vIFR) & vSR_INT) == vSR_INT) - cuda_intr(dev); + cuda_intr(dev); } static void @@ -392,7 +481,7 @@ cuda_intr(void *arg) device_t dev; struct cuda_softc *sc; - int i, ending, type, restart_send; + int i, ending, restart_send, process_inbound; uint8_t reg; dev = (device_t)arg; @@ -401,7 +490,13 @@ cuda_intr(void *arg) mtx_lock(&sc->sc_mutex); restart_send = 0; + process_inbound = 0; reg = cuda_read_reg(sc, vIFR); + if ((reg & vSR_INT) != vSR_INT) { + mtx_unlock(&sc->sc_mutex); + return; + } + cuda_write_reg(sc, vIFR, 0x7f); /* Clear interrupt */ switch_start: @@ -450,13 +545,6 @@ switch_start: } else sc->sc_received++; - if (sc->sc_received > 3) { - if ((sc->sc_in[3] == CMD_IIC) && - (sc->sc_received > (sc->sc_i2c_read_len + 4))) { - ending = 1; - } - } - /* intr off means this is the last byte (end of frame) */ if (cuda_intr_state(sc) == 0) { ending = 1; @@ -465,42 +553,24 @@ switch_start: } if (ending == 1) { /* end of message? */ - sc->sc_in[0] = sc->sc_received - 1; + struct cuda_packet *pkt; /* reset vars and signal the end of this frame */ cuda_idle(sc); - /* check if we have a handler for this message */ - type = sc->sc_in[1]; + /* Queue up the packet */ + pkt = malloc(sizeof(struct cuda_packet), M_CUDA, + M_WAITOK); + + pkt->len = sc->sc_received - 2; + pkt->type = sc->sc_in[1]; + memcpy(pkt->data, &sc->sc_in[2], pkt->len); - switch (type) { - case CUDA_ADB: - if (sc->sc_received > 4) { - adb_receive_raw_packet(sc->adb_bus, - sc->sc_in[2],sc->sc_in[3], - sc->sc_received - 4,&sc->sc_in[4]); - } else { - adb_receive_raw_packet(sc->adb_bus, - sc->sc_in[2],sc->sc_in[3],0,NULL); - } - break; - case CUDA_PSEUDO: - if (sc->sc_in[3] == CMD_AUTOPOLL) - sc->sc_autopoll = 1; - break; - case CUDA_ERROR: - device_printf(dev,"CUDA Error\n"); - sc->sc_error = 1; - break; - default: - device_printf(dev,"unknown CUDA command %d\n", - type); - break; - } + STAILQ_INSERT_TAIL(&sc->sc_inq, pkt, pkt_q); sc->sc_state = CUDA_IDLE; - sc->sc_received = 0; + process_inbound = 1; /* * If there is something waiting to be sent out, @@ -526,6 +596,7 @@ switch_start: DELAY(150); goto switch_start; } + /* * If we got here, it's ok to start sending * so load the first byte and tell the chip @@ -558,7 +629,6 @@ switch_start: break; } if (sc->sc_out_length == sc->sc_sent) { /* check for done */ - sc->sc_waiting = 0; /* done writing */ sc->sc_state = CUDA_IDLE; /* signal bus is idle */ cuda_in(sc); @@ -579,14 +649,26 @@ switch_start: } mtx_unlock(&sc->sc_mutex); + + if (process_inbound) + cuda_send_inbound(sc); + + mtx_lock(&sc->sc_mutex); + /* If we have another packet waiting, set it up */ + if (!sc->sc_waiting && sc->sc_state == CUDA_IDLE) + cuda_send_outbound(sc); + + mtx_unlock(&sc->sc_mutex); + } static u_int -cuda_adb_send(device_t dev, u_char command_byte, int len, u_char *data, u_char poll) +cuda_adb_send(device_t dev, u_char command_byte, int len, u_char *data, + u_char poll) { struct cuda_softc *sc = device_get_softc(dev); - int i; uint8_t packet[16]; + int i; /* construct an ADB command packet and send it */ packet[0] = CUDA_ADB; @@ -594,15 +676,9 @@ cuda_adb_send(device_t dev, u_char comma for (i = 0; i < len; i++) packet[i + 2] = data[i]; - if (poll) - cuda_poll(dev); - cuda_send(sc, poll, len + 2, packet); - if (poll) - cuda_poll(dev); - - return 0; + return (0); } static u_int @@ -615,17 +691,14 @@ cuda_adb_autopoll(device_t dev, uint16_t if (cmd[2] == sc->sc_autopoll) { mtx_unlock(&sc->sc_mutex); - return 0; + return (0); } - while (sc->sc_state != CUDA_IDLE) - mtx_sleep(dev,&sc->sc_mutex,0,"cuda",1); - sc->sc_autopoll = -1; - cuda_send(sc, 0, 3, cmd); + cuda_send(sc, 1, 3, cmd); mtx_unlock(&sc->sc_mutex); - - return 0; + + return (0); } Modified: head/sys/powerpc/powermac/cudavar.h ============================================================================== --- head/sys/powerpc/powermac/cudavar.h Sat Dec 6 23:00:48 2008 (r185723) +++ head/sys/powerpc/powermac/cudavar.h Sat Dec 6 23:26:02 2008 (r185724) @@ -61,6 +61,16 @@ #define CUDA_IN 0x4 /* receiving data */ #define CUDA_POLLING 0x5 /* polling - II only */ +struct cuda_packet { + uint8_t len; + uint8_t type; + + uint8_t data[253]; + STAILQ_ENTRY(cuda_packet) pkt_q; +}; + +STAILQ_HEAD(cuda_pktq, cuda_packet); + struct cuda_softc { device_t sc_dev; int sc_memrid; @@ -73,22 +83,24 @@ struct cuda_softc { device_t adb_bus; - int sc_node; - volatile int sc_state; - int sc_waiting; - int sc_polling; - int sc_sent; - int sc_out_length; - int sc_received; - int sc_iic_done; - int sc_error; - volatile int sc_autopoll; + int sc_node; + volatile int sc_state; + int sc_waiting; + int sc_polling; + int sc_iic_done; + volatile int sc_autopoll; int sc_i2c_read_len; /* internal buffers */ - uint8_t sc_in[256]; - uint8_t sc_out[256]; + uint8_t sc_in[256]; + uint8_t sc_out[256]; + int sc_sent; + int sc_out_length; + int sc_received; + + struct cuda_pktq sc_inq; + struct cuda_pktq sc_outq; }; #endif /* _POWERPC_CUDAVAR_H_ */ From nwhitehorn at FreeBSD.org Sat Dec 6 16:42:16 2008 From: nwhitehorn at FreeBSD.org (Nathan Whitehorn) Date: Sat Dec 6 16:42:27 2008 Subject: svn commit: r185727 - head/sys/powerpc/powermac Message-ID: <200812070042.mB70gFEK009493@svn.freebsd.org> Author: nwhitehorn Date: Sun Dec 7 00:42:15 2008 New Revision: 185727 URL: http://svn.freebsd.org/changeset/base/185727 Log: Add support for automated reboot after power failure on Apple Core99 machines (G3 laptops, all G4 machines, early G5s, G5 Xserves). The relevant sysctl is named dev.pmu.0.server_mode for mental compatibility with Linux. Modified: head/sys/powerpc/powermac/pmu.c Modified: head/sys/powerpc/powermac/pmu.c ============================================================================== --- head/sys/powerpc/powermac/pmu.c Sun Dec 7 00:41:40 2008 (r185726) +++ head/sys/powerpc/powermac/pmu.c Sun Dec 7 00:42:15 2008 (r185727) @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -65,10 +66,11 @@ static int pmu_probe(device_t); static int pmu_attach(device_t); static int pmu_detach(device_t); -static u_int pmu_adb_send(device_t dev, u_char command_byte, int len, +static u_int pmu_adb_send(device_t dev, u_char command_byte, int len, u_char *data, u_char poll); -static u_int pmu_adb_autopoll(device_t dev, uint16_t mask); -static void pmu_poll(device_t dev); +static u_int pmu_adb_autopoll(device_t dev, uint16_t mask); +static void pmu_poll(device_t dev); +static int pmu_server_mode(SYSCTL_HANDLER_ARGS); static device_method_t pmu_methods[] = { /* Device interface */ @@ -282,6 +284,8 @@ pmu_attach(device_t dev) uint8_t cmd[2] = {2, 0}; uint8_t resp[16]; phandle_t node,child; + struct sysctl_ctx_list *ctx; + struct sysctl_oid *tree; sc = device_get_softc(dev); sc->sc_dev = dev; @@ -341,6 +345,17 @@ pmu_attach(device_t dev) } } + /* + * Set up sysctls + */ + + ctx = device_get_sysctl_ctx(dev); + tree = device_get_sysctl_tree(dev); + + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + "server_mode", CTLTYPE_INT | CTLFLAG_RW, sc, 0, + pmu_server_mode, "I", "Enable reboot after power failure"); + return (bus_generic_attach(dev)); } @@ -613,3 +628,46 @@ pmu_adb_autopoll(device_t dev, uint16_t return 0; } + +static int +pmu_server_mode(SYSCTL_HANDLER_ARGS) +{ + struct pmu_softc *sc = arg1; + + u_int server_mode = 0; + uint8_t getcmd[] = {PMU_PWR_GET_POWERUP_EVENTS}; + uint8_t setcmd[] = {0, 0, PMU_PWR_WAKEUP_AC_INSERT}; + uint8_t resp[3]; + int error, len; + + mtx_lock(&sc->sc_mutex); + len = pmu_send(sc, PMU_POWER_EVENTS, 1, getcmd, 3, resp); + mtx_unlock(&sc->sc_mutex); + + if (len == 3) + server_mode = (resp[2] & PMU_PWR_WAKEUP_AC_INSERT) ? 1 : 0; + + error = sysctl_handle_int(oidp, &server_mode, 0, req); + + if (len != 3) + return (EINVAL); + + if (error || !req->newptr) + return (error); + + if (server_mode == 1) + setcmd[0] = PMU_PWR_SET_POWERUP_EVENTS; + else if (server_mode == 0) + setcmd[0] = PMU_PWR_CLR_POWERUP_EVENTS; + else + return (EINVAL); + + setcmd[1] = resp[1]; + + mtx_lock(&sc->sc_mutex); + pmu_send(sc, PMU_POWER_EVENTS, 3, setcmd, 2, resp); + mtx_unlock(&sc->sc_mutex); + + return (0); +} + From xcllnt at mac.com Sat Dec 6 17:45:16 2008 From: xcllnt at mac.com (Marcel Moolenaar) Date: Sat Dec 6 17:45:21 2008 Subject: svn commit: r185727 - head/sys/powerpc/powermac In-Reply-To: <200812070042.mB70gFEK009493@svn.freebsd.org> References: <200812070042.mB70gFEK009493@svn.freebsd.org> Message-ID: <01839E58-2D85-40CE-B39A-DC903D48955D@mac.com> On Dec 6, 2008, at 4:42 PM, Nathan Whitehorn wrote: > Author: nwhitehorn > Date: Sun Dec 7 00:42:15 2008 > New Revision: 185727 > URL: http://svn.freebsd.org/changeset/base/185727 > > Log: > Add support for automated reboot after power failure on Apple > Core99 machines > (G3 laptops, all G4 machines, early G5s, G5 Xserves). The relevant > sysctl > is named dev.pmu.0.server_mode for mental compatibility with Linux. Yay! Me and my RPC thank you :-) -- Marcel Moolenaar xcllnt@mac.com From peter at FreeBSD.org Sat Dec 6 18:32:50 2008 From: peter at FreeBSD.org (Peter Wemm) Date: Sat Dec 6 18:32:55 2008 Subject: svn commit: r185728 - head/lib/libthr/thread Message-ID: <200812070232.mB72WnrR011584@svn.freebsd.org> Author: peter Date: Sun Dec 7 02:32:49 2008 New Revision: 185728 URL: http://svn.freebsd.org/changeset/base/185728 Log: When libthr and rtld start up, there are a number of magic spells cast in order to get the symbol binding state "just so". This is to allow locking to be activated and not run into recursion problems later. However, one of the magic bits involves an explicit call to _umtx_op() to force symbol resolution. It does a wakeup operation on a fake, uninitialized (ie: random contents) umtx. Since libthr isn't active, this is harmless. Nothing can match the random wakeup. However, valgrind finds this and is not amused. Normally I'd just write a suppression record for it, but the idea of passing random args to syscalls (on purpose) just doesn't feel right. Modified: head/lib/libthr/thread/thr_rtld.c Modified: head/lib/libthr/thread/thr_rtld.c ============================================================================== --- head/lib/libthr/thread/thr_rtld.c Sun Dec 7 00:42:15 2008 (r185727) +++ head/lib/libthr/thread/thr_rtld.c Sun Dec 7 02:32:49 2008 (r185728) @@ -180,7 +180,7 @@ _thr_rtld_init(void) { struct RtldLockInfo li; struct pthread *curthread; - long dummy; + long dummy = -1; curthread = _get_curthread(); From imp at bsdimp.com Sat Dec 6 19:23:59 2008 From: imp at bsdimp.com (M. Warner Losh) Date: Sat Dec 6 19:24:05 2008 Subject: svn commit: r185647 - in head/sys: kern sys In-Reply-To: <20081205230002.GX2038@deviant.kiev.zoral.com.ua> References: <200812052050.mB5KoOcV072648@svn.freebsd.org> <20081205224600.GA16948@freebsd.org> <20081205230002.GX2038@deviant.kiev.zoral.com.ua> Message-ID: <20081206.202344.-160243400.imp@bsdimp.com> In message: <20081205230002.GX2038@deviant.kiev.zoral.com.ua> Kostik Belousov writes: : On Fri, Dec 05, 2008 at 11:46:00PM +0100, Roman Divacky wrote: : > On Fri, Dec 05, 2008 at 08:50:24PM +0000, Konstantin Belousov wrote: : > > Author: kib : > > Date: Fri Dec 5 20:50:24 2008 : > > New Revision: 185647 : > > URL: http://svn.freebsd.org/changeset/base/185647 : > > : > > Log: : > > Several threads in a process may do vfork() simultaneously. Then, all : > > parent threads sleep on the parent' struct proc until corresponding : > > child releases the vmspace. Each sleep is interlocked with proc mutex of : > > the child, that triggers assertion in the sleepq_add(). The assertion : > > requires that at any time, all simultaneous sleepers for the channel use : > > the same interlock. : > > : > > Silent the assertion by using conditional variable allocated in the : > > child. Broadcast the variable event on exec() and exit(). : > > : > > Since struct proc * sleep wait channel is overloaded for several : > > unrelated events, I was unable to remove wakeups from the places where : > > cv_broadcast() is added, except exec(). : > : > are there any differences (performance etc.) in using condition variables : > instead of sleep/wakeup? : : I do not think that there is any measurable difference. On the other : hand, the patch makes struct proc bigger by int + pointer. This shall : not be a problem too. : : Would I been able to convert _all_ uses of the struct proc * wait channel : to cond vars operation, this may be measurable on some loads, since it : would exclude spurious wakeups. Is that a measurable good difference, or a measurable bad difference? Warner From peter at FreeBSD.org Sat Dec 6 19:33:37 2008 From: peter at FreeBSD.org (Peter Wemm) Date: Sat Dec 6 19:33:43 2008 Subject: svn commit: r185729 - head/lib/libutil Message-ID: <200812070333.mB73XaM1012989@svn.freebsd.org> Author: peter Date: Sun Dec 7 03:33:36 2008 New Revision: 185729 URL: http://svn.freebsd.org/changeset/base/185729 Log: Add filler man pages for the kinfo functions I added recently. While here, hook up the hexdump(3) man page which wasn't being installed. Added: head/lib/libutil/kinfo_getfile.3 (contents, props changed) head/lib/libutil/kinfo_getvmmap.3 (contents, props changed) Modified: head/lib/libutil/Makefile Modified: head/lib/libutil/Makefile ============================================================================== --- head/lib/libutil/Makefile Sun Dec 7 02:32:49 2008 (r185728) +++ head/lib/libutil/Makefile Sun Dec 7 03:33:36 2008 (r185729) @@ -30,7 +30,8 @@ MAN+= kld.3 login.3 login_auth.3 login_t login_cap.3 login_class.3 login_times.3 login_ok.3 \ _secure_path.3 uucplock.3 property.3 auth.3 realhostname.3 \ realhostname_sa.3 trimdomain.3 fparseln.3 humanize_number.3 \ - pidfile.3 flopen.3 expand_number.3 + pidfile.3 flopen.3 expand_number.3 hexdump.3 \ + kinfo_getfile.3 kinfo_getvmmap.3 MAN+= login.conf.5 auth.conf.5 MLINKS+= kld.3 kld_isloaded.3 kld.3 kld_load.3 MLINKS+= property.3 properties_read.3 property.3 properties_free.3 Added: head/lib/libutil/kinfo_getfile.3 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libutil/kinfo_getfile.3 Sun Dec 7 03:33:36 2008 (r185729) @@ -0,0 +1,74 @@ +.\" +.\" Copyright (c) 2008 Peter Wemm +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd December 6, 2008 +.Os +.Dt KINFO_GETFILE 3 +.Sh NAME +.Nm kinfo_getfile +.Nd function for getting per-process file descriptor information +.Sh LIBRARY +.Lb libutil +.Sh SYNOPSIS +.In sys/types.h +.In libutil.h +.Ft struct kinfo_file * +.Fn kinfo_getfile "pid_t pid" "int *cntp" +.Sh DESCRIPTION +This function is used for obtaining the file descriptor information +of a particular process. +.Pp +The +.Ar pid +field contains the process identifier. +This should be the a process that you have privilige to access. +The +.Ar cntp +field is allows the caller to know how many records are returned. +.Pp +This function is a wrapper around +.Xr sysctl 3 +with the +.Dv KERN_PROC_FILEDESC +mib. +While the kernel returns a packed structure, this function expands the +data into a fixed record format. +.Sh RETURN VALUES +The +.Fn kinfo_getfile +function returns a pointer to an array of +.Vt struct kinfo_file +structures. +The array was obtained by an internal call to +.Xr malloc 3 +and must be freed by the caller with a call to +.Xr free 3 . +.Sh SEE ALSO +.Xr free 3 , +.Xr kinfo_getvmmap 3 , +.Xr malloc 3 , +.Xr sysctl 3 Added: head/lib/libutil/kinfo_getvmmap.3 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libutil/kinfo_getvmmap.3 Sun Dec 7 03:33:36 2008 (r185729) @@ -0,0 +1,73 @@ +.\" +.\" Copyright (c) 2008 Peter Wemm +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd December 6, 2008 +.Os +.Dt KINFO_GETVMMAP 3 +.Sh NAME +.Nm kinfo_getvmmap +.Nd function for getting per-process memory map information +.Sh LIBRARY +.Lb libutil +.Sh SYNOPSIS +.In sys/types.h +.In libutil.h +.Ft struct kinfo_vmentry * +.Fn kinfo_getfile "pid_t pid" "int *cntp" +.Sh DESCRIPTION +This function is used for obtaining the file descriptor information +of a particular process. +.Pp +The +.Ar pid +field contains the process identifier. +This should be the a process that you have privilige to access. +The +.Ar cntp +field is allows the caller to know how many records are returned. +.Pp +This function is a wrapper around +.Xr sysctl 3 +with the +.Dv KERN_PROC_VMMAP +mib. +While the kernel returns a packed structure, this function expands the +data into a fixed record format. +.Sh RETURN VALUES +The +.Fn kinfo_getvmmap +function returns a pointer to an array of +.Vt struct kinfo_vmentry +structures. +The array was obtained by an internal call to +.Xr malloc 3 +and must be freed by the caller with a call to +.Xr free 3 . +.Sh SEE ALSO +.Xr free 3 , +.Xr kinfo_getfile 3 , +.Xr malloc 3 From nwhitehorn at FreeBSD.org Sat Dec 6 22:18:48 2008 From: nwhitehorn at FreeBSD.org (Nathan Whitehorn) Date: Sat Dec 6 22:18:54 2008 Subject: svn commit: r185736 - head/share/man/man4/man4.powerpc Message-ID: <200812070618.mB76IlrY016346@svn.freebsd.org> Author: nwhitehorn Date: Sun Dec 7 06:18:47 2008 New Revision: 185736 URL: http://svn.freebsd.org/changeset/base/185736 Log: Now that pmu(4) has features, it should also have a man page. Added: head/share/man/man4/man4.powerpc/pmu.4 (contents, props changed) Modified: head/share/man/man4/man4.powerpc/Makefile Modified: head/share/man/man4/man4.powerpc/Makefile ============================================================================== --- head/share/man/man4/man4.powerpc/Makefile Sun Dec 7 06:01:09 2008 (r185735) +++ head/share/man/man4/man4.powerpc/Makefile Sun Dec 7 06:18:47 2008 (r185736) @@ -1,6 +1,7 @@ # $FreeBSD$ MAN= bm.4 \ + pmu.4 \ powermac_nvram.4 MANSUBDIR=/powerpc Added: head/share/man/man4/man4.powerpc/pmu.4 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/share/man/man4/man4.powerpc/pmu.4 Sun Dec 7 06:18:47 2008 (r185736) @@ -0,0 +1,95 @@ +.\"- +.\" Copyright (c) 2008 Nathan Whitehorn +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +.\" DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd December 6, 2008 +.Dt PMU 4 +.Os +.Sh NAME +.Nm pmu +.Nd Apple PMU99 Power Management Driver +.Sh SYNOPSIS +To compile this driver into the kernel, +place the following lines in your +kernel configuration file: +.Bd -ragged -offset indent +.Cd "device adb" +.Cd "device pmu" +.Ed +.Sh DESCRIPTION +The +.Nm +driver provides support for the Power Management Unit (PMU) find in Apple +Core99 hardware. This includes late G3 laptops, all G4 machines, early G5 +desktops and all G5 XServes. +.Ed +.Pp +The Apple PMU controller is a multi-purpose ASIC that provides power +management and thermal control, as well as an ADB bus for the internal +keyboard and mouse on laptops. +.Sh HARDWARE +.Pp +Chips supported by the +.Nm +driver include: +.Pp +.Bl -bullet -compact +.It +Apple KeyLargo PMU +.It +Apple K2-KeyLargo PMU +.El +.Pp +.Sh SYSCTL VARIABLES +The +.Nm +driver provides power management services in addition to an +.Xr adb 4 +interface. The following sysctls can be used to control the +power management behavior. +.Bl -tag -width indent +.It Va dev.pmu.%d.server_mode +Restart after power failure behavior (1 causes system to reboot after power +cut, 0 causes system to remain off) +.Sh SEE ALSO +.Xr adb 4 +.Sh HISTORY +The +.Nm +device driver appeared in +.Nx 4.0 , +and then in +.Fx 8.0 . +.Sh AUTHORS +.An -nosplit +The +.Nm +driver was written by +.An Michael Lorenz +.Aq macallan@NetBSD.org +and ported to FreeBSD by +.An Nathan Whitehorn +.Aq nwhitehorn@freebsd.org . From nwhitehorn at FreeBSD.org Sat Dec 6 22:34:51 2008 From: nwhitehorn at FreeBSD.org (Nathan Whitehorn) Date: Sat Dec 6 22:35:02 2008 Subject: svn commit: r185737 - head/share/man/man4/man4.powerpc Message-ID: <200812070634.mB76YoAU016718@svn.freebsd.org> Author: nwhitehorn Date: Sun Dec 7 06:34:50 2008 New Revision: 185737 URL: http://svn.freebsd.org/changeset/base/185737 Log: Fix spelling error (find -> found). Modified: head/share/man/man4/man4.powerpc/pmu.4 Modified: head/share/man/man4/man4.powerpc/pmu.4 ============================================================================== --- head/share/man/man4/man4.powerpc/pmu.4 Sun Dec 7 06:18:47 2008 (r185736) +++ head/share/man/man4/man4.powerpc/pmu.4 Sun Dec 7 06:34:50 2008 (r185737) @@ -42,7 +42,7 @@ kernel configuration file: .Sh DESCRIPTION The .Nm -driver provides support for the Power Management Unit (PMU) find in Apple +driver provides support for the Power Management Unit (PMU) found in Apple Core99 hardware. This includes late G3 laptops, all G4 machines, early G5 desktops and all G5 XServes. .Ed From kostikbel at gmail.com Sun Dec 7 02:26:26 2008 From: kostikbel at gmail.com (Kostik Belousov) Date: Sun Dec 7 02:26:38 2008 Subject: svn commit: r185647 - in head/sys: kern sys In-Reply-To: <20081206.202344.-160243400.imp@bsdimp.com> References: <200812052050.mB5KoOcV072648@svn.freebsd.org> <20081205224600.GA16948@freebsd.org> <20081205230002.GX2038@deviant.kiev.zoral.com.ua> <20081206.202344.-160243400.imp@bsdimp.com> Message-ID: <20081207102620.GK2038@deviant.kiev.zoral.com.ua> On Sat, Dec 06, 2008 at 08:23:44PM -0700, M. Warner Losh wrote: > In message: <20081205230002.GX2038@deviant.kiev.zoral.com.ua> > Kostik Belousov writes: > : On Fri, Dec 05, 2008 at 11:46:00PM +0100, Roman Divacky wrote: > : > On Fri, Dec 05, 2008 at 08:50:24PM +0000, Konstantin Belousov wrote: > : > > Author: kib > : > > Date: Fri Dec 5 20:50:24 2008 > : > > New Revision: 185647 > : > > URL: http://svn.freebsd.org/changeset/base/185647 > : > > > : > > Log: > : > > Several threads in a process may do vfork() simultaneously. Then, all > : > > parent threads sleep on the parent' struct proc until corresponding > : > > child releases the vmspace. Each sleep is interlocked with proc mutex of > : > > the child, that triggers assertion in the sleepq_add(). The assertion > : > > requires that at any time, all simultaneous sleepers for the channel use > : > > the same interlock. > : > > > : > > Silent the assertion by using conditional variable allocated in the > : > > child. Broadcast the variable event on exec() and exit(). > : > > > : > > Since struct proc * sleep wait channel is overloaded for several > : > > unrelated events, I was unable to remove wakeups from the places where > : > > cv_broadcast() is added, except exec(). > : > > : > are there any differences (performance etc.) in using condition variables > : > instead of sleep/wakeup? > : > : I do not think that there is any measurable difference. On the other > : hand, the patch makes struct proc bigger by int + pointer. This shall > : not be a problem too. > : > : Would I been able to convert _all_ uses of the struct proc * wait channel > : to cond vars operation, this may be measurable on some loads, since it > : would exclude spurious wakeups. > > Is that a measurable good difference, or a measurable bad difference? I expect this could be measurable good difference, i.e. such patch might improve performance on some loads by eliminating false wakeups. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 195 bytes Desc: not available Url : http://lists.freebsd.org/pipermail/svn-src-head/attachments/20081207/930114f8/attachment.pgp From kib at FreeBSD.org Sun Dec 7 05:25:07 2008 From: kib at FreeBSD.org (Konstantin Belousov) Date: Sun Dec 7 05:25:13 2008 Subject: svn commit: r185739 - head/sys/ufs/ufs Message-ID: <200812071325.mB7DP64P026630@svn.freebsd.org> Author: kib Date: Sun Dec 7 13:25:06 2008 New Revision: 185739 URL: http://svn.freebsd.org/changeset/base/185739 Log: Improve usefulness of the panic by printing the pointer to the problematic dquot. In-tree gdb is often unable to get the dq value, so supply it in panic message. MFC after: 3 days Modified: head/sys/ufs/ufs/ufs_quota.c Modified: head/sys/ufs/ufs/ufs_quota.c ============================================================================== --- head/sys/ufs/ufs/ufs_quota.c Sun Dec 7 07:02:26 2008 (r185738) +++ head/sys/ufs/ufs/ufs_quota.c Sun Dec 7 13:25:06 2008 (r185739) @@ -1151,7 +1151,7 @@ hfound: DQI_LOCK(dq); return (EUSERS); } if (dq->dq_cnt || (dq->dq_flags & DQ_MOD)) - panic("dqget: free dquot isn't"); + panic("dqget: free dquot isn't %p", dq); TAILQ_REMOVE(&dqfreelist, dq, dq_freelist); if (dq->dq_ump != NULL) LIST_REMOVE(dq, dq_hash); From imp at FreeBSD.org Sun Dec 7 10:32:10 2008 From: imp at FreeBSD.org (Warner Losh) Date: Sun Dec 7 10:32:21 2008 Subject: svn commit: r185740 - head/sys/dev/pccbb Message-ID: <200812071832.mB7IW96f032499@svn.freebsd.org> Author: imp Date: Sun Dec 7 18:32:09 2008 New Revision: 185740 URL: http://svn.freebsd.org/changeset/base/185740 Log: Use atomic_add_int rather than a simple ++ to ensure no cache races if the power interrupt and init code waiting for the interrupt are running on different CPUs. I haven't seen this make any real difference, but I've also had some reports of odd behavior I can't otherwise explain. It is an infrequent operation, and certainly wouldn't hurt. Modified: head/sys/dev/pccbb/pccbb_pci.c Modified: head/sys/dev/pccbb/pccbb_pci.c ============================================================================== --- head/sys/dev/pccbb/pccbb_pci.c Sun Dec 7 13:25:06 2008 (r185739) +++ head/sys/dev/pccbb/pccbb_pci.c Sun Dec 7 18:32:09 2008 (r185740) @@ -730,7 +730,7 @@ cbb_pci_filt(void *arg) if (sockevent & CBB_SOCKET_EVENT_POWER) { cbb_clrb(sc, CBB_SOCKET_MASK, CBB_SOCKET_EVENT_POWER); cbb_set(sc, CBB_SOCKET_EVENT, CBB_SOCKET_EVENT_POWER); - sc->powerintr++; + atomic_add_int(&sc->powerintr, 1); wakeup((void *)&sc->powerintr); } retval = FILTER_HANDLED; From imp at FreeBSD.org Sun Dec 7 10:34:27 2008 From: imp at FreeBSD.org (Warner Losh) Date: Sun Dec 7 10:34:39 2008 Subject: svn commit: r185741 - head/sys/dev/pccbb Message-ID: <200812071834.mB7IYR7k032653@svn.freebsd.org> Author: imp Date: Sun Dec 7 18:34:27 2008 New Revision: 185741 URL: http://svn.freebsd.org/changeset/base/185741 Log: Use '0' rather than PZERO to not change the priority that I'm waiting at. I don't think this will make a huge difference, but I have received a report of a interrupt storm on one 16-bit card that this might fix (chances are it won't, since I think that we may need to check both the CBB registers for the 16-bit card as well as the PCIC registers for power state change). Submitted by: jhb@ Modified: head/sys/dev/pccbb/pccbb.c Modified: head/sys/dev/pccbb/pccbb.c ============================================================================== --- head/sys/dev/pccbb/pccbb.c Sun Dec 7 18:32:09 2008 (r185740) +++ head/sys/dev/pccbb/pccbb.c Sun Dec 7 18:34:27 2008 (r185741) @@ -515,11 +515,11 @@ cbb_event_thread(void *arg) */ mtx_lock(&sc->mtx); cbb_setb(sc, CBB_SOCKET_MASK, CBB_SOCKET_MASK_CD | CBB_SOCKET_MASK_CSTS); - msleep(&sc->intrhand, &sc->mtx, PZERO, "-", 0); + msleep(&sc->intrhand, &sc->mtx, 0, "-", 0); err = 0; while (err != EWOULDBLOCK && (sc->flags & CBB_KTHREAD_DONE) == 0) - err = msleep(&sc->intrhand, &sc->mtx, PZERO, "-", hz / 5); + err = msleep(&sc->intrhand, &sc->mtx, 0, "-", hz / 5); } DEVPRINTF((sc->dev, "Thread terminating\n")); sc->flags &= ~CBB_KTHREAD_RUNNING; @@ -795,7 +795,7 @@ cbb_power(device_t brdev, int volts) sane = 10; while (!(cbb_get(sc, CBB_SOCKET_STATE) & CBB_STATE_POWER_CYCLE) && cnt == sc->powerintr && sane-- > 0) - msleep(&sc->powerintr, &sc->mtx, PZERO, "-", hz / 20); + msleep(&sc->powerintr, &sc->mtx, 0, "-", hz / 20); mtx_unlock(&sc->mtx); /* * The TOPIC95B requires a little bit extra time to get From trhodes at FreeBSD.org Sun Dec 7 10:45:30 2008 From: trhodes at FreeBSD.org (Tom Rhodes) Date: Sun Dec 7 10:45:37 2008 Subject: svn commit: r185742 - head/usr.sbin/syslogd Message-ID: <200812071845.mB7IjU4T032887@svn.freebsd.org> Author: trhodes Date: Sun Dec 7 18:45:30 2008 New Revision: 185742 URL: http://svn.freebsd.org/changeset/base/185742 Log: Use "allowed_peer" throughout this manual page. Modified: head/usr.sbin/syslogd/syslogd.8 Modified: head/usr.sbin/syslogd/syslogd.8 ============================================================================== --- head/usr.sbin/syslogd/syslogd.8 Sun Dec 7 18:34:27 2008 (r185741) +++ head/usr.sbin/syslogd/syslogd.8 Sun Dec 7 18:45:30 2008 (r185742) @@ -95,8 +95,9 @@ Multiple .Fl a options may be specified. .Pp -.Ar Allowed_peer -can be any of the following: +The +.Ar allowed_peer +option may be any of the following: .Bl -tag -width "ipaddr/masklen[:service]XX" .It Xo .Sm off From sam at FreeBSD.org Sun Dec 7 11:17:35 2008 From: sam at FreeBSD.org (Sam Leffler) Date: Sun Dec 7 11:17:48 2008 Subject: svn commit: r185743 - in head/tools/tools/ath: . athdebug athkey athpow athprom athregs athstats common Message-ID: <200812071917.mB7JHYYJ033534@svn.freebsd.org> Author: sam Date: Sun Dec 7 19:17:33 2008 New Revision: 185743 URL: http://svn.freebsd.org/changeset/base/185743 Log: bring in diagnostic tools that are useful now that we have hal source code Added: head/tools/tools/ath/Makefile.inc (contents, props changed) head/tools/tools/ath/athkey/ head/tools/tools/ath/athkey/Makefile (contents, props changed) head/tools/tools/ath/athkey/athkey.c (contents, props changed) head/tools/tools/ath/athpow/ head/tools/tools/ath/athpow/Makefile (contents, props changed) head/tools/tools/ath/athpow/athpow.c (contents, props changed) head/tools/tools/ath/athprom/ head/tools/tools/ath/athprom/Makefile (contents, props changed) head/tools/tools/ath/athprom/athprom.c (contents, props changed) head/tools/tools/ath/athprom/eeprom-14 (contents, props changed) head/tools/tools/ath/athprom/eeprom-3 (contents, props changed) head/tools/tools/ath/athprom/eeprom-4 (contents, props changed) head/tools/tools/ath/athprom/eeprom-5 (contents, props changed) head/tools/tools/ath/athregs/ head/tools/tools/ath/athregs/Makefile (contents, props changed) head/tools/tools/ath/athregs/dumpregs.c (contents, props changed) head/tools/tools/ath/athregs/dumpregs.h (contents, props changed) head/tools/tools/ath/athregs/dumpregs_5210.c (contents, props changed) head/tools/tools/ath/athregs/dumpregs_5211.c (contents, props changed) head/tools/tools/ath/athregs/dumpregs_5212.c (contents, props changed) head/tools/tools/ath/athregs/dumpregs_5416.c (contents, props changed) head/tools/tools/ath/common/ head/tools/tools/ath/common/ah_osdep.h (contents, props changed) head/tools/tools/ath/common/diag.h (contents, props changed) Modified: head/tools/tools/ath/Makefile head/tools/tools/ath/athdebug/Makefile head/tools/tools/ath/athstats/Makefile Modified: head/tools/tools/ath/Makefile ============================================================================== --- head/tools/tools/ath/Makefile Sun Dec 7 18:45:30 2008 (r185742) +++ head/tools/tools/ath/Makefile Sun Dec 7 19:17:33 2008 (r185743) @@ -1,5 +1,5 @@ # $FreeBSD$ -SUBDIR= athstats athdebug +SUBDIR= athdebug athkey athprom athregs athstats .include Added: head/tools/tools/ath/Makefile.inc ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/tools/ath/Makefile.inc Sun Dec 7 19:17:33 2008 (r185743) @@ -0,0 +1,11 @@ +# $FreeBSD$ + +BINDIR= /usr/local/bin +NO_MAN= + +ATH_DEFAULT= ath0 + +CFLAGS+=-DATH_DEFAULT='"${ATH_DEFAULT}"' +CFLAGS+=-I../common +CFLAGS+=-I../../../../sys/dev/ath +CFLAGS+=-I../../../../sys/dev/ath/ath_hal Modified: head/tools/tools/ath/athdebug/Makefile ============================================================================== --- head/tools/tools/ath/athdebug/Makefile Sun Dec 7 18:45:30 2008 (r185742) +++ head/tools/tools/ath/athdebug/Makefile Sun Dec 7 19:17:33 2008 (r185743) @@ -1,7 +1,7 @@ # $FreeBSD$ PROG= athdebug -BINDIR= /usr/local/bin -NO_MAN= + +.include <../Makefile.inc> .include Added: head/tools/tools/ath/athkey/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/tools/ath/athkey/Makefile Sun Dec 7 19:17:33 2008 (r185743) @@ -0,0 +1,7 @@ +# $FreeBSD$ + +PROG= athkey + +.include <../Makefile.inc> + +.include Added: head/tools/tools/ath/athkey/athkey.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/tools/ath/athkey/athkey.c Sun Dec 7 19:17:33 2008 (r185743) @@ -0,0 +1,203 @@ +/*- + * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any + * redistribution must be conditioned upon including a substantially + * similar Disclaimer requirement for further binary redistribution. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. + * + * $FreeBSD$ + */ + +#include "diag.h" + +#include "ah.h" +#include "ah_internal.h" + +#include +#include +#include +#include +#include + +const char *progname; + +static int +toint(int c) +{ + return isdigit(c) ? c - '0' : isupper(c) ? c - 'A' + 10 : c - 'a' + 10; +} + +static int +getdata(const char *arg, u_int8_t *data, size_t maxlen) +{ + const char *cp = arg; + int len; + + if (cp[0] == '0' && (cp[1] == 'x' || cp[1] == 'X')) + cp += 2; + len = 0; + while (*cp) { + int b0, b1; + if (cp[0] == ':' || cp[0] == '-' || cp[0] == '.') { + cp++; + continue; + } + if (!isxdigit(cp[0])) { + fprintf(stderr, "%s: invalid data value %c (not hex)\n", + progname, cp[0]); + exit(-1); + } + b0 = toint(cp[0]); + if (cp[1] != '\0') { + if (!isxdigit(cp[1])) { + fprintf(stderr, "%s: invalid data value %c " + "(not hex)\n", progname, cp[1]); + exit(-1); + } + b1 = toint(cp[1]); + cp += 2; + } else { /* fake up 0 */ + b1 = b0, b0 = 0; + cp += 1; + } + if (len > maxlen) { + fprintf(stderr, + "%s: too much data in %s, max %u bytes\n", + progname, arg, maxlen); + } + data[len++] = (b0<<4) | b1; + } + return len; +} + +/* XXX this assumes 5212 key types are common to 5211 and 5210 */ + +static int +getcipher(const char *name) +{ +#define streq(a,b) (strcasecmp(a,b) == 0) + + if (streq(name, "wep")) + return HAL_CIPHER_WEP; + if (streq(name, "tkip")) + return HAL_CIPHER_TKIP; + if (streq(name, "aes-ocb") || streq(name, "ocb")) + return HAL_CIPHER_AES_OCB; + if (streq(name, "aes-ccm") || streq(name, "ccm") || + streq(name, "aes")) + return HAL_CIPHER_AES_CCM; + if (streq(name, "ckip")) + return HAL_CIPHER_CKIP; + if (streq(name, "none") || streq(name, "clr")) + return HAL_CIPHER_CLR; + + fprintf(stderr, "%s: unknown cipher %s\n", progname, name); + exit(-1); +#undef streq +} + +static void +usage(void) +{ + fprintf(stderr, "usage: %s [-i device] keyix cipher keyval [mac]\n", + progname); + exit(-1); +} + +int +main(int argc, char *argv[]) +{ + const char *ifname; + struct ath_diag atd; + HAL_DIAG_KEYVAL setkey; + const char *cp; + int s, c; + u_int16_t keyix; + int op = HAL_DIAG_SETKEY; + int xor = 0; + + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s < 0) + err(1, "socket"); + ifname = getenv("ATH"); + if (!ifname) + ifname = ATH_DEFAULT; + + progname = argv[0]; + while ((c = getopt(argc, argv, "di:x")) != -1) + switch (c) { + case 'd': + op = HAL_DIAG_RESETKEY; + break; + case 'i': + ifname = optarg; + break; + case 'x': + xor = 1; + break; + default: + usage(); + /*NOTREACHED*/ + } + argc -= optind; + argv += optind; + if (argc < 1) + usage(); + + keyix = (u_int16_t) atoi(argv[0]); + if (keyix > 127) + errx(-1, "%s: invalid key index %s, must be [0..127]", + progname, argv[0]); + strncpy(atd.ad_name, ifname, sizeof (atd.ad_name)); + atd.ad_id = op | ATH_DIAG_IN | ATH_DIAG_DYN; + atd.ad_out_data = NULL; + atd.ad_out_size = 0; + switch (op) { + case HAL_DIAG_RESETKEY: + atd.ad_in_data = (caddr_t) &keyix; + atd.ad_in_size = sizeof(u_int16_t); + if (ioctl(s, SIOCGATHDIAG, &atd) < 0) + err(1, atd.ad_name); + return 0; + case HAL_DIAG_SETKEY: + if (argc != 3 && argc != 4) + usage(); + memset(&setkey, 0, sizeof(setkey)); + setkey.dk_keyix = keyix; + setkey.dk_xor = xor; + setkey.dk_keyval.kv_type = getcipher(argv[1]); + setkey.dk_keyval.kv_len = getdata(argv[2], + setkey.dk_keyval.kv_val, sizeof(setkey.dk_keyval.kv_val)); + /* XXX MIC */ + if (argc == 4) + (void) getdata(argv[3], setkey.dk_mac, + IEEE80211_ADDR_LEN); + atd.ad_in_data = (caddr_t) &setkey; + atd.ad_in_size = sizeof(setkey); + if (ioctl(s, SIOCGATHDIAG, &atd) < 0) + err(1, atd.ad_name); + return 0; + } + return -1; +} Added: head/tools/tools/ath/athpow/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/tools/ath/athpow/Makefile Sun Dec 7 19:17:33 2008 (r185743) @@ -0,0 +1,7 @@ +# $FreeBSD$ + +PROG= athpow + +.include <../Makefile.inc> + +.include Added: head/tools/tools/ath/athpow/athpow.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/tools/ath/athpow/athpow.c Sun Dec 7 19:17:33 2008 (r185743) @@ -0,0 +1,198 @@ +/*- + * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any + * redistribution must be conditioned upon including a substantially + * similar Disclaimer requirement for further binary redistribution. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. + * + * $FreeBSD$ + */ +#include "diag.h" + +#include +#include +#include + +#include "ah.h" +#include "ah_internal.h" +#include "ah_eeprom.h" +#include "ah_eeprom_v1.h" +#include "ah_eeprom_v3.h" +#include "ah_eeprom_v14.h" +#include "ar5212/ar5212reg.h" +#define IS_5112(ah) \ + (((ah)->ah_analog5GhzRev&0xf0) >= AR_RAD5112_SREV_MAJOR \ + && ((ah)->ah_analog5GhzRev&0xf0) < AR_RAD2316_SREV_MAJOR ) +#define IS_2316(ah) \ + ((ah)->ah_macVersion == AR_SREV_2415) +#define IS_2413(ah) \ + ((ah)->ah_macVersion == AR_SREV_2413 || IS_2316(ah)) +#define IS_5424(ah) \ + ((ah)->ah_macVersion == AR_SREV_5424 || \ + ((ah)->ah_macVersion == AR_SREV_5413 && \ + (ah)->ah_macRev <= AR_SREV_D2PLUS_MS)) +#define IS_5413(ah) \ + ((ah)->ah_macVersion == AR_SREV_5413 || IS_5424(ah)) + +#ifndef MAX +#define MAX(a,b) ((a) > (b) ? (a) : (b)) +#endif + +static void printPcdacTable(FILE *fd, u_int16_t pcdac[], u_int n); +static void printPowerPerRate(FILE *fd, u_int16_t ratesArray[], u_int n); +static void printRevs(FILE *fd, const HAL_REVS *revs); + +static void +usage(const char *progname) +{ + fprintf(stderr, "usage: %s [-v] [-i dev]\n", progname); + exit(1); +} + +int +main(int argc, char *argv[]) +{ + int s, i, verbose = 0, c; + struct ath_diag atd; + const char *ifname; + HAL_REVS revs; + u_int16_t pcdacTable[MAX(PWR_TABLE_SIZE,PWR_TABLE_SIZE_2413)]; + u_int16_t ratesArray[16]; + u_int nrates, npcdac; + + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s < 0) + err(1, "socket"); + ifname = getenv("ATH"); + if (!ifname) + ifname = ATH_DEFAULT; + while ((c = getopt(argc, argv, "i:v")) != -1) + switch (c) { + case 'i': + ifname = optarg; + break; + case 'v': + verbose++; + break; + default: + usage(argv[0]); + } + strncpy(atd.ad_name, ifname, sizeof (atd.ad_name)); + + atd.ad_id = HAL_DIAG_REVS; + atd.ad_out_data = (caddr_t) &revs; + atd.ad_out_size = sizeof(revs); + if (ioctl(s, SIOCGATHDIAG, &atd) < 0) + err(1, atd.ad_name); + + if (verbose) + printRevs(stdout, &revs); + + atd.ad_id = HAL_DIAG_TXRATES; + atd.ad_out_data = (caddr_t) ratesArray; + atd.ad_out_size = sizeof(ratesArray); + if (ioctl(s, SIOCGATHDIAG, &atd) < 0) + err(1, atd.ad_name); + nrates = sizeof(ratesArray) / sizeof(u_int16_t); + + atd.ad_id = HAL_DIAG_PCDAC; + atd.ad_out_data = (caddr_t) pcdacTable; + atd.ad_out_size = sizeof(pcdacTable); + if (ioctl(s, SIOCGATHDIAG, &atd) < 0) + err(1, atd.ad_name); + if (IS_2413(&revs) || IS_5413(&revs)) + npcdac = PWR_TABLE_SIZE_2413; + else + npcdac = PWR_TABLE_SIZE; + + printf("PCDAC table:\n"); + printPcdacTable(stdout, pcdacTable, npcdac); + + printf("Power per rate table:\n"); + printPowerPerRate(stdout, ratesArray, nrates); + + return 0; +} + +static void +printPcdacTable(FILE *fd, u_int16_t pcdac[], u_int n) +{ + int i, halfRates = n/2; + + for (i = 0; i < halfRates; i += 2) + fprintf(fd, "[%2u] %04x %04x [%2u] %04x %04x\n", + i, pcdac[2*i + 1], pcdac[2*i], + i+1, pcdac[2*(i+1) + 1], pcdac[2*(i+1)]); +} + +static void +printPowerPerRate(FILE *fd, u_int16_t ratesArray[], u_int n) +{ + const char *rateString[] = { + " 6mb OFDM", " 9mb OFDM", "12mb OFDM", "18mb OFDM", + "24mb OFDM", "36mb OFDM", "48mb OFDM", "54mb OFDM", + "1L CCK ", "2L CCK ", "2S CCK ", "5.5L CCK ", + "5.5S CCK ", "11L CCK ", "11S CCK ", "XR " + }; + int i, halfRates = n/2; + + for (i = 0; i < halfRates; i++) + fprintf(fd, " %s %3d.%1d dBm | %s %3d.%1d dBm\n", + rateString[i], ratesArray[i]/2, + (ratesArray[i] %2) * 5, + rateString[i + halfRates], + ratesArray[i + halfRates]/2, + (ratesArray[i + halfRates] %2) *5); +} + +static void +printRevs(FILE *fd, const HAL_REVS *revs) +{ + const char *rfbackend; + + fprintf(fd, "PCI device id 0x%x subvendor id 0x%x\n", + revs->ah_devid, revs->ah_subvendorid); + fprintf(fd, "mac %d.%d phy %d.%d" + , revs->ah_macVersion, revs->ah_macRev + , revs->ah_phyRev >> 4, revs->ah_phyRev & 0xf + ); + rfbackend = IS_5413(revs) ? "5413" : + IS_2413(revs) ? "2413" : + IS_5112(revs) ? "5112" : + "5111"; + if (revs->ah_analog5GhzRev && revs->ah_analog2GhzRev) + fprintf(fd, " 5ghz radio %d.%d 2ghz radio %d.%d (%s)\n" + , revs->ah_analog5GhzRev >> 4 + , revs->ah_analog5GhzRev & 0xf + , revs->ah_analog2GhzRev >> 4 + , revs->ah_analog2GhzRev & 0xf + , rfbackend + ); + else + fprintf(fd, " radio %d.%d (%s)\n" + , revs->ah_analog5GhzRev >> 4 + , revs->ah_analog5GhzRev & 0xf + , rfbackend + ); +} Added: head/tools/tools/ath/athprom/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/tools/ath/athprom/Makefile Sun Dec 7 19:17:33 2008 (r185743) @@ -0,0 +1,17 @@ +# $FreeBSD$ + +PROG= athprom + +.include <../Makefile.inc> + +TEMPLATEDIR= /usr/local/libdata/athprom +TEXTMODE?= 444 + +CFLAGS+=-DDIR_TEMPLATE='"${TEMPLATEDIR}"' + +beforeinstall: + mkdir -p ${DESTDIR}${TEMPLATEDIR} + ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${TEXTMODE} \ + ${.CURDIR}/eeprom-* ${DESTDIR}${TEMPLATEDIR}/ + +.include Added: head/tools/tools/ath/athprom/athprom.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/tools/ath/athprom/athprom.c Sun Dec 7 19:17:33 2008 (r185743) @@ -0,0 +1,978 @@ +/*- + * Copyright (c) 2008 Sam Leffler, Errno Consulting + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any + * redistribution must be conditioned upon including a substantially + * similar Disclaimer requirement for further binary redistribution. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. + * + * $FreeBSD$ + */ +#include "diag.h" + +#include "ah.h" +#include "ah_internal.h" +#include "ah_eeprom_v1.h" +#include "ah_eeprom_v3.h" +#include "ah_eeprom_v14.h" + +#define IS_VERS(op, v) (eeprom.ee_version op (v)) + +#include +#include +#include +#include +#include + +#ifndef DIR_TEMPLATE +#define DIR_TEMPLATE "/usr/local/libdata/athprom" +#endif + +struct ath_diag atd; +int s; +const char *progname; +union { + HAL_EEPROM legacy; /* format v3.x ... v5.x */ + struct ar5416eeprom v14; /* 11n format v14.x ... */ +} eep; +#define eeprom eep.legacy +#define eepromN eep.v14 + +static void parseTemplate(FILE *ftemplate, FILE *fd); +static uint16_t eeread(uint16_t); +static void eewrite(uint16_t, uint16_t); + +static void +usage() +{ + fprintf(stderr, "usage: %s [-i ifname] [-t pathname] [offset | offset=value]\n", progname); + exit(-1); +} + +static FILE * +opentemplate(const char *dir) +{ + char filename[PATH_MAX]; + FILE *fd; + + /* find the template using the eeprom version */ + snprintf(filename, sizeof(filename), "%s/eeprom-%d.%d", + dir, eeprom.ee_version >> 12, eeprom.ee_version & 0xfff); + fd = fopen(filename, "r"); + if (fd == NULL && errno == ENOENT) { + /* retry with just the major version */ + snprintf(filename, sizeof(filename), "%s/eeprom-%d", + dir, eeprom.ee_version >> 12); + fd = fopen(filename, "r"); + if (fd != NULL) /* XXX verbose */ + warnx("Using template file %s", filename); + } + return fd; +} + +int +main(int argc, char *argv[]) +{ + FILE *fd = NULL; + const char *ifname; + int c; + + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s < 0) + err(1, "socket"); + ifname = getenv("ATH"); + if (!ifname) + ifname = ATH_DEFAULT; + + progname = argv[0]; + while ((c = getopt(argc, argv, "i:t:")) != -1) + switch (c) { + case 'i': + ifname = optarg; + break; + case 't': + fd = fopen(optarg, "r"); + if (fd == NULL) + err(-1, "Cannot open %s", optarg); + break; + default: + usage(); + /*NOTREACHED*/ + } + argc -= optind; + argv += optind; + + strncpy(atd.ad_name, ifname, sizeof (atd.ad_name)); + + if (argc != 0) { + for (; argc > 0; argc--, argv++) { + uint16_t off, val, oval; + char line[256]; + char *cp; + + cp = strchr(argv[0], '='); + if (cp != NULL) + *cp = '\0'; + off = (uint16_t) strtoul(argv[0], NULL, 0); + if (off == 0 && errno == EINVAL) + errx(1, "%s: invalid eeprom offset %s", + progname, argv[0]); + if (cp == NULL) { + printf("%04x: %04x\n", off, eeread(off)); + } else { + val = (uint16_t) strtoul(cp+1, NULL, 0); + if (val == 0 && errno == EINVAL) + errx(1, "%s: invalid eeprom value %s", + progname, cp+1); + oval = eeread(off); + printf("Write %04x: %04x = %04x? ", + off, oval, val); + fflush(stdout); + if (fgets(line, sizeof(line), stdin) != NULL && + line[0] == 'y') + eewrite(off, val); + } + } + } else { + atd.ad_id = HAL_DIAG_EEPROM; + atd.ad_out_data = (caddr_t) &eep; + atd.ad_out_size = sizeof(eep); + if (ioctl(s, SIOCGATHDIAG, &atd) < 0) + err(1, atd.ad_name); + if (fd == NULL) { + fd = opentemplate(DIR_TEMPLATE); + if (fd == NULL) + fd = opentemplate("."); + if (fd == NULL) + errx(-1, "Cannot locate template file for " + "v%d.%d EEPROM", eeprom.ee_version >> 12, + eeprom.ee_version & 0xfff); + } + parseTemplate(fd, stdout); + fclose(fd); + } + return 0; +} + +static u_int16_t +eeread(u_int16_t off) +{ + u_int16_t eedata; + + atd.ad_id = HAL_DIAG_EEREAD | ATH_DIAG_IN | ATH_DIAG_DYN; + atd.ad_in_size = sizeof(off); + atd.ad_in_data = (caddr_t) &off; + atd.ad_out_size = sizeof(eedata); + atd.ad_out_data = (caddr_t) &eedata; + if (ioctl(s, SIOCGATHDIAG, &atd) < 0) + err(1, atd.ad_name); + return eedata; +} + +static void +eewrite(uint16_t off, uint16_t value) +{ + HAL_DIAG_EEVAL eeval; + + eeval.ee_off = off; + eeval.ee_data = value; + + atd.ad_id = HAL_DIAG_EEWRITE | ATH_DIAG_IN; + atd.ad_in_size = sizeof(eeval); + atd.ad_in_data = (caddr_t) &eeval; + atd.ad_out_size = 0; + atd.ad_out_data = NULL; + if (ioctl(s, SIOCGATHDIAG, &atd) < 0) + err(1, atd.ad_name); +} + +#define MAXID 128 +int lineno; +int bol; +int curmode = -1; +int curchan; +int curpdgain; /* raw pdgain index */ +int curlpdgain; /* logical pdgain index */ +int curpcdac; +int curctl; +int numChannels; +const RAW_DATA_STRUCT_2413 *pRaw; +const TRGT_POWER_INFO *pPowerInfo; +const DATA_PER_CHANNEL *pDataPerChannel; +const EEPROM_POWER_EXPN_5112 *pExpnPower; +int singleXpd; + +static int +token(FILE *fd, char id[], int maxid, const char *what) +{ + int c, i; + + i = 0; + for (;;) { + c = getc(fd); + if (c == EOF) + return EOF; + if (!isalnum(c) && c != '_') { + ungetc(c, fd); + break; + } + if (i == maxid-1) { + warnx("line %d, %s too long", lineno, what); + break; + } + id[i++] = c; + } + id[i] = '\0'; + if (i != 0) + bol = 0; + return i; +} + +static int +skipto(FILE *fd, const char *what) +{ + char id[MAXID]; + int c; + + for (;;) { + c = getc(fd); + if (c == EOF) + goto bad; + if (c == '.' && bol) { /* .directive */ + if (token(fd, id, MAXID, ".directive") == EOF) + goto bad; + if (strcasecmp(id, what) == 0) + break; + continue; + } + if (c == '\\') { /* escape next character */ + c = getc(fd); + if (c == EOF) + goto bad; + } + bol = (c == '\n'); + if (bol) + lineno++; + } + return 0; +bad: + warnx("EOF with no matching .%s", what); + return EOF; +} + +static int +skipws(FILE *fd) +{ + int c, i; + + i = 0; + while ((c = getc(fd)) != EOF && isblank(c)) + i++; + if (c != EOF) + ungetc(c, fd); + if (i != 0) + bol = 0; + return 0; +} + +static void +setmode(int mode) +{ + EEPROM_POWER_EXPN_5112 *exp; + + curmode = mode; + curchan = -1; + curctl = -1; + curpdgain = -1; + curlpdgain = -1; + curpcdac = -1; + switch (curmode) { + case headerInfo11A: + pPowerInfo = eeprom.ee_trgtPwr_11a; + pDataPerChannel = eeprom.ee_dataPerChannel11a; + break; + case headerInfo11B: + pPowerInfo = eeprom.ee_trgtPwr_11b; + pDataPerChannel = eeprom.ee_dataPerChannel11b; + break; + case headerInfo11G: + pPowerInfo = eeprom.ee_trgtPwr_11g; + pDataPerChannel = eeprom.ee_dataPerChannel11g; + break; + } + if (IS_VERS(<, AR_EEPROM_VER4_0)) /* nothing to do */ + return; + if (IS_VERS(<, AR_EEPROM_VER5_0)) { + exp = &eeprom.ee_modePowerArray5112[curmode]; + /* fetch indirect data*/ + atd.ad_id = HAL_DIAG_EEPROM_EXP_11A+curmode; + atd.ad_out_size = roundup( + sizeof(u_int16_t) * exp->numChannels, sizeof(u_int32_t)) + + sizeof(EXPN_DATA_PER_CHANNEL_5112) * exp->numChannels; + atd.ad_out_data = (caddr_t) malloc(atd.ad_out_size); + if (ioctl(s, SIOCGATHDIAG, &atd) < 0) + err(1, atd.ad_name); + exp->pChannels = (void *) atd.ad_out_data; + exp->pDataPerChannel = (void *)((char *)atd.ad_out_data + + roundup(sizeof(u_int16_t) * exp->numChannels, sizeof(u_int32_t))); + pExpnPower = exp; + numChannels = pExpnPower->numChannels; + if (exp->xpdMask != 0x9) { + for (singleXpd = 0; singleXpd < NUM_XPD_PER_CHANNEL; singleXpd++) + if (exp->xpdMask == (1<numChannels; + } +} + +int +nextctl(int start) +{ + int i; + + for (i = start; i < eeprom.ee_numCtls && eeprom.ee_ctl[i]; i++) { + switch (eeprom.ee_ctl[i] & 3) { + case 0: case 3: + if (curmode != headerInfo11A) + continue; + break; + case 1: + if (curmode != headerInfo11B) + continue; + break; + case 2: + if (curmode != headerInfo11G) + continue; + break; + } + return i; + } + return -1; +} + +static void +printAntennaControl(FILE *fd, int ant) +{ + fprintf(fd, "0x%02X", eeprom.ee_antennaControl[ant][curmode]); +} + +static void +printEdge(FILE *fd, int edge) +{ + const RD_EDGES_POWER *pRdEdgePwrInfo = + &eeprom.ee_rdEdgesPower[curctl*NUM_EDGES]; + + if (pRdEdgePwrInfo[edge].rdEdge == 0) + fprintf(fd, " -- "); + else + fprintf(fd, "%04d", pRdEdgePwrInfo[edge].rdEdge); +} + +static void +printEdgePower(FILE *fd, int edge) +{ + const RD_EDGES_POWER *pRdEdgePwrInfo = + &eeprom.ee_rdEdgesPower[curctl*NUM_EDGES]; + + if (pRdEdgePwrInfo[edge].rdEdge == 0) + fprintf(fd, " -- "); + else + fprintf(fd, "%2d.%d", + pRdEdgePwrInfo[edge].twice_rdEdgePower / 2, + (pRdEdgePwrInfo[edge].twice_rdEdgePower % 2) * 5); +} + +static void +printEdgeFlag(FILE *fd, int edge) +{ + const RD_EDGES_POWER *pRdEdgePwrInfo = + &eeprom.ee_rdEdgesPower[curctl*NUM_EDGES]; + + if (pRdEdgePwrInfo[edge].rdEdge == 0) + fprintf(fd, "--"); + else + fprintf(fd, " %1d", pRdEdgePwrInfo[edge].flag); +} + +static int16_t +getMaxPowerV5(const RAW_DATA_PER_CHANNEL_2413 *data) +{ + uint32_t i; + uint16_t numVpd; + + for (i = 0; i < MAX_NUM_PDGAINS_PER_CHANNEL; i++) { + numVpd = data->pDataPerPDGain[i].numVpd; + if (numVpd > 0) + return data->pDataPerPDGain[i].pwr_t4[numVpd-1]; + } + return 0; +} + +static void +printQuarterDbmPower(FILE *fd, int16_t power25dBm) +{ + fprintf(fd, "%2d.%02d", power25dBm / 4, (power25dBm % 4) * 25); +} + +static void +printHalfDbmPower(FILE *fd, int16_t power5dBm) +{ + fprintf(fd, "%2d.%d", power5dBm / 2, (power5dBm % 2) * 5); +} + +static void +printVpd(FILE *fd, int vpd) +{ + fprintf(fd, "[%3d]", vpd); +} + +static void +printPcdacValue(FILE *fd, int v) +{ + fprintf(fd, "%2d.%02d", v / EEP_SCALE, v % EEP_SCALE); +} + +static void +undef(const char *what) +{ + warnx("%s undefined for version %d.%d format EEPROM", what, + eeprom.ee_version >> 12, eeprom.ee_version & 0xfff); +} + +static int +pdgain(int lpdgain) +{ + uint32_t mask; + int i, l = lpdgain; + + if (IS_VERS(<, AR_EEPROM_VER5_0)) + mask = pExpnPower->xpdMask; + else + mask = pRaw->xpd_mask; + for (i = 0; mask != 0; mask >>= 1, i++) + if ((mask & 1) && l-- == 0) + return i; + warnx("can't find logical pdgain %d", lpdgain); + return -1; +} + +#define COUNTRY_ERD_FLAG 0x8000 +#define WORLDWIDE_ROAMING_FLAG 0x4000 + +void +eevar(FILE *fd, const char *var) +{ +#define streq(a,b) (strcasecmp(a,b) == 0) +#define strneq(a,b,n) (strncasecmp(a,b,n) == 0) + if (streq(var, "mode")) { + fprintf(fd, "%s", + curmode == headerInfo11A ? "11a" : + curmode == headerInfo11B ? "11b" : + curmode == headerInfo11G ? "11g" : "???"); + } else if (streq(var, "version")) { + fprintf(fd, "%04x", eeprom.ee_version); + } else if (streq(var, "V_major")) { + fprintf(fd, "%2d", eeprom.ee_version >> 12); + } else if (streq(var, "V_minor")) { + fprintf(fd, "%2d", eeprom.ee_version & 0xfff); + } else if (streq(var, "earStart")) { + fprintf(fd, "%03x", eeprom.ee_earStart); + } else if (streq(var, "tpStart")) { + fprintf(fd, "%03x", eeprom.ee_targetPowersStart); + } else if (streq(var, "eepMap")) { + fprintf(fd, "%3d", eeprom.ee_eepMap); + } else if (streq(var, "exist32KHzCrystal")) { + fprintf(fd, "%3d", eeprom.ee_exist32kHzCrystal); + } else if (streq(var, "eepMap2PowerCalStart")) { + fprintf(fd , "%3d", eeprom.ee_eepMap2PowerCalStart); + } else if (streq(var, "Amode")) { + fprintf(fd , "%1d", eeprom.ee_Amode); + } else if (streq(var, "Bmode")) { + fprintf(fd , "%1d", eeprom.ee_Bmode); *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From sam at FreeBSD.org Sun Dec 7 11:26:34 2008 From: sam at FreeBSD.org (Sam Leffler) Date: Sun Dec 7 11:26:41 2008 Subject: svn commit: r185744 - head/sys/dev/ath Message-ID: <200812071926.mB7JQYud033765@svn.freebsd.org> Author: sam Date: Sun Dec 7 19:26:34 2008 New Revision: 185744 URL: http://svn.freebsd.org/changeset/base/185744 Log: New periodic calibration scheme needed for 11n parts that have multiple algorithms and potentially collect multiple samples. Instead of a single calibration interval we now have short and long intervals; the long interval roughly corresponds to the previous single interval. The short interval is used to speedup collection of samples and happens much quicker. We make calls using the short interval until we're told the calibration work is complete at which point we fallback to the long interval. In addition there is a much longer reset interval used to flush all calibration state and cause everthing to start anew. With these changes you can also disable calibration entirely by setting the long interval to zero. Modified: head/sys/dev/ath/if_ath.c head/sys/dev/ath/if_athvar.h Modified: head/sys/dev/ath/if_ath.c ============================================================================== --- head/sys/dev/ath/if_ath.c Sun Dec 7 19:17:33 2008 (r185743) +++ head/sys/dev/ath/if_ath.c Sun Dec 7 19:26:34 2008 (r185744) @@ -219,9 +219,15 @@ static void ath_announce(struct ath_soft SYSCTL_DECL(_hw_ath); /* XXX validate sysctl values */ -static int ath_calinterval = 30; /* calibrate every 30 secs */ -SYSCTL_INT(_hw_ath, OID_AUTO, calibrate, CTLFLAG_RW, &ath_calinterval, - 0, "chip calibration interval (secs)"); +static int ath_longcalinterval = 30; /* long cals every 30 secs */ +SYSCTL_INT(_hw_ath, OID_AUTO, longcal, CTLFLAG_RW, &ath_longcalinterval, + 0, "long chip calibration interval (secs)"); +static int ath_shortcalinterval = 100; /* short cals every 100 ms */ +SYSCTL_INT(_hw_ath, OID_AUTO, shortcal, CTLFLAG_RW, &ath_shortcalinterval, + 0, "short chip calibration interval (msecs)"); +static int ath_resetcalinterval = 20*60; /* reset cal state 20 mins */ +SYSCTL_INT(_hw_ath, OID_AUTO, resetcal, CTLFLAG_RW, &ath_resetcalinterval, + 0, "reset chip calibration results (secs)"); static int ath_rxbuf = ATH_RXBUF; /* # rx buffers to allocate */ SYSCTL_INT(_hw_ath, OID_AUTO, rxbuf, CTLFLAG_RW, &ath_rxbuf, @@ -1433,8 +1439,9 @@ ath_init(void *arg) * state cached in the driver. */ sc->sc_diversity = ath_hal_getdiversity(ah); - sc->sc_calinterval = 1; - sc->sc_caltries = 0; + sc->sc_lastlongcal = 0; + sc->sc_resetcal = 1; + sc->sc_lastcalreset = 0; /* * Setup the hardware after reset: the key cache @@ -1566,8 +1573,6 @@ ath_reset(struct ifnet *ifp) if_printf(ifp, "%s: unable to reset hardware; hal status %u\n", __func__, status); sc->sc_diversity = ath_hal_getdiversity(ah); - sc->sc_calinterval = 1; - sc->sc_caltries = 0; if (ath_startrecv(sc) != 0) /* restart recv */ if_printf(ifp, "%s: unable to start recv logic\n", __func__); /* @@ -5493,8 +5498,6 @@ ath_chan_set(struct ath_softc *sc, struc } sc->sc_curchan = hchan; sc->sc_diversity = ath_hal_getdiversity(ah); - sc->sc_calinterval = 1; - sc->sc_caltries = 0; /* * Re-enable rx framework. @@ -5528,54 +5531,76 @@ ath_calibrate(void *arg) { struct ath_softc *sc = arg; struct ath_hal *ah = sc->sc_ah; - HAL_BOOL iqCalDone; - - sc->sc_stats.ast_per_cal++; + struct ifnet *ifp = sc->sc_ifp; + HAL_BOOL longCal, isCalDone; + int nextcal; - if (ath_hal_getrfgain(ah) == HAL_RFGAIN_NEED_CHANGE) { + longCal = (ticks - sc->sc_lastlongcal >= ath_longcalinterval*hz); + if (longCal) { + sc->sc_stats.ast_per_cal++; + if (ath_hal_getrfgain(ah) == HAL_RFGAIN_NEED_CHANGE) { + /* + * Rfgain is out of bounds, reset the chip + * to load new gain values. + */ + DPRINTF(sc, ATH_DEBUG_CALIBRATE, + "%s: rfgain change\n", __func__); + sc->sc_stats.ast_per_rfgain++; + ath_reset(ifp); + } /* - * Rfgain is out of bounds, reset the chip - * to load new gain values. + * If this long cal is after an idle period, then + * reset the data collection state so we start fresh. */ - DPRINTF(sc, ATH_DEBUG_CALIBRATE, - "%s: rfgain change\n", __func__); - sc->sc_stats.ast_per_rfgain++; - ath_reset(sc->sc_ifp); + if (sc->sc_resetcal) { + (void) ath_hal_calreset(ah, &sc->sc_curchan); + sc->sc_lastcalreset = ticks; + sc->sc_resetcal = 0; + } } - if (!ath_hal_calibrate(ah, &sc->sc_curchan, &iqCalDone)) { + if (ath_hal_calibrateN(ah, &sc->sc_curchan, longCal, &isCalDone)) { + if (longCal) { + /* + * Calibrate noise floor data again in case of change. + */ + ath_hal_process_noisefloor(ah); + } + } else { DPRINTF(sc, ATH_DEBUG_ANY, "%s: calibration of channel %u failed\n", __func__, sc->sc_curchan.channel); sc->sc_stats.ast_per_calfail++; } - /* - * Calibrate noise floor data again in case of change. - */ - ath_hal_process_noisefloor(ah); - /* - * Poll more frequently when the IQ calibration is in - * progress to speedup loading the final settings. - * We temper this aggressive polling with an exponential - * back off after 4 tries up to ath_calinterval. - */ - if (iqCalDone || sc->sc_calinterval >= ath_calinterval) { - sc->sc_caltries = 0; - sc->sc_calinterval = ath_calinterval; - } else if (sc->sc_caltries > 4) { - sc->sc_caltries = 0; - sc->sc_calinterval <<= 1; - if (sc->sc_calinterval > ath_calinterval) - sc->sc_calinterval = ath_calinterval; - } - KASSERT(0 < sc->sc_calinterval && sc->sc_calinterval <= ath_calinterval, - ("bad calibration interval %u", sc->sc_calinterval)); - - DPRINTF(sc, ATH_DEBUG_CALIBRATE, - "%s: next +%u (%siqCalDone tries %u)\n", __func__, - sc->sc_calinterval, iqCalDone ? "" : "!", sc->sc_caltries); - sc->sc_caltries++; - callout_reset(&sc->sc_cal_ch, sc->sc_calinterval * hz, - ath_calibrate, sc); + if (!isCalDone) { + /* + * Use a shorter interval to potentially collect multiple + * data samples required to complete calibration. Once + * we're told the work is done we drop back to a longer + * interval between requests. We're more aggressive doing + * work when operating as an AP to improve operation right + * after startup. + */ + nextcal = (1000*ath_shortcalinterval)/hz; + if (sc->sc_opmode != HAL_M_HOSTAP) + nextcal *= 10; + } else { + nextcal = ath_longcalinterval*hz; + sc->sc_lastlongcal = ticks; + if (sc->sc_lastcalreset == 0) + sc->sc_lastcalreset = sc->sc_lastlongcal; + else if (ticks - sc->sc_lastcalreset >= ath_resetcalinterval*hz) + sc->sc_resetcal = 1; /* setup reset next trip */ + } + + if (nextcal != 0) { + DPRINTF(sc, ATH_DEBUG_CALIBRATE, "%s: next +%u (%sisCalDone)\n", + __func__, nextcal, isCalDone ? "" : "!"); + callout_reset(&sc->sc_cal_ch, nextcal, ath_calibrate, sc); + } else { + DPRINTF(sc, ATH_DEBUG_CALIBRATE, "%s: calibration disabled\n", + __func__); + /* NB: don't rearm timer */ + } } static void @@ -5803,10 +5828,12 @@ ath_newstate(struct ieee80211vap *vap, e * Finally, start any timers and the task q thread * (in case we didn't go through SCAN state). */ - if (sc->sc_calinterval != 0) { + if (ath_longcalinterval != 0) { /* start periodic recalibration timer */ - callout_reset(&sc->sc_cal_ch, sc->sc_calinterval * hz, - ath_calibrate, sc); + callout_reset(&sc->sc_cal_ch, 1, ath_calibrate, sc); + } else { + DPRINTF(sc, ATH_DEBUG_CALIBRATE, + "%s: calibration disabled\n", __func__); } taskqueue_unblock(sc->sc_tq); } else if (nstate == IEEE80211_S_INIT) { Modified: head/sys/dev/ath/if_athvar.h ============================================================================== --- head/sys/dev/ath/if_athvar.h Sun Dec 7 19:17:33 2008 (r185743) +++ head/sys/dev/ath/if_athvar.h Sun Dec 7 19:26:34 2008 (r185744) @@ -248,7 +248,8 @@ struct ath_softc { sc_swbmiss : 1,/* sta mode using sw bmiss */ sc_stagbeacons:1,/* use staggered beacons */ sc_wmetkipmic:1,/* can do WME+TKIP MIC */ - sc_resume_up: 1;/* on resume, start all vaps */ + sc_resume_up: 1,/* on resume, start all vaps */ + sc_resetcal : 1;/* reset cal state next trip */ uint32_t sc_eerd; /* regdomain from EEPROM */ uint32_t sc_eecc; /* country code from EEPROM */ /* rate tables */ @@ -334,8 +335,8 @@ struct ath_softc { int sc_nbcnvaps; /* # vaps with beacons */ struct callout sc_cal_ch; /* callout handle for cals */ - int sc_calinterval; /* current polling interval */ - int sc_caltries; /* cals at current interval */ + int sc_lastlongcal; /* last long cal completed */ + int sc_lastcalreset;/* last cal reset done */ HAL_NODE_STATS sc_halstats; /* station-mode rssi stats */ }; @@ -438,6 +439,16 @@ void ath_intr(void *); ((*(_ah)->ah_setChannel)((_ah), (_chan))) #define ath_hal_calibrate(_ah, _chan, _iqcal) \ ((*(_ah)->ah_perCalibration)((_ah), (_chan), (_iqcal))) +#if HAL_ABI_VERSION >= 0x08111000 +#define ath_hal_calibrateN(_ah, _chan, _lcal, _isdone) \ + ((*(_ah)->ah_perCalibrationN)((_ah), (_chan), 0x1, (_lcal), (_isdone))) +#define ath_hal_calreset(_ah, _chan) \ + ((*(_ah)->ah_resetCalValid)((_ah), (_chan))) +#else +#define ath_hal_calibrateN(_ah, _chan, _lcal, _isdone) \ + ath_hal_calibrate(_ah, _chan, _isdone) +#define ath_hal_calreset(_ah, _chan) (0) +#endif #define ath_hal_setledstate(_ah, _state) \ ((*(_ah)->ah_setLedState)((_ah), (_state))) #define ath_hal_beaconinit(_ah, _nextb, _bperiod) \ From sam at FreeBSD.org Sun Dec 7 11:29:12 2008 From: sam at FreeBSD.org (Sam Leffler) Date: Sun Dec 7 11:29:24 2008 Subject: svn commit: r185745 - head/sys/dev/ath Message-ID: <200812071929.mB7JTCjB033855@svn.freebsd.org> Author: sam Date: Sun Dec 7 19:29:11 2008 New Revision: 185745 URL: http://svn.freebsd.org/changeset/base/185745 Log: honor IEEE80211_BPF_CRYPTO for raw xmit; fixes shared key auth in sta mode PR: kern/129022 Modified: head/sys/dev/ath/if_ath.c Modified: head/sys/dev/ath/if_ath.c ============================================================================== --- head/sys/dev/ath/if_ath.c Sun Dec 7 19:26:34 2008 (r185744) +++ head/sys/dev/ath/if_ath.c Sun Dec 7 19:29:11 2008 (r185745) @@ -6912,7 +6912,7 @@ ath_tx_raw_start(struct ath_softc *sc, s struct ieee80211com *ic = ifp->if_l2com; struct ath_hal *ah = sc->sc_ah; int error, ismcast, ismrr; - int hdrlen, pktlen, try0, txantenna; + int keyix, hdrlen, pktlen, try0, txantenna; u_int8_t rix, cix, txrate, ctsrate, rate1, rate2, rate3; struct ieee80211_frame *wh; u_int flags, ctsduration; @@ -6931,6 +6931,54 @@ ath_tx_raw_start(struct ath_softc *sc, s /* XXX honor IEEE80211_BPF_DATAPAD */ pktlen = m0->m_pkthdr.len - (hdrlen & 3) + IEEE80211_CRC_LEN; + if (params->ibp_flags & IEEE80211_BPF_CRYPTO) { + const struct ieee80211_cipher *cip; + struct ieee80211_key *k; + + /* + * Construct the 802.11 header+trailer for an encrypted + * frame. The only reason this can fail is because of an + * unknown or unsupported cipher/key type. + */ + k = ieee80211_crypto_encap(ni, m0); + if (k == NULL) { + /* + * This can happen when the key is yanked after the + * frame was queued. Just discard the frame; the + * 802.11 layer counts failures and provides + * debugging/diagnostics. + */ + ath_freetx(m0); + return EIO; + } + /* + * Adjust the packet + header lengths for the crypto + * additions and calculate the h/w key index. When + * a s/w mic is done the frame will have had any mic + * added to it prior to entry so m0->m_pkthdr.len will + * account for it. Otherwise we need to add it to the + * packet length. + */ + cip = k->wk_cipher; + hdrlen += cip->ic_header; + pktlen += cip->ic_header + cip->ic_trailer; + /* NB: frags always have any TKIP MIC done in s/w */ + if ((k->wk_flags & IEEE80211_KEY_SWMIC) == 0) + pktlen += cip->ic_miclen; + keyix = k->wk_keyix; + + /* packet header may have moved, reset our local pointer */ + wh = mtod(m0, struct ieee80211_frame *); + } else if (ni->ni_ucastkey.wk_cipher == &ieee80211_cipher_none) { + /* + * Use station key cache slot, if assigned. + */ + keyix = ni->ni_ucastkey.wk_keyix; + if (keyix == IEEE80211_KEYIX_NONE) + keyix = HAL_TXKEYIX_INVALID; + } else + keyix = HAL_TXKEYIX_INVALID; + error = ath_tx_dmasetup(sc, bf, m0); if (error != 0) return error; @@ -7019,7 +7067,7 @@ ath_tx_raw_start(struct ath_softc *sc, s , atype /* Atheros packet type */ , params->ibp_power /* txpower */ , txrate, try0 /* series 0 rate/tries */ - , HAL_TXKEYIX_INVALID /* key cache index */ + , keyix /* key cache index */ , txantenna /* antenna mode */ , flags /* flags */ , ctsrate /* rts/cts rate */ From luigi at FreeBSD.org Sun Dec 7 11:42:20 2008 From: luigi at FreeBSD.org (Luigi Rizzo) Date: Sun Dec 7 11:42:29 2008 Subject: svn commit: r185746 - head/sys/boot/forth Message-ID: <200812071942.mB7JgK94034137@svn.freebsd.org> Author: luigi Date: Sun Dec 7 19:42:20 2008 New Revision: 185746 URL: http://svn.freebsd.org/changeset/base/185746 Log: PROBLEM: putting in a loader config file a line of the form loader_conf_files="foo bar baz" should cause loading the files listed, and then resume with the remaining config files (from previous values of the variable). Unfortunately, sometimes the line was ignored -- actually even modifying the line in /boot/default/loader.conf sometimes doesn't work. ANALYSIS: After much investigation, turned out to be a bug in the logic. The existing code detected a new assignment by looking at the address of the the variable containing the string. This only worked by pure chance, i.e. if the new string is longer than the previous value then the memory allocator may return a different address to store the string hence triggering the detection. SOLUTION: This commit contains a minimal change to fix the problem, without altering too much the existing structure of the code. However, as a step towards improving the quality and reliability of this code, I have introduced a handful of one-line functions (strget, strset, strfree, string= ) that could be used in dozens of places in the existing code. HOWEVER: There is a much bigger problem here. Even though I am no Forth expert (as most fellow src committers) I can tell that much of the forth code (in support.4th at least) is in severe need of a review/refactoring: + pieces of code are replicated multiple times instead of writing functions (see e.g. set_module_*); + a lot of stale code (e.g. "structure" definitions for preloaded_files, kernel_module, pnp stuff) which is not used or at least belongs elsewhere. The code bload is extremely bad as the loader runs with very small memory constraints, and we already hit the limit once (see http://svn.freebsd.org/viewvc/base?view=revision&revision=185132 Reducing the footprint of the forth files is critical. + two different styles of coding, one using pure stack functions (maybe beautiful but surely highly unreadable), one using high level mechanisms to give names to arguments and local variables (which leads to readable code). Note that this code is used by default by all FreeBSD installations, so the fragility and the code bloat are extremely damaging. I will try to work fixing the three items above, but if others have time, please have a look at these issues. MFC after: 4 weeks Modified: head/sys/boot/forth/support.4th Modified: head/sys/boot/forth/support.4th ============================================================================== --- head/sys/boot/forth/support.4th Sun Dec 7 19:29:11 2008 (r185745) +++ head/sys/boot/forth/support.4th Sun Dec 7 19:42:20 2008 (r185746) @@ -288,6 +288,17 @@ only forth also support-functions defini : free-memory free if free_error throw then ; +: strget { var -- addr len } var .addr @ var .len @ ; + +\ assign addr len to variable. +: strset { addr len var -- } addr var .addr ! len var .len ! ; + +\ free memory and reset fields +: strfree { var -- } var .addr @ ?dup if free-memory 0 0 var strset then ; + +\ free old content, make a copy of the string and assign to variable +: string= { addr len var -- } var strfree addr len strdup var strset ; + \ Assignment data temporary storage string name_buffer @@ -712,19 +723,6 @@ only forth also support-functions also f module_loaderror_suffix suffix_type? ; -: set_conf_files - conf_files .addr @ ?dup if - free-memory - then - value_buffer .addr @ c@ [char] " = if - value_buffer .addr @ char+ value_buffer .len @ 2 chars - - else - value_buffer .addr @ value_buffer .len @ - then - strdup - conf_files .len ! conf_files .addr ! -; - : set_nextboot_conf nextboot_conf_file .addr @ ?dup if free-memory @@ -888,6 +886,11 @@ only forth also support-functions also f then ; +: set_conf_files + set_environment_variable + s" loader_conf_files" getenv conf_files string= +; + : set_nextboot_flag yes_value? to nextboot? ; @@ -1045,7 +1048,6 @@ only forth also support-functions defini \ Variables used for processing multiple conf files string current_file_name -variable current_conf_files \ Indicates if any conf file was succesfully read @@ -1053,16 +1055,8 @@ variable current_conf_files \ loader_conf_files processing support functions -: set_current_conf_files - conf_files .addr @ current_conf_files ! -; - -: get_conf_files - conf_files .addr @ conf_files .len @ strdup -; - -: recurse_on_conf_files? - current_conf_files @ conf_files .addr @ <> +: get_conf_files ( -- addr len ) \ put addr/len on stack, reset var + conf_files strget 0 0 conf_files strset ; : skip_leading_spaces { addr len pos -- addr len pos' } @@ -1133,7 +1127,6 @@ variable current_conf_files \ Interface to loader_conf_files processing : include_conf_files - set_current_conf_files get_conf_files 0 begin get_next_file ?dup @@ -1141,7 +1134,7 @@ variable current_conf_files set_current_file_name ['] load_conf catch process_conf_errors - recurse_on_conf_files? if recurse then + conf_files .addr @ if recurse then repeat ; From kmacy at FreeBSD.org Sun Dec 7 13:15:44 2008 From: kmacy at FreeBSD.org (Kip Macy) Date: Sun Dec 7 13:15:56 2008 Subject: svn commit: r185747 - in head/sys: contrib/pf/net kern net netinet6 Message-ID: <200812072115.mB7LFhD1036508@svn.freebsd.org> Author: kmacy Date: Sun Dec 7 21:15:43 2008 New Revision: 185747 URL: http://svn.freebsd.org/changeset/base/185747 Log: - convert radix node head lock from mutex to rwlock - make radix node head lock not recursive - fix LOR in rtexpunge - fix LOR in rtredirect Reviewed by: sam Modified: head/sys/contrib/pf/net/pf_table.c head/sys/kern/subr_witness.c head/sys/kern/vfs_export.c head/sys/net/radix.c head/sys/net/radix.h head/sys/net/route.c head/sys/net/route.h head/sys/net/rtsock.c head/sys/netinet6/in6_rmx.c head/sys/netinet6/nd6_rtr.c Modified: head/sys/contrib/pf/net/pf_table.c ============================================================================== --- head/sys/contrib/pf/net/pf_table.c Sun Dec 7 19:42:20 2008 (r185746) +++ head/sys/contrib/pf/net/pf_table.c Sun Dec 7 21:15:43 2008 (r185747) @@ -43,6 +43,8 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +#include #ifdef __FreeBSD__ #include #endif Modified: head/sys/kern/subr_witness.c ============================================================================== --- head/sys/kern/subr_witness.c Sun Dec 7 19:42:20 2008 (r185746) +++ head/sys/kern/subr_witness.c Sun Dec 7 21:15:43 2008 (r185747) @@ -505,7 +505,7 @@ static struct witness_order_list_entry o * Routing */ { "so_rcv", &lock_class_mtx_sleep }, - { "radix node head", &lock_class_mtx_sleep }, + { "radix node head", &lock_class_rw }, { "rtentry", &lock_class_mtx_sleep }, { "ifaddr", &lock_class_mtx_sleep }, { NULL, NULL }, Modified: head/sys/kern/vfs_export.c ============================================================================== --- head/sys/kern/vfs_export.c Sun Dec 7 19:42:20 2008 (r185746) +++ head/sys/kern/vfs_export.c Sun Dec 7 21:15:43 2008 (r185747) @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -425,10 +426,10 @@ vfs_export_lookup(struct mount *mp, stru saddr = nam; rnh = nep->ne_rtable[saddr->sa_family]; if (rnh != NULL) { - RADIX_NODE_HEAD_LOCK(rnh); + RADIX_NODE_HEAD_RLOCK(rnh); np = (struct netcred *) (*rnh->rnh_matchaddr)(saddr, rnh); - RADIX_NODE_HEAD_UNLOCK(rnh); + RADIX_NODE_HEAD_RUNLOCK(rnh); if (np && np->netc_rnodes->rn_flags & RNF_ROOT) np = NULL; } Modified: head/sys/net/radix.c ============================================================================== --- head/sys/net/radix.c Sun Dec 7 19:42:20 2008 (r185746) +++ head/sys/net/radix.c Sun Dec 7 21:15:43 2008 (r185747) @@ -38,6 +38,7 @@ #ifdef _KERNEL #include #include +#include #include #include #include Modified: head/sys/net/radix.h ============================================================================== --- head/sys/net/radix.h Sun Dec 7 19:42:20 2008 (r185746) +++ head/sys/net/radix.h Sun Dec 7 21:15:43 2008 (r185747) @@ -36,6 +36,7 @@ #ifdef _KERNEL #include #include +#include #endif #ifdef MALLOC_DECLARE @@ -132,7 +133,7 @@ struct radix_node_head { struct radix_node rnh_nodes[3]; /* empty tree for common case */ int rnh_multipath; /* multipath capable ? */ #ifdef _KERNEL - struct mtx rnh_mtx; /* locks entire radix tree */ + struct rwlock rnh_lock; /* locks entire radix tree */ #endif }; @@ -146,11 +147,17 @@ struct radix_node_head { #define Free(p) free((caddr_t)p, M_RTABLE); #define RADIX_NODE_HEAD_LOCK_INIT(rnh) \ - mtx_init(&(rnh)->rnh_mtx, "radix node head", NULL, MTX_DEF | MTX_RECURSE) -#define RADIX_NODE_HEAD_LOCK(rnh) mtx_lock(&(rnh)->rnh_mtx) -#define RADIX_NODE_HEAD_UNLOCK(rnh) mtx_unlock(&(rnh)->rnh_mtx) -#define RADIX_NODE_HEAD_DESTROY(rnh) mtx_destroy(&(rnh)->rnh_mtx) -#define RADIX_NODE_HEAD_LOCK_ASSERT(rnh) mtx_assert(&(rnh)->rnh_mtx, MA_OWNED) + rw_init_flags(&(rnh)->rnh_lock, "radix node head", 0) +#define RADIX_NODE_HEAD_LOCK(rnh) rw_wlock(&(rnh)->rnh_lock) +#define RADIX_NODE_HEAD_UNLOCK(rnh) rw_wunlock(&(rnh)->rnh_lock) +#define RADIX_NODE_HEAD_RLOCK(rnh) rw_rlock(&(rnh)->rnh_lock) +#define RADIX_NODE_HEAD_RUNLOCK(rnh) rw_runlock(&(rnh)->rnh_lock) +#define RADIX_NODE_HEAD_LOCK_TRY_UPGRADE(rnh) rw_try_upgrade(&(rnh)->rnh_lock) + + +#define RADIX_NODE_HEAD_DESTROY(rnh) rw_destroy(&(rnh)->rnh_lock) +#define RADIX_NODE_HEAD_LOCK_ASSERT(rnh) rw_assert(&(rnh)->rnh_lock, RA_LOCKED) +#define RADIX_NODE_HEAD_WLOCK_ASSERT(rnh) rw_assert(&(rnh)->rnh_lock, RA_WLOCKED) #endif /* _KERNEL */ void rn_init(void); Modified: head/sys/net/route.c ============================================================================== --- head/sys/net/route.c Sun Dec 7 19:42:20 2008 (r185746) +++ head/sys/net/route.c Sun Dec 7 21:15:43 2008 (r185747) @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -269,7 +270,8 @@ rtalloc1_fib(struct sockaddr *dst, int r struct rtentry *newrt; struct rt_addrinfo info; u_long nflags; - int err = 0, msgtype = RTM_MISS; + int needresolve = 0, err = 0, msgtype = RTM_MISS; + int needlock; KASSERT((fibnum < rt_numfibs), ("rtalloc1_fib: bad fibnum")); if (dst->sa_family != AF_INET) /* Only INET supports > 1 fib now */ @@ -283,59 +285,92 @@ rtalloc1_fib(struct sockaddr *dst, int r V_rtstat.rts_unreach++; goto miss2; } - RADIX_NODE_HEAD_LOCK(rnh); - if ((rn = rnh->rnh_matchaddr(dst, rnh)) && - (rn->rn_flags & RNF_ROOT) == 0) { - /* - * If we find it and it's not the root node, then - * get a reference on the rtentry associated. - */ + needlock = !(ignflags & RTF_RNH_LOCKED); +retry: + if (needlock) + RADIX_NODE_HEAD_RLOCK(rnh); +#ifdef INVARIANTS + else + RADIX_NODE_HEAD_LOCK_ASSERT(rnh); +#endif + rn = rnh->rnh_matchaddr(dst, rnh); + if (rn && ((rn->rn_flags & RNF_ROOT) == 0)) { + newrt = rt = RNTORT(rn); nflags = rt->rt_flags & ~ignflags; if (report && (nflags & RTF_CLONING)) { - /* - * We are apparently adding (report = 0 in delete). - * If it requires that it be cloned, do so. - * (This implies it wasn't a HOST route.) - */ - err = rtrequest_fib(RTM_RESOLVE, dst, NULL, - NULL, 0, &newrt, fibnum); - if (err) { + if (needlock && !RADIX_NODE_HEAD_LOCK_TRY_UPGRADE(rnh)) { + RADIX_NODE_HEAD_RUNLOCK(rnh); + RADIX_NODE_HEAD_LOCK(rnh); /* - * If the cloning didn't succeed, maybe - * what we have will do. Return that. + * lookup again to make sure it wasn't changed */ - newrt = rt; /* existing route */ - RT_LOCK(newrt); - RT_ADDREF(newrt); - goto miss; - } - KASSERT(newrt, ("no route and no error")); - RT_LOCK(newrt); - if (newrt->rt_flags & RTF_XRESOLVE) { - /* - * If the new route specifies it be - * externally resolved, then go do that. - */ - msgtype = RTM_RESOLVE; - goto miss; - } - /* Inform listeners of the new route. */ - bzero(&info, sizeof(info)); - info.rti_info[RTAX_DST] = rt_key(newrt); - info.rti_info[RTAX_NETMASK] = rt_mask(newrt); - info.rti_info[RTAX_GATEWAY] = newrt->rt_gateway; - if (newrt->rt_ifp != NULL) { - info.rti_info[RTAX_IFP] = - newrt->rt_ifp->if_addr->ifa_addr; - info.rti_info[RTAX_IFA] = newrt->rt_ifa->ifa_addr; + rn = rnh->rnh_matchaddr(dst, rnh); + if (!(rn && ((rn->rn_flags & RNF_ROOT) == 0))) { + RADIX_NODE_HEAD_UNLOCK(rnh); + needresolve = 0; + log(LOG_INFO, "retrying route lookup ...\n"); + goto retry; + } } - rt_missmsg(RTM_ADD, &info, newrt->rt_flags, 0); + needresolve = 1; } else { RT_LOCK(newrt); RT_ADDREF(newrt); + if (needlock) + RADIX_NODE_HEAD_RUNLOCK(rnh); + goto done; } - RADIX_NODE_HEAD_UNLOCK(rnh); + } + /* + * if needresolve is set then we have the exclusive lock + * and we need to keep it held for the benefit of rtrequest_fib + */ + if (!needresolve && needlock) + RADIX_NODE_HEAD_RUNLOCK(rnh); + + if (needresolve) { + RADIX_NODE_HEAD_WLOCK_ASSERT(rnh); + /* + * We are apparently adding (report = 0 in delete). + * If it requires that it be cloned, do so. + * (This implies it wasn't a HOST route.) + */ + err = rtrequest_fib(RTM_RESOLVE, dst, NULL, + NULL, RTF_RNH_LOCKED, &newrt, fibnum); + if (err) { + /* + * If the cloning didn't succeed, maybe + * what we have will do. Return that. + */ + newrt = rt; /* existing route */ + RT_LOCK(newrt); + RT_ADDREF(newrt); + goto miss; + } + KASSERT(newrt, ("no route and no error")); + RT_LOCK(newrt); + if (newrt->rt_flags & RTF_XRESOLVE) { + /* + * If the new route specifies it be + * externally resolved, then go do that. + */ + msgtype = RTM_RESOLVE; + goto miss; + } + /* Inform listeners of the new route. */ + bzero(&info, sizeof(info)); + info.rti_info[RTAX_DST] = rt_key(newrt); + info.rti_info[RTAX_NETMASK] = rt_mask(newrt); + info.rti_info[RTAX_GATEWAY] = newrt->rt_gateway; + if (newrt->rt_ifp != NULL) { + info.rti_info[RTAX_IFP] = + newrt->rt_ifp->if_addr->ifa_addr; + info.rti_info[RTAX_IFA] = newrt->rt_ifa->ifa_addr; + } + rt_missmsg(RTM_ADD, &info, newrt->rt_flags, 0); + if (needlock) + RADIX_NODE_HEAD_UNLOCK(rnh); } else { /* * Either we hit the root or couldn't find any match, @@ -344,7 +379,8 @@ rtalloc1_fib(struct sockaddr *dst, int r */ V_rtstat.rts_unreach++; miss: - RADIX_NODE_HEAD_UNLOCK(rnh); + if (needlock && needresolve) + RADIX_NODE_HEAD_UNLOCK(rnh); miss2: if (report) { /* * If required, report the failure to the supervising @@ -356,6 +392,7 @@ rtalloc1_fib(struct sockaddr *dst, int r rt_missmsg(msgtype, &info, 0, err); } } +done: if (newrt) RT_LOCK_ASSERT(newrt); return (newrt); @@ -475,6 +512,8 @@ rtredirect_fib(struct sockaddr *dst, short *stat = NULL; struct rt_addrinfo info; struct ifaddr *ifa; + struct radix_node_head *rnh = + V_rt_tables[rt->rt_fibnum][dst->sa_family]; /* verify the gateway is directly reachable */ if ((ifa = ifa_ifwithnet(gateway)) == NULL) { @@ -524,14 +563,17 @@ rtredirect_fib(struct sockaddr *dst, info.rti_info[RTAX_NETMASK] = netmask; info.rti_ifa = ifa; info.rti_flags = flags; + if (rt0 != NULL) + RT_UNLOCK(rt0); /* drop lock to avoid LOR with RNH */ error = rtrequest1_fib(RTM_ADD, &info, &rt, fibnum); if (rt != NULL) { RT_LOCK(rt); - EVENTHANDLER_INVOKE(route_redirect_event, rt0, rt, dst); + if (rt0 != NULL) + EVENTHANDLER_INVOKE(route_redirect_event, rt0, rt, dst); flags = rt->rt_flags; } - if (rt0) - RTFREE_LOCKED(rt0); + if (rt0 != NULL) + RTFREE(rt0); stat = &V_rtstat.rts_dynamic; } else { @@ -547,8 +589,12 @@ rtredirect_fib(struct sockaddr *dst, /* * add the key and gateway (in one malloc'd chunk). */ + RT_UNLOCK(rt); + RADIX_NODE_HEAD_LOCK(rnh); + RT_LOCK(rt); rt_setgate(rt, rt_key(rt), gateway); - gwrt = rtalloc1(gateway, 1, 0); + gwrt = rtalloc1(gateway, 1, RTF_RNH_LOCKED); + RADIX_NODE_HEAD_UNLOCK(rnh); EVENTHANDLER_INVOKE(route_redirect_event, rt, gwrt, dst); RTFREE_LOCKED(gwrt); } @@ -782,7 +828,9 @@ rtexpunge(struct rtentry *rt) struct ifaddr *ifa; int error = 0; + rnh = V_rt_tables[rt->rt_fibnum][rt_key(rt)->sa_family]; RT_LOCK_ASSERT(rt); + RADIX_NODE_HEAD_LOCK_ASSERT(rnh); #if 0 /* * We cannot assume anything about the reference count @@ -798,8 +846,6 @@ rtexpunge(struct rtentry *rt) if (rnh == NULL) return (EAFNOSUPPORT); - RADIX_NODE_HEAD_LOCK(rnh); - /* * Remove the item from the tree; it should be there, * but when callers invoke us blindly it may not (sigh). @@ -854,7 +900,6 @@ rtexpunge(struct rtentry *rt) */ V_rttrash++; bad: - RADIX_NODE_HEAD_UNLOCK(rnh); return (error); } @@ -869,7 +914,7 @@ rtrequest1_fib(int req, struct rt_addrin u_int fibnum) { INIT_VNET_NET(curvnet); - int error = 0; + int error = 0, needlock = 0; register struct rtentry *rt; register struct radix_node *rn; register struct radix_node_head *rnh; @@ -886,7 +931,10 @@ rtrequest1_fib(int req, struct rt_addrin rnh = V_rt_tables[fibnum][dst->sa_family]; if (rnh == NULL) return (EAFNOSUPPORT); - RADIX_NODE_HEAD_LOCK(rnh); + needlock = ((flags & RTF_RNH_LOCKED) == 0); + flags &= ~RTF_RNH_LOCKED; + if (needlock) + RADIX_NODE_HEAD_LOCK(rnh); /* * If we are adding a host route then we don't want to put * a netmask in the tree, nor do we want to clone it. @@ -1200,7 +1248,8 @@ deldone: error = EOPNOTSUPP; } bad: - RADIX_NODE_HEAD_UNLOCK(rnh); + if (needlock) + RADIX_NODE_HEAD_UNLOCK(rnh); return (error); #undef senderr } @@ -1307,7 +1356,8 @@ rt_setgate(struct rtentry *rt, struct so again: RT_LOCK_ASSERT(rt); - + RADIX_NODE_HEAD_LOCK_ASSERT(rnh); + /* * A host route with the destination equal to the gateway * will interfere with keeping LLINFO in the routing @@ -1333,7 +1383,7 @@ again: struct rtentry *gwrt; RT_UNLOCK(rt); /* XXX workaround LOR */ - gwrt = rtalloc1_fib(gate, 1, 0, rt->rt_fibnum); + gwrt = rtalloc1_fib(gate, 1, RTF_RNH_LOCKED, rt->rt_fibnum); if (gwrt == rt) { RT_REMREF(rt); return (EADDRINUSE); /* failure */ @@ -1404,12 +1454,8 @@ again: arg.rnh = rnh; arg.rt0 = rt; - RT_UNLOCK(rt); /* XXX workaround LOR */ - RADIX_NODE_HEAD_LOCK(rnh); - RT_LOCK(rt); rnh->rnh_walktree_from(rnh, rt_key(rt), rt_mask(rt), rt_fixchange, &arg); - RADIX_NODE_HEAD_UNLOCK(rnh); } return 0; Modified: head/sys/net/route.h ============================================================================== --- head/sys/net/route.h Sun Dec 7 19:42:20 2008 (r185746) +++ head/sys/net/route.h Sun Dec 7 21:15:43 2008 (r185747) @@ -196,6 +196,7 @@ struct ortentry { #define RTF_BROADCAST 0x400000 /* route represents a bcast address */ #define RTF_MULTICAST 0x800000 /* route represents a mcast address */ /* 0x1000000 and up unassigned */ +#define RTF_RNH_LOCKED 0x40000000 /* radix node head locked by caller */ /* Mask of RTF flags that are allowed to be modified by RTM_CHANGE. */ #define RTF_FMASK \ Modified: head/sys/net/rtsock.c ============================================================================== --- head/sys/net/rtsock.c Sun Dec 7 19:42:20 2008 (r185746) +++ head/sys/net/rtsock.c Sun Dec 7 21:15:43 2008 (r185747) @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -554,11 +555,11 @@ route_output(struct mbuf *m, struct sock rnh = V_rt_tables[so->so_fibnum][info.rti_info[RTAX_DST]->sa_family]; if (rnh == NULL) senderr(EAFNOSUPPORT); - RADIX_NODE_HEAD_LOCK(rnh); + RADIX_NODE_HEAD_RLOCK(rnh); rt = (struct rtentry *) rnh->rnh_lookup(info.rti_info[RTAX_DST], info.rti_info[RTAX_NETMASK], rnh); if (rt == NULL) { /* XXX looks bogus */ - RADIX_NODE_HEAD_UNLOCK(rnh); + RADIX_NODE_HEAD_RUNLOCK(rnh); senderr(ESRCH); } #ifdef RADIX_MPATH @@ -574,14 +575,14 @@ route_output(struct mbuf *m, struct sock (rtm->rtm_type != RTM_GET || info.rti_info[RTAX_GATEWAY])) { rt = rt_mpath_matchgate(rt, info.rti_info[RTAX_GATEWAY]); if (!rt) { - RADIX_NODE_HEAD_UNLOCK(rnh); + RADIX_NODE_HEAD_RUNLOCK(rnh); senderr(ESRCH); } } #endif RT_LOCK(rt); RT_ADDREF(rt); - RADIX_NODE_HEAD_UNLOCK(rnh); + RADIX_NODE_HEAD_RUNLOCK(rnh); /* * Fix for PR: 82974 Modified: head/sys/netinet6/in6_rmx.c ============================================================================== --- head/sys/netinet6/in6_rmx.c Sun Dec 7 19:42:20 2008 (r185746) +++ head/sys/netinet6/in6_rmx.c Sun Dec 7 21:15:43 2008 (r185747) @@ -83,6 +83,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include Modified: head/sys/netinet6/nd6_rtr.c ============================================================================== --- head/sys/netinet6/nd6_rtr.c Sun Dec 7 19:42:20 2008 (r185746) +++ head/sys/netinet6/nd6_rtr.c Sun Dec 7 21:15:43 2008 (r185747) @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include From thompsa at FreeBSD.org Sun Dec 7 13:32:57 2008 From: thompsa at FreeBSD.org (Andrew Thompson) Date: Sun Dec 7 13:33:02 2008 Subject: svn commit: r185748 - head/sys/dev/e1000 Message-ID: <200812072132.mB7LWuIT036873@svn.freebsd.org> Author: thompsa Date: Sun Dec 7 21:32:56 2008 New Revision: 185748 URL: http://svn.freebsd.org/changeset/base/185748 Log: Restore opt_inet.h include which was lost in the last commit. Modified: head/sys/dev/e1000/if_em.c Modified: head/sys/dev/e1000/if_em.c ============================================================================== --- head/sys/dev/e1000/if_em.c Sun Dec 7 21:15:43 2008 (r185747) +++ head/sys/dev/e1000/if_em.c Sun Dec 7 21:32:56 2008 (r185748) @@ -34,6 +34,7 @@ #ifdef HAVE_KERNEL_OPTION_HEADERS #include "opt_device_polling.h" +#include "opt_inet.h" #endif #include From imp at FreeBSD.org Sun Dec 7 14:49:48 2008 From: imp at FreeBSD.org (Warner Losh) Date: Sun Dec 7 14:49:54 2008 Subject: svn commit: r185749 - head/sys/dev/pccbb Message-ID: <200812072249.mB7MnmdA038341@svn.freebsd.org> Author: imp Date: Sun Dec 7 22:49:47 2008 New Revision: 185749 URL: http://svn.freebsd.org/changeset/base/185749 Log: Minor tweaks to some of the comments. Also, add a XXX wondering if we need to frob the 16-bit EXCA registers during the new interrupt-driven power-up sequence. Modified: head/sys/dev/pccbb/pccbb.c Modified: head/sys/dev/pccbb/pccbb.c ============================================================================== --- head/sys/dev/pccbb/pccbb.c Sun Dec 7 21:32:56 2008 (r185748) +++ head/sys/dev/pccbb/pccbb.c Sun Dec 7 22:49:47 2008 (r185749) @@ -765,15 +765,17 @@ cbb_power(device_t brdev, int volts) reg = cbb_o2micro_power_hack(sc); /* - * We have to mask the card change detect interrupt while - * we're messing with the power. It is allowed to bounce - * while we're messing with power as things settle down. In - * addition, we mask off the card's function interrupt by - * routing it via the ISA bus. This bit generally only - * affects 16-bit cards. Some bridges allow one to set - * another bit to have it also affect 32-bit cards. Since - * 32-bit cards are required to be better behaved, we don't - * bother to get into those bridge specific features. + * We have to mask the card change detect interrupt while we're + * messing with the power. It is allowed to bounce while we're + * messing with power as things settle down. In addition, we mask off + * the card's function interrupt by routing it via the ISA bus. This + * bit generally only affects 16-bit cards. Some bridges allow one to + * set another bit to have it also affect 32-bit cards. Since 32-bit + * cards are required to be better behaved, we don't bother to get + * into those bridge specific features. + * + * XXX I wonder if we need to enable the READY bit interrupt in the + * EXCA CSC register for 16-bit cards, and disable the CD bit? */ mask = cbb_get(sc, CBB_SOCKET_MASK); mask |= CBB_SOCKET_MASK_POWER; @@ -786,11 +788,10 @@ cbb_power(device_t brdev, int volts) mtx_lock(&sc->mtx); cnt = sc->powerintr; /* - * We have a shortish timeout of 500ms here. Some - * bridges do not generate a POWER_CYCLE event for - * 16-bit cards. In those cases, we have to cope the - * best we can, and having only a short delay is - * better than the alternatives. + * We have a shortish timeout of 500ms here. Some bridges do + * not generate a POWER_CYCLE event for 16-bit cards. In + * those cases, we have to cope the best we can, and having + * only a short delay is better than the alternatives. */ sane = 10; while (!(cbb_get(sc, CBB_SOCKET_STATE) & CBB_STATE_POWER_CYCLE) && @@ -798,9 +799,9 @@ cbb_power(device_t brdev, int volts) msleep(&sc->powerintr, &sc->mtx, 0, "-", hz / 20); mtx_unlock(&sc->mtx); /* - * The TOPIC95B requires a little bit extra time to get - * its act together, so delay for an additional 100ms. Also - * as documented below, it doesn't seem to set the POWER_CYCLE + * The TOPIC95B requires a little bit extra time to get its + * act together, so delay for an additional 100ms. Also as + * documented below, it doesn't seem to set the POWER_CYCLE * bit, so don't whine if it never came on. */ if (sc->chipset == CB_TOPIC95) { From marius at FreeBSD.org Sun Dec 7 15:02:38 2008 From: marius at FreeBSD.org (Marius Strobl) Date: Sun Dec 7 15:02:44 2008 Subject: svn commit: r185750 - head/sys/dev/dc Message-ID: <200812072302.mB7N2bkp038633@svn.freebsd.org> Author: marius Date: Sun Dec 7 23:02:37 2008 New Revision: 185750 URL: http://svn.freebsd.org/changeset/base/185750 Log: - According to the corresponding Linux, NetBSD and OpenSolaris drivers, there should be a 1us delay after every write when bit-banging the MII. Also insert barriers in order to ensure the intended ordering. These changes hopefully will solve the bus wedging occasionally experienced with DM9102A since r182461. - Deobfuscate dc_mii_readreg() a bit. Modified: head/sys/dev/dc/if_dc.c head/sys/dev/dc/if_dcreg.h Modified: head/sys/dev/dc/if_dc.c ============================================================================== --- head/sys/dev/dc/if_dc.c Sun Dec 7 22:49:47 2008 (r185749) +++ head/sys/dev/dc/if_dc.c Sun Dec 7 23:02:37 2008 (r185750) @@ -607,15 +607,22 @@ dc_read_eeprom(struct dc_softc *sc, cadd static void dc_mii_writebit(struct dc_softc *sc, int bit) { + uint32_t reg; - if (bit) - CSR_WRITE_4(sc, DC_SIO, - DC_SIO_ROMCTL_WRITE | DC_SIO_MII_DATAOUT); - else - CSR_WRITE_4(sc, DC_SIO, DC_SIO_ROMCTL_WRITE); - - DC_SETBIT(sc, DC_SIO, DC_SIO_MII_CLK); - DC_CLRBIT(sc, DC_SIO, DC_SIO_MII_CLK); + reg = DC_SIO_ROMCTL_WRITE | (bit != 0 ? DC_SIO_MII_DATAOUT : 0); + CSR_WRITE_4(sc, DC_SIO, reg); + CSR_BARRIER_4(sc, DC_SIO, + BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); + DELAY(1); + + CSR_WRITE_4(sc, DC_SIO, reg | DC_SIO_MII_CLK); + CSR_BARRIER_4(sc, DC_SIO, + BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); + DELAY(1); + CSR_WRITE_4(sc, DC_SIO, reg); + CSR_BARRIER_4(sc, DC_SIO, + BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); + DELAY(1); } /* @@ -624,11 +631,22 @@ dc_mii_writebit(struct dc_softc *sc, int static int dc_mii_readbit(struct dc_softc *sc) { + uint32_t reg; - CSR_WRITE_4(sc, DC_SIO, DC_SIO_ROMCTL_READ | DC_SIO_MII_DIR); - CSR_READ_4(sc, DC_SIO); - DC_SETBIT(sc, DC_SIO, DC_SIO_MII_CLK); - DC_CLRBIT(sc, DC_SIO, DC_SIO_MII_CLK); + reg = DC_SIO_ROMCTL_READ | DC_SIO_MII_DIR; + CSR_WRITE_4(sc, DC_SIO, reg); + CSR_BARRIER_4(sc, DC_SIO, + BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); + DELAY(1); + (void)CSR_READ_4(sc, DC_SIO); + CSR_WRITE_4(sc, DC_SIO, reg | DC_SIO_MII_CLK); + CSR_BARRIER_4(sc, DC_SIO, + BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); + DELAY(1); + CSR_WRITE_4(sc, DC_SIO, reg); + CSR_BARRIER_4(sc, DC_SIO, + BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); + DELAY(1); if (CSR_READ_4(sc, DC_SIO) & DC_SIO_MII_DATAIN) return (1); @@ -644,6 +662,9 @@ dc_mii_sync(struct dc_softc *sc) int i; CSR_WRITE_4(sc, DC_SIO, DC_SIO_ROMCTL_WRITE); + CSR_BARRIER_4(sc, DC_SIO, + BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); + DELAY(1); for (i = 0; i < 32; i++) dc_mii_writebit(sc, 1); @@ -667,15 +688,13 @@ dc_mii_send(struct dc_softc *sc, u_int32 static int dc_mii_readreg(struct dc_softc *sc, struct dc_mii_frame *frame) { - int i, ack; + int i; /* * Set up frame for RX. */ frame->mii_stdelim = DC_MII_STARTDELIM; frame->mii_opcode = DC_MII_READOP; - frame->mii_turnaround = 0; - frame->mii_data = 0; /* * Sync the PHYs. @@ -690,38 +709,28 @@ dc_mii_readreg(struct dc_softc *sc, stru dc_mii_send(sc, frame->mii_phyaddr, 5); dc_mii_send(sc, frame->mii_regaddr, 5); -#ifdef notdef - /* Idle bit */ - dc_mii_writebit(sc, 1); - dc_mii_writebit(sc, 0); -#endif - - /* Check for ack. */ - ack = dc_mii_readbit(sc); - /* - * Now try reading data bits. If the ack failed, we still + * Now try reading data bits. If the turnaround failed, we still * need to clock through 16 cycles to keep the PHY(s) in sync. */ - if (ack) { + frame->mii_turnaround = dc_mii_readbit(sc); + if (frame->mii_turnaround != 0) { for (i = 0; i < 16; i++) dc_mii_readbit(sc); goto fail; } - for (i = 0x8000; i; i >>= 1) { - if (!ack) { - if (dc_mii_readbit(sc)) - frame->mii_data |= i; - } + if (dc_mii_readbit(sc)) + frame->mii_data |= i; } fail: + /* Clock the idle bits. */ dc_mii_writebit(sc, 0); dc_mii_writebit(sc, 0); - if (ack) + if (frame->mii_turnaround != 0) return (1); return (0); } @@ -736,7 +745,6 @@ dc_mii_writereg(struct dc_softc *sc, str /* * Set up frame for TX. */ - frame->mii_stdelim = DC_MII_STARTDELIM; frame->mii_opcode = DC_MII_WRITEOP; frame->mii_turnaround = DC_MII_TURNAROUND; @@ -753,7 +761,7 @@ dc_mii_writereg(struct dc_softc *sc, str dc_mii_send(sc, frame->mii_turnaround, 2); dc_mii_send(sc, frame->mii_data, 16); - /* Idle bit. */ + /* Clock the idle bits. */ dc_mii_writebit(sc, 0); dc_mii_writebit(sc, 0); Modified: head/sys/dev/dc/if_dcreg.h ============================================================================== --- head/sys/dev/dc/if_dcreg.h Sun Dec 7 22:49:47 2008 (r185749) +++ head/sys/dev/dc/if_dcreg.h Sun Dec 7 23:02:37 2008 (r185750) @@ -791,6 +791,9 @@ struct dc_softc { #define CSR_READ_4(sc, reg) \ bus_space_read_4(sc->dc_btag, sc->dc_bhandle, reg) +#define CSR_BARRIER_4(sc, reg, flags) \ + bus_space_barrier(sc->dc_btag, sc->dc_bhandle, reg, 4, flags) + #define DC_TIMEOUT 1000 #define ETHER_ALIGN 2 From imp at FreeBSD.org Sun Dec 7 16:28:22 2008 From: imp at FreeBSD.org (Warner Losh) Date: Sun Dec 7 16:28:28 2008 Subject: svn commit: r185751 - in head/sys: net netinet6 Message-ID: <200812080028.mB80SM3s040238@svn.freebsd.org> Author: imp Date: Mon Dec 8 00:28:21 2008 New Revision: 185751 URL: http://svn.freebsd.org/changeset/base/185751 Log: Add missing include to sys/lock.h before sys/rwlock.h Modified: head/sys/net/rtsock.c head/sys/netinet6/in6_rmx.c head/sys/netinet6/nd6_rtr.c Modified: head/sys/net/rtsock.c ============================================================================== --- head/sys/net/rtsock.c Sun Dec 7 23:02:37 2008 (r185750) +++ head/sys/net/rtsock.c Mon Dec 8 00:28:21 2008 (r185751) @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include Modified: head/sys/netinet6/in6_rmx.c ============================================================================== --- head/sys/netinet6/in6_rmx.c Sun Dec 7 23:02:37 2008 (r185750) +++ head/sys/netinet6/in6_rmx.c Mon Dec 8 00:28:21 2008 (r185751) @@ -78,6 +78,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include Modified: head/sys/netinet6/nd6_rtr.c ============================================================================== --- head/sys/netinet6/nd6_rtr.c Sun Dec 7 23:02:37 2008 (r185750) +++ head/sys/netinet6/nd6_rtr.c Mon Dec 8 00:28:21 2008 (r185751) @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include From yongari at FreeBSD.org Sun Dec 7 17:44:18 2008 From: yongari at FreeBSD.org (Pyun YongHyeon) Date: Sun Dec 7 17:44:24 2008 Subject: svn commit: r185752 - head/sys/dev/re Message-ID: <200812080144.mB81iIF0041697@svn.freebsd.org> Author: yongari Date: Mon Dec 8 01:44:18 2008 New Revision: 185752 URL: http://svn.freebsd.org/changeset/base/185752 Log: Make sure to return the result of meida change request. Previously it used to return success regardless of the result. Modified: head/sys/dev/re/if_re.c Modified: head/sys/dev/re/if_re.c ============================================================================== --- head/sys/dev/re/if_re.c Mon Dec 8 00:28:21 2008 (r185751) +++ head/sys/dev/re/if_re.c Mon Dec 8 01:44:18 2008 (r185752) @@ -2652,14 +2652,15 @@ re_ifmedia_upd(struct ifnet *ifp) { struct rl_softc *sc; struct mii_data *mii; + int error; sc = ifp->if_softc; mii = device_get_softc(sc->rl_miibus); RL_LOCK(sc); - mii_mediachg(mii); + error = mii_mediachg(mii); RL_UNLOCK(sc); - return (0); + return (error); } /* From yongari at FreeBSD.org Sun Dec 7 18:34:14 2008 From: yongari at FreeBSD.org (Pyun YongHyeon) Date: Sun Dec 7 18:34:25 2008 Subject: svn commit: r185753 - in head/sys: dev/re pci Message-ID: <200812080234.mB82YDD7042788@svn.freebsd.org> Author: yongari Date: Mon Dec 8 02:34:13 2008 New Revision: 185753 URL: http://svn.freebsd.org/changeset/base/185753 Log: o Implemented miibus_statchg handler. It detects whether re(4) established a valid link or not. In miibus_statchg handler add a check for established link is valid one for the controller(e.g. 1000baseT is not a valid link for fastethernet controllers.) o Added a flag RE_FLAG_FASTETHER to mark fastethernet controllers. o Added additional check to know whether we've really encountered watchdog timeouts or missed Tx completion interrupts. This change may help to track down the cause of watchdog timeouts. o In interrupt handler, removed a check for link state change interrupt. Not all controllers have the bit and re(4) did not rely on the event for a long time. In addition, re(4) didn't request the interrupt in RL_IMR register. Tested by: rpaulo Modified: head/sys/dev/re/if_re.c head/sys/pci/if_rlreg.h Modified: head/sys/dev/re/if_re.c ============================================================================== --- head/sys/dev/re/if_re.c Mon Dec 8 01:44:18 2008 (r185752) +++ head/sys/dev/re/if_re.c Mon Dec 8 02:34:13 2008 (r185753) @@ -573,7 +573,39 @@ re_miibus_writereg(device_t dev, int phy static void re_miibus_statchg(device_t dev) { + struct rl_softc *sc; + struct ifnet *ifp; + struct mii_data *mii; + sc = device_get_softc(dev); + mii = device_get_softc(sc->rl_miibus); + ifp = sc->rl_ifp; + if (mii == NULL || ifp == NULL || + (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) + return; + + sc->rl_flags &= ~RL_FLAG_LINK; + if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) == + (IFM_ACTIVE | IFM_AVALID)) { + switch (IFM_SUBTYPE(mii->mii_media_active)) { + case IFM_10_T: + case IFM_100_TX: + sc->rl_flags |= RL_FLAG_LINK; + break; + case IFM_1000_T: + if ((sc->rl_flags & RL_FLAG_FASTETHER) != 0) + break; + sc->rl_flags |= RL_FLAG_LINK; + break; + default: + break; + } + } + /* + * RealTek controllers does not provide any interface to + * Tx/Rx MACs for resolved speed, duplex and flow-control + * parameters. + */ } /* @@ -1204,18 +1236,18 @@ re_attach(device_t dev) switch (hw_rev->rl_rev) { case RL_HWREV_8139CPLUS: - sc->rl_flags |= RL_FLAG_NOJUMBO; + sc->rl_flags |= RL_FLAG_NOJUMBO | RL_FLAG_FASTETHER; break; case RL_HWREV_8100E: case RL_HWREV_8101E: sc->rl_flags |= RL_FLAG_NOJUMBO | RL_FLAG_INVMAR | - RL_FLAG_PHYWAKE; + RL_FLAG_PHYWAKE | RL_FLAG_FASTETHER; break; case RL_HWREV_8102E: case RL_HWREV_8102EL: sc->rl_flags |= RL_FLAG_NOJUMBO | RL_FLAG_INVMAR | RL_FLAG_PHYWAKE | RL_FLAG_PAR | RL_FLAG_DESCV2 | - RL_FLAG_MACSTAT; + RL_FLAG_MACSTAT | RL_FLAG_FASTETHER; break; case RL_HWREV_8168_SPIN1: case RL_HWREV_8168_SPIN2: @@ -2011,30 +2043,14 @@ re_tick(void *xsc) { struct rl_softc *sc; struct mii_data *mii; - struct ifnet *ifp; sc = xsc; - ifp = sc->rl_ifp; RL_LOCK_ASSERT(sc); - re_watchdog(sc); - mii = device_get_softc(sc->rl_miibus); mii_tick(mii); - if ((sc->rl_flags & RL_FLAG_LINK) != 0) { - if (!(mii->mii_media_status & IFM_ACTIVE)) - sc->rl_flags &= ~RL_FLAG_LINK; - } else { - if (mii->mii_media_status & IFM_ACTIVE && - IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) { - sc->rl_flags |= RL_FLAG_LINK; - if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) - taskqueue_enqueue_fast(taskqueue_fast, - &sc->rl_txtask); - } - } - + re_watchdog(sc); callout_reset(&sc->rl_stat_callout, hz, re_tick, sc); } @@ -2149,11 +2165,6 @@ re_int_task(void *arg, int npending) re_init_locked(sc); } - if (status & RL_ISR_LINKCHG) { - callout_stop(&sc->rl_stat_callout); - re_tick(sc); - } - if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) taskqueue_enqueue_fast(taskqueue_fast, &sc->rl_txtask); @@ -2815,18 +2826,30 @@ re_ioctl(struct ifnet *ifp, u_long comma static void re_watchdog(struct rl_softc *sc) { + struct ifnet *ifp; RL_LOCK_ASSERT(sc); if (sc->rl_watchdog_timer == 0 || --sc->rl_watchdog_timer != 0) return; - device_printf(sc->rl_dev, "watchdog timeout\n"); - sc->rl_ifp->if_oerrors++; - + ifp = sc->rl_ifp; re_txeof(sc); + if (sc->rl_ldata.rl_tx_free == sc->rl_ldata.rl_tx_desc_cnt) { + if_printf(ifp, "watchdog timeout (missed Tx interrupts) " + "-- recovering\n"); + if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) + taskqueue_enqueue_fast(taskqueue_fast, &sc->rl_txtask); + return; + } + + if_printf(ifp, "watchdog timeout\n"); + ifp->if_oerrors++; + re_rxeof(sc); re_init_locked(sc); + if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) + taskqueue_enqueue_fast(taskqueue_fast, &sc->rl_txtask); } /* Modified: head/sys/pci/if_rlreg.h ============================================================================== --- head/sys/pci/if_rlreg.h Mon Dec 8 01:44:18 2008 (r185752) +++ head/sys/pci/if_rlreg.h Mon Dec 8 02:34:13 2008 (r185753) @@ -882,6 +882,7 @@ struct rl_softc { #define RL_FLAG_PAR 0x0020 #define RL_FLAG_DESCV2 0x0040 #define RL_FLAG_MACSTAT 0x0080 +#define RL_FLAG_FASTETHER 0x0100 #define RL_FLAG_LINK 0x8000 }; From nwhitehorn at FreeBSD.org Sun Dec 7 18:37:09 2008 From: nwhitehorn at FreeBSD.org (Nathan Whitehorn) Date: Sun Dec 7 18:37:16 2008 Subject: svn commit: r185754 - in head: share/man/man4/man4.powerpc sys/powerpc/powermac Message-ID: <200812080237.mB82b9Hs042873@svn.freebsd.org> Author: nwhitehorn Date: Mon Dec 8 02:37:08 2008 New Revision: 185754 URL: http://svn.freebsd.org/changeset/base/185754 Log: Add facilities to pmu(4) to interrogate battery status on Apple PowerPC laptops. This includes battery presence detection, charging status, current and voltage readouts, and charge level indication. The sysctl interface is somewhat ACPI-like. Modified: head/share/man/man4/man4.powerpc/pmu.4 head/sys/powerpc/powermac/pmu.c head/sys/powerpc/powermac/pmuvar.h Modified: head/share/man/man4/man4.powerpc/pmu.4 ============================================================================== --- head/share/man/man4/man4.powerpc/pmu.4 Mon Dec 8 02:34:13 2008 (r185753) +++ head/share/man/man4/man4.powerpc/pmu.4 Mon Dec 8 02:37:08 2008 (r185754) @@ -69,13 +69,32 @@ The driver provides power management services in addition to an .Xr adb 4 interface. The following sysctls can be used to control the -power management behavior. +power management behavior and to examine current system power and +thermal conditions. .Bl -tag -width indent .It Va dev.pmu.%d.server_mode Restart after power failure behavior (1 causes system to reboot after power -cut, 0 causes system to remain off) +cut, 0 causes system to remain off). +.It Va dev.pmu.%d.batteries.%d.present +Indicates whether the relevant battery is inserted. +.It Va dev.pmu.%d.batteries.%d.charging +Indicates whether the battery is currently charging. +.It Va dev.pmu.%d.batteries.%d.charge +The current battery charge, in milliamp hours. +.It Va dev.pmu.%d.batteries.%d.maxcharge +The battery's self-reported maximum charge, in milliamp hours. +.It Va dev.pmu.%d.batteries.%d.rate +The current into the battery, in milliamps. While the battery is discharging, +this will be negative. +.It Va dev.pmu.%d.batteries.%d.voltage +Battery voltage, in millivolts. +.It Va dev.pmu.%d.batteries.%d.time +Estimated time until full battery charge (or discharge), in minutes. +.It Va dev.pmu.%d.batteries.%d.life +Current fraction of the battery's maximum charge, in percent. .Sh SEE ALSO -.Xr adb 4 +.Xr adb 4 , +.Xr acpi 4 .Sh HISTORY The .Nm Modified: head/sys/powerpc/powermac/pmu.c ============================================================================== --- head/sys/powerpc/powermac/pmu.c Mon Dec 8 02:34:13 2008 (r185753) +++ head/sys/powerpc/powermac/pmu.c Mon Dec 8 02:37:08 2008 (r185754) @@ -67,10 +67,29 @@ static int pmu_attach(device_t); static int pmu_detach(device_t); static u_int pmu_adb_send(device_t dev, u_char command_byte, int len, - u_char *data, u_char poll); + u_char *data, u_char poll); static u_int pmu_adb_autopoll(device_t dev, uint16_t mask); static void pmu_poll(device_t dev); + static int pmu_server_mode(SYSCTL_HANDLER_ARGS); +static int pmu_query_battery(struct pmu_softc *sc, int batt, + struct pmu_battstate *info); +static int pmu_battquery_sysctl(SYSCTL_HANDLER_ARGS); + +/* + * List of battery-related sysctls we might ask for + */ + +enum { + PMU_BATSYSCTL_PRESENT = 1 << 8, + PMU_BATSYSCTL_CHARGING = 2 << 8, + PMU_BATSYSCTL_CHARGE = 3 << 8, + PMU_BATSYSCTL_MAXCHARGE = 4 << 8, + PMU_BATSYSCTL_CURRENT = 5 << 8, + PMU_BATSYSCTL_VOLTAGE = 6 << 8, + PMU_BATSYSCTL_TIME = 7 << 8, + PMU_BATSYSCTL_LIFE = 8 << 8 +}; static device_method_t pmu_methods[] = { /* Device interface */ @@ -280,6 +299,7 @@ pmu_attach(device_t dev) { struct pmu_softc *sc; + int i; uint8_t reg; uint8_t cmd[2] = {2, 0}; uint8_t resp[16]; @@ -312,8 +332,6 @@ pmu_attach(device_t dev) return (ENXIO); } - sc->sc_error = 0; - sc->sc_polling = 0; sc->sc_autopoll = 0; /* Init PMU */ @@ -343,6 +361,18 @@ pmu_attach(device_t dev) if (strncmp(name, "adb", 4) == 0) { sc->adb_bus = device_add_child(dev,"adb",-1); } + + if (strncmp(name, "power-mgt", 9) == 0) { + uint32_t prim_info[9]; + + if (OF_getprop(child, "prim-info", prim_info, + sizeof(prim_info)) >= 7) + sc->sc_batteries = (prim_info[6] >> 16) & 0xff; + + if (bootverbose && sc->sc_batteries > 0) + device_printf(dev, "%d batteries detected\n", + sc->sc_batteries); + } } /* @@ -353,8 +383,61 @@ pmu_attach(device_t dev) tree = device_get_sysctl_tree(dev); SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, - "server_mode", CTLTYPE_INT | CTLFLAG_RW, sc, 0, - pmu_server_mode, "I", "Enable reboot after power failure"); + "server_mode", CTLTYPE_INT | CTLFLAG_RW, sc, 0, + pmu_server_mode, "I", "Enable reboot after power failure"); + + if (sc->sc_batteries > 0) { + struct sysctl_oid *oid, *battroot; + char battnum[2]; + + battroot = SYSCTL_ADD_NODE(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + "batteries", CTLFLAG_RD, 0, "Battery Information"); + + for (i = 0; i < sc->sc_batteries; i++) { + battnum[0] = i + '0'; + battnum[1] = '\0'; + + oid = SYSCTL_ADD_NODE(ctx, SYSCTL_CHILDREN(battroot), + OID_AUTO, battnum, CTLFLAG_RD, 0, + "Battery Information"); + + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, + "present", CTLTYPE_INT | CTLFLAG_RD, sc, + PMU_BATSYSCTL_PRESENT | i, pmu_battquery_sysctl, + "I", "Battery present"); + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, + "charging", CTLTYPE_INT | CTLFLAG_RD, sc, + PMU_BATSYSCTL_CHARGING | i, pmu_battquery_sysctl, + "I", "Battery charging"); + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, + "charge", CTLTYPE_INT | CTLFLAG_RD, sc, + PMU_BATSYSCTL_CHARGE | i, pmu_battquery_sysctl, + "I", "Battery charge (mAh)"); + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, + "maxcharge", CTLTYPE_INT | CTLFLAG_RD, sc, + PMU_BATSYSCTL_MAXCHARGE | i, pmu_battquery_sysctl, + "I", "Maximum battery capacity (mAh)"); + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, + "rate", CTLTYPE_INT | CTLFLAG_RD, sc, + PMU_BATSYSCTL_CURRENT | i, pmu_battquery_sysctl, + "I", "Battery discharge rate (mA)"); + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, + "voltage", CTLTYPE_INT | CTLFLAG_RD, sc, + PMU_BATSYSCTL_VOLTAGE | i, pmu_battquery_sysctl, + "I", "Battery voltage (mV)"); + + /* Knobs for mental compatibility with ACPI */ + + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, + "time", CTLTYPE_INT | CTLFLAG_RD, sc, + PMU_BATSYSCTL_TIME | i, pmu_battquery_sysctl, + "I", "Time Remaining (minutes)"); + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, + "life", CTLTYPE_INT | CTLFLAG_RD, sc, + PMU_BATSYSCTL_LIFE | i, pmu_battquery_sysctl, + "I", "Capacity remaining (percent)"); + } + } return (bus_generic_attach(dev)); } @@ -437,7 +520,6 @@ pmu_send(void *cookie, int cmd, int leng /* wait idle */ do {} while (pmu_intr_state(sc)); - sc->sc_error = 0; /* send command */ pmu_send_byte(sc, cmd); @@ -671,3 +753,124 @@ pmu_server_mode(SYSCTL_HANDLER_ARGS) return (0); } +static int +pmu_query_battery(struct pmu_softc *sc, int batt, struct pmu_battstate *info) +{ + uint8_t reg; + uint8_t resp[16]; + int len; + + reg = batt + 1; + + mtx_lock(&sc->sc_mutex); + len = pmu_send(sc, PMU_SMART_BATTERY_STATE, 1, ®, 16, resp); + mtx_unlock(&sc->sc_mutex); + + if (len < 3) + return (-1); + + /* All PMU battery info replies share a common header: + * Byte 1 Payload Format + * Byte 2 Battery Flags + */ + + info->state = resp[2]; + + switch (resp[1]) { + case 3: + case 4: + /* + * Formats 3 and 4 appear to be the same: + * Byte 3 Charge + * Byte 4 Max Charge + * Byte 5 Current + * Byte 6 Voltage + */ + + info->charge = resp[3]; + info->maxcharge = resp[4]; + /* Current can be positive or negative */ + info->current = (int8_t)resp[5]; + info->voltage = resp[6]; + break; + case 5: + /* + * Formats 5 is a wider version of formats 3 and 4 + * Byte 3-4 Charge + * Byte 5-6 Max Charge + * Byte 7-8 Current + * Byte 9-10 Voltage + */ + + info->charge = (resp[3] << 8) | resp[4]; + info->maxcharge = (resp[5] << 8) | resp[6]; + /* Current can be positive or negative */ + info->current = (int16_t)((resp[7] << 8) | resp[8]); + info->voltage = (resp[9] << 8) | resp[10]; + break; + default: + device_printf(sc->sc_dev, "Unknown battery info format (%d)!\n", + resp[1]); + return (-1); + } + + return (0); +} + +static int +pmu_battquery_sysctl(SYSCTL_HANDLER_ARGS) +{ + struct pmu_softc *sc; + struct pmu_battstate batt; + int error, result; + + sc = arg1; + + error = pmu_query_battery(sc, arg2 & 0x00ff, &batt); + + if (error != 0) + return (error); + + switch (arg2 & 0xff00) { + case PMU_BATSYSCTL_PRESENT: + result = (batt.state & PMU_PWR_BATT_PRESENT) ? 1 : 0; + break; + case PMU_BATSYSCTL_CHARGING: + result = (batt.state & PMU_PWR_BATT_CHARGING) ? 1 : 0; + break; + case PMU_BATSYSCTL_CHARGE: + result = batt.charge; + break; + case PMU_BATSYSCTL_MAXCHARGE: + result = batt.maxcharge; + break; + case PMU_BATSYSCTL_CURRENT: + result = batt.current; + break; + case PMU_BATSYSCTL_VOLTAGE: + result = batt.voltage; + break; + case PMU_BATSYSCTL_TIME: + /* Time remaining until full charge/discharge, in minutes */ + + if (batt.current >= 0) + result = (batt.maxcharge - batt.charge) /* mAh */ * 60 + / batt.current /* mA */; + else + result = (batt.charge /* mAh */ * 60) + / (-batt.current /* mA */); + break; + case PMU_BATSYSCTL_LIFE: + /* Battery charge fraction, in percent */ + result = (batt.charge * 100) / batt.maxcharge; + break; + default: + /* This should never happen */ + result = -1; + }; + + error = sysctl_handle_int(oidp, &result, 0, req); + + return (error); +} + Modified: head/sys/powerpc/powermac/pmuvar.h ============================================================================== --- head/sys/powerpc/powermac/pmuvar.h Mon Dec 8 02:34:13 2008 (r185753) +++ head/sys/powerpc/powermac/pmuvar.h Mon Dec 8 02:37:08 2008 (r185754) @@ -158,14 +158,18 @@ struct pmu_softc { void *sc_ih; struct mtx sc_mutex; - device_t adb_bus; + volatile int sc_autopoll; + int sc_batteries; +}; + +struct pmu_battstate { + int state; - int sc_node; - volatile int sc_state; - int sc_polling; - int sc_error; - volatile int sc_autopoll; + int charge; + int maxcharge; + int current; + int voltage; }; #endif /* PMUVAR_H */ From nwhitehorn at FreeBSD.org Sun Dec 7 18:38:14 2008 From: nwhitehorn at FreeBSD.org (Nathan Whitehorn) Date: Sun Dec 7 18:38:20 2008 Subject: svn commit: r185755 - head/sys/powerpc/conf Message-ID: <200812080238.mB82cD7I042929@svn.freebsd.org> Author: nwhitehorn Date: Mon Dec 8 02:38:13 2008 New Revision: 185755 URL: http://svn.freebsd.org/changeset/base/185755 Log: Accidentally left ADB out of the PowerPC NOTES file during initial import. Modified: head/sys/powerpc/conf/NOTES Modified: head/sys/powerpc/conf/NOTES ============================================================================== --- head/sys/powerpc/conf/NOTES Mon Dec 8 02:37:08 2008 (r185754) +++ head/sys/powerpc/conf/NOTES Mon Dec 8 02:38:13 2008 (r185755) @@ -26,6 +26,9 @@ device pci device bm # Apple BMAC (Big Mac Ethernet) device ofwd # Open Firmware disks +device adb # Apple Desktop Bus +device cuda # VIA-CUDA ADB interface +device pmu # Apple Power Management Unit ##################################################################### From yongari at FreeBSD.org Sun Dec 7 18:48:42 2008 From: yongari at FreeBSD.org (Pyun YongHyeon) Date: Sun Dec 7 18:48:54 2008 Subject: svn commit: r185756 - head/sys/dev/re Message-ID: <200812080248.mB82mfV9043154@svn.freebsd.org> Author: yongari Date: Mon Dec 8 02:48:41 2008 New Revision: 185756 URL: http://svn.freebsd.org/changeset/base/185756 Log: Reduce spin wait time consumed in GMII register access routines. Waiting for 1ms for each GMII register access looks overkill and it may also decrease overall performance of driver because re(4) invokes mii_tick for every hz. Tested by: rpaulo Modified: head/sys/dev/re/if_re.c Modified: head/sys/dev/re/if_re.c ============================================================================== --- head/sys/dev/re/if_re.c Mon Dec 8 02:38:13 2008 (r185755) +++ head/sys/dev/re/if_re.c Mon Dec 8 02:48:41 2008 (r185756) @@ -417,13 +417,12 @@ re_gmii_readreg(device_t dev, int phy, i } CSR_WRITE_4(sc, RL_PHYAR, reg << 16); - DELAY(1000); for (i = 0; i < RL_TIMEOUT; i++) { + DELAY(30); rval = CSR_READ_4(sc, RL_PHYAR); if (rval & RL_PHYAR_BUSY) break; - DELAY(100); } if (i == RL_TIMEOUT) { @@ -445,13 +444,12 @@ re_gmii_writereg(device_t dev, int phy, CSR_WRITE_4(sc, RL_PHYAR, (reg << 16) | (data & RL_PHYAR_PHYDATA) | RL_PHYAR_BUSY); - DELAY(1000); for (i = 0; i < RL_TIMEOUT; i++) { + DELAY(30); rval = CSR_READ_4(sc, RL_PHYAR); if (!(rval & RL_PHYAR_BUSY)) break; - DELAY(100); } if (i == RL_TIMEOUT) { From nwhitehorn at FreeBSD.org Sun Dec 7 19:00:45 2008 From: nwhitehorn at FreeBSD.org (Nathan Whitehorn) Date: Sun Dec 7 19:00:52 2008 Subject: svn commit: r185757 - head/sys/powerpc/powermac Message-ID: <200812080300.mB830j7j044568@svn.freebsd.org> Author: nwhitehorn Date: Mon Dec 8 03:00:45 2008 New Revision: 185757 URL: http://svn.freebsd.org/changeset/base/185757 Log: Clean up the mac GPIO interface a little. Also remove bogus copyright and 3rd license clause. Submitted by: Marco Trillo Modified: head/sys/powerpc/powermac/macgpio.c head/sys/powerpc/powermac/macgpiovar.h Modified: head/sys/powerpc/powermac/macgpio.c ============================================================================== --- head/sys/powerpc/powermac/macgpio.c Mon Dec 8 02:48:41 2008 (r185756) +++ head/sys/powerpc/powermac/macgpio.c Mon Dec 8 03:00:45 2008 (r185757) @@ -1,5 +1,5 @@ /*- - * Copyright 2002 by Peter Grehan. All rights reserved. + * Copyright 2008 by Nathan Whitehorn. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -9,8 +9,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -51,6 +49,8 @@ #include #include +#include + /* * Macgpio softc */ @@ -62,21 +62,18 @@ struct macgpio_softc { static MALLOC_DEFINE(M_MACGPIO, "macgpio", "macgpio device information"); -static int macgpio_probe(device_t); -static int macgpio_attach(device_t); -static int macgpio_print_child(device_t dev, device_t child); -static void macgpio_probe_nomatch(device_t, device_t); -static struct resource *macgpio_alloc_resource(device_t, device_t, int, int *, - u_long, u_long, u_long, u_int); -static int macgpio_activate_resource(device_t, device_t, int, int, - struct resource *); -static int macgpio_deactivate_resource(device_t, device_t, int, int, - struct resource *); +static int macgpio_probe(device_t); +static int macgpio_attach(device_t); +static int macgpio_print_child(device_t dev, device_t child); +static void macgpio_probe_nomatch(device_t, device_t); +static struct resource *macgpio_alloc_resource(device_t, device_t, int, int *, + u_long, u_long, u_long, u_int); +static int macgpio_activate_resource(device_t, device_t, int, int, + struct resource *); +static int macgpio_deactivate_resource(device_t, device_t, int, int, + struct resource *); static ofw_bus_get_devinfo_t macgpio_get_devinfo; -uint8_t macgpio_read(device_t dev); -void macgpio_write(device_t dev,uint8_t); - /* * Bus interface definition */ @@ -125,7 +122,7 @@ struct macgpio_devinfo { struct ofw_bus_devinfo mdi_obdinfo; struct resource_list mdi_resources; - int gpio_num; + int gpio_num; }; static int @@ -215,8 +212,14 @@ macgpio_print_child(device_t dev, device dinfo = device_get_ivars(child); retval += bus_print_child_header(dev, child); + + if (dinfo->gpio_num >= GPIO_BASE) + printf(" gpio %d", dinfo->gpio_num - GPIO_BASE); + else if (dinfo->gpio_num >= GPIO_EXTINT_BASE) + printf(" extint-gpio %d", dinfo->gpio_num - GPIO_EXTINT_BASE); + else + printf(" addr 0x%02x", dinfo->gpio_num); /* should not happen */ - printf(" gpio %d",dinfo->gpio_num); resource_list_print_type(&dinfo->mdi_resources, "irq", SYS_RES_IRQ, "%ld"); retval += bus_print_child_footer(dev, child); Modified: head/sys/powerpc/powermac/macgpiovar.h ============================================================================== --- head/sys/powerpc/powermac/macgpiovar.h Mon Dec 8 02:48:41 2008 (r185756) +++ head/sys/powerpc/powermac/macgpiovar.h Mon Dec 8 03:00:45 2008 (r185757) @@ -9,8 +9,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -30,13 +28,15 @@ #ifndef _MACIO_MACGPIOVAR_H_ #define _MACIO_MACGPIOVAR_H_ -struct macgpio_devinfo { - struct ofw_bus_devinfo mdi_obdinfo; - struct resource_list mdi_resources; - - int gpio_num; -}; - +/* relative offsets into gpio space */ +#define GPIO_EXTINT_BASE 0x08 +#define GPIO_BASE 0x1a + +/* gpio bit definitions */ +#define GPIO_DATA 0x01 /* GPIO data */ +#define GPIO_LEVEL_RO 0x02 /* read-only level on pin */ +#define GPIO_DDR_INPUT 0x00 /* use for input */ +#define GPIO_DDR_OUTPUT 0x04 /* use for output */ uint8_t macgpio_read(device_t dev); void macgpio_write(device_t dev,uint8_t); From yongari at FreeBSD.org Sun Dec 7 19:48:03 2008 From: yongari at FreeBSD.org (Pyun YongHyeon) Date: Sun Dec 7 19:48:15 2008 Subject: svn commit: r185758 - head/sys/dev/fxp Message-ID: <200812080348.mB83m3Oi045959@svn.freebsd.org> Author: yongari Date: Mon Dec 8 03:48:03 2008 New Revision: 185758 URL: http://svn.freebsd.org/changeset/base/185758 Log: mutex.h is needed here. It got it by namespace pollution. Pointed out by: bde Modified: head/sys/dev/fxp/if_fxp.c Modified: head/sys/dev/fxp/if_fxp.c ============================================================================== --- head/sys/dev/fxp/if_fxp.c Mon Dec 8 03:00:45 2008 (r185757) +++ head/sys/dev/fxp/if_fxp.c Mon Dec 8 03:48:03 2008 (r185758) @@ -44,7 +44,9 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include +#include #include #include #include From junyoung at netbsd.org Sun Dec 7 21:47:25 2008 From: junyoung at netbsd.org (Bang Jun-young) Date: Sun Dec 7 21:47:30 2008 Subject: svn commit: r185674 - head/lib/libarchive In-Reply-To: <200812060612.mB66COVb084955@svn.freebsd.org> References: <200812060612.mB66COVb084955@svn.freebsd.org> Message-ID: On Sat, Dec 6, 2008 at 3:12 PM, Tim Kientzle wrote: > Author: kientzle > Date: Sat Dec 6 06:12:24 2008 > New Revision: 185674 > URL: http://svn.freebsd.org/changeset/base/185674 > > Log: > A couple of portability fixes from Joerg Sonnenberger > > Modified: > head/lib/libarchive/archive_endian.h > > Modified: head/lib/libarchive/archive_endian.h > ============================================================================== > --- head/lib/libarchive/archive_endian.h Sat Dec 6 06:08:12 2008 (r185673) > +++ head/lib/libarchive/archive_endian.h Sat Dec 6 06:12:24 2008 (r185674) > @@ -35,14 +35,14 @@ > #define ARCHIVE_ENDIAN_H_INCLUDED > > > -/* Watcom C++ doesn't support 'inline' in C code. (For any version?) */ > -#if defined( __WATCOMC__ ) > - #define inline > -#endif > - > -/* Visual C++ 6.0 doesn't support 'inline' in C code. (Does VC7? VC8?) */ > -#if defined(_MSC_VER) > - #define inline > +/* > + * Disabling inline keyword for compilers known to choke on it: > + * - Watcom C++ in C code. (For any version?) > + * - SGI MIPSpro > + * - Microsoft Visual C++ 6.0 (supposedly newer versions too) > + */ > +#if defined(__WATCOMC__) || defined(__sgi) || defined(_MSC_VER) > +#define inline > #endif MSC actually supports inline functions as '__inline' keyword in C mode. The above should be written as follows: #if defined(__WATCOMC__) || defined(__sgi) #define inline #elif defined(_MSC_VER) #define inline __inline #endif See http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx http://msdn.microsoft.com/en-us/library/aa260842.aspx for details. junyoung From kib at FreeBSD.org Mon Dec 8 03:04:17 2008 From: kib at FreeBSD.org (Konstantin Belousov) Date: Mon Dec 8 03:04:23 2008 Subject: svn commit: r185761 - head/sys/ufs/ufs Message-ID: <200812081104.mB8B4HwA058122@svn.freebsd.org> Author: kib Date: Mon Dec 8 11:04:17 2008 New Revision: 185761 URL: http://svn.freebsd.org/changeset/base/185761 Log: The dqrele() function syncs the dq, then acquires the dqh lock, and then does final drop of the the dq reference to put it onto the free list. There is a possibility that the dq would be found by another thread after sync and before the dqh lock is acquired. If that other thread drops the dq before we have taken the dqh lock, the dirty dq is put on the free list. Recheck the DQ_MOD after the dqh lock is relocked. Repeat dqsync() if the dq is dirty. This ensures that up to date dq is written in the quota file and fixes assertion in dqget(). Reported and tested by: Frode Nordahl MFC after: 3 days Modified: head/sys/ufs/ufs/ufs_quota.c Modified: head/sys/ufs/ufs/ufs_quota.c ============================================================================== --- head/sys/ufs/ufs/ufs_quota.c Mon Dec 8 06:54:24 2008 (r185760) +++ head/sys/ufs/ufs/ufs_quota.c Mon Dec 8 11:04:17 2008 (r185761) @@ -1262,7 +1262,7 @@ dqrele(struct vnode *vp, struct dquot *d return; } DQH_UNLOCK(); - +sync: (void) dqsync(vp, dq); DQH_LOCK(); @@ -1271,6 +1271,18 @@ dqrele(struct vnode *vp, struct dquot *d DQH_UNLOCK(); return; } + + /* + * The dq may become dirty after it is synced but before it is + * put to the free list. Checking the DQ_MOD there without + * locking dq should be safe since no other references to the + * dq exist. + */ + if ((dq->dq_flags & DQ_MOD) != 0) { + dq->dq_cnt++; + DQH_UNLOCK(); + goto sync; + } TAILQ_INSERT_TAIL(&dqfreelist, dq, dq_freelist); DQH_UNLOCK(); } From jkoshy at FreeBSD.org Mon Dec 8 04:28:49 2008 From: jkoshy at FreeBSD.org (Joseph Koshy) Date: Mon Dec 8 04:28:55 2008 Subject: svn commit: r185763 - head/lib/libpmc Message-ID: <200812081228.mB8CSm4o059941@svn.freebsd.org> Author: jkoshy Date: Mon Dec 8 12:28:48 2008 New Revision: 185763 URL: http://svn.freebsd.org/changeset/base/185763 Log: Document processor errata that affect performance measurement. Modified: head/lib/libpmc/pmc.core.3 Modified: head/lib/libpmc/pmc.core.3 ============================================================================== --- head/lib/libpmc/pmc.core.3 Mon Dec 8 12:04:00 2008 (r185762) +++ head/lib/libpmc/pmc.core.3 Mon Dec 8 12:28:48 2008 (r185763) @@ -730,6 +730,58 @@ and the underlying hardware events used. .It Li interrupts Ta Li HW_Int_Rx .It Li unhalted-cycles Ta (unsupported) .El +.Sh PROCESSOR ERRATA +The following errata affect performance measurement on these +processors. +These errata are documented in +.Rs +.%T "Intel® CoreTM Duo Processor and Intel® CoreTM Solo Processor on 65 nm Process" +.%B "Specification Update" +.%N "Order Number 309222-017" +.%D July 2008 +.%Q "Intel Corporation" +.Re +.Bl -tag -width indent -compact +.It AE19 +Data prefetch performance monitoring events can only be enabled +on a single core. +.It AE25 +Performance monitoring counters that count external bus events +may report incorrect values after processor power state transitions. +.It AE28 +Performance monitoring events for retired floating point operations +(C1H) may not be accurate. +.It AE29 +DR3 address match on MOVD/MOVQ/MOVNTQ memory store +instruction may incorrectly increment performance monitoring count +for saturating simd instructions retired (Event CFH). +.It AE33 +Hardware prefetch performance monitoring events may be counted +inaccurately. +.It AE36 +The +.Li CPU_CLK_UNHALTED +performance monitoring event (Event 3CH) counts +clocks when the processor is in the C1/C2 processor power states. +.It AE39 +Certain performance monitoring counters related to bus, L2 cache +and power management are inaccurate. +.It AE51 +Performance monitoring events for retired instructions (Event C0H) may +not be accurate. +.It AE67 +Performance monitoring event +.Li FP_ASSIST +may not be accurate. +.It AE78 +Performance monitoring event for hardware prefetch requests (Event +4EH) and hardware prefetch request cache misses (Event 4FH) may not be +accurate. +.It AE82 +Performance monitoring event +.Li FP_MMX_TRANS_TO_MMX +may not count some transitions. +.El .Sh SEE ALSO .Xr pmc 3 , .Xr pmc.atom 3 , From kib at FreeBSD.org Mon Dec 8 04:29:30 2008 From: kib at FreeBSD.org (Konstantin Belousov) Date: Mon Dec 8 04:29:36 2008 Subject: svn commit: r185764 - head/sys/kern Message-ID: <200812081229.mB8CTU1E060005@svn.freebsd.org> Author: kib Date: Mon Dec 8 12:29:30 2008 New Revision: 185764 URL: http://svn.freebsd.org/changeset/base/185764 Log: Do drop vm map lock earlier in the sysctl_kern_proc_vmmap(), to avoid locking a vnode while having vm map locked. Reported and tested by: pho MFC after: 1 week Modified: head/sys/kern/kern_proc.c Modified: head/sys/kern/kern_proc.c ============================================================================== --- head/sys/kern/kern_proc.c Mon Dec 8 12:28:48 2008 (r185763) +++ head/sys/kern/kern_proc.c Mon Dec 8 12:29:30 2008 (r185764) @@ -1412,13 +1412,32 @@ sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_A lobj = tobj; } + kve->kve_start = (void*)entry->start; + kve->kve_end = (void*)entry->end; + kve->kve_offset = (off_t)entry->offset; + + if (entry->protection & VM_PROT_READ) + kve->kve_protection |= KVME_PROT_READ; + if (entry->protection & VM_PROT_WRITE) + kve->kve_protection |= KVME_PROT_WRITE; + if (entry->protection & VM_PROT_EXECUTE) + kve->kve_protection |= KVME_PROT_EXEC; + + if (entry->eflags & MAP_ENTRY_COW) + kve->kve_flags |= KVME_FLAG_COW; + if (entry->eflags & MAP_ENTRY_NEEDS_COPY) + kve->kve_flags |= KVME_FLAG_NEEDS_COPY; + + last_timestamp = map->timestamp; + vm_map_unlock_read(map); + kve->kve_fileid = 0; kve->kve_fsid = 0; freepath = NULL; fullpath = ""; if (lobj) { vp = NULL; - switch(lobj->type) { + switch (lobj->type) { case OBJT_DEFAULT: kve->kve_type = KVME_TYPE_DEFAULT; break; @@ -1468,28 +1487,10 @@ sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_A kve->kve_shadow_count = 0; } - kve->kve_start = (void*)entry->start; - kve->kve_end = (void*)entry->end; - kve->kve_offset = (off_t)entry->offset; - - if (entry->protection & VM_PROT_READ) - kve->kve_protection |= KVME_PROT_READ; - if (entry->protection & VM_PROT_WRITE) - kve->kve_protection |= KVME_PROT_WRITE; - if (entry->protection & VM_PROT_EXECUTE) - kve->kve_protection |= KVME_PROT_EXEC; - - if (entry->eflags & MAP_ENTRY_COW) - kve->kve_flags |= KVME_FLAG_COW; - if (entry->eflags & MAP_ENTRY_NEEDS_COPY) - kve->kve_flags |= KVME_FLAG_NEEDS_COPY; - strlcpy(kve->kve_path, fullpath, sizeof(kve->kve_path)); if (freepath != NULL) free(freepath, M_TEMP); - last_timestamp = map->timestamp; - vm_map_unlock_read(map); error = SYSCTL_OUT(req, kve, sizeof(*kve)); vm_map_lock_read(map); if (error) @@ -1577,13 +1578,32 @@ sysctl_kern_proc_vmmap(SYSCTL_HANDLER_AR lobj = tobj; } + kve->kve_start = entry->start; + kve->kve_end = entry->end; + kve->kve_offset = entry->offset; + + if (entry->protection & VM_PROT_READ) + kve->kve_protection |= KVME_PROT_READ; + if (entry->protection & VM_PROT_WRITE) + kve->kve_protection |= KVME_PROT_WRITE; + if (entry->protection & VM_PROT_EXECUTE) + kve->kve_protection |= KVME_PROT_EXEC; + + if (entry->eflags & MAP_ENTRY_COW) + kve->kve_flags |= KVME_FLAG_COW; + if (entry->eflags & MAP_ENTRY_NEEDS_COPY) + kve->kve_flags |= KVME_FLAG_NEEDS_COPY; + + last_timestamp = map->timestamp; + vm_map_unlock_read(map); + kve->kve_fileid = 0; kve->kve_fsid = 0; freepath = NULL; fullpath = ""; if (lobj) { vp = NULL; - switch(lobj->type) { + switch (lobj->type) { case OBJT_DEFAULT: kve->kve_type = KVME_TYPE_DEFAULT; break; @@ -1633,28 +1653,10 @@ sysctl_kern_proc_vmmap(SYSCTL_HANDLER_AR kve->kve_shadow_count = 0; } - kve->kve_start = entry->start; - kve->kve_end = entry->end; - kve->kve_offset = entry->offset; - - if (entry->protection & VM_PROT_READ) - kve->kve_protection |= KVME_PROT_READ; - if (entry->protection & VM_PROT_WRITE) - kve->kve_protection |= KVME_PROT_WRITE; - if (entry->protection & VM_PROT_EXECUTE) - kve->kve_protection |= KVME_PROT_EXEC; - - if (entry->eflags & MAP_ENTRY_COW) - kve->kve_flags |= KVME_FLAG_COW; - if (entry->eflags & MAP_ENTRY_NEEDS_COPY) - kve->kve_flags |= KVME_FLAG_NEEDS_COPY; - strlcpy(kve->kve_path, fullpath, sizeof(kve->kve_path)); if (freepath != NULL) free(freepath, M_TEMP); - last_timestamp = map->timestamp; - vm_map_unlock_read(map); /* Pack record size down */ kve->kve_structsize = offsetof(struct kinfo_vmentry, kve_path) + strlen(kve->kve_path) + 1; From kib at FreeBSD.org Mon Dec 8 04:34:52 2008 From: kib at FreeBSD.org (Konstantin Belousov) Date: Mon Dec 8 04:34:58 2008 Subject: svn commit: r185765 - in head/sys: compat/linprocfs fs/procfs Message-ID: <200812081234.mB8CYqr0060148@svn.freebsd.org> Author: kib Date: Mon Dec 8 12:34:52 2008 New Revision: 185765 URL: http://svn.freebsd.org/changeset/base/185765 Log: Change the linprocfs /maps and procfs /map handlers to use sbuf instead of doing uiomove. This allows for reads from non-zero offsets to work. Patch is forward-ported des@' one, and was adopted to current code by dchagin@ and me. Reviewed by: des (linprocfs part) PR: kern/101453 MFC after: 1 week Modified: head/sys/compat/linprocfs/linprocfs.c head/sys/fs/procfs/procfs_map.c Modified: head/sys/compat/linprocfs/linprocfs.c ============================================================================== --- head/sys/compat/linprocfs/linprocfs.c Mon Dec 8 12:29:30 2008 (r185764) +++ head/sys/compat/linprocfs/linprocfs.c Mon Dec 8 12:34:52 2008 (r185765) @@ -876,10 +876,12 @@ static int linprocfs_doprocmaps(PFS_FILL_ARGS) { vm_map_t map = &p->p_vmspace->vm_map; - vm_map_entry_t entry; + vm_map_entry_t entry, tmp_entry; vm_object_t obj, tobj, lobj; - vm_offset_t saved_end; + vm_offset_t e_start, e_end; vm_ooffset_t off = 0; + vm_prot_t e_prot; + unsigned int last_timestamp; char *name = "", *freename = NULL; ino_t ino; int ref_count, shadow_count, flags; @@ -905,7 +907,9 @@ linprocfs_doprocmaps(PFS_FILL_ARGS) freename = NULL; if (entry->eflags & MAP_ENTRY_IS_SUB_MAP) continue; - saved_end = entry->end; + e_prot = entry->protection; + e_start = entry->start; + e_end = entry->end; obj = entry->object.vm_object; for (lobj = tobj = obj; tobj; tobj = tobj->backing_object) { VM_OBJECT_LOCK(tobj); @@ -913,6 +917,8 @@ linprocfs_doprocmaps(PFS_FILL_ARGS) VM_OBJECT_UNLOCK(lobj); lobj = tobj; } + last_timestamp = map->timestamp; + vm_map_unlock_read(map); ino = 0; if (lobj) { off = IDX_TO_OFF(lobj->size); @@ -950,10 +956,10 @@ linprocfs_doprocmaps(PFS_FILL_ARGS) */ error = sbuf_printf(sb, "%08lx-%08lx %s%s%s%s %08lx %02x:%02x %lu%s%s\n", - (u_long)entry->start, (u_long)entry->end, - (entry->protection & VM_PROT_READ)?"r":"-", - (entry->protection & VM_PROT_WRITE)?"w":"-", - (entry->protection & VM_PROT_EXECUTE)?"x":"-", + (u_long)e_start, (u_long)e_end, + (e_prot & VM_PROT_READ)?"r":"-", + (e_prot & VM_PROT_WRITE)?"w":"-", + (e_prot & VM_PROT_EXECUTE)?"x":"-", "p", (u_long)off, 0, @@ -968,6 +974,16 @@ linprocfs_doprocmaps(PFS_FILL_ARGS) error = 0; break; } + vm_map_lock_read(map); + if (last_timestamp + 1 != map->timestamp) { + /* + * Look again for the entry because the map was + * modified while it was unlocked. Specifically, + * the entry may have been clipped, merged, or deleted. + */ + vm_map_lookup_entry(map, e_end - 1, &tmp_entry); + entry = tmp_entry; + } } vm_map_unlock_read(map); Modified: head/sys/fs/procfs/procfs_map.c ============================================================================== --- head/sys/fs/procfs/procfs_map.c Mon Dec 8 12:29:30 2008 (r185764) +++ head/sys/fs/procfs/procfs_map.c Mon Dec 8 12:34:52 2008 (r185765) @@ -84,9 +84,10 @@ procfs_doprocmap(PFS_FILL_ARGS) { int error, vfslocked; vm_map_t map = &p->p_vmspace->vm_map; - vm_map_entry_t entry; + vm_map_entry_t entry, tmp_entry; struct vnode *vp; char *fullpath, *freepath; + unsigned int last_timestamp; #ifdef COMPAT_IA32 int wrap32 = 0; #endif @@ -113,13 +114,19 @@ procfs_doprocmap(PFS_FILL_ARGS) entry = entry->next) { vm_object_t obj, tobj, lobj; int ref_count, shadow_count, flags; - vm_offset_t addr; + vm_offset_t e_start, e_end, addr; int resident, privateresident; char *type; + vm_eflags_t e_eflags; + vm_prot_t e_prot; if (entry->eflags & MAP_ENTRY_IS_SUB_MAP) continue; + e_eflags = entry->eflags; + e_prot = entry->protection; + e_start = entry->start; + e_end = entry->end; privateresident = 0; obj = entry->object.vm_object; if (obj != NULL) { @@ -143,11 +150,13 @@ procfs_doprocmap(PFS_FILL_ARGS) VM_OBJECT_UNLOCK(lobj); lobj = tobj; } + last_timestamp = map->timestamp; + vm_map_unlock_read(map); freepath = NULL; fullpath = "-"; if (lobj) { - switch(lobj->type) { + switch (lobj->type) { default: case OBJT_DEFAULT: type = "default"; @@ -193,19 +202,19 @@ procfs_doprocmap(PFS_FILL_ARGS) */ error = sbuf_printf(sb, "0x%lx 0x%lx %d %d %p %s%s%s %d %d 0x%x %s %s %s %s\n", - (u_long)entry->start, (u_long)entry->end, + (u_long)e_start, (u_long)e_end, resident, privateresident, #ifdef COMPAT_IA32 wrap32 ? NULL : obj, /* Hide 64 bit value */ #else obj, #endif - (entry->protection & VM_PROT_READ)?"r":"-", - (entry->protection & VM_PROT_WRITE)?"w":"-", - (entry->protection & VM_PROT_EXECUTE)?"x":"-", + (e_prot & VM_PROT_READ)?"r":"-", + (e_prot & VM_PROT_WRITE)?"w":"-", + (e_prot & VM_PROT_EXECUTE)?"x":"-", ref_count, shadow_count, flags, - (entry->eflags & MAP_ENTRY_COW)?"COW":"NCOW", - (entry->eflags & MAP_ENTRY_NEEDS_COPY)?"NC":"NNC", + (e_eflags & MAP_ENTRY_COW)?"COW":"NCOW", + (e_eflags & MAP_ENTRY_NEEDS_COPY)?"NC":"NNC", type, fullpath); if (freepath != NULL) @@ -215,6 +224,16 @@ procfs_doprocmap(PFS_FILL_ARGS) error = 0; break; } + vm_map_lock_read(map); + if (last_timestamp + 1 != map->timestamp) { + /* + * Look again for the entry because the map was + * modified while it was unlocked. Specifically, + * the entry may have been clipped, merged, or deleted. + */ + vm_map_lookup_entry(map, e_end - 1, &tmp_entry); + entry = tmp_entry; + } } vm_map_unlock_read(map); return (error); From kostikbel at gmail.com Mon Dec 8 05:01:51 2008 From: kostikbel at gmail.com (Kostik Belousov) Date: Mon Dec 8 05:02:03 2008 Subject: svn commit: r185765 - in head/sys: compat/linprocfs fs/procfs In-Reply-To: <200812081234.mB8CYqr0060148@svn.freebsd.org> References: <200812081234.mB8CYqr0060148@svn.freebsd.org> Message-ID: <20081208130144.GU2038@deviant.kiev.zoral.com.ua> On Mon, Dec 08, 2008 at 12:34:52PM +0000, Konstantin Belousov wrote: > Author: kib > Date: Mon Dec 8 12:34:52 2008 > New Revision: 185765 > URL: http://svn.freebsd.org/changeset/base/185765 > > Log: > Change the linprocfs /maps and procfs /map handlers to use > sbuf instead of doing uiomove. This allows for reads from non-zero > offsets to work. > > Patch is forward-ported des@' one, and was adopted to current code > by dchagin@ and me. > > Reviewed by: des (linprocfs part) > PR: kern/101453 > MFC after: 1 week > > Modified: > head/sys/compat/linprocfs/linprocfs.c > head/sys/fs/procfs/procfs_map.c Thanks for Roman Divacky for pointing this out, commit message is wrong. I specified wrong log file to the svn ci -F switch. The right commit message is below. In procfs map handler, and in linprocfs maps handler, do not call vn_fullpath() while having vm map locked. This is done in anticipation of the vop_vptocnp commit, that would make vn_fullpath sometime acquire vnode lock. Also, in linprocfs, maps handler already acquires vnode lock. No objections from: des MFC after: 2 week > > Modified: head/sys/compat/linprocfs/linprocfs.c > ============================================================================== > --- head/sys/compat/linprocfs/linprocfs.c Mon Dec 8 12:29:30 2008 (r185764) > +++ head/sys/compat/linprocfs/linprocfs.c Mon Dec 8 12:34:52 2008 (r185765) > @@ -876,10 +876,12 @@ static int > linprocfs_doprocmaps(PFS_FILL_ARGS) > { > vm_map_t map = &p->p_vmspace->vm_map; > - vm_map_entry_t entry; > + vm_map_entry_t entry, tmp_entry; > vm_object_t obj, tobj, lobj; > - vm_offset_t saved_end; > + vm_offset_t e_start, e_end; > vm_ooffset_t off = 0; > + vm_prot_t e_prot; > + unsigned int last_timestamp; > char *name = "", *freename = NULL; > ino_t ino; > int ref_count, shadow_count, flags; > @@ -905,7 +907,9 @@ linprocfs_doprocmaps(PFS_FILL_ARGS) > freename = NULL; > if (entry->eflags & MAP_ENTRY_IS_SUB_MAP) > continue; > - saved_end = entry->end; > + e_prot = entry->protection; > + e_start = entry->start; > + e_end = entry->end; > obj = entry->object.vm_object; > for (lobj = tobj = obj; tobj; tobj = tobj->backing_object) { > VM_OBJECT_LOCK(tobj); > @@ -913,6 +917,8 @@ linprocfs_doprocmaps(PFS_FILL_ARGS) > VM_OBJECT_UNLOCK(lobj); > lobj = tobj; > } > + last_timestamp = map->timestamp; > + vm_map_unlock_read(map); > ino = 0; > if (lobj) { > off = IDX_TO_OFF(lobj->size); > @@ -950,10 +956,10 @@ linprocfs_doprocmaps(PFS_FILL_ARGS) > */ > error = sbuf_printf(sb, > "%08lx-%08lx %s%s%s%s %08lx %02x:%02x %lu%s%s\n", > - (u_long)entry->start, (u_long)entry->end, > - (entry->protection & VM_PROT_READ)?"r":"-", > - (entry->protection & VM_PROT_WRITE)?"w":"-", > - (entry->protection & VM_PROT_EXECUTE)?"x":"-", > + (u_long)e_start, (u_long)e_end, > + (e_prot & VM_PROT_READ)?"r":"-", > + (e_prot & VM_PROT_WRITE)?"w":"-", > + (e_prot & VM_PROT_EXECUTE)?"x":"-", > "p", > (u_long)off, > 0, > @@ -968,6 +974,16 @@ linprocfs_doprocmaps(PFS_FILL_ARGS) > error = 0; > break; > } > + vm_map_lock_read(map); > + if (last_timestamp + 1 != map->timestamp) { > + /* > + * Look again for the entry because the map was > + * modified while it was unlocked. Specifically, > + * the entry may have been clipped, merged, or deleted. > + */ > + vm_map_lookup_entry(map, e_end - 1, &tmp_entry); > + entry = tmp_entry; > + } > } > vm_map_unlock_read(map); > > > Modified: head/sys/fs/procfs/procfs_map.c > ============================================================================== > --- head/sys/fs/procfs/procfs_map.c Mon Dec 8 12:29:30 2008 (r185764) > +++ head/sys/fs/procfs/procfs_map.c Mon Dec 8 12:34:52 2008 (r185765) > @@ -84,9 +84,10 @@ procfs_doprocmap(PFS_FILL_ARGS) > { > int error, vfslocked; > vm_map_t map = &p->p_vmspace->vm_map; > - vm_map_entry_t entry; > + vm_map_entry_t entry, tmp_entry; > struct vnode *vp; > char *fullpath, *freepath; > + unsigned int last_timestamp; > #ifdef COMPAT_IA32 > int wrap32 = 0; > #endif > @@ -113,13 +114,19 @@ procfs_doprocmap(PFS_FILL_ARGS) > entry = entry->next) { > vm_object_t obj, tobj, lobj; > int ref_count, shadow_count, flags; > - vm_offset_t addr; > + vm_offset_t e_start, e_end, addr; > int resident, privateresident; > char *type; > + vm_eflags_t e_eflags; > + vm_prot_t e_prot; > > if (entry->eflags & MAP_ENTRY_IS_SUB_MAP) > continue; > > + e_eflags = entry->eflags; > + e_prot = entry->protection; > + e_start = entry->start; > + e_end = entry->end; > privateresident = 0; > obj = entry->object.vm_object; > if (obj != NULL) { > @@ -143,11 +150,13 @@ procfs_doprocmap(PFS_FILL_ARGS) > VM_OBJECT_UNLOCK(lobj); > lobj = tobj; > } > + last_timestamp = map->timestamp; > + vm_map_unlock_read(map); > > freepath = NULL; > fullpath = "-"; > if (lobj) { > - switch(lobj->type) { > + switch (lobj->type) { > default: > case OBJT_DEFAULT: > type = "default"; > @@ -193,19 +202,19 @@ procfs_doprocmap(PFS_FILL_ARGS) > */ > error = sbuf_printf(sb, > "0x%lx 0x%lx %d %d %p %s%s%s %d %d 0x%x %s %s %s %s\n", > - (u_long)entry->start, (u_long)entry->end, > + (u_long)e_start, (u_long)e_end, > resident, privateresident, > #ifdef COMPAT_IA32 > wrap32 ? NULL : obj, /* Hide 64 bit value */ > #else > obj, > #endif > - (entry->protection & VM_PROT_READ)?"r":"-", > - (entry->protection & VM_PROT_WRITE)?"w":"-", > - (entry->protection & VM_PROT_EXECUTE)?"x":"-", > + (e_prot & VM_PROT_READ)?"r":"-", > + (e_prot & VM_PROT_WRITE)?"w":"-", > + (e_prot & VM_PROT_EXECUTE)?"x":"-", > ref_count, shadow_count, flags, > - (entry->eflags & MAP_ENTRY_COW)?"COW":"NCOW", > - (entry->eflags & MAP_ENTRY_NEEDS_COPY)?"NC":"NNC", > + (e_eflags & MAP_ENTRY_COW)?"COW":"NCOW", > + (e_eflags & MAP_ENTRY_NEEDS_COPY)?"NC":"NNC", > type, fullpath); > > if (freepath != NULL) > @@ -215,6 +224,16 @@ procfs_doprocmap(PFS_FILL_ARGS) > error = 0; > break; > } > + vm_map_lock_read(map); > + if (last_timestamp + 1 != map->timestamp) { > + /* > + * Look again for the entry because the map was > + * modified while it was unlocked. Specifically, > + * the entry may have been clipped, merged, or deleted. > + */ > + vm_map_lookup_entry(map, e_end - 1, &tmp_entry); > + entry = tmp_entry; > + } > } > vm_map_unlock_read(map); > return (error); -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 195 bytes Desc: not available Url : http://lists.freebsd.org/pipermail/svn-src-head/attachments/20081208/513d2cd6/attachment.pgp From des at des.no Mon Dec 8 05:08:42 2008 From: des at des.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Mon Dec 8 05:08:54 2008