From owner-svn-src-head@freebsd.org Wed Dec 16 14:36:58 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9BDED4BE25E; Wed, 16 Dec 2020 14:36:58 +0000 (UTC) (envelope-from mmel@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CwyPk40Lwz3FBg; Wed, 16 Dec 2020 14:36:58 +0000 (UTC) (envelope-from mmel@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7291B277F1; Wed, 16 Dec 2020 14:36:58 +0000 (UTC) (envelope-from mmel@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0BGEawY7078070; Wed, 16 Dec 2020 14:36:58 GMT (envelope-from mmel@FreeBSD.org) Received: (from mmel@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0BGEawOe078069; Wed, 16 Dec 2020 14:36:58 GMT (envelope-from mmel@FreeBSD.org) Message-Id: <202012161436.0BGEawOe078069@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mmel set sender to mmel@FreeBSD.org using -f From: Michal Meloun Date: Wed, 16 Dec 2020 14:36:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r368697 - head/sys/arm64/arm64 X-SVN-Group: head X-SVN-Commit-Author: mmel X-SVN-Commit-Paths: head/sys/arm64/arm64 X-SVN-Commit-Revision: 368697 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Dec 2020 14:36:58 -0000 Author: mmel Date: Wed Dec 16 14:36:57 2020 New Revision: 368697 URL: https://svnweb.freebsd.org/changeset/base/368697 Log: Allocate right number of pages for the bounced buffers crossing the page. One of the disadvantages of our current busdma code is the fact that we process the bounced buffer in a page-by-page manner. This means that the short (subpage) buffer allocated across page boundaries is bounced to 2 separate pages. This suboptimal behavior is consistent across all platforms and can be related to (probably unimplementable or incompatible with bouncing) BUS_DMA_KEEP_PG_OFFSET flag. Therefore, allocate one additional page to be fully comply with this requirement. Discused with: markj PR: 251018 Modified: head/sys/arm64/arm64/busdma_bounce.c Modified: head/sys/arm64/arm64/busdma_bounce.c ============================================================================== --- head/sys/arm64/arm64/busdma_bounce.c Wed Dec 16 14:01:04 2020 (r368696) +++ head/sys/arm64/arm64/busdma_bounce.c Wed Dec 16 14:36:57 2020 (r368697) @@ -297,6 +297,12 @@ bounce_bus_dma_tag_create(bus_dma_tag_t parent, bus_si if ((flags & BUS_DMA_ALLOCNOW) != 0) { struct bounce_zone *bz; + /* + * Round size up to a full page, and add one more page because + * there can always be one more boundary crossing than the + * number of pages in a transfer. + */ + maxsize = roundup2(maxsize, PAGE_SIZE) + PAGE_SIZE; /* Must bounce */ if ((error = alloc_bounce_zone(newtag)) != 0) { @@ -308,7 +314,7 @@ bounce_bus_dma_tag_create(bus_dma_tag_t parent, bus_si if (ptoa(bz->total_bpages) < maxsize) { int pages; - pages = atop(round_page(maxsize)) - bz->total_bpages; + pages = atop(maxsize) + 1 - bz->total_bpages; /* Add pages to our bounce pool */ if (alloc_bounce_pages(newtag, pages) < pages) @@ -436,8 +442,10 @@ bounce_bus_dmamap_create(bus_dma_tag_t dmat, int flags bz = dmat->bounce_zone; /* - * Attempt to add pages to our pool on a per-instance - * basis up to a sane limit. + * Attempt to add pages to our pool on a per-instancebasis up to a sane + * limit. Even if the tag isn't subject of bouncing due to alignment + * and boundary constraints, it could still auto-bounce due to + * cacheline alignment, which requires at most two bounce pages. */ if (dmat->common.alignment > 1) maxpages = MAX_BPAGES; @@ -446,9 +454,9 @@ bounce_bus_dmamap_create(bus_dma_tag_t dmat, int flags atop(dmat->common.lowaddr)); if ((dmat->bounce_flags & BF_MIN_ALLOC_COMP) == 0 || (bz->map_count > 0 && bz->total_bpages < maxpages)) { - pages = MAX(atop(dmat->common.maxsize), 1); + pages = atop(roundup2(dmat->common.maxsize, PAGE_SIZE)) + 1; pages = MIN(maxpages - bz->total_bpages, pages); - pages = MAX(pages, 1); + pages = MAX(pages, 2); if (alloc_bounce_pages(dmat, pages) < pages) error = ENOMEM; if ((dmat->bounce_flags & BF_MIN_ALLOC_COMP) == 0) {