Module Name:    src
Committed By:   riastradh
Date:           Sun Mar  2 01:23:11 UTC 2025

Modified Files:
        src/sys/arch/riscv/riscv: bus_dma.c

Log Message:
riscv/bus_dma: Handle pmap_extract failure.

That is, when the va is not mapped in the pmap.

Otherwise this trips over uninitialized memory, e.g.:

[   1.0000000] panic: kernel diagnostic assertion "(vaddr & PAGE_MASK) == 
(curaddr & PAGE_MASK)" failed: file 
"/tmp/build/2025.02.22.19.09.05-riscv-riscv64/src/sys/arch/riscv/riscv/bus_dma.c",
 line 1568 va 0xffffffc000a01718 curaddr 0x1

https://releng.netbsd.org/b5reports/riscv-riscv64/2025/2025.02.22.19.09.05/install.log

Perhaps the caller should guarantee that the va is valid, but

(a) for some reason this doesn't work when the va is on the stack,
(b) this is not documented in bus_dma(9), and
(c) if pmap_extract failure should lead to panic then it should do so
    intentionally instead of accidentally tripping over a subsequent
    assertion.

XXX Do this consistently across bus_dma implementations.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/riscv/riscv/bus_dma.c

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

Modified files:

Index: src/sys/arch/riscv/riscv/bus_dma.c
diff -u src/sys/arch/riscv/riscv/bus_dma.c:1.9 src/sys/arch/riscv/riscv/bus_dma.c:1.10
--- src/sys/arch/riscv/riscv/bus_dma.c:1.9	Tue Dec 10 07:42:03 2024
+++ src/sys/arch/riscv/riscv/bus_dma.c	Sun Mar  2 01:23:11 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_dma.c,v 1.9 2024/12/10 07:42:03 skrll Exp $	*/
+/*	$NetBSD: bus_dma.c,v 1.10 2025/03/02 01:23:11 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 #define _RISCV_NEED_BUS_DMA_BOUNCE
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.9 2024/12/10 07:42:03 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.10 2025/03/02 01:23:11 riastradh Exp $");
 
 #include <sys/param.h>
 
@@ -1563,7 +1563,8 @@ _bus_dmamap_load_buffer(bus_dma_tag_t t,
 		/*
 		 * Get the physical address for this segment.
 		 */
-		pmap_extract(pmap, vaddr, &curaddr);
+		if (!pmap_extract(pmap, vaddr, &curaddr))
+			return EFAULT;
 
 		KASSERTMSG((vaddr & PAGE_MASK) == (curaddr & PAGE_MASK),
 		    "va %#" PRIxVADDR " curaddr %#" PRIxBUSADDR, vaddr, curaddr);

Reply via email to