CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Mon Aug 26 15:50:15 UTC 2024 Modified Files: src/sys/kern: kern_entropy.c Log Message: entropy(9): Allow unprivileged reads of sysctl kern.entropy.epoch. Applications need this in order to know when to reseed. (We should also expose it through a page shared read-only with userland for cheaper access, but until we do, let's let applications get at it through sysctl.) PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM fork To generate a diff of this commit: cvs rdiff -u -r1.70 -r1.71 src/sys/kern/kern_entropy.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_entropy.c diff -u src/sys/kern/kern_entropy.c:1.70 src/sys/kern/kern_entropy.c:1.71 --- src/sys/kern/kern_entropy.c:1.70 Mon Aug 26 13:52:56 2024 +++ src/sys/kern/kern_entropy.c Mon Aug 26 15:50:15 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_entropy.c,v 1.70 2024/08/26 13:52:56 riastradh Exp $ */ +/* $NetBSD: kern_entropy.c,v 1.71 2024/08/26 15:50:15 riastradh Exp $ */ /*- * Copyright (c) 2019 The NetBSD Foundation, Inc. @@ -77,7 +77,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.70 2024/08/26 13:52:56 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.71 2024/08/26 15:50:15 riastradh Exp $"); #include #include @@ -400,7 +400,7 @@ entropy_init(void) SYSCTL_DESCR("Number of samples pending on CPUs"), NULL, 0, &E->samplespending, 0, CTL_CREATE, CTL_EOL); sysctl_createv(&entropy_sysctllog, 0, &entropy_sysctlroot, NULL, - CTLFLAG_PERMANENT|CTLFLAG_READONLY|CTLFLAG_PRIVATE, CTLTYPE_INT, + CTLFLAG_PERMANENT|CTLFLAG_READONLY, CTLTYPE_INT, "epoch", SYSCTL_DESCR("Entropy epoch"), NULL, 0, &E->epoch, 0, CTL_CREATE, CTL_EOL);
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Mon Aug 26 15:50:15 UTC 2024 Modified Files: src/sys/kern: kern_entropy.c Log Message: entropy(9): Allow unprivileged reads of sysctl kern.entropy.epoch. Applications need this in order to know when to reseed. (We should also expose it through a page shared read-only with userland for cheaper access, but until we do, let's let applications get at it through sysctl.) PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM fork To generate a diff of this commit: cvs rdiff -u -r1.70 -r1.71 src/sys/kern/kern_entropy.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Mon Aug 26 13:48:04 UTC 2024 Modified Files: src/sys/kern: kern_entropy.c Log Message: kern.entropy.gather: Fail with EINTR on signal. Just don't throw away the error code we already have! PR kern/58646: /dev/random, kern.entropy.*: signal bugs To generate a diff of this commit: cvs rdiff -u -r1.68 -r1.69 src/sys/kern/kern_entropy.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_entropy.c diff -u src/sys/kern/kern_entropy.c:1.68 src/sys/kern/kern_entropy.c:1.69 --- src/sys/kern/kern_entropy.c:1.68 Mon Aug 26 13:47:52 2024 +++ src/sys/kern/kern_entropy.c Mon Aug 26 13:48:04 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_entropy.c,v 1.68 2024/08/26 13:47:52 riastradh Exp $ */ +/* $NetBSD: kern_entropy.c,v 1.69 2024/08/26 13:48:04 riastradh Exp $ */ /*- * Copyright (c) 2019 The NetBSD Foundation, Inc. @@ -77,7 +77,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.68 2024/08/26 13:47:52 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.69 2024/08/26 13:48:04 riastradh Exp $"); #include #include @@ -1450,7 +1450,7 @@ sysctl_entropy_gather(SYSCTLFN_ARGS) mutex_exit(&E->lock); } - return 0; + return error; } /*
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Mon Aug 26 13:48:04 UTC 2024 Modified Files: src/sys/kern: kern_entropy.c Log Message: kern.entropy.gather: Fail with EINTR on signal. Just don't throw away the error code we already have! PR kern/58646: /dev/random, kern.entropy.*: signal bugs To generate a diff of this commit: cvs rdiff -u -r1.68 -r1.69 src/sys/kern/kern_entropy.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Mon Aug 26 13:47:52 UTC 2024 Modified Files: src/sys/kern: kern_entropy.c Log Message: kern.entropy.consolidate, ioctl(RNDCTL): Fail with EINTR on signal. This can happen if another thread is currently running consolidation and has the entropy source lock held. Use the new function entropy_consolidate_sig to get at EINTR. PR kern/58646: /dev/random, kern.entropy.*: signal bugs To generate a diff of this commit: cvs rdiff -u -r1.67 -r1.68 src/sys/kern/kern_entropy.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_entropy.c diff -u src/sys/kern/kern_entropy.c:1.67 src/sys/kern/kern_entropy.c:1.68 --- src/sys/kern/kern_entropy.c:1.67 Mon Aug 26 13:46:03 2024 +++ src/sys/kern/kern_entropy.c Mon Aug 26 13:47:52 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_entropy.c,v 1.67 2024/08/26 13:46:03 riastradh Exp $ */ +/* $NetBSD: kern_entropy.c,v 1.68 2024/08/26 13:47:52 riastradh Exp $ */ /*- * Copyright (c) 2019 The NetBSD Foundation, Inc. @@ -77,7 +77,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.67 2024/08/26 13:46:03 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.68 2024/08/26 13:47:52 riastradh Exp $"); #include #include @@ -1420,7 +1420,7 @@ sysctl_entropy_consolidate(SYSCTLFN_ARGS if (error || newp == NULL) return error; if (arg) - entropy_consolidate(); + error = entropy_consolidate_sig(); return error; } @@ -2793,7 +2793,7 @@ entropy_ioctl(unsigned long cmd, void *d /* Enter the data and consolidate entropy. */ rnd_add_data(&seed_rndsource, rdata->data, rdata->len, entropybits); - entropy_consolidate(); + error = entropy_consolidate_sig(); break; } default:
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Mon Aug 26 13:47:52 UTC 2024 Modified Files: src/sys/kern: kern_entropy.c Log Message: kern.entropy.consolidate, ioctl(RNDCTL): Fail with EINTR on signal. This can happen if another thread is currently running consolidation and has the entropy source lock held. Use the new function entropy_consolidate_sig to get at EINTR. PR kern/58646: /dev/random, kern.entropy.*: signal bugs To generate a diff of this commit: cvs rdiff -u -r1.67 -r1.68 src/sys/kern/kern_entropy.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Sun Aug 25 01:14:01 UTC 2024 Modified Files: src/sys/kern: kern_heartbeat.c Log Message: heartbeat(9): Use the cheaper and equally safe time_uptime32. Since we cache this every 15sec, and check it within a tick, there's no way for this to wrap around without first triggering a heartbeat panic. So just use time_uptime32, the low 32 bits of the number of seconds of uptime -- cheaper on LP32 platforms. PR kern/58633: heartbeat(9) makes unnecessary use of time_uptime To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sys/kern/kern_heartbeat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_heartbeat.c diff -u src/sys/kern/kern_heartbeat.c:1.13 src/sys/kern/kern_heartbeat.c:1.14 --- src/sys/kern/kern_heartbeat.c:1.13 Fri Mar 8 23:34:03 2024 +++ src/sys/kern/kern_heartbeat.c Sun Aug 25 01:14:01 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_heartbeat.c,v 1.13 2024/03/08 23:34:03 riastradh Exp $ */ +/* $NetBSD: kern_heartbeat.c,v 1.14 2024/08/25 01:14:01 riastradh Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -82,7 +82,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.13 2024/03/08 23:34:03 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.14 2024/08/25 01:14:01 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_ddb.h" @@ -170,7 +170,7 @@ heartbeat_resume_cpu(struct cpu_info *ci /* XXX KASSERT IPL_SCHED */ ci->ci_heartbeat_count = 0; - ci->ci_heartbeat_uptime_cache = time_uptime; + ci->ci_heartbeat_uptime_cache = time_uptime32; ci->ci_heartbeat_uptime_stamp = 0; } @@ -283,7 +283,7 @@ set_max_period(unsigned max_period) /* * If we're enabling heartbeat checks, make sure we have a - * reasonably up-to-date time_uptime cache on all CPUs so we + * reasonably up-to-date time_uptime32 cache on all CPUs so we * don't think we had an instant heart attack. */ if (heartbeat_max_period_secs == 0 && max_period != 0) { @@ -406,7 +406,7 @@ static void heartbeat_intr(void *cookie) { unsigned count = atomic_load_relaxed(&curcpu()->ci_heartbeat_count); - unsigned uptime = time_uptime; + unsigned uptime = time_uptime32; atomic_store_relaxed(&curcpu()->ci_heartbeat_uptime_stamp, count); atomic_store_relaxed(&curcpu()->ci_heartbeat_uptime_cache, uptime); @@ -420,7 +420,15 @@ heartbeat_intr(void *cookie) void heartbeat_start(void) { - const unsigned max_period = HEARTBEAT_MAX_PERIOD_DEFAULT; + enum { max_period = HEARTBEAT_MAX_PERIOD_DEFAULT }; + + /* + * Ensure the maximum period is small enough that we never have + * to worry about 32-bit wraparound even if there's a lot of + * slop. (In fact this is required to be less than + * UINT_MAX/4/hz, but that's not a compile-time constant.) + */ + __CTASSERT(max_period < UINT_MAX/4); /* * Establish a softint so we can schedule it once ready. This @@ -433,7 +441,7 @@ heartbeat_start(void) /* * Now that the softint is established, kick off heartbeat * monitoring with the default period. This will initialize - * the per-CPU state to an up-to-date cache of time_uptime. + * the per-CPU state to an up-to-date cache of time_uptime32. */ mutex_enter(&heartbeat_lock); set_max_period(max_period); @@ -651,7 +659,7 @@ heartbeat(void) * changed, and stop here -- we only do the cross-CPU work once * per second. */ - uptime = time_uptime; + uptime = time_uptime32; cache = atomic_load_relaxed(&curcpu()->ci_heartbeat_uptime_cache); if (__predict_true(cache == uptime)) { /* @@ -661,7 +669,7 @@ heartbeat(void) * suspended too. * * Our own heartbeat count can't roll back, and - * time_uptime should be updated before it wraps + * time_uptime32 should be updated before it wraps * around, so d should never go negative; hence no * check for d < UINT_MAX/2. */ @@ -679,8 +687,10 @@ heartbeat(void) /* * If the uptime has changed, make sure that it hasn't changed * so much that softints must be stuck on this CPU. Since - * time_uptime is monotonic, this can't go negative, hence no - * check for d < UINT_MAX/2. + * time_uptime32 is monotonic and our cache of it is updated at + * most every UINT_MAX/4/hz sec (hence no concern about + * wraparound even after 68 or 136 years), this can't go + * negative, hence no check for d < UINT_MAX/2. * * This uses the hard timer interrupt handler on the current * CPU to ensure soft interrupts at all priority levels have
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Sun Aug 25 01:14:01 UTC 2024 Modified Files: src/sys/kern: kern_heartbeat.c Log Message: heartbeat(9): Use the cheaper and equally safe time_uptime32. Since we cache this every 15sec, and check it within a tick, there's no way for this to wrap around without first triggering a heartbeat panic. So just use time_uptime32, the low 32 bits of the number of seconds of uptime -- cheaper on LP32 platforms. PR kern/58633: heartbeat(9) makes unnecessary use of time_uptime To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sys/kern/kern_heartbeat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Fri Aug 16 21:54:17 UTC 2024 Modified Files: src/sys/kern: subr_localcount.c Log Message: localcount: Update per-CPU total at splhigh. Otherwise localcount_acquire/release in interrupt context may lose counts. Duration spent at splhigh is very short. PR kern/58610: localcount(9) races with interrupts To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/kern/subr_localcount.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_localcount.c diff -u src/sys/kern/subr_localcount.c:1.7 src/sys/kern/subr_localcount.c:1.8 --- src/sys/kern/subr_localcount.c:1.7 Fri Nov 17 09:26:36 2017 +++ src/sys/kern/subr_localcount.c Fri Aug 16 21:54:17 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_localcount.c,v 1.7 2017/11/17 09:26:36 ozaki-r Exp $ */ +/* $NetBSD: subr_localcount.c,v 1.8 2024/08/16 21:54:17 riastradh Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -44,7 +44,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_localcount.c,v 1.7 2017/11/17 09:26:36 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_localcount.c,v 1.8 2024/08/16 21:54:17 riastradh Exp $"); #include #include @@ -161,11 +161,14 @@ localcount_xc(void *cookie0, void *cooki struct localcount *lc = cookie0; kmutex_t *interlock = cookie1; int64_t *localp; + int s; mutex_enter(interlock); localp = percpu_getref(lc->lc_percpu); + s = splhigh(); *lc->lc_totalp += *localp; *localp -= *localp; /* ie, *localp = 0; */ + splx(s); percpu_putref(lc->lc_percpu); mutex_exit(interlock); } @@ -180,9 +183,12 @@ static void localcount_adjust(struct localcount *lc, int delta) { int64_t *localp; + int s; localp = percpu_getref(lc->lc_percpu); + s = splhigh(); *localp += delta; + splx(s); percpu_putref(lc->lc_percpu); }
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Fri Aug 16 21:54:17 UTC 2024 Modified Files: src/sys/kern: subr_localcount.c Log Message: localcount: Update per-CPU total at splhigh. Otherwise localcount_acquire/release in interrupt context may lose counts. Duration spent at splhigh is very short. PR kern/58610: localcount(9) races with interrupts To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/kern/subr_localcount.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Fri Aug 16 20:11:18 UTC 2024 Modified Files: src/sys/kern: subr_devsw.c Log Message: devsw(9): Don't leak devsw reference on open d_devtounit failure. PR kern/56816: Deadlock: sleep during unloading module with kernconfig_lock being held To generate a diff of this commit: cvs rdiff -u -r1.51 -r1.52 src/sys/kern/subr_devsw.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_devsw.c diff -u src/sys/kern/subr_devsw.c:1.51 src/sys/kern/subr_devsw.c:1.52 --- src/sys/kern/subr_devsw.c:1.51 Wed Feb 15 13:12:45 2023 +++ src/sys/kern/subr_devsw.c Fri Aug 16 20:11:18 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_devsw.c,v 1.51 2023/02/15 13:12:45 riastradh Exp $ */ +/* $NetBSD: subr_devsw.c,v 1.52 2024/08/16 20:11:18 riastradh Exp $ */ /*- * Copyright (c) 2001, 2002, 2007, 2008 The NetBSD Foundation, Inc. @@ -69,7 +69,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.51 2023/02/15 13:12:45 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.52 2024/08/16 20:11:18 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_dtrace.h" @@ -1181,10 +1181,15 @@ bdev_open(dev_t dev, int flag, int devty * reviewing them all to find and verify a common * pattern. */ - if ((unit = (*d->d_devtounit)(dev)) == -1) - return ENXIO; - if ((dv = device_lookup_acquire(d->d_cfdriver, unit)) == NULL) - return ENXIO; + if ((unit = (*d->d_devtounit)(dev)) == -1) { + rv = ENXIO; + goto out; + } + if ((dv = device_lookup_acquire(d->d_cfdriver, unit)) == + NULL) { + rv = ENXIO; + goto out; + } SDT_PROBE6(sdt, bdev, open, acquire, d, dev, flag, devtype, unit, dv); } @@ -1201,7 +1206,7 @@ bdev_open(dev_t dev, int flag, int devty device_release(dv); } - bdevsw_release(d, lc); +out: bdevsw_release(d, lc); return rv; } @@ -1412,10 +1417,15 @@ cdev_open(dev_t dev, int flag, int devty * reviewing them all to find and verify a common * pattern. */ - if ((unit = (*d->d_devtounit)(dev)) == -1) - return ENXIO; - if ((dv = device_lookup_acquire(d->d_cfdriver, unit)) == NULL) - return ENXIO; + if ((unit = (*d->d_devtounit)(dev)) == -1) { + rv = ENXIO; + goto out; + } + if ((dv = device_lookup_acquire(d->d_cfdriver, unit)) == + NULL) { + rv = ENXIO; + goto out; + } SDT_PROBE6(sdt, cdev, open, acquire, d, dev, flag, devtype, unit, dv); } @@ -1432,7 +1442,7 @@ cdev_open(dev_t dev, int flag, int devty device_release(dv); } - cdevsw_release(d, lc); +out: cdevsw_release(d, lc); return rv; }
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Fri Aug 16 20:11:18 UTC 2024 Modified Files: src/sys/kern: subr_devsw.c Log Message: devsw(9): Don't leak devsw reference on open d_devtounit failure. PR kern/56816: Deadlock: sleep during unloading module with kernconfig_lock being held To generate a diff of this commit: cvs rdiff -u -r1.51 -r1.52 src/sys/kern/subr_devsw.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: bad Date: Sun Aug 11 13:43:20 UTC 2024 Modified Files: src/sys/kern: vfs_syscalls.c Log Message: tweak restoration of asyncflag Simply update mp->mnt_flag with asyncflag as it contains the correct value. Use the same pattern as in the other two places (vfs_syscalls.c, ffs_wapbl.c). NFC. To generate a diff of this commit: cvs rdiff -u -r1.567 -r1.568 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_syscalls.c diff -u src/sys/kern/vfs_syscalls.c:1.567 src/sys/kern/vfs_syscalls.c:1.568 --- src/sys/kern/vfs_syscalls.c:1.567 Sun Aug 11 13:09:58 2024 +++ src/sys/kern/vfs_syscalls.c Sun Aug 11 13:43:20 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.567 2024/08/11 13:09:58 bad Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.568 2024/08/11 13:43:20 bad Exp $ */ /*- * Copyright (c) 2008, 2009, 2019, 2020, 2023 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.567 2024/08/11 13:09:58 bad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.568 2024/08/11 13:43:20 bad Exp $"); #ifdef _KERNEL_OPT #include "opt_fileassoc.h" @@ -749,8 +749,7 @@ do_sys_sync(struct lwp *l) asyncflag = mp->mnt_flag & MNT_ASYNC; mp->mnt_flag &= ~MNT_ASYNC; VFS_SYNC(mp, MNT_NOWAIT, l->l_cred); - if (asyncflag) - mp->mnt_flag |= MNT_ASYNC; + mp->mnt_flag |= asyncflag; } mutex_exit(mp->mnt_updating); }
CVS commit: src/sys/kern
Module Name:src Committed By: bad Date: Sun Aug 11 13:43:20 UTC 2024 Modified Files: src/sys/kern: vfs_syscalls.c Log Message: tweak restoration of asyncflag Simply update mp->mnt_flag with asyncflag as it contains the correct value. Use the same pattern as in the other two places (vfs_syscalls.c, ffs_wapbl.c). NFC. To generate a diff of this commit: cvs rdiff -u -r1.567 -r1.568 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: bad Date: Sun Aug 11 13:09:58 UTC 2024 Modified Files: src/sys/kern: vfs_mount.c vfs_syscalls.c Log Message: explain why MNT_ASYNC is temporarily cleared related to PR kern/58564. To generate a diff of this commit: cvs rdiff -u -r1.106 -r1.107 src/sys/kern/vfs_mount.c cvs rdiff -u -r1.566 -r1.567 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_mount.c diff -u src/sys/kern/vfs_mount.c:1.106 src/sys/kern/vfs_mount.c:1.107 --- src/sys/kern/vfs_mount.c:1.106 Sun Aug 11 12:58:10 2024 +++ src/sys/kern/vfs_mount.c Sun Aug 11 13:09:58 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_mount.c,v 1.106 2024/08/11 12:58:10 bad Exp $ */ +/* $NetBSD: vfs_mount.c,v 1.107 2024/08/11 13:09:58 bad Exp $ */ /*- * Copyright (c) 1997-2020 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.106 2024/08/11 12:58:10 bad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.107 2024/08/11 13:09:58 bad Exp $"); #include "veriexec.h" @@ -961,6 +961,10 @@ dounmount(struct mount *mp, int flags, s mp->mnt_iflag |= IMNT_UNMOUNT; mutex_enter(mp->mnt_updating); + /* + * Temporarily clear the MNT_ASYNC flags so that bwrite() doesn't + * convert the sync writes to delayed writes. + */ async = mp->mnt_flag & MNT_ASYNC; mp->mnt_flag &= ~MNT_ASYNC; cache_purgevfs(mp); /* remove cache entries for this file sys */ Index: src/sys/kern/vfs_syscalls.c diff -u src/sys/kern/vfs_syscalls.c:1.566 src/sys/kern/vfs_syscalls.c:1.567 --- src/sys/kern/vfs_syscalls.c:1.566 Thu Jul 4 16:42:37 2024 +++ src/sys/kern/vfs_syscalls.c Sun Aug 11 13:09:58 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.566 2024/07/04 16:42:37 christos Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.567 2024/08/11 13:09:58 bad Exp $ */ /*- * Copyright (c) 2008, 2009, 2019, 2020, 2023 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.566 2024/07/04 16:42:37 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.567 2024/08/11 13:09:58 bad Exp $"); #ifdef _KERNEL_OPT #include "opt_fileassoc.h" @@ -741,6 +741,11 @@ do_sys_sync(struct lwp *l) while ((mp = mountlist_iterator_next(iter)) != NULL) { mutex_enter(mp->mnt_updating); if ((mp->mnt_flag & MNT_RDONLY) == 0) { + /* + * Temporarily clear the MNT_ASYNC flags so that + * bwrite() doesnt convert the sync writes to + * delayed writes. + */ asyncflag = mp->mnt_flag & MNT_ASYNC; mp->mnt_flag &= ~MNT_ASYNC; VFS_SYNC(mp, MNT_NOWAIT, l->l_cred);
CVS commit: src/sys/kern
Module Name:src Committed By: bad Date: Sun Aug 11 13:09:58 UTC 2024 Modified Files: src/sys/kern: vfs_mount.c vfs_syscalls.c Log Message: explain why MNT_ASYNC is temporarily cleared related to PR kern/58564. To generate a diff of this commit: cvs rdiff -u -r1.106 -r1.107 src/sys/kern/vfs_mount.c cvs rdiff -u -r1.566 -r1.567 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: christos Date: Thu Jul 4 16:42:38 UTC 2024 Modified Files: src/sys/kern: vfs_syscalls.c Log Message: use the proper kernel pointer To generate a diff of this commit: cvs rdiff -u -r1.565 -r1.566 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_syscalls.c diff -u src/sys/kern/vfs_syscalls.c:1.565 src/sys/kern/vfs_syscalls.c:1.566 --- src/sys/kern/vfs_syscalls.c:1.565 Thu Jul 4 01:59:05 2024 +++ src/sys/kern/vfs_syscalls.c Thu Jul 4 12:42:37 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.565 2024/07/04 05:59:05 mrg Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.566 2024/07/04 16:42:37 christos Exp $ */ /*- * Copyright (c) 2008, 2009, 2019, 2020, 2023 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.565 2024/07/04 05:59:05 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.566 2024/07/04 16:42:37 christos Exp $"); #ifdef _KERNEL_OPT #include "opt_fileassoc.h" @@ -279,7 +279,7 @@ fd_nameiat_simple_user(struct lwp *l, in error = nameiat_simple(dvp, pb, sflags, vp_ret); - if (fdat != AT_FDCWD && path[0] != '/') + if (fdat != AT_FDCWD && p[0] != '/') fd_putfile(fdat); out:
CVS commit: src/sys/kern
Module Name:src Committed By: christos Date: Thu Jul 4 16:42:38 UTC 2024 Modified Files: src/sys/kern: vfs_syscalls.c Log Message: use the proper kernel pointer To generate a diff of this commit: cvs rdiff -u -r1.565 -r1.566 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Re: CVS commit: src/sys/kern
> Module Name:src > Committed By: mrg > Date: Thu Jul 4 05:59:05 UTC 2024 > > Modified Files: > src/sys/kern: vfs_syscalls.c > > Log Message: > don't fd_putfile() if you haven't grabbed a ref already. > > the condition to call fd_getvnode() was changed, but the condition > to call fd_putfile() afterwards was not changed, leading to a panic > seen by Chavdar on current-users, probably. > > builds, runs, seems obvious. The automatic testbed is failing to run tests to completion now: https://releng.netbsd.org/b5reports/i386/commits-2024.07.html#2024.07.04.05.59.05 Our sloppy process for fixing the vfs_syscalls.c issue is obviously failing now, after days of flailing around with band-aids. I propose to back out all of the recent changes: https://mail-index.netbsd.org/source-changes/2024/06/29/msg152020.html https://mail-index.netbsd.org/source-changes/2024/07/01/msg152081.html https://mail-index.netbsd.org/source-changes/2024/07/01/msg152082.html https://mail-index.netbsd.org/source-changes/2024/07/01/msg152083.html https://mail-index.netbsd.org/source-changes/2024/07/04/msg152216.html And then redo them with: 1. A PR that explains the problem, with references, and can track the changes in case we need to pull them up. 2. Posting the patch for public review first. 3. Adding automatic tests that exercise all the relevant cases and xfail, but that would pass with the fix. 4. _Then_ committing the fix.
CVS commit: src/sys/kern
Module Name:src Committed By: mrg Date: Thu Jul 4 05:59:05 UTC 2024 Modified Files: src/sys/kern: vfs_syscalls.c Log Message: don't fd_putfile() if you haven't grabbed a ref already. the condition to call fd_getvnode() was changed, but the condition to call fd_putfile() afterwards was not changed, leading to a panic seen by Chavdar on current-users, probably. builds, runs, seems obvious. To generate a diff of this commit: cvs rdiff -u -r1.564 -r1.565 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_syscalls.c diff -u src/sys/kern/vfs_syscalls.c:1.564 src/sys/kern/vfs_syscalls.c:1.565 --- src/sys/kern/vfs_syscalls.c:1.564 Mon Jul 1 00:58:04 2024 +++ src/sys/kern/vfs_syscalls.c Thu Jul 4 05:59:05 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.564 2024/07/01 00:58:04 christos Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.565 2024/07/04 05:59:05 mrg Exp $ */ /*- * Copyright (c) 2008, 2009, 2019, 2020, 2023 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.564 2024/07/01 00:58:04 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.565 2024/07/04 05:59:05 mrg Exp $"); #ifdef _KERNEL_OPT #include "opt_fileassoc.h" @@ -245,7 +245,7 @@ fd_nameiat(struct lwp *l, int fdat, stru error = namei(ndp); - if (fdat != AT_FDCWD) + if (fdat != AT_FDCWD && path[0] != '/') fd_putfile(fdat); out: pathbuf_stringcopy_put(ndp->ni_pathbuf, path); @@ -279,7 +279,7 @@ fd_nameiat_simple_user(struct lwp *l, in error = nameiat_simple(dvp, pb, sflags, vp_ret); - if (fdat != AT_FDCWD) + if (fdat != AT_FDCWD && path[0] != '/') fd_putfile(fdat); out:
CVS commit: src/sys/kern
Module Name:src Committed By: mrg Date: Thu Jul 4 05:59:05 UTC 2024 Modified Files: src/sys/kern: vfs_syscalls.c Log Message: don't fd_putfile() if you haven't grabbed a ref already. the condition to call fd_getvnode() was changed, but the condition to call fd_putfile() afterwards was not changed, leading to a panic seen by Chavdar on current-users, probably. builds, runs, seems obvious. To generate a diff of this commit: cvs rdiff -u -r1.564 -r1.565 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: christos Date: Mon Jul 1 00:51:11 UTC 2024 Modified Files: src/sys/kern: vfs_syscalls.c Log Message: remove the part of previous that crashes for now. To generate a diff of this commit: cvs rdiff -u -r1.562 -r1.563 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: christos Date: Mon Jul 1 00:51:11 UTC 2024 Modified Files: src/sys/kern: vfs_syscalls.c Log Message: remove the part of previous that crashes for now. To generate a diff of this commit: cvs rdiff -u -r1.562 -r1.563 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_syscalls.c diff -u src/sys/kern/vfs_syscalls.c:1.562 src/sys/kern/vfs_syscalls.c:1.563 --- src/sys/kern/vfs_syscalls.c:1.562 Sat Jun 29 09:31:07 2024 +++ src/sys/kern/vfs_syscalls.c Sun Jun 30 20:51:11 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.562 2024/06/29 13:31:07 christos Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.563 2024/07/01 00:51:11 christos Exp $ */ /*- * Copyright (c) 2008, 2009, 2019, 2020, 2023 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.562 2024/06/29 13:31:07 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.563 2024/07/01 00:51:11 christos Exp $"); #ifdef _KERNEL_OPT #include "opt_fileassoc.h" @@ -260,7 +260,7 @@ fd_nameiat_simple_user(struct lwp *l, in struct vnode *dvp; int error; - if (fdat != AT_FDCWD && path[0] != '/') { + if (fdat != AT_FDCWD) { if ((error = fd_getvnode(fdat, &dfp)) != 0) goto out;
CVS commit: src/sys/kern
Module Name:src Committed By: christos Date: Sat Jun 29 13:31:07 UTC 2024 Modified Files: src/sys/kern: vfs_syscalls.c Log Message: Ignore the file descriptor argument for absolute pathnames, per posix eg: https://pubs.opengroup.org/onlinepubs/9699919799/functions/access.html To generate a diff of this commit: cvs rdiff -u -r1.561 -r1.562 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_syscalls.c diff -u src/sys/kern/vfs_syscalls.c:1.561 src/sys/kern/vfs_syscalls.c:1.562 --- src/sys/kern/vfs_syscalls.c:1.561 Sat Sep 9 14:34:44 2023 +++ src/sys/kern/vfs_syscalls.c Sat Jun 29 09:31:07 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.561 2023/09/09 18:34:44 ad Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.562 2024/06/29 13:31:07 christos Exp $ */ /*- * Copyright (c) 2008, 2009, 2019, 2020, 2023 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.561 2023/09/09 18:34:44 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.562 2024/06/29 13:31:07 christos Exp $"); #ifdef _KERNEL_OPT #include "opt_fileassoc.h" @@ -234,8 +234,9 @@ fd_nameiat(struct lwp *l, int fdat, stru { file_t *dfp; int error; + const char *path = pathbuf_stringcopy_get(ndp->ni_pathbuf); - if (fdat != AT_FDCWD) { + if (fdat != AT_FDCWD && path[0] != '/') { if ((error = fd_getvnode(fdat, &dfp)) != 0) goto out; @@ -247,6 +248,7 @@ fd_nameiat(struct lwp *l, int fdat, stru if (fdat != AT_FDCWD) fd_putfile(fdat); out: + pathbuf_stringcopy_put(ndp->ni_pathbuf, path); return error; } @@ -258,7 +260,7 @@ fd_nameiat_simple_user(struct lwp *l, in struct vnode *dvp; int error; - if (fdat != AT_FDCWD) { + if (fdat != AT_FDCWD && path[0] != '/') { if ((error = fd_getvnode(fdat, &dfp)) != 0) goto out;
CVS commit: src/sys/kern
Module Name:src Committed By: christos Date: Sat Jun 29 13:31:07 UTC 2024 Modified Files: src/sys/kern: vfs_syscalls.c Log Message: Ignore the file descriptor argument for absolute pathnames, per posix eg: https://pubs.opengroup.org/onlinepubs/9699919799/functions/access.html To generate a diff of this commit: cvs rdiff -u -r1.561 -r1.562 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: christos Date: Sun May 19 15:56:55 UTC 2024 Modified Files: src/sys/kern: sys_descrip.c Log Message: PR/58266: Collin Funk: Fail if from == to, like FreeBSD and Linux. The test is done in dup3 before any other tests so even if a bad descriptor it is passed we will return EINVAL not EBADFD like Linux does. To generate a diff of this commit: cvs rdiff -u -r1.48 -r1.49 src/sys/kern/sys_descrip.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_descrip.c diff -u src/sys/kern/sys_descrip.c:1.48 src/sys/kern/sys_descrip.c:1.49 --- src/sys/kern/sys_descrip.c:1.48 Sun Jul 9 22:31:55 2023 +++ src/sys/kern/sys_descrip.c Sun May 19 11:56:55 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_descrip.c,v 1.48 2023/07/10 02:31:55 christos Exp $ */ +/* $NetBSD: sys_descrip.c,v 1.49 2024/05/19 15:56:55 christos Exp $ */ /*- * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.48 2023/07/10 02:31:55 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.49 2024/05/19 15:56:55 christos Exp $"); #include #include @@ -156,6 +156,8 @@ sys_dup3(struct lwp *l, const struct sys syscallarg(int) to; syscallarg(int) flags; } */ + if (SCARG(uap, from) == SCARG(uap, to)) + return EINVAL; return dodup(l, SCARG(uap, from), SCARG(uap, to), SCARG(uap, flags), retval); }
CVS commit: src/sys/kern
Module Name:src Committed By: christos Date: Sun May 19 15:56:55 UTC 2024 Modified Files: src/sys/kern: sys_descrip.c Log Message: PR/58266: Collin Funk: Fail if from == to, like FreeBSD and Linux. The test is done in dup3 before any other tests so even if a bad descriptor it is passed we will return EINVAL not EBADFD like Linux does. To generate a diff of this commit: cvs rdiff -u -r1.48 -r1.49 src/sys/kern/sys_descrip.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: msaitoh Date: Mon May 13 00:32:09 UTC 2024 Modified Files: src/sys/kern: kern_module.c Log Message: s/signficant/significant/ in comment. To generate a diff of this commit: cvs rdiff -u -r1.161 -r1.162 src/sys/kern/kern_module.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_module.c diff -u src/sys/kern/kern_module.c:1.161 src/sys/kern/kern_module.c:1.162 --- src/sys/kern/kern_module.c:1.161 Tue Jan 31 13:21:37 2023 +++ src/sys/kern/kern_module.c Mon May 13 00:32:09 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_module.c,v 1.161 2023/01/31 13:21:37 riastradh Exp $ */ +/* $NetBSD: kern_module.c,v 1.162 2024/05/13 00:32:09 msaitoh Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.161 2023/01/31 13:21:37 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.162 2024/05/13 00:32:09 msaitoh Exp $"); #define _MODULE_INTERNAL @@ -641,7 +641,7 @@ module_init_class(modclass_t modclass) * * Return true if the two supplied kernel versions are said to * have the same binary interface for kernel code. The entire - * version is signficant for the development tree (-current), + * version is significant for the development tree (-current), * major and minor versions are significant for official * releases of the system. */
CVS commit: src/sys/kern
Module Name:src Committed By: msaitoh Date: Mon May 13 00:32:09 UTC 2024 Modified Files: src/sys/kern: kern_module.c Log Message: s/signficant/significant/ in comment. To generate a diff of this commit: cvs rdiff -u -r1.161 -r1.162 src/sys/kern/kern_module.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: andvar Date: Sat May 11 06:34:45 UTC 2024 Modified Files: src/sys/kern: kern_tc.c Log Message: s/timetamp/timestamp/ in comment. To generate a diff of this commit: cvs rdiff -u -r1.76 -r1.77 src/sys/kern/kern_tc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: andvar Date: Sat May 11 06:34:45 UTC 2024 Modified Files: src/sys/kern: kern_tc.c Log Message: s/timetamp/timestamp/ in comment. To generate a diff of this commit: cvs rdiff -u -r1.76 -r1.77 src/sys/kern/kern_tc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_tc.c diff -u src/sys/kern/kern_tc.c:1.76 src/sys/kern/kern_tc.c:1.77 --- src/sys/kern/kern_tc.c:1.76 Sun Jul 30 12:39:18 2023 +++ src/sys/kern/kern_tc.c Sat May 11 06:34:45 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_tc.c,v 1.76 2023/07/30 12:39:18 riastradh Exp $ */ +/* $NetBSD: kern_tc.c,v 1.77 2024/05/11 06:34:45 andvar Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -44,7 +44,7 @@ #include /* __FBSDID("$FreeBSD: src/sys/kern/kern_tc.c,v 1.166 2005/09/19 22:16:31 andre Exp $"); */ -__KERNEL_RCSID(0, "$NetBSD: kern_tc.c,v 1.76 2023/07/30 12:39:18 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_tc.c,v 1.77 2024/05/11 06:34:45 andvar Exp $"); #ifdef _KERNEL_OPT #include "opt_ntp.h" @@ -1128,7 +1128,7 @@ pps_init(struct pps_state *pps) } /* - * capture a timetamp in the pps structure + * capture a timestamp in the pps structure */ void pps_capture(struct pps_state *pps)
CVS commit: src/sys/kern
Module Name:src Committed By: mlelstv Date: Sat May 4 13:33:18 UTC 2024 Modified Files: src/sys/kern: subr_iostat.c Log Message: Account for trailing NUL bytes when calculating userland buffer size. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/sys/kern/subr_iostat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_iostat.c diff -u src/sys/kern/subr_iostat.c:1.25 src/sys/kern/subr_iostat.c:1.26 --- src/sys/kern/subr_iostat.c:1.25 Wed May 22 08:47:02 2019 +++ src/sys/kern/subr_iostat.c Sat May 4 13:33:18 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_iostat.c,v 1.25 2019/05/22 08:47:02 hannken Exp $ */ +/* $NetBSD: subr_iostat.c,v 1.26 2024/05/04 13:33:18 mlelstv Exp $ */ /* NetBSD: subr_disk.c,v 1.69 2005/05/29 22:24:15 christos Exp */ /*- @@ -68,7 +68,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_iostat.c,v 1.25 2019/05/22 08:47:02 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_iostat.c,v 1.26 2024/05/04 13:33:18 mlelstv Exp $"); #include #include @@ -370,6 +370,8 @@ iostati_getnames(int disk_only, char *ol memset(bf, 0, sizeof(bf)); if (first) { strncpy(bf, stats->io_name, sizeof(bf)); +/* account for trailing NUL byte */ +needed += 1; first = 0; } else { bf[0] = ' ';
CVS commit: src/sys/kern
Module Name:src Committed By: mlelstv Date: Sat May 4 13:33:18 UTC 2024 Modified Files: src/sys/kern: subr_iostat.c Log Message: Account for trailing NUL bytes when calculating userland buffer size. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/sys/kern/subr_iostat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: thorpej Date: Wed Apr 24 02:08:03 UTC 2024 Modified Files: src/sys/kern: subr_vmem.c Log Message: vmem_init(): Ensure that the quantum is a power of 2, and that if private tags are being used, they are added to the arena before the first span is added. To generate a diff of this commit: cvs rdiff -u -r1.115 -r1.116 src/sys/kern/subr_vmem.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: thorpej Date: Wed Apr 24 02:08:03 UTC 2024 Modified Files: src/sys/kern: subr_vmem.c Log Message: vmem_init(): Ensure that the quantum is a power of 2, and that if private tags are being used, they are added to the arena before the first span is added. To generate a diff of this commit: cvs rdiff -u -r1.115 -r1.116 src/sys/kern/subr_vmem.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_vmem.c diff -u src/sys/kern/subr_vmem.c:1.115 src/sys/kern/subr_vmem.c:1.116 --- src/sys/kern/subr_vmem.c:1.115 Sun Dec 3 19:34:08 2023 +++ src/sys/kern/subr_vmem.c Wed Apr 24 02:08:03 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_vmem.c,v 1.115 2023/12/03 19:34:08 thorpej Exp $ */ +/* $NetBSD: subr_vmem.c,v 1.116 2024/04/24 02:08:03 thorpej Exp $ */ /*- * Copyright (c)2006,2007,2008,2009 YAMAMOTO Takashi, @@ -46,7 +46,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.115 2023/12/03 19:34:08 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.116 2024/04/24 02:08:03 thorpej Exp $"); #if defined(_KERNEL) && defined(_KERNEL_OPT) #include "opt_ddb.h" @@ -971,6 +971,14 @@ vmem_init(vmem_t *vm, const char *name, KASSERT((flags & (VM_SLEEP|VM_NOSLEEP)) != 0); KASSERT((~flags & (VM_SLEEP|VM_NOSLEEP)) != 0); KASSERT(quantum > 0); + KASSERT(powerof2(quantum)); + + /* + * If private tags are going to be used, they must + * be added to the arena before the first span is + * added. + */ + KASSERT((flags & VM_PRIVTAGS) == 0 || size == 0); #if defined(_KERNEL) /* XXX: SMP, we get called early... */
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Fri Apr 19 00:45:41 UTC 2024 Modified Files: src/sys/kern: vfs_mount.c Log Message: dounmount: Avoid &((struct vnode_impl *)NULL)->vi_vnode. Member access of a null pointer is undefined, even if the result should also be null because vi_vnode is at the start of vnode_impl. Reported-by: syzbot+a4b2d13c0d6d4dac2...@syzkaller.appspotmail.com https://syzkaller.appspot.com/bug?extid=a4b2d13c0d6d4dac2d07 To generate a diff of this commit: cvs rdiff -u -r1.104 -r1.105 src/sys/kern/vfs_mount.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_mount.c diff -u src/sys/kern/vfs_mount.c:1.104 src/sys/kern/vfs_mount.c:1.105 --- src/sys/kern/vfs_mount.c:1.104 Wed Jan 17 10:17:29 2024 +++ src/sys/kern/vfs_mount.c Fri Apr 19 00:45:41 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_mount.c,v 1.104 2024/01/17 10:17:29 hannken Exp $ */ +/* $NetBSD: vfs_mount.c,v 1.105 2024/04/19 00:45:41 riastradh Exp $ */ /*- * Copyright (c) 1997-2020 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.104 2024/01/17 10:17:29 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.105 2024/04/19 00:45:41 riastradh Exp $"); #include "veriexec.h" @@ -936,7 +936,8 @@ err_mounted: int dounmount(struct mount *mp, int flags, struct lwp *l) { - vnode_t *coveredvp, *vp; + struct vnode *coveredvp, *vp; + struct vnode_impl *vip; int error, async, used_syncer, used_extattr; const bool was_suspended = fstrans_is_owner(mp); @@ -1003,7 +1004,9 @@ dounmount(struct mount *mp, int flags, s vfs_resume(mp); mountlist_remove(mp); - if ((vp = VIMPL_TO_VNODE(TAILQ_FIRST(&mp->mnt_vnodelist))) != NULL) { + + if ((vip = TAILQ_FIRST(&mp->mnt_vnodelist)) != NULL) { + vp = VIMPL_TO_VNODE(vip); vprint("dangling", vp); panic("unmount: dangling vnode"); }
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Fri Apr 19 00:45:41 UTC 2024 Modified Files: src/sys/kern: vfs_mount.c Log Message: dounmount: Avoid &((struct vnode_impl *)NULL)->vi_vnode. Member access of a null pointer is undefined, even if the result should also be null because vi_vnode is at the start of vnode_impl. Reported-by: syzbot+a4b2d13c0d6d4dac2...@syzkaller.appspotmail.com https://syzkaller.appspot.com/bug?extid=a4b2d13c0d6d4dac2d07 To generate a diff of this commit: cvs rdiff -u -r1.104 -r1.105 src/sys/kern/vfs_mount.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Thu Apr 11 13:51:36 UTC 2024 Modified Files: src/sys/kern: sys_futex.c Log Message: sys_futex.c: Fix illustration of futex(2). In this illustration, we need to _set_ bit 1 to claim ownership, not _clear_ bit 1 to claim ownership. No functional change intended -- comment only. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/sys/kern/sys_futex.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Thu Apr 11 13:51:36 UTC 2024 Modified Files: src/sys/kern: sys_futex.c Log Message: sys_futex.c: Fix illustration of futex(2). In this illustration, we need to _set_ bit 1 to claim ownership, not _clear_ bit 1 to claim ownership. No functional change intended -- comment only. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/sys/kern/sys_futex.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_futex.c diff -u src/sys/kern/sys_futex.c:1.19 src/sys/kern/sys_futex.c:1.20 --- src/sys/kern/sys_futex.c:1.19 Fri Feb 24 11:02:27 2023 +++ src/sys/kern/sys_futex.c Thu Apr 11 13:51:36 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_futex.c,v 1.19 2023/02/24 11:02:27 riastradh Exp $ */ +/* $NetBSD: sys_futex.c,v 1.20 2024/04/11 13:51:36 riastradh Exp $ */ /*- * Copyright (c) 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sys_futex.c,v 1.19 2023/02/24 11:02:27 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_futex.c,v 1.20 2024/04/11 13:51:36 riastradh Exp $"); /* * Futexes @@ -62,7 +62,7 @@ __KERNEL_RCSID(0, "$NetBSD: sys_futex.c, *futex(FUTEX_WAIT, &lock, v | 2, NULL, NULL, 0); *continue; * } - * } while (atomic_cas_uint(&lock, v, v & ~1) != v); + * } while (atomic_cas_uint(&lock, v, v | 1) != v); * membar_acquire(); * * ...
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Fri Mar 8 23:34:03 UTC 2024 Modified Files: src/sys/kern: kern_heartbeat.c Log Message: heartbeat(9): Return early if panicstr is set. This way we avoid doing unnecessary work -- and print unnecessary messages -- to _not_ trigger another panic anyway. PR kern/58011 To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/sys/kern/kern_heartbeat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_heartbeat.c diff -u src/sys/kern/kern_heartbeat.c:1.12 src/sys/kern/kern_heartbeat.c:1.13 --- src/sys/kern/kern_heartbeat.c:1.12 Wed Feb 28 04:14:47 2024 +++ src/sys/kern/kern_heartbeat.c Fri Mar 8 23:34:03 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_heartbeat.c,v 1.12 2024/02/28 04:14:47 riastradh Exp $ */ +/* $NetBSD: kern_heartbeat.c,v 1.13 2024/03/08 23:34:03 riastradh Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -82,7 +82,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.12 2024/02/28 04:14:47 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.13 2024/03/08 23:34:03 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_ddb.h" @@ -627,11 +627,17 @@ heartbeat(void) KASSERT(curcpu_stable()); + /* + * If heartbeat checks are disabled globally, or if they are + * suspended locally, or if we're already panicking so it's not + * helpful to trigger more panics for more reasons, do nothing. + */ period_ticks = atomic_load_relaxed(&heartbeat_max_period_ticks); period_secs = atomic_load_relaxed(&heartbeat_max_period_secs); if (__predict_false(period_ticks == 0) || __predict_false(period_secs == 0) || - __predict_false(curcpu()->ci_heartbeat_suspend)) + __predict_false(curcpu()->ci_heartbeat_suspend) || + __predict_false(panicstr != NULL)) return; /*
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Fri Mar 8 23:34:03 UTC 2024 Modified Files: src/sys/kern: kern_heartbeat.c Log Message: heartbeat(9): Return early if panicstr is set. This way we avoid doing unnecessary work -- and print unnecessary messages -- to _not_ trigger another panic anyway. PR kern/58011 To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/sys/kern/kern_heartbeat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: mlelstv Date: Sat Mar 2 08:59:47 UTC 2024 Modified Files: src/sys/kern: sysv_shm.c Log Message: Avoid overflow when computing kern.ipc.shmmax. Keep shmmax (bytes) and shmall (pages) values aligned and use arithmetic everywhere instead of shifts. Should fix PR 57979 To generate a diff of this commit: cvs rdiff -u -r1.141 -r1.142 src/sys/kern/sysv_shm.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sysv_shm.c diff -u src/sys/kern/sysv_shm.c:1.141 src/sys/kern/sysv_shm.c:1.142 --- src/sys/kern/sysv_shm.c:1.141 Wed Oct 9 17:47:13 2019 +++ src/sys/kern/sysv_shm.c Sat Mar 2 08:59:47 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: sysv_shm.c,v 1.141 2019/10/09 17:47:13 chs Exp $ */ +/* $NetBSD: sysv_shm.c,v 1.142 2024/03/02 08:59:47 mlelstv Exp $ */ /*- * Copyright (c) 1999, 2007 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sysv_shm.c,v 1.141 2019/10/09 17:47:13 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sysv_shm.c,v 1.142 2024/03/02 08:59:47 mlelstv Exp $"); #ifdef _KERNEL_OPT #include "opt_sysv.h" @@ -961,10 +961,10 @@ shminit(void) ALIGN(shminfo.shmmni * sizeof(struct shmid_ds))); if (shminfo.shmmax == 0) - shminfo.shmmax = uimax(physmem / 4, 1024) * PAGE_SIZE; + shminfo.shmall = uimax(physmem / 4, 1024); else - shminfo.shmmax *= PAGE_SIZE; - shminfo.shmall = shminfo.shmmax / PAGE_SIZE; + shminfo.shmall = shminfo.shmmax / PAGE_SIZE; + shminfo.shmmax = (uint64_t)shminfo.shmall * PAGE_SIZE; for (i = 0; i < shminfo.shmmni; i++) { cv_init(&shm_cv[i], "shmwait"); @@ -1083,7 +1083,7 @@ sysctl_ipc_shmmax(SYSCTLFN_ARGS) return EINVAL; shminfo.shmmax = round_page(newsize); - shminfo.shmall = shminfo.shmmax >> PAGE_SHIFT; + shminfo.shmall = shminfo.shmmax / PAGE_SIZE; return 0; }
CVS commit: src/sys/kern
Module Name:src Committed By: mlelstv Date: Sat Mar 2 08:59:47 UTC 2024 Modified Files: src/sys/kern: sysv_shm.c Log Message: Avoid overflow when computing kern.ipc.shmmax. Keep shmmax (bytes) and shmall (pages) values aligned and use arithmetic everywhere instead of shifts. Should fix PR 57979 To generate a diff of this commit: cvs rdiff -u -r1.141 -r1.142 src/sys/kern/sysv_shm.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: mrg Date: Fri Mar 1 04:32:38 UTC 2024 Modified Files: src/sys/kern: kern_idle.c kern_softint.c subr_workqueue.c subr_xcall.c Log Message: check that l_nopreempt (preemption count) doesn't change after callbacks check that the idle loop, soft interrupt handlers, workqueue, and xcall callbacks do not modify the preemption count, in most cases, knowing it should be 0 currently. this work was originally done by simonb. cleaned up slightly and some minor enhancement made by myself, and with discussion with riastradh@. other callback call sites could check this as well (such as MD interrupt handlers, or really anything that includes a callback registration. x86 version to be commited separately.) To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/sys/kern/kern_idle.c cvs rdiff -u -r1.75 -r1.76 src/sys/kern/kern_softint.c cvs rdiff -u -r1.47 -r1.48 src/sys/kern/subr_workqueue.c cvs rdiff -u -r1.37 -r1.38 src/sys/kern/subr_xcall.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_idle.c diff -u src/sys/kern/kern_idle.c:1.35 src/sys/kern/kern_idle.c:1.36 --- src/sys/kern/kern_idle.c:1.35 Thu Oct 5 19:10:18 2023 +++ src/sys/kern/kern_idle.c Fri Mar 1 04:32:38 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_idle.c,v 1.35 2023/10/05 19:10:18 ad Exp $ */ +/* $NetBSD: kern_idle.c,v 1.36 2024/03/01 04:32:38 mrg Exp $ */ /*- * Copyright (c)2002, 2006, 2007 YAMAMOTO Takashi, @@ -28,7 +28,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: kern_idle.c,v 1.35 2023/10/05 19:10:18 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_idle.c,v 1.36 2024/03/01 04:32:38 mrg Exp $"); #include #include @@ -75,6 +75,8 @@ idle_loop(void *dummy) KASSERT(l == curlwp); KASSERT(CURCPU_IDLE_P()); KASSERT(l->l_priority == PRI_IDLE); + KASSERTMSG(l->l_nopreempt == 0, "lwp %p nopreempt %d", + l, l->l_nopreempt); sched_idle(); if (!sched_curcpu_runnable_p()) { Index: src/sys/kern/kern_softint.c diff -u src/sys/kern/kern_softint.c:1.75 src/sys/kern/kern_softint.c:1.76 --- src/sys/kern/kern_softint.c:1.75 Fri Aug 4 12:24:36 2023 +++ src/sys/kern/kern_softint.c Fri Mar 1 04:32:38 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_softint.c,v 1.75 2023/08/04 12:24:36 riastradh Exp $ */ +/* $NetBSD: kern_softint.c,v 1.76 2024/03/01 04:32:38 mrg Exp $ */ /*- * Copyright (c) 2007, 2008, 2019, 2020 The NetBSD Foundation, Inc. @@ -170,7 +170,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.75 2023/08/04 12:24:36 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.76 2024/03/01 04:32:38 mrg Exp $"); #include #include @@ -569,6 +569,8 @@ softint_execute(lwp_t *l, int s) KASSERT(si->si_cpu == curcpu()); KASSERT(si->si_lwp->l_wchan == NULL); KASSERT(si->si_active); + KASSERTMSG(l->l_nopreempt == 0, "lwp %p nopreempt %d", + l, l->l_nopreempt); /* * Note: due to priority inheritance we may have interrupted a @@ -616,6 +618,10 @@ softint_execute(lwp_t *l, int s) KASSERTMSG(l->l_blcnt == 0, "%s: sh_func=%p leaked %d biglocks", __func__, sh->sh_func, curlwp->l_blcnt); + /* Diagnostic: check that LWP nopreempt remains zero. */ + KASSERTMSG(l->l_nopreempt == 0, + "%s: lwp %p nopreempt %d func %p", + __func__, l, l->l_nopreempt, sh->sh_func); (void)splhigh(); } Index: src/sys/kern/subr_workqueue.c diff -u src/sys/kern/subr_workqueue.c:1.47 src/sys/kern/subr_workqueue.c:1.48 --- src/sys/kern/subr_workqueue.c:1.47 Wed Aug 9 08:24:18 2023 +++ src/sys/kern/subr_workqueue.c Fri Mar 1 04:32:38 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_workqueue.c,v 1.47 2023/08/09 08:24:18 riastradh Exp $ */ +/* $NetBSD: subr_workqueue.c,v 1.48 2024/03/01 04:32:38 mrg Exp $ */ /*- * Copyright (c)2002, 2005, 2006, 2007 YAMAMOTO Takashi, @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_workqueue.c,v 1.47 2023/08/09 08:24:18 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_workqueue.c,v 1.48 2024/03/01 04:32:38 mrg Exp $"); #include @@ -140,6 +140,10 @@ workqueue_runlist(struct workqueue *wq, { work_impl_t *wk; work_impl_t *next; + struct lwp *l = curlwp; + + KASSERTMSG(l->l_nopreempt == 0, "lwp %p nopreempt %d", + l, l->l_nopreempt); for (wk = SIMPLEQ_FIRST(list); wk != NULL; wk = next) { next = SIMPLEQ_NEXT(wk, wk_entry); @@ -148,6 +152,9 @@ workqueue_runlist(struct workqueue *wq, (*wq->wq_func)((void *)wk, wq->wq_arg); SDT_PROBE4(sdt, kernel, workqueue, return, wq, wk, wq->wq_func, wq->wq_arg); + KASSERTMSG(l->l_nopreempt == 0, + "lwp %p nopreempt %d func %p", + l, l->l_nopreempt, wq->wq_func); } } Index: src/sys/kern/subr_xcall.c diff -u src/sys/kern/subr_xcall.c:1.37 src/sys/kern/subr_xcall.c:1.38 --- src/sys/kern/subr_xcall.c:1.37 Sun Aug 6 17:50:20 2023 +++ src/sys/kern/subr_xcall.c Fri Mar 1 04:32:38 2024 @@ -
CVS commit: src/sys/kern
Module Name:src Committed By: mrg Date: Fri Mar 1 04:32:38 UTC 2024 Modified Files: src/sys/kern: kern_idle.c kern_softint.c subr_workqueue.c subr_xcall.c Log Message: check that l_nopreempt (preemption count) doesn't change after callbacks check that the idle loop, soft interrupt handlers, workqueue, and xcall callbacks do not modify the preemption count, in most cases, knowing it should be 0 currently. this work was originally done by simonb. cleaned up slightly and some minor enhancement made by myself, and with discussion with riastradh@. other callback call sites could check this as well (such as MD interrupt handlers, or really anything that includes a callback registration. x86 version to be commited separately.) To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/sys/kern/kern_idle.c cvs rdiff -u -r1.75 -r1.76 src/sys/kern/kern_softint.c cvs rdiff -u -r1.47 -r1.48 src/sys/kern/subr_workqueue.c cvs rdiff -u -r1.37 -r1.38 src/sys/kern/subr_xcall.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Wed Feb 28 04:14:47 UTC 2024 Modified Files: src/sys/kern: kern_heartbeat.c Log Message: heartbeat(9): Restore still-applicable comment nixed in last commit. The nesting depth is stored in ci_heartbeat_suspend which is 32-bit. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/sys/kern/kern_heartbeat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_heartbeat.c diff -u src/sys/kern/kern_heartbeat.c:1.11 src/sys/kern/kern_heartbeat.c:1.12 --- src/sys/kern/kern_heartbeat.c:1.11 Wed Feb 28 04:12:59 2024 +++ src/sys/kern/kern_heartbeat.c Wed Feb 28 04:14:47 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_heartbeat.c,v 1.11 2024/02/28 04:12:59 riastradh Exp $ */ +/* $NetBSD: kern_heartbeat.c,v 1.12 2024/02/28 04:14:47 riastradh Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -82,7 +82,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.11 2024/02/28 04:12:59 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.12 2024/02/28 04:14:47 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_ddb.h" @@ -132,8 +132,8 @@ void *heartbeat_sih __read_mostly; * * Called after the current CPU has been marked offline but before * it has stopped running, or after IPL has been raised for - * polling-mode console input. Nestable. Reversed by - * heartbeat_resume. + * polling-mode console input. Nestable (but only 2^32 times, so + * don't do this in a loop). Reversed by heartbeat_resume. * * Caller must be bound to the CPU, i.e., curcpu_stable() must be * true. This function does not assert curcpu_stable() since it
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Wed Feb 28 04:14:47 UTC 2024 Modified Files: src/sys/kern: kern_heartbeat.c Log Message: heartbeat(9): Restore still-applicable comment nixed in last commit. The nesting depth is stored in ci_heartbeat_suspend which is 32-bit. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/sys/kern/kern_heartbeat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Wed Feb 28 04:13:00 UTC 2024 Modified Files: src/sys/kern: kern_heartbeat.c Log Message: heartbeat(9): No kpreempt_disable/enable in heartbeat_suspend/resume. This causes a leak of l_nopreempt in xc_thread when a CPU is offlined and onlined again, because the offlining heartbeat_suspend and the onlining heartbeat_resume happen in separate xcalls. No change to callers because they are already bound to the CPU: 1. cnpollc does kpreempt_disable/enable itself around the calls to heartbeat_suspend/resume anyway 2. cpu_xc_offline/online run in the xcall thread, which is always bound to the CPU that is being offlined or onlined To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sys/kern/kern_heartbeat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Wed Feb 28 04:13:00 UTC 2024 Modified Files: src/sys/kern: kern_heartbeat.c Log Message: heartbeat(9): No kpreempt_disable/enable in heartbeat_suspend/resume. This causes a leak of l_nopreempt in xc_thread when a CPU is offlined and onlined again, because the offlining heartbeat_suspend and the onlining heartbeat_resume happen in separate xcalls. No change to callers because they are already bound to the CPU: 1. cnpollc does kpreempt_disable/enable itself around the calls to heartbeat_suspend/resume anyway 2. cpu_xc_offline/online run in the xcall thread, which is always bound to the CPU that is being offlined or onlined To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sys/kern/kern_heartbeat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_heartbeat.c diff -u src/sys/kern/kern_heartbeat.c:1.10 src/sys/kern/kern_heartbeat.c:1.11 --- src/sys/kern/kern_heartbeat.c:1.10 Wed Sep 6 12:29:14 2023 +++ src/sys/kern/kern_heartbeat.c Wed Feb 28 04:12:59 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_heartbeat.c,v 1.10 2023/09/06 12:29:14 riastradh Exp $ */ +/* $NetBSD: kern_heartbeat.c,v 1.11 2024/02/28 04:12:59 riastradh Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -82,7 +82,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.10 2023/09/06 12:29:14 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.11 2024/02/28 04:12:59 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_ddb.h" @@ -132,24 +132,20 @@ void *heartbeat_sih __read_mostly; * * Called after the current CPU has been marked offline but before * it has stopped running, or after IPL has been raised for - * polling-mode console input. Binds to the current CPU as a side - * effect. Nestable (but only up to 2^32 times, so don't do this - * in a loop). Reversed by heartbeat_resume. + * polling-mode console input. Nestable. Reversed by + * heartbeat_resume. + * + * Caller must be bound to the CPU, i.e., curcpu_stable() must be + * true. This function does not assert curcpu_stable() since it + * is used in the ddb entry path, where any assertions risk + * infinite regress into undebuggable chaos, so callers must be + * careful. */ void heartbeat_suspend(void) { unsigned *p; - /* - * We could use curlwp_bind, but we'd have to record whether we - * were already bound or not to pass to curlwp_bindx in - * heartbeat_resume. Using kpreempt_disable is simpler and - * unlikely to have any adverse consequences, since this only - * happens when we're about to go into a tight polling loop at - * raised IPL anyway. - */ - kpreempt_disable(); p = &curcpu()->ci_heartbeat_suspend; atomic_store_relaxed(p, *p + 1); } @@ -186,6 +182,9 @@ heartbeat_resume_cpu(struct cpu_info *ci * Called after the current CPU has started running but before it * has been marked online, or when ending polling-mode input * before IPL is restored. Reverses heartbeat_suspend. + * + * Caller must be bound to the CPU, i.e., curcpu_stable() must be + * true. */ void heartbeat_resume(void) @@ -194,6 +193,8 @@ heartbeat_resume(void) unsigned *p; int s; + KASSERT(curcpu_stable()); + /* * Reset the state so nobody spuriously thinks we had a heart * attack as soon as the heartbeat checks resume. @@ -204,7 +205,6 @@ heartbeat_resume(void) p = &ci->ci_heartbeat_suspend; atomic_store_relaxed(p, *p - 1); - kpreempt_enable(); } /*
CVS commit: src/sys/kern
Module Name:src Committed By: jdolecek Date: Sun Feb 11 13:01:29 UTC 2024 Modified Files: src/sys/kern: uipc_socket.c Log Message: make kqfilter() behave the same for PIPE_SOCKETPAIR pipe as it does for standard one - refuse EVFILT_WRITE if the reader is already disconnected fixes test failure for kernel/kqueue/write/t_pipe.c on PIPE_SOCKETPAIR kernel PR kern/55690 To generate a diff of this commit: cvs rdiff -u -r1.308 -r1.309 src/sys/kern/uipc_socket.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: jdolecek Date: Sun Feb 11 13:01:29 UTC 2024 Modified Files: src/sys/kern: uipc_socket.c Log Message: make kqfilter() behave the same for PIPE_SOCKETPAIR pipe as it does for standard one - refuse EVFILT_WRITE if the reader is already disconnected fixes test failure for kernel/kqueue/write/t_pipe.c on PIPE_SOCKETPAIR kernel PR kern/55690 To generate a diff of this commit: cvs rdiff -u -r1.308 -r1.309 src/sys/kern/uipc_socket.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/uipc_socket.c diff -u src/sys/kern/uipc_socket.c:1.308 src/sys/kern/uipc_socket.c:1.309 --- src/sys/kern/uipc_socket.c:1.308 Sat Feb 3 19:05:14 2024 +++ src/sys/kern/uipc_socket.c Sun Feb 11 13:01:29 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_socket.c,v 1.308 2024/02/03 19:05:14 jdolecek Exp $ */ +/* $NetBSD: uipc_socket.c,v 1.309 2024/02/11 13:01:29 jdolecek Exp $ */ /* * Copyright (c) 2002, 2007, 2008, 2009, 2023 The NetBSD Foundation, Inc. @@ -71,7 +71,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.308 2024/02/03 19:05:14 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.309 2024/02/11 13:01:29 jdolecek Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -81,6 +81,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_socket. #include "opt_somaxkva.h" #include "opt_multiprocessor.h" /* XXX */ #include "opt_sctp.h" +#include "opt_pipe.h" #endif #include @@ -2394,6 +2395,16 @@ soo_kqfilter(struct file *fp, struct kno case EVFILT_WRITE: kn->kn_fop = &sowrite_filtops; sb = &so->so_snd; + +#ifdef PIPE_SOCKETPAIR + if (so->so_state & SS_ISAPIPE) { + /* Other end of pipe has been closed. */ + if (so->so_state & SS_ISDISCONNECTED) { +sounlock(so); +return EBADF; + } + } +#endif break; case EVFILT_EMPTY: kn->kn_fop = &soempty_filtops;
CVS commit: src/sys/kern
Module Name:src Committed By: christos Date: Wed Jan 24 16:11:48 UTC 2024 Modified Files: src/sys/kern: sched_m2.c Log Message: Unbreak sched_m2 (died because lwp_eproc() KASSERT in DIAGNOSTIC) and explain what is going on. This has been broken since the introduction of l_mutex 5 months ago. To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/sys/kern/sched_m2.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sched_m2.c diff -u src/sys/kern/sched_m2.c:1.39 src/sys/kern/sched_m2.c:1.40 --- src/sys/kern/sched_m2.c:1.39 Sat May 23 17:24:41 2020 +++ src/sys/kern/sched_m2.c Wed Jan 24 11:11:48 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: sched_m2.c,v 1.39 2020/05/23 21:24:41 ad Exp $ */ +/* $NetBSD: sched_m2.c,v 1.40 2024/01/24 16:11:48 christos Exp $ */ /* * Copyright (c) 2007, 2008 Mindaugas Rasiukevicius @@ -33,7 +33,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sched_m2.c,v 1.39 2020/05/23 21:24:41 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sched_m2.c,v 1.40 2024/01/24 16:11:48 christos Exp $"); #include @@ -91,14 +91,22 @@ sched_rqinit(void) sched_rrticks = mstohz(100); /* ~100 ms */ sched_precalcts(); -#ifdef notdef +#ifdef notyet /* Need to set the name etc. This does not belong here */ /* Attach the primary CPU here */ sched_cpuattach(curcpu()); #endif sched_lwp_fork(NULL, &lwp0); +#ifdef notyet + /* without attaching the primary CPU l_mutex does not get initialized */ + lwp_lock(&lwp0); sched_newts(&lwp0); + lwp_unlock(&lwp0); +#else + /* gross */ + lwp0.l_sched.timeslice = ts_map[lwp0.l_auxprio]; +#endif } /* Pre-calculate the time-slices for the priorities */
CVS commit: src/sys/kern
Module Name:src Committed By: christos Date: Wed Jan 24 16:11:48 UTC 2024 Modified Files: src/sys/kern: sched_m2.c Log Message: Unbreak sched_m2 (died because lwp_eproc() KASSERT in DIAGNOSTIC) and explain what is going on. This has been broken since the introduction of l_mutex 5 months ago. To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/sys/kern/sched_m2.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: christos Date: Fri Jan 19 19:07:38 UTC 2024 Modified Files: src/sys/kern: subr_acl_nfs4.c Log Message: add lint comments To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/kern/subr_acl_nfs4.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_acl_nfs4.c diff -u src/sys/kern/subr_acl_nfs4.c:1.1 src/sys/kern/subr_acl_nfs4.c:1.2 --- src/sys/kern/subr_acl_nfs4.c:1.1 Sat May 16 14:31:50 2020 +++ src/sys/kern/subr_acl_nfs4.c Fri Jan 19 14:07:38 2024 @@ -37,7 +37,7 @@ #if 0 __FBSDID("$FreeBSD: head/sys/kern/subr_acl_nfs4.c 341827 2018-12-11 19:32:16Z mjg $"); #endif -__KERNEL_RCSID(0, "$NetBSD: subr_acl_nfs4.c,v 1.1 2020/05/16 18:31:50 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_acl_nfs4.c,v 1.2 2024/01/19 19:07:38 christos Exp $"); #include #include @@ -261,6 +261,7 @@ __acl_nfs4_sync_mode_from_acl(mode_t *_m * Populate the ACL with entries inherited from parent_aclp. */ static void +/*ARGSUSED*/ acl_nfs4_inherit_entries(const struct acl *parent_aclp, struct acl *child_aclp, mode_t mode, int file_owner_id, int is_directory) @@ -469,6 +470,7 @@ acl_nfs4_trivial_from_mode(struct acl *a * and acl_is_trivial_np(3). */ void +/*ARGSUSED*/ __acl_nfs4_trivial_from_mode_libc(struct acl *aclp, int mode, int canonical_six) {
CVS commit: src/sys/kern
Module Name:src Committed By: christos Date: Fri Jan 19 19:07:38 UTC 2024 Modified Files: src/sys/kern: subr_acl_nfs4.c Log Message: add lint comments To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/kern/subr_acl_nfs4.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: hannken Date: Wed Jan 17 10:18:41 UTC 2024 Modified Files: src/sys/kern: init_main.c kern_hook.c Log Message: Protect kernel hooks exechook, exithook and forkhook with rwlock. Lock as writer on establish/disestablish and as reader on list traverse. For exechook ride "exec_lock" as it is already take as reader when traversing the list. Add local locks for exithook and forkhook. Move exec_init before signal_init as signal_init calls exechook_establish() that needs "exec_lock". PR kern/39913 "exec, fork, exit hooks need locking" To generate a diff of this commit: cvs rdiff -u -r1.546 -r1.547 src/sys/kern/init_main.c cvs rdiff -u -r1.14 -r1.15 src/sys/kern/kern_hook.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/init_main.c diff -u src/sys/kern/init_main.c:1.546 src/sys/kern/init_main.c:1.547 --- src/sys/kern/init_main.c:1.546 Sat Sep 23 18:21:11 2023 +++ src/sys/kern/init_main.c Wed Jan 17 10:18:41 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: init_main.c,v 1.546 2023/09/23 18:21:11 ad Exp $ */ +/* $NetBSD: init_main.c,v 1.547 2024/01/17 10:18:41 hannken Exp $ */ /*- * Copyright (c) 2008, 2009, 2019, 2023 The NetBSD Foundation, Inc. @@ -97,7 +97,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.546 2023/09/23 18:21:11 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.547 2024/01/17 10:18:41 hannken Exp $"); #include "opt_cnmagic.h" #include "opt_ddb.h" @@ -407,6 +407,9 @@ main(void) /* Must be called after lwpinit (lwpinit_specificdata) */ psref_init(); + /* Initialize exec structures */ + exec_init(1); /* signal_init calls exechook_establish() */ + /* Initialize signal-related data structures. */ signal_init(); @@ -579,9 +582,6 @@ main(void) vmem_rehash_start(); /* must be before exec_init */ - /* Initialize exec structures */ - exec_init(1); /* seminit calls exithook_establish() */ - #if NVERIEXEC > 0 /* * Initialise the Veriexec subsystem. Index: src/sys/kern/kern_hook.c diff -u src/sys/kern/kern_hook.c:1.14 src/sys/kern/kern_hook.c:1.15 --- src/sys/kern/kern_hook.c:1.14 Wed Oct 26 23:21:06 2022 +++ src/sys/kern/kern_hook.c Wed Jan 17 10:18:41 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_hook.c,v 1.14 2022/10/26 23:21:06 riastradh Exp $ */ +/* $NetBSD: kern_hook.c,v 1.15 2024/01/17 10:18:41 hannken Exp $ */ /*- * Copyright (c) 1997, 1998, 1999, 2002, 2007, 2008 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_hook.c,v 1.14 2022/10/26 23:21:06 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_hook.c,v 1.15 2024/01/17 10:18:41 hannken Exp $"); #include @@ -42,6 +42,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_hook.c, #include #include #include +#include #include #include @@ -74,25 +75,48 @@ struct khook_list { int powerhook_debug = 0; +static ONCE_DECL(hook_control); +static krwlock_t exithook_lock; +static krwlock_t forkhook_lock; + +static int +hook_init(void) +{ + + rw_init(&exithook_lock); + rw_init(&forkhook_lock); + + return 0; +} + static void * -hook_establish(hook_list_t *list, void (*fn)(void *), void *arg) +hook_establish(hook_list_t *list, krwlock_t *lock, +void (*fn)(void *), void *arg) { struct hook_desc *hd; - hd = malloc(sizeof(*hd), M_DEVBUF, M_NOWAIT); - if (hd == NULL) - return (NULL); + RUN_ONCE(&hook_control, hook_init); - hd->hk_fn = fn; - hd->hk_arg = arg; - LIST_INSERT_HEAD(list, hd, hk_list); + hd = malloc(sizeof(*hd), M_DEVBUF, M_NOWAIT); + if (hd != NULL) { + if (lock) + rw_enter(lock, RW_WRITER); + hd->hk_fn = fn; + hd->hk_arg = arg; + LIST_INSERT_HEAD(list, hd, hk_list); + if (lock) + rw_exit(lock); + } return (hd); } static void -hook_disestablish(hook_list_t *list, void *vhook) +hook_disestablish(hook_list_t *list, krwlock_t *lock, void *vhook) { + + if (lock) + rw_enter(lock, RW_WRITER); #ifdef DIAGNOSTIC struct hook_desc *hd; @@ -106,6 +130,8 @@ hook_disestablish(hook_list_t *list, voi #endif LIST_REMOVE((struct hook_desc *)vhook, hk_list); free(vhook, M_DEVBUF); + if (lock) + rw_exit(lock); } static void @@ -120,14 +146,20 @@ hook_destroy(hook_list_t *list) } static void -hook_proc_run(hook_list_t *list, struct proc *p) +hook_proc_run(hook_list_t *list, krwlock_t *lock, struct proc *p) { struct hook_desc *hd; + RUN_ONCE(&hook_control, hook_init); + + if (lock) + rw_enter(lock, RW_READER); LIST_FOREACH(hd, list, hk_list) { __FPTRCAST(void (*)(struct proc *, void *), *hd->hk_fn)(p, hd->hk_arg); } + if (lock) + rw_exit(lock); } /* @@ -146,13 +178,13 @@ static hook_list_t shutdownhook_list = L void * shutdownhook_establish(void (*fn)(void *), void *arg) { - return hook_establish(&shutdownhook_list, fn, arg); + return hook_establish(&shutdownhook_list, NULL, fn, arg); } void shutdownhook_disestablish(void *vhook) { -
CVS commit: src/sys/kern
Module Name:src Committed By: hannken Date: Wed Jan 17 10:18:41 UTC 2024 Modified Files: src/sys/kern: init_main.c kern_hook.c Log Message: Protect kernel hooks exechook, exithook and forkhook with rwlock. Lock as writer on establish/disestablish and as reader on list traverse. For exechook ride "exec_lock" as it is already take as reader when traversing the list. Add local locks for exithook and forkhook. Move exec_init before signal_init as signal_init calls exechook_establish() that needs "exec_lock". PR kern/39913 "exec, fork, exit hooks need locking" To generate a diff of this commit: cvs rdiff -u -r1.546 -r1.547 src/sys/kern/init_main.c cvs rdiff -u -r1.14 -r1.15 src/sys/kern/kern_hook.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: hannken Date: Wed Jan 17 10:17:29 UTC 2024 Modified Files: src/sys/kern: vfs_mount.c Log Message: Print dangling vnode before panic() to help debug. PR kern/57775 ""panic: unmount: dangling vnode" while umounting procfs" To generate a diff of this commit: cvs rdiff -u -r1.103 -r1.104 src/sys/kern/vfs_mount.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_mount.c diff -u src/sys/kern/vfs_mount.c:1.103 src/sys/kern/vfs_mount.c:1.104 --- src/sys/kern/vfs_mount.c:1.103 Thu Dec 28 12:48:08 2023 +++ src/sys/kern/vfs_mount.c Wed Jan 17 10:17:29 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_mount.c,v 1.103 2023/12/28 12:48:08 hannken Exp $ */ +/* $NetBSD: vfs_mount.c,v 1.104 2024/01/17 10:17:29 hannken Exp $ */ /*- * Copyright (c) 1997-2020 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.103 2023/12/28 12:48:08 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.104 2024/01/17 10:17:29 hannken Exp $"); #include "veriexec.h" @@ -936,7 +936,7 @@ err_mounted: int dounmount(struct mount *mp, int flags, struct lwp *l) { - vnode_t *coveredvp; + vnode_t *coveredvp, *vp; int error, async, used_syncer, used_extattr; const bool was_suspended = fstrans_is_owner(mp); @@ -1003,8 +1003,10 @@ dounmount(struct mount *mp, int flags, s vfs_resume(mp); mountlist_remove(mp); - if (TAILQ_FIRST(&mp->mnt_vnodelist) != NULL) + if ((vp = VIMPL_TO_VNODE(TAILQ_FIRST(&mp->mnt_vnodelist))) != NULL) { + vprint("dangling", vp); panic("unmount: dangling vnode"); + } vfs_hooks_unmount(mp); vfs_set_lowermount(mp, NULL);
CVS commit: src/sys/kern
Module Name:src Committed By: hannken Date: Wed Jan 17 10:17:29 UTC 2024 Modified Files: src/sys/kern: vfs_mount.c Log Message: Print dangling vnode before panic() to help debug. PR kern/57775 ""panic: unmount: dangling vnode" while umounting procfs" To generate a diff of this commit: cvs rdiff -u -r1.103 -r1.104 src/sys/kern/vfs_mount.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: andvar Date: Sun Jan 14 11:46:05 UTC 2024 Modified Files: src/sys/kern: kern_lock.c Log Message: Surround db_stacktrace() with "#ifdef DDB" check. Fixes LOCKDEBUG enabled build without DDB option. To generate a diff of this commit: cvs rdiff -u -r1.187 -r1.188 src/sys/kern/kern_lock.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_lock.c diff -u src/sys/kern/kern_lock.c:1.187 src/sys/kern/kern_lock.c:1.188 --- src/sys/kern/kern_lock.c:1.187 Wed Oct 4 20:28:06 2023 +++ src/sys/kern/kern_lock.c Sun Jan 14 11:46:05 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_lock.c,v 1.187 2023/10/04 20:28:06 ad Exp $ */ +/* $NetBSD: kern_lock.c,v 1.188 2024/01/14 11:46:05 andvar Exp $ */ /*- * Copyright (c) 2002, 2006, 2007, 2008, 2009, 2020, 2023 @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.187 2023/10/04 20:28:06 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.188 2024/01/14 11:46:05 andvar Exp $"); #ifdef _KERNEL_OPT #include "opt_lockdebug.h" @@ -137,7 +137,9 @@ lockops_t _kernel_lock_ops = { #ifdef LOCKDEBUG +#ifdef DDB #include +#endif static void kernel_lock_trace_ipi(void *cookie) @@ -146,7 +148,9 @@ kernel_lock_trace_ipi(void *cookie) printf("%s[%d %s]: hogging kernel lock\n", cpu_name(curcpu()), curlwp->l_lid, curlwp->l_name ? curlwp->l_name : curproc->p_comm); +#ifdef DDB db_stacktrace(); +#endif } #endif
CVS commit: src/sys/kern
Module Name:src Committed By: andvar Date: Sun Jan 14 11:46:05 UTC 2024 Modified Files: src/sys/kern: kern_lock.c Log Message: Surround db_stacktrace() with "#ifdef DDB" check. Fixes LOCKDEBUG enabled build without DDB option. To generate a diff of this commit: cvs rdiff -u -r1.187 -r1.188 src/sys/kern/kern_lock.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: mlelstv Date: Thu Jan 4 11:18:20 UTC 2024 Modified Files: src/sys/kern: subr_cpu.c Log Message: dump topology information with aprint_debug instead of requiring to build a DEBUG kernel. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/sys/kern/subr_cpu.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: mlelstv Date: Thu Jan 4 11:18:20 UTC 2024 Modified Files: src/sys/kern: subr_cpu.c Log Message: dump topology information with aprint_debug instead of requiring to build a DEBUG kernel. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/sys/kern/subr_cpu.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_cpu.c diff -u src/sys/kern/subr_cpu.c:1.19 src/sys/kern/subr_cpu.c:1.20 --- src/sys/kern/subr_cpu.c:1.19 Sat Jul 8 13:59:05 2023 +++ src/sys/kern/subr_cpu.c Thu Jan 4 11:18:19 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_cpu.c,v 1.19 2023/07/08 13:59:05 riastradh Exp $ */ +/* $NetBSD: subr_cpu.c,v 1.20 2024/01/04 11:18:19 mlelstv Exp $ */ /*- * Copyright (c) 2007, 2008, 2009, 2010, 2012, 2019, 2020 @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_cpu.c,v 1.19 2023/07/08 13:59:05 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_cpu.c,v 1.20 2024/01/04 11:18:19 mlelstv Exp $"); #include #include @@ -223,7 +223,6 @@ cpu_topology_link(struct cpu_info *ci, s static void cpu_topology_dump(void) { -#ifdef DEBUG CPU_INFO_ITERATOR cii; struct cpu_info *ci, *ci2; const char *names[] = { "core", "pkg", "1st" }; @@ -237,25 +236,24 @@ cpu_topology_dump(void) for (CPU_INFO_FOREACH(cii, ci)) { if (cpu_topology_haveslow) - printf("%s ", ci->ci_is_slow ? "slow" : "fast"); + aprint_debug("%s ", ci->ci_is_slow ? "slow" : "fast"); for (rel = 0; rel < __arraycount(ci->ci_sibling); rel++) { - printf("%s has %d %s siblings:", cpu_name(ci), + aprint_debug("%s has %d %s siblings:", cpu_name(ci), ci->ci_nsibling[rel], names[rel]); ci2 = ci->ci_sibling[rel]; i = 0; do { -printf(" %s", cpu_name(ci2)); +aprint_debug(" %s", cpu_name(ci2)); ci2 = ci2->ci_sibling[rel]; } while (++i < 64 && ci2 != ci->ci_sibling[rel]); if (i == 64) { -printf(" GAVE UP"); +aprint_debug(" GAVE UP"); } - printf("\n"); + aprint_debug("\n"); } - printf("%s first in package: %s\n", cpu_name(ci), + aprint_debug("%s first in package: %s\n", cpu_name(ci), cpu_name(ci->ci_package1st)); } -#endif /* DEBUG */ } /*
CVS commit: src/sys/kern
Module Name:src Committed By: hannken Date: Thu Dec 28 12:49:06 UTC 2023 Modified Files: src/sys/kern: kern_fileassoc.c Log Message: Initialize mutex fileassoc_global.lock. To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 src/sys/kern/kern_fileassoc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: hannken Date: Thu Dec 28 12:49:06 UTC 2023 Modified Files: src/sys/kern: kern_fileassoc.c Log Message: Initialize mutex fileassoc_global.lock. To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 src/sys/kern/kern_fileassoc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_fileassoc.c diff -u src/sys/kern/kern_fileassoc.c:1.37 src/sys/kern/kern_fileassoc.c:1.38 --- src/sys/kern/kern_fileassoc.c:1.37 Wed Aug 2 07:11:31 2023 +++ src/sys/kern/kern_fileassoc.c Thu Dec 28 12:49:06 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_fileassoc.c,v 1.37 2023/08/02 07:11:31 riastradh Exp $ */ +/* $NetBSD: kern_fileassoc.c,v 1.38 2023/12/28 12:49:06 hannken Exp $ */ /*- * Copyright (c) 2006 Elad Efrat @@ -28,7 +28,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_fileassoc.c,v 1.37 2023/08/02 07:11:31 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_fileassoc.c,v 1.38 2023/12/28 12:49:06 hannken Exp $"); #include "opt_fileassoc.h" @@ -219,6 +219,8 @@ fileassoc_init(void) } fileassoc_domain = specificdata_domain_create(); + mutex_init(&fileassoc_global.lock, MUTEX_DEFAULT, IPL_NONE); + return 0; }
CVS commit: src/sys/kern
Module Name:src Committed By: hannken Date: Thu Dec 28 12:48:09 UTC 2023 Modified Files: src/sys/kern: vfs_mount.c Log Message: Include "veriexec.h" and to run veriexec_unmountchk() on "NVERIEXEC > 0". To generate a diff of this commit: cvs rdiff -u -r1.102 -r1.103 src/sys/kern/vfs_mount.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_mount.c diff -u src/sys/kern/vfs_mount.c:1.102 src/sys/kern/vfs_mount.c:1.103 --- src/sys/kern/vfs_mount.c:1.102 Fri Feb 24 11:02:27 2023 +++ src/sys/kern/vfs_mount.c Thu Dec 28 12:48:08 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_mount.c,v 1.102 2023/02/24 11:02:27 riastradh Exp $ */ +/* $NetBSD: vfs_mount.c,v 1.103 2023/12/28 12:48:08 hannken Exp $ */ /*- * Copyright (c) 1997-2020 The NetBSD Foundation, Inc. @@ -67,7 +67,9 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.102 2023/02/24 11:02:27 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.103 2023/12/28 12:48:08 hannken Exp $"); + +#include "veriexec.h" #include #include @@ -85,6 +87,7 @@ __KERNEL_RCSID(0, "$NetBSD: vfs_mount.c, #include #include #include +#include #include #include #include
CVS commit: src/sys/kern
Module Name:src Committed By: hannken Date: Thu Dec 28 12:48:09 UTC 2023 Modified Files: src/sys/kern: vfs_mount.c Log Message: Include "veriexec.h" and to run veriexec_unmountchk() on "NVERIEXEC > 0". To generate a diff of this commit: cvs rdiff -u -r1.102 -r1.103 src/sys/kern/vfs_mount.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: andvar Date: Wed Dec 20 21:03:50 UTC 2023 Modified Files: src/sys/kern: kern_lwp.c Log Message: s/deatched/detached/ in comment. While here, fix an article before annoyance. To generate a diff of this commit: cvs rdiff -u -r1.268 -r1.269 src/sys/kern/kern_lwp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: andvar Date: Wed Dec 20 21:03:50 UTC 2023 Modified Files: src/sys/kern: kern_lwp.c Log Message: s/deatched/detached/ in comment. While here, fix an article before annoyance. To generate a diff of this commit: cvs rdiff -u -r1.268 -r1.269 src/sys/kern/kern_lwp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_lwp.c diff -u src/sys/kern/kern_lwp.c:1.268 src/sys/kern/kern_lwp.c:1.269 --- src/sys/kern/kern_lwp.c:1.268 Wed Dec 20 20:35:37 2023 +++ src/sys/kern/kern_lwp.c Wed Dec 20 21:03:50 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_lwp.c,v 1.268 2023/12/20 20:35:37 andvar Exp $ */ +/* $NetBSD: kern_lwp.c,v 1.269 2023/12/20 21:03:50 andvar Exp $ */ /*- * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019, 2020, 2023 @@ -217,7 +217,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.268 2023/12/20 20:35:37 andvar Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.269 2023/12/20 21:03:50 andvar Exp $"); #include "opt_ddb.h" #include "opt_lockdebug.h" @@ -1171,7 +1171,7 @@ lwp_exit(struct lwp *l) * Get rid of all references to the LWP that others (e.g. procfs) * may have, and mark the LWP as a zombie. If the LWP is detached, * mark it waiting for collection in the proc structure. Note that - * before we can do that, we need to free any other dead, deatched + * before we can do that, we need to free any other dead, detached * LWP waiting to meet its maker. * * All conditions need to be observed upon under the same hold of @@ -1666,7 +1666,7 @@ lwp_eprio(lwp_t *l) * The function of the boost is to get the LWP onto a CPU and * running quickly. Once that happens the LWP loses the priority * boost and could be preempted very quickly by another LWP but that - * won't happen often enough to be a annoyance. + * won't happen often enough to be an annoyance. */ if (pri <= MAXPRI_USER && l->l_boostpri > MAXPRI_USER) pri = (pri >> 1) + l->l_boostpri;
CVS commit: src/sys/kern
Module Name:src Committed By: pgoyette Date: Thu Dec 7 09:00:32 UTC 2023 Modified Files: src/sys/kern: tty.c Log Message: There's no COMPAT_60 code left here, so no need for conditional inclusion of header file. To generate a diff of this commit: cvs rdiff -u -r1.311 -r1.312 src/sys/kern/tty.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/tty.c diff -u src/sys/kern/tty.c:1.311 src/sys/kern/tty.c:1.312 --- src/sys/kern/tty.c:1.311 Mon May 22 14:07:37 2023 +++ src/sys/kern/tty.c Thu Dec 7 09:00:32 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: tty.c,v 1.311 2023/05/22 14:07:37 riastradh Exp $ */ +/* $NetBSD: tty.c,v 1.312 2023/12/07 09:00:32 pgoyette Exp $ */ /*- * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.311 2023/05/22 14:07:37 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.312 2023/12/07 09:00:32 pgoyette Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -103,10 +103,6 @@ __KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.31 #include #include -#ifdef COMPAT_60 -#include -#endif /* COMPAT_60 */ - static int ttnread(struct tty *); static void ttyblock(struct tty *); static void ttyecho(int, struct tty *);
CVS commit: src/sys/kern
Module Name:src Committed By: pgoyette Date: Thu Dec 7 09:00:32 UTC 2023 Modified Files: src/sys/kern: tty.c Log Message: There's no COMPAT_60 code left here, so no need for conditional inclusion of header file. To generate a diff of this commit: cvs rdiff -u -r1.311 -r1.312 src/sys/kern/tty.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: thorpej Date: Sun Dec 3 14:35:54 UTC 2023 Modified Files: src/sys/kern: subr_vmem.c Log Message: bt_freetrim(): Restructure the loop as a LIST_FOREACH_SAFE() rather than a while(). No real change in behavior now, but makes upcoming enhancements easier. To generate a diff of this commit: cvs rdiff -u -r1.112 -r1.113 src/sys/kern/subr_vmem.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: thorpej Date: Sun Dec 3 14:35:54 UTC 2023 Modified Files: src/sys/kern: subr_vmem.c Log Message: bt_freetrim(): Restructure the loop as a LIST_FOREACH_SAFE() rather than a while(). No real change in behavior now, but makes upcoming enhancements easier. To generate a diff of this commit: cvs rdiff -u -r1.112 -r1.113 src/sys/kern/subr_vmem.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_vmem.c diff -u src/sys/kern/subr_vmem.c:1.112 src/sys/kern/subr_vmem.c:1.113 --- src/sys/kern/subr_vmem.c:1.112 Sun Dec 3 02:50:09 2023 +++ src/sys/kern/subr_vmem.c Sun Dec 3 14:35:54 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_vmem.c,v 1.112 2023/12/03 02:50:09 thorpej Exp $ */ +/* $NetBSD: subr_vmem.c,v 1.113 2023/12/03 14:35:54 thorpej Exp $ */ /*- * Copyright (c)2006,2007,2008,2009 YAMAMOTO Takashi, @@ -46,7 +46,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.112 2023/12/03 02:50:09 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.113 2023/12/03 14:35:54 thorpej Exp $"); #if defined(_KERNEL) && defined(_KERNEL_OPT) #include "opt_ddb.h" @@ -347,15 +347,17 @@ bt_free(vmem_t *vm, bt_t *bt) static void bt_freetrim(vmem_t *vm, int freelimit) { - bt_t *t; + bt_t *bt, *next_bt; LIST_HEAD(, vmem_btag) tofree; VMEM_ASSERT_LOCKED(vm); LIST_INIT(&tofree); - while (vm->vm_nfreetags > freelimit) { - bt_t *bt = LIST_FIRST(&vm->vm_freetags); + LIST_FOREACH_SAFE(bt, &vm->vm_freetags, bt_freelist, next_bt) { + if (vm->vm_nfreetags <= freelimit) { + break; + } LIST_REMOVE(bt, bt_freelist); vm->vm_nfreetags--; if (bt >= static_bts @@ -372,9 +374,9 @@ bt_freetrim(vmem_t *vm, int freelimit) VMEM_UNLOCK(vm); while (!LIST_EMPTY(&tofree)) { - t = LIST_FIRST(&tofree); - LIST_REMOVE(t, bt_freelist); - pool_put(&vmem_btag_pool, t); + bt = LIST_FIRST(&tofree); + LIST_REMOVE(bt, bt_freelist); + pool_put(&vmem_btag_pool, bt); } } #endif /* defined(_KERNEL) */
CVS commit: src/sys/kern
Module Name:src Committed By: thorpej Date: Sun Dec 3 02:50:09 UTC 2023 Modified Files: src/sys/kern: subr_vmem.c Log Message: Assert that the vmem_btag_pool has been initialized before we attempt to allocate from it. To generate a diff of this commit: cvs rdiff -u -r1.111 -r1.112 src/sys/kern/subr_vmem.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: thorpej Date: Sun Dec 3 02:50:09 UTC 2023 Modified Files: src/sys/kern: subr_vmem.c Log Message: Assert that the vmem_btag_pool has been initialized before we attempt to allocate from it. To generate a diff of this commit: cvs rdiff -u -r1.111 -r1.112 src/sys/kern/subr_vmem.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_vmem.c diff -u src/sys/kern/subr_vmem.c:1.111 src/sys/kern/subr_vmem.c:1.112 --- src/sys/kern/subr_vmem.c:1.111 Sat Dec 2 21:02:12 2023 +++ src/sys/kern/subr_vmem.c Sun Dec 3 02:50:09 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_vmem.c,v 1.111 2023/12/02 21:02:12 thorpej Exp $ */ +/* $NetBSD: subr_vmem.c,v 1.112 2023/12/03 02:50:09 thorpej Exp $ */ /*- * Copyright (c)2006,2007,2008,2009 YAMAMOTO Takashi, @@ -46,7 +46,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.111 2023/12/02 21:02:12 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.112 2023/12/03 02:50:09 thorpej Exp $"); #if defined(_KERNEL) && defined(_KERNEL_OPT) #include "opt_ddb.h" @@ -205,6 +205,7 @@ static kmutex_t vmem_btag_lock; static LIST_HEAD(, vmem_btag) vmem_btag_freelist; static size_t vmem_btag_freelist_count = 0; static struct pool vmem_btag_pool; +static bool vmem_btag_pool_initialized __read_mostly; /* boundary tag */ @@ -263,6 +264,7 @@ bt_refill_locked(vmem_t *vm) while (vm->vm_nfreetags <= BT_MINRESERVE) { VMEM_UNLOCK(vm); + KASSERT(vmem_btag_pool_initialized); mutex_enter(&vmem_btag_refill_lock); bt = pool_get(&vmem_btag_pool, PR_NOWAIT); mutex_exit(&vmem_btag_refill_lock); @@ -697,6 +699,7 @@ vmem_subsystem_init(vmem_t *vm) pool_init(&vmem_btag_pool, sizeof(bt_t), coherency_unit, 0, PR_PHINPAGE, "vmembt", &pool_allocator_vmem_meta, IPL_VM); + vmem_btag_pool_initialized = true; } #endif /* defined(_KERNEL) */
CVS commit: src/sys/kern
Module Name:src Committed By: thorpej Date: Sat Dec 2 19:06:17 UTC 2023 Modified Files: src/sys/kern: subr_vmem.c Log Message: Minor changes to let this build as the "subr_vmem" test program again. To generate a diff of this commit: cvs rdiff -u -r1.109 -r1.110 src/sys/kern/subr_vmem.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_vmem.c diff -u src/sys/kern/subr_vmem.c:1.109 src/sys/kern/subr_vmem.c:1.110 --- src/sys/kern/subr_vmem.c:1.109 Sun Apr 9 09:18:09 2023 +++ src/sys/kern/subr_vmem.c Sat Dec 2 19:06:17 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_vmem.c,v 1.109 2023/04/09 09:18:09 riastradh Exp $ */ +/* $NetBSD: subr_vmem.c,v 1.110 2023/12/02 19:06:17 thorpej Exp $ */ /*- * Copyright (c)2006,2007,2008,2009 YAMAMOTO Takashi, @@ -46,7 +46,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.109 2023/04/09 09:18:09 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.110 2023/12/02 19:06:17 thorpej Exp $"); #if defined(_KERNEL) && defined(_KERNEL_OPT) #include "opt_ddb.h" @@ -112,12 +112,13 @@ VMEM_EVCNT_DEFINE(static_bt_inuse) #define UNITTEST #define KASSERT(a) assert(a) +#define KASSERTMSG(a, m, ...) assert(a) #define mutex_init(a, b, c) /* nothing */ #define mutex_destroy(a) /* nothing */ #define mutex_enter(a) /* nothing */ #define mutex_tryenter(a) true #define mutex_exit(a) /* nothing */ -#define mutex_owned(a) /* nothing */ +#define mutex_owned(a) true #define ASSERT_SLEEPABLE() /* nothing */ #define panic(...) printf(__VA_ARGS__); abort() #endif /* defined(_KERNEL) */ @@ -142,12 +143,12 @@ static LIST_HEAD(, vmem) vmem_list = LIS /* misc */ -#define VMEM_LOCK(vm) mutex_enter(&vm->vm_lock) -#define VMEM_TRYLOCK(vm) mutex_tryenter(&vm->vm_lock) -#define VMEM_UNLOCK(vm) mutex_exit(&vm->vm_lock) -#define VMEM_LOCK_INIT(vm, ipl) mutex_init(&vm->vm_lock, MUTEX_DEFAULT, ipl) -#define VMEM_LOCK_DESTROY(vm) mutex_destroy(&vm->vm_lock) -#define VMEM_ASSERT_LOCKED(vm) KASSERT(mutex_owned(&vm->vm_lock)) +#define VMEM_LOCK(vm) mutex_enter(&(vm)->vm_lock) +#define VMEM_TRYLOCK(vm) mutex_tryenter(&(vm)->vm_lock) +#define VMEM_UNLOCK(vm) mutex_exit(&(vm)->vm_lock) +#define VMEM_LOCK_INIT(vm, ipl) mutex_init(&(vm)->vm_lock, MUTEX_DEFAULT, (ipl)) +#define VMEM_LOCK_DESTROY(vm) mutex_destroy(&(vm)->vm_lock) +#define VMEM_ASSERT_LOCKED(vm) KASSERT(mutex_owned(&(vm)->vm_lock)) #define VMEM_ALIGNUP(addr, align) \ (-(-(addr) & -(align))) @@ -158,11 +159,22 @@ static LIST_HEAD(, vmem) vmem_list = LIS #define ORDER2SIZE(order) ((vmem_size_t)1 << (order)) #define SIZE2ORDER(size) ((int)ilog2(size)) +static void +vmem_kick_pdaemon(void) +{ +#if defined(_KERNEL) + uvm_kick_pdaemon(); +#endif +} + +static void vmem_xfree_bt(vmem_t *, bt_t *); + #if !defined(_KERNEL) #define xmalloc(sz, flags) malloc(sz) #define xfree(p, sz) free(p) #define bt_alloc(vm, flags) malloc(sizeof(bt_t)) #define bt_free(vm, bt) free(bt) +#define bt_freetrim(vm, l) /* nothing */ #else /* defined(_KERNEL) */ #define xmalloc(sz, flags) \ @@ -194,16 +206,6 @@ static LIST_HEAD(, vmem_btag) vmem_btag_ static size_t vmem_btag_freelist_count = 0; static struct pool vmem_btag_pool; -static void vmem_xfree_bt(vmem_t *, bt_t *); - -static void -vmem_kick_pdaemon(void) -{ -#if defined(_KERNEL) - uvm_kick_pdaemon(); -#endif -} - /* boundary tag */ static int bt_refill(vmem_t *vm); @@ -807,6 +809,7 @@ vmem_import(vmem_t *vm, vmem_size_t size return 0; } +#if defined(_KERNEL) static int vmem_rehash(vmem_t *vm, size_t newhashsize, vm_flag_t flags) { @@ -864,6 +867,7 @@ vmem_rehash(vmem_t *vm, size_t newhashsi return 0; } +#endif /* _KERNEL */ /* * vmem_fit: check if a bt can satisfy the given restrictions. @@ -1096,7 +1100,9 @@ vmem_alloc(vmem_t *vm, vmem_size_t size, error = vmem_xalloc(vm, size, 0, 0, 0, VMEM_ADDR_MIN, VMEM_ADDR_MAX, flags, addrp); -out: +#if defined(QCACHE) + out: +#endif /* defined(QCACHE) */ KASSERTMSG(error || addrp == NULL || (*addrp & vm->vm_quantum_mask) == 0, "vmem %s mask=0x%jx addr=0x%jx", @@ -1353,8 +1359,10 @@ vmem_xfreeall(vmem_t *vm) { bt_t *bt; +#if defined(QCACHE) /* This can't be used if the arena has a quantum cache. */ KASSERT(vm->vm_qcache_max == 0); +#endif /* defined(QCACHE) */ for (;;) { VMEM_LOCK(vm);
CVS commit: src/sys/kern
Module Name:src Committed By: thorpej Date: Sat Dec 2 19:06:17 UTC 2023 Modified Files: src/sys/kern: subr_vmem.c Log Message: Minor changes to let this build as the "subr_vmem" test program again. To generate a diff of this commit: cvs rdiff -u -r1.109 -r1.110 src/sys/kern/subr_vmem.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: hannken Date: Mon Nov 27 16:13:59 UTC 2023 Modified Files: src/sys/kern: vfs_vnode.c Log Message: Restore kpause() accidentially removed with last commit. To generate a diff of this commit: cvs rdiff -u -r1.152 -r1.153 src/sys/kern/vfs_vnode.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: hannken Date: Mon Nov 27 16:13:59 UTC 2023 Modified Files: src/sys/kern: vfs_vnode.c Log Message: Restore kpause() accidentially removed with last commit. To generate a diff of this commit: cvs rdiff -u -r1.152 -r1.153 src/sys/kern/vfs_vnode.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_vnode.c diff -u src/sys/kern/vfs_vnode.c:1.152 src/sys/kern/vfs_vnode.c:1.153 --- src/sys/kern/vfs_vnode.c:1.152 Mon Nov 27 10:03:40 2023 +++ src/sys/kern/vfs_vnode.c Mon Nov 27 16:13:59 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_vnode.c,v 1.152 2023/11/27 10:03:40 hannken Exp $ */ +/* $NetBSD: vfs_vnode.c,v 1.153 2023/11/27 16:13:59 hannken Exp $ */ /*- * Copyright (c) 1997-2011, 2019, 2020 The NetBSD Foundation, Inc. @@ -148,7 +148,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.152 2023/11/27 10:03:40 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.153 2023/11/27 16:13:59 hannken Exp $"); #ifdef _KERNEL_OPT #include "opt_pax.h" @@ -709,7 +709,7 @@ vdrain_task(struct threadpool_job *job) mutex_enter(&vdrain_lock); while (!vdrain_one(target)) - ; + kpause("vdrain", false, 1, &vdrain_lock); threadpool_job_done(job); mutex_exit(&vdrain_lock);
CVS commit: src/sys/kern
Module Name:src Committed By: hannken Date: Mon Nov 27 10:03:40 UTC 2023 Modified Files: src/sys/kern: vfs_vnode.c Log Message: Implement and use an iterator over LRU lists. Replace the vdrain kernel thread with two threadpool jobs, one to process deferred vrele and one to keep the number of allocated vnodes below limit. To generate a diff of this commit: cvs rdiff -u -r1.151 -r1.152 src/sys/kern/vfs_vnode.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_vnode.c diff -u src/sys/kern/vfs_vnode.c:1.151 src/sys/kern/vfs_vnode.c:1.152 --- src/sys/kern/vfs_vnode.c:1.151 Wed Nov 22 13:19:50 2023 +++ src/sys/kern/vfs_vnode.c Mon Nov 27 10:03:40 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_vnode.c,v 1.151 2023/11/22 13:19:50 riastradh Exp $ */ +/* $NetBSD: vfs_vnode.c,v 1.152 2023/11/27 10:03:40 hannken Exp $ */ /*- * Copyright (c) 1997-2011, 2019, 2020 The NetBSD Foundation, Inc. @@ -148,7 +148,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.151 2023/11/22 13:19:50 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.152 2023/11/27 10:03:40 hannken Exp $"); #ifdef _KERNEL_OPT #include "opt_pax.h" @@ -164,7 +164,6 @@ __KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c, #include #include #include -#include #include #include #include @@ -172,6 +171,7 @@ __KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c, #include #include #include +#include #include #include #include @@ -198,14 +198,17 @@ __KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c, * private cache line as vnodes migrate between them while under the same * lock (vdrain_lock). */ + +typedef struct { + vnode_impl_t *li_marker; +} lru_iter_t; + u_int numvnodes __cacheline_aligned; static vnodelst_t lru_list[LRU_COUNT] __cacheline_aligned; +static struct threadpool *threadpool; +static struct threadpool_job vdrain_job; +static struct threadpool_job vrele_job; static kmutex_t vdrain_lock __cacheline_aligned; -static kcondvar_t vdrain_cv; -static int vdrain_gen; -static kcondvar_t vdrain_gen_cv; -static bool vdrain_retry; -static lwp_t * vdrain_lwp; SLIST_HEAD(hashhead, vnode_impl); static kmutex_t vcache_lock __cacheline_aligned; static kcondvar_t vcache_cv; @@ -215,16 +218,22 @@ static struct hashhead *vcache_hashtab; static pool_cache_t vcache_pool; static void lru_requeue(vnode_t *, vnodelst_t *); static vnodelst_t * lru_which(vnode_t *); +static vnode_impl_t * lru_iter_first(int, lru_iter_t *); +static vnode_impl_t * lru_iter_next(lru_iter_t *); +static void lru_iter_release(lru_iter_t *); static vnode_impl_t * vcache_alloc(void); static void vcache_dealloc(vnode_impl_t *); static void vcache_free(vnode_impl_t *); static void vcache_init(void); static void vcache_reinit(void); static void vcache_reclaim(vnode_t *); +static void vrele_deferred(vnode_impl_t *); static void vrelel(vnode_t *, int, int); -static void vdrain_thread(void *); static void vnpanic(vnode_t *, const char *, ...) __printflike(2, 3); +static bool vdrain_one(u_int); +static void vdrain_task(struct threadpool_job *); +static void vrele_task(struct threadpool_job *); /* Routines having to do with the management of the vnode table. */ @@ -424,11 +433,10 @@ vfs_vnode_sysinit(void) } vcache_init(); - cv_init(&vdrain_cv, "vdrain"); - cv_init(&vdrain_gen_cv, "vdrainwt"); - error = kthread_create(PRI_VM, KTHREAD_MPSAFE, NULL, vdrain_thread, - NULL, &vdrain_lwp, "vdrain"); - KASSERTMSG((error == 0), "kthread_create(vdrain) failed: %d", error); + error = threadpool_get(&threadpool, PRI_NONE); + KASSERTMSG((error == 0), "threadpool_get failed: %d", error); + threadpool_job_init(&vdrain_job, vdrain_task, &vdrain_lock, "vdrain"); + threadpool_job_init(&vrele_job, vrele_task, &vdrain_lock, "vrele"); } /* @@ -536,189 +544,208 @@ lru_requeue(vnode_t *vp, vnodelst_t *lis */ numvnodes += d; } - if ((d > 0 && numvnodes > desiredvnodes) || - listhd == &lru_list[LRU_VRELE]) - cv_signal(&vdrain_cv); + if (listhd == &lru_list[LRU_VRELE]) + threadpool_schedule_job(threadpool, &vrele_job); + if (d > 0 && numvnodes > desiredvnodes) + threadpool_schedule_job(threadpool, &vdrain_job); if (d > 0 && numvnodes > desiredvnodes + desiredvnodes / 16) kpause("vnfull", false, MAX(1, mstohz(10)), &vdrain_lock); mutex_exit(&vdrain_lock); } /* - * Release deferred vrele vnodes for this mount. - * Called with file system suspended. + * LRU list iterator. + * Caller holds vdrain_lock. */ -void -vrele_flush(struct mount *mp) +static vnode_impl_t * +lru_iter_first(int idx, lru_iter_t *iterp) { - vnode_impl_t *vip, *marker; - vnode_t *vp; - int when = 0; + vnode_impl_t *marker; - KASSERT(fstrans_is_owner(mp)); + KASSERT(mutex_owned(&vdrain_lock)); + mutex_exit(&vdrain_lock); marker = VNODE_TO_VIMPL(vnalloc_marker(NULL)); - mutex_enter(&vdrain_lock); - TAILQ_INSERT_HEAD(
CVS commit: src/sys/kern
Module Name:src Committed By: hannken Date: Mon Nov 27 10:03:40 UTC 2023 Modified Files: src/sys/kern: vfs_vnode.c Log Message: Implement and use an iterator over LRU lists. Replace the vdrain kernel thread with two threadpool jobs, one to process deferred vrele and one to keep the number of allocated vnodes below limit. To generate a diff of this commit: cvs rdiff -u -r1.151 -r1.152 src/sys/kern/vfs_vnode.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: ozaki-r Date: Mon Nov 27 02:50:27 UTC 2023 Modified Files: src/sys/kern: uipc_mbuf.c Log Message: mbuf: avoid assertion failure when splitting mbuf cluster >From OpenBSD: commit 7b4d35e0a60ba1dd4daf4b1c2932020a22463a89 Author: bluhm Date: Fri Oct 20 16:25:15 2023 + Avoid assertion failure when splitting mbuf cluster. m_split() calls m_align() to initialize the data pointer of newly allocated mbuf. If the new mbuf will be converted to a cluster, this is not necessary. If additionally the new mbuf is larger than MLEN, this can lead to a panic. Only call m_align() when a valid m_data is needed. This is the case if we do not refecence the existing cluster, but memcpy() the data into the new mbuf. Reported-by: syzbot+0e6817f5877926f0e...@syzkaller.appspotmail.com OK claudio@ deraadt@ The issue is harmless if DIAGNOSTIC is not enabled. XXX pullup-10 XXX pullup-9 To generate a diff of this commit: cvs rdiff -u -r1.251 -r1.252 src/sys/kern/uipc_mbuf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/uipc_mbuf.c diff -u src/sys/kern/uipc_mbuf.c:1.251 src/sys/kern/uipc_mbuf.c:1.252 --- src/sys/kern/uipc_mbuf.c:1.251 Wed Apr 12 06:48:08 2023 +++ src/sys/kern/uipc_mbuf.c Mon Nov 27 02:50:27 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_mbuf.c,v 1.251 2023/04/12 06:48:08 riastradh Exp $ */ +/* $NetBSD: uipc_mbuf.c,v 1.252 2023/11/27 02:50:27 ozaki-r Exp $ */ /* * Copyright (c) 1999, 2001, 2018 The NetBSD Foundation, Inc. @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.251 2023/04/12 06:48:08 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.252 2023/11/27 02:50:27 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_mbuftrace.h" @@ -1343,10 +1343,7 @@ m_split_internal(struct mbuf *m0, int le len_save = m0->m_pkthdr.len; m0->m_pkthdr.len = len0; - if (m->m_flags & M_EXT) - goto extpacket; - - if (remain > MHLEN) { + if ((m->m_flags & M_EXT) == 0 && remain > MHLEN) { /* m can't be the lead packet */ m_align(n, 0); n->m_len = 0; @@ -1357,8 +1354,6 @@ m_split_internal(struct mbuf *m0, int le return NULL; } return n; - } else { - m_align(n, remain); } } else if (remain == 0) { n = m->m_next; @@ -1369,14 +1364,13 @@ m_split_internal(struct mbuf *m0, int le if (n == NULL) return NULL; MCLAIM(n, m->m_owner); - m_align(n, remain); } -extpacket: if (m->m_flags & M_EXT) { n->m_data = m->m_data + len; MCLADDREFERENCE(m, n); } else { + m_align(n, remain); memcpy(mtod(n, void *), mtod(m, char *) + len, remain); }
CVS commit: src/sys/kern
Module Name:src Committed By: ozaki-r Date: Mon Nov 27 02:50:27 UTC 2023 Modified Files: src/sys/kern: uipc_mbuf.c Log Message: mbuf: avoid assertion failure when splitting mbuf cluster >From OpenBSD: commit 7b4d35e0a60ba1dd4daf4b1c2932020a22463a89 Author: bluhm Date: Fri Oct 20 16:25:15 2023 + Avoid assertion failure when splitting mbuf cluster. m_split() calls m_align() to initialize the data pointer of newly allocated mbuf. If the new mbuf will be converted to a cluster, this is not necessary. If additionally the new mbuf is larger than MLEN, this can lead to a panic. Only call m_align() when a valid m_data is needed. This is the case if we do not refecence the existing cluster, but memcpy() the data into the new mbuf. Reported-by: syzbot+0e6817f5877926f0e...@syzkaller.appspotmail.com OK claudio@ deraadt@ The issue is harmless if DIAGNOSTIC is not enabled. XXX pullup-10 XXX pullup-9 To generate a diff of this commit: cvs rdiff -u -r1.251 -r1.252 src/sys/kern/uipc_mbuf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Wed Nov 22 13:19:50 UTC 2023 Modified Files: src/sys/kern: vfs_vnode.c Log Message: vfs(9): Make sure to kpause at least one tick, not zero. kpause(9) forbids zero. Local workaround for wider problem in PR kern/57718, to address immediate symptom of crash on any system with hz=50, e.g. alpha in qemu: panic: kernel diagnostic assertion "timo != 0 || intr" failed: file "/usr/src/sys/kern/kern_synch.c", line 249 XXX pullup-10 XXX pullup-9 XXX pullup-8 To generate a diff of this commit: cvs rdiff -u -r1.150 -r1.151 src/sys/kern/vfs_vnode.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_vnode.c diff -u src/sys/kern/vfs_vnode.c:1.150 src/sys/kern/vfs_vnode.c:1.151 --- src/sys/kern/vfs_vnode.c:1.150 Mon Nov 6 12:17:50 2023 +++ src/sys/kern/vfs_vnode.c Wed Nov 22 13:19:50 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_vnode.c,v 1.150 2023/11/06 12:17:50 hannken Exp $ */ +/* $NetBSD: vfs_vnode.c,v 1.151 2023/11/22 13:19:50 riastradh Exp $ */ /*- * Copyright (c) 1997-2011, 2019, 2020 The NetBSD Foundation, Inc. @@ -148,7 +148,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.150 2023/11/06 12:17:50 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.151 2023/11/22 13:19:50 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_pax.h" @@ -540,7 +540,7 @@ lru_requeue(vnode_t *vp, vnodelst_t *lis listhd == &lru_list[LRU_VRELE]) cv_signal(&vdrain_cv); if (d > 0 && numvnodes > desiredvnodes + desiredvnodes / 16) - kpause("vnfull", false, mstohz(10), &vdrain_lock); + kpause("vnfull", false, MAX(1, mstohz(10)), &vdrain_lock); mutex_exit(&vdrain_lock); }
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Wed Nov 22 13:19:50 UTC 2023 Modified Files: src/sys/kern: vfs_vnode.c Log Message: vfs(9): Make sure to kpause at least one tick, not zero. kpause(9) forbids zero. Local workaround for wider problem in PR kern/57718, to address immediate symptom of crash on any system with hz=50, e.g. alpha in qemu: panic: kernel diagnostic assertion "timo != 0 || intr" failed: file "/usr/src/sys/kern/kern_synch.c", line 249 XXX pullup-10 XXX pullup-9 XXX pullup-8 To generate a diff of this commit: cvs rdiff -u -r1.150 -r1.151 src/sys/kern/vfs_vnode.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Wed Nov 22 13:18:49 UTC 2023 Modified Files: src/sys/kern: kern_synch.c Log Message: kpause(9): KASSERT -> KASSERTMSG PR kern/57718 (might help to diagnose manifestations of the problem) To generate a diff of this commit: cvs rdiff -u -r1.365 -r1.366 src/sys/kern/kern_synch.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_synch.c diff -u src/sys/kern/kern_synch.c:1.365 src/sys/kern/kern_synch.c:1.366 --- src/sys/kern/kern_synch.c:1.365 Sun Oct 15 10:29:10 2023 +++ src/sys/kern/kern_synch.c Wed Nov 22 13:18:48 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_synch.c,v 1.365 2023/10/15 10:29:10 riastradh Exp $ */ +/* $NetBSD: kern_synch.c,v 1.366 2023/11/22 13:18:48 riastradh Exp $ */ /*- * Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2009, 2019, 2020, 2023 @@ -69,7 +69,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.365 2023/10/15 10:29:10 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.366 2023/11/22 13:18:48 riastradh Exp $"); #include "opt_kstack.h" #include "opt_ddb.h" @@ -246,7 +246,8 @@ kpause(const char *wmesg, bool intr, int struct lwp *l = curlwp; int error, nlocks; - KASSERT(timo != 0 || intr); + KASSERTMSG(timo != 0 || intr, "wmesg=%s intr=%s timo=%d mtx=%p", + wmesg, intr ? "true" : "false", timo, mtx); if (sleepq_dontsleep(l)) return sleepq_abort(NULL, 0);
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Wed Nov 22 13:18:49 UTC 2023 Modified Files: src/sys/kern: kern_synch.c Log Message: kpause(9): KASSERT -> KASSERTMSG PR kern/57718 (might help to diagnose manifestations of the problem) To generate a diff of this commit: cvs rdiff -u -r1.365 -r1.366 src/sys/kern/kern_synch.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: martin Date: Tue Nov 21 12:12:26 UTC 2023 Modified Files: src/sys/kern: exec_subr.c Log Message: Stopgap build fix for kernels w/o PAX_MPROTECT after the fixes for PR 57711: mark variable as unused (sometimes, e.g. in macppc kernels). To generate a diff of this commit: cvs rdiff -u -r1.86 -r1.87 src/sys/kern/exec_subr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/exec_subr.c diff -u src/sys/kern/exec_subr.c:1.86 src/sys/kern/exec_subr.c:1.87 --- src/sys/kern/exec_subr.c:1.86 Tue Nov 21 00:09:18 2023 +++ src/sys/kern/exec_subr.c Tue Nov 21 12:12:26 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: exec_subr.c,v 1.86 2023/11/21 00:09:18 riastradh Exp $ */ +/* $NetBSD: exec_subr.c,v 1.87 2023/11/21 12:12:26 martin Exp $ */ /* * Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: exec_subr.c,v 1.86 2023/11/21 00:09:18 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: exec_subr.c,v 1.87 2023/11/21 12:12:26 martin Exp $"); #include "opt_pax.h" @@ -162,7 +162,7 @@ static int vmcmd_get_prot(struct lwp *l, const struct exec_vmcmd *cmd, vm_prot_t *prot, vm_prot_t *maxprot) { - vm_prot_t extraprot = PROT_MPROTECT_EXTRACT(cmd->ev_prot); + vm_prot_t extraprot __unused = PROT_MPROTECT_EXTRACT(cmd->ev_prot); *prot = cmd->ev_prot & UVM_PROT_ALL; *maxprot = PAX_MPROTECT_MAXPROTECT(l, *prot, extraprot, UVM_PROT_ALL);
CVS commit: src/sys/kern
Module Name:src Committed By: martin Date: Tue Nov 21 12:12:26 UTC 2023 Modified Files: src/sys/kern: exec_subr.c Log Message: Stopgap build fix for kernels w/o PAX_MPROTECT after the fixes for PR 57711: mark variable as unused (sometimes, e.g. in macppc kernels). To generate a diff of this commit: cvs rdiff -u -r1.86 -r1.87 src/sys/kern/exec_subr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Sun Nov 19 17:16:00 UTC 2023 Modified Files: src/sys/kern: sys_eventfd.c Log Message: eventfd(2): Prune dead branch. Fallout from PR kern/57703 fix. XXX pullup-10 To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sys/kern/sys_eventfd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_eventfd.c diff -u src/sys/kern/sys_eventfd.c:1.10 src/sys/kern/sys_eventfd.c:1.11 --- src/sys/kern/sys_eventfd.c:1.10 Sun Nov 19 04:13:37 2023 +++ src/sys/kern/sys_eventfd.c Sun Nov 19 17:16:00 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_eventfd.c,v 1.10 2023/11/19 04:13:37 riastradh Exp $ */ +/* $NetBSD: sys_eventfd.c,v 1.11 2023/11/19 17:16:00 riastradh Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sys_eventfd.c,v 1.10 2023/11/19 04:13:37 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_eventfd.c,v 1.11 2023/11/19 17:16:00 riastradh Exp $"); /* * eventfd @@ -196,9 +196,7 @@ eventfd_wake(struct eventfd * const efd, sel = &efd->efd_write_sel; pollev = POLLOUT | POLLWRNORM; } - if (waitcv != NULL) { - cv_broadcast(waitcv); - } + cv_broadcast(waitcv); selnotify(sel, pollev, NOTE_SUBMIT); }
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Sun Nov 19 17:16:00 UTC 2023 Modified Files: src/sys/kern: sys_eventfd.c Log Message: eventfd(2): Prune dead branch. Fallout from PR kern/57703 fix. XXX pullup-10 To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sys/kern/sys_eventfd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Sun Nov 19 04:13:38 UTC 2023 Modified Files: src/sys/kern: sys_eventfd.c Log Message: eventfd(2): Omit needless micro-optimization causing PR kern/57703. Unfortunately, owing to PR kern/57705 and PR misc/57706, it isn't convenient to flip the xfail switch on a test for this bug. So we'll do that separately. (But I did verify that a rumpified version of the test postd to PR kern/57703 failed without this change, and passed with this change.) PR kern/57703 XXX pullup-10 To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/sys/kern/sys_eventfd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/sys_eventfd.c diff -u src/sys/kern/sys_eventfd.c:1.9 src/sys/kern/sys_eventfd.c:1.10 --- src/sys/kern/sys_eventfd.c:1.9 Thu Feb 17 16:28:29 2022 +++ src/sys/kern/sys_eventfd.c Sun Nov 19 04:13:37 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_eventfd.c,v 1.9 2022/02/17 16:28:29 thorpej Exp $ */ +/* $NetBSD: sys_eventfd.c,v 1.10 2023/11/19 04:13:37 riastradh Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sys_eventfd.c,v 1.9 2022/02/17 16:28:29 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_eventfd.c,v 1.10 2023/11/19 04:13:37 riastradh Exp $"); /* * eventfd @@ -69,8 +69,6 @@ struct eventfd { eventfd_t efd_val; int64_t efd_nwaiters; bool efd_restarting; - bool efd_has_read_waiters; - bool efd_has_write_waiters; bool efd_is_semaphore; /* @@ -117,8 +115,6 @@ eventfd_destroy(struct eventfd * const e { KASSERT(efd->efd_nwaiters == 0); - KASSERT(efd->efd_has_read_waiters == false); - KASSERT(efd->efd_has_write_waiters == false); cv_destroy(&efd->efd_read_wait); cv_destroy(&efd->efd_write_wait); @@ -155,10 +151,8 @@ eventfd_wait(struct eventfd * const efd, } if (is_write) { - efd->efd_has_write_waiters = true; waitcv = &efd->efd_write_wait; } else { - efd->efd_has_read_waiters = true; waitcv = &efd->efd_read_wait; } @@ -194,17 +188,11 @@ eventfd_wake(struct eventfd * const efd, int pollev; if (is_write) { - if (efd->efd_has_read_waiters) { - waitcv = &efd->efd_read_wait; - efd->efd_has_read_waiters = false; - } + waitcv = &efd->efd_read_wait; sel = &efd->efd_read_sel; pollev = POLLIN | POLLRDNORM; } else { - if (efd->efd_has_write_waiters) { - waitcv = &efd->efd_write_wait; - efd->efd_has_write_waiters = false; - } + waitcv = &efd->efd_write_wait; sel = &efd->efd_write_sel; pollev = POLLOUT | POLLWRNORM; } @@ -537,14 +525,8 @@ eventfd_fop_restart(file_t * const fp) if (efd->efd_nwaiters != 0) { efd->efd_restarting = true; - if (efd->efd_has_read_waiters) { - cv_broadcast(&efd->efd_read_wait); - efd->efd_has_read_waiters = false; - } - if (efd->efd_has_write_waiters) { - cv_broadcast(&efd->efd_write_wait); - efd->efd_has_write_waiters = false; - } + cv_broadcast(&efd->efd_read_wait); + cv_broadcast(&efd->efd_write_wait); } mutex_exit(&efd->efd_lock);
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Sun Nov 19 04:13:38 UTC 2023 Modified Files: src/sys/kern: sys_eventfd.c Log Message: eventfd(2): Omit needless micro-optimization causing PR kern/57703. Unfortunately, owing to PR kern/57705 and PR misc/57706, it isn't convenient to flip the xfail switch on a test for this bug. So we'll do that separately. (But I did verify that a rumpified version of the test postd to PR kern/57703 failed without this change, and passed with this change.) PR kern/57703 XXX pullup-10 To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/sys/kern/sys_eventfd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: hannken Date: Mon Nov 6 12:17:50 UTC 2023 Modified Files: src/sys/kern: vfs_vnode.c Log Message: As the number of allocated vnodes goes beyond 106% of desiredvnodes start throttling threads allocating new vnodes at a rate of ~100 new vnodes per second and thread. To generate a diff of this commit: cvs rdiff -u -r1.149 -r1.150 src/sys/kern/vfs_vnode.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/vfs_vnode.c diff -u src/sys/kern/vfs_vnode.c:1.149 src/sys/kern/vfs_vnode.c:1.150 --- src/sys/kern/vfs_vnode.c:1.149 Fri Feb 24 11:02:27 2023 +++ src/sys/kern/vfs_vnode.c Mon Nov 6 12:17:50 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_vnode.c,v 1.149 2023/02/24 11:02:27 riastradh Exp $ */ +/* $NetBSD: vfs_vnode.c,v 1.150 2023/11/06 12:17:50 hannken Exp $ */ /*- * Copyright (c) 1997-2011, 2019, 2020 The NetBSD Foundation, Inc. @@ -148,7 +148,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.149 2023/02/24 11:02:27 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.150 2023/11/06 12:17:50 hannken Exp $"); #ifdef _KERNEL_OPT #include "opt_pax.h" @@ -539,6 +539,8 @@ lru_requeue(vnode_t *vp, vnodelst_t *lis if ((d > 0 && numvnodes > desiredvnodes) || listhd == &lru_list[LRU_VRELE]) cv_signal(&vdrain_cv); + if (d > 0 && numvnodes > desiredvnodes + desiredvnodes / 16) + kpause("vnfull", false, mstohz(10), &vdrain_lock); mutex_exit(&vdrain_lock); } @@ -689,7 +691,7 @@ vdrain_thread(void *cookie) for (;;) { vdrain_retry = false; - target = desiredvnodes - desiredvnodes/10; + target = desiredvnodes - desiredvnodes / 16; for (i = 0; i < LRU_COUNT; i++) { TAILQ_INSERT_HEAD(&lru_list[i], marker, vi_lrulist);
CVS commit: src/sys/kern
Module Name:src Committed By: hannken Date: Mon Nov 6 12:17:50 UTC 2023 Modified Files: src/sys/kern: vfs_vnode.c Log Message: As the number of allocated vnodes goes beyond 106% of desiredvnodes start throttling threads allocating new vnodes at a rate of ~100 new vnodes per second and thread. To generate a diff of this commit: cvs rdiff -u -r1.149 -r1.150 src/sys/kern/vfs_vnode.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Tue Oct 17 11:57:20 UTC 2023 Modified Files: src/sys/kern: subr_thmap.c Log Message: thmap(9): Preallocate GC list storage for thmap_del. thmap_del can't fail, and it is used in places in npf where sleeping is forbidden, so it can't rely on allocating memory either. Instead of having thmap_del allocate memory on the fly for each object to defer freeing until thmap_gc, arrange to have thmap(9) preallocate the same storage when allocating all the objects in the first place, with a GC header. This is suboptimal for memory usage, especially on insertion- and lookup-heavy but deletion-light workloads, but it's not clear rmind's alternative (https://github.com/rmind/thmap/tree/thmap_del_mem_fail) is ready to use yet, so we'll go with this for correctness. PR kern/57208 https://github.com/rmind/npf/issues/129 XXX pullup-10 XXX pullup-9 To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/sys/kern/subr_thmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_thmap.c diff -u src/sys/kern/subr_thmap.c:1.14 src/sys/kern/subr_thmap.c:1.15 --- src/sys/kern/subr_thmap.c:1.14 Tue Oct 17 11:55:28 2023 +++ src/sys/kern/subr_thmap.c Tue Oct 17 11:57:20 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_thmap.c,v 1.14 2023/10/17 11:55:28 riastradh Exp $ */ +/* $NetBSD: subr_thmap.c,v 1.15 2023/10/17 11:57:20 riastradh Exp $ */ /*- * Copyright (c) 2018 Mindaugas Rasiukevicius @@ -112,7 +112,7 @@ #include "utils.h" #endif -THMAP_RCSID("$NetBSD: subr_thmap.c,v 1.14 2023/10/17 11:55:28 riastradh Exp $"); +THMAP_RCSID("$NetBSD: subr_thmap.c,v 1.15 2023/10/17 11:57:20 riastradh Exp $"); #include @@ -212,11 +212,17 @@ typedef struct { uint32_t hashval; // current hash value } thmap_query_t; -typedef struct { - uintptr_t addr; +union thmap_align { + void * p; + uint64_t v; +}; + +typedef struct thmap_gc thmap_gc_t; +struct thmap_gc { size_t len; - void * next; -} thmap_gc_t; + thmap_gc_t * next; + char data[] __aligned(sizeof(union thmap_align)); +}; #define THMAP_ROOT_LEN (sizeof(thmap_ptr_t) * ROOT_SIZE) @@ -252,6 +258,34 @@ static const thmap_ops_t thmap_default_o .free = free_wrapper }; +static uintptr_t +gc_alloc(const thmap_t *thmap, size_t len) +{ + const size_t alloclen = offsetof(struct thmap_gc, data[len]); + const uintptr_t gcaddr = thmap->ops->alloc(alloclen); + + if (!gcaddr) + return 0; + + thmap_gc_t *const gc = THMAP_GETPTR(thmap, gcaddr); + gc->len = len; + return THMAP_GETOFF(thmap, &gc->data[0]); +} + +static void +gc_free(const thmap_t *thmap, uintptr_t addr, size_t len) +{ + const size_t alloclen = offsetof(struct thmap_gc, data[len]); + char *const ptr = THMAP_GETPTR(thmap, addr); + thmap_gc_t *const gc = container_of(ptr, struct thmap_gc, data[0]); + const uintptr_t gcaddr = THMAP_GETOFF(thmap, gc); + + KASSERTMSG(gc->len == len, "thmap=%p ops=%p addr=%p len=%zu" + " gc=%p gc->len=%zu", + thmap, thmap->ops, (void *)addr, len, gc, gc->len); + thmap->ops->free(gcaddr, alloclen); +} + /* * NODE LOCKING. */ @@ -395,7 +429,7 @@ node_create(thmap_t *thmap, thmap_inode_ thmap_inode_t *node; uintptr_t p; - p = thmap->ops->alloc(THMAP_INODE_LEN); + p = gc_alloc(thmap, THMAP_INODE_LEN); if (!p) { return NULL; } @@ -456,7 +490,7 @@ leaf_create(const thmap_t *thmap, const thmap_leaf_t *leaf; uintptr_t leaf_off, key_off; - leaf_off = thmap->ops->alloc(sizeof(thmap_leaf_t)); + leaf_off = gc_alloc(thmap, sizeof(thmap_leaf_t)); if (!leaf_off) { return NULL; } @@ -467,9 +501,9 @@ leaf_create(const thmap_t *thmap, const /* * Copy the key. */ - key_off = thmap->ops->alloc(len); + key_off = gc_alloc(thmap, len); if (!key_off) { - thmap->ops->free(leaf_off, sizeof(thmap_leaf_t)); + gc_free(thmap, leaf_off, sizeof(thmap_leaf_t)); return NULL; } memcpy(THMAP_GETPTR(thmap, key_off), key, len); @@ -487,9 +521,9 @@ static void leaf_free(const thmap_t *thmap, thmap_leaf_t *leaf) { if ((thmap->flags & THMAP_NOCOPY) == 0) { - thmap->ops->free(leaf->key, leaf->len); + gc_free(thmap, leaf->key, leaf->len); } - thmap->ops->free(THMAP_GETOFF(thmap, leaf), sizeof(thmap_leaf_t)); + gc_free(thmap, THMAP_GETOFF(thmap, leaf), sizeof(thmap_leaf_t)); } static thmap_leaf_t * @@ -547,7 +581,7 @@ root_try_put(thmap_t *thmap, const thmap nptr = THMAP_GETOFF(thmap, node); again: if (atomic_load_relaxed(&thmap->root[i])) { - thmap->ops->free(nptr, THMAP_INODE_LEN); + gc_free(thmap, nptr, THMAP_INODE_LEN); return EEXIST; } /* Release to subsequent consume in find_edge_node(). */ @@ -927,11 +961,13 @@ thmap_del(thmap_t *thmap, const void *ke static void stage_mem_gc(thmap_t *thmap, uintptr_t addr, size_t len) { + char *const ptr = THMAP_GETPTR(thmap, addr); thmap_gc_t *head, *gc; - gc = kmem_intr_alloc(sizeof(thmap_gc_t), KM_NOSLEEP);
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Tue Oct 17 11:57:20 UTC 2023 Modified Files: src/sys/kern: subr_thmap.c Log Message: thmap(9): Preallocate GC list storage for thmap_del. thmap_del can't fail, and it is used in places in npf where sleeping is forbidden, so it can't rely on allocating memory either. Instead of having thmap_del allocate memory on the fly for each object to defer freeing until thmap_gc, arrange to have thmap(9) preallocate the same storage when allocating all the objects in the first place, with a GC header. This is suboptimal for memory usage, especially on insertion- and lookup-heavy but deletion-light workloads, but it's not clear rmind's alternative (https://github.com/rmind/thmap/tree/thmap_del_mem_fail) is ready to use yet, so we'll go with this for correctness. PR kern/57208 https://github.com/rmind/npf/issues/129 XXX pullup-10 XXX pullup-9 To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/sys/kern/subr_thmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Tue Oct 17 11:55:28 UTC 2023 Modified Files: src/sys/kern: subr_thmap.c Log Message: thmap(9): Test alloc failure, not THMAP_GETPTR failure. THMAP_GETPTR may return nonnull even though alloc returned zero. Note that this failure branch is not actually appropriate; thmap_create should not fail. We really need to pass KM_SLEEP through in this call site even though there are other call sites for which KM_NOSLEEP is appropriate. Adapted from: https://github.com/rmind/thmap/pull/14 PR kern/57666 https://github.com/rmind/thmap/issues/13 XXX pullup-10 XXX pullup-9 To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sys/kern/subr_thmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/subr_thmap.c diff -u src/sys/kern/subr_thmap.c:1.13 src/sys/kern/subr_thmap.c:1.14 --- src/sys/kern/subr_thmap.c:1.13 Tue Apr 11 13:06:21 2023 +++ src/sys/kern/subr_thmap.c Tue Oct 17 11:55:28 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_thmap.c,v 1.13 2023/04/11 13:06:21 riastradh Exp $ */ +/* $NetBSD: subr_thmap.c,v 1.14 2023/10/17 11:55:28 riastradh Exp $ */ /*- * Copyright (c) 2018 Mindaugas Rasiukevicius @@ -112,7 +112,7 @@ #include "utils.h" #endif -THMAP_RCSID("$NetBSD: subr_thmap.c,v 1.13 2023/04/11 13:06:21 riastradh Exp $"); +THMAP_RCSID("$NetBSD: subr_thmap.c,v 1.14 2023/10/17 11:55:28 riastradh Exp $"); #include @@ -987,11 +987,11 @@ thmap_create(uintptr_t baseptr, const th if ((thmap->flags & THMAP_SETROOT) == 0) { /* Allocate the root level. */ root = thmap->ops->alloc(THMAP_ROOT_LEN); - thmap->root = THMAP_GETPTR(thmap, root); - if (!thmap->root) { + if (!root) { kmem_free(thmap, sizeof(thmap_t)); return NULL; } + thmap->root = THMAP_GETPTR(thmap, root); memset(thmap->root, 0, THMAP_ROOT_LEN); }
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Tue Oct 17 11:55:28 UTC 2023 Modified Files: src/sys/kern: subr_thmap.c Log Message: thmap(9): Test alloc failure, not THMAP_GETPTR failure. THMAP_GETPTR may return nonnull even though alloc returned zero. Note that this failure branch is not actually appropriate; thmap_create should not fail. We really need to pass KM_SLEEP through in this call site even though there are other call sites for which KM_NOSLEEP is appropriate. Adapted from: https://github.com/rmind/thmap/pull/14 PR kern/57666 https://github.com/rmind/thmap/issues/13 XXX pullup-10 XXX pullup-9 To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sys/kern/subr_thmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/kern
Module Name:src Committed By: riastradh Date: Tue Oct 17 10:27:35 UTC 2023 Modified Files: src/sys/kern: kern_ktrace.c Log Message: kern_ktrace.c: Sort includes. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r1.183 -r1.184 src/sys/kern/kern_ktrace.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_ktrace.c diff -u src/sys/kern/kern_ktrace.c:1.183 src/sys/kern/kern_ktrace.c:1.184 --- src/sys/kern/kern_ktrace.c:1.183 Sun Oct 15 10:27:11 2023 +++ src/sys/kern/kern_ktrace.c Tue Oct 17 10:27:34 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_ktrace.c,v 1.183 2023/10/15 10:27:11 riastradh Exp $ */ +/* $NetBSD: kern_ktrace.c,v 1.184 2023/10/17 10:27:34 riastradh Exp $ */ /*- * Copyright (c) 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc. @@ -61,26 +61,26 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.183 2023/10/15 10:27:11 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.184 2023/10/17 10:27:34 riastradh Exp $"); #include -#include -#include + +#include +#include #include -#include -#include -#include -#include -#include #include #include -#include #include -#include -#include - +#include +#include +#include +#include #include +#include +#include #include +#include +#include /* * TODO: