Module Name: src
Committed By: ad
Date: Wed Oct 4 20:42:38 UTC 2023
Modified Files:
src/sys/kern: kern_exit.c kern_lwp.c kern_sig.c sys_sig.c
Log Message:
Sprinkle a bunch more calls to lwp_need_userret(). There should be no
functional change but it does get rid of a bunch of assumptions about how
mi_userret() works making it easier to adjust in that in the future, and
works as a kind of documentation too.
To generate a diff of this commit:
cvs rdiff -u -r1.295 -r1.296 src/sys/kern/kern_exit.c
cvs rdiff -u -r1.258 -r1.259 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.406 -r1.407 src/sys/kern/kern_sig.c
cvs rdiff -u -r1.56 -r1.57 src/sys/kern/sys_sig.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_exit.c
diff -u src/sys/kern/kern_exit.c:1.295 src/sys/kern/kern_exit.c:1.296
--- src/sys/kern/kern_exit.c:1.295 Wed Oct 4 20:29:18 2023
+++ src/sys/kern/kern_exit.c Wed Oct 4 20:42:38 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_exit.c,v 1.295 2023/10/04 20:29:18 ad Exp $ */
+/* $NetBSD: kern_exit.c,v 1.296 2023/10/04 20:42:38 ad Exp $ */
/*-
* Copyright (c) 1998, 1999, 2006, 2007, 2008, 2020, 2023
@@ -68,7 +68,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.295 2023/10/04 20:29:18 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.296 2023/10/04 20:42:38 ad Exp $");
#include "opt_ktrace.h"
#include "opt_dtrace.h"
@@ -632,6 +632,7 @@ retry:
continue;
lwp_lock(l2);
l2->l_flag |= LW_WEXIT;
+ lwp_need_userret(l2);
if ((l2->l_stat == LSSLEEP && (l2->l_flag & LW_SINTR)) ||
l2->l_stat == LSSUSPENDED || l2->l_stat == LSSTOP) {
l2->l_flag &= ~LW_DBGSUSPEND;
@@ -639,7 +640,6 @@ retry:
setrunnable(l2);
continue;
}
- lwp_need_userret(l2);
lwp_unlock(l2);
}
Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.258 src/sys/kern/kern_lwp.c:1.259
--- src/sys/kern/kern_lwp.c:1.258 Wed Oct 4 20:28:06 2023
+++ src/sys/kern/kern_lwp.c Wed Oct 4 20:42:38 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_lwp.c,v 1.258 2023/10/04 20:28:06 ad Exp $ */
+/* $NetBSD: kern_lwp.c,v 1.259 2023/10/04 20:42:38 ad Exp $ */
/*-
* Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -217,7 +217,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.258 2023/10/04 20:28:06 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.259 2023/10/04 20:42:38 ad Exp $");
#include "opt_ddb.h"
#include "opt_lockdebug.h"
@@ -468,6 +468,7 @@ lwp_suspend(struct lwp *curl, struct lwp
case LSSLEEP:
t->l_flag |= LW_WSUSPEND;
+ lwp_need_userret(t);
/*
* Kick the LWP and try to get it to the kernel boundary
@@ -486,6 +487,7 @@ lwp_suspend(struct lwp *curl, struct lwp
case LSSTOP:
t->l_flag |= LW_WSUSPEND;
+ lwp_need_userret(t);
setrunnable(t);
break;
@@ -962,6 +964,11 @@ lwp_create(lwp_t *l1, proc_t *p2, vaddr_
lwp_unlock(l1);
}
+ /* Ensure a trip through lwp_userret() if needed. */
+ if ((l2->l_flag & LW_USERRET) != 0) {
+ lwp_need_userret(l2);
+ }
+
/* This marks the end of the "must be atomic" section. */
mutex_exit(p2->p_lock);
@@ -1794,7 +1801,7 @@ lwp_need_userret(struct lwp *l)
{
KASSERT(!cpu_intr_p());
- KASSERT(lwp_locked(l, NULL));
+ KASSERT(lwp_locked(l, NULL) || l->l_stat == LSIDL);
/*
* If the LWP is in any state other than LSONPROC, we know that it
Index: src/sys/kern/kern_sig.c
diff -u src/sys/kern/kern_sig.c:1.406 src/sys/kern/kern_sig.c:1.407
--- src/sys/kern/kern_sig.c:1.406 Wed Oct 4 20:29:18 2023
+++ src/sys/kern/kern_sig.c Wed Oct 4 20:42:38 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_sig.c,v 1.406 2023/10/04 20:29:18 ad Exp $ */
+/* $NetBSD: kern_sig.c,v 1.407 2023/10/04 20:42:38 ad Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008, 2019, 2023 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.406 2023/10/04 20:29:18 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.407 2023/10/04 20:42:38 ad Exp $");
#include "opt_execfmt.h"
#include "opt_ptrace.h"
@@ -2266,6 +2266,7 @@ sigexit(struct lwp *l, int signo)
if ((p->p_sflag & PS_WCORE) != 0) {
lwp_lock(l);
l->l_flag |= (LW_WCORE | LW_WEXIT | LW_WSUSPEND);
+ lwp_need_userret(l);
lwp_unlock(l);
mutex_exit(p->p_lock);
lwp_userret(l);
@@ -2297,6 +2298,7 @@ sigexit(struct lwp *l, int signo)
continue;
}
t->l_flag |= (LW_WCORE | LW_WEXIT);
+ lwp_need_userret(t);
lwp_suspend(l, t);
}
Index: src/sys/kern/sys_sig.c
diff -u src/sys/kern/sys_sig.c:1.56 src/sys/kern/sys_sig.c:1.57
--- src/sys/kern/sys_sig.c:1.56 Thu Apr 21 21:31:11 2022
+++ src/sys/kern/sys_sig.c Wed Oct 4 20:42:38 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_sig.c,v 1.56 2022/04/21 21:31:11 andvar Exp $ */
+/* $NetBSD: sys_sig.c,v 1.57 2023/10/04 20:42:38 ad Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_sig.c,v 1.56 2022/04/21 21:31:11 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_sig.c,v 1.57 2023/10/04 20:42:38 ad Exp $");
#include "opt_dtrace.h"
@@ -569,6 +569,7 @@ sigaction1(struct lwp *l, int signum, co
if (sigispending(l, 0)) {
lwp_lock(l);
l->l_flag |= LW_PENDSIG;
+ lwp_need_userret(l);
lwp_unlock(l);
}
out:
@@ -617,6 +618,7 @@ sigprocmask1(struct lwp *l, int how, con
*/
lwp_lock(l);
l->l_flag |= LW_PENDSIG;
+ lwp_need_userret(l);
lwp_unlock(l);
}
return 0;
@@ -655,6 +657,7 @@ sigsuspendsetup(struct lwp *l, const sig
if (sigispending(l, 0)) {
lwp_lock(l);
l->l_flag |= LW_PENDSIG;
+ lwp_need_userret(l);
lwp_unlock(l);
}
mutex_exit(p->p_lock);
@@ -671,6 +674,7 @@ sigsuspendteardown(struct lwp *l)
if (sigispending(l, 0)) {
lwp_lock(l);
l->l_flag |= LW_PENDSIG;
+ lwp_need_userret(l);
lwp_unlock(l);
} else {
l->l_sigrestore = 0;