git: 8876ff3c4aae - stable/13 - vm: Add kva_alloc_aligned
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 02 Sep 2024 09:12:34 UTC
The branch stable/13 has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=8876ff3c4aae7713f57eceede0173732c73c01d6 commit 8876ff3c4aae7713f57eceede0173732c73c01d6 Author: Andrew Turner <andrew@FreeBSD.org> AuthorDate: 2023-11-29 12:54:49 +0000 Commit: Andrew Turner <andrew@FreeBSD.org> CommitDate: 2024-09-02 09:11:57 +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 a1aba0ba5b26..c867d3c20eb2 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 ba3badf29c3b..defc862a4ac5 100644 --- a/sys/vm/vm_kern.c +++ b/sys/vm/vm_kern.c @@ -154,6 +154,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: *