From owner-freebsd-amd64@FreeBSD.ORG Sun Apr 12 19:30:50 2009 Return-Path: Delivered-To: freebsd-amd64@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EFD7C1065678 for ; Sun, 12 Apr 2009 19:30:50 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.terabit.net.ua (mail.terabit.net.ua [195.137.202.147]) by mx1.freebsd.org (Postfix) with ESMTP id 87AC68FC18 for ; Sun, 12 Apr 2009 19:30:50 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from skuns.zoral.com.ua ([91.193.166.194] helo=mail.zoral.com.ua) by mail.terabit.net.ua with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63 (FreeBSD)) (envelope-from ) id 1Lt5OC-0009q2-Qr; Sun, 12 Apr 2009 22:30:48 +0300 Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id n3CJUjJ5008097 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 12 Apr 2009 22:30:45 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3) with ESMTP id n3CJUjo6062033; Sun, 12 Apr 2009 22:30:45 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3/Submit) id n3CJUisj062032; Sun, 12 Apr 2009 22:30:44 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 12 Apr 2009 22:30:44 +0300 From: Kostik Belousov To: Scott Long Message-ID: <20090412193044.GN3014@deviant.kiev.zoral.com.ua> References: <200904121520.n3CFK6G8032035@freefall.freebsd.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="2DT8m24oj8Onh3Jp" Content-Disposition: inline In-Reply-To: <200904121520.n3CFK6G8032035@freefall.freebsd.org> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: ClamAV version 0.94.2, clamav-milter version 0.94.2 on skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua X-Virus-Scanned: mail.terabit.net.ua 1Lt5OC-0009q2-Qr af4d76cbd30b1303f8377d0cf41503b2 X-Terabit: YES Cc: freebsd-amd64@freebsd.org Subject: Re: amd64/133592: [busdma] [patch] busdma incorrectly calculates bounce buffer requirements for userspace buffers X-BeenThere: freebsd-amd64@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to the AMD64 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Apr 2009 19:30:51 -0000 --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 > 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--