From owner-dev-commits-src-main@freebsd.org Sun Jan 17 17:29:55 2021 Return-Path: Delivered-To: dev-commits-src-main@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 7F6EC4D0D35; Sun, 17 Jan 2021 17:29:55 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DJhkW2Yn9z3kXq; Sun, 17 Jan 2021 17:29:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4792524EDB; Sun, 17 Jan 2021 17:29:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10HHTtiH099932; Sun, 17 Jan 2021 17:29:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10HHTtaU099931; Sun, 17 Jan 2021 17:29:55 GMT (envelope-from git) Date: Sun, 17 Jan 2021 17:29:55 GMT Message-Id: <202101171729.10HHTtaU099931@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: f3ea417f96b0 - main - x86 busdma_bounce: use malloc_domainset_aligned(9). MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f3ea417f96b011a7eb4f43e3142e572833287ef4 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Jan 2021 17:29:55 -0000 The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=f3ea417f96b011a7eb4f43e3142e572833287ef4 commit f3ea417f96b011a7eb4f43e3142e572833287ef4 Author: Konstantin Belousov AuthorDate: 2021-01-14 04:02:21 +0000 Commit: Konstantin Belousov CommitDate: 2021-01-17 17:29:05 +0000 x86 busdma_bounce: use malloc_domainset_aligned(9). This stops busdma bounce making assumptions about alignment of malloc(9) results, which are no longer true. Also add assert that the result of malloc_aligned() fits into single page, which is the assumption of the code. Reported by: dim Reviewed by: andrew, jah, markj Tested by: pho MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D28147 --- sys/x86/x86/busdma_bounce.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sys/x86/x86/busdma_bounce.c b/sys/x86/x86/busdma_bounce.c index 65fbbb7ec1a4..75fdf4143b9b 100644 --- a/sys/x86/x86/busdma_bounce.c +++ b/sys/x86/x86/busdma_bounce.c @@ -433,9 +433,9 @@ bounce_bus_dmamem_alloc(bus_dma_tag_t dmat, void **vaddr, int flags, /* * Allocate the buffer from the malloc(9) allocator if... - * - It's small enough to fit into a single power of two sized bucket. - * - The alignment is less than or equal to the maximum size + * - It's small enough to fit into a single page. * - The low address requirement is fulfilled. + * - Default cache attributes are requested (WB). * else allocate non-contiguous pages if... * - The page count that could get allocated doesn't exceed * nsegments also when the maximum segment size is less @@ -445,19 +445,19 @@ bounce_bus_dmamem_alloc(bus_dma_tag_t dmat, void **vaddr, int flags, * else allocate a block of contiguous pages because one or more of the * constraints is something that only the contig allocator can fulfill. * - * NOTE: The (dmat->common.alignment <= dmat->maxsize) check - * below is just a quick hack. The exact alignment guarantees - * of malloc(9) need to be nailed down, and the code below - * should be rewritten to take that into account. - * - * In the meantime warn the user if malloc gets it wrong. + * Warn the user if malloc gets it wrong. */ if (dmat->common.maxsize <= PAGE_SIZE && - dmat->common.alignment <= dmat->common.maxsize && dmat->common.lowaddr >= ptoa((vm_paddr_t)Maxmem) && attr == VM_MEMATTR_DEFAULT) { - *vaddr = malloc_domainset(dmat->common.maxsize, M_DEVBUF, + *vaddr = malloc_domainset_aligned(dmat->common.maxsize, + dmat->common.alignment, M_DEVBUF, DOMAINSET_PREF(dmat->common.domain), mflags); + KASSERT(*vaddr == NULL || ((uintptr_t)*vaddr & PAGE_MASK) + + dmat->common.maxsize <= PAGE_SIZE, + ("bounce_bus_dmamem_alloc: multi-page alloc %p maxsize " + "%#jx align %#jx", *vaddr, (uintmax_t)dmat->common.maxsize, + (uintmax_t)dmat->common.alignment)); } else if (dmat->common.nsegments >= howmany(dmat->common.maxsize, MIN(dmat->common.maxsegsz, PAGE_SIZE)) &&