CVS commit: src/sys/arch/sh3/include

2023-09-02 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Sat Sep  2 21:54:55 UTC 2023

Modified Files:
src/sys/arch/sh3/include: db_machdep.h

Log Message:
remove (db_addr_t) cast in sh3 PC_REGS(regs) definition.

Fixes KGDB build option for SH3/4 code.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/sh3/include/db_machdep.h

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

Modified files:

Index: src/sys/arch/sh3/include/db_machdep.h
diff -u src/sys/arch/sh3/include/db_machdep.h:1.17 src/sys/arch/sh3/include/db_machdep.h:1.18
--- src/sys/arch/sh3/include/db_machdep.h:1.17	Mon Nov  6 03:47:48 2017
+++ src/sys/arch/sh3/include/db_machdep.h	Sat Sep  2 21:54:55 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_machdep.h,v 1.17 2017/11/06 03:47:48 christos Exp $	*/
+/*	$NetBSD: db_machdep.h,v 1.18 2023/09/02 21:54:55 andvar Exp $	*/
 
 /*
  * Mach Operating System
@@ -46,7 +46,7 @@ typedef struct trapframe db_regs_t;
 extern db_regs_t	ddb_regs;	/* register state */
 #define	DDB_REGS	(_regs)
 
-#define	PC_REGS(regs)	((db_addr_t)(regs)->tf_spc)
+#define	PC_REGS(regs)	((regs)->tf_spc)
 #define PC_ADVANCE(regs) ((regs)->tf_spc += BKPT_SIZE)
 
 #define	BKPT_ADDR(addr)	(addr)		/* breakpoint address */



CVS commit: src/sys/arch/sh3/include

2023-09-02 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Sat Sep  2 21:54:55 UTC 2023

Modified Files:
src/sys/arch/sh3/include: db_machdep.h

Log Message:
remove (db_addr_t) cast in sh3 PC_REGS(regs) definition.

Fixes KGDB build option for SH3/4 code.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/sh3/include/db_machdep.h

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



CVS commit: src/sys/compat/netbsd32

2023-09-02 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Sep  2 21:11:54 UTC 2023

Modified Files:
src/sys/compat/netbsd32: netbsd32_epoll.c

Log Message:
redo previous: use same variable type for the interator as the comparison


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/compat/netbsd32/netbsd32_epoll.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/compat/netbsd32/netbsd32_epoll.c
diff -u src/sys/compat/netbsd32/netbsd32_epoll.c:1.4 src/sys/compat/netbsd32/netbsd32_epoll.c:1.5
--- src/sys/compat/netbsd32/netbsd32_epoll.c:1.4	Wed Aug 30 22:15:06 2023
+++ src/sys/compat/netbsd32/netbsd32_epoll.c	Sat Sep  2 21:11:54 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_epoll.c,v 1.4 2023/08/30 22:15:06 mrg Exp $	*/
+/*	$NetBSD: netbsd32_epoll.c,v 1.5 2023/09/02 21:11:54 mrg Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause
@@ -28,7 +28,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_epoll.c,v 1.4 2023/08/30 22:15:06 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_epoll.c,v 1.5 2023/09/02 21:11:54 mrg Exp $");
 
 #include 
 #include 
@@ -135,7 +135,7 @@ netbsd32_epoll_pwait2(struct lwp *l,
 	struct netbsd32_epoll_event *events32 =
 	kmem_alloc(*retval * sizeof(*events32), KM_SLEEP);
 
-	for (unsigned i = 0; i < *retval; i++)
+	for (register_t i = 0; i < *retval; i++)
 		netbsd32_from_epoll_event([i], [i]);
 
 	error = copyout(events, SCARG_P32(uap, events),



CVS commit: src/sys/compat/netbsd32

2023-09-02 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Sep  2 21:11:54 UTC 2023

Modified Files:
src/sys/compat/netbsd32: netbsd32_epoll.c

Log Message:
redo previous: use same variable type for the interator as the comparison


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/compat/netbsd32/netbsd32_epoll.c

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



CVS commit: src/crypto/external/bsd/openssl/dist/crypto

2023-09-02 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Sep  2 20:07:32 UTC 2023

Modified Files:
src/crypto/external/bsd/openssl/dist/crypto: sparccpuid.S

Log Message:
fix SPARC v8/v9 detection code.

this code uses a trick where the encoding on both v8 and v9 are
the same, and are not illegal instructions, but that the v9 one
has a detectable difference than v8.

the idea is that we perform a "subcc" (set condition codes) which
sets "%ccr" on v9, which is an unimplemented "%asr2" on v8, then
we read %ccr (v9) or %asr2 (v8), which will always be 0x99 on v9,
and .. is non-trapping but impleentation defined on v8.

for many implementations this returns the value of the %y reg.

as nothing actually sets %y in this path, it remains the value it
was most recently set to by something (anything), and if it just
happens to be 0x99 then the v9 paths will be taken on v8.

fix this by clearing the %y register before the potential read.

fixes PR port-sparc/57594.  tested on ss20 and in qemu.  this
version of the patch has been submitted upstream.

XXX: pullup-10, pullup-9, pullup-8.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 \
src/crypto/external/bsd/openssl/dist/crypto/sparccpuid.S

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

Modified files:

Index: src/crypto/external/bsd/openssl/dist/crypto/sparccpuid.S
diff -u src/crypto/external/bsd/openssl/dist/crypto/sparccpuid.S:1.10 src/crypto/external/bsd/openssl/dist/crypto/sparccpuid.S:1.11
--- src/crypto/external/bsd/openssl/dist/crypto/sparccpuid.S:1.10	Sun May  7 18:40:16 2023
+++ src/crypto/external/bsd/openssl/dist/crypto/sparccpuid.S	Sat Sep  2 20:07:32 2023
@@ -47,10 +47,14 @@ OPENSSL_wipe_cpu:
 	subcc	%g0,1,%o0
 	! Following is V9 "rd %ccr,%o0" instruction. However! V8
 	! specification says that it ("rd %asr2,%o0" in V8 terms) does
-	! not cause illegal_instruction trap. It therefore can be used
-	! to determine if the CPU the code is executing on is V8- or
-	! V9-compliant, as V9 returns a distinct value of 0x99,
-	! "negative" and "borrow" bits set in both %icc and %xcc.
+	! not cause illegal_instruction trap, however it may read from
+	! the %y register. It therefore can be used to determine if the
+	! CPU the code is executing on is V8- or V9-compliant, as V9
+	! returns a distinct value of 0x99, "negative" and "borrow"
+	! bits set in both %icc and %xcc. The %y register needs to be
+	! set away from 0x99 to avoid false-positives matches.
+	! 
+	wr	0, %y
 	.word	0x91408000	!rd	%ccr,%o0
 	cmp	%o0,0x99
 	bne	.v8
@@ -178,6 +182,7 @@ walk_reg_wins:
 OPENSSL_atomic_add:
 #ifndef ABI64
 	subcc	%g0,1,%o2
+	wr	0, %y
 	.word	0x95408000	!rd	%ccr,%o2, see comment above
 	cmp	%o2,0x99
 	be	.v9
@@ -226,7 +231,8 @@ OPENSSL_atomic_add:
 .align	32
 _sparcv9_rdtick:
 	subcc	%g0,1,%o0
-	.word	0x91408000	!rd	%ccr,%o0
+	wr	0, %y
+	.word	0x91408000	!rd	%ccr,%o0, see comment above
 	cmp	%o0,0x99
 	bne	.notick
 	xor	%o0,%o0,%o0
@@ -388,7 +394,8 @@ OPENSSL_cleanse:
 #ifndef ABI64
 	subcc	%g0,1,%g1
 	! see above for explanation
-	.word	0x83408000	!rd	%ccr,%g1
+	wr	0, %y
+	.word	0x83408000	!rd	%ccr,%g1, see comment above
 	cmp	%g1,0x99
 	bne	.v8lot
 	nop



CVS commit: src/crypto/external/bsd/openssl/dist/crypto

2023-09-02 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Sep  2 20:07:32 UTC 2023

Modified Files:
src/crypto/external/bsd/openssl/dist/crypto: sparccpuid.S

Log Message:
fix SPARC v8/v9 detection code.

this code uses a trick where the encoding on both v8 and v9 are
the same, and are not illegal instructions, but that the v9 one
has a detectable difference than v8.

the idea is that we perform a "subcc" (set condition codes) which
sets "%ccr" on v9, which is an unimplemented "%asr2" on v8, then
we read %ccr (v9) or %asr2 (v8), which will always be 0x99 on v9,
and .. is non-trapping but impleentation defined on v8.

for many implementations this returns the value of the %y reg.

as nothing actually sets %y in this path, it remains the value it
was most recently set to by something (anything), and if it just
happens to be 0x99 then the v9 paths will be taken on v8.

fix this by clearing the %y register before the potential read.

fixes PR port-sparc/57594.  tested on ss20 and in qemu.  this
version of the patch has been submitted upstream.

XXX: pullup-10, pullup-9, pullup-8.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 \
src/crypto/external/bsd/openssl/dist/crypto/sparccpuid.S

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



CVS commit: src/tools/compat

2023-09-02 Thread Palle Lyckegaard
Module Name:src
Committed By:   palle
Date:   Sat Sep  2 18:45:48 UTC 2023

Modified Files:
src/tools/compat: README

Log Message:
Update build instructions for Solaris 10 hosts


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/tools/compat/README

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



CVS commit: src/tools/compat

2023-09-02 Thread Palle Lyckegaard
Module Name:src
Committed By:   palle
Date:   Sat Sep  2 18:45:48 UTC 2023

Modified Files:
src/tools/compat: README

Log Message:
Update build instructions for Solaris 10 hosts


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/tools/compat/README

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

Modified files:

Index: src/tools/compat/README
diff -u src/tools/compat/README:1.28 src/tools/compat/README:1.29
--- src/tools/compat/README:1.28	Thu Aug 24 19:30:48 2023
+++ src/tools/compat/README	Sat Sep  2 18:45:48 2023
@@ -1,4 +1,4 @@
-$NetBSD: README,v 1.28 2023/08/24 19:30:48 palle Exp $
+$NetBSD: README,v 1.29 2023/09/02 18:45:48 palle Exp $
 
 Special notes for cross-hosting a NetBSD build on certain platforms.  
 Only those platforms which have been tested to complete a "build.sh" run
@@ -117,7 +117,7 @@ Solaris 10:
 * Solaris 10 1/13 (u11)
  * POSIX.1-2001, SUSv3 (see standards(7))
  * Using gcc-5 from opencsw.org
- * Set PATH to /usr/xpg6/bin:/usr/xpg4/bin:/usr/bin
+ * Set PATH to /usr/xpg6/bin:/usr/xpg4/bin:/usr/bin:/usr/ccs/bin
  * Set HOST_CC to /opt/csw/bin/gcc
  * Set HOST_SH to /usr/bin/bash
 



CVS commit: src/sys

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:44:59 UTC 2023

Modified Files:
src/sys/dev: cons.c
src/sys/kern: init_main.c kern_clock.c kern_cpu.c
src/sys/sys: heartbeat.h

Log Message:
heartbeat(9): Move #ifdef HEARTBEAT to sys/heartbeat.h.

Less error-prone this way, and the callers are less cluttered.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/dev/cons.c
cvs rdiff -u -r1.542 -r1.543 src/sys/kern/init_main.c
cvs rdiff -u -r1.150 -r1.151 src/sys/kern/kern_clock.c
cvs rdiff -u -r1.96 -r1.97 src/sys/kern/kern_cpu.c
cvs rdiff -u -r1.1 -r1.2 src/sys/sys/heartbeat.h

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

Modified files:

Index: src/sys/dev/cons.c
diff -u src/sys/dev/cons.c:1.94 src/sys/dev/cons.c:1.95
--- src/sys/dev/cons.c:1.94	Sat Sep  2 17:44:12 2023
+++ src/sys/dev/cons.c	Sat Sep  2 17:44:59 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: cons.c,v 1.94 2023/09/02 17:44:12 riastradh Exp $	*/
+/*	$NetBSD: cons.c,v 1.95 2023/09/02 17:44:59 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -39,11 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.94 2023/09/02 17:44:12 riastradh Exp $");
-
-#ifdef _KERNEL_OPT
-#include "opt_heartbeat.h"
-#endif
+__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.95 2023/09/02 17:44:59 riastradh Exp $");
 
 #include 
 
@@ -423,7 +419,6 @@ cnpollc(int on)
 	if (!on)
 		--refcount;
 	if (refcount == 0) {
-#ifdef HEARTBEAT
 		if (on) {
 			/*
 			 * Bind to the current CPU by disabling
@@ -437,14 +432,11 @@ cnpollc(int on)
 			kpreempt_disable();
 			heartbeat_suspend();
 		}
-#endif
 		(*cn_tab->cn_pollc)(cn_tab->cn_dev, on);
-#ifdef HEARTBEAT
 		if (!on) {
 			heartbeat_resume();
 			kpreempt_enable();
 		}
-#endif
 	}
 	if (on)
 		++refcount;

Index: src/sys/kern/init_main.c
diff -u src/sys/kern/init_main.c:1.542 src/sys/kern/init_main.c:1.543
--- src/sys/kern/init_main.c:1.542	Fri Jul  7 12:34:50 2023
+++ src/sys/kern/init_main.c	Sat Sep  2 17:44:59 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: init_main.c,v 1.542 2023/07/07 12:34:50 riastradh Exp $	*/
+/*	$NetBSD: init_main.c,v 1.543 2023/09/02 17:44:59 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -97,11 +97,10 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.542 2023/07/07 12:34:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.543 2023/09/02 17:44:59 riastradh Exp $");
 
 #include "opt_cnmagic.h"
 #include "opt_ddb.h"
-#include "opt_heartbeat.h"
 #include "opt_inet.h"
 #include "opt_ipsec.h"
 #include "opt_modular.h"
@@ -559,13 +558,11 @@ main(void)
 	/* Once all CPUs are detected, initialize the per-CPU cprng_fast.  */
 	cprng_fast_init();
 
-#ifdef HEARTBEAT
 	/*
 	 * Now that softints can be established, start monitoring
 	 * system heartbeat on all CPUs.
 	 */
 	heartbeat_start();
-#endif
 
 	ssp_init();
 

Index: src/sys/kern/kern_clock.c
diff -u src/sys/kern/kern_clock.c:1.150 src/sys/kern/kern_clock.c:1.151
--- src/sys/kern/kern_clock.c:1.150	Fri Jul  7 12:34:50 2023
+++ src/sys/kern/kern_clock.c	Sat Sep  2 17:44:59 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_clock.c,v 1.150 2023/07/07 12:34:50 riastradh Exp $	*/
+/*	$NetBSD: kern_clock.c,v 1.151 2023/09/02 17:44:59 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -69,12 +69,11 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_clock.c,v 1.150 2023/07/07 12:34:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_clock.c,v 1.151 2023/09/02 17:44:59 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dtrace.h"
 #include "opt_gprof.h"
-#include "opt_heartbeat.h"
 #include "opt_multiprocessor.h"
 #endif
 
@@ -337,12 +336,10 @@ hardclock(struct clockframe *frame)
 		tc_ticktock();
 	}
 
-#ifdef HEARTBEAT
 	/*
 	 * Make sure the CPUs and timecounter are making progress.
 	 */
 	heartbeat();
-#endif
 
 	/*
 	 * Update real-time timeout queue.

Index: src/sys/kern/kern_cpu.c
diff -u src/sys/kern/kern_cpu.c:1.96 src/sys/kern/kern_cpu.c:1.97
--- src/sys/kern/kern_cpu.c:1.96	Sat Sep  2 17:43:28 2023
+++ src/sys/kern/kern_cpu.c	Sat Sep  2 17:44:59 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_cpu.c,v 1.96 2023/09/02 17:43:28 riastradh Exp $	*/
+/*	$NetBSD: kern_cpu.c,v 1.97 2023/09/02 17:44:59 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009, 2010, 2012, 2019 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.96 2023/09/02 17:43:28 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.97 2023/09/02 17:44:59 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_cpu_ucode.h"
@@ -370,9 +370,7 @@ cpu_xc_offline(struct cpu_info *ci, void
 	pcu_save_all_on_cpu();
 #endif
 
-#ifdef HEARTBEAT
 	heartbeat_suspend();
-#endif
 
 #ifdef __HAVE_MD_CPU_OFFLINE
 	cpu_offline_md();
@@ -391,9 +389,7 @@ cpu_xc_online(struct 

CVS commit: src/sys/kern

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:44:41 UTC 2023

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

Log Message:
heartbeat(9): Move panicstr check into the IPI itself.

We can't return early from defibrillate because the IPI may have yet
to run -- we can't return until the other CPU is definitely done
using the ipi_msg_t we created on the stack.

We should avoid calling panic again on the patient CPU in case it was
already in the middle of a panic, so that we don't re-enter panic
while, e.g., trying to print a stack trace.

Sprinkle some comments.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 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.8 src/sys/kern/kern_heartbeat.c:1.9
--- src/sys/kern/kern_heartbeat.c:1.8	Sat Sep  2 17:44:32 2023
+++ src/sys/kern/kern_heartbeat.c	Sat Sep  2 17:44:41 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_heartbeat.c,v 1.8 2023/09/02 17:44:32 riastradh Exp $	*/
+/*	$NetBSD: kern_heartbeat.c,v 1.9 2023/09/02 17:44:41 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -82,7 +82,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.8 2023/09/02 17:44:32 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.9 2023/09/02 17:44:41 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -457,7 +457,21 @@ defibrillator(void *cookie)
 {
 	bool *ack = cookie;
 
+	/*
+	 * Acknowledge the interrupt so the doctor CPU won't trigger a
+	 * new panic for defibrillation timeout.
+	 */
 	atomic_store_relaxed(ack, true);
+
+	/*
+	 * If a panic is already in progress, we may have interrupted
+	 * the logic that prints a stack trace on this CPU -- so let's
+	 * not make it worse by giving the misapprehension of a
+	 * recursive panic.
+	 */
+	if (atomic_load_relaxed() != NULL)
+		return;
+
 	panic("%s[%d %s]: heart stopped beating", cpu_name(curcpu()),
 	curlwp->l_lid,
 	curlwp->l_name ? curlwp->l_name : curproc->p_comm);
@@ -498,13 +512,11 @@ defibrillate(struct cpu_info *ci, unsign
 	/*
 	 * Busy-wait up to 1sec for the patient CPU to print a stack
 	 * trace and panic.  If the patient CPU acknowledges the IPI,
-	 * or if we're panicking anyway, just give up and stop here --
-	 * the system is coming down soon and we should avoid getting
-	 * in the way.
+	 * just give up and stop here -- the system is coming down soon
+	 * and we should avoid getting in the way.
 	 */
 	while (countdown --> 0) {
-		if (atomic_load_relaxed() ||
-		atomic_load_relaxed() != NULL)
+		if (atomic_load_relaxed())
 			return;
 		DELAY(1000);	/* 1ms */
 	}



CVS commit: src/sys/kern

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:44:41 UTC 2023

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

Log Message:
heartbeat(9): Move panicstr check into the IPI itself.

We can't return early from defibrillate because the IPI may have yet
to run -- we can't return until the other CPU is definitely done
using the ipi_msg_t we created on the stack.

We should avoid calling panic again on the patient CPU in case it was
already in the middle of a panic, so that we don't re-enter panic
while, e.g., trying to print a stack trace.

Sprinkle some comments.


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

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:44:32 UTC 2023

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

Log Message:
heartbeat(9): More detail about manual test success criteria.

Changes comments only, no functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 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.7 src/sys/kern/kern_heartbeat.c:1.8
--- src/sys/kern/kern_heartbeat.c:1.7	Sat Sep  2 17:44:23 2023
+++ src/sys/kern/kern_heartbeat.c	Sat Sep  2 17:44:32 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_heartbeat.c,v 1.7 2023/09/02 17:44:23 riastradh Exp $	*/
+/*	$NetBSD: kern_heartbeat.c,v 1.8 2023/09/02 17:44:32 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -53,21 +53,25 @@
  *
  * 4.	sysctl -w debug.crashme_enable=1
  *	sysctl -w debug.crashme.spl_spinout=1   # IPL_SOFTCLOCK
- *	# verify system panics after 15sec
+ *	# verify system panics after 15sec, with a stack trace through
+ *	# crashme_spl_spinout
  *
  * 5.	sysctl -w debug.crashme_enable=1
  *	sysctl -w debug.crashme.spl_spinout=6   # IPL_SCHED
- *	# verify system panics after 15sec
+ *	# verify system panics after 15sec, with a stack trace through
+ *	# crashme_spl_spinout
  *
  * 6.	cpuctl offline 0
  *	sysctl -w debug.crashme_enable=1
  *	sysctl -w debug.crashme.spl_spinout=1   # IPL_SOFTCLOCK
- *	# verify system panics after 15sec
+ *	# verify system panics after 15sec, with a stack trace through
+ *	# crashme_spl_spinout
  *
  * 7.	cpuctl offline 0
  *	sysctl -w debug.crashme_enable=1
  *	sysctl -w debug.crashme.spl_spinout=5   # IPL_VM
- *	# verify system panics after 15sec
+ *	# verify system panics after 15sec, with a stack trace through
+ *	# crashme_spl_spinout
  *
  *	# Not this -- IPL_SCHED and IPL_HIGH spinout on a single CPU
  *	# require a hardware watchdog timer.
@@ -78,7 +82,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.7 2023/09/02 17:44:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.8 2023/09/02 17:44:32 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"



CVS commit: src/sys/kern

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:44:23 UTC 2023

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

Log Message:
heartbeat(9): Ignore stale tc if primary CPU heartbeat is suspended.

The timecounter ticks only on the primary CPU, so of course it will
go stale if it's suspended.

(It is, perhaps, a mistake that it only ticks on the primary CPU,
even if the primary CPU is offlined or in a polled-input console
loop, but that's a separate issue.)


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 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.6 src/sys/kern/kern_heartbeat.c:1.7
--- src/sys/kern/kern_heartbeat.c:1.6	Sat Sep  2 17:43:37 2023
+++ src/sys/kern/kern_heartbeat.c	Sat Sep  2 17:44:23 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_heartbeat.c,v 1.6 2023/09/02 17:43:37 riastradh Exp $	*/
+/*	$NetBSD: kern_heartbeat.c,v 1.7 2023/09/02 17:44:23 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.6 2023/09/02 17:43:37 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.7 2023/09/02 17:44:23 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -199,6 +199,41 @@ heartbeat_resume(void)
 }
 
 /*
+ * heartbeat_timecounter_suspended()
+ *
+ *	True if timecounter heartbeat checks are suspended because the
+ *	timecounter may not be advancing, false if heartbeat checks
+ *	should check for timecounter progress.
+ */
+static bool
+heartbeat_timecounter_suspended(void)
+{
+	CPU_INFO_ITERATOR cii;
+	struct cpu_info *ci;
+
+	/*
+	 * The timecounter ticks only on the primary CPU.  Check
+	 * whether it's suspended.
+	 *
+	 * XXX Would be nice if we could find the primary CPU without
+	 * iterating over all CPUs.
+	 */
+	for (CPU_INFO_FOREACH(cii, ci)) {
+		if (CPU_IS_PRIMARY(ci)) {
+			return ci->ci_schedstate.spc_flags &
+			SPCF_HEARTBEATSUSPENDED;
+		}
+	}
+
+	/*
+	 * This should be unreachable -- there had better be a primary
+	 * CPU in the system!  If not, the timecounter will be busted
+	 * anyway.
+	 */
+	panic("no primary CPU");
+}
+
+/*
  * heartbeat_reset_xc(a, b)
  *
  *	Cross-call handler to reset heartbeat state just prior to
@@ -598,7 +633,8 @@ heartbeat(void)
 		/*
 		 * Timecounter hasn't advanced by more than a second.
 		 * Make sure the timecounter isn't stuck according to
-		 * our heartbeats.
+		 * our heartbeats -- unless timecounter heartbeats are
+		 * suspended too.
 		 *
 		 * Our own heartbeat count can't roll back, and
 		 * time_uptime should be updated before it wraps
@@ -608,7 +644,8 @@ heartbeat(void)
 		stamp =
 		atomic_load_relaxed(()->ci_heartbeat_uptime_stamp);
 		d = count - stamp;
-		if (__predict_false(d > period_ticks)) {
+		if (__predict_false(d > period_ticks) &&
+		!heartbeat_timecounter_suspended()) {
 			panic("%s: time has not advanced in %u heartbeats",
 			cpu_name(curcpu()), d);
 		}



CVS commit: src/sys

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:43:38 UTC 2023

Modified Files:
src/sys/kern: kern_heartbeat.c
src/sys/sys: sched.h

Log Message:
heartbeat(9): New flag SPCF_HEARTBEATSUSPENDED.

This way we can suspend heartbeats on a single CPU while the console
is in polling mode, not just when the CPU is offlined.  This should
be rare, so it's not _convenient_, but it should enable us to fix
polling-mode console input when the hardclock timer is still running
on other CPUs.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/kern/kern_heartbeat.c
cvs rdiff -u -r1.92 -r1.93 src/sys/sys/sched.h

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.5 src/sys/kern/kern_heartbeat.c:1.6
--- src/sys/kern/kern_heartbeat.c:1.5	Sun Jul 16 10:18:19 2023
+++ src/sys/kern/kern_heartbeat.c	Sat Sep  2 17:43:37 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_heartbeat.c,v 1.5 2023/07/16 10:18:19 riastradh Exp $	*/
+/*	$NetBSD: kern_heartbeat.c,v 1.6 2023/09/02 17:43:37 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.5 2023/07/16 10:18:19 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.6 2023/09/02 17:43:37 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -127,17 +127,22 @@ void *heartbeat_sih			__read_mostly;
  *	Suspend heartbeat monitoring of the current CPU.
  *
  *	Called after the current CPU has been marked offline but before
- *	it has stopped running.  Caller must have preemption disabled.
+ *	it has stopped running, or after IPL has been raised for
+ *	polling-mode console input.  Caller must have preemption
+ *	disabled.  Non-nestable.  Reversed by heartbeat_resume.
  */
 void
 heartbeat_suspend(void)
 {
+	struct cpu_info *ci = curcpu();
+	int s;
 
 	KASSERT(curcpu_stable());
+	KASSERT((ci->ci_schedstate.spc_flags & SPCF_HEARTBEATSUSPENDED) == 0);
 
-	/*
-	 * Nothing to do -- we just check the SPCF_OFFLINE flag.
-	 */
+	s = splsched();
+	ci->ci_schedstate.spc_flags |= SPCF_HEARTBEATSUSPENDED;
+	splx(s);
 }
 
 /*
@@ -148,6 +153,8 @@ heartbeat_suspend(void)
  *	Called at startup while cold, and whenever heartbeat monitoring
  *	is re-enabled after being disabled or the period is changed.
  *	When not cold, ci must be the current CPU.
+ *
+ *	Must be run at splsched.
  */
 static void
 heartbeat_resume_cpu(struct cpu_info *ci)
@@ -155,6 +162,7 @@ heartbeat_resume_cpu(struct cpu_info *ci
 
 	KASSERT(__predict_false(cold) || curcpu_stable());
 	KASSERT(__predict_false(cold) || ci == curcpu());
+	/* XXX KASSERT IPL_SCHED */
 
 	ci->ci_heartbeat_count = 0;
 	ci->ci_heartbeat_uptime_cache = time_uptime;
@@ -167,9 +175,8 @@ heartbeat_resume_cpu(struct cpu_info *ci
  *	Resume heartbeat monitoring of the current CPU.
  *
  *	Called after the current CPU has started running but before it
- *	has been marked online.  Also used internally when starting up
- *	heartbeat monitoring at boot or when the maximum period is set
- *	from zero to nonzero.  Caller must have preemption disabled.
+ *	has been marked online, or when ending polling-mode input
+ *	before IPL is restored.  Caller must have preemption disabled.
  */
 void
 heartbeat_resume(void)
@@ -178,6 +185,7 @@ heartbeat_resume(void)
 	int s;
 
 	KASSERT(curcpu_stable());
+	KASSERT(ci->ci_schedstate.spc_flags & SPCF_HEARTBEATSUSPENDED);
 
 	/*
 	 * Block heartbeats while we reset the state so we don't
@@ -185,6 +193,7 @@ heartbeat_resume(void)
 	 * resetting the count and the uptime stamp.
 	 */
 	s = splsched();
+	ci->ci_schedstate.spc_flags &= ~SPCF_HEARTBEATSUSPENDED;
 	heartbeat_resume_cpu(ci);
 	splx(s);
 }
@@ -198,8 +207,11 @@ heartbeat_resume(void)
 static void
 heartbeat_reset_xc(void *a, void *b)
 {
+	int s;
 
-	heartbeat_resume();
+	s = splsched();
+	heartbeat_resume_cpu(curcpu());
+	splx(s);
 }
 
 /*
@@ -488,7 +500,7 @@ select_patient(void)
 	 * in the iteration order.
 	 */
 	for (CPU_INFO_FOREACH(cii, ci)) {
-		if (ci->ci_schedstate.spc_flags & SPCF_OFFLINE)
+		if (ci->ci_schedstate.spc_flags & SPCF_HEARTBEATSUSPENDED)
 			continue;
 		if (passedcur) {
 			/*
@@ -565,7 +577,8 @@ heartbeat(void)
 	period_secs = atomic_load_relaxed(_max_period_secs);
 	if (__predict_false(period_ticks == 0) ||
 	__predict_false(period_secs == 0) ||
-	__predict_false(curcpu()->ci_schedstate.spc_flags & SPCF_OFFLINE))
+	__predict_false(curcpu()->ci_schedstate.spc_flags &
+		SPCF_HEARTBEATSUSPENDED))
 		return;
 
 	/*
@@ -637,8 +650,8 @@ heartbeat(void)
 	 * Verify that time is advancing on the patient CPU.  If the
 	 * delta exceeds UINT_MAX/2, that means it is already ahead by
 	 * a little on the other CPU, and the subtraction went
-	 * negative, which is OK.  If the CPU has been
-	 * offlined since we 

CVS commit: src/sys/dev

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:43:47 UTC 2023

Modified Files:
src/sys/dev: cons.c

Log Message:
cons(9): Sort includes.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/sys/dev/cons.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/dev/cons.c
diff -u src/sys/dev/cons.c:1.92 src/sys/dev/cons.c:1.93
--- src/sys/dev/cons.c:1.92	Tue Oct 25 23:21:33 2022
+++ src/sys/dev/cons.c	Sat Sep  2 17:43:46 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: cons.c,v 1.92 2022/10/25 23:21:33 riastradh Exp $	*/
+/*	$NetBSD: cons.c,v 1.93 2023/09/02 17:43:46 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -39,23 +39,24 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.92 2022/10/25 23:21:33 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.93 2023/09/02 17:43:46 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 
 



CVS commit: src/sys/dev

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:43:47 UTC 2023

Modified Files:
src/sys/dev: cons.c

Log Message:
cons(9): Sort includes.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/sys/dev/cons.c

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



CVS commit: src/sys

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:43:38 UTC 2023

Modified Files:
src/sys/kern: kern_heartbeat.c
src/sys/sys: sched.h

Log Message:
heartbeat(9): New flag SPCF_HEARTBEATSUSPENDED.

This way we can suspend heartbeats on a single CPU while the console
is in polling mode, not just when the CPU is offlined.  This should
be rare, so it's not _convenient_, but it should enable us to fix
polling-mode console input when the hardclock timer is still running
on other CPUs.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/kern/kern_heartbeat.c
cvs rdiff -u -r1.92 -r1.93 src/sys/sys/sched.h

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



CVS commit: src

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:41:43 UTC 2023

Modified Files:
src/tests/usr.sbin/certctl: t_certctl.sh
src/usr.sbin/certctl: certctl.sh

Log Message:
certctl(8): Fix some bugs with evil pathnames.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.sbin/certctl/t_certctl.sh
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/certctl/certctl.sh

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

Modified files:

Index: src/tests/usr.sbin/certctl/t_certctl.sh
diff -u src/tests/usr.sbin/certctl/t_certctl.sh:1.6 src/tests/usr.sbin/certctl/t_certctl.sh:1.7
--- src/tests/usr.sbin/certctl/t_certctl.sh:1.6	Sat Sep  2 17:41:33 2023
+++ src/tests/usr.sbin/certctl/t_certctl.sh	Sat Sep  2 17:41:43 2023
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-#	$NetBSD: t_certctl.sh,v 1.6 2023/09/02 17:41:33 riastradh Exp $
+#	$NetBSD: t_certctl.sh,v 1.7 2023/09/02 17:41:43 riastradh Exp $
 #
 # Copyright (c) 2023 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -319,8 +319,6 @@ evilcertsdir_body()
 
 	setupconf certs1
 
-	atf_expect_fail "mistakes were made with evil pathnames"
-
 	# initial (re)hash, nonexistent certs directory
 	atf_check -s exit:0 $CERTCTL rehash
 	atf_check -s exit:0 certctl -C certs.conf \

Index: src/usr.sbin/certctl/certctl.sh
diff -u src/usr.sbin/certctl/certctl.sh:1.3 src/usr.sbin/certctl/certctl.sh:1.4
--- src/usr.sbin/certctl/certctl.sh:1.3	Mon Aug 28 22:25:50 2023
+++ src/usr.sbin/certctl/certctl.sh	Sat Sep  2 17:41:43 2023
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-#	$NetBSD: certctl.sh,v 1.3 2023/08/28 22:25:50 riastradh Exp $
+#	$NetBSD: certctl.sh,v 1.4 2023/09/02 17:41:43 riastradh Exp $
 #
 # Copyright (c) 2023 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -432,7 +432,7 @@ rehash()
 	if [ -f "$certsdir/.certctl" ]; then
 		# Directory exists and is managed by certctl(8).
 		# Safe to delete it and everything in it.
-		run rm -rf "$certsdir"
+		run rm -rf -- "$certsdir"
 	elif [ -h "$certsdir" ]; then
 		# Paranoia: refuse to chase a symlink.  (Caveat: this
 		# is not secure against an adversary who can recreate
@@ -445,15 +445,15 @@ rehash()
 	elif [ ! -d "$certsdir" ]; then
 		error "certificates directory is not a directory"
 		return 1
-	elif ! find "$certsdir" -maxdepth 0 -type d -empty -exit 1; then
+	elif ! find -f "$certsdir" -- -maxdepth 0 -type d -empty -exit 1; then
 		# certsdir exists, is a directory, and is empty.  Safe
 		# to delete it with rmdir and take it over.
-		run rmdir "$certsdir"
+		run rmdir -- "$certsdir"
 	else
 		error "existing certificates; set manual or move them"
 		return 1
 	fi
-	run mkdir "$certsdir"
+	run mkdir -- "$certsdir"
 	if $vflag; then
 		printf '# initialize %s\n' "$certsdir"
 	fi



CVS commit: src/tests/usr.sbin/certctl

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:41:33 UTC 2023

Modified Files:
src/tests/usr.sbin/certctl: t_certctl.sh

Log Message:
certctl(8): Test more evil pathnames.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.sbin/certctl/t_certctl.sh

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

Modified files:

Index: src/tests/usr.sbin/certctl/t_certctl.sh
diff -u src/tests/usr.sbin/certctl/t_certctl.sh:1.5 src/tests/usr.sbin/certctl/t_certctl.sh:1.6
--- src/tests/usr.sbin/certctl/t_certctl.sh:1.5	Mon Aug 28 22:25:49 2023
+++ src/tests/usr.sbin/certctl/t_certctl.sh	Sat Sep  2 17:41:33 2023
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-#	$NetBSD: t_certctl.sh,v 1.5 2023/08/28 22:25:49 riastradh Exp $
+#	$NetBSD: t_certctl.sh,v 1.6 2023/09/02 17:41:33 riastradh Exp $
 #
 # Copyright (c) 2023 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -299,6 +299,71 @@ EOF
 	atf_check -s exit:0 test -h certs/0123abcd.0
 }
 
+atf_test_case evilcertsdir
+evilcertsdir_head()
+{
+	atf_set "descr" "Test certificate directory with evil characters"
+}
+evilcertsdir_body()
+{
+	local certs1 diginotar_base diginotar evilcertsdir evildistrustdir
+
+	certs1=$(atf_get_srcdir)/certs1
+	diginotar_base=Explicitly_Distrust_DigiNotar_Root_CA.pem
+	diginotar=$certs1/$diginotar_base
+
+	evilcertsdir=$(printf '-evil certs\n.')
+	evilcertsdir=${evilcertsdir%.}
+	evildistrustdir=$(printf '-evil untrusted\n.')
+	evildistrustdir=${evildistrustdir%.}
+
+	setupconf certs1
+
+	atf_expect_fail "mistakes were made with evil pathnames"
+
+	# initial (re)hash, nonexistent certs directory
+	atf_check -s exit:0 $CERTCTL rehash
+	atf_check -s exit:0 certctl -C certs.conf \
+	-c "$evilcertsdir" -u "$evildistrustdir" \
+	rehash
+	atf_check -s exit:0 diff -ruN -- certs "$evilcertsdir"
+	atf_check -s exit:0 test ! -e untrusted
+	atf_check -s exit:0 test ! -h untrusted
+	atf_check -s exit:0 test ! -e "$evildistrustdir"
+	atf_check -s exit:0 test ! -h "$evildistrustdir"
+
+	# initial (re)hash, empty certs directory
+	atf_check -s exit:0 rm -rf -- certs
+	atf_check -s exit:0 rm -rf -- "$evilcertsdir"
+	atf_check -s exit:0 mkdir -- certs
+	atf_check -s exit:0 mkdir -- "$evilcertsdir"
+	atf_check -s exit:0 $CERTCTL rehash
+	atf_check -s exit:0 certctl -C certs.conf \
+	-c "$evilcertsdir" -u "$evildistrustdir" \
+	rehash
+	atf_check -s exit:0 diff -ruN -- certs "$evilcertsdir"
+	atf_check -s exit:0 test ! -e untrusted
+	atf_check -s exit:0 test ! -h untrusted
+	atf_check -s exit:0 test ! -e "$evildistrustdir"
+	atf_check -s exit:0 test ! -h "$evildistrustdir"
+
+	# test distrusting a CA
+	atf_check -s exit:0 $CERTCTL untrust "$diginotar"
+	atf_check -s exit:0 certctl -C certs.conf \
+	-c "$evilcertsdir" -u "$evildistrustdir" \
+	untrust "$diginotar"
+	atf_check -s exit:0 diff -ruN -- certs "$evilcertsdir"
+	atf_check -s exit:0 diff -ruN -- untrusted "$evildistrustdir"
+
+	# second rehash
+	atf_check -s exit:0 $CERTCTL rehash
+	atf_check -s exit:0 certctl -C certs.conf \
+	-c "$evilcertsdir" -u "$evildistrustdir" \
+	rehash
+	atf_check -s exit:0 diff -ruN -- certs "$evilcertsdir"
+	atf_check -s exit:0 diff -ruN -- untrusted "$evildistrustdir"
+}
+
 atf_test_case evilpath
 evilpath_head()
 {
@@ -407,6 +472,7 @@ atf_init_test_cases()
 	atf_add_test_case collidebase
 	atf_add_test_case collidehash
 	atf_add_test_case empty
+	atf_add_test_case evilcertsdir
 	atf_add_test_case evilpath
 	atf_add_test_case manual
 	atf_add_test_case missingconf



CVS commit: src/tests/usr.sbin/certctl

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:41:33 UTC 2023

Modified Files:
src/tests/usr.sbin/certctl: t_certctl.sh

Log Message:
certctl(8): Test more evil pathnames.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.sbin/certctl/t_certctl.sh

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



CVS commit: src/sys

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:44:59 UTC 2023

Modified Files:
src/sys/dev: cons.c
src/sys/kern: init_main.c kern_clock.c kern_cpu.c
src/sys/sys: heartbeat.h

Log Message:
heartbeat(9): Move #ifdef HEARTBEAT to sys/heartbeat.h.

Less error-prone this way, and the callers are less cluttered.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/dev/cons.c
cvs rdiff -u -r1.542 -r1.543 src/sys/kern/init_main.c
cvs rdiff -u -r1.150 -r1.151 src/sys/kern/kern_clock.c
cvs rdiff -u -r1.96 -r1.97 src/sys/kern/kern_cpu.c
cvs rdiff -u -r1.1 -r1.2 src/sys/sys/heartbeat.h

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-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:44:32 UTC 2023

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

Log Message:
heartbeat(9): More detail about manual test success criteria.

Changes comments only, no functional change.


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

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:44:23 UTC 2023

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

Log Message:
heartbeat(9): Ignore stale tc if primary CPU heartbeat is suspended.

The timecounter ticks only on the primary CPU, so of course it will
go stale if it's suspended.

(It is, perhaps, a mistake that it only ticks on the primary CPU,
even if the primary CPU is offlined or in a polled-input console
loop, but that's a separate issue.)


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 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/external/mpl/mozilla-certdata/share

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:39:52 UTC 2023

Modified Files:
src/external/mpl/mozilla-certdata/share: Makefile

Log Message:
mozilla-certdata: Install relative symlinks.

Slightly more compact this way, and you can examine them in a destdir
without chrooting.  Not terribly important, but a minor convenience.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/external/mpl/mozilla-certdata/share/Makefile

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



CVS commit: src/sys/dev

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:44:12 UTC 2023

Modified Files:
src/sys/dev: cons.c

Log Message:
cons(9): Suspend heartbeat checks while in polled-input mode.

This goes into a tight loop at high IPL, so it is to be expected that
the heartbeats will stop happening.

Should fix heartbeat panics at root device prompt on boot.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/sys/dev/cons.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/dev/cons.c
diff -u src/sys/dev/cons.c:1.93 src/sys/dev/cons.c:1.94
--- src/sys/dev/cons.c:1.93	Sat Sep  2 17:43:46 2023
+++ src/sys/dev/cons.c	Sat Sep  2 17:44:12 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: cons.c,v 1.93 2023/09/02 17:43:46 riastradh Exp $	*/
+/*	$NetBSD: cons.c,v 1.94 2023/09/02 17:44:12 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -39,7 +39,11 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.93 2023/09/02 17:43:46 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.94 2023/09/02 17:44:12 riastradh Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_heartbeat.h"
+#endif
 
 #include 
 
@@ -47,6 +51,7 @@ __KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.9
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -417,8 +422,30 @@ cnpollc(int on)
 		return;
 	if (!on)
 		--refcount;
-	if (refcount == 0)
+	if (refcount == 0) {
+#ifdef HEARTBEAT
+		if (on) {
+			/*
+			 * Bind to the current CPU by disabling
+			 * preemption (more convenient than finding a
+			 * place to store a stack to unwind for
+			 * curlwp_bind/bindx, and preemption wouldn't
+			 * happen anyway while spinning at high IPL in
+			 * cngetc) so that curcpu() is stable so that
+			 * we can suspend heartbeat checks for it.
+			 */
+			kpreempt_disable();
+			heartbeat_suspend();
+		}
+#endif
 		(*cn_tab->cn_pollc)(cn_tab->cn_dev, on);
+#ifdef HEARTBEAT
+		if (!on) {
+			heartbeat_resume();
+			kpreempt_enable();
+		}
+#endif
+	}
 	if (on)
 		++refcount;
 }



CVS commit: src/sys/dev

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:44:12 UTC 2023

Modified Files:
src/sys/dev: cons.c

Log Message:
cons(9): Suspend heartbeat checks while in polled-input mode.

This goes into a tight loop at high IPL, so it is to be expected that
the heartbeats will stop happening.

Should fix heartbeat panics at root device prompt on boot.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/sys/dev/cons.c

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



CVS commit: src/etc/mtree

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:39:43 UTC 2023

Modified Files:
src/etc/mtree: special

Log Message:
etc/mtree/special: Fix spaces/tabs.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.177 -r1.178 src/etc/mtree/special

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



CVS commit: src/sys/dev/usb

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:43:17 UTC 2023

Modified Files:
src/sys/dev/usb: ukbd.c

Log Message:
ukbd(4): Sort includes.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 src/sys/dev/usb/ukbd.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/dev/usb/ukbd.c
diff -u src/sys/dev/usb/ukbd.c:1.163 src/sys/dev/usb/ukbd.c:1.164
--- src/sys/dev/usb/ukbd.c:1.163	Sat Sep  2 17:42:47 2023
+++ src/sys/dev/usb/ukbd.c	Sat Sep  2 17:43:16 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: ukbd.c,v 1.163 2023/09/02 17:42:47 riastradh Exp $*/
+/*  $NetBSD: ukbd.c,v 1.164 2023/09/02 17:43:16 riastradh Exp $*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.163 2023/09/02 17:42:47 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.164 2023/09/02 17:43:16 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -47,28 +47,29 @@ __KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.1
 #endif /* _KERNEL_OPT */
 
 #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/dev/usb

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:43:17 UTC 2023

Modified Files:
src/sys/dev/usb: ukbd.c

Log Message:
ukbd(4): Sort includes.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 src/sys/dev/usb/ukbd.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-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:43:28 UTC 2023

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

Log Message:
cpu_setstate: Fix call to heartbeat_suspend.

Do this on successful offlining, not on failed offlining.

No functional change right now because heartbeat_suspend is
implemented as a noop -- heartbeat(9) will just check the
SPCF_OFFLINE flag.  But if we change it to not be a noop, well, then
we need to call it in the right place.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/sys/kern/kern_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/kern_cpu.c
diff -u src/sys/kern/kern_cpu.c:1.95 src/sys/kern/kern_cpu.c:1.96
--- src/sys/kern/kern_cpu.c:1.95	Fri Jul  7 12:34:50 2023
+++ src/sys/kern/kern_cpu.c	Sat Sep  2 17:43:28 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_cpu.c,v 1.95 2023/07/07 12:34:50 riastradh Exp $	*/
+/*	$NetBSD: kern_cpu.c,v 1.96 2023/09/02 17:43:28 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009, 2010, 2012, 2019 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.95 2023/07/07 12:34:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.96 2023/09/02 17:43:28 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_cpu_ucode.h"
@@ -370,6 +370,10 @@ cpu_xc_offline(struct cpu_info *ci, void
 	pcu_save_all_on_cpu();
 #endif
 
+#ifdef HEARTBEAT
+	heartbeat_suspend();
+#endif
+
 #ifdef __HAVE_MD_CPU_OFFLINE
 	cpu_offline_md();
 #endif
@@ -379,10 +383,6 @@ fail:
 	s = splsched();
 	spc->spc_flags &= ~SPCF_OFFLINE;
 	splx(s);
-
-#ifdef HEARTBEAT
-	heartbeat_suspend();
-#endif
 }
 
 static void



CVS commit: src/sys/kern

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:43:28 UTC 2023

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

Log Message:
cpu_setstate: Fix call to heartbeat_suspend.

Do this on successful offlining, not on failed offlining.

No functional change right now because heartbeat_suspend is
implemented as a noop -- heartbeat(9) will just check the
SPCF_OFFLINE flag.  But if we change it to not be a noop, well, then
we need to call it in the right place.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/sys/kern/kern_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/dev/usb

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:42:47 UTC 2023

Modified Files:
src/sys/dev/usb: ukbd.c

Log Message:
ukbd(4): Fix ordering in ukbd_cnpollc exit.

This is probably an MP-safety issue waiting to happen, but let's at
least make the wind and unwind sequences mirror images.


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/sys/dev/usb/ukbd.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/dev/usb/ukbd.c
diff -u src/sys/dev/usb/ukbd.c:1.162 src/sys/dev/usb/ukbd.c:1.163
--- src/sys/dev/usb/ukbd.c:1.162	Tue Jan 10 18:20:10 2023
+++ src/sys/dev/usb/ukbd.c	Sat Sep  2 17:42:47 2023
@@ -1,4 +1,4 @@
-/*  $NetBSD: ukbd.c,v 1.162 2023/01/10 18:20:10 mrg Exp $*/
+/*  $NetBSD: ukbd.c,v 1.163 2023/09/02 17:42:47 riastradh Exp $*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.162 2023/01/10 18:20:10 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.163 2023/09/02 17:42:47 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1055,11 +1055,12 @@ ukbd_cnpollc(void *v, int on)
 	if (on) {
 		sc->sc_spl = splusb();
 		pollenter++;
-	} else {
-		splx(sc->sc_spl);
-		pollenter--;
 	}
 	usbd_set_polling(dev, on);
+	if (!on) {
+		pollenter--;
+		splx(sc->sc_spl);
+	}
 }
 
 int



CVS commit: src/sys/dev/usb

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:42:47 UTC 2023

Modified Files:
src/sys/dev/usb: ukbd.c

Log Message:
ukbd(4): Fix ordering in ukbd_cnpollc exit.

This is probably an MP-safety issue waiting to happen, but let's at
least make the wind and unwind sequences mirror images.


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/sys/dev/usb/ukbd.c

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



CVS commit: src/tests/usr.sbin/certctl

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:42:01 UTC 2023

Modified Files:
src/tests/usr.sbin/certctl: t_certctl.sh

Log Message:
certctl(8): Fix quoting and whitespace style in evilpath test.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.sbin/certctl/t_certctl.sh

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

Modified files:

Index: src/tests/usr.sbin/certctl/t_certctl.sh
diff -u src/tests/usr.sbin/certctl/t_certctl.sh:1.7 src/tests/usr.sbin/certctl/t_certctl.sh:1.8
--- src/tests/usr.sbin/certctl/t_certctl.sh:1.7	Sat Sep  2 17:41:43 2023
+++ src/tests/usr.sbin/certctl/t_certctl.sh	Sat Sep  2 17:42:01 2023
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-#	$NetBSD: t_certctl.sh,v 1.7 2023/09/02 17:41:43 riastradh Exp $
+#	$NetBSD: t_certctl.sh,v 1.8 2023/09/02 17:42:01 riastradh Exp $
 #
 # Copyright (c) 2023 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -371,17 +371,17 @@ evilpath_body()
 {
 	local evildir
 
-	evildir="$(printf 'evil\n.')"
-evildir=${evildir%.}
-mkdir "$evildir"
+	evildir=$(printf 'evil\n.')
+	evildir=${evildir%.}
+	mkdir "$evildir"
 
-cp -p "$(atf_get_srcdir)/certs2"/*.pem "$evildir"/
+	cp -p "$(atf_get_srcdir)/certs2"/*.pem "$evildir"/
 
-setupconf certs1
-cat <>certs.conf
+	setupconf certs1
+	cat <>certs.conf
 path $(printf '%s' "$(pwd)/$evildir" | vis -M)
 EOF
-checks certs1 "$(pwd)/$evildir"
+	checks certs1 "$(pwd)/$evildir"
 }
 
 atf_test_case missingconf



CVS commit: src/tests/usr.sbin/certctl

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:42:01 UTC 2023

Modified Files:
src/tests/usr.sbin/certctl: t_certctl.sh

Log Message:
certctl(8): Fix quoting and whitespace style in evilpath test.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.sbin/certctl/t_certctl.sh

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



CVS commit: src

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:41:43 UTC 2023

Modified Files:
src/tests/usr.sbin/certctl: t_certctl.sh
src/usr.sbin/certctl: certctl.sh

Log Message:
certctl(8): Fix some bugs with evil pathnames.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.sbin/certctl/t_certctl.sh
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/certctl/certctl.sh

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



CVS commit: src/usr.sbin/certctl

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:41:17 UTC 2023

Modified Files:
src/usr.sbin/certctl: certctl.8

Log Message:
certctl(8): Minor man page clarifications.

- Specify exactly what /etc/openssl/certs gets populated with.
- Change HTTPS to TLS.
- Specify the permitted character class in certs.conf.
  (Maybe more conservative than strictly needed; but let's stay on
  the safe side.)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/certctl/certctl.8

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

Modified files:

Index: src/usr.sbin/certctl/certctl.8
diff -u src/usr.sbin/certctl/certctl.8:1.1 src/usr.sbin/certctl/certctl.8:1.2
--- src/usr.sbin/certctl/certctl.8:1.1	Sat Aug 26 05:27:15 2023
+++ src/usr.sbin/certctl/certctl.8	Sat Sep  2 17:41:17 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: certctl.8,v 1.1 2023/08/26 05:27:15 riastradh Exp $
+.\"	$NetBSD: certctl.8,v 1.2 2023/09/02 17:41:17 riastradh Exp $
 .\"
 .\" Copyright (c) 2023 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -56,21 +56,21 @@
 The
 .Nm
 utility manages certificates used by OpenSSL-based applications as
-trust anchors for certificate validation in HTTPS or other purposes.
+trust anchors for certificate validation in TLS or other purposes,
+for example by
+.Xr ftp 1
+in HTTPS.
 .Nm
 allows configuring the set of certificates and persistently excluding
 individual certificates.
 .Pp
-For HTTPS certificate validation, OpenSSL applications typically
-use either a directory at
+For trust anchors to validate TLS certificates, OpenSSL applications
+typically use a directory at
 .Pa /etc/openssl/certs
 of hashed certificates in PEM format, with names like
 .Pa "3513523f.0"
-used for lookup
-.Pq see Xr openssl_rehash 1 ,
-or a single-file bundle at
-.Pa /etc/openssl/certs/ca-certificates.crt
-concatenating all the certificates in PEM format.
+used for lookup; see
+.Xr openssl_rehash 1 .
 .Pp
 .Nm
 scans all directories in the certificate search path specified by the
@@ -87,7 +87,23 @@ in PEM format, except for those that hav
 and keeps
 .Ar certsdir
 .Pq default: Pa /etc/openssl/certs
-populated with symlinks to them.
+populated with:
+.Bl -dash
+.It
+symlinks to the original files in the certificate search path, for
+applications that scan a directory for all files matching
+.Pa *.cer ,
+.Pa *.crt ,
+or
+.Pa *.pem ;
+.It
+hashed symlinks as in
+.Xr openssl_rehash 1 ; and
+.It
+a single-file bundle
+.Pa ca-certificates.crt
+concatenating all the certificates in PEM format.
+.El
 .Pp
 .Nm
 treats
@@ -189,7 +205,9 @@ Add
 to the certificate search path.
 .Ar dir
 must be an absolute pathname,
-.Xr vis 3 Ns -encoded .
+.Xr vis 3 Ns -encoded
+if it has any characters outside the class
+.Ql "a-zA-Z0-9,.:=/+-" .
 .Pp
 All certificates must have unique base names across all directories
 in the certificate search path.
@@ -211,15 +229,15 @@ update
 .Sh FILES
 .Bl -tag -width Pa
 .It Pa /etc/openssl/certs
-Default directory of hashed HTTPS CA certificates.
+Default directory of hashed TLS CA certificates.
 .It Pa /etc/openssl/certs/ca-certificates.crt
-Default single-file HTTPS CA certificate bundle.
+Default single-file TLS CA certificate bundle.
 .It Pa /etc/openssl/certs.conf
-Default configuration file for HTTPS CA certificates.
+Default configuration file for TLS CA certificates.
 .It Pa /etc/openssl/untrusted
 Default
 .Ar untrusted
-directory of excluded HTTPS CA certificates.
+directory of excluded TLS CA certificates.
 .It Pa /usr/share/certs/mozilla/all
 All root CA certificates published by Mozilla, including untrustworthy
 certificates.
@@ -229,7 +247,7 @@ All root CA certificates published by Mo
 All root CA certificates published by Mozilla for use in email
 authentication.
 .It Pa /usr/share/certs/mozilla/server
-All root CA certificates published by Mozilla for use in HTTPS server
+All root CA certificates published by Mozilla for use in TLS server
 authentication.
 .El
 .\"



CVS commit: src/usr.sbin/certctl

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:41:17 UTC 2023

Modified Files:
src/usr.sbin/certctl: certctl.8

Log Message:
certctl(8): Minor man page clarifications.

- Specify exactly what /etc/openssl/certs gets populated with.
- Change HTTPS to TLS.
- Specify the permitted character class in certs.conf.
  (Maybe more conservative than strictly needed; but let's stay on
  the safe side.)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/certctl/certctl.8

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



CVS commit: src/share/man/man7

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:40:45 UTC 2023

Modified Files:
src/share/man/man7: hier.7

Log Message:
hier(7): Document /etc/openssl.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/share/man/man7/hier.7

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

Modified files:

Index: src/share/man/man7/hier.7
diff -u src/share/man/man7/hier.7:1.140 src/share/man/man7/hier.7:1.141
--- src/share/man/man7/hier.7:1.140	Tue May 12 10:20:16 2020
+++ src/share/man/man7/hier.7	Sat Sep  2 17:40:45 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: hier.7,v 1.140 2020/05/12 10:20:16 leot Exp $
+.\"	$NetBSD: hier.7,v 1.141 2023/09/02 17:40:45 riastradh Exp $
 .\"
 .\" Copyright (c) 1990, 1993, 1994
 .\"	The Regents of the University of California.  All rights reserved.
@@ -258,6 +258,52 @@ Network groups; see
 .It Pa networks
 Network name database; see
 .Xr networks 5 .
+.It Pa openssl/
+OpenSSL TLS trust anchors, configuration file, private keys, and
+more.
+Returned by
+.Xr X509_get_default_cert_area 3 .
+.Bl -tag -width "certs/" -compact
+.It Pa certs/
+Hashed directory of trust anchors for TLS certificate validation.
+Managed by
+.Xr certctl 8
+according to
+.Pa certs.conf .
+See
+.Xr openssl_rehash 1 .
+Returned by
+.Xr X509_get_default_cert_dir 3 .
+.It Pa certs/ca-certificates.crt
+Bundle of TLS anchors in PEM format formed by concatenation of
+PEM-format certificates.
+Managed by
+.Xr certctl 8
+according to
+.Pa certs.conf .
+.It Pa certs.conf
+Configuration file for
+.Xr certctl 8 .
+.It Pa misc/
+Miscellaneous OpenSSL scripts.
+Unused in
+.Nx
+base.
+.It Pa openssl.cnf
+Optional default OpenSSL configuration file.
+See
+.Xr openssl_config 5 .
+Returned by
+.Xr CONF_get1_default_config_file 3 .
+.It Pa private/
+Private key area.
+Read/write/execute permitted only by root.
+Unused in
+.Nx
+base.
+Returned by
+.Xr X509_get_default_private_dir 3 .
+.El
 .It Pa passwd
 World readable password file generated from master.passwd; see
 .Xr passwd 5 ,



CVS commit: src/share/man/man7

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:40:45 UTC 2023

Modified Files:
src/share/man/man7: hier.7

Log Message:
hier(7): Document /etc/openssl.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/share/man/man7/hier.7

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



CVS commit: src/external/mpl/mozilla-certdata/share

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:39:52 UTC 2023

Modified Files:
src/external/mpl/mozilla-certdata/share: Makefile

Log Message:
mozilla-certdata: Install relative symlinks.

Slightly more compact this way, and you can examine them in a destdir
without chrooting.  Not terribly important, but a minor convenience.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/external/mpl/mozilla-certdata/share/Makefile

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

Modified files:

Index: src/external/mpl/mozilla-certdata/share/Makefile
diff -u src/external/mpl/mozilla-certdata/share/Makefile:1.1 src/external/mpl/mozilla-certdata/share/Makefile:1.2
--- src/external/mpl/mozilla-certdata/share/Makefile:1.1	Sat Aug 26 05:47:53 2023
+++ src/external/mpl/mozilla-certdata/share/Makefile	Sat Sep  2 17:39:52 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.1 2023/08/26 05:47:53 riastradh Exp $
+#	$NetBSD: Makefile,v 1.2 2023/09/02 17:39:52 riastradh Exp $
 #
 
 MOZCERTS=	/usr/share/certs/mozilla
@@ -16,7 +16,7 @@ FILES+=		${CERTS}
 .for D in ${TRUSTDOMAINS}
 $D_CERTS!=	cat ${.CURDIR:Q}/$D.trust
 .  for C in ${$D_CERTS}
-SYMLINKS+=	${MOZCERTS}/all/$C.pem ${MOZCERTS}/$D/$C.pem
+SYMLINKS+=	../all/$C.pem ${MOZCERTS}/$D/$C.pem
 .  endfor
 .endfor
 



CVS commit: src/etc/mtree

2023-09-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  2 17:39:43 UTC 2023

Modified Files:
src/etc/mtree: special

Log Message:
etc/mtree/special: Fix spaces/tabs.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.177 -r1.178 src/etc/mtree/special

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

Modified files:

Index: src/etc/mtree/special
diff -u src/etc/mtree/special:1.177 src/etc/mtree/special:1.178
--- src/etc/mtree/special:1.177	Wed Aug 30 08:09:38 2023
+++ src/etc/mtree/special	Sat Sep  2 17:39:43 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: special,v 1.177 2023/08/30 08:09:38 martin Exp $
+#	$NetBSD: special,v 1.178 2023/09/02 17:39:43 riastradh Exp $
 #	@(#)special	8.2 (Berkeley) 1/23/94
 #
 # This file may be overwritten on upgrades.
@@ -134,7 +134,7 @@
 ./etc/nsswitch.conf		type=file mode=0644
 ./etc/ntp.conf			type=file mode=0644 optional
 ./etc/openssl			type=dir  mode=0755
-./etc/openssl/certs.conftype=file mode=0644
+./etc/openssl/certs.conf	type=file mode=0644
 ./etc/pam.conf			type=file mode=0644 optional
 ./etc/pam.d			type=dir  mode=0755
 ./etc/pam.d/display_manager	type=file mode=0644



CVS commit: [netbsd-10] src/doc

2023-09-02 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Sep  2 16:20:28 UTC 2023

Modified Files:
src/doc [netbsd-10]: CHANGES-10.0

Log Message:
Ticket #341


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.113 -r1.1.2.114 src/doc/CHANGES-10.0

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

Modified files:

Index: src/doc/CHANGES-10.0
diff -u src/doc/CHANGES-10.0:1.1.2.113 src/doc/CHANGES-10.0:1.1.2.114
--- src/doc/CHANGES-10.0:1.1.2.113	Wed Aug 23 18:21:39 2023
+++ src/doc/CHANGES-10.0	Sat Sep  2 16:20:27 2023
@@ -1,4 +1,4 @@
-# $NetBSD: CHANGES-10.0,v 1.1.2.113 2023/08/23 18:21:39 martin Exp $
+# $NetBSD: CHANGES-10.0,v 1.1.2.114 2023/09/02 16:20:27 martin Exp $
 
 A complete list of changes from the initial NetBSD 10.0 branch on 2022-12-16
 until the 10.0 release:
@@ -11258,3 +11258,8 @@ sys/net/npf/npf_ruleset.c			1.52
 	npf(7): PR 56990: fix handling of dynamic groups.
 	[kardel, ticket #340]
 
+sys/arch/newsmips/apbus/if_sn.c			1.53
+
+	newsmips: fix build with SNDEBUG option enabled.
+	[andvar, ticket #341]
+



CVS commit: [netbsd-10] src/doc

2023-09-02 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Sep  2 16:20:28 UTC 2023

Modified Files:
src/doc [netbsd-10]: CHANGES-10.0

Log Message:
Ticket #341


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.113 -r1.1.2.114 src/doc/CHANGES-10.0

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



CVS commit: [netbsd-10] src/sys/arch/newsmips/apbus

2023-09-02 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Sep  2 16:19:35 UTC 2023

Modified Files:
src/sys/arch/newsmips/apbus [netbsd-10]: if_sn.c

Log Message:
Pull up following revision(s) (requested by andvar in ticket #341):

sys/arch/newsmips/apbus/if_sn.c: revision 1.53

newsmips: fix build with SNDEBUG option enabled.

It was broken since rev 1.21 24 years ago, and got more broken code later on:
remove leftover device_xname(sc->sc_dev) param from aprint_debug_dev
in one block.
fix wrong method name devoce_xname to device_xname in second block.
rename et to eh for consistency, and define it (definition was removed
in the past).
while here, improve the code with riastradh help to make it safer.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.52.4.1 src/sys/arch/newsmips/apbus/if_sn.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/arch/newsmips/apbus/if_sn.c
diff -u src/sys/arch/newsmips/apbus/if_sn.c:1.52 src/sys/arch/newsmips/apbus/if_sn.c:1.52.4.1
--- src/sys/arch/newsmips/apbus/if_sn.c:1.52	Sun Sep 18 12:49:34 2022
+++ src/sys/arch/newsmips/apbus/if_sn.c	Sat Sep  2 16:19:35 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_sn.c,v 1.52 2022/09/18 12:49:34 thorpej Exp $	*/
+/*	$NetBSD: if_sn.c,v 1.52.4.1 2023/09/02 16:19:35 martin Exp $	*/
 
 /*
  * National Semiconductor  DP8393X SONIC Driver
@@ -16,7 +16,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_sn.c,v 1.52 2022/09/18 12:49:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_sn.c,v 1.52.4.1 2023/09/02 16:19:35 martin Exp $");
 
 #include "opt_inet.h"
 
@@ -202,7 +202,7 @@ snsetup(struct sn_softc	*sc, uint8_t *ll
 
 #ifdef SNDEBUG
 	aprint_debug_dev(sc->sc_dev, "buffers: rra=%p cda=%p rda=%p tda=%p\n",
-	device_xname(sc->sc_dev), sc->p_rra[0], sc->p_cda,
+	sc->p_rra[0], sc->p_cda,
 	sc->p_rda, sc->mtda[0].mtd_txp);
 #endif
 
@@ -1033,15 +1033,6 @@ sonic_read(struct sn_softc *sc, void *pk
 	struct ifnet *ifp = >sc_if;
 	struct mbuf *m;
 
-#ifdef SNDEBUG
-	{
-		printf("%s: rcvd %p len=%d type=0x%x from %s",
-		devoce_xname(sc->sc_dev), et, len, htons(et->ether_type),
-		ether_sprintf(et->ether_shost));
-		printf(" (to %s)\n", ether_sprintf(et->ether_dhost));
-	}
-#endif /* SNDEBUG */
-
 	if (len < (ETHER_MIN_LEN - ETHER_CRC_LEN) ||
 	len > (ETHER_MAX_LEN - ETHER_CRC_LEN)) {
 		printf("%s: invalid packet length %d bytes\n",
@@ -1049,6 +1040,18 @@ sonic_read(struct sn_softc *sc, void *pk
 		return 0;
 	}
 
+#ifdef SNDEBUG
+	{   
+		struct ether_header eh_s, *eh = _s;
+		memcpy(eh, pkt, sizeof(*eh));
+		CTASSERT(sizeof(*eh) <= ETHER_MIN_LEN);
+		printf("%s: rcvd %p len=%d type=0x%x from %s",
+		device_xname(sc->sc_dev), eh, len, htons(eh->ether_type),
+		ether_sprintf(eh->ether_shost));
+		printf(" (to %s)\n", ether_sprintf(eh->ether_dhost));
+	}   
+#endif /* SNDEBUG */
+
 	m = sonic_get(sc, pkt, len);
 	if (m == NULL)
 		return 0;



CVS commit: [netbsd-10] src/sys/arch/newsmips/apbus

2023-09-02 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Sep  2 16:19:35 UTC 2023

Modified Files:
src/sys/arch/newsmips/apbus [netbsd-10]: if_sn.c

Log Message:
Pull up following revision(s) (requested by andvar in ticket #341):

sys/arch/newsmips/apbus/if_sn.c: revision 1.53

newsmips: fix build with SNDEBUG option enabled.

It was broken since rev 1.21 24 years ago, and got more broken code later on:
remove leftover device_xname(sc->sc_dev) param from aprint_debug_dev
in one block.
fix wrong method name devoce_xname to device_xname in second block.
rename et to eh for consistency, and define it (definition was removed
in the past).
while here, improve the code with riastradh help to make it safer.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.52.4.1 src/sys/arch/newsmips/apbus/if_sn.c

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



CVS commit: src/libexec/ftpd

2023-09-02 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sat Sep  2 12:16:29 UTC 2023

Modified Files:
src/libexec/ftpd: ftpd.c version.h

Log Message:
ftpd: improve seteuid error handling

Handle seteuid() failures. Per suggestion by Simon Josefsson.
Consistent logging and fatal exit if uid/gid switching fails.
Log correct errno if dataconn() fails.


To generate a diff of this commit:
cvs rdiff -u -r1.206 -r1.207 src/libexec/ftpd/ftpd.c
cvs rdiff -u -r1.77 -r1.78 src/libexec/ftpd/version.h

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



CVS commit: src/libexec/ftpd

2023-09-02 Thread Luke Mewburn
 c
 		if (file == NULL) {
 			char hbuf[NI_MAXHOST];
 			char pbuf[NI_MAXSERV];
-
+			conerrno = errno;
 			if (getnameinfo((struct sockaddr *)_source.si_su,
 			data_source.su_len, hbuf, sizeof(hbuf), pbuf,
 			sizeof(pbuf), NI_NUMERICHOST | NI_NUMERICSERV))
 strlcpy(hbuf, "?", sizeof(hbuf));
 			reply(425, "Can't create data socket (%s,%s): %s.",
-			  hbuf, pbuf, strerror(errno));
+			  hbuf, pbuf, strerror(conerrno));
 			return (NULL);
 		}
 		data = fileno(file);

Index: src/libexec/ftpd/version.h
diff -u src/libexec/ftpd/version.h:1.77 src/libexec/ftpd/version.h:1.78
--- src/libexec/ftpd/version.h:1.77	Sat Jul  4 01:20:42 2020
+++ src/libexec/ftpd/version.h	Sat Sep  2 12:16:29 2023
@@ -1,6 +1,6 @@
-/*	$NetBSD: version.h,v 1.77 2020/07/04 01:20:42 lukem Exp $	*/
+/*	$NetBSD: version.h,v 1.78 2023/09/02 12:16:29 lukem Exp $	*/
 /*-
- * Copyright (c) 1999-2020 The NetBSD Foundation, Inc.
+ * Copyright (c) 1999-2023 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -29,5 +29,5 @@
  */
 
 #ifndef FTPD_VERSION
-#define	FTPD_VERSION	"NetBSD-ftpd 20200615"
+#define	FTPD_VERSION	"NetBSD-ftpd 20230902"
 #endif



CVS commit: src/share/mk

2023-09-02 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sat Sep  2 12:09:10 UTC 2023

Modified Files:
src/share/mk: bsd.own.mk

Log Message:
bsd.own.mk: sort the CC_WNO variables


To generate a diff of this commit:
cvs rdiff -u -r1.1359 -r1.1360 src/share/mk/bsd.own.mk

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

Modified files:

Index: src/share/mk/bsd.own.mk
diff -u src/share/mk/bsd.own.mk:1.1359 src/share/mk/bsd.own.mk:1.1360
--- src/share/mk/bsd.own.mk:1.1359	Thu Aug 24 06:18:07 2023
+++ src/share/mk/bsd.own.mk	Sat Sep  2 12:09:10 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: bsd.own.mk,v 1.1359 2023/08/24 06:18:07 rin Exp $
+#	$NetBSD: bsd.own.mk,v 1.1360 2023/09/02 12:09:10 lukem Exp $
 
 # This needs to be before bsd.init.mk
 .if defined(BSD_MK_COMPAT_FILE)
@@ -686,18 +686,18 @@ OBJC=		${TOOL_OBJC.${ACTIVE_OBJC}}
 CC_WNO_ADDRESS_OF_PACKED_MEMBER=${${ACTIVE_CC} == "clang" :? -Wno-error=address-of-packed-member :} \
 ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 9:? -Wno-address-of-packed-member :}
 
+CC_WNO_ARRAY_BOUNDS=		${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 12:? -Wno-array-bounds :}
 CC_WNO_CAST_FUNCTION_TYPE=	${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 8:? -Wno-cast-function-type :}
 CC_WNO_FORMAT_OVERFLOW=		${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 7:? -Wno-format-overflow :}
 CC_WNO_FORMAT_TRUNCATION=	${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 7:? -Wno-format-truncation :}
 CC_WNO_IMPLICIT_FALLTHROUGH=	${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 7:? -Wno-implicit-fallthrough :}
 CC_WNO_MAYBE_UNINITIALIZED=	${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-maybe-uninitialized :}
+CC_WNO_MISSING_TEMPLATE_KEYWORD=${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 12:? -Wno-missing-template-keyword :}
+CC_WNO_REGISTER=		${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 12:? -Wno-register :}
 CC_WNO_RETURN_LOCAL_ADDR=	${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-return-local-addr :}
 CC_WNO_STRINGOP_OVERFLOW=	${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 7:? -Wno-stringop-overflow :}
-CC_WNO_STRINGOP_TRUNCATION=	${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 8:? -Wno-stringop-truncation :}
-CC_WNO_MISSING_TEMPLATE_KEYWORD=${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 12:? -Wno-missing-template-keyword :}
 CC_WNO_STRINGOP_OVERREAD=	${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 12:? -Wno-stringop-overread :}
-CC_WNO_REGISTER=		${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 12:? -Wno-register :}
-CC_WNO_ARRAY_BOUNDS=		${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 12:? -Wno-array-bounds :}
+CC_WNO_STRINGOP_TRUNCATION=	${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 8:? -Wno-stringop-truncation :}
 
 # For each ${MACHINE_CPU}, list the ports that use it.
 MACHINES.aarch64=	evbarm



CVS commit: src/share/mk

2023-09-02 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sat Sep  2 12:09:10 UTC 2023

Modified Files:
src/share/mk: bsd.own.mk

Log Message:
bsd.own.mk: sort the CC_WNO variables


To generate a diff of this commit:
cvs rdiff -u -r1.1359 -r1.1360 src/share/mk/bsd.own.mk

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



CVS commit: src/sys/arch/riscv/dev

2023-09-02 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Sep  2 09:58:15 UTC 2023

Modified Files:
src/sys/arch/riscv/dev: plic.c plic_fdt.c plicvar.h

Log Message:
Be clear about hart vs cpu. NFCI.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/riscv/dev/plic.c \
src/sys/arch/riscv/dev/plicvar.h
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/riscv/dev/plic_fdt.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/arch/riscv/dev/plic.c
diff -u src/sys/arch/riscv/dev/plic.c:1.1 src/sys/arch/riscv/dev/plic.c:1.2
--- src/sys/arch/riscv/dev/plic.c:1.1	Sun May  7 12:41:48 2023
+++ src/sys/arch/riscv/dev/plic.c	Sat Sep  2 09:58:15 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: plic.c,v 1.1 2023/05/07 12:41:48 skrll Exp $ */
+/* $NetBSD: plic.c,v 1.2 2023/09/02 09:58:15 skrll Exp $ */
 
 /*-
  * Copyright (c) 2022 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include "opt_multiprocessor.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: plic.c,v 1.1 2023/05/07 12:41:48 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: plic.c,v 1.2 2023/09/02 09:58:15 skrll Exp $");
 
 #include 
 
@@ -46,15 +46,15 @@ __KERNEL_RCSID(0, "$NetBSD: plic.c,v 1.1
 
 #define	PLIC_PRIORITY(irq)	(PLIC_PRIORITY_BASE + (irq) * 4)
 
-#define	PLIC_ENABLE(sc, c, irq)	(PLIC_ENABLE_BASE +		 	   \
- sc->sc_context[(c)] * PLIC_ENABLE_SIZE +  \
+#define	PLIC_ENABLE(sc, h, irq)	(PLIC_ENABLE_BASE +		 	   \
+ sc->sc_context[(h)] * PLIC_ENABLE_SIZE +  \
  ((irq / 32) * sizeof(uint32_t)))
 
-#define	PLIC_CONTEXT(sc, c)	(PLIC_CONTEXT_BASE +			\
- sc->sc_context[(c)] * PLIC_CONTEXT_SIZE)
-#define	PLIC_CLAIM(sc, c)	(PLIC_CONTEXT(sc, c) + PLIC_CLAIM_COMPLETE_OFFS)
-#define	PLIC_COMPLETE(sc, c)	PLIC_CLAIM(sc, c)	/* same address */
-#define	PLIC_THRESHOLD(sc, c)	(PLIC_CONTEXT(sc, c) + PLIC_THRESHOLD_OFFS)
+#define	PLIC_CONTEXT(sc, h)	(PLIC_CONTEXT_BASE +			\
+ sc->sc_context[(h)] * PLIC_CONTEXT_SIZE)
+#define	PLIC_CLAIM(sc, h)	(PLIC_CONTEXT(sc, h) + PLIC_CLAIM_COMPLETE_OFFS)
+#define	PLIC_COMPLETE(sc, h)	PLIC_CLAIM(sc, h)	/* same address */
+#define	PLIC_THRESHOLD(sc, h)	(PLIC_CONTEXT(sc, h) + PLIC_THRESHOLD_OFFS)
 
 #define	PLIC_READ(sc, reg)		\
 	bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
@@ -72,9 +72,11 @@ plic_intr_establish_xname(u_int irq, int
 	struct plic_softc * const sc = plic_sc;
 	struct plic_intrhand *ih;
 
-	/* XXX need a better CPU selection method */
-//	u_int cidx = cpu_index(curcpu());
-	u_int cidx = 0;
+	/*
+	 * Choose hart 0.
+	 * XXX need a better hart selection method
+	 */
+	u_int hartid = 0;
 
 	evcnt_attach_dynamic(>sc_intrevs[irq], EVCNT_TYPE_INTR, NULL,
 	"plic", xname);
@@ -90,10 +92,10 @@ plic_intr_establish_xname(u_int irq, int
 	ih->ih_func = func;
 	ih->ih_arg = arg;
 	ih->ih_irq = irq;
-	ih->ih_cidx = cidx;
+	ih->ih_hartid = hartid;
 
 	plic_set_priority(sc, irq, 1);
-	plic_enable(sc, cidx, irq);
+	plic_enable(sc, hartid, irq);
 
 	return ih;
 }
@@ -103,10 +105,10 @@ plic_intr_disestablish(void *cookie)
 {
 	struct plic_softc * const sc = plic_sc;
 	struct plic_intrhand * const ih = cookie;
-	const u_int cidx = ih->ih_cidx;
+	const u_int hartid = ih->ih_hartid;
 	const u_int irq = ih->ih_irq;
 
-	plic_disable(sc, cidx, irq);
+	plic_disable(sc, hartid, irq);
 	plic_set_priority(sc, irq, 0);
 
 	memset(>sc_intr[irq], 0, sizeof(*sc->sc_intr));
@@ -116,9 +118,9 @@ int
 plic_intr(void *arg)
 {
 	struct plic_softc * const sc = arg;
-	const cpuid_t cpuid = cpu_number();
-	const bus_addr_t claim_addr = PLIC_CLAIM(sc, cpuid);
-	const bus_addr_t complete_addr = PLIC_COMPLETE(sc, cpuid);
+	const cpuid_t hartid = cpu_number();
+	const bus_addr_t claim_addr = PLIC_CLAIM(sc, hartid);
+	const bus_addr_t complete_addr = PLIC_COMPLETE(sc, hartid);
 	uint32_t pending;
 	int rv = 0;
 
@@ -144,22 +146,23 @@ plic_intr(void *arg)
 }
 
 void
-plic_enable(struct plic_softc *sc, u_int cpu, u_int irq)
+plic_enable(struct plic_softc *sc, u_int hartid, u_int irq)
 {
 	KASSERT(irq < PLIC_NIRQ);
-	const bus_addr_t addr = PLIC_ENABLE(sc, cpu, irq);
+	const bus_addr_t addr = PLIC_ENABLE(sc, hartid, irq);
 	const uint32_t mask = __BIT(irq % 32);
 
 	uint32_t reg = PLIC_READ(sc, addr);
 	reg |= mask;
+
 	PLIC_WRITE(sc, addr, reg);
 }
 
 void
-plic_disable(struct plic_softc *sc, u_int cpu, u_int irq)
+plic_disable(struct plic_softc *sc, u_int hartid, u_int irq)
 {
 	KASSERT(irq < PLIC_NIRQ);
-	const bus_addr_t addr = PLIC_ENABLE(sc, cpu, irq);
+	const bus_addr_t addr = PLIC_ENABLE(sc, hartid, irq);
 	const uint32_t mask = __BIT(irq % 32);
 
 	uint32_t reg = PLIC_READ(sc, addr);
@@ -177,9 +180,9 @@ plic_set_priority(struct plic_softc *sc,
 }
 
 void
-plic_set_threshold(struct plic_softc *sc, cpuid_t cpu, uint32_t threshold)
+plic_set_threshold(struct plic_softc *sc, cpuid_t hartid, uint32_t threshold)
 {
-	const bus_addr_t addr = PLIC_THRESHOLD(sc, cpu);
+	const bus_addr_t addr = PLIC_THRESHOLD(sc, 

CVS commit: src/sys/arch/riscv/dev

2023-09-02 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Sep  2 09:58:15 UTC 2023

Modified Files:
src/sys/arch/riscv/dev: plic.c plic_fdt.c plicvar.h

Log Message:
Be clear about hart vs cpu. NFCI.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/riscv/dev/plic.c \
src/sys/arch/riscv/dev/plicvar.h
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/riscv/dev/plic_fdt.c

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



CVS commit: src/sys/arch/riscv/dev

2023-09-02 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Sep  2 09:29:59 UTC 2023

Modified Files:
src/sys/arch/riscv/dev: plic_fdt.c

Log Message:
Simplify plic_fdt_intr_disestablish by calling plic_intr_disestablish


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/riscv/dev/plic_fdt.c

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



CVS commit: src/sys/arch/riscv/include

2023-09-02 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Sep  2 09:27:09 UTC 2023

Modified Files:
src/sys/arch/riscv/include: db_machdep.h

Log Message:
Fix a comment and enable RISC-V ddb mach commands


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/riscv/include/db_machdep.h

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



CVS commit: src/sys/arch/riscv/dev

2023-09-02 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Sep  2 09:29:59 UTC 2023

Modified Files:
src/sys/arch/riscv/dev: plic_fdt.c

Log Message:
Simplify plic_fdt_intr_disestablish by calling plic_intr_disestablish


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/riscv/dev/plic_fdt.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/arch/riscv/dev/plic_fdt.c
diff -u src/sys/arch/riscv/dev/plic_fdt.c:1.1 src/sys/arch/riscv/dev/plic_fdt.c:1.2
--- src/sys/arch/riscv/dev/plic_fdt.c:1.1	Sun May  7 12:41:48 2023
+++ src/sys/arch/riscv/dev/plic_fdt.c	Sat Sep  2 09:29:59 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: plic_fdt.c,v 1.1 2023/05/07 12:41:48 skrll Exp $ */
+/* $NetBSD: plic_fdt.c,v 1.2 2023/09/02 09:29:59 skrll Exp $ */
 
 /*-
  * Copyright (c) 2022 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: plic_fdt.c,v 1.1 2023/05/07 12:41:48 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: plic_fdt.c,v 1.2 2023/09/02 09:29:59 skrll Exp $");
 
 #include 
 
@@ -70,18 +70,12 @@ plic_fdt_intr_establish(device_t dev, u_
 
 	return ih;
 }
+
 static void
 plic_fdt_intr_disestablish(device_t dev, void *cookie)
 {
-	struct plic_softc * const sc = device_private(dev);
-	struct plic_intrhand * const ih = cookie;
-	const u_int cidx = ih->ih_cidx;
-	const u_int irq = ih->ih_irq;
-
-	plic_disable(sc, cidx, irq);
-	plic_set_priority(sc, irq, 0);
 
-	memset(>sc_intr[irq], 0, sizeof(*sc->sc_intr));
+	plic_intr_disestablish(cookie);
 }
 
 



CVS commit: src/sys/arch/riscv/include

2023-09-02 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Sep  2 09:27:09 UTC 2023

Modified Files:
src/sys/arch/riscv/include: db_machdep.h

Log Message:
Fix a comment and enable RISC-V ddb mach commands


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/riscv/include/db_machdep.h

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

Modified files:

Index: src/sys/arch/riscv/include/db_machdep.h
diff -u src/sys/arch/riscv/include/db_machdep.h:1.8 src/sys/arch/riscv/include/db_machdep.h:1.9
--- src/sys/arch/riscv/include/db_machdep.h:1.8	Mon Jun 12 19:04:14 2023
+++ src/sys/arch/riscv/include/db_machdep.h	Sat Sep  2 09:27:09 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: db_machdep.h,v 1.8 2023/06/12 19:04:14 skrll Exp $ */
+/* $NetBSD: db_machdep.h,v 1.9 2023/09/02 09:27:09 skrll Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -107,7 +107,7 @@ typedef	register_t	kgdb_reg_t;
 #define	KGDB_BUFLEN	1024
 
 /*
- * RISCV cpus have no hardware single-step.
+ * RISC-V harts have no hardware single-step.
  */
 #define	SOFTWARE_SSTEP
 
@@ -126,12 +126,10 @@ bool ddb_running_on_this_cpu_p(void);
 bool ddb_running_on_any_cpu_p(void);
 void db_resume_others(void);
 
-#if 0
 /*
  * We have machine-dependent commands.
  */
 #define	DB_MACHINE_COMMANDS
-#endif
 
 void dump_trapframe(const struct trapframe *, void (*)(const char *, ...) __printflike(1, 2));
 



CVS commit: src/sys/arch

2023-09-02 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Sat Sep  2 07:15:30 UTC 2023

Modified Files:
src/sys/arch/amd64/conf: ALL
src/sys/arch/i386/conf: ALL
src/sys/arch/newsmips/apbus: if_sn.c

Log Message:
newsmips/sn(4): rename SONIC_DEBUG to SNDEBUG for consistency.

nix this option from i386/amd64 ALL configs, it isn't used anywhere anymore.


To generate a diff of this commit:
cvs rdiff -u -r1.179 -r1.180 src/sys/arch/amd64/conf/ALL
cvs rdiff -u -r1.511 -r1.512 src/sys/arch/i386/conf/ALL
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/newsmips/apbus/if_sn.c

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



CVS commit: src/sys/arch

2023-09-02 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Sat Sep  2 07:15:30 UTC 2023

Modified Files:
src/sys/arch/amd64/conf: ALL
src/sys/arch/i386/conf: ALL
src/sys/arch/newsmips/apbus: if_sn.c

Log Message:
newsmips/sn(4): rename SONIC_DEBUG to SNDEBUG for consistency.

nix this option from i386/amd64 ALL configs, it isn't used anywhere anymore.


To generate a diff of this commit:
cvs rdiff -u -r1.179 -r1.180 src/sys/arch/amd64/conf/ALL
cvs rdiff -u -r1.511 -r1.512 src/sys/arch/i386/conf/ALL
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/newsmips/apbus/if_sn.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/arch/amd64/conf/ALL
diff -u src/sys/arch/amd64/conf/ALL:1.179 src/sys/arch/amd64/conf/ALL:1.180
--- src/sys/arch/amd64/conf/ALL:1.179	Tue Jul 18 10:02:25 2023
+++ src/sys/arch/amd64/conf/ALL	Sat Sep  2 07:15:30 2023
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.179 2023/07/18 10:02:25 riastradh Exp $
+# $NetBSD: ALL,v 1.180 2023/09/02 07:15:30 andvar Exp $
 # From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
 #
 # ALL machine description file
@@ -17,7 +17,7 @@ include 	"arch/amd64/conf/std.amd64"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident		"ALL-$Revision: 1.179 $"
+#ident		"ALL-$Revision: 1.180 $"
 
 maxusers	64		# estimated number of users
 
@@ -2201,7 +2201,6 @@ options SMB_VNODE_DEBUG
 options SNAPPER_DEBUG
 options SNDEBUG
 options SOCKBUF_DEBUG
-options SONIC_DEBUG
 options SPARC_PCI_DEBUG
 options SPC_DEBUG
 options SPIC_DEBUG

Index: src/sys/arch/i386/conf/ALL
diff -u src/sys/arch/i386/conf/ALL:1.511 src/sys/arch/i386/conf/ALL:1.512
--- src/sys/arch/i386/conf/ALL:1.511	Tue Jul 18 10:02:25 2023
+++ src/sys/arch/i386/conf/ALL	Sat Sep  2 07:15:30 2023
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.511 2023/07/18 10:02:25 riastradh Exp $
+# $NetBSD: ALL,v 1.512 2023/09/02 07:15:30 andvar Exp $
 # From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
 #
 # ALL machine description file
@@ -17,7 +17,7 @@ include 	"arch/i386/conf/std.i386"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident		"ALL-$Revision: 1.511 $"
+#ident		"ALL-$Revision: 1.512 $"
 
 maxusers	64		# estimated number of users
 
@@ -2298,7 +2298,6 @@ options SMB_VNODE_DEBUG
 options SNAPPER_DEBUG
 options SNDEBUG
 options SOCKBUF_DEBUG
-options SONIC_DEBUG
 options SPARC_PCI_DEBUG
 options SPC_DEBUG
 options SPIC_DEBUG

Index: src/sys/arch/newsmips/apbus/if_sn.c
diff -u src/sys/arch/newsmips/apbus/if_sn.c:1.54 src/sys/arch/newsmips/apbus/if_sn.c:1.55
--- src/sys/arch/newsmips/apbus/if_sn.c:1.54	Tue Aug 22 08:33:50 2023
+++ src/sys/arch/newsmips/apbus/if_sn.c	Sat Sep  2 07:15:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_sn.c,v 1.54 2023/08/22 08:33:50 andvar Exp $	*/
+/*	$NetBSD: if_sn.c,v 1.55 2023/09/02 07:15:30 andvar Exp $	*/
 
 /*
  * National Semiconductor  DP8393X SONIC Driver
@@ -16,7 +16,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_sn.c,v 1.54 2023/08/22 08:33:50 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_sn.c,v 1.55 2023/09/02 07:15:30 andvar Exp $");
 
 #include "opt_inet.h"
 
@@ -51,9 +51,9 @@ __KERNEL_RCSID(0, "$NetBSD: if_sn.c,v 1.
 #include 
 #include 
 
-/* #define SONIC_DEBUG */
+/* #define SNDEBUG */
 
-#ifdef SONIC_DEBUG
+#ifdef SNDEBUG
 # define DPRINTF printf
 #else
 # define DPRINTF while (0) printf