Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 25 Sep 2021 13:11:31 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 24a3897c2c32 - main - x86 bounce_bus_dmamem_alloc(): use malloc_aligned() only when possible
Message-ID:  <202109251311.18PDBVqf077216@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=24a3897c2c3205c2ec0cf323c555c403d3171e2c

commit 24a3897c2c3205c2ec0cf323c555c403d3171e2c
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-09-24 17:46:47 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-09-25 12:58:12 +0000

    x86 bounce_bus_dmamem_alloc(): use malloc_aligned() only when possible
    
    malloc_domainset_aligned() requires that alignment is less than
    page size. Fall back to other allocation methods, most likely
    kmem_alloc_contig(), when malloc_aligned() cannot fullfill the driver
    request.
    
    Reported by:    Loic F <loic.f@hardenedbsd.org>
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D32127
---
 sys/x86/x86/busdma_bounce.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/x86/x86/busdma_bounce.c b/sys/x86/x86/busdma_bounce.c
index 53ec6a3cab96..5519888542d3 100644
--- a/sys/x86/x86/busdma_bounce.c
+++ b/sys/x86/x86/busdma_bounce.c
@@ -453,6 +453,7 @@ 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 page.
+	 *  - Its alignment requirement is also smaller than the page size.
 	 *  - The low address requirement is fulfilled.
 	 *  - Default cache attributes are requested (WB).
 	 * else allocate non-contiguous pages if...
@@ -467,6 +468,7 @@ bounce_bus_dmamem_alloc(bus_dma_tag_t dmat, void **vaddr, int flags,
 	 * Warn the user if malloc gets it wrong.
 	 */
 	if (dmat->common.maxsize <= PAGE_SIZE &&
+	    dmat->common.alignment <= PAGE_SIZE &&
 	    dmat->common.lowaddr >= ptoa((vm_paddr_t)Maxmem) &&
 	    attr == VM_MEMATTR_DEFAULT) {
 		*vaddr = malloc_domainset_aligned(dmat->common.maxsize,



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