Date: Sun, 12 Apr 2009 22:30:44 +0300 From: Kostik Belousov <kostikbel@gmail.com> To: Scott Long <scottl@samsco.org> Cc: freebsd-amd64@freebsd.org Subject: Re: amd64/133592: [busdma] [patch] busdma incorrectly calculates bounce buffer requirements for userspace buffers Message-ID: <20090412193044.GN3014@deviant.kiev.zoral.com.ua> In-Reply-To: <200904121520.n3CFK6G8032035@freefall.freebsd.org> References: <200904121520.n3CFK6G8032035@freefall.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--2DT8m24oj8Onh3Jp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Apr 12, 2009 at 03:20:06PM +0000, Scott Long wrote: > The following reply was made to PR amd64/133592; it has been noted by GNA= TS. >=20 > From: Scott Long <scottl@samsco.org> > To: bug-followup@FreeBSD.org, jason.harmening@gmail.com > Cc: =20 > Subject: Re: amd64/133592: [busdma] [patch] busdma incorrectly calculates > bounce buffer requirements for userspace buffers > Date: Sun, 12 Apr 2009 08:53:47 -0600 >=20 > You're right, it's definitely a problem. The patch looks correct, feel > free to commit to i386, amd64, and ia64. Arm needs a similar fix, but > the code looks to be somewhat different. Below is updated patch. It was compile-tested on all affected arches. Scott, any notes ? diff --git a/sys/amd64/amd64/busdma_machdep.c b/sys/amd64/amd64/busdma_mach= dep.c index c50fcc3..de4717c 100644 --- a/sys/amd64/amd64/busdma_machdep.c +++ b/sys/amd64/amd64/busdma_machdep.c @@ -606,7 +606,10 @@ _bus_dmamap_load_buffer(bus_dma_tag_t dmat, vendaddr =3D (vm_offset_t)buf + buflen; =20 while (vaddr < vendaddr) { - paddr =3D pmap_kextract(vaddr); + if (pmap) + paddr =3D pmap_extract(pmap, vaddr); + else + paddr =3D pmap_kextract(vaddr); if (run_filter(dmat, paddr) !=3D 0) map->pagesneeded++; vaddr +=3D (PAGE_SIZE - ((vm_offset_t)vaddr & PAGE_MASK)); diff --git a/sys/arm/arm/busdma_machdep.c b/sys/arm/arm/busdma_machdep.c index a738172..153d83f 100644 --- a/sys/arm/arm/busdma_machdep.c +++ b/sys/arm/arm/busdma_machdep.c @@ -669,8 +669,8 @@ bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dm= amap_t map) } =20 static int -_bus_dmamap_count_pages(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, - bus_size_t buflen, int flags) +_bus_dmamap_count_pages(bus_dma_tag_t dmat, bus_dmamap_t map, pmap_t pmap, + void *buf, bus_size_t buflen, int flags) { vm_offset_t vaddr; vm_offset_t vendaddr; @@ -689,7 +689,10 @@ _bus_dmamap_count_pages(bus_dma_tag_t dmat, bus_dmamap= _t map, void *buf, vendaddr =3D (vm_offset_t)buf + buflen; =20 while (vaddr < vendaddr) { - paddr =3D pmap_kextract(vaddr); + if (pmap !=3D NULL) + paddr =3D pmap_extract(pmap, vaddr); + else + paddr =3D pmap_kextract(vaddr); if (((dmat->flags & BUS_DMA_COULD_BOUNCE) !=3D 0) && run_filter(dmat, paddr) !=3D 0) map->pagesneeded++; @@ -745,7 +748,8 @@ bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dma_segm= ent_t *segs, bmask =3D ~(dmat->boundary - 1); =20 if ((dmat->flags & BUS_DMA_COULD_BOUNCE) !=3D 0) { - error =3D _bus_dmamap_count_pages(dmat, map, buf, buflen, flags); + error =3D _bus_dmamap_count_pages(dmat, map, pmap, buf, buflen, + flags); if (error) return (error); } diff --git a/sys/i386/i386/busdma_machdep.c b/sys/i386/i386/busdma_machdep.c index d4aa9b5..cf0ac51 100644 --- a/sys/i386/i386/busdma_machdep.c +++ b/sys/i386/i386/busdma_machdep.c @@ -142,8 +142,8 @@ static bus_addr_t add_bounce_page(bus_dma_tag_t dmat, b= us_dmamap_t map, vm_offset_t vaddr, bus_size_t size); static void free_bounce_page(bus_dma_tag_t dmat, struct bounce_page *bpage= ); int run_filter(bus_dma_tag_t dmat, bus_addr_t paddr); -int _bus_dmamap_count_pages(bus_dma_tag_t dmat, bus_dmamap_t map, void *bu= f, - bus_size_t buflen, int flags); +int _bus_dmamap_count_pages(bus_dma_tag_t dmat, bus_dmamap_t map, pmap_t p= map, + void *buf, bus_size_t buflen, int flags); =20 #ifdef XEN #undef pmap_kextract @@ -577,8 +577,8 @@ bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dm= amap_t map) } =20 int -_bus_dmamap_count_pages(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, - bus_size_t buflen, int flags) +_bus_dmamap_count_pages(bus_dma_tag_t dmat, bus_dmamap_t map, pmap_t pmap, + void *buf, bus_size_t buflen, int flags) { vm_offset_t vaddr; vm_offset_t vendaddr; @@ -598,7 +598,10 @@ _bus_dmamap_count_pages(bus_dma_tag_t dmat, bus_dmamap= _t map, void *buf, vendaddr =3D (vm_offset_t)buf + buflen; =20 while (vaddr < vendaddr) { - paddr =3D pmap_kextract(vaddr); + if (pmap) + paddr =3D pmap_extract(pmap, vaddr); + else + paddr =3D pmap_kextract(vaddr); if (((dmat->flags & BUS_DMA_COULD_BOUNCE) !=3D 0) && run_filter(dmat, paddr) !=3D 0) { map->pagesneeded++; @@ -660,7 +663,7 @@ _bus_dmamap_load_buffer(bus_dma_tag_t dmat, map =3D &nobounce_dmamap; =20 if ((dmat->flags & BUS_DMA_COULD_BOUNCE) !=3D 0) { - error =3D _bus_dmamap_count_pages(dmat, map, buf, buflen, flags); + error =3D _bus_dmamap_count_pages(dmat, map, pmap, buf, buflen, flags); if (error) return (error); } diff --git a/sys/ia64/ia64/busdma_machdep.c b/sys/ia64/ia64/busdma_machdep.c index 659db52..609a8a9 100644 --- a/sys/ia64/ia64/busdma_machdep.c +++ b/sys/ia64/ia64/busdma_machdep.c @@ -527,7 +527,10 @@ _bus_dmamap_load_buffer(bus_dma_tag_t dmat, vendaddr =3D (vm_offset_t)buf + buflen; =20 while (vaddr < vendaddr) { - paddr =3D pmap_kextract(vaddr); + if (pmap !=3D NULL) + paddr =3D pmap_extract(pmap, vaddr); + else + paddr =3D pmap_kextract(vaddr); if (run_filter(dmat, paddr, 0) !=3D 0) map->pagesneeded++; vaddr +=3D PAGE_SIZE; --2DT8m24oj8Onh3Jp Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (FreeBSD) iEYEARECAAYFAkniQWQACgkQC3+MBN1Mb4jqAgCgkuaUlrdqHW19UJ/z7vvdrwAl IlMAoIHgzihAGYpeq66pJiFLO/Cgb0yk =obUa -----END PGP SIGNATURE----- --2DT8m24oj8Onh3Jp--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090412193044.GN3014>