Date: Fri, 18 Apr 2025 14:36:49 GMT From: "Bjoern A. Zeeb" <bz@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: bc6e1ca80704 - stable/14 - LinuxKPI: make __kmalloc() play by the rules Message-ID: <202504181436.53IEanqw091024@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=bc6e1ca8070467eca4e22e8dc0a4fc962169cad7 commit bc6e1ca8070467eca4e22e8dc0a4fc962169cad7 Author: Bjoern A. Zeeb <bz@FreeBSD.org> AuthorDate: 2024-09-12 18:11:01 +0000 Commit: Bjoern A. Zeeb <bz@FreeBSD.org> CommitDate: 2025-04-18 14:35:57 +0000 LinuxKPI: make __kmalloc() play by the rules According to Documentation/core-api/dma-api.rst kmalloc() is supposd to provide physically contiguous memory. [1] In order to guarantee that allocations are contiguous even if using PAGE_SIZE or larger check the size and use contigmalloc if needed. This makes use of 9e6544dd6e02 (and following) allowing free(9) to also work for contigmalloced memory. Sponsored by: The FreeBSD Foundation Pointed out by: jhb [1] Reviewed by: jhb, emaste Differential Revision: https://reviews.freebsd.org/D46656 (cherry picked from commit 19df0c5abcb9d4e951e610b6de98d4d8a00bd5f9) --- sys/compat/linuxkpi/common/src/linux_slab.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sys/compat/linuxkpi/common/src/linux_slab.c b/sys/compat/linuxkpi/common/src/linux_slab.c index 72b35fee9214..5be4c1ec674c 100644 --- a/sys/compat/linuxkpi/common/src/linux_slab.c +++ b/sys/compat/linuxkpi/common/src/linux_slab.c @@ -215,7 +215,11 @@ lkpi___kmalloc(size_t size, gfp_t flags) /* sizeof(struct llist_node) is used for kfree_async(). */ _s = MAX(size, sizeof(struct llist_node)); - return (malloc(_s, M_KMALLOC, linux_check_m_flags(flags))); + if (_s < PAGE_SIZE) + return (malloc(_s, M_KMALLOC, linux_check_m_flags(flags))); + else + return (contigmalloc(_s, M_KMALLOC, linux_check_m_flags(flags), + 0, -1UL, PAGE_SIZE, 0)); } struct lkpi_kmalloc_ctx {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202504181436.53IEanqw091024>