Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Jan 2019 13:38:56 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r343146 - in head/sys/x86: include x86
Message-ID:  <201901181338.x0IDcuND085826@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Fri Jan 18 13:38:56 2019
New Revision: 343146
URL: https://svnweb.freebsd.org/changeset/base/343146

Log:
  x86 busdma: fix mis-use of bus_addr_t where vm_paddr_t is assumed.
  
  Right now bus_addr_t and vm_paddr_t are always aliased to the same
  underlying integer type on x86, which makes the interchange hard to
  detect.  Shortly, i386 kernel would use uint64_t for vm_paddr_t to
  enable automatic use of PAE paging structures if hardware allows it,
  while bus_addr_t would be extended to 64bit only when PAE option is
  specified.
  
  Fix all places that were identified as using bus_addr_t while page
  address was assumed.  This was performed by testing the complete PAE
  merging patch on machine with > 4G of RAM enabled.
  
  Reviewed by:	markj
  Tested by:	pho
  Sponsored by:	The FreeBSD Foundation
  MFC after:	2 weeks
  Differential revision:	https://reviews.freebsd.org/D18854

Modified:
  head/sys/x86/include/busdma_impl.h
  head/sys/x86/x86/busdma_bounce.c
  head/sys/x86/x86/busdma_machdep.c

Modified: head/sys/x86/include/busdma_impl.h
==============================================================================
--- head/sys/x86/include/busdma_impl.h	Fri Jan 18 13:35:06 2019	(r343145)
+++ head/sys/x86/include/busdma_impl.h	Fri Jan 18 13:38:56 2019	(r343146)
@@ -87,7 +87,7 @@ struct bus_dma_impl {
 };
 
 void bus_dma_dflt_lock(void *arg, bus_dma_lock_op_t op);
-int bus_dma_run_filter(struct bus_dma_tag_common *dmat, bus_addr_t paddr);
+int bus_dma_run_filter(struct bus_dma_tag_common *dmat, vm_paddr_t paddr);
 int common_bus_dma_tag_create(struct bus_dma_tag_common *parent,
     bus_size_t alignment,
     bus_addr_t boundary, bus_addr_t lowaddr, bus_addr_t highaddr,

Modified: head/sys/x86/x86/busdma_bounce.c
==============================================================================
--- head/sys/x86/x86/busdma_bounce.c	Fri Jan 18 13:35:06 2019	(r343145)
+++ head/sys/x86/x86/busdma_bounce.c	Fri Jan 18 13:38:56 2019	(r343146)
@@ -139,7 +139,7 @@ static int alloc_bounce_pages(bus_dma_tag_t dmat, u_in
 static int reserve_bounce_pages(bus_dma_tag_t dmat, bus_dmamap_t map,
     int commit);
 static bus_addr_t add_bounce_page(bus_dma_tag_t dmat, bus_dmamap_t map,
-    vm_offset_t vaddr, bus_addr_t addr1, bus_addr_t addr2, bus_size_t size);
+    vm_offset_t vaddr, vm_paddr_t addr1, vm_paddr_t addr2, bus_size_t size);
 static void free_bounce_page(bus_dma_tag_t dmat, struct bounce_page *bpage);
 static void _bus_dmamap_count_pages(bus_dma_tag_t dmat, bus_dmamap_t map,
     pmap_t pmap, void *buf, bus_size_t buflen, int flags);
@@ -507,7 +507,7 @@ static void
 _bus_dmamap_count_phys(bus_dma_tag_t dmat, bus_dmamap_t map, vm_paddr_t buf,
     bus_size_t buflen, int flags)
 {
-	bus_addr_t curaddr;
+	vm_paddr_t curaddr;
 	bus_size_t sgsize;
 
 	if (map != &nobounce_dmamap && map->pagesneeded == 0) {
@@ -536,7 +536,7 @@ _bus_dmamap_count_pages(bus_dma_tag_t dmat, bus_dmamap
 {
 	vm_offset_t vaddr;
 	vm_offset_t vendaddr;
-	bus_addr_t paddr;
+	vm_paddr_t paddr;
 	bus_size_t sg_len;
 
 	if (map != &nobounce_dmamap && map->pagesneeded == 0) {
@@ -643,12 +643,19 @@ _bus_dmamap_reserve_pages(bus_dma_tag_t dmat, bus_dmam
  * Add a single contiguous physical range to the segment list.
  */
 static int
-_bus_dmamap_addseg(bus_dma_tag_t dmat, bus_dmamap_t map, bus_addr_t curaddr,
+_bus_dmamap_addseg(bus_dma_tag_t dmat, bus_dmamap_t map, vm_paddr_t curaddr,
     bus_size_t sgsize, bus_dma_segment_t *segs, int *segp)
 {
 	bus_addr_t baddr, bmask;
 	int seg;
 
+	KASSERT(curaddr <= BUS_SPACE_MAXADDR,
+	    ("ds_addr %#jx > BUS_SPACE_MAXADDR %#jx; dmat %p fl %#x low %#jx "
+	    "hi %#jx",
+	    (uintmax_t)curaddr, (uintmax_t)BUS_SPACE_MAXADDR,
+	    dmat, dmat->bounce_flags, (uintmax_t)dmat->common.lowaddr,
+	    (uintmax_t)dmat->common.highaddr));
+
 	/*
 	 * Make sure we don't cross any boundaries.
 	 */
@@ -695,7 +702,7 @@ bounce_bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dm
     int *segp)
 {
 	bus_size_t sgsize;
-	bus_addr_t curaddr;
+	vm_paddr_t curaddr;
 	int error;
 
 	if (map == NULL)
@@ -747,7 +754,7 @@ bounce_bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_
     int *segp)
 {
 	bus_size_t sgsize, max_sgsize;
-	bus_addr_t curaddr;
+	vm_paddr_t curaddr;
 	vm_offset_t kvaddr, vaddr;
 	int error;
 
@@ -1194,7 +1201,7 @@ reserve_bounce_pages(bus_dma_tag_t dmat, bus_dmamap_t 
 
 static bus_addr_t
 add_bounce_page(bus_dma_tag_t dmat, bus_dmamap_t map, vm_offset_t vaddr,
-    bus_addr_t addr1, bus_addr_t addr2, bus_size_t size)
+    vm_paddr_t addr1, vm_paddr_t addr2, bus_size_t size)
 {
 	struct bounce_zone *bz;
 	struct bounce_page *bpage;

Modified: head/sys/x86/x86/busdma_machdep.c
==============================================================================
--- head/sys/x86/x86/busdma_machdep.c	Fri Jan 18 13:35:06 2019	(r343145)
+++ head/sys/x86/x86/busdma_machdep.c	Fri Jan 18 13:38:56 2019	(r343146)
@@ -99,14 +99,15 @@ bus_dma_dflt_lock(void *arg, bus_dma_lock_op_t op)
  * to check for a match, if there is no filter callback then assume a match.
  */
 int
-bus_dma_run_filter(struct bus_dma_tag_common *tc, bus_addr_t paddr)
+bus_dma_run_filter(struct bus_dma_tag_common *tc, vm_paddr_t paddr)
 {
 	int retval;
 
 	retval = 0;
 	do {
-		if (((paddr > tc->lowaddr && paddr <= tc->highaddr) ||
-		    ((paddr & (tc->alignment - 1)) != 0)) &&
+		if ((paddr >= BUS_SPACE_MAXADDR ||
+		    (paddr > tc->lowaddr && paddr <= tc->highaddr) ||
+		    (paddr & (tc->alignment - 1)) != 0) &&
 		    (tc->filter == NULL ||
 		    (*tc->filter)(tc->filterarg, paddr) != 0))
 			retval = 1;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201901181338.x0IDcuND085826>