CVS commit: src/sys/kern

2024-04-18 Thread Taylor R Campbell
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(>mnt_vnodelist))) != NULL) {
+
+	if ((vip = TAILQ_FIRST(>mnt_vnodelist)) != NULL) {
+		vp = VIMPL_TO_VNODE(vip);
 		vprint("dangling", vp);
 		panic("unmount: dangling vnode");
 	}



CVS commit: src/sys/kern

2024-04-18 Thread Taylor R Campbell
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

2024-04-11 Thread Taylor R Campbell
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

2024-04-11 Thread Taylor R Campbell
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, , v | 2, NULL, NULL, 0);
  *continue;
  *			}
- *		} while (atomic_cas_uint(, v, v & ~1) != v);
+ *		} while (atomic_cas_uint(, v, v | 1) != v);
  *		membar_acquire();
  *
  *		...



CVS commit: src/sys/kern

2024-03-08 Thread Taylor R Campbell
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(_max_period_ticks);
 	period_secs = atomic_load_relaxed(_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

2024-03-08 Thread Taylor R Campbell
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

2024-03-02 Thread Michael van Elst
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(_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

2024-03-02 Thread Michael van Elst
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

2024-02-29 Thread matthew green
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

2024-02-29 Thread matthew green
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

2024-02-27 Thread Taylor R Campbell
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

2024-02-27 Thread Taylor R Campbell
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

2024-02-27 Thread Taylor R Campbell
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

2024-02-27 Thread Taylor R Campbell
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 = ()->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_heartbeat_suspend;
 	atomic_store_relaxed(p, *p - 1);
-	kpreempt_enable();
 }
 
 /*



CVS commit: src/sys/kern

2024-02-11 Thread Jaromir Dolecek
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

2024-02-11 Thread Jaromir Dolecek
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 = _filtops;
 		sb = >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 = _filtops;



CVS commit: src/sys/kern

2024-01-24 Thread Christos Zoulas
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, );
+#ifdef notyet
+	/* without attaching the primary CPU l_mutex does not get initialized */
+	lwp_lock();
 	sched_newts();
+	lwp_unlock();
+#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

2024-01-24 Thread Christos Zoulas
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

2024-01-19 Thread Christos Zoulas
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

2024-01-19 Thread Christos Zoulas
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

2024-01-17 Thread Juergen Hannken-Illjes
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(_lock);
+	rw_init(_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(_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(_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(_list, fn, arg);
+	return hook_establish(_list, NULL, fn, arg);
 }
 
 void
 shutdownhook_disestablish(void *vhook)
 {
-	hook_disestablish(_list, vhook);
+	

CVS commit: src/sys/kern

2024-01-17 Thread Juergen Hannken-Illjes
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

2024-01-17 Thread Juergen Hannken-Illjes
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(>mnt_vnodelist) != NULL)
+	if ((vp = VIMPL_TO_VNODE(TAILQ_FIRST(>mnt_vnodelist))) != NULL) {
+		vprint("dangling", vp);
 		panic("unmount: dangling vnode");
+	}
 	vfs_hooks_unmount(mp);
 
 	vfs_set_lowermount(mp, NULL);



CVS commit: src/sys/kern

2024-01-17 Thread Juergen Hannken-Illjes
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

2024-01-14 Thread Andrius Varanavicius
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

2024-01-14 Thread Andrius Varanavicius
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

2024-01-04 Thread Michael van Elst
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

2024-01-04 Thread Michael van Elst
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

2023-12-28 Thread Juergen Hannken-Illjes
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

2023-12-28 Thread Juergen Hannken-Illjes
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(_global.lock, MUTEX_DEFAULT, IPL_NONE);
+
 	return 0;
 }
 



CVS commit: src/sys/kern

2023-12-28 Thread Juergen Hannken-Illjes
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

2023-12-28 Thread Juergen Hannken-Illjes
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

2023-12-20 Thread Andrius Varanavicius
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

2023-12-20 Thread Andrius Varanavicius
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

2023-12-07 Thread Paul Goyette
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

2023-12-07 Thread Paul Goyette
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

2023-12-03 Thread Jason R Thorpe
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

2023-12-03 Thread Jason R Thorpe
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();
 
-	while (vm->vm_nfreetags > freelimit) {
-		bt_t *bt = LIST_FIRST(>vm_freetags);
+	LIST_FOREACH_SAFE(bt, >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()) {
-		t = LIST_FIRST();
-		LIST_REMOVE(t, bt_freelist);
-		pool_put(_btag_pool, t);
+		bt = LIST_FIRST();
+		LIST_REMOVE(bt, bt_freelist);
+		pool_put(_btag_pool, bt);
 	}
 }
 #endif	/* defined(_KERNEL) */



CVS commit: src/sys/kern

2023-12-02 Thread Jason R Thorpe
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

2023-12-02 Thread Jason R Thorpe
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(_btag_refill_lock);
 		bt = pool_get(_btag_pool, PR_NOWAIT);
 		mutex_exit(_btag_refill_lock);
@@ -697,6 +699,7 @@ vmem_subsystem_init(vmem_t *vm)
 
 	pool_init(_btag_pool, sizeof(bt_t), coherency_unit, 0,
 	PR_PHINPAGE, "vmembt", _allocator_vmem_meta, IPL_VM);
+	vmem_btag_pool_initialized = true;
 }
 #endif /* defined(_KERNEL) */
 



CVS commit: src/sys/kern

2023-12-02 Thread Jason R Thorpe
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_lock)
-#define	VMEM_TRYLOCK(vm)	mutex_tryenter(>vm_lock)
-#define	VMEM_UNLOCK(vm)		mutex_exit(>vm_lock)
-#define	VMEM_LOCK_INIT(vm, ipl)	mutex_init(>vm_lock, MUTEX_DEFAULT, ipl)
-#define	VMEM_LOCK_DESTROY(vm)	mutex_destroy(>vm_lock)
-#define	VMEM_ASSERT_LOCKED(vm)	KASSERT(mutex_owned(>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

2023-12-02 Thread Jason R Thorpe
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

2023-11-27 Thread Juergen Hannken-Illjes
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

2023-11-27 Thread Juergen Hannken-Illjes
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(_lock);
 
 	while (!vdrain_one(target))
-		;
+		kpause("vdrain", false, 1, _lock);
 
 	threadpool_job_done(job);
 	mutex_exit(_lock);



CVS commit: src/sys/kern

2023-11-27 Thread Juergen Hannken-Illjes
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(_cv, "vdrain");
-	cv_init(_gen_cv, "vdrainwt");
-	error = kthread_create(PRI_VM, KTHREAD_MPSAFE, NULL, vdrain_thread,
-	NULL, _lwp, "vdrain");
-	KASSERTMSG((error == 0), "kthread_create(vdrain) failed: %d", error);
+	error = threadpool_get(, PRI_NONE);
+	KASSERTMSG((error == 0), "threadpool_get failed: %d", error);
+	threadpool_job_init(_job, vdrain_task, _lock, "vdrain");
+	threadpool_job_init(_job, vrele_task, _lock, "vrele");
 }
 
 /*
@@ -536,189 +544,208 @@ lru_requeue(vnode_t *vp, vnodelst_t *lis
 		 */
 		numvnodes += d;
 	}
-	if ((d > 0 && numvnodes > desiredvnodes) ||
-	listhd == _list[LRU_VRELE])
-		cv_signal(_cv);
+	if (listhd == _list[LRU_VRELE])
+		threadpool_schedule_job(threadpool, _job);
+	if (d > 0 && numvnodes > desiredvnodes)
+		threadpool_schedule_job(threadpool, _job);
 	if (d > 0 && numvnodes > desiredvnodes + desiredvnodes / 16)
 		kpause("vnfull", false, MAX(1, mstohz(10)), _lock);
 	mutex_exit(_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(_lock));
 
+	mutex_exit(_lock);
 	marker = VNODE_TO_VIMPL(vnalloc_marker(NULL));
-
 	mutex_enter(_lock);
-	TAILQ_INSERT_HEAD(_list[LRU_VRELE], marker, vi_lrulist);
+	marker->vi_lrulisthd = _list[idx];
+	iterp->li_marker = marker;
 
-	while ((vip 

CVS commit: src/sys/kern

2023-11-27 Thread Juergen Hannken-Illjes
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

2023-11-26 Thread Ryota Ozaki
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

2023-11-26 Thread Ryota Ozaki
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

2023-11-22 Thread Taylor R Campbell
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 == _list[LRU_VRELE])
 		cv_signal(_cv);
 	if (d > 0 && numvnodes > desiredvnodes + desiredvnodes / 16)
-		kpause("vnfull", false, mstohz(10), _lock);
+		kpause("vnfull", false, MAX(1, mstohz(10)), _lock);
 	mutex_exit(_lock);
 }
 



CVS commit: src/sys/kern

2023-11-22 Thread Taylor R Campbell
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

2023-11-22 Thread Taylor R Campbell
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

2023-11-22 Thread Taylor R Campbell
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

2023-11-21 Thread Martin Husemann
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

2023-11-21 Thread Martin Husemann
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

2023-11-19 Thread Taylor R Campbell
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_write_sel;
 		pollev = POLLOUT | POLLWRNORM;
 	}
-	if (waitcv != NULL) {
-		cv_broadcast(waitcv);
-	}
+	cv_broadcast(waitcv);
 	selnotify(sel, pollev, NOTE_SUBMIT);
 }
 



CVS commit: src/sys/kern

2023-11-19 Thread Taylor R Campbell
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

2023-11-18 Thread Taylor R Campbell
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_read_wait);
 	cv_destroy(>efd_write_wait);
@@ -155,10 +151,8 @@ eventfd_wait(struct eventfd * const efd,
 	}
 
 	if (is_write) {
-		efd->efd_has_write_waiters = true;
 		waitcv = >efd_write_wait;
 	} else {
-		efd->efd_has_read_waiters = true;
 		waitcv = >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_read_wait;
-			efd->efd_has_read_waiters = false;
-		}
+		waitcv = >efd_read_wait;
 		sel = >efd_read_sel;
 		pollev = POLLIN | POLLRDNORM;
 	} else {
-		if (efd->efd_has_write_waiters) {
-			waitcv = >efd_write_wait;
-			efd->efd_has_write_waiters = false;
-		}
+		waitcv = >efd_write_wait;
 		sel = >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_read_wait);
-			efd->efd_has_read_waiters = false;
-		}
-		if (efd->efd_has_write_waiters) {
-			cv_broadcast(>efd_write_wait);
-			efd->efd_has_write_waiters = false;
-		}
+		cv_broadcast(>efd_read_wait);
+		cv_broadcast(>efd_write_wait);
 	}
 
 	mutex_exit(>efd_lock);



CVS commit: src/sys/kern

2023-11-18 Thread Taylor R Campbell
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

2023-11-06 Thread Juergen Hannken-Illjes
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 == _list[LRU_VRELE])
 		cv_signal(_cv);
+	if (d > 0 && numvnodes > desiredvnodes + desiredvnodes / 16)
+		kpause("vnfull", false, mstohz(10), _lock);
 	mutex_exit(_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(_list[i], marker, vi_lrulist);



CVS commit: src/sys/kern

2023-11-06 Thread Juergen Hannken-Illjes
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

2023-10-17 Thread Taylor R Campbell
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, >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(>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);
-	gc->addr 

CVS commit: src/sys/kern

2023-10-17 Thread Taylor R Campbell
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

2023-10-17 Thread Taylor R Campbell
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

2023-10-17 Thread Taylor R Campbell
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

2023-10-17 Thread Taylor R Campbell
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:



CVS commit: src/sys/kern

2023-10-17 Thread Taylor R Campbell
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.



CVS commit: src/sys/kern

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:30:20 UTC 2023

Modified Files:
src/sys/kern: kern_turnstile.c

Log Message:
kern_turnstile.c: Use  explicitly for struct lwp members.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/kern/kern_turnstile.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_turnstile.c
diff -u src/sys/kern/kern_turnstile.c:1.54 src/sys/kern/kern_turnstile.c:1.55
--- src/sys/kern/kern_turnstile.c:1.54	Sun Oct 15 10:27:11 2023
+++ src/sys/kern/kern_turnstile.c	Sun Oct 15 10:30:20 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_turnstile.c,v 1.54 2023/10/15 10:27:11 riastradh Exp $	*/
+/*	$NetBSD: kern_turnstile.c,v 1.55 2023/10/15 10:30:20 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2009, 2019, 2020, 2023
@@ -61,10 +61,12 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_turnstile.c,v 1.54 2023/10/15 10:27:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_turnstile.c,v 1.55 2023/10/15 10:30:20 riastradh Exp $");
 
 #include 
+
 #include 
+#include 
 #include 
 #include 
 #include 



CVS commit: src/sys/kern

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:30:20 UTC 2023

Modified Files:
src/sys/kern: kern_turnstile.c

Log Message:
kern_turnstile.c: Use  explicitly for struct lwp members.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/kern/kern_turnstile.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

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:29:34 UTC 2023

Modified Files:
src/sys/kern: sys_select.c

Log Message:
sys_select.c: Sort includes.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/kern/sys_select.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_select.c
diff -u src/sys/kern/sys_select.c:1.65 src/sys/kern/sys_select.c:1.66
--- src/sys/kern/sys_select.c:1.65	Sun Oct 15 10:27:11 2023
+++ src/sys/kern/sys_select.c	Sun Oct 15 10:29:34 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_select.c,v 1.65 2023/10/15 10:27:11 riastradh Exp $	*/
+/*	$NetBSD: sys_select.c,v 1.66 2023/10/15 10:29:34 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009, 2010, 2019, 2020, 2023
@@ -85,28 +85,29 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_select.c,v 1.65 2023/10/15 10:27:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_select.c,v 1.66 2023/10/15 10:29: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 
+#include 
 #include 
+#include 
+#include 
+#include 
+#include 
 
 /* Flags for lwp::l_selflag. */
 #define	SEL_RESET	0	/* awoken, interrupted, or not yet polling */



CVS commit: src/sys/kern

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:29:34 UTC 2023

Modified Files:
src/sys/kern: sys_select.c

Log Message:
sys_select.c: Sort includes.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/kern/sys_select.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

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:29:24 UTC 2023

Modified Files:
src/sys/kern: sys_lwp.c

Log Message:
kern_lwp.c: Sort includes.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/kern/sys_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/sys_lwp.c
diff -u src/sys/kern/sys_lwp.c:1.88 src/sys/kern/sys_lwp.c:1.89
--- src/sys/kern/sys_lwp.c:1.88	Sun Oct 15 10:27:11 2023
+++ src/sys/kern/sys_lwp.c	Sun Oct 15 10:29:24 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_lwp.c,v 1.88 2023/10/15 10:27:11 riastradh Exp $	*/
+/*	$NetBSD: sys_lwp.c,v 1.89 2023/10/15 10:29:24 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2019, 2020, 2023
@@ -36,22 +36,23 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.88 2023/10/15 10:27:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.89 2023/10/15 10:29:24 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 
 



CVS commit: src/sys/kern

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:29:24 UTC 2023

Modified Files:
src/sys/kern: sys_lwp.c

Log Message:
kern_lwp.c: Sort includes.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/kern/sys_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

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:29:11 UTC 2023

Modified Files:
src/sys/kern: kern_synch.c

Log Message:
kern_synch.c: Sort includes.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.364 -r1.365 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.364 src/sys/kern/kern_synch.c:1.365
--- src/sys/kern/kern_synch.c:1.364	Sun Oct 15 10:27:11 2023
+++ src/sys/kern/kern_synch.c	Sun Oct 15 10:29:10 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_synch.c,v 1.364 2023/10/15 10:27:11 riastradh Exp $	*/
+/*	$NetBSD: kern_synch.c,v 1.365 2023/10/15 10:29:10 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.364 2023/10/15 10:27:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.365 2023/10/15 10:29:10 riastradh Exp $");
 
 #include "opt_kstack.h"
 #include "opt_ddb.h"
@@ -78,30 +78,31 @@ __KERNEL_RCSID(0, "$NetBSD: kern_synch.c
 #define	__MUTEX_PRIVATE
 
 #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 
+#include 
+#include 
+#include 
 
 #include 
 
 #include 
 
-#include 
 int dtrace_vtime_active=0;
 dtrace_vtime_switch_func_t  dtrace_vtime_switch_func;
 



CVS commit: src/sys/kern

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:29:11 UTC 2023

Modified Files:
src/sys/kern: kern_synch.c

Log Message:
kern_synch.c: Sort includes.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.364 -r1.365 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

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:29:02 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
kern_sleepq.c: Sort includes.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/kern/kern_sleepq.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_sleepq.c
diff -u src/sys/kern/kern_sleepq.c:1.85 src/sys/kern/kern_sleepq.c:1.86
--- src/sys/kern/kern_sleepq.c:1.85	Sun Oct 15 10:27:11 2023
+++ src/sys/kern/kern_sleepq.c	Sun Oct 15 10:29:02 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sleepq.c,v 1.85 2023/10/15 10:27:11 riastradh Exp $	*/
+/*	$NetBSD: kern_sleepq.c,v 1.86 2023/10/15 10:29:02 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -36,20 +36,21 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.85 2023/10/15 10:27:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.86 2023/10/15 10:29:02 riastradh Exp $");
 
 #include 
-#include 
+
 #include 
 #include 
+#include 
+#include 
 #include 
-#include  
+#include 
 #include 
 #include 
-#include 
 #include 
-#include 
 #include 
+#include 
 
 /*
  * for sleepq_abort:



CVS commit: src/sys/kern

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:29:02 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
kern_sleepq.c: Sort includes.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/kern/kern_sleepq.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

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:28:48 UTC 2023

Modified Files:
src/sys/kern: kern_rwlock.c

Log Message:
kern_rwlock.c: Sort includes.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sys/kern/kern_rwlock.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_rwlock.c
diff -u src/sys/kern/kern_rwlock.c:1.75 src/sys/kern/kern_rwlock.c:1.76
--- src/sys/kern/kern_rwlock.c:1.75	Sun Oct 15 10:27:11 2023
+++ src/sys/kern/kern_rwlock.c	Sun Oct 15 10:28:48 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_rwlock.c,v 1.75 2023/10/15 10:27:11 riastradh Exp $	*/
+/*	$NetBSD: kern_rwlock.c,v 1.76 2023/10/15 10:28:48 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -45,24 +45,25 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.75 2023/10/15 10:27:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.76 2023/10/15 10:28:48 riastradh Exp $");
 
 #include "opt_lockdebug.h"
 
 #define	__RWLOCK_PRIVATE
 
 #include 
+
+#include 
+#include 
+#include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
 #include 
+#include 
 
 #include 
 



CVS commit: src/sys/kern

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:28:48 UTC 2023

Modified Files:
src/sys/kern: kern_rwlock.c

Log Message:
kern_rwlock.c: Sort includes.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sys/kern/kern_rwlock.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

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:28:23 UTC 2023

Modified Files:
src/sys/kern: kern_mutex.c

Log Message:
kern_mutex.c: Sort includes.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/sys/kern/kern_mutex.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

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:28:23 UTC 2023

Modified Files:
src/sys/kern: kern_mutex.c

Log Message:
kern_mutex.c: Sort includes.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/sys/kern/kern_mutex.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_mutex.c
diff -u src/sys/kern/kern_mutex.c:1.111 src/sys/kern/kern_mutex.c:1.112
--- src/sys/kern/kern_mutex.c:1.111	Sun Oct 15 10:27:11 2023
+++ src/sys/kern/kern_mutex.c	Sun Oct 15 10:28:23 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_mutex.c,v 1.111 2023/10/15 10:27:11 riastradh Exp $	*/
+/*	$NetBSD: kern_mutex.c,v 1.112 2023/10/15 10:28:23 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2019, 2023
@@ -41,23 +41,24 @@
 #define	__MUTEX_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.111 2023/10/15 10:27:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.112 2023/10/15 10:28:23 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 
 



CVS commit: src/sys/kern

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:28:14 UTC 2023

Modified Files:
src/sys/kern: kern_lwp.c

Log Message:
kern_lwp: Sort includes.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.266 -r1.267 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

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:28:14 UTC 2023

Modified Files:
src/sys/kern: kern_lwp.c

Log Message:
kern_lwp: Sort includes.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.266 -r1.267 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.266 src/sys/kern/kern_lwp.c:1.267
--- src/sys/kern/kern_lwp.c:1.266	Sun Oct 15 10:27:11 2023
+++ src/sys/kern/kern_lwp.c	Sun Oct 15 10:28:14 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.266 2023/10/15 10:27:11 riastradh Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.267 2023/10/15 10:28:14 riastradh 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.266 2023/10/15 10:27:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.267 2023/10/15 10:28:14 riastradh Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -226,34 +226,35 @@ __KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v
 #define _LWP_API_PRIVATE
 
 #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 
-#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 



CVS commit: src/sys/kern

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:28:00 UTC 2023

Modified Files:
src/sys/kern: kern_condvar.c

Log Message:
kern_condvar.c: Sort includes.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/kern/kern_condvar.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_condvar.c
diff -u src/sys/kern/kern_condvar.c:1.61 src/sys/kern/kern_condvar.c:1.62
--- src/sys/kern/kern_condvar.c:1.61	Sun Oct 15 10:27:11 2023
+++ src/sys/kern/kern_condvar.c	Sun Oct 15 10:28:00 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_condvar.c,v 1.61 2023/10/15 10:27:11 riastradh Exp $	*/
+/*	$NetBSD: kern_condvar.c,v 1.62 2023/10/15 10:28:00 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2019, 2020, 2023
@@ -35,17 +35,18 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.61 2023/10/15 10:27:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.62 2023/10/15 10:28:00 riastradh Exp $");
 
 #include 
-#include 
-#include 
+
 #include 
-#include 
-#include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
+#include 
 
 /*
  * Accessors for the private contents of the kcondvar_t data type.



CVS commit: src/sys/kern

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 10:28:00 UTC 2023

Modified Files:
src/sys/kern: kern_condvar.c

Log Message:
kern_condvar.c: Sort includes.  No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/kern/kern_condvar.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

2023-10-13 Thread Taylor R Campbell
> Date: Fri, 13 Oct 2023 17:52:07 +0900
> From: Rin Okuyama 
> 
> It would be really nice if we can find some systematical/reliable methods to
> figure out files that really depends on struct syncobj, e.g.. I tried
> ctfdump(1) to
> *.o for kernel modules, but I cannot extract information better than
> ``grep syncobj.h .depend''...

The attached patch removes all use of sys/syncobj.h outside .c files
under sys, so we can be reasonably confident userland programs --
except for crash(8), which is kind of special -- are unaffected.

However, I'm going to hold off on committing this until the tree's
sleepq issues are fixed so our testbed can run again.
>From 7e9e2af19ecc6f4262b928da8a97a49d171c8072 Mon Sep 17 00:00:00 2001
From: Taylor R Campbell 
Date: Fri, 13 Oct 2023 11:04:20 +
Subject: [PATCH] sys/lwp.h: Nix sys/syncobj.h dependency.

Remove it in ddb/db_syncobj.h too.

New sys/wchan.h defines wchan_t so that users need not pull in
sys/syncobj.h to get it.

Sprinkle #include  in .c files where it is now needed.
---
 sys/ddb/db_syncobj.h  |  2 +-
 sys/kern/kern_condvar.c   |  1 +
 sys/kern/kern_ktrace.c|  1 +
 sys/kern/kern_lwp.c   |  1 +
 sys/kern/kern_mutex.c |  1 +
 sys/kern/kern_rwlock.c|  1 +
 sys/kern/kern_sleepq.c|  1 +
 sys/kern/kern_turnstile.c |  1 +
 sys/kern/sys_lwp.c|  1 +
 sys/kern/sys_select.c |  1 +
 sys/sys/lwp.h |  2 +-
 sys/sys/sleepq.h  |  2 +-
 sys/sys/sleeptab.h|  6 +-
 sys/sys/syncobj.h |  4 ++--
 sys/sys/wchan.h   | 37 +
 15 files changed, 56 insertions(+), 6 deletions(-)
 create mode 100644 sys/sys/wchan.h

diff --git a/sys/ddb/db_syncobj.h b/sys/ddb/db_syncobj.h
index 2c2ad89ba177..dc7594f5163e 100644
--- a/sys/ddb/db_syncobj.h
+++ b/sys/ddb/db_syncobj.h
@@ -29,7 +29,7 @@
 #ifndef_DDB_DB_SYNCOBJ_H
 #define_DDB_DB_SYNCOBJ_H
 
-#include 
+#include 
 
 struct lwp;
 struct syncobj;
diff --git a/sys/kern/kern_condvar.c b/sys/kern/kern_condvar.c
index 478c4a35ff2b..c25282e1beb3 100644
--- a/sys/kern/kern_condvar.c
+++ b/sys/kern/kern_condvar.c
@@ -45,6 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.59 2023/10/12 
23:51:05 ad Exp $")
 #include 
 #include 
 #include 
+#include 
 
 /*
  * Accessors for the private contents of the kcondvar_t data type.
diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c
index 5ad5272af7d8..812be0c2c9ca 100644
--- a/sys/kern/kern_ktrace.c
+++ b/sys/kern/kern_ktrace.c
@@ -77,6 +77,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.182 2022/07/01 
01:07:56 riastradh
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
diff --git a/sys/kern/kern_lwp.c b/sys/kern/kern_lwp.c
index 77e43242f0f9..971e0180f1f6 100644
--- a/sys/kern/kern_lwp.c
+++ b/sys/kern/kern_lwp.c
@@ -253,6 +253,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.265 2023/10/05 
19:41:06 ad Exp $");
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c
index 810ea121a0bd..640909bc533e 100644
--- a/sys/kern/kern_mutex.c
+++ b/sys/kern/kern_mutex.c
@@ -57,6 +57,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.110 2023/09/23 
18:48:04 ad Exp $");
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c
index 88db7d507b4d..96312874a069 100644
--- a/sys/kern/kern_rwlock.c
+++ b/sys/kern/kern_rwlock.c
@@ -62,6 +62,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.74 2023/10/04 
20:39:35 ad Exp $");
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
diff --git a/sys/kern/kern_sleepq.c b/sys/kern/kern_sleepq.c
index e9d39445f75b..bb43e78f6f6b 100644
--- a/sys/kern/kern_sleepq.c
+++ b/sys/kern/kern_sleepq.c
@@ -49,6 +49,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.83 2023/10/08 
13:37:26 ad Exp $");
 #include 
 #include 
 #include 
+#include 
 
 /*
  * for sleepq_abort:
diff --git a/sys/kern/kern_turnstile.c b/sys/kern/kern_turnstile.c
index 0cd8886cb6b5..85bdf946c325 100644
--- a/sys/kern/kern_turnstile.c
+++ b/sys/kern/kern_turnstile.c
@@ -68,6 +68,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_turnstile.c,v 1.53 
2023/10/08 13:23:05 ad Exp $
 #include 
 #include 
 #include 
+#include 
 #include 
 
 /*
diff --git a/sys/kern/sys_lwp.c b/sys/kern/sys_lwp.c
index c71cf1e823d6..108d40641e38 100644
--- a/sys/kern/sys_lwp.c
+++ b/sys/kern/sys_lwp.c
@@ -51,6 +51,7 @@ __KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.87 2023/10/08 
13:23:05 ad Exp $");
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
diff --git a/sys/kern/sys_select.c b/sys/kern/sys_select.c
index 9719d220e319..16962505663c 100644
--- a/sys/kern/sys_select.c
+++ b/sys/kern/sys_select.c
@@ -106,6 +106,7 @@ __KERNEL_RCSID(0, "$NetBSD: sys_select.c,v 1.64 2023/10/08 
13:23:05 ad Exp $");
 #include 
 #include 
 #include 
+#include 
 
 /* Flags for lwp::l_selflag. */
 #defineSEL_RESET   0   /* awoken, interrupted, or not yet 

Re: CVS commit: src/sys/kern

2023-10-13 Thread Rin Okuyama
On Thu, Oct 12, 2023 at 8:23 PM Taylor R Campbell
 wrote:
>
> > Date: Thu, 12 Oct 2023 17:06:02 +0900
> > From: Rin Okuyama 
> >
> > On Thu, Oct 5, 2023 at 5:39 AM Andrew Doran  wrote:
> > >
> > > Module Name:src
> > > Committed By:   ad
> > > Date:   Wed Oct  4 20:39:35 UTC 2023
> > >
> > > Modified Files:
> > > src/sys/kern: kern_rwlock.c kern_turnstile.c
> > >
> > > Log Message:
> > > Turnstiles: use the syncobj name for ps/top wmesg when sleeping since it's
> > > more informative than "tstile".
> >
> > Cool! Can I send a pull up request to netbsd-10?
>
> Not sure -- it would depend on this commit to introduce struct
> syncobj::sobj_name:
>
> https://mail-index.netbsd.org/source-changes/2023/07/17/msg146058.html
>
> This is a potential kernel ABI change.  I didn't investigate to
> determine whether it would be safe to pull up.

Thanks, I didn't notice that. It should be too risky to pull these up
just before RC1.
I withdraw this proposal.

PS
It would be really nice if we can find some systematical/reliable methods to
figure out files that really depends on struct syncobj, e.g.. I tried
ctfdump(1) to
*.o for kernel modules, but I cannot extract information better than
``grep syncobj.h .depend''...

Thanks,
rin


CVS commit: src/sys/kern

2023-10-12 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Oct 12 23:51:06 UTC 2023

Modified Files:
src/sys/kern: kern_condvar.c

Log Message:
Comments.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/kern/kern_condvar.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_condvar.c
diff -u src/sys/kern/kern_condvar.c:1.58 src/sys/kern/kern_condvar.c:1.59
--- src/sys/kern/kern_condvar.c:1.58	Sun Oct  8 13:23:05 2023
+++ src/sys/kern/kern_condvar.c	Thu Oct 12 23:51:05 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_condvar.c,v 1.58 2023/10/08 13:23:05 ad Exp $	*/
+/*	$NetBSD: kern_condvar.c,v 1.59 2023/10/12 23:51:05 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2019, 2020, 2023
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.58 2023/10/08 13:23:05 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.59 2023/10/12 23:51:05 ad Exp $");
 
 #include 
 #include 
@@ -451,8 +451,9 @@ cv_timedwaitbt_sig(kcondvar_t *cv, kmute
 /*
  * cv_signal:
  *
- *	Wake the highest priority LWP waiting on a condition variable.
- *	Must be called with the interlocking mutex held.
+ *	Wake the highest priority LWP waiting on a condition variable.  Must
+ *	be called with the interlocking mutex held or just after it has been
+ *	released (so the awoken LWP will see the changed condition).
  */
 void
 cv_signal(kcondvar_t *cv)
@@ -460,8 +461,13 @@ cv_signal(kcondvar_t *cv)
 
 	KASSERT(cv_is_valid(cv));
 
-	if (__predict_false(!LIST_EMPTY(CV_SLEEPQ(cv
+	if (__predict_false(!LIST_EMPTY(CV_SLEEPQ(cv {
+		/*
+		 * Compiler turns into a tail call usually, i.e. jmp,
+		 * because the arguments are the same and no locals.
+		 */
 		cv_wakeup_one(cv);
+	}
 }
 
 /*
@@ -492,8 +498,9 @@ cv_wakeup_one(kcondvar_t *cv)
 /*
  * cv_broadcast:
  *
- *	Wake all LWPs waiting on a condition variable.  Must be called
- *	with the interlocking mutex held.
+ *	Wake all LWPs waiting on a condition variable.  Must be called with
+ *	the interlocking mutex held or just after it has been released (so
+ *	the awoken LWP will see the changed condition).
  */
 void
 cv_broadcast(kcondvar_t *cv)
@@ -501,8 +508,13 @@ cv_broadcast(kcondvar_t *cv)
 
 	KASSERT(cv_is_valid(cv));
 
-	if (__predict_false(!LIST_EMPTY(CV_SLEEPQ(cv  
+	if (__predict_false(!LIST_EMPTY(CV_SLEEPQ(cv {
+		/*
+		 * Compiler turns into a tail call usually, i.e. jmp,
+		 * because the arguments are the same and no locals.
+		 */
 		cv_wakeup_all(cv);
+	}
 }
 
 /*



CVS commit: src/sys/kern

2023-10-12 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Oct 12 23:51:06 UTC 2023

Modified Files:
src/sys/kern: kern_condvar.c

Log Message:
Comments.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/kern/kern_condvar.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

2023-10-12 Thread Taylor R Campbell
> Date: Thu, 12 Oct 2023 17:06:02 +0900
> From: Rin Okuyama 
> 
> On Thu, Oct 5, 2023 at 5:39 AM Andrew Doran  wrote:
> >
> > Module Name:src
> > Committed By:   ad
> > Date:   Wed Oct  4 20:39:35 UTC 2023
> >
> > Modified Files:
> > src/sys/kern: kern_rwlock.c kern_turnstile.c
> >
> > Log Message:
> > Turnstiles: use the syncobj name for ps/top wmesg when sleeping since it's
> > more informative than "tstile".
> 
> Cool! Can I send a pull up request to netbsd-10?

Not sure -- it would depend on this commit to introduce struct
syncobj::sobj_name:

https://mail-index.netbsd.org/source-changes/2023/07/17/msg146058.html

This is a potential kernel ABI change.  I didn't investigate to
determine whether it would be safe to pull up.


Re: CVS commit: src/sys/kern

2023-10-12 Thread Rin Okuyama
Cool! Can I send a pull up request to netbsd-10?

I've not yet observed deadlocks since this was committed,
fortunately or unfortunately, although ;)

Thanks,
rin

On Thu, Oct 5, 2023 at 5:39 AM Andrew Doran  wrote:
>
> Module Name:src
> Committed By:   ad
> Date:   Wed Oct  4 20:39:35 UTC 2023
>
> Modified Files:
> src/sys/kern: kern_rwlock.c kern_turnstile.c
>
> Log Message:
> Turnstiles: use the syncobj name for ps/top wmesg when sleeping since it's
> more informative than "tstile".
>
>
> To generate a diff of this commit:
> cvs rdiff -u -r1.73 -r1.74 src/sys/kern/kern_rwlock.c
> cvs rdiff -u -r1.51 -r1.52 src/sys/kern/kern_turnstile.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

2023-10-08 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Oct  8 13:37:26 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
Oops, fix inverted test.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/kern/kern_sleepq.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_sleepq.c
diff -u src/sys/kern/kern_sleepq.c:1.82 src/sys/kern/kern_sleepq.c:1.83
--- src/sys/kern/kern_sleepq.c:1.82	Sun Oct  8 13:23:05 2023
+++ src/sys/kern/kern_sleepq.c	Sun Oct  8 13:37:26 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sleepq.c,v 1.82 2023/10/08 13:23:05 ad Exp $	*/
+/*	$NetBSD: kern_sleepq.c,v 1.83 2023/10/08 13:37:26 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.82 2023/10/08 13:23:05 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.83 2023/10/08 13:37:26 ad Exp $");
 
 #include 
 #include 
@@ -416,7 +416,7 @@ sleepq_block(int timo, bool catch_p, syn
 	 */
 	flag = atomic_load_relaxed(>l_flag);
 	if (__predict_false((flag & mask) != 0)) {
-		if ((flag & LW_CATCHINTR) == 0 && error != 0)
+		if ((flag & LW_CATCHINTR) == 0 || error != 0)
 			/* nothing */;
 		else if ((flag & (LW_CANCELLED | LW_WEXIT | LW_WCORE)) != 0)
 			error = EINTR;



CVS commit: src/sys/kern

2023-10-08 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Oct  8 13:37:26 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
Oops, fix inverted test.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/kern/kern_sleepq.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

2023-10-08 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Oct  8 12:38:58 UTC 2023

Modified Files:
src/sys/kern: kern_exec.c kern_exit.c

Log Message:
Defer some wakeups till lock release.


To generate a diff of this commit:
cvs rdiff -u -r1.520 -r1.521 src/sys/kern/kern_exec.c
cvs rdiff -u -r1.297 -r1.298 src/sys/kern/kern_exit.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

2023-10-08 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Oct  8 12:38:58 UTC 2023

Modified Files:
src/sys/kern: kern_exec.c kern_exit.c

Log Message:
Defer some wakeups till lock release.


To generate a diff of this commit:
cvs rdiff -u -r1.520 -r1.521 src/sys/kern/kern_exec.c
cvs rdiff -u -r1.297 -r1.298 src/sys/kern/kern_exit.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_exec.c
diff -u src/sys/kern/kern_exec.c:1.520 src/sys/kern/kern_exec.c:1.521
--- src/sys/kern/kern_exec.c:1.520	Wed Oct  4 22:17:09 2023
+++ src/sys/kern/kern_exec.c	Sun Oct  8 12:38:58 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.520 2023/10/04 22:17:09 ad Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.521 2023/10/08 12:38:58 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.520 2023/10/04 22:17:09 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.521 2023/10/08 12:38:58 ad Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -1314,7 +1314,6 @@ execve_runproc(struct lwp *l, struct exe
 		lp = p->p_vforklwp;
 		p->p_vforklwp = NULL;
 		l->l_lwpctl = NULL; /* was on loan from blocked parent */
-		cv_broadcast(>l_waitcv);
 
 		/* Clear flags after cv_broadcast() (scheduler needs them). */
 		p->p_lflag &= ~PL_PPWAIT;
@@ -1322,6 +1321,7 @@ execve_runproc(struct lwp *l, struct exe
 
 		/* If parent is still on same CPU, teleport curlwp elsewhere. */
 		samecpu = (lp->l_cpu == curlwp->l_cpu);
+		cv_broadcast(>l_waitcv);
 		mutex_exit(_lock);
 
 		/* Give the parent its CPU back - find a new home. */

Index: src/sys/kern/kern_exit.c
diff -u src/sys/kern/kern_exit.c:1.297 src/sys/kern/kern_exit.c:1.298
--- src/sys/kern/kern_exit.c:1.297	Wed Oct  4 20:48:13 2023
+++ src/sys/kern/kern_exit.c	Sun Oct  8 12:38:58 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exit.c,v 1.297 2023/10/04 20:48:13 ad Exp $	*/
+/*	$NetBSD: kern_exit.c,v 1.298 2023/10/08 12:38:58 ad Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2006, 2007, 2008, 2020, 2023
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.297 2023/10/04 20:48:13 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.298 2023/10/08 12:38:58 ad Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_dtrace.h"
@@ -548,9 +548,6 @@ exit1(struct lwp *l, int exitcode, int s
 	calcru(p, >p_stats->p_ru.ru_utime, >p_stats->p_ru.ru_stime,
 	NULL, NULL);
 
-	if (wakeinit)
-		cv_broadcast(>p_waitcv);
-
 	callout_destroy(>l_timeout_ch);
 
 	/*
@@ -558,7 +555,6 @@ exit1(struct lwp *l, int exitcode, int s
 	 */
 	pcu_discard_all(l);
 
-	mutex_enter(p->p_lock);
 	/*
 	 * Notify other processes tracking us with a knote that
 	 * we're exiting.
@@ -568,6 +564,7 @@ exit1(struct lwp *l, int exitcode, int s
 	 * knote_proc_exit() expects that p->p_lock is already
 	 * held (and will assert so).
 	 */
+	mutex_enter(p->p_lock);
 	if (!SLIST_EMPTY(>p_klist)) {
 		knote_proc_exit(p);
 	}
@@ -592,9 +589,11 @@ exit1(struct lwp *l, int exitcode, int s
 	 * Signal the parent to collect us, and drop the proclist lock.
 	 * Drop debugger/procfs lock; no new references can be gained.
 	 */
-	cv_broadcast(>p_pptr->p_waitcv);
 	rw_exit(>p_reflock);
+	cv_broadcast(>p_pptr->p_waitcv);
 	mutex_exit(_lock);
+	if (wakeinit)
+		cv_broadcast(>p_waitcv);
 
 	/*
 	 * NOTE: WE ARE NO LONGER ALLOWED TO SLEEP!



CVS commit: src/sys/kern

2023-10-08 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Oct  8 11:12:47 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
sleepq_block(): slightly reduce number of test+branch in the common case.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/kern/kern_sleepq.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_sleepq.c
diff -u src/sys/kern/kern_sleepq.c:1.80 src/sys/kern/kern_sleepq.c:1.81
--- src/sys/kern/kern_sleepq.c:1.80	Sat Oct  7 20:48:50 2023
+++ src/sys/kern/kern_sleepq.c	Sun Oct  8 11:12:47 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sleepq.c,v 1.80 2023/10/07 20:48:50 ad Exp $	*/
+/*	$NetBSD: kern_sleepq.c,v 1.81 2023/10/08 11:12:47 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.80 2023/10/07 20:48:50 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.81 2023/10/08 11:12:47 ad Exp $");
 
 #include 
 #include 
@@ -334,7 +334,8 @@ sleepq_uncatch(lwp_t *l)
 int
 sleepq_block(int timo, bool catch_p, syncobj_t *syncobj, int nlocks)
 {
-	int error = 0, sig;
+	const int mask = LW_CANCELLED|LW_WEXIT|LW_WCORE|LW_PENDSIG;
+	int error = 0, sig, flag;
 	struct proc *p;
 	lwp_t *l = curlwp;
 	bool early = false;
@@ -406,11 +407,14 @@ sleepq_block(int timo, bool catch_p, syn
 	 * considering it is only meaningful here inside this function,
 	 * and is set to reflect intent upon entry.
 	 */
-	if ((l->l_flag & LW_CATCHINTR) != 0 && error == 0) {
+	flag = atomic_load_relaxed(>l_flag);
+	if (__predict_false((flag & mask) != 0)) {
 		p = l->l_proc;
-		if ((l->l_flag & (LW_CANCELLED | LW_WEXIT | LW_WCORE)) != 0)
+		if ((flag & LW_CATCHINTR) == 0 && error != 0)
+			/* nothing */;
+		else if ((flag & (LW_CANCELLED | LW_WEXIT | LW_WCORE)) != 0)
 			error = EINTR;
-		else if ((l->l_flag & LW_PENDSIG) != 0) {
+		else if ((flag & LW_PENDSIG) != 0) {
 			/*
 			 * Acquiring p_lock may cause us to recurse
 			 * through the sleep path and back into this



CVS commit: src/sys/kern

2023-10-08 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Oct  8 11:12:47 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
sleepq_block(): slightly reduce number of test+branch in the common case.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/kern/kern_sleepq.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

2023-10-07 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct  7 20:48:50 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
sleepq_uncatch(): fix typo that's been there since 2020, hello @thorpej lol:

-   l->l_flag = ~(LW_SINTR | LW_CATCHINTR | LW_STIMO);
+   l->l_flag &= ~(LW_SINTR | LW_CATCHINTR | LW_STIMO);


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/kern/kern_sleepq.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_sleepq.c
diff -u src/sys/kern/kern_sleepq.c:1.79 src/sys/kern/kern_sleepq.c:1.80
--- src/sys/kern/kern_sleepq.c:1.79	Sat Oct  7 14:12:29 2023
+++ src/sys/kern/kern_sleepq.c	Sat Oct  7 20:48:50 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sleepq.c,v 1.79 2023/10/07 14:12:29 ad Exp $	*/
+/*	$NetBSD: kern_sleepq.c,v 1.80 2023/10/07 20:48:50 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.79 2023/10/07 14:12:29 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.80 2023/10/07 20:48:50 ad Exp $");
 
 #include 
 #include 
@@ -319,7 +319,7 @@ void
 sleepq_uncatch(lwp_t *l)
 {
 
-	l->l_flag = ~(LW_SINTR | LW_CATCHINTR | LW_STIMO);
+	l->l_flag &= ~(LW_SINTR | LW_CATCHINTR | LW_STIMO);
 }
 
 /*



CVS commit: src/sys/kern

2023-10-07 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct  7 20:48:50 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
sleepq_uncatch(): fix typo that's been there since 2020, hello @thorpej lol:

-   l->l_flag = ~(LW_SINTR | LW_CATCHINTR | LW_STIMO);
+   l->l_flag &= ~(LW_SINTR | LW_CATCHINTR | LW_STIMO);


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/kern/kern_sleepq.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

2023-10-07 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct  7 14:12:29 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
sleepq_uncatch(): clear LW_STIMO too, so that there's no possibility that
the newly non-interruptable sleep could produce EWOULDBLOCK (paranoia).


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sys/kern/kern_sleepq.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_sleepq.c
diff -u src/sys/kern/kern_sleepq.c:1.78 src/sys/kern/kern_sleepq.c:1.79
--- src/sys/kern/kern_sleepq.c:1.78	Thu Oct  5 19:28:30 2023
+++ src/sys/kern/kern_sleepq.c	Sat Oct  7 14:12:29 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sleepq.c,v 1.78 2023/10/05 19:28:30 ad Exp $	*/
+/*	$NetBSD: kern_sleepq.c,v 1.79 2023/10/07 14:12:29 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.78 2023/10/05 19:28:30 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.79 2023/10/07 14:12:29 ad Exp $");
 
 #include 
 #include 
@@ -318,7 +318,8 @@ sleepq_transfer(lwp_t *l, sleepq_t *from
 void
 sleepq_uncatch(lwp_t *l)
 {
-	l->l_flag = ~(LW_SINTR | LW_CATCHINTR);
+
+	l->l_flag = ~(LW_SINTR | LW_CATCHINTR | LW_STIMO);
 }
 
 /*



CVS commit: src/sys/kern

2023-10-07 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct  7 14:12:29 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
sleepq_uncatch(): clear LW_STIMO too, so that there's no possibility that
the newly non-interruptable sleep could produce EWOULDBLOCK (paranoia).


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sys/kern/kern_sleepq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



  1   2   3   4   5   6   7   8   9   10   >