CVS commit: [netbsd-9] src/sys/kern

2021-06-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jun 21 16:14:14 UTC 2021

Modified Files:
src/sys/kern [netbsd-9]: kern_ksyms.c

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1299):

sys/kern/kern_ksyms.c: revision 1.90
sys/kern/kern_ksyms.c: revision 1.91
sys/kern/kern_ksyms.c: revision 1.92
sys/kern/kern_ksyms.c: revision 1.93
sys/kern/kern_ksyms.c: revision 1.94
sys/kern/kern_ksyms.c: revision 1.95
sys/kern/kern_ksyms.c: revision 1.96
sys/kern/kern_ksyms.c: revision 1.97

ksyms(4): Fix ksymsread synchronization.

Fixes crash on concurrent update and read of /dev/ksyms.
XXX Unclear why we have to skip sd_gone entries here -- it seems like
they should be preserved until ksymsclose.
ksyms(4): Modify ksyms_symtabs only at IPL_HIGH.

This limits the opportunities for ddb to witness an inconsistent
state of the symbol table list.
ksyms(4): Don't skip symbol tables that are soon to be freed.

They will not actually be freed until /dev/ksyms is closed, so
continued access to them remains kosher.
Revert "ksyms(4): Don't skip symbol tables that are soon to be freed."

Apparently the equality kassert this restored doesn't work; to be
analyzed.

Fix regression introduced in rev 1.90
in which the last element of ksyms_symtabs is skipped by mistake.

ksyms(4): Fix race in ksymsread iteration.
TAILQ_NEXT(ksyms_last_snapshot) might change while we are iterating,
but ksyms_last_snapshot itself cannot, so invert the loop structure.

Discussed with rin@.

ksyms(4): Don't skip symbol tables that are soon to be freed, take 2.

They will not actually be freed until /dev/ksyms is closed, so
continued access to them remains kosher.
The previous change was busted because of an off-by-one error in a
previous previous change's iteration over the symtabs; that error has
since been corrected.

ksyms(4): Allow multiple concurrent opens of /dev/ksyms.

First one takes a snapshot; others all agree with the snapshot.
Previously this code path was just broken (could fail horribly if
modules were unloaded after one of the opens is closed), so I just
blocked it off in an earlier commit, but that broke crash(8).  So
let's continue allowing multiple opens seeing the same snapshot, but
without the horrible bugs.


To generate a diff of this commit:
cvs rdiff -u -r1.87.8.1 -r1.87.8.2 src/sys/kern/kern_ksyms.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_ksyms.c
diff -u src/sys/kern/kern_ksyms.c:1.87.8.1 src/sys/kern/kern_ksyms.c:1.87.8.2
--- src/sys/kern/kern_ksyms.c:1.87.8.1	Tue Jan  7 11:54:57 2020
+++ src/sys/kern/kern_ksyms.c	Mon Jun 21 16:14:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_ksyms.c,v 1.87.8.1 2020/01/07 11:54:57 martin Exp $	*/
+/*	$NetBSD: kern_ksyms.c,v 1.87.8.2 2021/06/21 16:14:14 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.87.8.1 2020/01/07 11:54:57 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.87.8.2 2021/06/21 16:14:14 martin Exp $");
 
 #if defined(_KERNEL) && defined(_KERNEL_OPT)
 #include "opt_copy_symtab.h"
@@ -92,6 +92,8 @@ __KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #ifdef DDB
 #include 
@@ -110,7 +112,8 @@ static uint32_t *ksyms_nmap = NULL;
 #endif
 
 static int ksyms_maxlen;
-static bool ksyms_isopen;
+static uint64_t ksyms_opencnt;
+static struct ksyms_symtab *ksyms_last_snapshot;
 static bool ksyms_initted;
 static bool ksyms_loaded;
 static kmutex_t ksyms_lock __cacheline_aligned;
@@ -140,7 +143,7 @@ struct ksyms_hdr ksyms_hdr;
 int ksyms_symsz;
 int ksyms_strsz;
 int ksyms_ctfsz;	/* this is not currently used by savecore(8) */
-TAILQ_HEAD(, ksyms_symtab) ksyms_symtabs =
+TAILQ_HEAD(ksyms_symtab_queue, ksyms_symtab) ksyms_symtabs =
 TAILQ_HEAD_INITIALIZER(ksyms_symtabs);
 
 static int
@@ -296,6 +299,7 @@ addsymtab(const char *name, void *symsta
 	int i, j, n, nglob;
 	char *str;
 	int nsyms = symsize / sizeof(Elf_Sym);
+	int s;
 
 	/* Sanity check for pre-allocated map table used during startup. */
 	if ((nmap == ksyms_nmap) && (nsyms >= KSYMS_MAX_ID)) {
@@ -419,7 +423,7 @@ addsymtab(const char *name, void *symsta
 		for (new = 0; new < n; new++) {
 			uint32_t orig = nsym[new].st_size - 1;
 			uint32_t size = nmap[orig];
-	
+
 			nmap[orig] = new + 1;
 
 			/* restore the size */
@@ -428,9 +432,18 @@ addsymtab(const char *name, void *symsta
 	}
 #endif
 
-	/* ksymsread() is unlocked, so membar. */
-	membar_producer();
+	KASSERT(strcmp(name, "netbsd") == 0 || mutex_owned(_lock));
+	KASSERT(cold || mutex_owned(_lock));
+
+	/*
+	 * Ensure ddb never witnesses an inconsistent state of the
+	 * queue, unless memory is so corrupt that we crash in
+	 * TAILQ_INSERT_TAIL.
+	 */
+	s = splhigh();
 	

CVS commit: [netbsd-9] src/sys/kern

2021-05-03 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon May  3 09:12:50 UTC 2021

Modified Files:
src/sys/kern [netbsd-9]: kern_exec.c

Log Message:
Pull up following revision(s) (requested by martin in ticket #1265):
sys/kern/kern_exec.c: revision 1.505 via patch
Fix copy in handling of POSIX_SPAWN_RESETIDS in posix_spawn(3)


To generate a diff of this commit:
cvs rdiff -u -r1.478.2.1 -r1.478.2.2 src/sys/kern/kern_exec.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.478.2.1 src/sys/kern/kern_exec.c:1.478.2.2
--- src/sys/kern/kern_exec.c:1.478.2.1	Tue Oct 15 18:32:13 2019
+++ src/sys/kern/kern_exec.c	Mon May  3 09:12:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.478.2.1 2019/10/15 18:32:13 martin Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.478.2.2 2021/05/03 09:12:50 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.478.2.1 2019/10/15 18:32:13 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.478.2.2 2021/05/03 09:12:50 bouyer Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -2124,7 +2124,7 @@ spawn_return(void *arg)
 
 		/* Reset user ID's */
 		if (spawn_data->sed_attrs->sa_flags & POSIX_SPAWN_RESETIDS) {
-			error = do_setresuid(l, -1,
+			error = do_setresgid(l, -1,
 			 kauth_cred_getgid(l->l_cred), -1,
 			 ID_E_EQ_R | ID_E_EQ_S);
 			if (error)



CVS commit: [netbsd-9] src/sys/kern

2021-03-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Mar  5 13:48:27 UTC 2021

Modified Files:
src/sys/kern [netbsd-9]: kern_subr.c

Log Message:
Pull up following revision(s) (requested by tsutsui in ticket #1222):

sys/kern/kern_subr.c: revision 1.229

Restore missing message for RB_ASKNAME.
Cleanups.


To generate a diff of this commit:
cvs rdiff -u -r1.223.4.1 -r1.223.4.2 src/sys/kern/kern_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/kern_subr.c
diff -u src/sys/kern/kern_subr.c:1.223.4.1 src/sys/kern/kern_subr.c:1.223.4.2
--- src/sys/kern/kern_subr.c:1.223.4.1	Tue Sep 17 19:45:03 2019
+++ src/sys/kern/kern_subr.c	Fri Mar  5 13:48:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_subr.c,v 1.223.4.1 2019/09/17 19:45:03 martin Exp $	*/
+/*	$NetBSD: kern_subr.c,v 1.223.4.2 2021/03/05 13:48:27 martin Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 1999, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.223.4.1 2019/09/17 19:45:03 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.223.4.2 2021/03/05 13:48:27 martin Exp $");
 
 #include "opt_ddb.h"
 #include "opt_md.h"
@@ -442,8 +442,20 @@ setroot_ask(device_t bootdv, int bootpar
 		}
 	}
 
+	switch (device_class(rootdv)) {
+	case DV_IFNET:
+	case DV_DISK:
+		aprint_normal("root on %s", device_xname(rootdv));
+		if (DEV_USES_PARTITIONS(rootdv))
+			aprint_normal("%c", (int)DISKPART(rootdev) + 'a');
+		break;
+	default:
+		printf("can't determine root device\n");
+		return;
+	}
+
 	root_device = rootdv;
-	setroot_dump(root_device, dumpdv);
+	setroot_dump(rootdv, dumpdv);
 }
 
 /*



CVS commit: [netbsd-9] src/sys/kern

2021-02-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Feb  7 16:42:41 UTC 2021

Modified Files:
src/sys/kern [netbsd-9]: kern_event.c

Log Message:
Apply additional patch, requested by jdolecek in ticket #1191:

sys/kern/kern_event.c   1.110-1.115 (via patch)

Fix merge botch for the EV_ONESHOT branch.


To generate a diff of this commit:
cvs rdiff -u -r1.104.4.1 -r1.104.4.2 src/sys/kern/kern_event.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_event.c
diff -u src/sys/kern/kern_event.c:1.104.4.1 src/sys/kern/kern_event.c:1.104.4.2
--- src/sys/kern/kern_event.c:1.104.4.1	Thu Feb  4 16:57:25 2021
+++ src/sys/kern/kern_event.c	Sun Feb  7 16:42:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_event.c,v 1.104.4.1 2021/02/04 16:57:25 martin Exp $	*/
+/*	$NetBSD: kern_event.c,v 1.104.4.2 2021/02/07 16:42:41 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.104.4.1 2021/02/04 16:57:25 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.104.4.2 2021/02/07 16:42:41 martin Exp $");
 
 #include 
 #include 
@@ -1399,9 +1399,11 @@ relock:
 		/* XXXAD should be got from f_event if !oneshot. */
 		*kevp++ = kn->kn_kevent;
 		nkev++;
+		influx = 1;
 		if (kn->kn_flags & EV_ONESHOT) {
 			/* delete ONESHOT events after retrieval */
 			kn->kn_status &= ~KN_BUSY;
+			kq->kq_count--;
 			mutex_spin_exit(>kq_lock);
 			knote_detach(kn, fdp, true);
 			mutex_enter(>fd_lock);



CVS commit: [netbsd-9] src/sys/kern

2021-02-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Feb  4 16:57:25 UTC 2021

Modified Files:
src/sys/kern [netbsd-9]: kern_event.c

Log Message:
Pullup the following (requested by jdolecek in ticket #1191):

sys/kern/kern_event.c   r1.110-1.115 (via patch)

fix a race in kqueue_scan() - when multiple threads check the same
kqueue, it could happen other thread seen empty kqueue while kevent
was being checked for re-firing and re-queued

make sure to keep retrying if there are outstanding kevents even
if no kevent is found on first pass through the queue, and only
kq_count when actually completely done with the kevent

PR kern/50094 by Christof Meerwal

Also fixes timer latency in Go, as reported in
https://github.com/golang/go/issues/42515 by Michael Pratt


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.104.4.1 src/sys/kern/kern_event.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_event.c
diff -u src/sys/kern/kern_event.c:1.104 src/sys/kern/kern_event.c:1.104.4.1
--- src/sys/kern/kern_event.c:1.104	Tue Nov 13 06:58:14 2018
+++ src/sys/kern/kern_event.c	Thu Feb  4 16:57:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_event.c,v 1.104 2018/11/13 06:58:14 maxv Exp $	*/
+/*	$NetBSD: kern_event.c,v 1.104.4.1 2021/02/04 16:57:25 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.104 2018/11/13 06:58:14 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.104.4.1 2021/02/04 16:57:25 martin Exp $");
 
 #include 
 #include 
@@ -166,6 +166,8 @@ static int	kq_calloutmax = (4 * 1024);
 
 extern const struct filterops sig_filtops;
 
+#define KQ_FLUX_WAKEUP(kq)	cv_broadcast(>kq_cv)
+
 /*
  * Table for for all system-defined filters.
  * These should be listed in the numeric order of the EVFILT_* defines.
@@ -1226,7 +1228,10 @@ kqueue_check(const char *func, size_t li
 			}
 			count++;
 			if (count > kq->kq_count) {
-goto bad;
+panic("%s,%zu: kq=%p kq->kq_count(%d) != "
+"count(%d), nmarker=%d",
+				func, line, kq, kq->kq_count, count,
+nmarker);
 			}
 		} else {
 			nmarker++;
@@ -1240,11 +1245,6 @@ kqueue_check(const char *func, size_t li
 #endif
 		}
 	}
-	if (kq->kq_count != count) {
-bad:
-		panic("%s,%zu: kq=%p kq->kq_count(%d) != count(%d), nmarker=%d",
-		func, line, kq, kq->kq_count, count, nmarker);
-	}
 }
 #define kq_check(a) kqueue_check(__func__, __LINE__, (a))
 #else /* defined(DEBUG) */
@@ -1268,7 +1268,7 @@ kqueue_scan(file_t *fp, size_t maxevents
 	struct timespec	ats, sleepts;
 	struct knote	*kn, *marker, morker;
 	size_t		count, nkev, nevents;
-	int		timeout, error, rv;
+	int		timeout, error, rv, influx;
 	filedesc_t	*fdp;
 
 	fdp = curlwp->l_fd;
@@ -1317,119 +1317,140 @@ kqueue_scan(file_t *fp, size_t maxevents
 			}
 		}
 		mutex_spin_exit(>kq_lock);
-	} else {
-		/* mark end of knote list */
-		TAILQ_INSERT_TAIL(>kq_head, marker, kn_tqe);
+		goto done;
+	}
 
-		/*
-		 * Acquire the fdp->fd_lock interlock to avoid races with
-		 * file creation/destruction from other threads.
-		 */
-		mutex_spin_exit(>kq_lock);
-		mutex_enter(>fd_lock);
-		mutex_spin_enter(>kq_lock);
+	/* mark end of knote list */
+	TAILQ_INSERT_TAIL(>kq_head, marker, kn_tqe);
+	influx = 0;
 
-		while (count != 0) {
-			kn = TAILQ_FIRST(>kq_head);	/* get next knote */
-			while ((kn->kn_status & KN_MARKER) != 0) {
-if (kn == marker) {
-	/* it's our marker, stop */
-	TAILQ_REMOVE(>kq_head, kn, kn_tqe);
-	if (count < maxevents || (tsp != NULL &&
-	(timeout = gettimeleft(,
-	)) <= 0))
-		goto done;
-	mutex_exit(>fd_lock);
-	goto retry;
-}
-/* someone else's marker. */
-kn = TAILQ_NEXT(kn, kn_tqe);
+	/*
+	 * Acquire the fdp->fd_lock interlock to avoid races with
+	 * file creation/destruction from other threads.
+	 */
+relock:
+	mutex_spin_exit(>kq_lock);
+	mutex_enter(>fd_lock);
+	mutex_spin_enter(>kq_lock);
+
+	while (count != 0) {
+		kn = TAILQ_FIRST(>kq_head);	/* get next knote */
+
+		if ((kn->kn_status & KN_MARKER) != 0 && kn != marker) {
+			if (influx) {
+influx = 0;
+KQ_FLUX_WAKEUP(kq);
 			}
-			kq_check(kq);
+			mutex_exit(>fd_lock);
+			(void)cv_wait(>kq_cv, >kq_lock);
+			goto relock;
+		}
+
+		TAILQ_REMOVE(>kq_head, kn, kn_tqe);
+		if (kn == marker) {
+			/* it's our marker, stop */
+			KQ_FLUX_WAKEUP(kq);
+			if (count == maxevents) {
+mutex_exit(>fd_lock);
+goto retry;
+			}
+			break;
+		}
+		KASSERT((kn->kn_status & KN_BUSY) == 0);
+
+		kq_check(kq);
+		kn->kn_status &= ~KN_QUEUED;
+		kn->kn_status |= KN_BUSY;
+		kq_check(kq);
+		if (kn->kn_status & KN_DISABLED) {
+			kn->kn_status &= ~KN_BUSY;
 			kq->kq_count--;
-			TAILQ_REMOVE(>kq_head, kn, kn_tqe);
-			kn->kn_status &= ~KN_QUEUED;
-			kn->kn_status |= KN_BUSY;
-			kq_check(kq);
-			if 

CVS commit: [netbsd-9] src/sys/kern

2021-01-25 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jan 25 14:12:50 UTC 2021

Modified Files:
src/sys/kern [netbsd-9]: kern_threadpool.c

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1187):

sys/kern/kern_threadpool.c: revision 1.23

threadpool(9): Fix synchronization between cancel and dispatch.
- threadpool_cancel_job_async tried to prevent
  threadpool_dispatcher_thread from taking the job by setting
  job->job_thread = NULL and then removing the job from the queue.
- But threadpool_cancel_job_async didn't notice job->job_thread is
  null until after it also removes the job from the queue =>
  double-remove, *boom*.

The solution is to teach threadpool_dispatcher_thread to wait until
it has acquired the job lock to test whether job->job_thread is still
valid before it decides to remove the job from the queue.

Fixes PR kern/55948.

XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.15.6.1 src/sys/kern/kern_threadpool.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_threadpool.c
diff -u src/sys/kern/kern_threadpool.c:1.15 src/sys/kern/kern_threadpool.c:1.15.6.1
--- src/sys/kern/kern_threadpool.c:1.15	Thu Jan 17 10:18:52 2019
+++ src/sys/kern/kern_threadpool.c	Mon Jan 25 14:12:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_threadpool.c,v 1.15 2019/01/17 10:18:52 hannken Exp $	*/
+/*	$NetBSD: kern_threadpool.c,v 1.15.6.1 2021/01/25 14:12:50 martin Exp $	*/
 
 /*-
  * Copyright (c) 2014, 2018 The NetBSD Foundation, Inc.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_threadpool.c,v 1.15 2019/01/17 10:18:52 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_threadpool.c,v 1.15.6.1 2021/01/25 14:12:50 martin Exp $");
 
 #include 
 #include 
@@ -947,7 +947,7 @@ threadpool_overseer_thread(void *arg)
 
 		/* There are idle threads, so try giving one a job.  */
 		struct threadpool_job *const job = TAILQ_FIRST(>tp_jobs);
-		TAILQ_REMOVE(>tp_jobs, job, job_entry);
+
 		/*
 		 * Take an extra reference on the job temporarily so that
 		 * it won't disappear on us while we have both locks dropped.
@@ -959,6 +959,7 @@ threadpool_overseer_thread(void *arg)
 		/* If the job was cancelled, we'll no longer be its thread.  */
 		if (__predict_true(job->job_thread == overseer)) {
 			mutex_spin_enter(>tp_lock);
+			TAILQ_REMOVE(>tp_jobs, job, job_entry);
 			if (__predict_false(
 TAILQ_EMPTY(>tp_idle_threads))) {
 /*



CVS commit: [netbsd-9] src/sys/kern

2021-01-03 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jan  3 12:51:33 UTC 2021

Modified Files:
src/sys/kern [netbsd-9]: init_main.c

Log Message:
Apply patch, requested by khorben in ticket #1177 (issue solved differently
in -current):

sys/kern/init_main.c(apply patch)

PR kern/55906: create the aiodone workqueue before running mountroothooks.


To generate a diff of this commit:
cvs rdiff -u -r1.504.2.1 -r1.504.2.2 src/sys/kern/init_main.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.504.2.1 src/sys/kern/init_main.c:1.504.2.2
--- src/sys/kern/init_main.c:1.504.2.1	Sat Nov 14 15:36:11 2020
+++ src/sys/kern/init_main.c	Sun Jan  3 12:51:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init_main.c,v 1.504.2.1 2020/11/14 15:36:11 martin Exp $	*/
+/*	$NetBSD: init_main.c,v 1.504.2.2 2021/01/03 12:51:33 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.504.2.1 2020/11/14 15:36:11 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.504.2.2 2021/01/03 12:51:33 martin Exp $");
 
 #include "opt_ddb.h"
 #include "opt_inet.h"
@@ -668,6 +668,11 @@ main(void)
 	cpu_rootconf();
 	cpu_dumpconf();
 
+	/* Create the aiodone daemon kernel thread. */
+	if (workqueue_create(_queue, "aiodoned",
+	uvm_aiodone_worker, NULL, PRI_VM, IPL_NONE, WQ_MPSAFE))
+		panic("fork aiodoned");
+
 	/* Mount the root file system. */
 	do {
 		domountroothook(root_device);
@@ -736,11 +741,6 @@ main(void)
 	NULL, NULL, "ioflush"))
 		panic("fork syncer");
 
-	/* Create the aiodone daemon kernel thread. */
-	if (workqueue_create(_queue, "aiodoned",
-	uvm_aiodone_worker, NULL, PRI_VM, IPL_NONE, WQ_MPSAFE))
-		panic("fork aiodoned");
-
 	/* Wait for final configure threads to complete. */
 	config_finalize_mountroot();
 



CVS commit: [netbsd-9] src/sys/kern

2021-01-02 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Jan  2 10:23:46 UTC 2021

Modified Files:
src/sys/kern [netbsd-9]: core_elf32.c

Log Message:
Additionally pull up following revision(s) (requested by rin in ticket #1173):

sys/kern/core_elf32.c: revision 1.67

Use  instead of ,
which is not intended for standalone use.

Compile tested for all ports with their own COMPAT_NETBSD32 codes:
aarch64, amd64, arm, mips64, sparc64, and algor64.

Should fix build failure for mips64 in netbsd-9, where netbsd32.h is not
included by other header files.


To generate a diff of this commit:
cvs rdiff -u -r1.58.4.1 -r1.58.4.2 src/sys/kern/core_elf32.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/core_elf32.c
diff -u src/sys/kern/core_elf32.c:1.58.4.1 src/sys/kern/core_elf32.c:1.58.4.2
--- src/sys/kern/core_elf32.c:1.58.4.1	Fri Jan  1 13:04:08 2021
+++ src/sys/kern/core_elf32.c	Sat Jan  2 10:23:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: core_elf32.c,v 1.58.4.1 2021/01/01 13:04:08 martin Exp $	*/
+/*	$NetBSD: core_elf32.c,v 1.58.4.2 2021/01/02 10:23:46 martin Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.58.4.1 2021/01/01 13:04:08 martin Exp $");
+__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.58.4.2 2021/01/02 10:23:46 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_coredump.h"
@@ -68,7 +68,7 @@ __KERNEL_RCSID(1, "$NetBSD: core_elf32.c
 #ifdef COREDUMP
 
 #ifdef COMPAT_NETBSD32
-#include 
+#include 
 #endif
 
 struct writesegs_state {



CVS commit: [netbsd-9] src/sys/kern

2021-01-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jan  1 13:04:08 UTC 2021

Modified Files:
src/sys/kern [netbsd-9]: core_elf32.c

Log Message:
Pull up following revision(s) (requested by rin in ticket #1173):

sys/kern/core_elf32.c: revision 1.65 (patch)

Use correct note types for register storage in 32-bit core files for
architecture on which 64- and 32-bit ABIs use different values for
PT_GET{,FP}REGS, i.e., aarch64{,eb}.

Now, 32-bit GDB works fine for core files generated by aarch64{,eb}
kernel.

Should be no functional changes for ports other than aarch64{,eb}.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.58.4.1 src/sys/kern/core_elf32.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/core_elf32.c
diff -u src/sys/kern/core_elf32.c:1.58 src/sys/kern/core_elf32.c:1.58.4.1
--- src/sys/kern/core_elf32.c:1.58	Tue Jan 22 03:44:44 2019
+++ src/sys/kern/core_elf32.c	Fri Jan  1 13:04:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: core_elf32.c,v 1.58 2019/01/22 03:44:44 kamil Exp $	*/
+/*	$NetBSD: core_elf32.c,v 1.58.4.1 2021/01/01 13:04:08 martin Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.58 2019/01/22 03:44:44 kamil Exp $");
+__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.58.4.1 2021/01/01 13:04:08 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_coredump.h"
@@ -67,6 +67,10 @@ __KERNEL_RCSID(1, "$NetBSD: core_elf32.c
 
 #ifdef COREDUMP
 
+#ifdef COMPAT_NETBSD32
+#include 
+#endif
+
 struct writesegs_state {
 	Elf_Phdr *psections;
 	proc_t   *p;
@@ -489,8 +493,13 @@ ELFNAMEEND(coredump_note)(struct lwp *l,
 	if (error)
 		return (error);
 
-	ELFNAMEEND(coredump_savenote)(ns, PT_GETREGS, name, ,
-	sizeof(intreg));
+	ELFNAMEEND(coredump_savenote)(ns,
+#if ELFSIZE == 32 && defined(PT32_GETREGS)
+	PT32_GETREGS,
+#else
+	PT_GETREGS,
+#endif
+	name, , sizeof(intreg));
 
 #ifdef PT_GETFPREGS
 	freglen = sizeof(freg);
@@ -498,7 +507,13 @@ ELFNAMEEND(coredump_note)(struct lwp *l,
 	if (error)
 		return (error);
 
-	ELFNAMEEND(coredump_savenote)(ns, PT_GETFPREGS, name, , freglen);
+	ELFNAMEEND(coredump_savenote)(ns,
+#  if ELFSIZE == 32 && defined(PT32_GETFPREGS)
+	PT32_GETFPREGS,
+#  else
+	PT_GETFPREGS,
+#  endif
+	name, , freglen);
 #endif
 	/* XXX Add hook for machdep per-LWP notes. */
 	return (0);



CVS commit: [netbsd-9] src/sys/kern

2020-11-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Nov  1 17:26:01 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: kern_time.c

Log Message:
Pull up following revision(s) (requested by nia in ticket #1124):

sys/kern/kern_time.c: revision 1.206

kern_time: prevent the system clock from being set too low or high
currently doing this will drive KUBSAN haywire and possibly cause
system lock-ups, so more testing should probably be performed before
we let the clock be set too many thousands of years into the future.

ditto for negative values, which were being passed by chrony for
some reason while my internet connection was being unreliable.
this also triggered some interesting KUBSAN reports.


To generate a diff of this commit:
cvs rdiff -u -r1.197.4.3 -r1.197.4.4 src/sys/kern/kern_time.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_time.c
diff -u src/sys/kern/kern_time.c:1.197.4.3 src/sys/kern/kern_time.c:1.197.4.4
--- src/sys/kern/kern_time.c:1.197.4.3	Mon May 18 19:05:32 2020
+++ src/sys/kern/kern_time.c	Sun Nov  1 17:26:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_time.c,v 1.197.4.3 2020/05/18 19:05:32 martin Exp $	*/
+/*	$NetBSD: kern_time.c,v 1.197.4.4 2020/11/01 17:26:01 martin Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2004, 2005, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.197.4.3 2020/05/18 19:05:32 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.197.4.4 2020/11/01 17:26:01 martin Exp $");
 
 #include 
 #include 
@@ -138,6 +138,13 @@ settime1(struct proc *p, const struct ti
 	struct timespec delta, now;
 	int s;
 
+	/*
+	 * The time being set to an unreasonable value will cause
+	 * unreasonable system behaviour.
+	 */
+	if (ts->tv_sec < 0 || ts->tv_sec > (1LL << 36))
+		return (EINVAL);
+
 	/* WHAT DO WE DO ABOUT PENDING REAL-TIME TIMEOUTS??? */
 	s = splclock();
 	nanotime();



CVS commit: [netbsd-9] src/sys/kern

2020-09-22 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Sep 22 18:39:01 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: uipc_socket.c uipc_socket2.c uipc_usrreq.c

Log Message:
Pull up following revision(s) (requested by christos in ticket #1091):

sys/kern/uipc_socket.c: revision 1.291
sys/kern/uipc_usrreq.c: revision 1.199
sys/kern/uipc_socket2.c: revision 1.138

add socket info for user and group for unix sockets in fstat.


To generate a diff of this commit:
cvs rdiff -u -r1.281.2.2 -r1.281.2.3 src/sys/kern/uipc_socket.c
cvs rdiff -u -r1.134 -r1.134.2.1 src/sys/kern/uipc_socket2.c
cvs rdiff -u -r1.194 -r1.194.2.1 src/sys/kern/uipc_usrreq.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.281.2.2 src/sys/kern/uipc_socket.c:1.281.2.3
--- src/sys/kern/uipc_socket.c:1.281.2.2	Tue Feb 25 19:10:51 2020
+++ src/sys/kern/uipc_socket.c	Tue Sep 22 18:39:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_socket.c,v 1.281.2.2 2020/02/25 19:10:51 martin Exp $	*/
+/*	$NetBSD: uipc_socket.c,v 1.281.2.3 2020/09/22 18:39:01 martin Exp $	*/
 
 /*
  * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.281.2.2 2020/02/25 19:10:51 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.281.2.3 2020/09/22 18:39:01 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -526,6 +526,7 @@ socreate(int dom, struct socket **aso, i
 #endif
 	uid = kauth_cred_geteuid(l->l_cred);
 	so->so_uidinfo = uid_find(uid);
+	so->so_egid = kauth_cred_getegid(l->l_cred);
 	so->so_cpid = l->l_proc->p_pid;
 
 	/*

Index: src/sys/kern/uipc_socket2.c
diff -u src/sys/kern/uipc_socket2.c:1.134 src/sys/kern/uipc_socket2.c:1.134.2.1
--- src/sys/kern/uipc_socket2.c:1.134	Thu Jul 11 17:30:44 2019
+++ src/sys/kern/uipc_socket2.c	Tue Sep 22 18:39:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_socket2.c,v 1.134 2019/07/11 17:30:44 maxv Exp $	*/
+/*	$NetBSD: uipc_socket2.c,v 1.134.2.1 2020/09/22 18:39:01 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.134 2019/07/11 17:30:44 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.134.2.1 2020/09/22 18:39:01 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -317,6 +317,7 @@ sonewconn(struct socket *head, bool sore
 	so->so_send = head->so_send;
 	so->so_receive = head->so_receive;
 	so->so_uidinfo = head->so_uidinfo;
+	so->so_egid = head->so_egid;
 	so->so_cpid = head->so_cpid;
 
 	/*

Index: src/sys/kern/uipc_usrreq.c
diff -u src/sys/kern/uipc_usrreq.c:1.194 src/sys/kern/uipc_usrreq.c:1.194.2.1
--- src/sys/kern/uipc_usrreq.c:1.194	Mon Jul 29 09:42:17 2019
+++ src/sys/kern/uipc_usrreq.c	Tue Sep 22 18:39:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_usrreq.c,v 1.194 2019/07/29 09:42:17 maxv Exp $	*/
+/*	$NetBSD: uipc_usrreq.c,v 1.194.2.1 2020/09/22 18:39:01 martin Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.194 2019/07/29 09:42:17 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.194.2.1 2020/09/22 18:39:01 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -898,6 +898,8 @@ unp_stat(struct socket *so, struct stat 
 		unp->unp_ino = unp_ino++;
 	ub->st_atimespec = ub->st_mtimespec = ub->st_ctimespec = unp->unp_ctime;
 	ub->st_ino = unp->unp_ino;
+	ub->st_uid = so->so_uidinfo->ui_uid;
+	ub->st_gid = so->so_egid;
 	return (0);
 }
 



CVS commit: [netbsd-9] src/sys/kern

2020-09-02 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Sep  2 12:42:32 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: kern_syscall.c

Log Message:
Pull up following revision(s) (requested by christos in ticket #1072):

sys/kern/kern_syscall.c: revision 1.21

PR/55629: Andreas Gustafsson: Don't crash when an emulation does not provide
e_dtrace_syscall (like compat_netbsd32)


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.18.2.1 src/sys/kern/kern_syscall.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_syscall.c
diff -u src/sys/kern/kern_syscall.c:1.18 src/sys/kern/kern_syscall.c:1.18.2.1
--- src/sys/kern/kern_syscall.c:1.18	Mon May  6 08:05:03 2019
+++ src/sys/kern/kern_syscall.c	Wed Sep  2 12:42:32 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_syscall.c,v 1.18 2019/05/06 08:05:03 kamil Exp $	*/
+/*	$NetBSD: kern_syscall.c,v 1.18.2.1 2020/09/02 12:42:32 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_syscall.c,v 1.18 2019/05/06 08:05:03 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_syscall.c,v 1.18.2.1 2020/09/02 12:42:32 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_modular.h"
@@ -238,11 +238,16 @@ int
 trace_enter(register_t code, const struct sysent *sy, const void *args)
 {
 	int error = 0;
+#if defined(PTRACE) || defined(KDTRACE_HOOKS)
+	struct proc *p = curlwp->l_proc;
+#endif
 
 #ifdef KDTRACE_HOOKS
 	if (sy->sy_entry) {
-		struct emul *e = curlwp->l_proc->p_emul;
-		(*e->e_dtrace_syscall)(sy->sy_entry, code, sy, args, NULL, 0);
+		struct emul *e = p->p_emul;
+		if (e->e_dtrace_syscall)
+			(*e->e_dtrace_syscall)(sy->sy_entry, code, sy, args,
+			NULL, 0);
 	}
 #endif
 
@@ -253,7 +258,7 @@ trace_enter(register_t code, const struc
 	ktrsyscall(code, args, sy->sy_narg);
 
 #ifdef PTRACE
-	if ((curlwp->l_proc->p_slflag & (PSL_SYSCALL|PSL_TRACED)) ==
+	if ((p->p_slflag & (PSL_SYSCALL|PSL_TRACED)) ==
 	(PSL_SYSCALL|PSL_TRACED)) {
 		proc_stoptrace(TRAP_SCE, code, args, NULL, 0);
 		if (curlwp->l_proc->p_slflag & PSL_SYSCALLEMU) {
@@ -282,8 +287,10 @@ trace_exit(register_t code, const struct
 
 #ifdef KDTRACE_HOOKS
 	if (sy->sy_return) {
-		(*p->p_emul->e_dtrace_syscall)(sy->sy_return, code, sy, args,
-		rval, error);
+		struct emul *e = p->p_emul;
+		if (e->e_dtrace_syscall)
+			(*p->p_emul->e_dtrace_syscall)(sy->sy_return, code, sy,
+			args, rval, error);
 	}
 #endif
 



CVS commit: [netbsd-9] src/sys/kern

2020-07-15 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Jul 15 13:30:20 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: subr_percpu.c

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1005):

sys/kern/subr_percpu.c: revision 1.20

Allow equality in this assertion.

This can happen if we lose the race mentioned in percpu_cpu_swap.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.18.14.1 src/sys/kern/subr_percpu.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_percpu.c
diff -u src/sys/kern/subr_percpu.c:1.18 src/sys/kern/subr_percpu.c:1.18.14.1
--- src/sys/kern/subr_percpu.c:1.18	Wed May 31 23:54:17 2017
+++ src/sys/kern/subr_percpu.c	Wed Jul 15 13:30:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_percpu.c,v 1.18 2017/05/31 23:54:17 chs Exp $	*/
+/*	$NetBSD: subr_percpu.c,v 1.18.14.1 2020/07/15 13:30:20 martin Exp $	*/
 
 /*-
  * Copyright (c)2007,2008 YAMAMOTO Takashi,
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_percpu.c,v 1.18 2017/05/31 23:54:17 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_percpu.c,v 1.18.14.1 2020/07/15 13:30:20 martin Exp $");
 
 #include 
 #include 
@@ -149,7 +149,7 @@ percpu_cpu_enlarge(size_t size)
 			where = xc_unicast(0, percpu_cpu_swap, ci, , ci);
 			xc_wait(where);
 		}
-		KASSERT(pcc.pcc_size < size);
+		KASSERT(pcc.pcc_size <= size);
 		if (pcc.pcc_data != NULL) {
 			kmem_free(pcc.pcc_data, pcc.pcc_size);
 		}



CVS commit: [netbsd-9] src/sys/kern

2020-06-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jun  7 17:07:07 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: subr_pcu.c

Log Message:
Pull up following revision(s) (requested by thorpej in ticket #949):

sys/kern/subr_pcu.c: revision 1.22

Relax the KASSERT() in pcu_discard_all() to allow non-curlwp if it is
in LSIDL state, which can happen if the new LWP is exiting before it's
ever run, e.g. if an error occurs in _lwp_create(2).


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.21.8.1 src/sys/kern/subr_pcu.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_pcu.c
diff -u src/sys/kern/subr_pcu.c:1.21 src/sys/kern/subr_pcu.c:1.21.8.1
--- src/sys/kern/subr_pcu.c:1.21	Mon Oct 16 15:03:57 2017
+++ src/sys/kern/subr_pcu.c	Sun Jun  7 17:07:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_pcu.c,v 1.21 2017/10/16 15:03:57 bouyer Exp $	*/
+/*	$NetBSD: subr_pcu.c,v 1.21.8.1 2020/06/07 17:07:07 martin Exp $	*/
 
 /*-
  * Copyright (c) 2011, 2014 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_pcu.c,v 1.21 2017/10/16 15:03:57 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pcu.c,v 1.21.8.1 2020/06/07 17:07:07 martin Exp $");
 
 #include 
 #include 
@@ -130,7 +130,12 @@ pcu_discard_all(lwp_t *l)
 {
 	const uint32_t pcu_valid = l->l_pcu_valid;
 
-	KASSERT(l == curlwp || ((l->l_flag & LW_SYSTEM) && pcu_valid == 0));
+	/*
+	 * The check for LSIDL here is to catch the case where the LWP exits
+	 * due to an error in the LWP creation path before it ever runs.
+	 */
+	KASSERT(l == curlwp || l->l_stat == LSIDL ||
+		((l->l_flag & LW_SYSTEM) && pcu_valid == 0));
 
 	if (__predict_true(pcu_valid == 0)) {
 		/* PCUs are not in use. */



CVS commit: [netbsd-9] src/sys/kern

2020-05-25 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon May 25 17:19:37 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: subr_thmap.c

Log Message:
Pull up following revision(s) (requested by rmind in ticket #929):

sys/kern/subr_thmap.c: revision 1.6

thmap(9): merge changes from the upstream -- primarily, switch to the
C11-style memory fences and atomic primitives; in NetBSD, this translates
to using the atomic_loadstore(9) primitives.

To be pulled up (just in case).


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.5.6.1 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.5 src/sys/kern/subr_thmap.c:1.5.6.1
--- src/sys/kern/subr_thmap.c:1.5	Mon Feb  4 08:00:27 2019
+++ src/sys/kern/subr_thmap.c	Mon May 25 17:19:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_thmap.c,v 1.5 2019/02/04 08:00:27 mrg Exp $	*/
+/*	$NetBSD: subr_thmap.c,v 1.5.6.1 2020/05/25 17:19:37 martin Exp $	*/
 
 /*-
  * Copyright (c) 2018 Mindaugas Rasiukevicius 
@@ -53,7 +53,7 @@
  *   re-try from the root; this is a case for deletions and is achieved
  *   using the NODE_DELETED flag.
  *
- *   iii) the node destruction must be synchronised with the readers,
+ *   iii) the node destruction must be synchronized with the readers,
  *   e.g. by using the Epoch-based reclamation or other techniques.
  *
  * - WRITERS AND LOCKING: Each intermediate node has a spin-lock (which
@@ -87,7 +87,6 @@
  *	https://www.csd.uoc.gr/~hy460/pdf/p650-lehman.pdf
  */
 
-
 #ifdef _KERNEL
 #include 
 #include 
@@ -112,20 +111,19 @@
 #include "utils.h"
 #endif
 
-THMAP_RCSID("$NetBSD: subr_thmap.c,v 1.5 2019/02/04 08:00:27 mrg Exp $");
+THMAP_RCSID("$NetBSD: subr_thmap.c,v 1.5.6.1 2020/05/25 17:19:37 martin Exp $");
 
 /*
  * NetBSD kernel wrappers
  */
 #ifdef _KERNEL
 #define	ASSERT KASSERT
-#define	atomic_thread_fence(x) x
-#define	memory_order_stores membar_producer()
-#define	memory_order_loads membar_consumer()
-#define	atomic_cas_32_p(p, e, n) (atomic_cas_32((p), (e), (n)) == (e))
-#define	atomic_cas_ptr_p(p, e, n) \
-(atomic_cas_ptr((p), (void *)(e), (void *)(n)) == (e))
-#define	atomic_exchange atomic_swap_ptr
+#define	atomic_thread_fence(x) membar_sync()
+#define	atomic_compare_exchange_weak_explicit_32(p, e, n, m1, m2) \
+(atomic_cas_32((p), *(e), (n)) == *(e))
+#define	atomic_compare_exchange_weak_explicit_ptr(p, e, n, m1, m2) \
+(atomic_cas_ptr((p), *(void **)(e), (void *)(n)) == *(void **)(e))
+#define	atomic_exchange_explicit(o, n, m1) atomic_swap_ptr((o), (n))
 #define	murmurhash3 murmurhash2
 #endif
 
@@ -160,6 +158,7 @@ THMAP_RCSID("$NetBSD: subr_thmap.c,v 1.5
  * least significant bit.
  */
 typedef uintptr_t thmap_ptr_t;
+typedef uintptr_t atomic_thmap_ptr_t;			// C11 _Atomic
 
 #define	THMAP_NULL		((thmap_ptr_t)0)
 
@@ -188,9 +187,9 @@ typedef uintptr_t thmap_ptr_t;
  */
 
 typedef struct {
-	uint32_t	state;
-	thmap_ptr_t	parent;
-	thmap_ptr_t	slots[LEVEL_SIZE];
+	uint32_t		state;			// C11 _Atomic
+	thmap_ptr_t		parent;
+	atomic_thmap_ptr_t	slots[LEVEL_SIZE];
 } thmap_inode_t;
 
 #define	THMAP_INODE_LEN	sizeof(thmap_inode_t)
@@ -217,11 +216,11 @@ typedef struct {
 #define	THMAP_ROOT_LEN	(sizeof(thmap_ptr_t) * ROOT_SIZE)
 
 struct thmap {
-	uintptr_t	baseptr;
-	thmap_ptr_t *	root;
-	unsigned	flags;
-	const thmap_ops_t *ops;
-	thmap_gc_t *	gc_list;
+	uintptr_t		baseptr;
+	atomic_thmap_ptr_t *	root;
+	unsigned		flags;
+	const thmap_ops_t *	ops;
+	thmap_gc_t *		gc_list;		// C11 _Atomic
 };
 
 static void	stage_mem_gc(thmap_t *, uintptr_t, size_t);
@@ -253,9 +252,9 @@ static const thmap_ops_t thmap_default_o
 
 #ifdef DIAGNOSTIC
 static inline bool
-node_locked_p(const thmap_inode_t *node)
+node_locked_p(thmap_inode_t *node)
 {
-	return (node->state & NODE_LOCKED) != 0;
+	return (atomic_load_relaxed(>state) & NODE_LOCKED) != 0;
 }
 #endif
 
@@ -265,18 +264,14 @@ lock_node(thmap_inode_t *node)
 	unsigned bcount = SPINLOCK_BACKOFF_MIN;
 	uint32_t s;
 again:
-	s = node->state;
+	s = atomic_load_relaxed(>state);
 	if (s & NODE_LOCKED) {
 		SPINLOCK_BACKOFF(bcount);
 		goto again;
 	}
-	/*
-	 * CAS will issue a full memory fence for us.
-	 *
-	 * WARNING: for optimisations purposes, callers rely on us
-	 * issuing load and store fence
-	 */
-	if (!atomic_cas_32_p(>state, s, s | NODE_LOCKED)) {
+	/* Acquire from prior release in unlock_node.() */
+	if (!atomic_compare_exchange_weak_explicit_32(>state,
+	, s | NODE_LOCKED, memory_order_acquire, memory_order_relaxed)) {
 		bcount = SPINLOCK_BACKOFF_MIN;
 		goto again;
 	}
@@ -285,11 +280,11 @@ again:
 static void
 unlock_node(thmap_inode_t *node)
 {
-	uint32_t s = node->state & ~NODE_LOCKED;
+	uint32_t s = atomic_load_relaxed(>state) & ~NODE_LOCKED;
 
 	ASSERT(node_locked_p(node));
-	atomic_thread_fence(memory_order_stores);
-	node->state = s; // atomic store
+	/* Release to subsequent 

CVS commit: [netbsd-9] src/sys/kern

2020-05-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue May 19 16:24:38 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: vnode_if.c vnode_if.src

Log Message:
Pull up following revision(s) (requested by hannken in ticket #917):

sys/kern/vnode_if.src: revision 1.80
sys/kern/vnode_if.c: revision 1.112

VOP_STRATEGY() may still deadlock with devices.

Change FSTRANS from LAZY to NO.

Regen.


To generate a diff of this commit:
cvs rdiff -u -r1.107.10.1 -r1.107.10.2 src/sys/kern/vnode_if.c
cvs rdiff -u -r1.77.10.1 -r1.77.10.2 src/sys/kern/vnode_if.src

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/vnode_if.c
diff -u src/sys/kern/vnode_if.c:1.107.10.1 src/sys/kern/vnode_if.c:1.107.10.2
--- src/sys/kern/vnode_if.c:1.107.10.1	Tue Oct 15 18:13:55 2019
+++ src/sys/kern/vnode_if.c	Tue May 19 16:24:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vnode_if.c,v 1.107.10.1 2019/10/15 18:13:55 martin Exp $	*/
+/*	$NetBSD: vnode_if.c,v 1.107.10.2 2020/05/19 16:24:38 martin Exp $	*/
 
 /*
  * Warning: DO NOT EDIT! This file is automatically generated!
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vnode_if.c,v 1.107.10.1 2019/10/15 18:13:55 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vnode_if.c,v 1.107.10.2 2020/05/19 16:24:38 martin Exp $");
 
 #include 
 #include 
@@ -1380,11 +1380,11 @@ VOP_STRATEGY(struct vnode *vp,
 	a.a_desc = VDESC(vop_strategy);
 	a.a_vp = vp;
 	a.a_bp = bp;
-	error = vop_pre(vp, , , FST_LAZY);
+	error = vop_pre(vp, , , FST_NO);
 	if (error)
 		return error;
 	error = (VCALL(vp, VOFFSET(vop_strategy), ));
-	vop_post(vp, mp, mpsafe, FST_LAZY);
+	vop_post(vp, mp, mpsafe, FST_NO);
 	return error;
 }
 

Index: src/sys/kern/vnode_if.src
diff -u src/sys/kern/vnode_if.src:1.77.10.1 src/sys/kern/vnode_if.src:1.77.10.2
--- src/sys/kern/vnode_if.src:1.77.10.1	Tue Oct 15 18:12:25 2019
+++ src/sys/kern/vnode_if.src	Tue May 19 16:24:38 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: vnode_if.src,v 1.77.10.1 2019/10/15 18:12:25 martin Exp $
+#	$NetBSD: vnode_if.src,v 1.77.10.2 2020/05/19 16:24:38 martin Exp $
 #
 # Copyright (c) 1992, 1993
 #	The Regents of the University of California.  All rights reserved.
@@ -436,7 +436,7 @@ vop_bmap {
 #% strategy   vp  = = =
 #
 vop_strategy {
-	FSTRANS=LAZY
+	FSTRANS=NO
 	IN struct vnode *vp;
 	IN struct buf *bp;
 };



CVS commit: [netbsd-9] src/sys/kern

2020-05-18 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon May 18 19:05:32 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: kern_time.c

Log Message:
Pull up following revision(s) (requested by maxv in ticket #916):

sys/kern/kern_time.c: revision 1.204

Fix uninitialized memory access. Found by KMSAN.


To generate a diff of this commit:
cvs rdiff -u -r1.197.4.2 -r1.197.4.3 src/sys/kern/kern_time.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_time.c
diff -u src/sys/kern/kern_time.c:1.197.4.2 src/sys/kern/kern_time.c:1.197.4.3
--- src/sys/kern/kern_time.c:1.197.4.2	Wed Sep 11 16:36:13 2019
+++ src/sys/kern/kern_time.c	Mon May 18 19:05:32 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_time.c,v 1.197.4.2 2019/09/11 16:36:13 martin Exp $	*/
+/*	$NetBSD: kern_time.c,v 1.197.4.3 2020/05/18 19:05:32 martin Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2004, 2005, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.197.4.2 2019/09/11 16:36:13 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.197.4.3 2020/05/18 19:05:32 martin Exp $");
 
 #include 
 #include 
@@ -356,8 +356,12 @@ again:
 		struct timespec rmtend;
 		struct timespec t0;
 		struct timespec *t;
+		int err;
+
+		err = clock_gettime1(clock_id, );
+		if (err != 0)
+			return err;
 
-		(void)clock_gettime1(clock_id, );
 		t = (rmt != NULL) ? rmt : 
 		if (flags & TIMER_ABSTIME) {
 			timespecsub(rqt, , t);



CVS commit: [netbsd-9] src/sys/kern

2020-05-18 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon May 18 18:57:32 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: subr_cprng.c

Log Message:
Pull up following revision(s) (requested by nia in ticket #914):

sys/kern/subr_cprng.c: revision 1.37 (via patch, adapted)

Make kern.arandom truncate the output instead of failing with ETOOBIG
when the requested data exceeds 256 bytes in size. The actual size of
the returned data is output to oldlenp.

This matches FreeBSD's behaviour and seems to be more in line with
what software in the wild expects.

"sounds reasonble" - Riastradh


To generate a diff of this commit:
cvs rdiff -u -r1.30.2.3 -r1.30.2.4 src/sys/kern/subr_cprng.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_cprng.c
diff -u src/sys/kern/subr_cprng.c:1.30.2.3 src/sys/kern/subr_cprng.c:1.30.2.4
--- src/sys/kern/subr_cprng.c:1.30.2.3	Thu Apr 30 15:34:06 2020
+++ src/sys/kern/subr_cprng.c	Mon May 18 18:57:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_cprng.c,v 1.30.2.3 2020/04/30 15:34:06 martin Exp $ */
+/*	$NetBSD: subr_cprng.c,v 1.30.2.4 2020/05/18 18:57:31 martin Exp $ */
 
 /*-
  * Copyright (c) 2011-2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.30.2.3 2020/04/30 15:34:06 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.30.2.4 2020/05/18 18:57:31 martin Exp $");
 
 #include 
 #include 
@@ -551,7 +551,7 @@ sysctl_kern_arnd(SYSCTLFN_ARGS)
 		return 0;
 	default:
 		if (*oldlenp > 256) {
-			return E2BIG;
+			*oldlenp = 256;
 		}
 		RUN_ONCE(_prng_once, makeprng);
 		v = kmem_alloc(*oldlenp, KM_SLEEP);



CVS commit: [netbsd-9] src/sys/kern

2020-05-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue May  5 20:12:37 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: uipc_sem.c

Log Message:
Pull up following revision(s) (requested by maya in ticket #888):

sys/kern/uipc_sem.c: revision 1.59

Release the collision if we find one.

Candidate fix for:
panic: lock error: Mutex: mutex_vector_enter,542: locking against myself: lock 
0x8f611abd37e0 cpu 8 lwp 0x8f60a3c6a040
cpu8: Begin traceback...
vpanic() at netbsd:vpanic+0x178
snprintf() at netbsd:snprintf
lockdebug_abort() at netbsd:lockdebug_abort+0xe6
mutex_vector_enter() at netbsd:mutex_vector_enter+0x3c1
ksem_close_fop() at netbsd:ksem_close_fop+0x17
closef() at netbsd:closef+0x69
fd_free() at netbsd:fd_free+0x101
exit1() at netbsd:exit1+0x118
sys_exit() at netbsd:sys_exit+0x3d
syscall() at netbsd:syscall+0x299

Would be nice to have an automatic test for this.  Since semids are
only 24 bits, we only need to create a few thousand of them to have a
high probability of collision.  Maybe we should bump default semmax
while here...


To generate a diff of this commit:
cvs rdiff -u -r1.55.4.1 -r1.55.4.2 src/sys/kern/uipc_sem.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_sem.c
diff -u src/sys/kern/uipc_sem.c:1.55.4.1 src/sys/kern/uipc_sem.c:1.55.4.2
--- src/sys/kern/uipc_sem.c:1.55.4.1	Wed Dec 18 20:20:17 2019
+++ src/sys/kern/uipc_sem.c	Tue May  5 20:12:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_sem.c,v 1.55.4.1 2019/12/18 20:20:17 martin Exp $	*/
+/*	$NetBSD: uipc_sem.c,v 1.55.4.2 2020/05/05 20:12:37 martin Exp $	*/
 
 /*-
  * Copyright (c) 2011, 2019 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.55.4.1 2019/12/18 20:20:17 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.55.4.2 2020/05/05 20:12:37 martin Exp $");
 
 #include 
 #include 
@@ -110,6 +110,7 @@ static kauth_listener_t	ksem_listener;
 static int		ksem_sysinit(void);
 static int		ksem_sysfini(bool);
 static int		ksem_modcmd(modcmd_t, void *);
+static void		ksem_release(ksem_t *, int);
 static int		ksem_close_fop(file_t *);
 static int		ksem_stat_fop(file_t *, struct stat *);
 static int		ksem_read_fop(file_t *, off_t *, struct uio *,
@@ -366,6 +367,7 @@ ksem_lookup_pshared(intptr_t id)
 static void
 ksem_alloc_pshared_id(ksem_t *ksem)
 {
+	ksem_t *ksem0;
 	uint32_t try;
 
 	KASSERT(ksem->ks_pshared_proc != NULL);
@@ -375,10 +377,11 @@ ksem_alloc_pshared_id(ksem_t *ksem)
 		try = (cprng_fast32() & ~KSEM_MARKER_MASK) |
 		KSEM_PSHARED_MARKER;
 
-		if (ksem_lookup_pshared_locked(try) == NULL) {
+		if ((ksem0 = ksem_lookup_pshared_locked(try)) == NULL) {
 			/* Got it! */
 			break;
 		}
+		ksem_release(ksem0, -1);
 	}
 	ksem->ks_pshared_id = try;
 	u_long bucket = KSEM_PSHARED_HASH(ksem->ks_pshared_id);



CVS commit: [netbsd-9] src/sys/kern

2020-05-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri May  1 11:54:53 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: vfs_mount.c

Log Message:
Pull up following revision(s) (requested by hannken in ticket #881):

sys/kern/vfs_mount.c: revision 1.82

Undo Rev. 1.79, it breaks root-on-raid where it destroys the component
disks before the raid:

 forcefully unmounting / (/dev/raid0a)...
 sd1: detached
 sd0: detached
 raid0: cache flush to component /dev/sd0a failed.
 raid0: cache flush to component /dev/sd1a failed.
 fatal page fault in supervisor mode
 Stopped in pid 2356.2356 (reboot) at netbsd:sdstrategy+0x36

Reopens PR kern/54969: Disk cache is no longer flushed on shutdown


To generate a diff of this commit:
cvs rdiff -u -r1.70.4.1 -r1.70.4.2 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.70.4.1 src/sys/kern/vfs_mount.c:1.70.4.2
--- src/sys/kern/vfs_mount.c:1.70.4.1	Wed Apr 22 18:05:11 2020
+++ src/sys/kern/vfs_mount.c	Fri May  1 11:54:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.70.4.1 2020/04/22 18:05:11 martin Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.70.4.2 2020/05/01 11:54:53 martin Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.70.4.1 2020/04/22 18:05:11 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.70.4.2 2020/05/01 11:54:53 martin Exp $");
 
 #include 
 #include 
@@ -114,8 +114,6 @@ static struct vnode *vfs_vnode_iterator_
 /* Root filesystem. */
 vnode_t *			rootvnode;
 
-extern struct mount		*dead_rootmount;
-
 /* Mounted filesystem list. */
 static TAILQ_HEAD(mountlist, mountlist_entry) mountlist;
 static kmutex_t			mountlist_lock;
@@ -1002,7 +1000,6 @@ bool
 vfs_unmountall1(struct lwp *l, bool force, bool verbose)
 {
 	struct mount *mp;
-	mount_iterator_t *iter;
 	bool any_error = false, progress = false;
 	uint64_t gen;
 	int error;
@@ -1037,24 +1034,6 @@ vfs_unmountall1(struct lwp *l, bool forc
 	if (any_error && verbose) {
 		printf("WARNING: some file systems would not unmount\n");
 	}
-
-	/* If the mountlist is empty destroy anonymous device vnodes. */
-	mountlist_iterator_init();
-	if (mountlist_iterator_next(iter) == NULL) {
-		struct vnode_iterator *marker;
-		vnode_t *vp;
-
-		vfs_vnode_iterator_init(dead_rootmount, );
-		while ((vp = vfs_vnode_iterator_next(marker, NULL, NULL))) {
-			if (vp->v_type == VCHR || vp->v_type == VBLK)
-vgone(vp);
-			else
-vrele(vp);
-		}
-		vfs_vnode_iterator_destroy(marker);
-	}
-	mountlist_iterator_destroy(iter);
-
 	return progress;
 }
 



CVS commit: [netbsd-9] src/sys/kern

2020-04-30 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Apr 30 15:34:06 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: subr_cprng.c

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #874):

sys/kern/subr_cprng.c: revision 1.34

Disable rngtest on output of cprng_strong.

We already do a self-test for correctenss of Hash_DRBG output;
applying rngtest to it does nothing but give everyone warning fatigue
about spurious rngtest failures.


To generate a diff of this commit:
cvs rdiff -u -r1.30.2.2 -r1.30.2.3 src/sys/kern/subr_cprng.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_cprng.c
diff -u src/sys/kern/subr_cprng.c:1.30.2.2 src/sys/kern/subr_cprng.c:1.30.2.3
--- src/sys/kern/subr_cprng.c:1.30.2.2	Mon Nov 25 17:00:22 2019
+++ src/sys/kern/subr_cprng.c	Thu Apr 30 15:34:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_cprng.c,v 1.30.2.2 2019/11/25 17:00:22 martin Exp $ */
+/*	$NetBSD: subr_cprng.c,v 1.30.2.3 2020/04/30 15:34:06 martin Exp $ */
 
 /*-
  * Copyright (c) 2011-2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.30.2.2 2019/11/25 17:00:22 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.30.2.3 2020/04/30 15:34:06 martin Exp $");
 
 #include 
 #include 
@@ -49,9 +49,6 @@ __KERNEL_RCSID(0, "$NetBSD: subr_cprng.c
 #include 
 #include 
 #include 
-#if DIAGNOSTIC
-#include 
-#endif
 
 #include 
 
@@ -66,9 +63,6 @@ static void	cprng_strong_generate(struct
 static void	cprng_strong_reseed(struct cprng_strong *);
 static void	cprng_strong_reseed_from(struct cprng_strong *, const void *,
 		size_t, bool);
-#if DIAGNOSTIC
-static void	cprng_strong_rngtest(struct cprng_strong *);
-#endif
 
 static rndsink_callback_t	cprng_strong_rndsink_callback;
 
@@ -482,48 +476,8 @@ cprng_strong_reseed_from(struct cprng_st
 		/* XXX Fix nist_hash_drbg API so this can't happen.  */
 		panic("cprng %s: NIST Hash_DRBG reseed failed",
 		cprng->cs_name);
-
-#if DIAGNOSTIC
-	cprng_strong_rngtest(cprng);
-#endif
 }
 
-#if DIAGNOSTIC
-/*
- * Generate some output and apply a statistical RNG test to it.
- */
-static void
-cprng_strong_rngtest(struct cprng_strong *cprng)
-{
-
-	KASSERT(mutex_owned(>cs_lock));
-
-	/* XXX Switch to a pool cache instead?  */
-	rngtest_t *const rt = kmem_intr_alloc(sizeof(*rt), KM_NOSLEEP);
-	if (rt == NULL)
-		/* XXX Warn?  */
-		return;
-
-	(void)strlcpy(rt->rt_name, cprng->cs_name, sizeof(rt->rt_name));
-
-	if (nist_hash_drbg_generate(>cs_drbg, rt->rt_b,
-		sizeof(rt->rt_b), NULL, 0))
-		panic("cprng %s: NIST Hash_DRBG failed after reseed",
-		cprng->cs_name);
-
-	if (rngtest(rt)) {
-		printf("cprng %s: failed statistical RNG test\n",
-		cprng->cs_name);
-		/* XXX Not clear that this does any good...  */
-		cprng->cs_ready = false;
-		rndsink_schedule(cprng->cs_rndsink);
-	}
-
-	explicit_memset(rt, 0, sizeof(*rt)); /* paranoia */
-	kmem_intr_free(rt, sizeof(*rt));
-}
-#endif
-
 /*
  * Feed entropy from an rndsink request into the CPRNG for which the
  * request was issued.



CVS commit: [netbsd-9] src/sys/kern

2020-04-22 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Apr 22 18:05:11 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: vfs_mount.c

Log Message:
Pull up following revision(s) (requested by gson in ticket #839):

sys/kern/vfs_mount.c: revision 1.79

Destroy anonymous device vnodes on reboot once the last file system
got unmounted and the mount list is empty.

PR kern/54969: Disk cache is no longer flushed on shutdown


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.70.4.1 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.70 src/sys/kern/vfs_mount.c:1.70.4.1
--- src/sys/kern/vfs_mount.c:1.70	Wed Feb 20 10:08:37 2019
+++ src/sys/kern/vfs_mount.c	Wed Apr 22 18:05:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_mount.c,v 1.70 2019/02/20 10:08:37 hannken Exp $	*/
+/*	$NetBSD: vfs_mount.c,v 1.70.4.1 2020/04/22 18:05:11 martin Exp $	*/
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.70 2019/02/20 10:08:37 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.70.4.1 2020/04/22 18:05:11 martin Exp $");
 
 #include 
 #include 
@@ -114,6 +114,8 @@ static struct vnode *vfs_vnode_iterator_
 /* Root filesystem. */
 vnode_t *			rootvnode;
 
+extern struct mount		*dead_rootmount;
+
 /* Mounted filesystem list. */
 static TAILQ_HEAD(mountlist, mountlist_entry) mountlist;
 static kmutex_t			mountlist_lock;
@@ -1000,6 +1002,7 @@ bool
 vfs_unmountall1(struct lwp *l, bool force, bool verbose)
 {
 	struct mount *mp;
+	mount_iterator_t *iter;
 	bool any_error = false, progress = false;
 	uint64_t gen;
 	int error;
@@ -1034,6 +1037,24 @@ vfs_unmountall1(struct lwp *l, bool forc
 	if (any_error && verbose) {
 		printf("WARNING: some file systems would not unmount\n");
 	}
+
+	/* If the mountlist is empty destroy anonymous device vnodes. */
+	mountlist_iterator_init();
+	if (mountlist_iterator_next(iter) == NULL) {
+		struct vnode_iterator *marker;
+		vnode_t *vp;
+
+		vfs_vnode_iterator_init(dead_rootmount, );
+		while ((vp = vfs_vnode_iterator_next(marker, NULL, NULL))) {
+			if (vp->v_type == VCHR || vp->v_type == VBLK)
+vgone(vp);
+			else
+vrele(vp);
+		}
+		vfs_vnode_iterator_destroy(marker);
+	}
+	mountlist_iterator_destroy(iter);
+
 	return progress;
 }
 



CVS commit: [netbsd-9] src/sys/kern

2020-03-08 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Mar  8 11:21:29 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: kern_mutex.c

Log Message:
Pull up following revision(s) (requested by chs in ticket #768):

sys/kern/kern_mutex.c: revision 1.90

split an "a && b" assertion into two so it's clear in the dump which condition
was not true even if both are true by the time the dump is written.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.79.2.1 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.79 src/sys/kern/kern_mutex.c:1.79.2.1
--- src/sys/kern/kern_mutex.c:1.79	Thu May  9 05:00:31 2019
+++ src/sys/kern/kern_mutex.c	Sun Mar  8 11:21:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_mutex.c,v 1.79 2019/05/09 05:00:31 ozaki-r Exp $	*/
+/*	$NetBSD: kern_mutex.c,v 1.79.2.1 2020/03/08 11:21:29 martin Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
 #define	__MUTEX_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.79 2019/05/09 05:00:31 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.79.2.1 2020/03/08 11:21:29 martin Exp $");
 
 #include 
 #include 
@@ -397,8 +397,8 @@ mutex_destroy(kmutex_t *mtx)
 {
 
 	if (MUTEX_ADAPTIVE_P(mtx)) {
-		MUTEX_ASSERT(mtx, !MUTEX_OWNED(mtx->mtx_owner) &&
-		!MUTEX_HAS_WAITERS(mtx));
+		MUTEX_ASSERT(mtx, !MUTEX_OWNED(mtx->mtx_owner));
+		MUTEX_ASSERT(mtx, !MUTEX_HAS_WAITERS(mtx));
 	} else {
 		MUTEX_ASSERT(mtx, !MUTEX_SPINBIT_LOCKED_P(mtx));
 	}



CVS commit: [netbsd-9] src/sys/kern

2020-03-08 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Mar  8 11:04:43 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: subr_pool.c

Log Message:
Pull up following revision(s) (requested by chs in ticket #766):

sys/kern/subr_pool.c: revision 1.265

fix assertions about when it is ok for pool_get() to return NULL.


To generate a diff of this commit:
cvs rdiff -u -r1.252.2.2 -r1.252.2.3 src/sys/kern/subr_pool.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_pool.c
diff -u src/sys/kern/subr_pool.c:1.252.2.2 src/sys/kern/subr_pool.c:1.252.2.3
--- src/sys/kern/subr_pool.c:1.252.2.2	Sun Sep  1 10:56:00 2019
+++ src/sys/kern/subr_pool.c	Sun Mar  8 11:04:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_pool.c,v 1.252.2.2 2019/09/01 10:56:00 martin Exp $	*/
+/*	$NetBSD: subr_pool.c,v 1.252.2.3 2020/03/08 11:04:43 martin Exp $	*/
 
 /*
  * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008, 2010, 2014, 2015, 2018
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.252.2.2 2019/09/01 10:56:00 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.252.2.3 2020/03/08 11:04:43 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1062,7 +1062,7 @@ pool_get(struct pool *pp, int flags)
 
 			pp->pr_nfail++;
 			mutex_exit(>pr_lock);
-			KASSERT((flags & (PR_WAITOK|PR_NOWAIT)) == PR_NOWAIT);
+			KASSERT((flags & (PR_NOWAIT|PR_LIMITFAIL)) != 0);
 			return NULL;
 		}
 
@@ -2422,7 +2422,7 @@ pool_cache_get_slow(pool_cache_cpu_t *cc
 	object = pool_get(>pc_pool, flags);
 	*objectp = object;
 	if (__predict_false(object == NULL)) {
-		KASSERT((flags & (PR_WAITOK|PR_NOWAIT)) == PR_NOWAIT);
+		KASSERT((flags & (PR_NOWAIT|PR_LIMITFAIL)) != 0);
 		return false;
 	}
 



CVS commit: [netbsd-9] src/sys/kern

2020-03-03 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Mar  3 18:51:03 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: files.kern

Log Message:
Pull up following revision(s) (requested by rin in ticket #754):

sys/kern/files.kern: revision 1.44

Include kern_crashme.c in non-DEBUG kernels.
This is useful for simulating crashes in production to test failover.


To generate a diff of this commit:
cvs rdiff -u -r1.34.4.1 -r1.34.4.2 src/sys/kern/files.kern

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/files.kern
diff -u src/sys/kern/files.kern:1.34.4.1 src/sys/kern/files.kern:1.34.4.2
--- src/sys/kern/files.kern:1.34.4.1	Tue Jan 21 15:33:33 2020
+++ src/sys/kern/files.kern	Tue Mar  3 18:51:03 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.kern,v 1.34.4.1 2020/01/21 15:33:33 martin Exp $
+#	$NetBSD: files.kern,v 1.34.4.2 2020/03/03 18:51:03 martin Exp $
 
 #
 # kernel sources
@@ -77,7 +77,7 @@ file	kern/kern_rwlock.c		kern
 file	kern/kern_rwlock_obj.c		kern
 file	kern/kern_scdebug.c		kern
 file	kern/kern_sdt.c			kdtrace_hooks
-file	kern/kern_crashme.c		debug
+file	kern/kern_crashme.c		kern
 file	kern/kern_sig.c			kern
 file	kern/kern_sleepq.c		kern
 file	kern/kern_softint.c		kern



CVS commit: [netbsd-9] src/sys/kern

2020-02-25 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Feb 25 19:10:52 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: uipc_socket.c

Log Message:
Pull up following revision(s) (requested by maxv in ticket #720):

sys/kern/uipc_socket.c: revision 1.288

Zero out 'tv', to prevent uninitialized bytes in its padding from leaking
to userland. Found by kMSan.


To generate a diff of this commit:
cvs rdiff -u -r1.281.2.1 -r1.281.2.2 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.281.2.1 src/sys/kern/uipc_socket.c:1.281.2.2
--- src/sys/kern/uipc_socket.c:1.281.2.1	Mon Oct 21 20:06:17 2019
+++ src/sys/kern/uipc_socket.c	Tue Feb 25 19:10:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_socket.c,v 1.281.2.1 2019/10/21 20:06:17 martin Exp $	*/
+/*	$NetBSD: uipc_socket.c,v 1.281.2.2 2020/02/25 19:10:51 martin Exp $	*/
 
 /*
  * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.281.2.1 2019/10/21 20:06:17 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.281.2.2 2020/02/25 19:10:51 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1990,6 +1990,7 @@ sogetopt1(struct socket *so, struct sock
 		optval = (opt == SO_SNDTIMEO ?
 		 so->so_snd.sb_timeo : so->so_rcv.sb_timeo);
 
+		memset(, 0, sizeof(tv));
 		tv.tv_sec = optval / hz;
 		tv.tv_usec = (optval % hz) * tick;
 



CVS commit: [netbsd-9] src/sys/kern

2020-02-12 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Feb 12 19:35:31 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: kern_lwp.c

Log Message:
Pull up following revision(s) (requested by maya in ticket #697):

sys/kern/kern_lwp.c: revision 1.224
sys/kern/kern_lwp.c: revision 1.225

Preserve pcu(9) state in fork.

There should perhaps be a pcu_fork operation to keep this factored
neatly but this will be simpler to pull up.

In practical terms, this may not affect most architecture that use
pcu(9) -- alpha, arm32, mips, powerpc, riscv -- but it does affect
aarch64, in which v8-v15 are callee-saves, and GCC actually takes
advantage of them, and for more than just floating-point data too.

XXX pullup

fix compilation failure for arches without l_pcu_valid
ok riastradh


To generate a diff of this commit:
cvs rdiff -u -r1.202.2.2 -r1.202.2.3 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.202.2.2 src/sys/kern/kern_lwp.c:1.202.2.3
--- src/sys/kern/kern_lwp.c:1.202.2.2	Tue Oct 15 19:01:06 2019
+++ src/sys/kern/kern_lwp.c	Wed Feb 12 19:35:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.202.2.2 2019/10/15 19:01:06 martin Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.202.2.3 2020/02/12 19:35:31 martin Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -211,7 +211,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.202.2.2 2019/10/15 19:01:06 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.202.2.3 2020/02/12 19:35:31 martin Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -897,6 +897,9 @@ lwp_create(lwp_t *l1, proc_t *p2, vaddr_
 	 * the MD cpu_lwp_fork() can copy the saved state to the new LWP.
 	 */
 	pcu_save_all(l1);
+#if PCU_UNIT_COUNT > 0
+	l2->l_pcu_valid = l1->l_pcu_valid;
+#endif
 
 	uvm_lwp_setuarea(l2, uaddr);
 	uvm_lwp_fork(l1, l2, stack, stacksize, func, (arg != NULL) ? arg : l2);



CVS commit: [netbsd-9] src/sys/kern

2020-01-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jan 21 15:33:33 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: files.kern

Log Message:
Apply patch, requested by pgoyette in ticket #633:

PR kern/54874: fix load failure of the exec_aout kernel module.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.34.4.1 src/sys/kern/files.kern

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/files.kern
diff -u src/sys/kern/files.kern:1.34 src/sys/kern/files.kern:1.34.4.1
--- src/sys/kern/files.kern:1.34	Thu Apr  4 20:19:07 2019
+++ src/sys/kern/files.kern	Tue Jan 21 15:33:33 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.kern,v 1.34 2019/04/04 20:19:07 christos Exp $
+#	$NetBSD: files.kern,v 1.34.4.1 2020/01/21 15:33:33 martin Exp $
 
 #
 # kernel sources
@@ -16,7 +16,8 @@ file	kern/bufq_readprio.c		bufq_readprio
 file	kern/compat_stub.c		kern
 file	kern/core_elf32.c		exec_elf32
 file	kern/core_elf64.c		exec_elf64
-file	kern/core_netbsd.c		exec_aout | exec_coff | exec_ecoff
+file	kern/core_netbsd.c		exec_aout | exec_coff | exec_ecoff |
+	modular
 file	kern/cnmagic.c			kern
 file	kern/exec_aout.c		exec_aout
 file	kern/exec_ecoff.c		exec_ecoff



CVS commit: [netbsd-9] src/sys/kern

2020-01-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jan  7 11:54:58 UTC 2020

Modified Files:
src/sys/kern [netbsd-9]: kern_ksyms.c

Log Message:
Pull up following revision(s) (requested by pgoyette in ticket #609):

sys/kern/kern_ksyms.c: revision 1.88

When reading from /dev/ksyms we need to skip over entries that have
been marked as sd_gone.  Otherwise we might try to uiomove() data from
memory that has been unmapped, resulting in EFAULT.

XXX This (along with other pre-existing checks st->sd_gone) is still
racy, but it's an improvement over current code.  Ideally we would
make a complete copy of the symbol table when we open /dev/ksyms so
we could ignore any changes that occur.

ad@ says "good enough for now"

XXX Pullup to -9 and -8


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.87.8.1 src/sys/kern/kern_ksyms.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_ksyms.c
diff -u src/sys/kern/kern_ksyms.c:1.87 src/sys/kern/kern_ksyms.c:1.87.8.1
--- src/sys/kern/kern_ksyms.c:1.87	Sat Nov  4 22:17:55 2017
+++ src/sys/kern/kern_ksyms.c	Tue Jan  7 11:54:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_ksyms.c,v 1.87 2017/11/04 22:17:55 christos Exp $	*/
+/*	$NetBSD: kern_ksyms.c,v 1.87.8.1 2020/01/07 11:54:57 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.87 2017/11/04 22:17:55 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.87.8.1 2020/01/07 11:54:57 martin Exp $");
 
 #if defined(_KERNEL) && defined(_KERNEL_OPT)
 #include "opt_copy_symtab.h"
@@ -765,9 +765,9 @@ ksyms_modunload(const char *name)
 		if (strcmp(name, st->sd_name) != 0)
 			continue;
 		st->sd_gone = true;
+		ksyms_sizes_calc();
 		if (!ksyms_isopen) {
 			TAILQ_REMOVE(_symtabs, st, sd_queue);
-			ksyms_sizes_calc();
 			kmem_free(st->sd_nmap,
   st->sd_nmapsize * sizeof(uint32_t));
 			kmem_free(st, sizeof(*st));
@@ -856,6 +856,8 @@ ksyms_sizes_calc(void)
 
 	ksyms_symsz = ksyms_strsz = 0;
 	TAILQ_FOREACH(st, _symtabs, sd_queue) {
+		if (__predict_false(st->sd_gone))
+			continue;
 		delta = ksyms_strsz - st->sd_usroffset;
 		if (delta != 0) {
 			for (i = 0; i < st->sd_symsize/sizeof(Elf_Sym); i++)
@@ -1034,6 +1036,8 @@ ksymsread(dev_t dev, struct uio *uio, in
 	 */
 	filepos = sizeof(struct ksyms_hdr);
 	TAILQ_FOREACH(st, _symtabs, sd_queue) {
+		if (__predict_false(st->sd_gone))
+			continue;
 		if (uio->uio_resid == 0)
 			return 0;
 		if (uio->uio_offset <= st->sd_symsize + filepos) {
@@ -1052,6 +1056,8 @@ ksymsread(dev_t dev, struct uio *uio, in
 	KASSERT(filepos == sizeof(struct ksyms_hdr) +
 	ksyms_hdr.kh_shdr[SYMTAB].sh_size);
 	TAILQ_FOREACH(st, _symtabs, sd_queue) {
+		if (__predict_false(st->sd_gone))
+			continue;
 		if (uio->uio_resid == 0)
 			return 0;
 		if (uio->uio_offset <= st->sd_strsize + filepos) {



CVS commit: [netbsd-9] src/sys/kern

2019-12-12 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Dec 12 20:43:08 UTC 2019

Modified Files:
src/sys/kern [netbsd-9]: kern_resource.c kern_softint.c

Log Message:
Pull up following revision(s) (requested by ad in ticket #546):

sys/kern/kern_resource.c: revision 1.183
sys/kern/kern_softint.c: revision 1.49

calcru: ignore running softints, unless softint_timing is on.
Fixes crazy times reported for proc0.


To generate a diff of this commit:
cvs rdiff -u -r1.182 -r1.182.4.1 src/sys/kern/kern_resource.c
cvs rdiff -u -r1.47 -r1.47.2.1 src/sys/kern/kern_softint.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_resource.c
diff -u src/sys/kern/kern_resource.c:1.182 src/sys/kern/kern_resource.c:1.182.4.1
--- src/sys/kern/kern_resource.c:1.182	Fri Apr  5 00:33:21 2019
+++ src/sys/kern/kern_resource.c	Thu Dec 12 20:43:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_resource.c,v 1.182 2019/04/05 00:33:21 mlelstv Exp $	*/
+/*	$NetBSD: kern_resource.c,v 1.182.4.1 2019/12/12 20:43:08 martin Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.182 2019/04/05 00:33:21 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.182.4.1 2019/12/12 20:43:08 martin Exp $");
 
 #include 
 #include 
@@ -506,7 +506,8 @@ calcru(struct proc *p, struct timeval *u
 	LIST_FOREACH(l, >p_lwps, l_sibling) {
 		lwp_lock(l);
 		bintime_add(, >l_rtime);
-		if ((l->l_pflag & LP_RUNNING) != 0) {
+		if ((l->l_pflag & LP_RUNNING) != 0 &&
+		(l->l_pflag & (LP_INTR | LP_TIMEINTR)) != LP_INTR) {
 			struct bintime diff;
 			/*
 			 * Adjust for the current time slice.  This is
@@ -516,6 +517,7 @@ calcru(struct proc *p, struct timeval *u
 			 * error.
 			 */
 			binuptime();
+			membar_consumer(); /* for softint_dispatch() */
 			bintime_sub(, >l_stime);
 			bintime_add(, );
 		}

Index: src/sys/kern/kern_softint.c
diff -u src/sys/kern/kern_softint.c:1.47 src/sys/kern/kern_softint.c:1.47.2.1
--- src/sys/kern/kern_softint.c:1.47	Fri May 17 03:34:26 2019
+++ src/sys/kern/kern_softint.c	Thu Dec 12 20:43:08 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: kern_softint.c,v 1.47 2019/05/17 03:34:26 ozaki-r Exp $	*/
+/*	$NetBSD: kern_softint.c,v 1.47.2.1 2019/12/12 20:43:08 martin Exp $	*/
 
 /*-
- * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 2007, 2008, 2019 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -170,7 +170,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.47 2019/05/17 03:34:26 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.47.2.1 2019/12/12 20:43:08 martin Exp $");
 
 #include 
 #include 
@@ -868,14 +868,16 @@ softint_dispatch(lwp_t *pinned, int s)
 	timing = (softint_timing ? LP_TIMEINTR : 0);
 	l->l_switchto = pinned;
 	l->l_stat = LSONPROC;
-	l->l_pflag |= (LP_RUNNING | timing);
 
 	/*
 	 * Dispatch the interrupt.  If softints are being timed, charge
 	 * for it.
 	 */
-	if (timing)
+	if (timing) {
 		binuptime(>l_stime);
+		membar_producer();	/* for calcru */
+	}
+	l->l_pflag |= (LP_RUNNING | timing);
 	softint_execute(si, l, s);
 	if (timing) {
 		binuptime();