CVS commit: src/sys/dev/i2c

2021-05-23 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon May 24 05:58:42 UTC 2021

Modified Files:
src/sys/dev/i2c: axppmic.c

Log Message:
Bail out of axpreg_attach if axpreg_get_voltage returns an error.

uvol isn't updated and shouldn't be used.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/dev/i2c/axppmic.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/i2c/axppmic.c
diff -u src/sys/dev/i2c/axppmic.c:1.34 src/sys/dev/i2c/axppmic.c:1.35
--- src/sys/dev/i2c/axppmic.c:1.34	Sat Apr 24 23:36:54 2021
+++ src/sys/dev/i2c/axppmic.c	Mon May 24 05:58:42 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: axppmic.c,v 1.34 2021/04/24 23:36:54 thorpej Exp $ */
+/* $NetBSD: axppmic.c,v 1.35 2021/05/24 05:58:42 skrll Exp $ */
 
 /*-
  * Copyright (c) 2014-2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.34 2021/04/24 23:36:54 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.35 2021/05/24 05:58:42 skrll Exp $");
 
 #include 
 #include 
@@ -1161,7 +1161,10 @@ axpreg_attach(device_t parent, device_t 
 	else
 		aprint_normal("\n");
 
-	axpreg_get_voltage(self, );
+	int error = axpreg_get_voltage(self, );
+	if (error)
+		return;
+
 	if (of_getprop_uint32(phandle, "regulator-min-microvolt", _uvol) == 0 &&
 	of_getprop_uint32(phandle, "regulator-max-microvolt", _uvol) == 0) {
 		if (uvol < min_uvol || uvol > max_uvol) {



CVS commit: src/sys/arch/alpha

2021-05-23 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon May 24 03:43:24 UTC 2021

Modified Files:
src/sys/arch/alpha/alpha: pmap.c
src/sys/arch/alpha/include: pmap.h

Log Message:
pmap_tlb_shootdown_all_user() can be called in the PV scenario as well
as the forward scenario, for example if a pmap_page_protect() to remove
all mappings results in the freeing of a PT page.  It therefore needs
to do the same reference counting dance as pmap_tlb_shootdown_pv().

Also fix a use-after-free error in pmap_page_protect().

Add / tweak some assertions, and shrink the pmap::pm_count field from
long to unsigned int (which gave me a spare unsigned int field for
debugging purposes).

PR port-alpha/56201.


To generate a diff of this commit:
cvs rdiff -u -r1.277 -r1.278 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.84 -r1.85 src/sys/arch/alpha/include/pmap.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/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.277 src/sys/arch/alpha/alpha/pmap.c:1.278
--- src/sys/arch/alpha/alpha/pmap.c:1.277	Sun May 23 19:13:27 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Mon May 24 03:43:24 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.277 2021/05/23 19:13:27 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.278 2021/05/24 03:43:24 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.277 2021/05/23 19:13:27 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.278 2021/05/24 03:43:24 thorpej Exp $");
 
 #include 
 #include 
@@ -667,17 +667,17 @@ pmap_tlb_init(void)
 }
 
 static inline void
-pmap_tlb_context_init(struct pmap_tlb_context * const tlbctx)
+pmap_tlb_context_init(struct pmap_tlb_context * const tlbctx, uintptr_t flags)
 {
 	/* Initialize the minimum number of fields. */
 	tlbctx->t_addrdata[0] = 0;
-	tlbctx->t_addrdata[1] = 0;
+	tlbctx->t_addrdata[1] = flags;
 	tlbctx->t_pmap = NULL;
 	LIST_INIT(>t_freeptq);
 }
 
 static void
-pmap_tlb_shootdown(pmap_t const pmap, vaddr_t const va,
+pmap_tlb_shootdown_internal(pmap_t const pmap, vaddr_t const va,
 pt_entry_t const pte_bits, struct pmap_tlb_context * const tlbctx)
 {
 	KASSERT(pmap != NULL);
@@ -730,6 +730,14 @@ pmap_tlb_shootdown(pmap_t const pmap, va
 }
 
 static void
+pmap_tlb_shootdown(pmap_t const pmap, vaddr_t const va,
+pt_entry_t const pte_bits, struct pmap_tlb_context * const tlbctx)
+{
+	KASSERT((TLB_CTX_FLAGS(tlbctx) & TLB_CTX_F_PV) == 0);
+	pmap_tlb_shootdown_internal(pmap, va, pte_bits, tlbctx);
+}
+
+static void
 pmap_tlb_shootdown_all_user(pmap_t const pmap, pt_entry_t const pte_bits,
 struct pmap_tlb_context * const tlbctx)
 {
@@ -743,29 +751,42 @@ pmap_tlb_shootdown_all_user(pmap_t const
 		TLB_CTX_SET_FLAG(tlbctx, TLB_CTX_F_IMB);
 	}
 
-	KASSERT(tlbctx->t_pmap == NULL || tlbctx->t_pmap == pmap);
-	tlbctx->t_pmap = pmap;
+	if (TLB_CTX_FLAGS(tlbctx) & TLB_CTX_F_PV) {
+		if (tlbctx->t_pmap == NULL || tlbctx->t_pmap == pmap) {
+			if (tlbctx->t_pmap == NULL) {
+pmap_reference(pmap);
+tlbctx->t_pmap = pmap;
+			}
+		} else {
+			TLB_CTX_SET_FLAG(tlbctx, TLB_CTX_F_MULTI);
+		}
+	} else {
+		KASSERT(tlbctx->t_pmap == NULL || tlbctx->t_pmap == pmap);
+		tlbctx->t_pmap = pmap;
+	}
 
 	TLB_CTX_SET_ALLVA(tlbctx);
 }
 
 static void
-pmap_tlb_shootdown_pv(const pv_entry_t pv, pt_entry_t const pte_bits,
-struct pmap_tlb_context * const tlbctx)
+pmap_tlb_shootdown_pv(pmap_t const pmap, vaddr_t const va,
+pt_entry_t const pte_bits, struct pmap_tlb_context * const tlbctx)
 {
-	uintptr_t flags = TLB_CTX_F_PV;
+
+	KASSERT(TLB_CTX_FLAGS(tlbctx) & TLB_CTX_F_PV);
 
 	TLB_COUNT(shootdown_pv);
 
-	if (tlbctx->t_pmap == NULL || tlbctx->t_pmap == pv->pv_pmap) {
+	if (tlbctx->t_pmap == NULL || tlbctx->t_pmap == pmap) {
 		if (tlbctx->t_pmap == NULL) {
-			pmap_reference(pv->pv_pmap);
+			pmap_reference(pmap);
+			tlbctx->t_pmap = pmap;
 		}
-		pmap_tlb_shootdown(pv->pv_pmap, pv->pv_va, pte_bits, tlbctx);
+		pmap_tlb_shootdown_internal(pmap, va, pte_bits, tlbctx);
 	} else {
 		TLB_COUNT(shootdown_pv_multi);
-		flags |= TLB_CTX_F_MULTI;
-		if (pv->pv_pmap == pmap_kernel()) {
+		uintptr_t flags = TLB_CTX_F_MULTI;
+		if (pmap == pmap_kernel()) {
 			KASSERT(pte_bits & PG_ASM);
 			flags |= TLB_CTX_F_ASM;
 		} else {
@@ -780,8 +801,8 @@ pmap_tlb_shootdown_pv(const pv_entry_t p
 			flags |= TLB_CTX_F_IMB;
 		}
 		TLB_CTX_SET_ALLVA(tlbctx);
+		TLB_CTX_SET_FLAG(tlbctx, flags);
 	}
-	TLB_CTX_SET_FLAG(tlbctx, flags);
 }
 
 static void
@@ -1034,6 +1055,7 @@ pmap_tlb_shootnow(const struct pmap_tlb_
 #if defined(MULTIPROCESSOR)
 void
 pmap_tlb_shootdown_ipi(struct cpu_info * const ci,
+
 struct trapframe * const tf __unused)
 {
 	KASSERT(tlb_context != NULL);
@@ -1367,7 +1389,7 @@ pmap_bootstrap(paddr_t ptaddr, u_int max
 	 */
 	memset(pmap_kernel(), 0, 

CVS commit: src/sys/arch/mips

2021-05-23 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun May 23 23:24:45 UTC 2021

Modified Files:
src/sys/arch/mips/include: mips_param.h netbsd32_machdep.h
src/sys/arch/mips/mips: cpu_exec.c netbsd32_machdep.c

Log Message:
fix "uname -p" on mips n32.

this has been returning "mipsn64eb" on my edgerouter4 with the
32 bit uname binary.

introduce o32, n32, and n64 versions of MACHINE_ARCH, and use
them appropriately in PROC_MACHINE_ARCH32().  now o32, n32 and
n64 "uname -p" all return different values.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/mips/include/mips_param.h
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/mips/include/netbsd32_machdep.h
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/mips/mips/cpu_exec.c
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/mips/mips/netbsd32_machdep.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/mips/include/mips_param.h
diff -u src/sys/arch/mips/include/mips_param.h:1.49 src/sys/arch/mips/include/mips_param.h:1.50
--- src/sys/arch/mips/include/mips_param.h:1.49	Sat May  8 13:09:58 2021
+++ src/sys/arch/mips/include/mips_param.h	Sun May 23 23:24:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: mips_param.h,v 1.49 2021/05/08 13:09:58 skrll Exp $	*/
+/*	$NetBSD: mips_param.h,v 1.50 2021/05/23 23:24:45 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -38,19 +38,28 @@
 # error neither __MIPSEL__ nor __MIPSEB__ are defined.
 #endif
 
+#define	___MACHINE32_OARCH		mips##_MACHINE_SUFFIX
+#define	__MACHINE32_OARCH		"mips" MACHINE_SUFFIX
+#define	___MACHINE32_NARCH		mips64##_MACHINE_SUFFIX
+#define	__MACHINE32_NARCH		"mips64" MACHINE_SUFFIX
+#define	___MACHINE64_NARCH		mipsn64##_MACHINE_SUFFIX
+#define	__MACHINE64_NARCH		"mipsn64" MACHINE_SUFFIX
+
 #if defined(__mips_n32) || defined(__mips_n64)
 # if defined(__mips_n32)
-#  define	_MACHINE_ARCH	mips64##_MACHINE_SUFFIX
-#  define	MACHINE_ARCH	"mips64" MACHINE_SUFFIX
+#  define	_MACHINE_ARCH		___MACHINE32_NARCH
+#  define	MACHINE_ARCH		__MACHINE32_NARCH
 # else /* __mips_n64 */
-#  define	_MACHINE_ARCH	mipsn64##_MACHINE_SUFFIX
-#  define	MACHINE_ARCH	"mipsn64" MACHINE_SUFFIX
+#  define	_MACHINE_ARCH		___MACHINE64_NARCH
+#  define	MACHINE_ARCH		__MACHINE64_NARCH
+#  define	_MACHINE32_NARCH	___MACHINE32_NARCH
+#  define	MACHINE32_NARCH		__MACHINE32_NARCH
 # endif
-# define	_MACHINE32_ARCH	mips##_MACHINE_SUFFIX
-# define	MACHINE32_ARCH	"mips" MACHINE_SUFFIX
+# define	_MACHINE32_OARCH	___MACHINE32_OARCH
+# define	MACHINE32_OARCH		__MACHINE32_OARCH
 #else /* o32 */
-# define	_MACHINE_ARCH	mips##_MACHINE_SUFFIX
-# define	MACHINE_ARCH	"mips" MACHINE_SUFFIX
+# define	_MACHINE_ARCH		___MACHINE32_OARCH
+# define	MACHINE_ARCH		__MACHINE32_OARCH
 #endif
 
 /*

Index: src/sys/arch/mips/include/netbsd32_machdep.h
diff -u src/sys/arch/mips/include/netbsd32_machdep.h:1.6 src/sys/arch/mips/include/netbsd32_machdep.h:1.7
--- src/sys/arch/mips/include/netbsd32_machdep.h:1.6	Sun Jul 26 08:08:41 2020
+++ src/sys/arch/mips/include/netbsd32_machdep.h	Sun May 23 23:24:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.h,v 1.6 2020/07/26 08:08:41 simonb Exp $	*/
+/*	$NetBSD: netbsd32_machdep.h,v 1.7 2021/05/23 23:24:45 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -44,10 +44,17 @@ typedef struct { NETBSD32_POINTER_TYPE i
 
 typedef netbsd32_pointer_t			netbsd32_sigcontextp_t;
 
-/* Support varying ABI names for netbsd32 */
-extern const char machine_arch32[];
+/* Support varying ABI names for netbsd32/ABI */
+extern const char machine_archo32[];
+#if defined(__mips_n64)
+extern const char machine_archn32[];
 #define	PROC_MACHINE_ARCH32(P)	((P)->p_md.md_abi == _MIPS_BSD_API_O32) ? \
-	__UNCONST(machine_arch32) : machine_arch
+	__UNCONST(machine_archo32) : ((P)->p_md.md_abi == _MIPS_BSD_API_N32) ? \
+	__UNCONST(machine_archn32) : machine_arch
+#else
+#define	PROC_MACHINE_ARCH32(P)	((P)->p_md.md_abi == _MIPS_BSD_API_O32) ? \
+	__UNCONST(machine_archo32) : machine_arch
+#endif
 
 /*
  * The sigcode is ABI neutral.

Index: src/sys/arch/mips/mips/cpu_exec.c
diff -u src/sys/arch/mips/mips/cpu_exec.c:1.67 src/sys/arch/mips/mips/cpu_exec.c:1.68
--- src/sys/arch/mips/mips/cpu_exec.c:1.67	Sun Aug 19 10:33:49 2018
+++ src/sys/arch/mips/mips/cpu_exec.c	Sun May 23 23:24:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu_exec.c,v 1.67 2018/08/19 10:33:49 mrg Exp $	*/
+/*	$NetBSD: cpu_exec.c,v 1.68 2021/05/23 23:24:45 mrg Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.67 2018/08/19 10:33:49 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.68 2021/05/23 23:24:45 mrg Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_compat_ultrix.h"
@@ -201,7 +201,7 @@ coredump_elf32_setup(struct lwp *l, void
 		eh->e_flags |= EF_MIPS_ABI2;
 		break;
 	case _MIPS_BSD_API_O32:
-		eh->e_flags |=EF_MIPS_ABI_O32; 
+		eh->e_flags |= 

CVS commit: src/sys/arch

2021-05-23 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun May 23 23:22:55 UTC 2021

Modified Files:
src/sys/arch/mips/mips: db_disasm.c db_interface.c
src/sys/arch/riscv/riscv: db_disasm.c db_machdep.c

Log Message:
Improve ddb disassembly for mips (and riscv, cribbed from mips).

- use db_read_bytes to get instructions
- move the address check logic previously attached only to fetching
  instructions for disassembly to db_read_bytes (and db_write_bytes)

Motivated by related x86 changes this afternoon.

Note that the address check logic is not as sophisticated as what the
x86 code does, but it's what we had before. (Except that riscv will
now also try to fetch usermode instructions instead of just failing.)


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/mips/mips/db_disasm.c
cvs rdiff -u -r1.93 -r1.94 src/sys/arch/mips/mips/db_interface.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/riscv/riscv/db_disasm.c \
src/sys/arch/riscv/riscv/db_machdep.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/mips/mips/db_disasm.c
diff -u src/sys/arch/mips/mips/db_disasm.c:1.42 src/sys/arch/mips/mips/db_disasm.c:1.43
--- src/sys/arch/mips/mips/db_disasm.c:1.42	Mon Apr 12 11:35:22 2021
+++ src/sys/arch/mips/mips/db_disasm.c	Sun May 23 23:22:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_disasm.c,v 1.42 2021/04/12 11:35:22 simonb Exp $	*/
+/*	$NetBSD: db_disasm.c,v 1.43 2021/05/23 23:22:55 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.42 2021/04/12 11:35:22 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.43 2021/05/23 23:22:55 dholland Exp $");
 
 #include 
 #include 
@@ -47,6 +47,7 @@ __KERNEL_RCSID(0, "$NetBSD: db_disasm.c,
 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -218,11 +219,6 @@ static void print_addr(db_addr_t);
  * "next instruction" does NOT mean the next instruction to
  * be executed but the 'linear' next instruction.
  */
-#ifdef _LP64
-#define	DISASM_KERN_START	MIPS_XKSEG_START
-#else
-#define	DISASM_KERN_START	MIPS_KSEG0_START
-#endif
 db_addr_t
 db_disasm(db_addr_t loc, bool altfmt)
 {
@@ -232,19 +228,14 @@ db_disasm(db_addr_t loc, bool altfmt)
 	 * Take some care with addresses to not UTLB here as it
 	 * loses the current debugging context.  KSEG2 and XKSEG
 	 * are not checked.
+	 * Update: db_read_bytes is supposed to do that, and now
+	 * does, so we can use that.
+	 *
+	 * XXX db_read_bytes_can't return failure but instead zeros
+	 * the output. That's ok here, but if ever improved the
+	 * proper thing here on error is to return the original loc.
 	 */
-	if (loc < (db_addr_t)DISASM_KERN_START) {
-#ifdef _KERNEL
-		if (ufetch_32((void *)loc, ) != 0) {
-			db_printf("invalid address.\n");
-			return loc;
-		}
-#else
-		return loc;
-#endif
-	} else {
-		instr =  *(uint32_t *)loc;
-	}
+	db_read_bytes(loc, sizeof(instr), (void *));
 
 	return (db_disasm_insn(instr, loc, altfmt));
 }

Index: src/sys/arch/mips/mips/db_interface.c
diff -u src/sys/arch/mips/mips/db_interface.c:1.93 src/sys/arch/mips/mips/db_interface.c:1.94
--- src/sys/arch/mips/mips/db_interface.c:1.93	Mon Apr 12 02:23:41 2021
+++ src/sys/arch/mips/mips/db_interface.c	Sun May 23 23:22:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_interface.c,v 1.93 2021/04/12 02:23:41 mrg Exp $	*/
+/*	$NetBSD: db_interface.c,v 1.94 2021/05/23 23:22:55 dholland Exp $	*/
 
 /*
  * Mach Operating System
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.93 2021/04/12 02:23:41 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.94 2021/05/23 23:22:55 dholland Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_multiprocessor.h"
@@ -180,6 +180,23 @@ void
 db_read_bytes(vaddr_t addr, size_t size, char *data)
 {
 	const char *src = (char *)addr;
+	int err;
+
+	/*
+	 * If asked to fetch from userspace, do it safely.
+	 * Note that MIPS_KSEG0_START is the proper address for
+	 * both 32-bit and 64-bit kernels.
+	 */
+	if (addr < (vaddr_t)MIPS_KSEG0_START) {
+		err = copyin(src, data, size);
+		if (err) {
+#ifdef DDB
+			db_printf("address %p is invalid\n", src);
+#endif
+			memset(data, 0, size);
+		}
+		return;
+	}
 
 	if (size <= 8 && (size & (size-1)) == 0 && (addr & (size-1)) == 0
 	&& ((uintptr_t)data & (size-1)) == 0) {
@@ -205,6 +222,18 @@ db_write_bytes(vaddr_t addr, size_t size
 {
 	char *p = (char *)addr;
 	size_t n = size;
+	int err;
+
+	/* If asked to fetch from userspace, do it safely */
+	if (addr < (vaddr_t)MIPS_KSEG0_START) {
+		err = copyout(data, p, size);
+		if (err) {
+#ifdef DDB
+			db_printf("address %p is invalid\n", p);
+#endif
+		}
+		return;
+	}
 
 	if (size <= 8 && (size & (size-1)) == 0 && (addr & (size-1)) == 0
 	&& ((uintptr_t)data & (size-1)) == 0) {

Index: src/sys/arch/riscv/riscv/db_disasm.c
diff -u 

CVS commit: src/sys/dev/usb

2021-05-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 23 21:12:29 UTC 2021

Modified Files:
src/sys/dev/usb: xhci.c xhcivar.h

Log Message:
xhci(4): Block commands and issue Stop Endpoint on suspend.


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/sys/dev/usb/xhci.c
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/usb/xhcivar.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/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.139 src/sys/dev/usb/xhci.c:1.140
--- src/sys/dev/usb/xhci.c:1.139	Sun May 23 11:49:45 2021
+++ src/sys/dev/usb/xhci.c	Sun May 23 21:12:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.139 2021/05/23 11:49:45 riastradh Exp $	*/
+/*	$NetBSD: xhci.c,v 1.140 2021/05/23 21:12:28 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.139 2021/05/23 11:49:45 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.140 2021/05/23 21:12:28 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -157,6 +157,8 @@ static int xhci_roothub_ctrl(struct usbd
 static usbd_status xhci_configure_endpoint(struct usbd_pipe *);
 //static usbd_status xhci_unconfigure_endpoint(struct usbd_pipe *);
 static usbd_status xhci_reset_endpoint(struct usbd_pipe *);
+static usbd_status xhci_stop_endpoint_cmd(struct xhci_softc *,
+struct xhci_slot *, u_int, uint32_t);
 static usbd_status xhci_stop_endpoint(struct usbd_pipe *);
 
 static void xhci_host_dequeue(struct xhci_ring * const);
@@ -699,14 +701,70 @@ bool
 xhci_suspend(device_t self, const pmf_qual_t *qual)
 {
 	struct xhci_softc * const sc = device_private(self);
-	size_t i, j, bn;
+	size_t i, j, bn, dci;
 	int port;
 	uint32_t v;
+	usbd_status err;
+	bool ok = false;
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
 
+	mutex_enter(>sc_lock);
+
+	/*
+	 * Block issuance of new commands, and wait for all pending
+	 * commands to complete.
+	 */
+	KASSERT(sc->sc_suspender == NULL);
+	sc->sc_suspender = curlwp;
+	while (sc->sc_command_addr != 0)
+		cv_wait(>sc_cmdbusy_cv, >sc_lock);
+
+	/*
+	 * xHCI Requirements Specification 1.2, May 2019, Sec. 4.23.2:
+	 * xHCI Power Management, p. 342
+	 * https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf#page=342
+	 */
+
+	/*
+	 * `1. Stop all USB activity by issuing Stop Endpoint Commands
+	 * for Busy endpoints in the Running state.  If the Force
+	 * Save Context Capability (FSC = ``0'') is not supported,
+	 * then Stop Endpoint Commands shall be issued for all idle
+	 * endpoints in the Running state as well.  The Stop
+	 * Endpoint Command causes the xHC to update the respective
+	 * Endpoint or Stream Contexts in system memory, e.g. the
+	 * TR Dequeue Pointer, DCS, etc. fields.  Refer to
+	 * Implementation Note "0".'
+	 */
+	for (i = 0; i < sc->sc_maxslots; i++) {
+		struct xhci_slot *xs = >sc_slots[i];
+
+		/* Skip if the slot is not in use.  */
+		if (xs->xs_idx == 0)
+			continue;
+
+		for (dci = XHCI_DCI_SLOT; dci <= XHCI_MAX_DCI; dci++) {
+			/* Skip if the endpoint is not Running.  */
+			/* XXX What about Busy?  */
+			if (xhci_get_epstate(sc, xs, dci) !=
+			XHCI_EPSTATE_RUNNING)
+continue;
+
+			/* Stop endpoint.  */
+			err = xhci_stop_endpoint_cmd(sc, xs, dci,
+			XHCI_TRB_3_SUSP_EP_BIT);
+			if (err) {
+device_printf(self, "failed to stop endpoint"
+" slot %zu dci %zu err %d\n",
+i, dci, err);
+goto out;
+			}
+		}
+	}
+
 	/*
-	 * First, suspend all the ports:
+	 * Next, suspend all the ports:
 	 *
 	 * xHCI Requirements Specification 1.2, May 2019, Sec. 4.15:
 	 * Suspend-Resume, pp. 276-283
@@ -767,33 +825,12 @@ xhci_suspend(device_t self, const pmf_qu
 device_printf(self,
 "suspend timeout on bus %zu port %zu\n",
 bn, i);
-return false;
+goto out;
 			}
 		}
 	}
 
 	/*
-	 * xHCI Requirements Specification 1.2, May 2019, Sec. 4.23.2:
-	 * xHCI Power Management, p. 342
-	 * https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf#page=342
-	 */
-
-	/*
-	 * `1. Stop all USB activity by issuing Stop Endpoint Commands
-	 * for Busy endpoints in the Running state.  If the Force
-	 * Save Context Capability (FSC = ``0'') is not supported,
-	 * then Stop Endpoint Commands shall be issued for all Idle
-	 * endpoints in the Running state as well.  The Stop
-	 * Endpoint Command causes the xHC to update the respective
-	 * Endpoint or Stream Contexts in system memory, e.g. the
-	 * TR Dequeue Pointer, DCS, etc. fields.  Refer to
-	 * Implementation Note "0".'
-	 *
-	 * XXX Not entirely sure if this is necessary for us; also it
-	 * probably has to happen before suspending the ports.
-	 */
-
-	/*
 	 * `2. 

CVS commit: src/sys/arch/alpha/alpha

2021-05-23 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 23 19:13:27 UTC 2021

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

Log Message:
Fix a bug in pmap_tlb_shootdown_all_user(), where it was not
stashing away the pointer to the pmap in the TLB context structure
like pmap_tlb_shootdown() was doing.  This would result in the
following failure scenario:

- Page fault handler calls pmap_enter() to map a page.  Mapping
  is the first one for that L2 PT L3 PT, meaning that an L2 PT
  and an L3 PT must be allocated.
- L2 PT allocation succeeds.
- L3 PT allocation fails under memory pressure.
- pmap_enter() goes to drop the reference on the L2 PT, which, because
  it was the first of its mappings, frees the L2 PT.  Becuse PALcode
  may have already tried to service a TLB miss though that L2 PT, we
  must issue an all-user-VA shootdown, and call pmap_tlb_shootdown_all_user()
  to do so.
- pmap_tlb_shootnow() is called and an assert fires because the TLB
  context structure does not point to a pmap.

This did not fail in the pmap_remove() scenario because the TLB context
would have already had at least one call to pmap_tlb_shootdown(), which
was initializing the pmap pointer properly.

PR port-alpha/56200


To generate a diff of this commit:
cvs rdiff -u -r1.276 -r1.277 src/sys/arch/alpha/alpha/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/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.276 src/sys/arch/alpha/alpha/pmap.c:1.277
--- src/sys/arch/alpha/alpha/pmap.c:1.276	Sat Apr  3 15:29:02 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Sun May 23 19:13:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.276 2021/04/03 15:29:02 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.277 2021/05/23 19:13:27 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.276 2021/04/03 15:29:02 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.277 2021/05/23 19:13:27 thorpej Exp $");
 
 #include 
 #include 
@@ -743,6 +743,9 @@ pmap_tlb_shootdown_all_user(pmap_t const
 		TLB_CTX_SET_FLAG(tlbctx, TLB_CTX_F_IMB);
 	}
 
+	KASSERT(tlbctx->t_pmap == NULL || tlbctx->t_pmap == pmap);
+	tlbctx->t_pmap = pmap;
+
 	TLB_CTX_SET_ALLVA(tlbctx);
 }
 



CVS commit: src/sys/arch/i386/i386

2021-05-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 23 11:56:28 UTC 2021

Modified Files:
src/sys/arch/i386/i386: db_disasm.c

Log Message:
ddb/i386: Don't go out of the way to detect invalid addresses.

db_read_bytes already does this better (but didn't at the time this
check was originally added back in 1998).  Not sure if this code had
the same mistake as the amd64 code causing it to trip over its own
shoelaces, but there should be no need for it here.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/i386/i386/db_disasm.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/i386/i386/db_disasm.c
diff -u src/sys/arch/i386/i386/db_disasm.c:1.48 src/sys/arch/i386/i386/db_disasm.c:1.49
--- src/sys/arch/i386/i386/db_disasm.c:1.48	Sat Mar  9 08:42:25 2019
+++ src/sys/arch/i386/i386/db_disasm.c	Sun May 23 11:56:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_disasm.c,v 1.48 2019/03/09 08:42:25 maxv Exp $	*/
+/*	$NetBSD: db_disasm.c,v 1.49 2021/05/23 11:56:28 riastradh Exp $	*/
 
 /* 
  * Mach Operating System
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.48 2019/03/09 08:42:25 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.49 2021/05/23 11:56:28 riastradh Exp $");
 
 #include 
 #include 
@@ -1132,26 +1132,6 @@ db_disasm(db_addr_t loc, bool altfmt)
 	int	len;
 	struct i_addr	address;
 
-#ifdef _KERNEL
-	pt_entry_t *pte, *pde;
-
-	/*
-	 * Don't try to disassemble the location if the mapping is invalid.
-	 * If we do, we'll fault, and end up debugging the debugger!
-	 * in the case of largepages, "pte" is really the pde and "pde" is
-	 * really the entry for the pdp itself.
-	 */
-	if ((vaddr_t)loc >= VM_MIN_KERNEL_ADDRESS)
-		pte = kvtopte((vaddr_t)loc);
-	else
-		pte = vtopte((vaddr_t)loc);
-	pde = vtopte((vaddr_t)pte);
-	if ((*pde & PTE_P) == 0 || (*pte & PTE_P) == 0) {
-		db_printf("invalid address\n");
-		return (loc);
-	}
-#endif
-
 	get_value_inc(inst, loc, 1, false);
 	short_addr = false;
 	size = LONG;



CVS commit: src/sys/dev/usb

2021-05-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 23 11:49:45 UTC 2021

Modified Files:
src/sys/dev/usb: xhci.c xhcireg.h xhcivar.h

Log Message:
xhci(4): Draft suspend/resume.

Work almost entirely done and tested by maya@ based on xhci 1.2 spec;
tidied up and tweaked by me.

Not sure about issuing Stop Endpoint commands or ensuring the Command
Ring is in the Stopped or Idle state, but this seems to work as is,
so it's already an improvement over what we had before which was no
xhci suspend/resume at all.

In particular, it's not clear to us:

- if we don't have any pending USB activity whether we need to issue
  the Stop Endpoints or quiesce the command ring; but

- if we do have any pending USB activity whether issuing Stop
  Endpoint is enough or whether we also need to do anything to
  synchronize with other software logic to quiesce it too.


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/sys/dev/usb/xhci.c
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/usb/xhcireg.h
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/usb/xhcivar.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/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.138 src/sys/dev/usb/xhci.c:1.139
--- src/sys/dev/usb/xhci.c:1.138	Tue Jan  5 18:00:21 2021
+++ src/sys/dev/usb/xhci.c	Sun May 23 11:49:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.138 2021/01/05 18:00:21 skrll Exp $	*/
+/*	$NetBSD: xhci.c,v 1.139 2021/05/23 11:49:45 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.138 2021/01/05 18:00:21 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.139 2021/05/23 11:49:45 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -388,7 +388,6 @@ xhci_rt_write_4(const struct xhci_softc 
 	bus_space_write_4(sc->sc_iot, sc->sc_rbh, offset, value);
 }
 
-#if 0 /* unused */
 static inline uint64_t
 xhci_rt_read_8(const struct xhci_softc * const sc, bus_size_t offset)
 {
@@ -408,7 +407,6 @@ xhci_rt_read_8(const struct xhci_softc *
 
 	return value;
 }
-#endif /* unused */
 
 static inline void
 xhci_rt_write_8(const struct xhci_softc * const sc, bus_size_t offset,
@@ -698,15 +696,357 @@ xhci_activate(device_t self, enum devact
 }
 
 bool
-xhci_suspend(device_t dv, const pmf_qual_t *qual)
+xhci_suspend(device_t self, const pmf_qual_t *qual)
 {
-	return false;
+	struct xhci_softc * const sc = device_private(self);
+	size_t i, j, bn;
+	int port;
+	uint32_t v;
+
+	XHCIHIST_FUNC(); XHCIHIST_CALLED();
+
+	/*
+	 * First, suspend all the ports:
+	 *
+	 * xHCI Requirements Specification 1.2, May 2019, Sec. 4.15:
+	 * Suspend-Resume, pp. 276-283
+	 * https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf#page=276
+	 */
+	for (bn = 0; bn < 2; bn++) {
+		for (i = 1; i <= sc->sc_rhportcount[bn]; i++) {
+			/* 4.15.1: Port Suspend.  */
+			port = XHCI_PORTSC(xhci_rhport2ctlrport(sc, bn, i));
+
+			/*
+			 * `System software places individual ports
+			 *  into suspend mode by writing a ``3'' into
+			 *  the appropriate PORTSC register Port Link
+			 *  State (PLS) field (refer to Section 5.4.8).
+			 *  Software should only set the PLS field to
+			 *  ``3'' when the port is in the Enabled
+			 *  state.'
+			 *
+			 * `Software should not attempt to suspend a
+			 *  port unless the port reports that it is in
+			 *  the enabled (PED = ``1''; PLS < ``3'')
+			 *  state (refer to Section 5.4.8 for more
+			 *  information about PED and PLS).'
+			 */
+			v = xhci_op_read_4(sc, port);
+			if (((v & XHCI_PS_PED) == 0) ||
+			XHCI_PS_PLS_GET(v) >= XHCI_PS_PLS_U3)
+continue;
+			v &= ~(XHCI_PS_PLS_MASK | XHCI_PS_CLEAR);
+			v |= XHCI_PS_LWS | XHCI_PS_PLS_SET(XHCI_PS_PLS_SETU3);
+			xhci_op_write_4(sc, port, v);
+
+			/*
+			 * `When the PLS field is written with U3
+			 *  (``3''), the status of the PLS bit will not
+			 *  change to the target U state U3 until the
+			 *  suspend signaling has completed to the
+			 *  attached device (which may be as long as
+			 *  10ms.).'
+			 *
+			 * `Software is required to wait for U3
+			 *  transitions to complete before it puts the
+			 *  xHC into a low power state, and before
+			 *  resuming the port.'
+			 *
+			 * XXX Take advantage of the technique to
+			 * reduce polling on host controllers that
+			 * support the U3C capability.
+			 */
+			for (j = 0; j < XHCI_WAIT_PLS_U3; j++) {
+v = xhci_op_read_4(sc, port);
+if (XHCI_PS_PLS_GET(v) == XHCI_PS_PLS_U3)
+	break;
+usb_delay_ms(>sc_bus, 1);
+			}
+			if (j == XHCI_WAIT_PLS_U3) {
+device_printf(self,
+"suspend timeout on bus %zu port %zu\n",
+bn, i);
+return false;
+			}
+		}
+	}
+
+	/*
+	 * xHCI Requirements Specification 1.2, May 2019, Sec. 4.23.2:
+	 * xHCI Power Management, p. 342
+	 * 

CVS commit: src/sys/arch/amd64/amd64

2021-05-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 23 08:59:08 UTC 2021

Modified Files:
src/sys/arch/amd64/amd64: db_disasm.c

Log Message:
ddb/amd64: Don't go out of the way to detect invalid addresses.

db_disasm had logic to detect invalid addresses before trying to
disassemble them.  But when disassembling a null instruction address,
the logic to detect invalid addresses itself tried to dereference an
invalid address.

db_get_value can already handle this situation gracefully, so there is
no need for this faulty fault-avoidance logic.

Fixes double-fault in ddb on calling null function pointers.  With
any luck, this should make diagnosing such bugs easier in the future!


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/amd64/amd64/db_disasm.c

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

Modified files:

Index: src/sys/arch/amd64/amd64/db_disasm.c
diff -u src/sys/arch/amd64/amd64/db_disasm.c:1.27 src/sys/arch/amd64/amd64/db_disasm.c:1.28
--- src/sys/arch/amd64/amd64/db_disasm.c:1.27	Sat Mar  9 08:42:25 2019
+++ src/sys/arch/amd64/amd64/db_disasm.c	Sun May 23 08:59:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_disasm.c,v 1.27 2019/03/09 08:42:25 maxv Exp $	*/
+/*	$NetBSD: db_disasm.c,v 1.28 2021/05/23 08:59:08 riastradh Exp $	*/
 
 /* 
  * Mach Operating System
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.27 2019/03/09 08:42:25 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.28 2021/05/23 08:59:08 riastradh Exp $");
 
 #ifndef _KERNEL
 #include 
@@ -1191,33 +1191,8 @@ db_disasm(db_addr_t loc, bool altfmt)
 	uint64_t imm64;
 	int	len;
 	struct i_addr	address;
-#ifdef _KERNEL
-	pt_entry_t *pte, *pde;
-#endif
 	u_int	rex = 0;
 
-#ifdef _KERNEL
-	/*
-	 * Don't try to disassemble the location if the mapping is invalid.
-	 * If we do, we'll fault, and end up debugging the debugger!
-	 * in the case of largepages, "pte" is really the pde and "pde" is
-	 * really the entry for the pdp itself.
-	 */
-	if ((vaddr_t)loc >= VM_MIN_KERNEL_ADDRESS)
-		pte = kvtopte((vaddr_t)loc);
-	else
-		pte = vtopte((vaddr_t)loc);
-	if ((vaddr_t)pte >= VM_MIN_KERNEL_ADDRESS)
-		pde = kvtopte((vaddr_t)pte);
-	else
-		pde = vtopte((vaddr_t)pte);
-
-	if ((*pde & PTE_P) == 0 || (*pte & PTE_P) == 0) {
-		db_printf("invalid address\n");
-		return (loc);
-	}
-#endif
-
 	get_value_inc(inst, loc, 1, false);
 	short_addr = false;
 	size = LONG;



CVS commit: src/sys/dev/usb

2021-05-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 23 08:42:32 UTC 2021

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

Log Message:
umass(4): Use an empty function callback, not null pointer.

This stupid bug, with an `XXX Broken!' comment right above, has been
preventing NetBSD from suspend/resume with a USB drive plugged in for
longer than I want to even think about admitting.  *sigh*


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/dev/usb/umass_scsipi.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/umass_scsipi.c
diff -u src/sys/dev/usb/umass_scsipi.c:1.67 src/sys/dev/usb/umass_scsipi.c:1.68
--- src/sys/dev/usb/umass_scsipi.c:1.67	Sat Apr 24 23:36:59 2021
+++ src/sys/dev/usb/umass_scsipi.c	Sun May 23 08:42:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: umass_scsipi.c,v 1.67 2021/04/24 23:36:59 thorpej Exp $	*/
+/*	$NetBSD: umass_scsipi.c,v 1.68 2021/05/23 08:42:32 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2001, 2003, 2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.67 2021/04/24 23:36:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.68 2021/05/23 08:42:32 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -101,6 +101,8 @@ Static int umass_scsipi_ioctl(struct scs
 Static int umass_scsipi_getgeom(struct scsipi_periph *,
 struct disk_parms *, u_long);
 
+Static void umass_null_cb(struct umass_softc *, void *,
+			  int, int);
 Static void umass_scsipi_cb(struct umass_softc *, void *,
 			int, int);
 Static void umass_scsipi_sense_cb(struct umass_softc *, void *,
@@ -321,7 +323,7 @@ umass_scsipi_request(struct scsipi_chann
 		  cmdlen, xs->data,
 		  xs->datalen, dir,
 		  xs->timeout, USBD_SYNCHRONOUS,
-		  0, xs);
+		  umass_null_cb, xs);
 			DPRINTFM(UDMASS_SCSI, "done err=%jd",
 			scbus->sc_sync_status, 0, 0, 0);
 			switch (scbus->sc_sync_status) {
@@ -421,6 +423,12 @@ umass_scsipi_getgeom(struct scsipi_perip
 }
 
 Static void
+umass_null_cb(struct umass_softc *sc, void *priv, int residue, int status)
+{
+	UMASSHIST_FUNC(); UMASSHIST_CALLED();
+}
+
+Static void
 umass_scsipi_cb(struct umass_softc *sc, void *priv, int residue, int status)
 {
 	UMASSHIST_FUNC(); UMASSHIST_CALLED();



CVS commit: src/sys/dev/usb

2021-05-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 23 08:42:47 UTC 2021

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

Log Message:
umass(4): Assert that we got a cb up front.

Avoids jump to zero waaay down the line where we've forgotten why
we wanted to jump into oblivion.


To generate a diff of this commit:
cvs rdiff -u -r1.184 -r1.185 src/sys/dev/usb/umass.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/umass.c
diff -u src/sys/dev/usb/umass.c:1.184 src/sys/dev/usb/umass.c:1.185
--- src/sys/dev/usb/umass.c:1.184	Mon Apr 13 09:26:43 2020
+++ src/sys/dev/usb/umass.c	Sun May 23 08:42:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: umass.c,v 1.184 2020/04/13 09:26:43 jdolecek Exp $	*/
+/*	$NetBSD: umass.c,v 1.185 2021/05/23 08:42:47 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -124,7 +124,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.184 2020/04/13 09:26:43 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.185 2021/05/23 08:42:47 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1177,6 +1177,7 @@ umass_bbb_transfer(struct umass_softc *s
 	sc, cb, priv, data, datalen, dir, timeout);
 	static int dCBWtag = 42;	/* unique for CBW of transfer */
 
+	KASSERT(cb);
 	DPRINTFM(UDMASS_BBB, "sc %#jx cmd=0x%02jx", (uintptr_t)sc,
 	*(u_char *)cmd, 0, 0);
 
@@ -1708,6 +1709,7 @@ umass_cbi_transfer(struct umass_softc *s
 	DPRINTFM(UDMASS_CBI, "sc %#jx: cmd=0x%02jx, len=%jd",
 	 (uintptr_t)sc, *(u_char *)cmd, datalen, 0);
 
+	KASSERT(cb);
 	KASSERTMSG(sc->sc_wire & (UMASS_WPROTO_CBI|UMASS_WPROTO_CBI_I),
 		   "sc->sc_wire == 0x%02x wrong for umass_cbi_transfer\n",
 		   sc->sc_wire);



CVS commit: src/sbin/ping6

2021-05-23 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 23 07:17:51 UTC 2021

Modified Files:
src/sbin/ping6: ping6.c

Log Message:
Make sure the output packet buffer and the control message buffer
are aligned.

Fixes bin/56198.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sbin/ping6/ping6.c

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

Modified files:

Index: src/sbin/ping6/ping6.c
diff -u src/sbin/ping6/ping6.c:1.103 src/sbin/ping6/ping6.c:1.104
--- src/sbin/ping6/ping6.c:1.103	Tue Apr 24 07:22:32 2018
+++ src/sbin/ping6/ping6.c	Sun May 23 07:17:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ping6.c,v 1.103 2018/04/24 07:22:32 maxv Exp $	*/
+/*	$NetBSD: ping6.c,v 1.104 2021/05/23 07:17:50 thorpej Exp $	*/
 /*	$KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $	*/
 
 /*
@@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c	8.1 (
 #else
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ping6.c,v 1.103 2018/04/24 07:22:32 maxv Exp $");
+__RCSID("$NetBSD: ping6.c,v 1.104 2021/05/23 07:17:50 thorpej Exp $");
 #endif
 #endif
 
@@ -201,7 +201,7 @@ static struct sockaddr_in6 src;	/* src a
 static socklen_t srclen;
 static int datalen = DEFDATALEN;
 static int s;/* socket file descriptor */
-static u_char outpack[MAXPACKETLEN];
+static u_char outpack[MAXPACKETLEN] __aligned(sizeof(u_long));
 static char BSPACE = '\b';		/* characters written for flood */
 static char DOT = '.';
 static char *hostname;
@@ -923,7 +923,7 @@ doit(u_char *packet, u_int packlen)
 
 	for (;;) {
 		struct msghdr m;
-		u_char buf[1024];
+		u_long buf[1024 / sizeof(u_long)];
 		struct iovec iov[2];
 
 		clock_gettime(CLOCK_MONOTONIC, );