Date: Mon, 2 Sep 2024 08:50:35 GMT From: Andrew Turner <andrew@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: bdbb0be0436a - stable/14 - vm: Add kva_alloc_aligned Message-ID: <202409020850.4828oZal006795@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=bdbb0be0436a6db70c043a3cd8710de59b497e88 commit bdbb0be0436a6db70c043a3cd8710de59b497e88 Author: Andrew Turner <andrew@FreeBSD.org> AuthorDate: 2023-11-29 12:54:49 +0000 Commit: Andrew Turner <andrew@FreeBSD.org> CommitDate: 2024-09-02 08:43:18 +0000 vm: Add kva_alloc_aligned Add a function like kva_alloc that allows us to specify the alignment of the virtual address space returned. Reviewed by: alc, kib, markj Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D42788 (cherry picked from commit 839999e7efdc980d5ada92ea93719c7e29765809) --- sys/vm/vm_extern.h | 1 + sys/vm/vm_kern.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/sys/vm/vm_extern.h b/sys/vm/vm_extern.h index 4bcd8ac601ae..566c837aab7e 100644 --- a/sys/vm/vm_extern.h +++ b/sys/vm/vm_extern.h @@ -49,6 +49,7 @@ struct domainset; /* These operate on kernel virtual addresses only. */ vm_offset_t kva_alloc(vm_size_t); +vm_offset_t kva_alloc_aligned(vm_size_t, vm_size_t); void kva_free(vm_offset_t, vm_size_t); /* These operate on pageable virtual addresses. */ diff --git a/sys/vm/vm_kern.c b/sys/vm/vm_kern.c index 35dbae20449f..387d73d2e46e 100644 --- a/sys/vm/vm_kern.c +++ b/sys/vm/vm_kern.c @@ -157,6 +157,27 @@ kva_alloc(vm_size_t size) return (addr); } +/* + * kva_alloc_aligned: + * + * Allocate a virtual address range as in kva_alloc where the base + * address is aligned to align. + */ +vm_offset_t +kva_alloc_aligned(vm_size_t size, vm_size_t align) +{ + vm_offset_t addr; + + TSENTER(); + size = round_page(size); + if (vmem_xalloc(kernel_arena, size, align, 0, 0, VMEM_ADDR_MIN, + VMEM_ADDR_MAX, M_BESTFIT | M_NOWAIT, &addr)) + return (0); + TSEXIT(); + + return (addr); +} + /* * kva_free: *
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202409020850.4828oZal006795>