Module Name:    src
Committed By:   thorpej
Date:           Mon Jul 19 16:25:54 UTC 2021

Modified Files:
        src/sys/arch/alpha/common: bus_dma.c sgmap_typedep.c

Log Message:
There is already a fast-path in pmap_extract() for the kernel pmap, so
don't bother doing a conditional for kernel vs. user-space here.

KASSERT() that pmap_extract() succeeds; it is a programming error if
it does not, and it's not a great idea to insert a garbage address
into the SGMAP page table.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/alpha/common/bus_dma.c
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/alpha/common/sgmap_typedep.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/common/bus_dma.c
diff -u src/sys/arch/alpha/common/bus_dma.c:1.72 src/sys/arch/alpha/common/bus_dma.c:1.73
--- src/sys/arch/alpha/common/bus_dma.c:1.72	Fri May  7 16:58:33 2021
+++ src/sys/arch/alpha/common/bus_dma.c	Mon Jul 19 16:25:54 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: bus_dma.c,v 1.72 2021/05/07 16:58:33 thorpej Exp $ */
+/* $NetBSD: bus_dma.c,v 1.73 2021/07/19 16:25:54 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.72 2021/05/07 16:58:33 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.73 2021/07/19 16:25:54 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -138,6 +138,7 @@ _bus_dmamap_load_buffer_direct(bus_dma_t
 	bus_addr_t curaddr, lastaddr, baddr, bmask;
 	vaddr_t vaddr = (vaddr_t)buf;
 	int seg;
+	bool address_is_valid __diagused;
 
 	lastaddr = *lastaddrp;
 	bmask = ~(map->_dm_boundary - 1);
@@ -146,10 +147,9 @@ _bus_dmamap_load_buffer_direct(bus_dma_t
 		/*
 		 * Get the physical address for this segment.
 		 */
-		if (!VMSPACE_IS_KERNEL_P(vm))
-			(void) pmap_extract(vm->vm_map.pmap, vaddr, &curaddr);
-		else
-			curaddr = vtophys(vaddr);
+		address_is_valid =
+		    pmap_extract(vm->vm_map.pmap, vaddr, &curaddr);
+		KASSERT(address_is_valid);
 
 		/*
 		 * If we're beyond the current DMA window, indicate

Index: src/sys/arch/alpha/common/sgmap_typedep.c
diff -u src/sys/arch/alpha/common/sgmap_typedep.c:1.43 src/sys/arch/alpha/common/sgmap_typedep.c:1.44
--- src/sys/arch/alpha/common/sgmap_typedep.c:1.43	Sun Jul 18 05:12:27 2021
+++ src/sys/arch/alpha/common/sgmap_typedep.c	Mon Jul 19 16:25:54 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmap_typedep.c,v 1.43 2021/07/18 05:12:27 thorpej Exp $ */
+/* $NetBSD: sgmap_typedep.c,v 1.44 2021/07/19 16:25:54 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.43 2021/07/18 05:12:27 thorpej Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.44 2021/07/19 16:25:54 thorpej Exp $");
 
 #include "opt_ddb.h"
 
@@ -74,6 +74,7 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 	bus_size_t sgvalen, extra_sgvalen, boundary, alignment;
 	SGMAP_PTE_TYPE *pte, *page_table = sgmap->aps_pt;
 	int pteidx, error, spill, seg = *segp;
+	bool address_is_valid __diagused;
 
 	/* Initialize the spill page PTE if it hasn't been already. */
 	if (__C(SGMAP_TYPE,_prefetch_spill_page_pte) == 0)
@@ -268,10 +269,8 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 	for (; va < endva; va += PAGE_SIZE, pteidx++,
 	     pte = &page_table[pteidx * SGMAP_PTE_SPACING]) {
 		/* Get the physical address for this segment. */
-		if (!VMSPACE_IS_KERNEL_P(vm))
-			(void) pmap_extract(vm->vm_map.pmap, va, &pa);
-		else
-			pa = vtophys(va);
+		address_is_valid = pmap_extract(vm->vm_map.pmap, va, &pa);
+		KASSERT(address_is_valid);
 
 		/* Load the current PTE with this page. */
 		*pte = (pa >> SGPTE_PGADDR_SHIFT) | SGPTE_VALID;
@@ -289,10 +288,8 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 
 		/* va == endva == address of extra page */
 		KASSERT(va == endva);
-		if (!VMSPACE_IS_KERNEL_P(vm))
-			(void) pmap_extract(vm->vm_map.pmap, va, &pa);
-		else
-			pa = vtophys(va);
+		address_is_valid = pmap_extract(vm->vm_map.pmap, va, &pa);
+		KASSERT(address_is_valid);
 
 		/*
 		 * If a spill page is needed, the previous segment will

Reply via email to