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

2021-09-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Sep  8 00:35:56 UTC 2021

Modified Files:
src/sys/arch/sh3/sh3: pmap.c

Log Message:
Misc cosmetic fixes:
- Remove redundant parentheses/braces/comments.
- Improve uniformity of panic messages. Also, use __func__ instead of
  hard-coded function names.
- Fix indents.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/arch/sh3/sh3/pmap.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/sh3/sh3/pmap.c
diff -u src/sys/arch/sh3/sh3/pmap.c:1.88 src/sys/arch/sh3/sh3/pmap.c:1.89
--- src/sys/arch/sh3/sh3/pmap.c:1.88	Wed Sep  8 00:24:29 2021
+++ src/sys/arch/sh3/sh3/pmap.c	Wed Sep  8 00:35:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.88 2021/09/08 00:24:29 rin Exp $	*/
+/*	$NetBSD: pmap.c,v 1.89 2021/09/08 00:35:56 rin Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.88 2021/09/08 00:24:29 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.89 2021/09/08 00:35:56 rin Exp $");
 
 #include 
 #include 
@@ -153,7 +153,7 @@ pmap_steal_memory(vsize_t size, vaddr_t 
 	va = SH3_PHYS_TO_P1SEG(pa);
 	memset((void *)va, 0, size);
 
-	return (va);
+	return va;
 }
 
 vaddr_t
@@ -162,7 +162,7 @@ pmap_growkernel(vaddr_t maxkvaddr)
 	int i, n;
 
 	if (maxkvaddr <= __pmap_kve)
-		return (__pmap_kve);
+		return __pmap_kve;
 
 	i = __PMAP_PTP_INDEX(__pmap_kve - VM_MIN_KERNEL_ADDRESS);
 	__pmap_kve = __PMAP_PTP_TRUNC(maxkvaddr);
@@ -190,9 +190,9 @@ pmap_growkernel(vaddr_t maxkvaddr)
 		}
 	}
 
-	return (__pmap_kve);
+	return __pmap_kve;
  error:
-	panic("pmap_growkernel: out of memory.");
+	panic("%s: out of memory", __func__);
 	/* NOTREACHED */
 }
 
@@ -248,7 +248,7 @@ pmap_create(void)
 		uvm_pagealloc(NULL, 0, NULL,
 			UVM_PGA_USERESERVE | UVM_PGA_ZERO)));
 
-	return (pmap);
+	return pmap;
 }
 
 void
@@ -271,7 +271,7 @@ pmap_destroy(pmap_t pmap)
 			for (j = 0; j < __PMAP_PTP_PG_N; j++, pte++)
 KDASSERT(*pte == 0);
 		}
-#endif /* DEBUG */
+#endif
 		/* Purge cache entry for next use of this page. */
 		if (SH_HAS_VIRTUAL_ALIAS)
 			sh_dcache_inv_range(va, PAGE_SIZE);
@@ -323,7 +323,7 @@ pmap_enter(pmap_t pmap, vaddr_t va, padd
 	struct vm_page *pg;
 	struct vm_page_md *pvh;
 	pt_entry_t entry, *pte;
-	bool kva = (pmap == pmap_kernel());
+	bool kva = pmap == pmap_kernel();
 
 	/* "flags" never exceed "prot" */
 	KDASSERT(prot != 0 && ((flags & VM_PROT_ALL) & ~prot) == 0);
@@ -362,24 +362,23 @@ pmap_enter(pmap_t pmap, vaddr_t va, padd
 
 		/* Check for existing mapping */
 		if (__pmap_map_change(pmap, va, pa, prot, entry))
-			return (0);
+			return 0;
 
 		/* Add to physical-virtual map list of this page */
 		if (__pmap_pv_enter(pmap, pg, va)) {
 			if (flags & PMAP_CANFAIL)
 return ENOMEM;
-			panic("%s: __pmap_pv_enter failed", __func__);
+			panic("%s: cannot allocate pv", __func__);
 		}
 	} else {	/* bus-space (always uncached map) */
-		if (kva) {
+		if (kva)
 			entry |= PG_V | PG_SH |
-			((prot & VM_PROT_WRITE) ?
-			(PG_PR_KRW | PG_D) : PG_PR_KRO);
-		} else {
+			(prot & VM_PROT_WRITE) ?
+			(PG_PR_KRW | PG_D) : PG_PR_KRO;
+		else
 			entry |= PG_V |
-			((prot & VM_PROT_WRITE) ?
-			(PG_PR_URW | PG_D) : PG_PR_URO);
-		}
+			(prot & VM_PROT_WRITE) ?
+			(PG_PR_URW | PG_D) : PG_PR_URO;
 	}
 
 	/* Register to page table */
@@ -393,7 +392,7 @@ pmap_enter(pmap_t pmap, vaddr_t va, padd
 	__pmap_pv_remove(pmap, pg, va);
 return ENOMEM;
 			}
-			panic("%s: __pmap_pte_alloc failed", __func__);
+			panic("%s: cannot allocate pte", __func__);
 		}
 	}
 
@@ -410,7 +409,7 @@ pmap_enter(pmap_t pmap, vaddr_t va, padd
 		pmap->pm_stats.wired_count++;
 	pmap->pm_stats.resident_count++;
 
-	return (0);
+	return 0;
 }
 
 /*
@@ -428,13 +427,13 @@ __pmap_map_change(pmap_t pmap, vaddr_t v
 	vaddr_t eva = va + PAGE_SIZE;
 
 	if ((pte = __pmap_pte_lookup(pmap, va)) == NULL ||
-	((oentry = *pte) == 0))
-		return (false);		/* no mapping exists. */
+	(oentry = *pte) == 0)
+		return false;		/* no mapping exists. */
 
 	if (pa != (oentry & PG_PPN)) {
 		/* Enter a mapping at a mapping to another physical page. */
 		pmap_remove(pmap, va, eva);
-		return (false);
+		return false;
 	}
 
 	/* Pre-existing mapping */
@@ -454,10 +453,10 @@ __pmap_map_change(pmap_t pmap, vaddr_t v
 	} else if (entry & _PG_WIRED) {
 		/* unwired -> wired. make sure to reflect "flags" */
 		pmap_remove(pmap, va, eva);
-		return (false);
+		return false;
 	}
 
-	return (true);	/* mapping was changed. */
+	return true;	/* mapping was changed. */
 }
 
 /*
@@ -575,7 +574,7 @@ __pmap_pv_remove(pmap_t pmap, struct vm_
 #ifdef DEBUG
 	/* Check duplicated map. */
 	SLIST_FOREACH(pv, >pvh_head, pv_link)
-	KDASSERT(!(pv->pv_pmap == pmap && pv->pv_va == vaddr));
+		KDASSERT(!(pv->pv_pmap == pmap && pv->pv_va == vaddr));
 #endif
 	

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

2021-09-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Sep  8 00:35:56 UTC 2021

Modified Files:
src/sys/arch/sh3/sh3: pmap.c

Log Message:
Misc cosmetic fixes:
- Remove redundant parentheses/braces/comments.
- Improve uniformity of panic messages. Also, use __func__ instead of
  hard-coded function names.
- Fix indents.


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

2021-09-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Sep  8 00:24:29 UTC 2021

Modified Files:
src/sys/arch/sh3/sh3: pmap.c

Log Message:
Turn KASSERT's added for PR port-sh3/56381 into KDASSERT's;
they are less likely expected to fire again.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/arch/sh3/sh3/pmap.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/sh3/sh3/pmap.c
diff -u src/sys/arch/sh3/sh3/pmap.c:1.87 src/sys/arch/sh3/sh3/pmap.c:1.88
--- src/sys/arch/sh3/sh3/pmap.c:1.87	Thu Sep  2 08:02:33 2021
+++ src/sys/arch/sh3/sh3/pmap.c	Wed Sep  8 00:24:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.87 2021/09/02 08:02:33 rin Exp $	*/
+/*	$NetBSD: pmap.c,v 1.88 2021/09/08 00:24:29 rin Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.87 2021/09/02 08:02:33 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.88 2021/09/08 00:24:29 rin Exp $");
 
 #include 
 #include 
@@ -737,10 +737,10 @@ pmap_page_protect(struct vm_page *pg, vm
 		while ((pv = SLIST_FIRST(>pvh_head)) != NULL) {
 			pmap = pv->pv_pmap;
 			va = pv->pv_va;
-#ifdef DIAGNOSTIC
+#ifdef DEBUG
 			pt_entry_t *pte = __pmap_pte_lookup(pmap, va);
-			KASSERT(pte != NULL);
-			KASSERT(*pte != 0);
+			KDASSERT(pte != NULL);
+			KDASSERT(*pte != 0);
 #endif
 			pmap_remove(pmap, va, va + PAGE_SIZE);
 		}



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

2021-09-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Sep  8 00:24:29 UTC 2021

Modified Files:
src/sys/arch/sh3/sh3: pmap.c

Log Message:
Turn KASSERT's added for PR port-sh3/56381 into KDASSERT's;
they are less likely expected to fire again.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/arch/sh3/sh3/pmap.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/powerpc/ibm4xx

2021-09-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Sep  8 00:17:21 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx: pmap.c

Log Message:
pte_enter() and pmap_enter_pv(): return zero for success, and
non-zero value for failure, as normally expected.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/arch/powerpc/ibm4xx/pmap.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/powerpc/ibm4xx/pmap.c
diff -u src/sys/arch/powerpc/ibm4xx/pmap.c:1.104 src/sys/arch/powerpc/ibm4xx/pmap.c:1.105
--- src/sys/arch/powerpc/ibm4xx/pmap.c:1.104	Sun Sep  5 12:47:10 2021
+++ src/sys/arch/powerpc/ibm4xx/pmap.c	Wed Sep  8 00:17:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.104 2021/09/05 12:47:10 rin Exp $	*/
+/*	$NetBSD: pmap.c,v 1.105 2021/09/08 00:17:21 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.104 2021/09/05 12:47:10 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.105 2021/09/08 00:17:21 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -235,13 +235,13 @@ pte_enter(struct pmap *pm, vaddr_t va, u
 	if (!pm->pm_ptbl[seg]) {
 		/* Don't allocate a page to clear a non-existent mapping. */
 		if (!pte)
-			return 1;
+			return 0;
 
 		vaddr_t km = uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
 		UVM_KMF_WIRED | UVM_KMF_ZERO | UVM_KMF_NOWAIT);
 
 		if (__predict_false(km == 0))
-			return 0;
+			return ENOMEM;
 
 		pm->pm_ptbl[seg] = (u_int *)km;
 	}
@@ -256,7 +256,7 @@ pte_enter(struct pmap *pm, vaddr_t va, u
 		else
 			pm->pm_stats.resident_count++;
 	}
-	return 1;
+	return 0;
 }
 
 /*
@@ -700,9 +700,6 @@ pmap_copy_page(paddr_t src, paddr_t dst)
 	dcache_wbinv_page(dst);
 }
 
-/*
- * This returns != 0 on success.
- */
 static inline int
 pmap_enter_pv(struct pmap *pm, vaddr_t va, paddr_t pa, int flags)
 {
@@ -731,7 +728,7 @@ pmap_enter_pv(struct pmap *pm, vaddr_t v
 			if ((flags & PMAP_CANFAIL) == 0)
 panic("pmap_enter_pv: failed");
 			splx(s);
-			return 0;
+			return ENOMEM;
 		}
 		npv->pv_va = va;
 		npv->pv_pm = pm;
@@ -746,7 +743,7 @@ pmap_enter_pv(struct pmap *pm, vaddr_t v
 
 	splx(s);
 
-	return 1;
+	return 0;
 }
 
 static void
@@ -849,7 +846,7 @@ pmap_enter(struct pmap *pm, vaddr_t va, 
 	if (pmap_initialized && managed) {
 		char *attr;
 
-		if (!pmap_enter_pv(pm, va, pa, flags)) {
+		if (pmap_enter_pv(pm, va, pa, flags)) {
 			/* Could not enter pv on a managed page */
 			return ENOMEM;
 		}
@@ -866,7 +863,7 @@ pmap_enter(struct pmap *pm, vaddr_t va, 
 	s = splvm();
 
 	/* Insert page into page table. */
-	if (__predict_false(!pte_enter(pm, va, tte))) {
+	if (__predict_false(pte_enter(pm, va, tte))) {
 		if (__predict_false((flags & PMAP_CANFAIL) == 0))
 			panic("%s: pte_enter", __func__);
 		splx(s);
@@ -961,7 +958,7 @@ pmap_kenter_pa(vaddr_t va, paddr_t pa, v
 	s = splvm();
 
 	/* Insert page into page table. */
-	if (__predict_false(!pte_enter(pm, va, tte)))
+	if (__predict_false(pte_enter(pm, va, tte)))
 		panic("%s: pte_enter", __func__);
 
 	splx(s);



CVS commit: src/sys/arch/powerpc/ibm4xx

2021-09-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Sep  8 00:17:21 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx: pmap.c

Log Message:
pte_enter() and pmap_enter_pv(): return zero for success, and
non-zero value for failure, as normally expected.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/arch/powerpc/ibm4xx/pmap.c

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



CVS commit: [netbsd-9] src/doc

2021-09-07 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Sep  7 22:30:10 UTC 2021

Modified Files:
src/doc [netbsd-9]: CHANGES-9.3

Log Message:
1344


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.27 -r1.1.2.28 src/doc/CHANGES-9.3

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-9.3
diff -u src/doc/CHANGES-9.3:1.1.2.27 src/doc/CHANGES-9.3:1.1.2.28
--- src/doc/CHANGES-9.3:1.1.2.27	Tue Sep  7 17:13:20 2021
+++ src/doc/CHANGES-9.3	Tue Sep  7 22:30:10 2021
@@ -1,4 +1,4 @@
-# $NetBSD: CHANGES-9.3,v 1.1.2.27 2021/09/07 17:13:20 martin Exp $
+# $NetBSD: CHANGES-9.3,v 1.1.2.28 2021/09/07 22:30:10 snj Exp $
 
 A complete list of changes from the NetBSD 9.2 release to the NetBSD 9.3
 release:
@@ -635,3 +635,9 @@ sys/kern/vfs_lockf.c1.74
 	Tie the maximum file lock per unprivilegied uid to kern.maxfiles.
 	[manu, ticket #1343]
 
+distrib/sets/makesrctars			1.43
+
+	PR 56389: do not include top level .git or .hg directories
+	in source sets.
+	[martin, ticket #1344]
+



CVS commit: [netbsd-9] src/doc

2021-09-07 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Sep  7 22:30:10 UTC 2021

Modified Files:
src/doc [netbsd-9]: CHANGES-9.3

Log Message:
1344


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.27 -r1.1.2.28 src/doc/CHANGES-9.3

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



CVS commit: [netbsd-9] src/distrib/sets

2021-09-07 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Sep  7 22:29:46 UTC 2021

Modified Files:
src/distrib/sets [netbsd-9]: makesrctars

Log Message:
Pull up following revision(s) (requested by martin in ticket #1344):
distrib/sets/makesrctars: revision 1.43
PR 56389: do not include top level .git or .hg directories
in source sets.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.42.2.1 src/distrib/sets/makesrctars

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

Modified files:

Index: src/distrib/sets/makesrctars
diff -u src/distrib/sets/makesrctars:1.42 src/distrib/sets/makesrctars:1.42.2.1
--- src/distrib/sets/makesrctars:1.42	Fri Sep 28 15:04:20 2018
+++ src/distrib/sets/makesrctars	Tue Sep  7 22:29:46 2021
@@ -1,6 +1,6 @@
 #! /bin/sh
 #
-#	$NetBSD: makesrctars,v 1.42 2018/09/28 15:04:20 martin Exp $
+#	$NetBSD: makesrctars,v 1.42.2.1 2021/09/07 22:29:46 snj Exp $
 #
 # makesrctars srcdir setdir
 #	Create source tarballs in setdir from the source under srcdir.
@@ -84,8 +84,10 @@ makeset()
 		cd "${dir}"
 		srcprefix="${srcprefix}/${dir}"
 	fi
-	# Gets rid of any obj dirs and things below it 
-	echo "obj" > "${intmp}"
+	# Gets rid of any obj dirs and things below it. Also skip
+	# .hg or .git repositories (if we got the source via git
+	# or mercurial)
+	printf "obj\n./.git\n./.hg\n" > "${intmp}"
 	egrep="$*"
 	if [ "${egrep}" = "" ]; then
 		egrep='.'



CVS commit: [netbsd-9] src/distrib/sets

2021-09-07 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Sep  7 22:29:46 UTC 2021

Modified Files:
src/distrib/sets [netbsd-9]: makesrctars

Log Message:
Pull up following revision(s) (requested by martin in ticket #1344):
distrib/sets/makesrctars: revision 1.43
PR 56389: do not include top level .git or .hg directories
in source sets.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.42.2.1 src/distrib/sets/makesrctars

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



CVS commit: [netbsd-8] src/doc

2021-09-07 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Sep  7 22:29:07 UTC 2021

Modified Files:
src/doc [netbsd-8]: CHANGES-8.3

Log Message:
1694


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.98 -r1.1.2.99 src/doc/CHANGES-8.3

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-8.3
diff -u src/doc/CHANGES-8.3:1.1.2.98 src/doc/CHANGES-8.3:1.1.2.99
--- src/doc/CHANGES-8.3:1.1.2.98	Fri Sep  3 10:24:09 2021
+++ src/doc/CHANGES-8.3	Tue Sep  7 22:29:07 2021
@@ -1,4 +1,4 @@
-# $NetBSD: CHANGES-8.3,v 1.1.2.98 2021/09/03 10:24:09 martin Exp $
+# $NetBSD: CHANGES-8.3,v 1.1.2.99 2021/09/07 22:29:07 snj Exp $
 
 A complete list of changes from the NetBSD 8.2 release to the NetBSD 8.3
 release:
@@ -2012,3 +2012,9 @@ sys/dev/pci/if_vte.c1.32
 	after MAC reset.
 	[andvar, ticket #1693]
 
+distrib/sets/makesrctars			1.43
+
+	PR 56389: do not include top level .git or .hg directories
+	in source sets.
+	[martin, ticket #1694]
+



CVS commit: [netbsd-8] src/doc

2021-09-07 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Sep  7 22:29:07 UTC 2021

Modified Files:
src/doc [netbsd-8]: CHANGES-8.3

Log Message:
1694


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.98 -r1.1.2.99 src/doc/CHANGES-8.3

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



CVS commit: [netbsd-8] src/distrib/sets

2021-09-07 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Sep  7 22:28:31 UTC 2021

Modified Files:
src/distrib/sets [netbsd-8]: makesrctars

Log Message:
Pull up following revision(s) (requested by martin in ticket #1694):
distrib/sets/makesrctars: revision 1.43
PR 56389: do not include top level .git or .hg directories
in source sets.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.41.4.1 src/distrib/sets/makesrctars

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

Modified files:

Index: src/distrib/sets/makesrctars
diff -u src/distrib/sets/makesrctars:1.41 src/distrib/sets/makesrctars:1.41.4.1
--- src/distrib/sets/makesrctars:1.41	Wed Apr 12 17:29:49 2017
+++ src/distrib/sets/makesrctars	Tue Sep  7 22:28:31 2021
@@ -1,6 +1,6 @@
 #! /bin/sh
 #
-#	$NetBSD: makesrctars,v 1.41 2017/04/12 17:29:49 christos Exp $
+#	$NetBSD: makesrctars,v 1.41.4.1 2021/09/07 22:28:31 snj Exp $
 #
 # makesrctars srcdir setdir
 #	Create source tarballs in setdir from the source under srcdir.
@@ -84,8 +84,10 @@ makeset()
 		cd "${dir}"
 		srcprefix="${srcprefix}/${dir}"
 	fi
-	# Gets rid of any obj dirs and things below it 
-	echo "obj" > "${intmp}"
+	# Gets rid of any obj dirs and things below it. Also skip
+	# .hg or .git repositories (if we got the source via git
+	# or mercurial)
+	printf "obj\n./.git\n./.hg\n" > "${intmp}"
 	egrep="$*"
 	if [ "${egrep}" = "" ]; then
 		egrep='.'



CVS commit: [netbsd-8] src/distrib/sets

2021-09-07 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Sep  7 22:28:31 UTC 2021

Modified Files:
src/distrib/sets [netbsd-8]: makesrctars

Log Message:
Pull up following revision(s) (requested by martin in ticket #1694):
distrib/sets/makesrctars: revision 1.43
PR 56389: do not include top level .git or .hg directories
in source sets.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.41.4.1 src/distrib/sets/makesrctars

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



CVS commit: src/usr.bin/make/unit-tests

2021-09-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Sep  7 20:41:58 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: cond-short.mk var-eval-short.exp
var-eval-short.mk

Log Message:
tests/make: expand on the history of unnecessary evaluation


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/make/unit-tests/cond-short.mk
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/make/unit-tests/var-eval-short.exp
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/var-eval-short.mk

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

Modified files:

Index: src/usr.bin/make/unit-tests/cond-short.mk
diff -u src/usr.bin/make/unit-tests/cond-short.mk:1.16 src/usr.bin/make/unit-tests/cond-short.mk:1.17
--- src/usr.bin/make/unit-tests/cond-short.mk:1.16	Sun Mar 14 11:49:37 2021
+++ src/usr.bin/make/unit-tests/cond-short.mk	Tue Sep  7 20:41:58 2021
@@ -1,4 +1,4 @@
-# $NetBSD: cond-short.mk,v 1.16 2021/03/14 11:49:37 rillig Exp $
+# $NetBSD: cond-short.mk,v 1.17 2021/09/07 20:41:58 rillig Exp $
 #
 # Demonstrates that in conditions, the right-hand side of an && or ||
 # is only evaluated if it can actually influence the result.
@@ -12,7 +12,20 @@
 # possible to skip evaluation of irrelevant variable expressions and only
 # parse them.  They were still evaluated though, the only difference to
 # relevant variable expressions was that in the irrelevant variable
-# expressions, undefined variables were allowed.
+# expressions, undefined variables were allowed.  This allowed for conditions
+# like 'defined(VAR) && ${VAR:S,from,to,} != ""', which no longer produced an
+# error message 'Malformed conditional', but it still evaluated the
+# expression, even though the expression was irrelevant.
+#
+# Since the initial commit on 1993-03-21, the manual page has been saying that
+# make 'will only evaluate a conditional as far as is necessary to determine',
+# but that was wrong.  The code in cond.c 1.1 from 1993-03-21 looks good since
+# it calls Var_Parse(condExpr, VAR_CMD, doEval,,), but the
+# definition of Var_Parse does not call the third parameter 'doEval', as would
+# be expected, but instead 'err', accompanied by the comment 'TRUE if
+# undefined variables are an error'.  This subtle difference between 'do not
+# evaluate at all' and 'allow undefined variables' led to the unexpected
+# evaluation.
 #
 # See also:
 #	var-eval-short.mk, for short-circuited variable modifiers

Index: src/usr.bin/make/unit-tests/var-eval-short.exp
diff -u src/usr.bin/make/unit-tests/var-eval-short.exp:1.13 src/usr.bin/make/unit-tests/var-eval-short.exp:1.14
--- src/usr.bin/make/unit-tests/var-eval-short.exp:1.13	Mon Apr  5 13:35:41 2021
+++ src/usr.bin/make/unit-tests/var-eval-short.exp	Tue Sep  7 20:41:58 2021
@@ -1,16 +1,16 @@
 make: "var-eval-short.mk" line 41: In the :@ modifier of "", the variable name "${FAIL}" must not contain a dollar.
 make: "var-eval-short.mk" line 41: Malformed conditional (0 && ${:Uword:@${FAIL}@expr@})
-make: "var-eval-short.mk" line 79: Invalid time value: ${FAIL}}
-make: "var-eval-short.mk" line 79: Malformed conditional (0 && ${:Uword:gmtime=${FAIL}})
-make: "var-eval-short.mk" line 93: Invalid time value: ${FAIL}}
-make: "var-eval-short.mk" line 93: Malformed conditional (0 && ${:Uword:localtime=${FAIL}})
+make: "var-eval-short.mk" line 81: Invalid time value: ${FAIL}}
+make: "var-eval-short.mk" line 81: Malformed conditional (0 && ${:Uword:gmtime=${FAIL}})
+make: "var-eval-short.mk" line 95: Invalid time value: ${FAIL}}
+make: "var-eval-short.mk" line 95: Malformed conditional (0 && ${:Uword:localtime=${FAIL}})
 CondParser_Eval: 0 && ${0:?${FAIL}then:${FAIL}else}
 Var_Parse: ${0:?${FAIL}then:${FAIL}else} (parse-only)
 Parsing modifier ${0:?...}
 Modifier part: "${FAIL}then"
 Modifier part: "${FAIL}else"
 Result of ${0:?${FAIL}then:${FAIL}else} is "" (parse-only, defined)
-ParseReadLine (158): 'DEFINED=	defined'
+ParseReadLine (160): 'DEFINED=	defined'
 Global: DEFINED = defined
 CondParser_Eval: 0 && ${DEFINED:L:?${FAIL}then:${FAIL}else}
 Var_Parse: ${DEFINED:L:?${FAIL}then:${FAIL}else} (parse-only)
@@ -20,7 +20,7 @@ Parsing modifier ${DEFINED:?...}
 Modifier part: "${FAIL}then"
 Modifier part: "${FAIL}else"
 Result of ${DEFINED:?${FAIL}then:${FAIL}else} is "defined" (parse-only, regular)
-ParseReadLine (161): '.MAKEFLAGS: -d0'
+ParseReadLine (163): '.MAKEFLAGS: -d0'
 ParseDependency(.MAKEFLAGS: -d0)
 Global: .MAKEFLAGS =  -r -k -d cpv -d
 Global: .MAKEFLAGS =  -r -k -d cpv -d 0

Index: src/usr.bin/make/unit-tests/var-eval-short.mk
diff -u src/usr.bin/make/unit-tests/var-eval-short.mk:1.6 src/usr.bin/make/unit-tests/var-eval-short.mk:1.7
--- src/usr.bin/make/unit-tests/var-eval-short.mk:1.6	Mon Sep  6 19:38:30 2021
+++ src/usr.bin/make/unit-tests/var-eval-short.mk	Tue Sep  7 20:41:58 2021
@@ -1,4 +1,4 @@
-# $NetBSD: var-eval-short.mk,v 1.6 2021/09/06 19:38:30 rillig Exp $
+# $NetBSD: 

CVS commit: src/usr.bin/make/unit-tests

2021-09-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Sep  7 20:41:58 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: cond-short.mk var-eval-short.exp
var-eval-short.mk

Log Message:
tests/make: expand on the history of unnecessary evaluation


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/make/unit-tests/cond-short.mk
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/make/unit-tests/var-eval-short.exp
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/var-eval-short.mk

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



CVS commit: src/distrib/sets

2021-09-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Sep  7 18:02:46 UTC 2021

Modified Files:
src/distrib/sets: makesrctars

Log Message:
PR 56389: do not include top level .git or .hg directories
in source sets.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/distrib/sets/makesrctars

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

Modified files:

Index: src/distrib/sets/makesrctars
diff -u src/distrib/sets/makesrctars:1.42 src/distrib/sets/makesrctars:1.43
--- src/distrib/sets/makesrctars:1.42	Fri Sep 28 15:04:20 2018
+++ src/distrib/sets/makesrctars	Tue Sep  7 18:02:46 2021
@@ -1,6 +1,6 @@
 #! /bin/sh
 #
-#	$NetBSD: makesrctars,v 1.42 2018/09/28 15:04:20 martin Exp $
+#	$NetBSD: makesrctars,v 1.43 2021/09/07 18:02:46 martin Exp $
 #
 # makesrctars srcdir setdir
 #	Create source tarballs in setdir from the source under srcdir.
@@ -84,8 +84,10 @@ makeset()
 		cd "${dir}"
 		srcprefix="${srcprefix}/${dir}"
 	fi
-	# Gets rid of any obj dirs and things below it 
-	echo "obj" > "${intmp}"
+	# Gets rid of any obj dirs and things below it. Also skip
+	# .hg or .git repositories (if we got the source via git
+	# or mercurial)
+	printf "obj\n./.git\n./.hg\n" > "${intmp}"
 	egrep="$*"
 	if [ "${egrep}" = "" ]; then
 		egrep='.'



CVS commit: src/distrib/sets

2021-09-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Sep  7 18:02:46 UTC 2021

Modified Files:
src/distrib/sets: makesrctars

Log Message:
PR 56389: do not include top level .git or .hg directories
in source sets.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/distrib/sets/makesrctars

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



CVS commit: [netbsd-9] src/doc

2021-09-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Sep  7 17:13:20 UTC 2021

Modified Files:
src/doc [netbsd-9]: CHANGES-9.3

Log Message:
Ticket #1343


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.26 -r1.1.2.27 src/doc/CHANGES-9.3

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-9.3
diff -u src/doc/CHANGES-9.3:1.1.2.26 src/doc/CHANGES-9.3:1.1.2.27
--- src/doc/CHANGES-9.3:1.1.2.26	Sun Sep  5 10:49:51 2021
+++ src/doc/CHANGES-9.3	Tue Sep  7 17:13:20 2021
@@ -1,4 +1,4 @@
-# $NetBSD: CHANGES-9.3,v 1.1.2.26 2021/09/05 10:49:51 martin Exp $
+# $NetBSD: CHANGES-9.3,v 1.1.2.27 2021/09/07 17:13:20 martin Exp $
 
 A complete list of changes from the NetBSD 9.2 release to the NetBSD 9.3
 release:
@@ -627,4 +627,11 @@ sys/arch/mips/mips/trap.c			1.250,1.251
 	mips: fix and disable a debug message for TLB handling.
 	[tsutsui, ticket #1342]
 
+lib/libc/sys/fcntl.21.46 (patch)
+lib/libc/sys/flock.21.23
+share/man/man7/sysctl.71.153
+sys/kern/vfs_lockf.c1.74
+
+	Tie the maximum file lock per unprivilegied uid to kern.maxfiles.
+	[manu, ticket #1343]
 



CVS commit: [netbsd-9] src/doc

2021-09-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Sep  7 17:13:20 UTC 2021

Modified Files:
src/doc [netbsd-9]: CHANGES-9.3

Log Message:
Ticket #1343


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.26 -r1.1.2.27 src/doc/CHANGES-9.3

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



CVS commit: [netbsd-9] src

2021-09-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Sep  7 17:12:21 UTC 2021

Modified Files:
src/lib/libc/sys [netbsd-9]: fcntl.2 flock.2
src/share/man/man7 [netbsd-9]: sysctl.7
src/sys/kern [netbsd-9]: vfs_lockf.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1343):

share/man/man7/sysctl.7: revision 1.153
sys/kern/vfs_lockf.c: revision 1.74
lib/libc/sys/fcntl.2: revision 1.46
lib/libc/sys/flock.2: revision 1.23

Tie the maximum file lock per unprivilegied uid to kern.maxfiles

This makes the limit simple to raise at run time. While there, document
that fcntl(2) and flock(2) may return ENOMEM when this limit is reached.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.41.28.1 src/lib/libc/sys/fcntl.2
cvs rdiff -u -r1.22 -r1.22.44.1 src/lib/libc/sys/flock.2
cvs rdiff -u -r1.139.2.1 -r1.139.2.2 src/share/man/man7/sysctl.7
cvs rdiff -u -r1.73 -r1.73.60.1 src/sys/kern/vfs_lockf.c

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

Modified files:

Index: src/lib/libc/sys/fcntl.2
diff -u src/lib/libc/sys/fcntl.2:1.41 src/lib/libc/sys/fcntl.2:1.41.28.1
--- src/lib/libc/sys/fcntl.2:1.41	Sat Dec 28 20:03:22 2013
+++ src/lib/libc/sys/fcntl.2	Tue Sep  7 17:12:21 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: fcntl.2,v 1.41 2013/12/28 20:03:22 dholland Exp $
+.\"	$NetBSD: fcntl.2,v 1.41.28.1 2021/09/07 17:12:21 martin Exp $
 .\"
 .\" Copyright (c) 1983, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -501,6 +501,10 @@ or
 .Dv F_SETLKW ,
 and satisfying the lock or unlock request would result in the
 number of locked regions in the system exceeding a system-imposed limit.
+.It Bq Er ENOMEM
+The file lock limit for the current unprivilegied user 
+has been reached. It can be modified using sysctl
+.Li kern.maxfiles .
 .It Bq Er ESRCH
 .Fa cmd
 is

Index: src/lib/libc/sys/flock.2
diff -u src/lib/libc/sys/flock.2:1.22 src/lib/libc/sys/flock.2:1.22.44.1
--- src/lib/libc/sys/flock.2:1.22	Sat Oct 15 21:35:50 2011
+++ src/lib/libc/sys/flock.2	Tue Sep  7 17:12:21 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: flock.2,v 1.22 2011/10/15 21:35:50 rmind Exp $
+.\"	$NetBSD: flock.2,v 1.22.44.1 2021/09/07 17:12:21 martin Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -137,6 +137,10 @@ does not include exactly one of
 .Dv LOCK_SH ,
 or
 .Dv LOCK_UN .
+.It Bq Eq ENOMEM
+The file lock limit for the current unprivilegied user 
+has been reached. It can be modifed using sysctl
+.Li kern.maxfiles .
 .It Bq Er EOPNOTSUPP
 The argument
 .Fa fd

Index: src/share/man/man7/sysctl.7
diff -u src/share/man/man7/sysctl.7:1.139.2.1 src/share/man/man7/sysctl.7:1.139.2.2
--- src/share/man/man7/sysctl.7:1.139.2.1	Mon Nov 18 19:45:00 2019
+++ src/share/man/man7/sysctl.7	Tue Sep  7 17:12:21 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sysctl.7,v 1.139.2.1 2019/11/18 19:45:00 martin Exp $
+.\"	$NetBSD: sysctl.7,v 1.139.2.2 2021/09/07 17:12:21 martin Exp $
 .\"
 .\" Copyright (c) 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -736,6 +736,11 @@ Memory Mapped Files Option is available 
 otherwise\ 0.
 .It Li kern.maxfiles ( Dv KERN_MAXFILES )
 The maximum number of open files that may be open in the system.
+This also controls the maximum file locks per unprivilegied user 
+enforced by
+.Xr fnctl 2
+and 
+.Xr flock 2 .
 .It Li kern.maxpartitions ( Dv KERN_MAXPARTITIONS )
 The maximum number of partitions allowed per disk.
 .It Li kern.maxlwp

Index: src/sys/kern/vfs_lockf.c
diff -u src/sys/kern/vfs_lockf.c:1.73 src/sys/kern/vfs_lockf.c:1.73.60.1
--- src/sys/kern/vfs_lockf.c:1.73	Mon Jan 31 08:25:32 2011
+++ src/sys/kern/vfs_lockf.c	Tue Sep  7 17:12:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_lockf.c,v 1.73 2011/01/31 08:25:32 dholland Exp $	*/
+/*	$NetBSD: vfs_lockf.c,v 1.73.60.1 2021/09/07 17:12:21 martin Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_lockf.c,v 1.73 2011/01/31 08:25:32 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_lockf.c,v 1.73.60.1 2021/09/07 17:12:21 martin Exp $");
 
 #include 
 #include 
@@ -123,7 +123,7 @@ int	lockf_debug = 0;
  * so that the unlock can succeed.  If the unlocking causes too many splits,
  * however, you're totally cutoff.
  */
-int maxlocksperuid = 1024;
+#define MAXLOCKSPERUID (2 * maxfiles)
 
 #ifdef LOCKF_DEBUG
 /*
@@ -200,7 +200,7 @@ lf_alloc(int allowfail)
 	uip = uid_find(uid);
 	lcnt = atomic_inc_ulong_nv(>ui_lockcnt);
 	if (uid && allowfail && lcnt >
-	(allowfail == 1 ? maxlocksperuid : (maxlocksperuid * 2))) {
+	(allowfail == 1 ? MAXLOCKSPERUID : (MAXLOCKSPERUID * 2))) {
 		atomic_dec_ulong(>ui_lockcnt);
 		return NULL;
 	}



CVS commit: [netbsd-9] src

2021-09-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Sep  7 17:12:21 UTC 2021

Modified Files:
src/lib/libc/sys [netbsd-9]: fcntl.2 flock.2
src/share/man/man7 [netbsd-9]: sysctl.7
src/sys/kern [netbsd-9]: vfs_lockf.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1343):

share/man/man7/sysctl.7: revision 1.153
sys/kern/vfs_lockf.c: revision 1.74
lib/libc/sys/fcntl.2: revision 1.46
lib/libc/sys/flock.2: revision 1.23

Tie the maximum file lock per unprivilegied uid to kern.maxfiles

This makes the limit simple to raise at run time. While there, document
that fcntl(2) and flock(2) may return ENOMEM when this limit is reached.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.41.28.1 src/lib/libc/sys/fcntl.2
cvs rdiff -u -r1.22 -r1.22.44.1 src/lib/libc/sys/flock.2
cvs rdiff -u -r1.139.2.1 -r1.139.2.2 src/share/man/man7/sysctl.7
cvs rdiff -u -r1.73 -r1.73.60.1 src/sys/kern/vfs_lockf.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

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 16:56:25 UTC 2021

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

Log Message:
Revert "ksyms(4): Simply block unload until last /dev/ksyms close."

This appears to break t_execsnoop -- presumably something goes wrong
with how libdtrace uses ksyms.  To investigate.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 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.101 src/sys/kern/kern_ksyms.c:1.102
--- src/sys/kern/kern_ksyms.c:1.101	Tue Sep  7 16:56:13 2021
+++ src/sys/kern/kern_ksyms.c	Tue Sep  7 16:56:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_ksyms.c,v 1.101 2021/09/07 16:56:13 riastradh Exp $	*/
+/*	$NetBSD: kern_ksyms.c,v 1.102 2021/09/07 16:56:25 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.101 2021/09/07 16:56:13 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.102 2021/09/07 16:56:25 riastradh Exp $");
 
 #if defined(_KERNEL) && defined(_KERNEL_OPT)
 #include "opt_copy_symtab.h"
@@ -117,7 +117,6 @@ static struct ksyms_symtab *ksyms_last_s
 static bool ksyms_initted;
 static bool ksyms_loaded;
 static kmutex_t ksyms_lock __cacheline_aligned;
-static kcondvar_t ksyms_cv;
 static struct ksyms_symtab kernel_symtab;
 
 static void ksyms_hdr_init(const void *);
@@ -246,7 +245,6 @@ ksyms_init(void)
 
 	if (!ksyms_initted) {
 		mutex_init(_lock, MUTEX_DEFAULT, IPL_NONE);
-		cv_init(_cv, "ksyms");
 		ksyms_initted = true;
 	}
 }
@@ -330,6 +328,7 @@ addsymtab(const char *name, void *symsta
 	tab->sd_minsym = UINTPTR_MAX;
 	tab->sd_maxsym = 0;
 	tab->sd_usroffset = 0;
+	tab->sd_gone = false;
 	tab->sd_ctfstart = ctfstart;
 	tab->sd_ctfsize = ctfsize;
 	tab->sd_nmap = nmap;
@@ -447,9 +446,9 @@ addsymtab(const char *name, void *symsta
 	KASSERT(cold || mutex_owned(_lock));
 
 	/*
-	 * Publish the symtab.  Do this at splhigh to ensure ddb never
-	 * witnesses an inconsistent state of the queue, unless memory
-	 * is so corrupt that we crash in TAILQ_INSERT_TAIL.
+	 * Ensure ddb never witnesses an inconsistent state of the
+	 * queue, unless memory is so corrupt that we crash in
+	 * TAILQ_INSERT_TAIL.
 	 */
 	s = splhigh();
 	TAILQ_INSERT_TAIL(_symtabs, tab, sd_queue);
@@ -602,6 +601,8 @@ ksyms_getval_unlocked(const char *mod, c
 #endif
 
 	TAILQ_FOREACH(st, _symtabs, sd_queue) {
+		if (__predict_false(st->sd_gone))
+			continue;
 		if (mod != NULL && strcmp(st->sd_name, mod))
 			continue;
 		if ((es = findsym(sym, st, type)) != NULL) {
@@ -635,6 +636,8 @@ ksyms_get_mod(const char *mod)
 
 	mutex_enter(_lock);
 	TAILQ_FOREACH(st, _symtabs, sd_queue) {
+		if (__predict_false(st->sd_gone))
+			continue;
 		if (mod != NULL && strcmp(st->sd_name, mod))
 			continue;
 		break;
@@ -668,6 +671,8 @@ ksyms_mod_foreach(const char *mod, ksyms
 
 	/* find the module */
 	TAILQ_FOREACH(st, _symtabs, sd_queue) {
+		if (__predict_false(st->sd_gone))
+			continue;
 		if (mod != NULL && strcmp(st->sd_name, mod))
 			continue;
 
@@ -711,6 +716,8 @@ ksyms_getname(const char **mod, const ch
 		return ENOENT;
 
 	TAILQ_FOREACH(st, _symtabs, sd_queue) {
+		if (st->sd_gone)
+			continue;
 		if (v < st->sd_minsym || v > st->sd_maxsym)
 			continue;
 		sz = st->sd_symsize/sizeof(Elf_Sym);
@@ -773,44 +780,37 @@ void
 ksyms_modunload(const char *name)
 {
 	struct ksyms_symtab *st;
+	bool do_free = false;
 	int s;
 
 	mutex_enter(_lock);
 	TAILQ_FOREACH(st, _symtabs, sd_queue) {
+		if (st->sd_gone)
+			continue;
 		if (strcmp(name, st->sd_name) != 0)
 			continue;
+		st->sd_gone = true;
+		ksyms_sizes_calc();
+		if (ksyms_opencnt == 0) {
+			/*
+			 * Ensure ddb never witnesses an inconsistent
+			 * state of the queue, unless memory is so
+			 * corrupt that we crash in TAILQ_REMOVE.
+			 */
+			s = splhigh();
+			TAILQ_REMOVE(_symtabs, st, sd_queue);
+			splx(s);
+			do_free = true;
+		}
 		break;
 	}
-	KASSERT(st != NULL);
-
-	/*
-	 * Wait for last /dev/ksyms close -- readers may be in the
-	 * middle of viewing a snapshot including this module.  (We
-	 * could skip this if it's past ksyms_last_snapshot, but it's
-	 * not clear that's worth the effort.)
-	 */
-	while (ksyms_opencnt)
-		cv_wait(_cv, _lock);
-
-	/*
-	 * Remove the symtab.  Do this at splhigh to ensure ddb never
-	 * witnesses an inconsistent state of the queue, unless memory
-	 * is so corrupt that we crash in TAILQ_REMOVE.
-	 */
-	s = splhigh();
-	TAILQ_REMOVE(_symtabs, st, sd_queue);
-	splx(s);
-
-	/* Recompute the ksyms sizes now that we've removed st.  */
-	ksyms_sizes_calc();
 	mutex_exit(_lock);
+	KASSERT(st != NULL);
 
-	/*
-	 * No more references are possible.  Free the name map and the
-	 * symtab itself, which we had allocated in ksyms_modload.
-	 */
-	

CVS commit: src/sys/kern

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 16:56:25 UTC 2021

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

Log Message:
Revert "ksyms(4): Simply block unload until last /dev/ksyms close."

This appears to break t_execsnoop -- presumably something goes wrong
with how libdtrace uses ksyms.  To investigate.


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



CVS commit: src/sys

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 16:56:13 UTC 2021

Modified Files:
src/sys/arch/sparc64/sparc64: machdep.c
src/sys/kern: kern_ksyms.c subr_csan.c subr_msan.c
src/sys/sys: ksyms.h

Log Message:
Revert "ksyms: Use pserialize(9) for kernel access to ksyms."


To generate a diff of this commit:
cvs rdiff -u -r1.301 -r1.302 src/sys/arch/sparc64/sparc64/machdep.c
cvs rdiff -u -r1.100 -r1.101 src/sys/kern/kern_ksyms.c
cvs rdiff -u -r1.11 -r1.12 src/sys/kern/subr_csan.c
cvs rdiff -u -r1.15 -r1.16 src/sys/kern/subr_msan.c
cvs rdiff -u -r1.40 -r1.41 src/sys/sys/ksyms.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/sparc64/sparc64/machdep.c
diff -u src/sys/arch/sparc64/sparc64/machdep.c:1.301 src/sys/arch/sparc64/sparc64/machdep.c:1.302
--- src/sys/arch/sparc64/sparc64/machdep.c:1.301	Tue Sep  7 11:00:02 2021
+++ src/sys/arch/sparc64/sparc64/machdep.c	Tue Sep  7 16:56:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.301 2021/09/07 11:00:02 riastradh Exp $ */
+/*	$NetBSD: machdep.c,v 1.302 2021/09/07 16:56:13 riastradh Exp $ */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2019 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.301 2021/09/07 11:00:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.302 2021/09/07 16:56:13 riastradh Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -102,7 +102,6 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 
 #include 
 #include 
 #include 
-#include 
 
 #include 
 
@@ -837,22 +836,17 @@ get_symbol_and_offset(const char **mod, 
 {
 	static char symbuf[256];
 	unsigned long symaddr;
-	int s, error;
 
 #if NKSYMS || defined(DDB) || defined(MODULAR)
-	s = pserialize_read_enter();
 	if (ksyms_getname(mod, sym, pc,
 			  KSYMS_CLOSEST|KSYMS_PROC|KSYMS_ANY) == 0) {
-		error = ksyms_getval(*mod, *sym, ,
-		KSYMS_CLOSEST|KSYMS_PROC|KSYMS_ANY);
-		pserialize_read_exit(s);
-		if (error)
+		if (ksyms_getval(*mod, *sym, ,
+ KSYMS_CLOSEST|KSYMS_PROC|KSYMS_ANY) != 0)
 			goto failed;
 
 		*offset = (vaddr_t)(pc - symaddr);
 		return;
 	}
-	pserialize_read_exit(s);
 #endif
  failed:
 	snprintf(symbuf, sizeof symbuf, "%llx", (unsigned long long)pc);

Index: src/sys/kern/kern_ksyms.c
diff -u src/sys/kern/kern_ksyms.c:1.100 src/sys/kern/kern_ksyms.c:1.101
--- src/sys/kern/kern_ksyms.c:1.100	Tue Sep  7 11:00:02 2021
+++ src/sys/kern/kern_ksyms.c	Tue Sep  7 16:56:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_ksyms.c,v 1.100 2021/09/07 11:00:02 riastradh Exp $	*/
+/*	$NetBSD: kern_ksyms.c,v 1.101 2021/09/07 16:56:13 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.100 2021/09/07 11:00:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.101 2021/09/07 16:56:13 riastradh Exp $");
 
 #if defined(_KERNEL) && defined(_KERNEL_OPT)
 #include "opt_copy_symtab.h"
@@ -94,7 +94,6 @@ __KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c
 #include 
 #include 
 #include 
-#include 
 
 #ifdef DDB
 #include 
@@ -119,7 +118,6 @@ static bool ksyms_initted;
 static bool ksyms_loaded;
 static kmutex_t ksyms_lock __cacheline_aligned;
 static kcondvar_t ksyms_cv;
-static pserialize_t ksyms_psz __read_mostly;
 static struct ksyms_symtab kernel_symtab;
 
 static void ksyms_hdr_init(const void *);
@@ -148,7 +146,6 @@ int ksyms_strsz;
 int ksyms_ctfsz;	/* this is not currently used by savecore(8) */
 TAILQ_HEAD(ksyms_symtab_queue, ksyms_symtab) ksyms_symtabs =
 TAILQ_HEAD_INITIALIZER(ksyms_symtabs);
-static struct pslist_head ksyms_symtabs_psz = PSLIST_INITIALIZER;
 
 static int
 ksyms_verify(const void *symstart, const void *strstart)
@@ -250,7 +247,6 @@ ksyms_init(void)
 	if (!ksyms_initted) {
 		mutex_init(_lock, MUTEX_DEFAULT, IPL_NONE);
 		cv_init(_cv, "ksyms");
-		ksyms_psz = pserialize_create();
 		ksyms_initted = true;
 	}
 }
@@ -453,19 +449,9 @@ addsymtab(const char *name, void *symsta
 	/*
 	 * Publish the symtab.  Do this at splhigh to ensure ddb never
 	 * witnesses an inconsistent state of the queue, unless memory
-	 * is so corrupt that we crash in PSLIST_WRITER_INSERT_AFTER or
-	 * TAILQ_INSERT_TAIL.
+	 * is so corrupt that we crash in TAILQ_INSERT_TAIL.
 	 */
-	PSLIST_ENTRY_INIT(tab, sd_pslist);
 	s = splhigh();
-	if (TAILQ_EMPTY(_symtabs)) {
-		PSLIST_WRITER_INSERT_HEAD(_symtabs_psz, tab, sd_pslist);
-	} else {
-		struct ksyms_symtab *last;
-
-		last = TAILQ_LAST(_symtabs, ksyms_symtab_queue);
-		PSLIST_WRITER_INSERT_AFTER(last, tab, sd_pslist);
-	}
 	TAILQ_INSERT_TAIL(_symtabs, tab, sd_queue);
 	splx(s);
 
@@ -601,9 +587,7 @@ ksyms_addsyms_explicit(void *ehdr, void 
  * "val" is a pointer to the corresponding value, if call succeeded.
  * Returns 0 if success or ENOENT if no such entry.
  *
- * If symp is nonnull, caller must hold ksyms_lock or 

CVS commit: src/sys

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 16:56:13 UTC 2021

Modified Files:
src/sys/arch/sparc64/sparc64: machdep.c
src/sys/kern: kern_ksyms.c subr_csan.c subr_msan.c
src/sys/sys: ksyms.h

Log Message:
Revert "ksyms: Use pserialize(9) for kernel access to ksyms."


To generate a diff of this commit:
cvs rdiff -u -r1.301 -r1.302 src/sys/arch/sparc64/sparc64/machdep.c
cvs rdiff -u -r1.100 -r1.101 src/sys/kern/kern_ksyms.c
cvs rdiff -u -r1.11 -r1.12 src/sys/kern/subr_csan.c
cvs rdiff -u -r1.15 -r1.16 src/sys/kern/subr_msan.c
cvs rdiff -u -r1.40 -r1.41 src/sys/sys/ksyms.h

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



CVS commit: src/games/fortune/datfiles

2021-09-07 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Tue Sep  7 13:29:41 UTC 2021

Modified Files:
src/games/fortune/datfiles: netbsd-tips

Log Message:
person on internet is confused by how to list disks because there's
so much in /dev


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/games/fortune/datfiles/netbsd-tips

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

Modified files:

Index: src/games/fortune/datfiles/netbsd-tips
diff -u src/games/fortune/datfiles/netbsd-tips:1.12 src/games/fortune/datfiles/netbsd-tips:1.13
--- src/games/fortune/datfiles/netbsd-tips:1.12	Thu Aug 19 14:03:43 2021
+++ src/games/fortune/datfiles/netbsd-tips	Tue Sep  7 13:29:41 2021
@@ -203,3 +203,7 @@ Network interface traffic can be monitor
 command:
 
 	sysstat ifstat
+%
+To list connected disk devices:
+
+	sysctl hw.disknames



CVS commit: src/games/fortune/datfiles

2021-09-07 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Tue Sep  7 13:29:41 UTC 2021

Modified Files:
src/games/fortune/datfiles: netbsd-tips

Log Message:
person on internet is confused by how to list disks because there's
so much in /dev


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/games/fortune/datfiles/netbsd-tips

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



CVS commit: src

2021-09-07 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Tue Sep  7 13:24:46 UTC 2021

Modified Files:
src/common/lib/libprop: prop_string.c
src/sys/arch/hppa/hppa: intr.c
src/sys/arch/sparc64/sparc64: autoconf.c
src/sys/dev/audio: audio.c
src/sys/dev/sysmon: sysmon_envsys.c
src/sys/kern: sys_pipe.c
src/sys/netinet: dccp_tfrc.c sctp_output.c

Log Message:
s/aquire/acquire/ in comments, also one typo fix acqure->acquire.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/common/lib/libprop/prop_string.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/hppa/hppa/intr.c
cvs rdiff -u -r1.235 -r1.236 src/sys/arch/sparc64/sparc64/autoconf.c
cvs rdiff -u -r1.106 -r1.107 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.147 -r1.148 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.152 -r1.153 src/sys/kern/sys_pipe.c
cvs rdiff -u -r1.6 -r1.7 src/sys/netinet/dccp_tfrc.c
cvs rdiff -u -r1.24 -r1.25 src/sys/netinet/sctp_output.c

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

Modified files:

Index: src/common/lib/libprop/prop_string.c
diff -u src/common/lib/libprop/prop_string.c:1.15 src/common/lib/libprop/prop_string.c:1.16
--- src/common/lib/libprop/prop_string.c:1.15	Sat Jun 20 00:16:50 2020
+++ src/common/lib/libprop/prop_string.c	Tue Sep  7 13:24:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: prop_string.c,v 1.15 2020/06/20 00:16:50 christos Exp $	*/
+/*	$NetBSD: prop_string.c,v 1.16 2021/09/07 13:24:45 andvar Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2020 The NetBSD Foundation, Inc.
@@ -146,7 +146,7 @@ _prop_string_free(prop_stack_t stack, pr
 		_PROP_MUTEX_LOCK(_prop_string_tree_mutex);
 		/*
 		 * Double-check the retain count now that we've
-		 * acqured the tree lock; holding this lock prevents
+		 * acquired the tree lock; holding this lock prevents
 		 * new retains from coming in by finding it in the
 		 * tree.
 		 */

Index: src/sys/arch/hppa/hppa/intr.c
diff -u src/sys/arch/hppa/hppa/intr.c:1.4 src/sys/arch/hppa/hppa/intr.c:1.5
--- src/sys/arch/hppa/hppa/intr.c:1.4	Thu Jul  1 22:57:45 2021
+++ src/sys/arch/hppa/hppa/intr.c	Tue Sep  7 13:24:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.4 2021/07/01 22:57:45 macallan Exp $	*/
+/*	$NetBSD: intr.c,v 1.5 2021/09/07 13:24:45 andvar Exp $	*/
 /*	$OpenBSD: intr.c,v 1.27 2009/12/31 12:52:35 jsing Exp $	*/
 
 /*
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.4 2021/07/01 22:57:45 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.5 2021/09/07 13:24:45 andvar Exp $");
 
 #define __MUTEX_PRIVATE
 
@@ -349,7 +349,7 @@ hppa_intr(struct trapframe *frame)
 	/*
 	 * If we interrupted in the middle of mutex_enter(), we must patch up
 	 * the lock owner value quickly if we got the interlock.  If any of the
-	 * interrupt handlers need to aquire the mutex, they could deadlock if
+	 * interrupt handlers need to acquire the mutex, they could deadlock if
 	 * the owner value is left unset.
 	 */
 	if (frame->tf_iisq_head == HPPA_SID_KERNEL &&

Index: src/sys/arch/sparc64/sparc64/autoconf.c
diff -u src/sys/arch/sparc64/sparc64/autoconf.c:1.235 src/sys/arch/sparc64/sparc64/autoconf.c:1.236
--- src/sys/arch/sparc64/sparc64/autoconf.c:1.235	Sat Aug 21 11:55:25 2021
+++ src/sys/arch/sparc64/sparc64/autoconf.c	Tue Sep  7 13:24:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.235 2021/08/21 11:55:25 andvar Exp $ */
+/*	$NetBSD: autoconf.c,v 1.236 2021/09/07 13:24:46 andvar Exp $ */
 
 /*
  * Copyright (c) 1996
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.235 2021/08/21 11:55:25 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.236 2021/09/07 13:24:46 andvar Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -1457,7 +1457,7 @@ device_register_post_config(device_t dev
 
 		/*
 		 * If this is a FC-AL drive it will have
-		 * aquired its WWN device property by now,
+		 * acquired its WWN device property by now,
 		 * so we can properly match it.
 		 */
 		if (prop_dictionary_get_uint64(device_properties(dev),

Index: src/sys/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.106 src/sys/dev/audio/audio.c:1.107
--- src/sys/dev/audio/audio.c:1.106	Sat Aug  7 16:19:09 2021
+++ src/sys/dev/audio/audio.c	Tue Sep  7 13:24:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.106 2021/08/07 16:19:09 thorpej Exp $	*/
+/*	$NetBSD: audio.c,v 1.107 2021/09/07 13:24:46 andvar Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.106 2021/08/07 16:19:09 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.107 2021/09/07 13:24:46 andvar Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1645,7 +1645,7 @@ audio_track_waitio(struct audio_softc *s
 
 /*
  * Try to acquire track lock.
- * It doesn't block if the track lock is already aquired.
+ * It doesn't block if the track lock is already acquired.
 

CVS commit: src

2021-09-07 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Tue Sep  7 13:24:46 UTC 2021

Modified Files:
src/common/lib/libprop: prop_string.c
src/sys/arch/hppa/hppa: intr.c
src/sys/arch/sparc64/sparc64: autoconf.c
src/sys/dev/audio: audio.c
src/sys/dev/sysmon: sysmon_envsys.c
src/sys/kern: sys_pipe.c
src/sys/netinet: dccp_tfrc.c sctp_output.c

Log Message:
s/aquire/acquire/ in comments, also one typo fix acqure->acquire.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/common/lib/libprop/prop_string.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/hppa/hppa/intr.c
cvs rdiff -u -r1.235 -r1.236 src/sys/arch/sparc64/sparc64/autoconf.c
cvs rdiff -u -r1.106 -r1.107 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.147 -r1.148 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.152 -r1.153 src/sys/kern/sys_pipe.c
cvs rdiff -u -r1.6 -r1.7 src/sys/netinet/dccp_tfrc.c
cvs rdiff -u -r1.24 -r1.25 src/sys/netinet/sctp_output.c

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



CVS commit: src/lib/libcurses

2021-09-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Sep  7 12:36:57 UTC 2021

Modified Files:
src/lib/libcurses: fileio.c

Log Message:
Do not compile in whole fileio.c for LIBHACK.

Fix build failure when built as libhack, due to missing fileio.h.

IMO, this should be cleaner than generating fileio.h for {get,put}win(3),
that are useless for install media.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/libcurses/fileio.c

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



CVS commit: src/lib/libcurses

2021-09-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Sep  7 12:36:57 UTC 2021

Modified Files:
src/lib/libcurses: fileio.c

Log Message:
Do not compile in whole fileio.c for LIBHACK.

Fix build failure when built as libhack, due to missing fileio.h.

IMO, this should be cleaner than generating fileio.h for {get,put}win(3),
that are useless for install media.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/libcurses/fileio.c

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

Modified files:

Index: src/lib/libcurses/fileio.c
diff -u src/lib/libcurses/fileio.c:1.8 src/lib/libcurses/fileio.c:1.9
--- src/lib/libcurses/fileio.c:1.8	Mon Sep  6 07:03:49 2021
+++ src/lib/libcurses/fileio.c	Tue Sep  7 12:36:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: fileio.c,v 1.8 2021/09/06 07:03:49 rin Exp $	*/
+/*	$NetBSD: fileio.c,v 1.9 2021/09/07 12:36:57 rin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,9 +29,10 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifndef LIBHACK
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fileio.c,v 1.8 2021/09/06 07:03:49 rin Exp $");
+__RCSID("$NetBSD: fileio.c,v 1.9 2021/09/07 12:36:57 rin Exp $");
 #endif/* not lint */
 
 #include "curses.h"
@@ -241,3 +242,4 @@ error0:
 		free(wtmp);
 	return NULL;
 }
+#endif /* !LIBHACK */



CVS commit: src/sys/compat

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 11:43:05 UTC 2021

Modified Files:
src/sys/compat/common: ieee80211_20.c if_media_80.c kern_info_09.c
kern_info_43.c kern_resource_43.c kern_sig_13.c kern_sig_43.c
kern_time_50.c vfs_syscalls_12.c vfs_syscalls_30.c
vfs_syscalls_43.c
src/sys/compat/freebsd: freebsd_machdep.c freebsd_misc.c
freebsd_sched.c
src/sys/compat/linux/arch/alpha: linux_machdep.c linux_osf1.c
src/sys/compat/linux/arch/amd64: linux_machdep.c
src/sys/compat/linux/arch/arm: linux_machdep.c linux_ptrace.c
src/sys/compat/linux/arch/i386: linux_machdep.c linux_ptrace.c
src/sys/compat/linux/arch/m68k: linux_machdep.c
src/sys/compat/linux/arch/mips: linux_machdep.c
src/sys/compat/linux/arch/powerpc: linux_exec_powerpc.c linux_machdep.c
linux_ptrace.c
src/sys/compat/linux/common: linux_cdrom.c linux_fdio.c linux_file.c
linux_hdio.c linux_misc.c linux_mtio.c linux_oldolduname.c
linux_olduname.c linux_sched.c linux_signal.c linux_socket.c
linux_time.c
src/sys/compat/linux32/arch/amd64: linux32_machdep.c
src/sys/compat/linux32/common: linux32_exec_elf32.c linux32_resource.c
linux32_signal.c linux32_time.c
src/sys/compat/netbsd32: netbsd32_compat_12.c netbsd32_compat_20.c
netbsd32_compat_43.c netbsd32_compat_50.c netbsd32_conv.h
netbsd32_nfssvc.c netbsd32_ptrace.c netbsd32_signal.c
netbsd32_time.c netbsd32_wait.c
src/sys/compat/ossaudio: ossaudio.c
src/sys/compat/sunos: sunos_ioctl.c sunos_misc.c
src/sys/compat/sunos32: sunos32_ioctl.c sunos32_misc.c
src/sys/compat/sys: statvfs.h time_types.h
src/sys/compat/ultrix: ultrix_ioctl.c ultrix_misc.c

Log Message:
sys/compat: Memset zero before copyout.

Just in case of uninitialized padding which would lead to kernel
stack disclosure.  If the compiler can prove the memset redundant
then it can optimize it away; otherwise better safe than sorry.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/compat/common/ieee80211_20.c
cvs rdiff -u -r1.3 -r1.4 src/sys/compat/common/if_media_80.c
cvs rdiff -u -r1.21 -r1.22 src/sys/compat/common/kern_info_09.c \
src/sys/compat/common/kern_sig_13.c
cvs rdiff -u -r1.39 -r1.40 src/sys/compat/common/kern_info_43.c
cvs rdiff -u -r1.22 -r1.23 src/sys/compat/common/kern_resource_43.c
cvs rdiff -u -r1.36 -r1.37 src/sys/compat/common/kern_sig_43.c \
src/sys/compat/common/kern_time_50.c
cvs rdiff -u -r1.37 -r1.38 src/sys/compat/common/vfs_syscalls_12.c
cvs rdiff -u -r1.42 -r1.43 src/sys/compat/common/vfs_syscalls_30.c
cvs rdiff -u -r1.67 -r1.68 src/sys/compat/common/vfs_syscalls_43.c
cvs rdiff -u -r1.4 -r1.5 src/sys/compat/freebsd/freebsd_machdep.c
cvs rdiff -u -r1.33 -r1.34 src/sys/compat/freebsd/freebsd_misc.c
cvs rdiff -u -r1.22 -r1.23 src/sys/compat/freebsd/freebsd_sched.c
cvs rdiff -u -r1.51 -r1.52 src/sys/compat/linux/arch/alpha/linux_machdep.c
cvs rdiff -u -r1.4 -r1.5 src/sys/compat/linux/arch/alpha/linux_osf1.c
cvs rdiff -u -r1.59 -r1.60 src/sys/compat/linux/arch/amd64/linux_machdep.c
cvs rdiff -u -r1.33 -r1.34 src/sys/compat/linux/arch/arm/linux_machdep.c
cvs rdiff -u -r1.22 -r1.23 src/sys/compat/linux/arch/arm/linux_ptrace.c
cvs rdiff -u -r1.167 -r1.168 src/sys/compat/linux/arch/i386/linux_machdep.c
cvs rdiff -u -r1.34 -r1.35 src/sys/compat/linux/arch/i386/linux_ptrace.c
cvs rdiff -u -r1.42 -r1.43 src/sys/compat/linux/arch/m68k/linux_machdep.c
cvs rdiff -u -r1.43 -r1.44 src/sys/compat/linux/arch/mips/linux_machdep.c
cvs rdiff -u -r1.24 -r1.25 \
src/sys/compat/linux/arch/powerpc/linux_exec_powerpc.c
cvs rdiff -u -r1.50 -r1.51 src/sys/compat/linux/arch/powerpc/linux_machdep.c
cvs rdiff -u -r1.32 -r1.33 src/sys/compat/linux/arch/powerpc/linux_ptrace.c
cvs rdiff -u -r1.27 -r1.28 src/sys/compat/linux/common/linux_cdrom.c
cvs rdiff -u -r1.13 -r1.14 src/sys/compat/linux/common/linux_fdio.c
cvs rdiff -u -r1.118 -r1.119 src/sys/compat/linux/common/linux_file.c
cvs rdiff -u -r1.18 -r1.19 src/sys/compat/linux/common/linux_hdio.c
cvs rdiff -u -r1.251 -r1.252 src/sys/compat/linux/common/linux_misc.c
cvs rdiff -u -r1.7 -r1.8 src/sys/compat/linux/common/linux_mtio.c
cvs rdiff -u -r1.66 -r1.67 src/sys/compat/linux/common/linux_oldolduname.c \
src/sys/compat/linux/common/linux_olduname.c
cvs rdiff -u -r1.78 -r1.79 src/sys/compat/linux/common/linux_sched.c
cvs rdiff -u -r1.83 -r1.84 src/sys/compat/linux/common/linux_signal.c
cvs rdiff -u -r1.152 -r1.153 src/sys/compat/linux/common/linux_socket.c
cvs rdiff -u -r1.39 -r1.40 src/sys/compat/linux/common/linux_time.c
cvs rdiff -u -r1.45 -r1.46 \
src/sys/compat/linux32/arch/amd64/linux32_machdep.c
cvs rdiff -u -r1.19 -r1.20 src/sys/compat/linux32/common/linux32_exec_elf32.c
cvs rdiff -u -r1.11 -r1.12 

CVS commit: src/sys/compat

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 11:43:05 UTC 2021

Modified Files:
src/sys/compat/common: ieee80211_20.c if_media_80.c kern_info_09.c
kern_info_43.c kern_resource_43.c kern_sig_13.c kern_sig_43.c
kern_time_50.c vfs_syscalls_12.c vfs_syscalls_30.c
vfs_syscalls_43.c
src/sys/compat/freebsd: freebsd_machdep.c freebsd_misc.c
freebsd_sched.c
src/sys/compat/linux/arch/alpha: linux_machdep.c linux_osf1.c
src/sys/compat/linux/arch/amd64: linux_machdep.c
src/sys/compat/linux/arch/arm: linux_machdep.c linux_ptrace.c
src/sys/compat/linux/arch/i386: linux_machdep.c linux_ptrace.c
src/sys/compat/linux/arch/m68k: linux_machdep.c
src/sys/compat/linux/arch/mips: linux_machdep.c
src/sys/compat/linux/arch/powerpc: linux_exec_powerpc.c linux_machdep.c
linux_ptrace.c
src/sys/compat/linux/common: linux_cdrom.c linux_fdio.c linux_file.c
linux_hdio.c linux_misc.c linux_mtio.c linux_oldolduname.c
linux_olduname.c linux_sched.c linux_signal.c linux_socket.c
linux_time.c
src/sys/compat/linux32/arch/amd64: linux32_machdep.c
src/sys/compat/linux32/common: linux32_exec_elf32.c linux32_resource.c
linux32_signal.c linux32_time.c
src/sys/compat/netbsd32: netbsd32_compat_12.c netbsd32_compat_20.c
netbsd32_compat_43.c netbsd32_compat_50.c netbsd32_conv.h
netbsd32_nfssvc.c netbsd32_ptrace.c netbsd32_signal.c
netbsd32_time.c netbsd32_wait.c
src/sys/compat/ossaudio: ossaudio.c
src/sys/compat/sunos: sunos_ioctl.c sunos_misc.c
src/sys/compat/sunos32: sunos32_ioctl.c sunos32_misc.c
src/sys/compat/sys: statvfs.h time_types.h
src/sys/compat/ultrix: ultrix_ioctl.c ultrix_misc.c

Log Message:
sys/compat: Memset zero before copyout.

Just in case of uninitialized padding which would lead to kernel
stack disclosure.  If the compiler can prove the memset redundant
then it can optimize it away; otherwise better safe than sorry.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/compat/common/ieee80211_20.c
cvs rdiff -u -r1.3 -r1.4 src/sys/compat/common/if_media_80.c
cvs rdiff -u -r1.21 -r1.22 src/sys/compat/common/kern_info_09.c \
src/sys/compat/common/kern_sig_13.c
cvs rdiff -u -r1.39 -r1.40 src/sys/compat/common/kern_info_43.c
cvs rdiff -u -r1.22 -r1.23 src/sys/compat/common/kern_resource_43.c
cvs rdiff -u -r1.36 -r1.37 src/sys/compat/common/kern_sig_43.c \
src/sys/compat/common/kern_time_50.c
cvs rdiff -u -r1.37 -r1.38 src/sys/compat/common/vfs_syscalls_12.c
cvs rdiff -u -r1.42 -r1.43 src/sys/compat/common/vfs_syscalls_30.c
cvs rdiff -u -r1.67 -r1.68 src/sys/compat/common/vfs_syscalls_43.c
cvs rdiff -u -r1.4 -r1.5 src/sys/compat/freebsd/freebsd_machdep.c
cvs rdiff -u -r1.33 -r1.34 src/sys/compat/freebsd/freebsd_misc.c
cvs rdiff -u -r1.22 -r1.23 src/sys/compat/freebsd/freebsd_sched.c
cvs rdiff -u -r1.51 -r1.52 src/sys/compat/linux/arch/alpha/linux_machdep.c
cvs rdiff -u -r1.4 -r1.5 src/sys/compat/linux/arch/alpha/linux_osf1.c
cvs rdiff -u -r1.59 -r1.60 src/sys/compat/linux/arch/amd64/linux_machdep.c
cvs rdiff -u -r1.33 -r1.34 src/sys/compat/linux/arch/arm/linux_machdep.c
cvs rdiff -u -r1.22 -r1.23 src/sys/compat/linux/arch/arm/linux_ptrace.c
cvs rdiff -u -r1.167 -r1.168 src/sys/compat/linux/arch/i386/linux_machdep.c
cvs rdiff -u -r1.34 -r1.35 src/sys/compat/linux/arch/i386/linux_ptrace.c
cvs rdiff -u -r1.42 -r1.43 src/sys/compat/linux/arch/m68k/linux_machdep.c
cvs rdiff -u -r1.43 -r1.44 src/sys/compat/linux/arch/mips/linux_machdep.c
cvs rdiff -u -r1.24 -r1.25 \
src/sys/compat/linux/arch/powerpc/linux_exec_powerpc.c
cvs rdiff -u -r1.50 -r1.51 src/sys/compat/linux/arch/powerpc/linux_machdep.c
cvs rdiff -u -r1.32 -r1.33 src/sys/compat/linux/arch/powerpc/linux_ptrace.c
cvs rdiff -u -r1.27 -r1.28 src/sys/compat/linux/common/linux_cdrom.c
cvs rdiff -u -r1.13 -r1.14 src/sys/compat/linux/common/linux_fdio.c
cvs rdiff -u -r1.118 -r1.119 src/sys/compat/linux/common/linux_file.c
cvs rdiff -u -r1.18 -r1.19 src/sys/compat/linux/common/linux_hdio.c
cvs rdiff -u -r1.251 -r1.252 src/sys/compat/linux/common/linux_misc.c
cvs rdiff -u -r1.7 -r1.8 src/sys/compat/linux/common/linux_mtio.c
cvs rdiff -u -r1.66 -r1.67 src/sys/compat/linux/common/linux_oldolduname.c \
src/sys/compat/linux/common/linux_olduname.c
cvs rdiff -u -r1.78 -r1.79 src/sys/compat/linux/common/linux_sched.c
cvs rdiff -u -r1.83 -r1.84 src/sys/compat/linux/common/linux_signal.c
cvs rdiff -u -r1.152 -r1.153 src/sys/compat/linux/common/linux_socket.c
cvs rdiff -u -r1.39 -r1.40 src/sys/compat/linux/common/linux_time.c
cvs rdiff -u -r1.45 -r1.46 \
src/sys/compat/linux32/arch/amd64/linux32_machdep.c
cvs rdiff -u -r1.19 -r1.20 src/sys/compat/linux32/common/linux32_exec_elf32.c
cvs rdiff -u -r1.11 -r1.12 

CVS commit: src/sys

2021-09-07 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Tue Sep  7 11:41:32 UTC 2021

Modified Files:
src/sys/arch/i386/stand/boot: boot2.c
src/sys/arch/i386/stand/efiboot: boot.c efiboot.h
src/sys/arch/i386/stand/pxeboot: main.c
src/sys/lib/libsa: bootcfg.c bootcfg.h
src/sys/stand/efiboot: boot.c efiboot.h

Log Message:
Remove banner printing code from bootloaders, add it to libsa.

This harmonizes efiboot and the various x86 bootloaders to use shared
code for printing the banner. By friendly coincidence, it also adds
support for specifying 'banner=' in arm efiboot's boot.cfg, as on x86.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/arch/i386/stand/boot/boot2.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/i386/stand/efiboot/boot.c
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/i386/stand/efiboot/efiboot.h
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/i386/stand/pxeboot/main.c
cvs rdiff -u -r1.6 -r1.7 src/sys/lib/libsa/bootcfg.c
cvs rdiff -u -r1.4 -r1.5 src/sys/lib/libsa/bootcfg.h
cvs rdiff -u -r1.35 -r1.36 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.15 -r1.16 src/sys/stand/efiboot/efiboot.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/i386/stand/boot/boot2.c
diff -u src/sys/arch/i386/stand/boot/boot2.c:1.77 src/sys/arch/i386/stand/boot/boot2.c:1.78
--- src/sys/arch/i386/stand/boot/boot2.c:1.77	Mon Jun 21 19:52:17 2021
+++ src/sys/arch/i386/stand/boot/boot2.c	Tue Sep  7 11:41:31 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot2.c,v 1.77 2021/06/21 19:52:17 nia Exp $	*/
+/*	$NetBSD: boot2.c,v 1.78 2021/09/07 11:41:31 nia Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -121,7 +121,6 @@ static const char *default_part_name;
 
 char *sprint_bootsel(const char *);
 static void bootit(const char *, int);
-void print_banner(void);
 void boot2(int, uint64_t);
 
 void	command_help(char *);
@@ -298,35 +297,6 @@ bootit(const char *filename, int howto)
 		printf("boot returned\n");
 }
 
-void
-print_banner(void)
-{
-
-	clearit();
-#ifndef SMALL
-	int n;
-	if (bootcfg_info.banner[0]) {
-		for (n = 0; n < BOOTCFG_MAXBANNER && bootcfg_info.banner[n];
-		n++) 
-			printf("%s\n", bootcfg_info.banner[n]);
-	} else {
-#endif /* !SMALL */
-		printf("\n"
-		   "  \\-__,--,___.\n"
-		   "   \\__,---`  %s (from NetBSD %s)\n"
-		   "\\   `---,_.  Revision %s\n"
-		   " \\-,_,.---`  Memory: %d/%d k\n"
-		   "  \\\n"
-		   "   \\\n"
-		   "\\\n",
-		   bootprog_name, bootprog_kernrev,
-		   bootprog_rev,
-		   getbasemem(), getextmem());
-#ifndef SMALL
-	}
-#endif /* !SMALL */
-}
-
 /*
  * Called from the initial entry point boot_start in biosboot.S
  *
@@ -379,10 +349,12 @@ boot2(int biosdev, uint64_t biossector)
 	 * If console set in boot.cfg, switch to it.
 	 * This will print the banner, so we don't need to explicitly do it
 	 */
-	if (bootcfg_info.consdev)
+	if (bootcfg_info.consdev) {
 		command_consdev(bootcfg_info.consdev);
-	else 
-		print_banner();
+	} else {
+		clearit();
+		print_bootcfg_banner(bootprog_name, bootprog_rev);
+	}
 
 	/* Display the menu, if applicable */
 	twiddle_toggle = 0;
@@ -393,7 +365,8 @@ boot2(int biosdev, uint64_t biossector)
 
 #else
 	twiddle_toggle = 0;
-	print_banner();
+	clearit();
+	print_bootcfg_banner(bootprog_name, bootprog_rev);
 #endif
 
 	printf("Press return to boot now, any other key for boot menu\n");
@@ -616,7 +589,8 @@ command_consdev(char *arg)
 		}
 
 		initio(cdp->tag);
-		print_banner();
+		clearit();
+		print_bootcfg_banner(bootprog_name, bootprog_rev);
 		return;
 	}
 error:

Index: src/sys/arch/i386/stand/efiboot/boot.c
diff -u src/sys/arch/i386/stand/efiboot/boot.c:1.19 src/sys/arch/i386/stand/efiboot/boot.c:1.20
--- src/sys/arch/i386/stand/efiboot/boot.c:1.19	Tue Jun 22 19:53:58 2021
+++ src/sys/arch/i386/stand/efiboot/boot.c	Tue Sep  7 11:41:31 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.19 2021/06/22 19:53:58 nia Exp $	*/
+/*	$NetBSD: boot.c,v 1.20 2021/09/07 11:41:31 nia Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -278,31 +278,6 @@ bootit(const char *filename, int howto)
 }
 
 void
-print_banner(void)
-{
-	int n;
-
-	clearit();
-	if (bootcfg_info.banner[0]) {
-		for (n = 0; n < BOOTCFG_MAXBANNER && bootcfg_info.banner[n];
-		n++)
-			printf("%s\n", bootcfg_info.banner[n]);
-	} else {
-		printf("\n"
-		   "  \\-__,--,___.\n"
-		   "   \\__,---`  %s (from NetBSD %s)\n"
-		   "\\   `---,_.  Revision %s\n"
-		   " \\-,_,.---`  Memory: %d/%d k\n"
-		   "  \\\n"  
-		   "   \\\n"
-		   "\\\n",
-		   bootprog_name, bootprog_kernrev,
-		   bootprog_rev,   
-		   getbasemem(), getextmem());
-	}
-}
-
-void
 boot(void)
 {
 	int currname;
@@ -344,10 +319,12 @@ boot(void)
 	 * If console set in boot.cfg, switch to it.
 	 * This will print the 

CVS commit: src/sys

2021-09-07 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Tue Sep  7 11:41:32 UTC 2021

Modified Files:
src/sys/arch/i386/stand/boot: boot2.c
src/sys/arch/i386/stand/efiboot: boot.c efiboot.h
src/sys/arch/i386/stand/pxeboot: main.c
src/sys/lib/libsa: bootcfg.c bootcfg.h
src/sys/stand/efiboot: boot.c efiboot.h

Log Message:
Remove banner printing code from bootloaders, add it to libsa.

This harmonizes efiboot and the various x86 bootloaders to use shared
code for printing the banner. By friendly coincidence, it also adds
support for specifying 'banner=' in arm efiboot's boot.cfg, as on x86.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/arch/i386/stand/boot/boot2.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/i386/stand/efiboot/boot.c
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/i386/stand/efiboot/efiboot.h
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/i386/stand/pxeboot/main.c
cvs rdiff -u -r1.6 -r1.7 src/sys/lib/libsa/bootcfg.c
cvs rdiff -u -r1.4 -r1.5 src/sys/lib/libsa/bootcfg.h
cvs rdiff -u -r1.35 -r1.36 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.15 -r1.16 src/sys/stand/efiboot/efiboot.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

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 11:00:13 UTC 2021

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

Log Message:
New crashme sysctl to enter ddb directly.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/kern/kern_crashme.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_crashme.c
diff -u src/sys/kern/kern_crashme.c:1.3 src/sys/kern/kern_crashme.c:1.4
--- src/sys/kern/kern_crashme.c:1.3	Thu Apr 23 03:15:47 2020
+++ src/sys/kern/kern_crashme.c	Tue Sep  7 11:00:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_crashme.c,v 1.3 2020/04/23 03:15:47 rin Exp $	*/
+/*	$NetBSD: kern_crashme.c,v 1.4 2021/09/07 11:00:13 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2018, 2019 Matthew R. Green
@@ -36,6 +36,10 @@
  * panic or crash.  you can add and remove nodes.
  */
 
+#ifdef _KERNEL_OPT
+#include "opt_ddb.h"
+#endif
+
 #include 
 #include 
 #include 
@@ -44,6 +48,10 @@
 #include 
 #include 
 
+#ifdef DDB
+#include 
+#endif
+
 #define DPRINTF(fmt, ...) \
 	printf("%s:%d: " fmt "\n", __func__, __LINE__, ## __VA_ARGS__)
 
@@ -51,6 +59,9 @@ static int crashme_sysctl_forwarder(SYSC
 
 static int crashme_panic(int);
 static int crashme_null_deref(int);
+#ifdef DDB
+static int crashme_ddb(int);
+#endif
 
 #define CMNODE(name, lname, func)	\
 {	\
@@ -62,6 +73,9 @@ static int crashme_null_deref(int);
 static crashme_node nodes[] = {
 CMNODE("panic", "plain old panic", crashme_panic),
 CMNODE("null_deref", "null dereference", crashme_null_deref),
+#ifdef DDB
+CMNODE("ddb", "enter ddb directly", crashme_ddb),
+#endif
 };
 static crashme_node *first_node;
 static kmutex_t crashme_lock;
@@ -234,3 +248,13 @@ crashme_null_deref(int flags)
 	*(volatile char *)0 = 0;
 	return -1;
 }
+
+#ifdef DDB
+static int
+crashme_ddb(int flags)
+{
+
+	Debugger();
+	return 0;
+}
+#endif



CVS commit: src/sys/kern

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 11:00:13 UTC 2021

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

Log Message:
New crashme sysctl to enter ddb directly.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/kern/kern_crashme.c

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



CVS commit: src/sys

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 11:00:02 UTC 2021

Modified Files:
src/sys/arch/sparc64/sparc64: machdep.c
src/sys/kern: kern_ksyms.c subr_csan.c subr_msan.c
src/sys/sys: ksyms.h

Log Message:
ksyms: Use pserialize(9) for kernel access to ksyms.

This makes it available in interrupt context, e.g. for printing
messages with kernel symbol names for return addresses as drm wants
to do.


To generate a diff of this commit:
cvs rdiff -u -r1.300 -r1.301 src/sys/arch/sparc64/sparc64/machdep.c
cvs rdiff -u -r1.99 -r1.100 src/sys/kern/kern_ksyms.c
cvs rdiff -u -r1.10 -r1.11 src/sys/kern/subr_csan.c
cvs rdiff -u -r1.14 -r1.15 src/sys/kern/subr_msan.c
cvs rdiff -u -r1.39 -r1.40 src/sys/sys/ksyms.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/sparc64/sparc64/machdep.c
diff -u src/sys/arch/sparc64/sparc64/machdep.c:1.300 src/sys/arch/sparc64/sparc64/machdep.c:1.301
--- src/sys/arch/sparc64/sparc64/machdep.c:1.300	Mon Aug  9 21:08:06 2021
+++ src/sys/arch/sparc64/sparc64/machdep.c	Tue Sep  7 11:00:02 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.300 2021/08/09 21:08:06 andvar Exp $ */
+/*	$NetBSD: machdep.c,v 1.301 2021/09/07 11:00:02 riastradh Exp $ */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2019 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.300 2021/08/09 21:08:06 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.301 2021/09/07 11:00:02 riastradh Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -102,6 +102,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -836,17 +837,22 @@ get_symbol_and_offset(const char **mod, 
 {
 	static char symbuf[256];
 	unsigned long symaddr;
+	int s, error;
 
 #if NKSYMS || defined(DDB) || defined(MODULAR)
+	s = pserialize_read_enter();
 	if (ksyms_getname(mod, sym, pc,
 			  KSYMS_CLOSEST|KSYMS_PROC|KSYMS_ANY) == 0) {
-		if (ksyms_getval(*mod, *sym, ,
- KSYMS_CLOSEST|KSYMS_PROC|KSYMS_ANY) != 0)
+		error = ksyms_getval(*mod, *sym, ,
+		KSYMS_CLOSEST|KSYMS_PROC|KSYMS_ANY);
+		pserialize_read_exit(s);
+		if (error)
 			goto failed;
 
 		*offset = (vaddr_t)(pc - symaddr);
 		return;
 	}
+	pserialize_read_exit(s);
 #endif
  failed:
 	snprintf(symbuf, sizeof symbuf, "%llx", (unsigned long long)pc);

Index: src/sys/kern/kern_ksyms.c
diff -u src/sys/kern/kern_ksyms.c:1.99 src/sys/kern/kern_ksyms.c:1.100
--- src/sys/kern/kern_ksyms.c:1.99	Tue Sep  7 10:59:46 2021
+++ src/sys/kern/kern_ksyms.c	Tue Sep  7 11:00:02 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_ksyms.c,v 1.99 2021/09/07 10:59:46 riastradh Exp $	*/
+/*	$NetBSD: kern_ksyms.c,v 1.100 2021/09/07 11:00:02 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.99 2021/09/07 10:59:46 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.100 2021/09/07 11:00:02 riastradh Exp $");
 
 #if defined(_KERNEL) && defined(_KERNEL_OPT)
 #include "opt_copy_symtab.h"
@@ -94,6 +94,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c
 #include 
 #include 
 #include 
+#include 
 
 #ifdef DDB
 #include 
@@ -118,6 +119,7 @@ static bool ksyms_initted;
 static bool ksyms_loaded;
 static kmutex_t ksyms_lock __cacheline_aligned;
 static kcondvar_t ksyms_cv;
+static pserialize_t ksyms_psz __read_mostly;
 static struct ksyms_symtab kernel_symtab;
 
 static void ksyms_hdr_init(const void *);
@@ -146,6 +148,7 @@ int ksyms_strsz;
 int ksyms_ctfsz;	/* this is not currently used by savecore(8) */
 TAILQ_HEAD(ksyms_symtab_queue, ksyms_symtab) ksyms_symtabs =
 TAILQ_HEAD_INITIALIZER(ksyms_symtabs);
+static struct pslist_head ksyms_symtabs_psz = PSLIST_INITIALIZER;
 
 static int
 ksyms_verify(const void *symstart, const void *strstart)
@@ -247,6 +250,7 @@ ksyms_init(void)
 	if (!ksyms_initted) {
 		mutex_init(_lock, MUTEX_DEFAULT, IPL_NONE);
 		cv_init(_cv, "ksyms");
+		ksyms_psz = pserialize_create();
 		ksyms_initted = true;
 	}
 }
@@ -449,9 +453,19 @@ addsymtab(const char *name, void *symsta
 	/*
 	 * Publish the symtab.  Do this at splhigh to ensure ddb never
 	 * witnesses an inconsistent state of the queue, unless memory
-	 * is so corrupt that we crash in TAILQ_INSERT_TAIL.
+	 * is so corrupt that we crash in PSLIST_WRITER_INSERT_AFTER or
+	 * TAILQ_INSERT_TAIL.
 	 */
+	PSLIST_ENTRY_INIT(tab, sd_pslist);
 	s = splhigh();
+	if (TAILQ_EMPTY(_symtabs)) {
+		PSLIST_WRITER_INSERT_HEAD(_symtabs_psz, tab, sd_pslist);
+	} else {
+		struct ksyms_symtab *last;
+
+		last = TAILQ_LAST(_symtabs, ksyms_symtab_queue);
+		PSLIST_WRITER_INSERT_AFTER(last, tab, sd_pslist);
+	}
 	TAILQ_INSERT_TAIL(_symtabs, tab, sd_queue);
 	splx(s);
 
@@ -587,7 +601,9 @@ ksyms_addsyms_explicit(void *ehdr, void 
  * "val" is a pointer to the corresponding value, if call 

CVS commit: src/sys

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 11:00:02 UTC 2021

Modified Files:
src/sys/arch/sparc64/sparc64: machdep.c
src/sys/kern: kern_ksyms.c subr_csan.c subr_msan.c
src/sys/sys: ksyms.h

Log Message:
ksyms: Use pserialize(9) for kernel access to ksyms.

This makes it available in interrupt context, e.g. for printing
messages with kernel symbol names for return addresses as drm wants
to do.


To generate a diff of this commit:
cvs rdiff -u -r1.300 -r1.301 src/sys/arch/sparc64/sparc64/machdep.c
cvs rdiff -u -r1.99 -r1.100 src/sys/kern/kern_ksyms.c
cvs rdiff -u -r1.10 -r1.11 src/sys/kern/subr_csan.c
cvs rdiff -u -r1.14 -r1.15 src/sys/kern/subr_msan.c
cvs rdiff -u -r1.39 -r1.40 src/sys/sys/ksyms.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

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:59:46 UTC 2021

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

Log Message:
ksyms(4): Simply block unload until last /dev/ksyms close.

Otherwise, readers may get a garbled snapshot of ksyms (or a crash on
an assertion failure because of the garbled snapshot) if modules are
unloaded while they read.

https://mail-index.netbsd.org/source-changes-d/2021/08/17/msg013425.html


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 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.98 src/sys/kern/kern_ksyms.c:1.99
--- src/sys/kern/kern_ksyms.c:1.98	Sun Jul 18 06:57:28 2021
+++ src/sys/kern/kern_ksyms.c	Tue Sep  7 10:59:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_ksyms.c,v 1.98 2021/07/18 06:57:28 mlelstv Exp $	*/
+/*	$NetBSD: kern_ksyms.c,v 1.99 2021/09/07 10:59:46 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.98 2021/07/18 06:57:28 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.99 2021/09/07 10:59:46 riastradh Exp $");
 
 #if defined(_KERNEL) && defined(_KERNEL_OPT)
 #include "opt_copy_symtab.h"
@@ -117,6 +117,7 @@ static struct ksyms_symtab *ksyms_last_s
 static bool ksyms_initted;
 static bool ksyms_loaded;
 static kmutex_t ksyms_lock __cacheline_aligned;
+static kcondvar_t ksyms_cv;
 static struct ksyms_symtab kernel_symtab;
 
 static void ksyms_hdr_init(const void *);
@@ -245,6 +246,7 @@ ksyms_init(void)
 
 	if (!ksyms_initted) {
 		mutex_init(_lock, MUTEX_DEFAULT, IPL_NONE);
+		cv_init(_cv, "ksyms");
 		ksyms_initted = true;
 	}
 }
@@ -328,7 +330,6 @@ addsymtab(const char *name, void *symsta
 	tab->sd_minsym = UINTPTR_MAX;
 	tab->sd_maxsym = 0;
 	tab->sd_usroffset = 0;
-	tab->sd_gone = false;
 	tab->sd_ctfstart = ctfstart;
 	tab->sd_ctfsize = ctfsize;
 	tab->sd_nmap = nmap;
@@ -446,9 +447,9 @@ addsymtab(const char *name, void *symsta
 	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.
+	 * Publish the symtab.  Do this at splhigh to ensure ddb never
+	 * witnesses an inconsistent state of the queue, unless memory
+	 * is so corrupt that we crash in TAILQ_INSERT_TAIL.
 	 */
 	s = splhigh();
 	TAILQ_INSERT_TAIL(_symtabs, tab, sd_queue);
@@ -601,8 +602,6 @@ ksyms_getval_unlocked(const char *mod, c
 #endif
 
 	TAILQ_FOREACH(st, _symtabs, sd_queue) {
-		if (__predict_false(st->sd_gone))
-			continue;
 		if (mod != NULL && strcmp(st->sd_name, mod))
 			continue;
 		if ((es = findsym(sym, st, type)) != NULL) {
@@ -636,8 +635,6 @@ ksyms_get_mod(const char *mod)
 
 	mutex_enter(_lock);
 	TAILQ_FOREACH(st, _symtabs, sd_queue) {
-		if (__predict_false(st->sd_gone))
-			continue;
 		if (mod != NULL && strcmp(st->sd_name, mod))
 			continue;
 		break;
@@ -671,8 +668,6 @@ ksyms_mod_foreach(const char *mod, ksyms
 
 	/* find the module */
 	TAILQ_FOREACH(st, _symtabs, sd_queue) {
-		if (__predict_false(st->sd_gone))
-			continue;
 		if (mod != NULL && strcmp(st->sd_name, mod))
 			continue;
 
@@ -716,8 +711,6 @@ ksyms_getname(const char **mod, const ch
 		return ENOENT;
 
 	TAILQ_FOREACH(st, _symtabs, sd_queue) {
-		if (st->sd_gone)
-			continue;
 		if (v < st->sd_minsym || v > st->sd_maxsym)
 			continue;
 		sz = st->sd_symsize/sizeof(Elf_Sym);
@@ -780,37 +773,44 @@ void
 ksyms_modunload(const char *name)
 {
 	struct ksyms_symtab *st;
-	bool do_free = false;
 	int s;
 
 	mutex_enter(_lock);
 	TAILQ_FOREACH(st, _symtabs, sd_queue) {
-		if (st->sd_gone)
-			continue;
 		if (strcmp(name, st->sd_name) != 0)
 			continue;
-		st->sd_gone = true;
-		ksyms_sizes_calc();
-		if (ksyms_opencnt == 0) {
-			/*
-			 * Ensure ddb never witnesses an inconsistent
-			 * state of the queue, unless memory is so
-			 * corrupt that we crash in TAILQ_REMOVE.
-			 */
-			s = splhigh();
-			TAILQ_REMOVE(_symtabs, st, sd_queue);
-			splx(s);
-			do_free = true;
-		}
 		break;
 	}
-	mutex_exit(_lock);
 	KASSERT(st != NULL);
 
-	if (do_free) {
-		kmem_free(st->sd_nmap, st->sd_nmapsize * sizeof(uint32_t));
-		kmem_free(st, sizeof(*st));
-	}
+	/*
+	 * Wait for last /dev/ksyms close -- readers may be in the
+	 * middle of viewing a snapshot including this module.  (We
+	 * could skip this if it's past ksyms_last_snapshot, but it's
+	 * not clear that's worth the effort.)
+	 */
+	while (ksyms_opencnt)
+		cv_wait(_cv, _lock);
+
+	/*
+	 * Remove the symtab.  Do this at splhigh to ensure ddb never
+	 * witnesses an inconsistent state of the queue, unless memory
+	 * is so corrupt that we crash in TAILQ_REMOVE.
+	 */
+	s = splhigh();
+	TAILQ_REMOVE(_symtabs, st, sd_queue);
+	splx(s);
+
+	/* Recompute the ksyms sizes now that we've 

CVS commit: src/sys/kern

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:59:46 UTC 2021

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

Log Message:
ksyms(4): Simply block unload until last /dev/ksyms close.

Otherwise, readers may get a garbled snapshot of ksyms (or a crash on
an assertion failure because of the garbled snapshot) if modules are
unloaded while they read.

https://mail-index.netbsd.org/source-changes-d/2021/08/17/msg013425.html


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



CVS commit: src/sys/dev/usb

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:44:18 UTC 2021

Modified Files:
src/sys/dev/usb: usb_subr.c usbdi.c usbdivar.h

Log Message:
usb(4): Fix xfer race between software abort and hardware completion.

This fixes a bug in the API contract of usbd_abort_pipe: with the
change, the caller is guaranteed the xfer completion callbacks have
returned; without the change, completion callbacks could still be
running on the queued xfers while the caller of usbd_abort_pipe
proceeds to concurrently issue usbd_destroy_xfer.

This also fixes the following problem for interrupt pipes, whose
xfers stay on the queue until the pipe is aborted:

Thread 1: Hardware completion interrupt calls usb_transfer_complete.
Thread 1: pipe->up_repeat is 1, so usb_transfer_complete keeps xfer
  queued.
Thread 2: Calls usbd_abort_pipe (e.g., in detach).
Thread 2: usbd_abort_pipe waits for bus lock.
Thread 1: usb_transfer_complete releases bus lock to invoke callback.
Thread 2: Sets pipe->up_repeat := 0 (too late for thread 1 to see).
Thread 1: usb_transfer_complete waits to reacquire bus lock before
  resetting xfer status to USBD_NOT_STARTED.
Thread 2: Repeatdly calls upm_abort on the same xfer, which does
  nothing because upm_abort just does usbd_abort_xfer which does
  nothing because the xfer status is (e.g.) USBD_IOERROR and not
  USBD_IN_PROGRESS.

Thread 2 is now spinning forever with the bus lock held (and possibly
the kernel lock) waiting for queue or xfer status to change, which
will never happen as long as it holds the bus lock.

The resolution is for thread 2 to notice that thread 1 is busy
invoking a callback, and to wait until thread 1 has finished invoking
the callback and updated the xfer status to reset it to
USBD_NOT_STARTED at which point thread 1 can make progress again.

XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.266 -r1.267 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.218 -r1.219 src/sys/dev/usb/usbdi.c
cvs rdiff -u -r1.129 -r1.130 src/sys/dev/usb/usbdivar.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/usb/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.266 src/sys/dev/usb/usb_subr.c:1.267
--- src/sys/dev/usb/usb_subr.c:1.266	Sat Aug  7 16:19:17 2021
+++ src/sys/dev/usb/usb_subr.c	Tue Sep  7 10:44:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.266 2021/08/07 16:19:17 thorpej Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.267 2021/09/07 10:44:18 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.266 2021/08/07 16:19:17 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.267 2021/09/07 10:44:18 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -946,6 +946,8 @@ usbd_setup_pipe_flags(struct usbd_device
 	p->up_interval = ival;
 	p->up_flags = flags;
 	SIMPLEQ_INIT(>up_queue);
+	p->up_callingxfer = NULL;
+	cv_init(>up_callingcv, "usbpipecb");
 
 	err = dev->ud_bus->ub_methods->ubm_open(p);
 	if (err) {
@@ -964,8 +966,10 @@ usbd_setup_pipe_flags(struct usbd_device
 	ep_acquired = false;	/* handed off to pipe */
 	err = USBD_NORMAL_COMPLETION;
 
-out:	if (p)
+out:	if (p) {
+		cv_destroy(>up_callingcv);
 		kmem_free(p, dev->ud_bus->ub_pipesize);
+	}
 	if (ep_acquired)
 		usbd_endpoint_release(dev, ep);
 	return err;

Index: src/sys/dev/usb/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.218 src/sys/dev/usb/usbdi.c:1.219
--- src/sys/dev/usb/usbdi.c:1.218	Wed Jun 16 13:20:49 2021
+++ src/sys/dev/usb/usbdi.c	Tue Sep  7 10:44:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.218 2021/06/16 13:20:49 riastradh Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.219 2021/09/07 10:44:18 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.218 2021/06/16 13:20:49 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.219 2021/09/07 10:44:18 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -340,6 +340,7 @@ usbd_close_pipe(struct usbd_pipe *pipe)
 	pipe->up_methods->upm_close(pipe);
 	usbd_unlock_pipe(pipe);
 
+	cv_destroy(>up_callingcv);
 	if (pipe->up_intrxfer)
 		usbd_destroy_xfer(pipe->up_intrxfer);
 	usb_rem_task_wait(pipe->up_dev, >up_async_task, USB_TASKQ_DRIVER,
@@ -991,6 +992,13 @@ usbd_ar_pipe(struct usbd_pipe *pipe)
 			/* Make the HC abort it (and invoke the callback). */
 			SDT_PROBE1(usb, device, xfer, abort,  xfer);
 			pipe->up_methods->upm_abort(xfer);
+			while (pipe->up_callingxfer == xfer) {
+USBHIST_LOG(usbdebug, "wait for callback"
+"pipe = %#jx xfer = %#jx",
+(uintptr_t)pipe, (uintptr_t)xfer, 0, 0);
+cv_wait(>up_callingcv,
+pipe->up_dev->ud_bus->ub_lock);
+			}
 			/* XXX only for non-0 usbd_clear_endpoint_stall(pipe); */
 		}
 	}
@@ 

CVS commit: src/sys/dev/usb

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:44:18 UTC 2021

Modified Files:
src/sys/dev/usb: usb_subr.c usbdi.c usbdivar.h

Log Message:
usb(4): Fix xfer race between software abort and hardware completion.

This fixes a bug in the API contract of usbd_abort_pipe: with the
change, the caller is guaranteed the xfer completion callbacks have
returned; without the change, completion callbacks could still be
running on the queued xfers while the caller of usbd_abort_pipe
proceeds to concurrently issue usbd_destroy_xfer.

This also fixes the following problem for interrupt pipes, whose
xfers stay on the queue until the pipe is aborted:

Thread 1: Hardware completion interrupt calls usb_transfer_complete.
Thread 1: pipe->up_repeat is 1, so usb_transfer_complete keeps xfer
  queued.
Thread 2: Calls usbd_abort_pipe (e.g., in detach).
Thread 2: usbd_abort_pipe waits for bus lock.
Thread 1: usb_transfer_complete releases bus lock to invoke callback.
Thread 2: Sets pipe->up_repeat := 0 (too late for thread 1 to see).
Thread 1: usb_transfer_complete waits to reacquire bus lock before
  resetting xfer status to USBD_NOT_STARTED.
Thread 2: Repeatdly calls upm_abort on the same xfer, which does
  nothing because upm_abort just does usbd_abort_xfer which does
  nothing because the xfer status is (e.g.) USBD_IOERROR and not
  USBD_IN_PROGRESS.

Thread 2 is now spinning forever with the bus lock held (and possibly
the kernel lock) waiting for queue or xfer status to change, which
will never happen as long as it holds the bus lock.

The resolution is for thread 2 to notice that thread 1 is busy
invoking a callback, and to wait until thread 1 has finished invoking
the callback and updated the xfer status to reset it to
USBD_NOT_STARTED at which point thread 1 can make progress again.

XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.266 -r1.267 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.218 -r1.219 src/sys/dev/usb/usbdi.c
cvs rdiff -u -r1.129 -r1.130 src/sys/dev/usb/usbdivar.h

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

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:44:05 UTC 2021

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

Log Message:
ugen(4): Keep fields null when not allocated; kassert on close.

This avoids silent leaks in DIAGNOSTIC kernels.


To generate a diff of this commit:
cvs rdiff -u -r1.166 -r1.167 src/sys/dev/usb/ugen.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/ugen.c
diff -u src/sys/dev/usb/ugen.c:1.166 src/sys/dev/usb/ugen.c:1.167
--- src/sys/dev/usb/ugen.c:1.166	Tue Sep  7 10:43:51 2021
+++ src/sys/dev/usb/ugen.c	Tue Sep  7 10:44:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugen.c,v 1.166 2021/09/07 10:43:51 riastradh Exp $	*/
+/*	$NetBSD: ugen.c,v 1.167 2021/09/07 10:44:04 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.166 2021/09/07 10:43:51 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.167 2021/09/07 10:44:04 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -669,8 +669,10 @@ ugenopen(dev_t dev, int flag, int mode, 
 			DPRINTFN(5, ("ugenopen: isoc open done\n"));
 			break;
 		bad:
-			while (--i >= 0) /* implicit buffer free */
+			while (--i >= 0) { /* implicit buffer free */
 usbd_destroy_xfer(sce->isoreqs[i].xfer);
+sce->isoreqs[i].xfer = NULL;
+			}
 			usbd_close_pipe(sce->pipeh);
 			sce->pipeh = NULL;
 			kmem_free(sce->ibuf, isize * UGEN_NISOFRAMES);
@@ -699,13 +701,8 @@ ugen_do_close(struct ugen_softc *sc, int
 
 	KASSERT(KERNEL_LOCKED_P()); /* sc_is_open */
 
-	if (!sc->sc_is_open[endpt]) {
-		KASSERT(sc->sc_endpoints[endpt][IN].pipeh == NULL);
-		KASSERT(sc->sc_endpoints[endpt][OUT].pipeh == NULL);
-		KASSERT(sc->sc_endpoints[endpt][IN].ibuf == NULL);
-		KASSERT(sc->sc_endpoints[endpt][OUT].ibuf == NULL);
-		return;
-	}
+	if (!sc->sc_is_open[endpt])
+		goto out;
 
 	if (endpt == USB_CONTROL_ENDPOINT) {
 		DPRINTFN(5, ("ugenclose: close control\n"));
@@ -733,13 +730,16 @@ ugen_do_close(struct ugen_softc *sc, int
 			msize = isize;
 			break;
 		case UE_ISOCHRONOUS:
-			for (i = 0; i < UGEN_NISOREQS; ++i)
+			for (i = 0; i < UGEN_NISOREQS; ++i) {
 usbd_destroy_xfer(sce->isoreqs[i].xfer);
+sce->isoreqs[i].xfer = NULL;
+			}
 			msize = isize * UGEN_NISOFRAMES;
 			break;
 		case UE_BULK:
 			if (sce->state & (UGEN_BULK_RA | UGEN_BULK_WB)) {
 usbd_destroy_xfer(sce->ra_wb_xfer);
+sce->ra_wb_xfer = NULL;
 msize = sce->ra_wb_bufsize;
 			}
 			break;
@@ -755,6 +755,14 @@ ugen_do_close(struct ugen_softc *sc, int
 	}
 
 out:	sc->sc_is_open[endpt] = 0;
+	for (dir = OUT; dir <= IN; dir++) {
+		sce = >sc_endpoints[endpt][dir];
+		KASSERT(sce->pipeh == NULL);
+		KASSERT(sce->ibuf == NULL);
+		KASSERT(sce->ra_wb_xfer == NULL);
+		for (i = 0; i < UGEN_NISOREQS; i++)
+			KASSERT(sce->isoreqs[i].xfer == NULL);
+	}
 }
 
 static int
@@ -1649,6 +1657,8 @@ ugen_do_ioctl(struct ugen_softc *sc, int
 			/* Only turn RA on if it's currently off. */
 			if (sce->state & UGEN_BULK_RA)
 return 0;
+			KASSERT(sce->ra_wb_xfer == NULL);
+			KASSERT(sce->ibuf == NULL);
 
 			if (sce->ra_wb_bufsize == 0 || sce->ra_wb_reqsize == 0)
 /* shouldn't happen */
@@ -1674,6 +1684,7 @@ ugen_do_ioctl(struct ugen_softc *sc, int
 kmem_free(sce->ibuf, sce->ra_wb_bufsize);
 sce->ibuf = NULL;
 usbd_destroy_xfer(sce->ra_wb_xfer);
+sce->ra_wb_xfer = NULL;
 return EIO;
 			}
 		} else {
@@ -1684,6 +1695,7 @@ ugen_do_ioctl(struct ugen_softc *sc, int
 			sce->state &= ~UGEN_BULK_RA;
 			usbd_abort_pipe(sce->pipeh);
 			usbd_destroy_xfer(sce->ra_wb_xfer);
+			sce->ra_wb_xfer = NULL;
 			/*
 			 * XXX Discard whatever's in the buffer, but we
 			 * should keep it around and drain the buffer
@@ -1707,12 +1719,15 @@ ugen_do_ioctl(struct ugen_softc *sc, int
 			/* Only turn WB on if it's currently off. */
 			if (sce->state & UGEN_BULK_WB)
 return 0;
+			KASSERT(sce->ra_wb_xfer == NULL);
+			KASSERT(sce->ibuf == NULL);
 
 			if (sce->ra_wb_bufsize == 0 || sce->ra_wb_reqsize == 0)
 /* shouldn't happen */
 return EINVAL;
 			error = usbd_create_xfer(sce->pipeh, sce->ra_wb_reqsize,
 			0, 0, >ra_wb_xfer);
+			/* XXX check error???  */
 			sce->ra_wb_xferlen = sce->ra_wb_reqsize;
 			sce->ibuf = kmem_alloc(sce->ra_wb_bufsize, KM_SLEEP);
 			sce->fill = sce->cur = sce->ibuf;
@@ -1732,6 +1747,7 @@ ugen_do_ioctl(struct ugen_softc *sc, int
 			 */
 			usbd_abort_pipe(sce->pipeh);
 			usbd_destroy_xfer(sce->ra_wb_xfer);
+			sce->ra_wb_xfer = NULL;
 			kmem_free(sce->ibuf, sce->ra_wb_bufsize);
 			sce->ibuf = NULL;
 		}



CVS commit: src/sys/dev/usb

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:44:05 UTC 2021

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

Log Message:
ugen(4): Keep fields null when not allocated; kassert on close.

This avoids silent leaks in DIAGNOSTIC kernels.


To generate a diff of this commit:
cvs rdiff -u -r1.166 -r1.167 src/sys/dev/usb/ugen.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

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:43:51 UTC 2021

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

Log Message:
ugen(4): Use cv_wait loop for draining reference count on detach.

- Should be no need to use cv_timedwait because all users have now
  been given a wakeup (previously writers were not, so we relied on
  the timeouts to work out).

- Need to run this in a loop or else a spurious wakeup could cause us
  to free data structures before the users have actually drained.


To generate a diff of this commit:
cvs rdiff -u -r1.165 -r1.166 src/sys/dev/usb/ugen.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/ugen.c
diff -u src/sys/dev/usb/ugen.c:1.165 src/sys/dev/usb/ugen.c:1.166
--- src/sys/dev/usb/ugen.c:1.165	Tue Sep  7 10:43:34 2021
+++ src/sys/dev/usb/ugen.c	Tue Sep  7 10:43:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugen.c,v 1.165 2021/09/07 10:43:34 riastradh Exp $	*/
+/*	$NetBSD: ugen.c,v 1.166 2021/09/07 10:43:51 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.165 2021/09/07 10:43:34 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.166 2021/09/07 10:43:51 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1215,6 +1215,12 @@ ugen_detach(device_t self, int flags)
 		}
 	}
 
+	/*
+	 * Wait for users to drain.  Before this point there can be no
+	 * more I/O operations started because we set sc_dying; after
+	 * this, there can be no more I/O operations in progress, so it
+	 * will be safe to free things.
+	 */
 	mutex_enter(>sc_lock);
 	if (--sc->sc_refcnt >= 0) {
 		/* Wake everyone */
@@ -1223,8 +1229,9 @@ ugen_detach(device_t self, int flags)
 cv_broadcast(>sc_endpoints[i][dir].cv);
 		}
 		/* Wait for processes to go away. */
-		if (cv_timedwait(>sc_detach_cv, >sc_lock, hz * 60))
-			aprint_error_dev(self, ": didn't detach\n");
+		do {
+			cv_wait(>sc_detach_cv, >sc_lock);
+		} while (sc->sc_refcnt >= 0);
 	}
 	mutex_exit(>sc_lock);
 



CVS commit: src/sys/dev/usb

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:43:51 UTC 2021

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

Log Message:
ugen(4): Use cv_wait loop for draining reference count on detach.

- Should be no need to use cv_timedwait because all users have now
  been given a wakeup (previously writers were not, so we relied on
  the timeouts to work out).

- Need to run this in a loop or else a spurious wakeup could cause us
  to free data structures before the users have actually drained.


To generate a diff of this commit:
cvs rdiff -u -r1.165 -r1.166 src/sys/dev/usb/ugen.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

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:43:34 UTC 2021

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

Log Message:
ugen(4): Use cv_broadcast to wake all I/O operations on detach.

Nothing prevents two concurrent reads or two concurrent writes on any
particular ugen endpoint, as far as I can tell, and we need to wake
all of them, so use cv_broadcast rather than cv_signal on detach.

XXX It's not clear to me that cv_signal in the xfer completion
callbacks is correct either: any one consumer might use less than the
full buffer.  So I think either we should use cv_broadcast, or
consumers that don't use the whole buffer need to issue cv_signal too
to wake up another consumer even if we want to avoid a thundering
herd.


To generate a diff of this commit:
cvs rdiff -u -r1.164 -r1.165 src/sys/dev/usb/ugen.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/ugen.c
diff -u src/sys/dev/usb/ugen.c:1.164 src/sys/dev/usb/ugen.c:1.165
--- src/sys/dev/usb/ugen.c:1.164	Tue Sep  7 10:43:21 2021
+++ src/sys/dev/usb/ugen.c	Tue Sep  7 10:43:34 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugen.c,v 1.164 2021/09/07 10:43:21 riastradh Exp $	*/
+/*	$NetBSD: ugen.c,v 1.165 2021/09/07 10:43:34 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.164 2021/09/07 10:43:21 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.165 2021/09/07 10:43:34 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1220,7 +1220,7 @@ ugen_detach(device_t self, int flags)
 		/* Wake everyone */
 		for (i = 0; i < USB_MAX_ENDPOINTS; i++) {
 			for (dir = OUT; dir <= IN; dir++)
-cv_signal(>sc_endpoints[i][dir].cv);
+cv_broadcast(>sc_endpoints[i][dir].cv);
 		}
 		/* Wait for processes to go away. */
 		if (cv_timedwait(>sc_detach_cv, >sc_lock, hz * 60))



CVS commit: src/sys/dev/usb

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:43:34 UTC 2021

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

Log Message:
ugen(4): Use cv_broadcast to wake all I/O operations on detach.

Nothing prevents two concurrent reads or two concurrent writes on any
particular ugen endpoint, as far as I can tell, and we need to wake
all of them, so use cv_broadcast rather than cv_signal on detach.

XXX It's not clear to me that cv_signal in the xfer completion
callbacks is correct either: any one consumer might use less than the
full buffer.  So I think either we should use cv_broadcast, or
consumers that don't use the whole buffer need to issue cv_signal too
to wake up another consumer even if we want to avoid a thundering
herd.


To generate a diff of this commit:
cvs rdiff -u -r1.164 -r1.165 src/sys/dev/usb/ugen.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

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:43:21 UTC 2021

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

Log Message:
ugen(4): Issue explicit wakeup on detach for OUT endpoints too.

Writers can be blocked in cv_timedwait_sig too.

While here, fix comment: aborting the pipes does not cause all
waiters to wake, because the xfer completion callbacks sometimes skip
the notification.  We should maybe change that, but this is a simpler
fix to ensure everyone waiting on I/O is woken to notice sc_dying.


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 src/sys/dev/usb/ugen.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/ugen.c
diff -u src/sys/dev/usb/ugen.c:1.163 src/sys/dev/usb/ugen.c:1.164
--- src/sys/dev/usb/ugen.c:1.163	Tue Sep  7 10:43:11 2021
+++ src/sys/dev/usb/ugen.c	Tue Sep  7 10:43:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugen.c,v 1.163 2021/09/07 10:43:11 riastradh Exp $	*/
+/*	$NetBSD: ugen.c,v 1.164 2021/09/07 10:43:21 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.163 2021/09/07 10:43:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.164 2021/09/07 10:43:21 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1206,7 +1206,7 @@ ugen_detach(device_t self, int flags)
 	if (!sc->sc_attached)
 		goto out;
 
-	/* Abort all pipes.  Causes processes waiting for transfer to wake. */
+	/* Abort all pipes.  */
 	for (i = 0; i < USB_MAX_ENDPOINTS; i++) {
 		for (dir = OUT; dir <= IN; dir++) {
 			sce = >sc_endpoints[i][dir];
@@ -1218,8 +1218,10 @@ ugen_detach(device_t self, int flags)
 	mutex_enter(>sc_lock);
 	if (--sc->sc_refcnt >= 0) {
 		/* Wake everyone */
-		for (i = 0; i < USB_MAX_ENDPOINTS; i++)
-			cv_signal(>sc_endpoints[i][IN].cv);
+		for (i = 0; i < USB_MAX_ENDPOINTS; i++) {
+			for (dir = OUT; dir <= IN; dir++)
+cv_signal(>sc_endpoints[i][dir].cv);
+		}
 		/* Wait for processes to go away. */
 		if (cv_timedwait(>sc_detach_cv, >sc_lock, hz * 60))
 			aprint_error_dev(self, ": didn't detach\n");



CVS commit: src/sys/dev/usb

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:43:21 UTC 2021

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

Log Message:
ugen(4): Issue explicit wakeup on detach for OUT endpoints too.

Writers can be blocked in cv_timedwait_sig too.

While here, fix comment: aborting the pipes does not cause all
waiters to wake, because the xfer completion callbacks sometimes skip
the notification.  We should maybe change that, but this is a simpler
fix to ensure everyone waiting on I/O is woken to notice sc_dying.


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 src/sys/dev/usb/ugen.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

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:43:11 UTC 2021

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

Log Message:
ugen(4): Ensure we close pipes on detach.

Calling vdevgone has the effect of VOP_REVOKE -> spec_node_revoke ->
VOP_CLOSE -> spec_close -> cdev_close -> ugenclose, but:

(a) the flags passed to VOP_CLOSE don't have FREAD or FWRITE, and
(b) ugenclose has no effect when sc_dying is set anyway.

So create another path into the close logic, ugen_do_close.  We have
to do this in detach _after_ the references have drained because we
may free buffers that other users are still using while the reference
count is nonzero.


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/sys/dev/usb/ugen.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/ugen.c
diff -u src/sys/dev/usb/ugen.c:1.162 src/sys/dev/usb/ugen.c:1.163
--- src/sys/dev/usb/ugen.c:1.162	Tue Sep  7 10:42:59 2021
+++ src/sys/dev/usb/ugen.c	Tue Sep  7 10:43:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugen.c,v 1.162 2021/09/07 10:42:59 riastradh Exp $	*/
+/*	$NetBSD: ugen.c,v 1.163 2021/09/07 10:43:11 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.162 2021/09/07 10:42:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.163 2021/09/07 10:43:11 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -690,30 +690,25 @@ out:	if (error && opened)
 	return error;
 }
 
-static int
-ugenclose(dev_t dev, int flag, int mode, struct lwp *l)
+static void
+ugen_do_close(struct ugen_softc *sc, int flag, int endpt)
 {
-	int endpt = UGENENDPOINT(dev);
-	struct ugen_softc *sc;
 	struct ugen_endpoint *sce;
 	int dir;
 	int i;
-	int error;
 
 	KASSERT(KERNEL_LOCKED_P()); /* sc_is_open */
 
-	if ((sc = ugenif_acquire(UGENUNIT(dev))) == NULL)
-		return ENXIO;
-
-	DPRINTFN(5, ("ugenclose: flag=%d, mode=%d, unit=%d, endpt=%d\n",
-		 flag, mode, UGENUNIT(dev), endpt));
-
-	KASSERT(sc->sc_is_open[endpt]);
+	if (!sc->sc_is_open[endpt]) {
+		KASSERT(sc->sc_endpoints[endpt][IN].pipeh == NULL);
+		KASSERT(sc->sc_endpoints[endpt][OUT].pipeh == NULL);
+		KASSERT(sc->sc_endpoints[endpt][IN].ibuf == NULL);
+		KASSERT(sc->sc_endpoints[endpt][OUT].ibuf == NULL);
+		return;
+	}
 
 	if (endpt == USB_CONTROL_ENDPOINT) {
 		DPRINTFN(5, ("ugenclose: close control\n"));
-		sc->sc_is_open[endpt] = 0;
-		error = 0;
 		goto out;
 	}
 
@@ -758,11 +753,31 @@ ugenclose(dev_t dev, int flag, int mode,
 			sce->ibuf = NULL;
 		}
 	}
-	sc->sc_is_open[endpt] = 0;
-	error = 0;
 
-out:	ugenif_release(sc);
-	return error;
+out:	sc->sc_is_open[endpt] = 0;
+}
+
+static int
+ugenclose(dev_t dev, int flag, int mode, struct lwp *l)
+{
+	int endpt = UGENENDPOINT(dev);
+	struct ugen_softc *sc;
+
+	DPRINTFN(5, ("ugenclose: flag=%d, mode=%d, unit=%d, endpt=%d\n",
+		 flag, mode, UGENUNIT(dev), endpt));
+
+	KASSERT(KERNEL_LOCKED_P()); /* ugen_do_close */
+
+	if ((sc = ugenif_acquire(UGENUNIT(dev))) == NULL)
+		return ENXIO;
+
+	KASSERT(sc->sc_is_open[endpt]);
+	ugen_do_close(sc, flag, endpt);
+	KASSERT(!sc->sc_is_open[endpt]);
+
+	ugenif_release(sc);
+
+	return 0;
 }
 
 Static int
@@ -1214,10 +1229,17 @@ ugen_detach(device_t self, int flags)
 	/* locate the major number */
 	maj = cdevsw_lookup_major(_cdevsw);
 
-	/* Nuke the vnodes for any open instances (calls close). */
+	/*
+	 * Nuke the vnodes for any open instances (calls ugenclose, but
+	 * with no effect because we already set sc_dying).
+	 */
 	mn = sc->sc_unit * USB_MAX_ENDPOINTS;
 	vdevgone(maj, mn, mn + USB_MAX_ENDPOINTS - 1, VCHR);
 
+	/* Actually close any lingering pipes.  */
+	for (i = 0; i < USB_MAX_ENDPOINTS; i++)
+		ugen_do_close(sc, FREAD|FWRITE, i);
+
 	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev);
 	ugenif_put_unit(sc);
 



CVS commit: src/sys/dev/usb

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:43:11 UTC 2021

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

Log Message:
ugen(4): Ensure we close pipes on detach.

Calling vdevgone has the effect of VOP_REVOKE -> spec_node_revoke ->
VOP_CLOSE -> spec_close -> cdev_close -> ugenclose, but:

(a) the flags passed to VOP_CLOSE don't have FREAD or FWRITE, and
(b) ugenclose has no effect when sc_dying is set anyway.

So create another path into the close logic, ugen_do_close.  We have
to do this in detach _after_ the references have drained because we
may free buffers that other users are still using while the reference
count is nonzero.


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/sys/dev/usb/ugen.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

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:42:59 UTC 2021

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

Log Message:
ugen(4): Refuse non-forced detach with EBUSY if endpoints are open.

Sprinkle some comments.


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/sys/dev/usb/ugen.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/ugen.c
diff -u src/sys/dev/usb/ugen.c:1.161 src/sys/dev/usb/ugen.c:1.162
--- src/sys/dev/usb/ugen.c:1.161	Tue Sep  7 10:42:48 2021
+++ src/sys/dev/usb/ugen.c	Tue Sep  7 10:42:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugen.c,v 1.161 2021/09/07 10:42:48 riastradh Exp $	*/
+/*	$NetBSD: ugen.c,v 1.162 2021/09/07 10:42:59 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.161 2021/09/07 10:42:48 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.162 2021/09/07 10:42:59 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1167,9 +1167,27 @@ ugen_detach(device_t self, int flags)
 
 	DPRINTF(("ugen_detach: sc=%p flags=%d\n", sc, flags));
 
+	KASSERT(KERNEL_LOCKED_P()); /* sc_is_open */
+
+	/*
+	 * Fail if we're not forced to detach and userland has any
+	 * endpoints open.
+	 */
+	if ((flags & DETACH_FORCE) == 0) {
+		for (i = 0; i < USB_MAX_ENDPOINTS; i++) {
+			if (sc->sc_is_open[i])
+return EBUSY;
+		}
+	}
+
+	/* Prevent new users.  Prevent suspend/resume.  */
 	sc->sc_dying = 1;
 	pmf_device_deregister(self);
 
+	/*
+	 * If we never finished attaching, skip nixing endpoints and
+	 * users because there aren't any.
+	 */
 	if (!sc->sc_attached)
 		goto out;
 



CVS commit: src/sys/dev/usb

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:42:59 UTC 2021

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

Log Message:
ugen(4): Refuse non-forced detach with EBUSY if endpoints are open.

Sprinkle some comments.


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/sys/dev/usb/ugen.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

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:42:48 UTC 2021

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

Log Message:
ugen(4): Prevent ugenopen while ugen_set_config is in progress.

(except on the control endpoint)

Although we hold the kernel lock (which we should eventually change),
we may sleep in usbd_set_config_no at which point ugenopen might
happen and start making use of endpoint state which we'll stomp all
over once usbd_set_config_no returns.  Setting sc_is_open[endpt]
while we wait prevents this.


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 src/sys/dev/usb/ugen.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/ugen.c
diff -u src/sys/dev/usb/ugen.c:1.160 src/sys/dev/usb/ugen.c:1.161
--- src/sys/dev/usb/ugen.c:1.160	Tue Sep  7 10:42:34 2021
+++ src/sys/dev/usb/ugen.c	Tue Sep  7 10:42:48 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugen.c,v 1.160 2021/09/07 10:42:34 riastradh Exp $	*/
+/*	$NetBSD: ugen.c,v 1.161 2021/09/07 10:42:48 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.160 2021/09/07 10:42:34 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.161 2021/09/07 10:42:48 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -455,6 +455,12 @@ ugen_set_config(struct ugen_softc *sc, i
   device_xname(sc->sc_dev), endptno));
 return USBD_IN_USE;
 			}
+
+		/* Prevent opening while we're setting the config.  */
+		for (endptno = 1; endptno < USB_MAX_ENDPOINTS; endptno++) {
+			KASSERT(!sc->sc_is_open[endptno]);
+			sc->sc_is_open[endptno] = 1;
+		}
 	}
 
 	/* Avoid setting the current value. */
@@ -462,23 +468,23 @@ ugen_set_config(struct ugen_softc *sc, i
 	if (!cdesc || cdesc->bConfigurationValue != configno) {
 		err = usbd_set_config_no(dev, configno, 1);
 		if (err)
-			return err;
+			goto out;
 	}
 
 	ugen_clear_endpoints(sc);
 
 	err = usbd_interface_count(dev, );
 	if (err)
-		return err;
+		goto out;
 
 	for (ifaceno = 0; ifaceno < niface; ifaceno++) {
 		DPRINTFN(1,("ugen_set_config: ifaceno %d\n", ifaceno));
 		err = usbd_device2interface_handle(dev, ifaceno, );
 		if (err)
-			return err;
+			goto out;
 		err = usbd_endpoint_count(iface, );
 		if (err)
-			return err;
+			goto out;
 		for (endptno = 0; endptno < nendpt; endptno++) {
 			ed = usbd_interface2endpoint_descriptor(iface,endptno);
 			KASSERT(ed != NULL);
@@ -494,7 +500,19 @@ ugen_set_config(struct ugen_softc *sc, i
 			sce->iface = iface;
 		}
 	}
-	return USBD_NORMAL_COMPLETION;
+	err = USBD_NORMAL_COMPLETION;
+
+out:	if (chkopen) {
+		/*
+		 * Allow open again now that we're done trying to set
+		 * the config.
+		 */
+		for (endptno = 1; endptno < USB_MAX_ENDPOINTS; endptno++) {
+			KASSERT(sc->sc_is_open[endptno]);
+			sc->sc_is_open[endptno] = 0;
+		}
+	}
+	return err;
 }
 
 static int



CVS commit: src/sys/dev/usb

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:42:48 UTC 2021

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

Log Message:
ugen(4): Prevent ugenopen while ugen_set_config is in progress.

(except on the control endpoint)

Although we hold the kernel lock (which we should eventually change),
we may sleep in usbd_set_config_no at which point ugenopen might
happen and start making use of endpoint state which we'll stomp all
over once usbd_set_config_no returns.  Setting sc_is_open[endpt]
while we wait prevents this.


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 src/sys/dev/usb/ugen.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

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:42:34 UTC 2021

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

Log Message:
ugen(4): Fix race of ugenopen against itself.

Even though we have the kernel lock held, a sleep during kmem_alloc
or usbd_open_pipe could allow another ugenopen to run concurrently
before we have marked the endpoint opened.

To avoid this, mark the endpoint open immediately (while we still
have the kernel lock held and before any sleeps, so there is no
TOCTOU error here), and then revert on unwind in the event of
failure.


To generate a diff of this commit:
cvs rdiff -u -r1.159 -r1.160 src/sys/dev/usb/ugen.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/ugen.c
diff -u src/sys/dev/usb/ugen.c:1.159 src/sys/dev/usb/ugen.c:1.160
--- src/sys/dev/usb/ugen.c:1.159	Tue Sep  7 10:42:22 2021
+++ src/sys/dev/usb/ugen.c	Tue Sep  7 10:42:34 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugen.c,v 1.159 2021/09/07 10:42:22 riastradh Exp $	*/
+/*	$NetBSD: ugen.c,v 1.160 2021/09/07 10:42:34 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.159 2021/09/07 10:42:22 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.160 2021/09/07 10:42:34 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -510,6 +510,7 @@ ugenopen(dev_t dev, int flag, int mode, 
 	struct usbd_xfer *xfer;
 	int i, j;
 	int error;
+	int opened;
 
 	KASSERT(KERNEL_LOCKED_P()); /* sc_is_open */
 
@@ -521,7 +522,7 @@ ugenopen(dev_t dev, int flag, int mode, 
 
 	/* The control endpoint allows multiple opens. */
 	if (endpt == USB_CONTROL_ENDPOINT) {
-		sc->sc_is_open[USB_CONTROL_ENDPOINT] = 1;
+		opened = sc->sc_is_open[USB_CONTROL_ENDPOINT] = 1;
 		error = 0;
 		goto out;
 	}
@@ -530,6 +531,7 @@ ugenopen(dev_t dev, int flag, int mode, 
 		error = EBUSY;
 		goto out;
 	}
+	opened = sc->sc_is_open[endpt] = 1;
 
 	/* Make sure there are pipes for all directions. */
 	for (dir = OUT; dir <= IN; dir++) {
@@ -663,9 +665,10 @@ ugenopen(dev_t dev, int flag, int mode, 
 			goto out;
 		}
 	}
-	sc->sc_is_open[endpt] = 1;
 	error = 0;
-out:	ugenif_release(sc);
+out:	if (error && opened)
+		sc->sc_is_open[endpt] = 0;
+	ugenif_release(sc);
 	return error;
 }
 



CVS commit: src/sys/dev/usb

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:42:34 UTC 2021

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

Log Message:
ugen(4): Fix race of ugenopen against itself.

Even though we have the kernel lock held, a sleep during kmem_alloc
or usbd_open_pipe could allow another ugenopen to run concurrently
before we have marked the endpoint opened.

To avoid this, mark the endpoint open immediately (while we still
have the kernel lock held and before any sleeps, so there is no
TOCTOU error here), and then revert on unwind in the event of
failure.


To generate a diff of this commit:
cvs rdiff -u -r1.159 -r1.160 src/sys/dev/usb/ugen.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

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:42:22 UTC 2021

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

Log Message:
ugen(4): Sprinkle KERNEL_LOCKED_P assertions around sc_is_open.


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 src/sys/dev/usb/ugen.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/ugen.c
diff -u src/sys/dev/usb/ugen.c:1.158 src/sys/dev/usb/ugen.c:1.159
--- src/sys/dev/usb/ugen.c:1.158	Fri Dec 18 01:40:20 2020
+++ src/sys/dev/usb/ugen.c	Tue Sep  7 10:42:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugen.c,v 1.158 2020/12/18 01:40:20 thorpej Exp $	*/
+/*	$NetBSD: ugen.c,v 1.159 2021/09/07 10:42:22 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.158 2020/12/18 01:40:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.159 2021/09/07 10:42:22 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -441,6 +441,8 @@ ugen_set_config(struct ugen_softc *sc, i
 	DPRINTFN(1,("ugen_set_config: %s to configno %d, sc=%p\n",
 		device_xname(sc->sc_dev), configno, sc));
 
+	KASSERT(KERNEL_LOCKED_P()); /* sc_is_open */
+
 	if (chkopen) {
 		/*
 		 * We start at 1, not 0, because we don't care whether the
@@ -509,6 +511,8 @@ ugenopen(dev_t dev, int flag, int mode, 
 	int i, j;
 	int error;
 
+	KASSERT(KERNEL_LOCKED_P()); /* sc_is_open */
+
 	if ((sc = ugenif_acquire(unit)) == NULL)
 		return ENXIO;
 
@@ -675,6 +679,8 @@ ugenclose(dev_t dev, int flag, int mode,
 	int i;
 	int error;
 
+	KASSERT(KERNEL_LOCKED_P()); /* sc_is_open */
+
 	if ((sc = ugenif_acquire(UGENUNIT(dev))) == NULL)
 		return ENXIO;
 
@@ -1530,6 +1536,8 @@ ugen_do_ioctl(struct ugen_softc *sc, int
 	int error;
 	int dir;
 
+	KASSERT(KERNEL_LOCKED_P()); /* ugen_set_config */
+
 	DPRINTFN(5, ("ugenioctl: cmd=%08lx\n", cmd));
 
 	switch (cmd) {



CVS commit: src/sys/dev/usb

2021-09-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  7 10:42:22 UTC 2021

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

Log Message:
ugen(4): Sprinkle KERNEL_LOCKED_P assertions around sc_is_open.


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 src/sys/dev/usb/ugen.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/evbarm/conf

2021-09-07 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Sep  7 10:09:34 UTC 2021

Modified Files:
src/sys/arch/evbarm/conf: GENERIC64

Log Message:
space+tab


To generate a diff of this commit:
cvs rdiff -u -r1.183 -r1.184 src/sys/arch/evbarm/conf/GENERIC64

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/evbarm/conf/GENERIC64
diff -u src/sys/arch/evbarm/conf/GENERIC64:1.183 src/sys/arch/evbarm/conf/GENERIC64:1.184
--- src/sys/arch/evbarm/conf/GENERIC64:1.183	Mon Aug 30 23:26:26 2021
+++ src/sys/arch/evbarm/conf/GENERIC64	Tue Sep  7 10:09:34 2021
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: GENERIC64,v 1.183 2021/08/30 23:26:26 jmcneill Exp $
+#	$NetBSD: GENERIC64,v 1.184 2021/09/07 10:09:34 msaitoh Exp $
 #
 #	GENERIC ARM (aarch64) kernel
 #
@@ -93,7 +93,7 @@ options 	EXEC_ELF32
 options 	EFI_RUNTIME
 
 # Device tree support
-armfdt0		at root
+armfdt0 	at root
 simplebus*	at fdt? pass 0
 
 # ACPI support
@@ -108,7 +108,7 @@ acpipcc*	at acpi?
 acpifan*	at acpi?
 acpiged*	at acpi?
 acpilid*	at acpi?
-acpitz*		at acpi?
+acpitz* 	at acpi?
 
 # CPUs
 cpus*		at fdt? pass 0
@@ -118,7 +118,7 @@ cpu*		at acpi?
 vmt*		at fdt?			# VMware Tools
 
 # Performance monitors
-armpmu*		at fdt?
+armpmu* 	at fdt?
 pseudo-device	tprof
 
 # CPU frequency scaling
@@ -127,7 +127,7 @@ cpufreqdt*	at cpu?
 # Power State Coordination Interface (PSCI)
 psci*		at fdt? pass 0
 
-fclock*		at fdt? pass 1
+fclock* 	at fdt? pass 1
 ffclock*	at fdt? pass 1
 fregulator*	at fdt? pass 4
 gregulator*	at fdt? pass 4
@@ -137,7 +137,7 @@ wskbd*		at gpiokeys? console ? mux 1
 gpioleds*	at fdt?
 
 # System Controller
-syscon*		at fdt? pass 1		# Generic System Controller
+syscon* 	at fdt? pass 1		# Generic System Controller
 sunxisramc*	at fdt? pass 1		# Allwinner System Control
 
 # Timer
@@ -156,11 +156,11 @@ sunxiwdt*	at fdt?			# Allwinner watchdog
 
 # Interrupt controller
 appleintc*	at fdt? pass 1		# Apple AIC
-bcmicu*		at fdt? pass 1		# Broadcom BCM283x ICU
+bcmicu* 	at fdt? pass 1		# Broadcom BCM283x ICU
 tegralic*	at fdt? pass 1		# NVIDIA Tegra LIC
 gic*		at fdt? pass 1		# ARM GICv2
 gic*		at acpi?
-armgic0		at gic?
+armgic0 	at gic?
 gicvthree*	at fdt? pass 1		# ARM GICv3
 gicvthree*	at acpi?
 imx7gpc*	at fdt? pass 2		# IMX GPCv2
@@ -175,7 +175,7 @@ tegramc*	at fdt?	pass 4		# NVIDIA Tegra 
 # Firmware devices
 bcmmbox*	at fdt?			# Broadcom VideoCore IV mailbox
 bcmmbox*	at acpi?
-vcmbox*		at bcmmbox?
+vcmbox* 	at bcmmbox?
 qemufwcfg*	at fdt?			# QEMU Firmware Configuration device
 qemufwcfg*	at acpi?
 
@@ -193,7 +193,7 @@ tegrapmc*	at fdt? pass 4		# NVIDIA Tegra
 
 # Clock and Reset controller
 bcmcprman*	at fdt? pass 1		# Broadcom BCM283x Clock Manager
-bcmaux*		at fdt? pass 1		# Broadcom BCM283x Aux Periph Clocks
+bcmaux* 	at fdt? pass 1		# Broadcom BCM283x Aux Periph Clocks
 g12aoclkc*	at fdt? pass 2		# Amlogic Meson G12 AO clock controller
 g12clkc*	at fdt? pass 2		# Amlogic Meson G12 EE clock controller
 gxbbaoclkc*	at fdt? pass 2		# Amlogic Meson GXBB AO clock controller
@@ -217,11 +217,11 @@ tegra210car*	at fdt? pass 3		# NVIDIA Te
 bcmgpio*	at fdt? pass 3		# Broadcom BCM283x GPIO
 imxgpio*	at fdt? pass 3		# IMX GPIO
 mesonpinctrl*	at fdt? pass 2		# Amlogic Meson GPIO
-plgpio*		at fdt?			# ARM PrimeCell PL061 GPIO
-plgpio*		at acpi?
+plgpio* 	at fdt?			# ARM PrimeCell PL061 GPIO
+plgpio* 	at acpi?
 sunxigpio*	at fdt? pass 3		# Allwinner GPIO
 tegragpio*	at fdt? pass 2		# NVIDIA Tegra GPIO
-rkgpio*		at rkiomux?		# Rockchip GPIO
+rkgpio* 	at rkiomux?		# Rockchip GPIO
 gpio*		at gpiobus?
 
 # PWM controller
@@ -242,7 +242,7 @@ tegra210xphy*	at tegra210xpad?
 applepcie*	at fdt?			# Apple PCIe
 pcihost*	at fdt?			# Generic PCI host controller
 acpipchb*	at acpi?		# ACPI PCIe host bridge
-rkpcie*		at fdt?			# Rockchip AXI PCIE
+rkpcie* 	at fdt?			# Rockchip AXI PCIE
 rkpciephy*	at fdt? pass 9		# Rockchip AXI PCIE PHY
 tegrapcie0	at fdt?			# NVIDIA Tegra PCIE
 pci*		at pcibus?
@@ -272,31 +272,31 @@ wm*		at pci? dev ? function ?	# Intel Gi
 
 # MII/PHY support
 atphy*		at mii? phy ?		# Attansic/Atheros PHYs
-brgphy*		at mii? phy ?		# Broadcom BCM5400-family PHYs
+brgphy* 	at mii? phy ?		# Broadcom BCM5400-family PHYs
 exphy* 		at mii? phy ?		# 3Com internal PHYs
 gentbi* 	at mii? phy ?		# Generic Ten-Bit 1000BASE-[CLS]X PHYs
 glxtphy*	at mii? phy ?		# Level One LXT-1000 PHYs
 gphyter* 	at mii? phy ?		# NS83861 Gig-E PHY
-gxlphy*		at mii? phy ?		# Amlogic Meson GX internal PHY
-icsphy*		at mii? phy ?		# Integrated Circuit Systems ICS189x
+gxlphy* 	at mii? phy ?		# Amlogic Meson GX internal PHY
+icsphy* 	at mii? phy ?		# Integrated Circuit Systems ICS189x
 igphy*		at mii? phy ?		# Intel IGP01E1000
 ihphy*		at mii? phy ?		# Intel 82577 PHYs
 ikphy*		at mii? phy ?		# Intel 82563 PHYs
 inphy*		at mii? phy ?		# Intel 82555 PHYs
 iophy*		at mii? phy ?		# Intel 82553 PHYs
-lxtphy*		at mii? phy ?		# Level One LXT-970 PHYs
-makphy*		at mii? phy ?		

CVS commit: src/sys/arch/evbarm/conf

2021-09-07 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Sep  7 10:09:34 UTC 2021

Modified Files:
src/sys/arch/evbarm/conf: GENERIC64

Log Message:
space+tab


To generate a diff of this commit:
cvs rdiff -u -r1.183 -r1.184 src/sys/arch/evbarm/conf/GENERIC64

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



CVS commit: src/sys/dev/pci/ixgbe

2021-09-07 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Sep  7 08:17:20 UTC 2021

Modified Files:
src/sys/dev/pci/ixgbe: ix_txrx.c

Log Message:
 Don't increment no_mbuf evcnt(9) when discarding multi-descriptor packet.


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/sys/dev/pci/ixgbe/ix_txrx.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/pci/ixgbe/ix_txrx.c
diff -u src/sys/dev/pci/ixgbe/ix_txrx.c:1.91 src/sys/dev/pci/ixgbe/ix_txrx.c:1.92
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.91	Tue Sep  7 03:48:01 2021
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Tue Sep  7 08:17:20 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.91 2021/09/07 03:48:01 msaitoh Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.92 2021/09/07 08:17:20 msaitoh Exp $ */
 
 /**
 
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ix_txrx.c,v 1.91 2021/09/07 03:48:01 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ix_txrx.c,v 1.92 2021/09/07 08:17:20 msaitoh Exp $");
 
 #include "opt_inet.h"
 #include "opt_inet6.h"
@@ -1877,12 +1877,14 @@ ixgbe_rxeof(struct ix_queue *que)
 		}
 
 		/* pre-alloc new mbuf */
-		if (!discard_multidesc)
+		if (!discard_multidesc) {
 			newmp = ixgbe_getcl();
-		else
+			if (__predict_false(newmp == NULL))
+rxr->no_mbuf.ev_count++;
+		} else
 			newmp = NULL;
+
 		if (__predict_false(newmp == NULL)) {
-			rxr->no_mbuf.ev_count++;
 			/*
 			 * Descriptor initialization is already done by the
 			 * above code (cur->wb.upper.status_error = 0).



CVS commit: src/sys/dev/pci/ixgbe

2021-09-07 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Sep  7 08:17:20 UTC 2021

Modified Files:
src/sys/dev/pci/ixgbe: ix_txrx.c

Log Message:
 Don't increment no_mbuf evcnt(9) when discarding multi-descriptor packet.


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/sys/dev/pci/ixgbe/ix_txrx.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/hpcmips/dev

2021-09-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Sep  7 06:36:06 UTC 2021

Modified Files:
src/sys/arch/hpcmips/dev: m38813c.c

Log Message:
Make this compile again.

XXX
Unfortunately, kernel does not boot on TX3922-based machines...


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/hpcmips/dev/m38813c.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/hpcmips/dev

2021-09-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Sep  7 06:36:06 UTC 2021

Modified Files:
src/sys/arch/hpcmips/dev: m38813c.c

Log Message:
Make this compile again.

XXX
Unfortunately, kernel does not boot on TX3922-based machines...


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/hpcmips/dev/m38813c.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/hpcmips/dev/m38813c.c
diff -u src/sys/arch/hpcmips/dev/m38813c.c:1.15 src/sys/arch/hpcmips/dev/m38813c.c:1.16
--- src/sys/arch/hpcmips/dev/m38813c.c:1.15	Sat Aug  7 16:18:54 2021
+++ src/sys/arch/hpcmips/dev/m38813c.c	Tue Sep  7 06:36:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: m38813c.c,v 1.15 2021/08/07 16:18:54 thorpej Exp $ */
+/*	$NetBSD: m38813c.c,v 1.16 2021/09/07 06:36:06 rin Exp $ */
 
 /*-
  * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: m38813c.c,v 1.15 2021/08/07 16:18:54 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m38813c.c,v 1.16 2021/09/07 06:36:06 rin Exp $");
 
 #include "opt_use_poll.h"
 
@@ -42,6 +42,8 @@ __KERNEL_RCSID(0, "$NetBSD: m38813c.c,v 
 #include 
 #include 
 
+#include 
+
 #include 
 #include