From nobody Wed Oct 8 19:18:26 2025 Received: from mailrelay6-3.pub.mailoutpod3-cph3.one.com (mailrelay6-3.pub.mailoutpod3-cph3.one.com [46.30.212.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB2957F9 for ; Wed, 25 Jun 2025 06:30:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.30.212.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750833021; cv=none; b=BnxDJ4CTBA4fWAK0ca376DILIChqHYS5RsvjzQ9gWFydOpjfqojFQFpX8hK+lAfnMd5RL9o8qivZqnfvsZFxuAUXULDeYcskE240UUXLz1iEiplvawa9ROTK/hSgCtYWwudHB67vxc1e4tUNSvAIOfUBdUPpRe5mVUJuxbyqewQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750833021; c=relaxed/simple; bh=qQLmriCJNRXZyEY7sikt2q77Kex+BuQ1f8VEOCmEHNM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OQrrPE7C2hekr/eJeJNsUyrwdgJOqSR3KuJP9tQjo9kqsOAVo35yI3qoY1dFGnwlG+e1EjVLwKr9c4gOVxjbssOdEghegn2Cv4FXCn44cA9Dqjs02Mqcl3KUGW1WgzyRSPSrsjELj0P4V0WPMg286zf9G7xLFaT7zVfdjco936M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=konsulko.se; spf=none smtp.mailfrom=konsulko.se; dkim=pass (2048-bit key) header.d=konsulko.se header.i=@konsulko.se header.b=mdHOsk+K; dkim=permerror (0-bit key) header.d=konsulko.se header.i=@konsulko.se header.b=D4JuP3p3; arc=none smtp.client-ip=46.30.212.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=konsulko.se Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=konsulko.se Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=konsulko.se header.i=@konsulko.se header.b="mdHOsk+K"; dkim=permerror (0-bit key) header.d=konsulko.se header.i=@konsulko.se header.b="D4JuP3p3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1750833016; x=1751437816; d=konsulko.se; s=rsa1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=D0x/pTDcFb9pevSx82X48KOGSgZKiyjVSzlAvoUa5m8=; b=mdHOsk+K5OeP97lLxGWgnLKIr0zfdUY00pO8VkeUHl5J4yZvHK0l1WUZf7QzxbK0movr+tHiUIy4N IunkDRbwiGpDICzRVUz55cpN6T9ggAweEbnVVzMGNdUhHph3xmQeNFZMFOmgkNkSx9yYL5YUOIQ2X+ tgzB2pmtBahZa8locAt037aGaAv8Xw12f5zfTCSAcmyY6LdAZ/xXycvRhs3tg0OnD2qBQ+OnxNbymy ew38oO1m5FiLbqwg1hy0llLBUXm0cFfzsVzBVJbdPMrv7NEXeNsq7K4rL0eLZAdSmon4KytHS1BWis 2mSqRrya3Q6AfMB6DgO/TD1MsJjeyBA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1750833016; x=1751437816; d=konsulko.se; s=ed1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=D0x/pTDcFb9pevSx82X48KOGSgZKiyjVSzlAvoUa5m8=; b=D4JuP3p3A3CvYIHdITepWPPwZJJgK6lsUPXyNfCfPJbAHtG8G/S2wadzC7MZzGtHKpYLtisVT8oa1 kOFQM6aCw== X-HalOne-ID: dabebd03-518d-11f0-bce5-417246ffdc90 Received: from localhost.localdomain (host-90-238-19-233.mobileonline.telia.com [90.238.19.233]) by mailrelay6.pub.mailoutpod3-cph3.one.com (Halon) with ESMTPSA id dabebd03-518d-11f0-bce5-417246ffdc90; Wed, 25 Jun 2025 06:30:16 +0000 (UTC) From: Vitaly Wool To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Uladzislau Rezki , Danilo Krummrich , Alice Ryhl , rust-for-linux@vger.kernel.org, Vitaly Wool Subject: [PATCH v3 1/2] mm/vmalloc: allow to set node and align in vrealloc Date: Wed, 25 Jun 2025 08:30:13 +0200 Message-Id: <20250625063013.3379896-1-vitaly.wool@konsulko.se> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250625062917.3379804-1-vitaly.wool@konsulko.se> References: <20250625062917.3379804-1-vitaly.wool@konsulko.se> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Reimplement vrealloc() to be able to set node and alignment should a user need to do so. Rename the function to vrealloc_node() to better match what it actually does now and introduce a macro for vrealloc() for backward compatibility. With that change we also provide the ability for the Rust part of the kernel to set node and aligmnent in its allocations. Signed-off-by: Vitaly Wool Reviewed-by: "Uladzislau Rezki (Sony)" --- include/linux/vmalloc.h | 8 +++++--- mm/nommu.c | 3 ++- mm/vmalloc.c | 16 +++++++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index fdc9aeb74a44..7d5251287687 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -197,9 +197,11 @@ extern void *__vcalloc_noprof(size_t n, size_t size, g= fp_t flags) __alloc_size(1 extern void *vcalloc_noprof(size_t n, size_t size) __alloc_size(1, 2); #define vcalloc(...) alloc_hooks(vcalloc_noprof(__VA_ARGS__)) =20 -void * __must_check vrealloc_noprof(const void *p, size_t size, gfp_t flag= s) - __realloc_size(2); -#define vrealloc(...) alloc_hooks(vrealloc_noprof(__VA_ARGS__)) +void *__must_check vrealloc_node_noprof(const void *p, size_t size, + unsigned long align, gfp_t flags, int nid) __realloc_size(2); +#define vrealloc_noprof(p, s, f) vrealloc_node_noprof(p, s, 1, f, NUMA_NO_= NODE) +#define vrealloc_node(...) alloc_hooks(vrealloc_node_noprof(__VA_ARGS__)) +#define vrealloc(...) alloc_hooks(vrealloc_noprof(__VA_ARGS__)) =20 extern void vfree(const void *addr); extern void vfree_atomic(const void *addr); diff --git a/mm/nommu.c b/mm/nommu.c index b624acec6d2e..ae240115607f 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -119,7 +119,8 @@ void *__vmalloc_noprof(unsigned long size, gfp_t gfp_ma= sk) } EXPORT_SYMBOL(__vmalloc_noprof); =20 -void *vrealloc_noprof(const void *p, size_t size, gfp_t flags) +void *vrealloc_node_noprof(const void *p, size_t size, unsigned long align, + gfp_t flags, int nid) { return krealloc_noprof(p, size, (flags | __GFP_COMP) & ~__GFP_HIGHMEM); } diff --git a/mm/vmalloc.c b/mm/vmalloc.c index ab986dd09b6a..117894301db1 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4081,10 +4081,12 @@ void *vzalloc_node_noprof(unsigned long size, int n= ode) EXPORT_SYMBOL(vzalloc_node_noprof); =20 /** - * vrealloc - reallocate virtually contiguous memory; contents remain unch= anged + * vrealloc_node - reallocate virtually contiguous memory; contents remain= unchanged * @p: object to reallocate memory for * @size: the size to reallocate + * @align: requested alignment * @flags: the flags for the page level allocator + * @nid: node id * * If @p is %NULL, vrealloc() behaves exactly like vmalloc(). If @size is = 0 and * @p is not a %NULL pointer, the object pointed to is freed. @@ -4103,7 +4105,7 @@ EXPORT_SYMBOL(vzalloc_node_noprof); * Return: pointer to the allocated memory; %NULL if @size is zero or in c= ase of * failure */ -void *vrealloc_noprof(const void *p, size_t size, gfp_t flags) +void *vrealloc_node_noprof(const void *p, size_t size, unsigned long align= , gfp_t flags, int nid) { struct vm_struct *vm =3D NULL; size_t alloced_size =3D 0; @@ -4127,6 +4129,13 @@ void *vrealloc_noprof(const void *p, size_t size, gf= p_t flags) if (WARN(alloced_size < old_size, "vrealloc() has mismatched area vs requested sizes (%p)\n", p)) return NULL; + if (WARN(nid !=3D NUMA_NO_NODE && nid !=3D page_to_nid(vmalloc_to_page(p= )), + "vrealloc() has mismatched nids\n")) + return NULL; + if (WARN((uintptr_t)p & (align - 1), + "will not reallocate with a bigger alignment (0x%lx)\n", + align)) + return NULL; } =20 /* @@ -4158,7 +4167,8 @@ void *vrealloc_noprof(const void *p, size_t size, gfp= _t flags) } =20 /* TODO: Grow the vm_area, i.e. allocate and map additional pages. */ - n =3D __vmalloc_noprof(size, flags); + n =3D __vmalloc_node_noprof(size, align, flags, nid, __builtin_return_add= ress(0)); + if (!n) return NULL; =20 --=20 2.39.2 From nobody Wed Oct 8 19:18:26 2025 Received: from mailrelay5-3.pub.mailoutpod3-cph3.one.com (mailrelay5-3.pub.mailoutpod3-cph3.one.com [46.30.212.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DACDC1E22E9 for ; Wed, 25 Jun 2025 06:30:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.30.212.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750833039; cv=none; b=XPLBd0EhkpwB1EVGozeScM7zeCD03HFNQFYUn+Alx27sTyWgufV37iZLjGJNh/M2ERgVcVzxrOCKpCAa3Fpo6iiwIPFRmmABaYnBOJJ9TMvSj6smimVIkO1Cihl9jUlocbkO8zyqdkGRQtw1w081Y1SHviYKxaybKd55UugCZy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750833039; c=relaxed/simple; bh=SKXNK2Zafi76+EibEJpmGhgohZuq3bLnhcDIWse9mlI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=keUSnFUC6y6I30P5uBR81lRxYqU3C7wbdvaA6bRixMRdQwNBJLD1qG9xT0feVIxRiwA1GxQo8w0uhMlk2pXKqJKRgwoRO8u/jXtLELwFSW/NMtxeY1hQ2RIVlfN1v2fsmnMdXV+Xubog7+z+o/IeOEclP+1tay2uCgQ/OJ6Q1xw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=konsulko.se; spf=none smtp.mailfrom=konsulko.se; dkim=pass (2048-bit key) header.d=konsulko.se header.i=@konsulko.se header.b=OA76rY39; dkim=permerror (0-bit key) header.d=konsulko.se header.i=@konsulko.se header.b=5cnH5iKX; arc=none smtp.client-ip=46.30.212.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=konsulko.se Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=konsulko.se Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=konsulko.se header.i=@konsulko.se header.b="OA76rY39"; dkim=permerror (0-bit key) header.d=konsulko.se header.i=@konsulko.se header.b="5cnH5iKX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1750833036; x=1751437836; d=konsulko.se; s=rsa1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=fSXvnx+fgvE5GXly6XPTqjm0PPBXVKwM6V3gQyXQXoE=; b=OA76rY39MWM22xsVJ7hjXljB1U16EOfI9O2OKw1kJEMLHNWpXNAgZQtS729VvpJkNjC6P+eeC3lzk c7/0/Q49KS8JL18LrHlcR99GInfun+HCs9uAtMi2UNhVDLot70cwryaXoyKk9qa0ORGHQyL3iEQU5A 0hl/j+XSJuxaQOad70p2vvSdatpluNbV8pwEIsb0Z3msrgc/fGWE+CPu0t9cUKt0Tr98O5SDSOeo/q PPAHx5C59dkmjTljVQCEzY9TZafPrgNHAL0FzauEdKJNVVa0nUDL/uNMZsW5xhrBF7AdFavVos44p8 B3ZYX0MFEduRh6j3ThTboU4AUZLx2YA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1750833036; x=1751437836; d=konsulko.se; s=ed1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=fSXvnx+fgvE5GXly6XPTqjm0PPBXVKwM6V3gQyXQXoE=; b=5cnH5iKXg5YmwXPrzVkNy8nYsX5vAWWPC5gI3yCxuRNWu586PmJyafz7HXDLMa/iqALpNMCI8A3bh U/QejuRCA== X-HalOne-ID: e5c569ab-518d-11f0-b995-d7c209f8bd06 Received: from localhost.localdomain (host-90-238-19-233.mobileonline.telia.com [90.238.19.233]) by mailrelay5.pub.mailoutpod3-cph3.one.com (Halon) with ESMTPSA id e5c569ab-518d-11f0-b995-d7c209f8bd06; Wed, 25 Jun 2025 06:30:35 +0000 (UTC) From: Vitaly Wool To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Uladzislau Rezki , Danilo Krummrich , Alice Ryhl , rust-for-linux@vger.kernel.org, Vitaly Wool Subject: [PATCH v3 2/2] rust: support align and NUMA id in allocations Date: Wed, 25 Jun 2025 08:30:26 +0200 Message-Id: <20250625063026.3379921-1-vitaly.wool@konsulko.se> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250625062917.3379804-1-vitaly.wool@konsulko.se> References: <20250625062917.3379804-1-vitaly.wool@konsulko.se> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for large (> PAGE_SIZE) alignments in Rust allocators (Kmalloc support for large alignments is limited to the requested size, which is a reasonable limitation anyway). Besides, add support for NUMA id to Vmalloc. Signed-off-by: Vitaly Wool --- rust/helpers/slab.c | 8 +++++-- rust/helpers/vmalloc.c | 4 ++-- rust/kernel/alloc.rs | 28 ++++++++++++++++++++++-- rust/kernel/alloc/allocator.rs | 40 +++++++++++++++++++--------------- rust/kernel/alloc/kvec.rs | 3 ++- 5 files changed, 59 insertions(+), 24 deletions(-) diff --git a/rust/helpers/slab.c b/rust/helpers/slab.c index a842bfbddcba..221c517f57a1 100644 --- a/rust/helpers/slab.c +++ b/rust/helpers/slab.c @@ -3,13 +3,17 @@ #include =20 void * __must_check __realloc_size(2) -rust_helper_krealloc(const void *objp, size_t new_size, gfp_t flags) +rust_helper_krealloc(const void *objp, size_t new_size, unsigned long alig= n, gfp_t flags, int nid) { + if (WARN_ON(new_size & (align - 1))) + return NULL; return krealloc(objp, new_size, flags); } =20 void * __must_check __realloc_size(2) -rust_helper_kvrealloc(const void *p, size_t size, gfp_t flags) +rust_helper_kvrealloc(const void *p, size_t size, unsigned long align, gfp= _t flags, int nid) { + if (WARN_ON(size & (align - 1))) + return NULL; return kvrealloc(p, size, flags); } diff --git a/rust/helpers/vmalloc.c b/rust/helpers/vmalloc.c index 80d34501bbc0..9131279222fa 100644 --- a/rust/helpers/vmalloc.c +++ b/rust/helpers/vmalloc.c @@ -3,7 +3,7 @@ #include =20 void * __must_check __realloc_size(2) -rust_helper_vrealloc(const void *p, size_t size, gfp_t flags) +rust_helper_vrealloc_node(const void *p, size_t size, unsigned long align,= gfp_t flags, int node) { - return vrealloc(p, size, flags); + return vrealloc_node(p, size, align, flags, node); } diff --git a/rust/kernel/alloc.rs b/rust/kernel/alloc.rs index 2e377c52fa07..12a723bf6092 100644 --- a/rust/kernel/alloc.rs +++ b/rust/kernel/alloc.rs @@ -161,7 +161,30 @@ pub unsafe trait Allocator { fn alloc(layout: Layout, flags: Flags) -> Result, AllocE= rror> { // SAFETY: Passing `None` to `realloc` is valid by its safety requ= irements and asks for a // new memory allocation. - unsafe { Self::realloc(None, layout, Layout::new::<()>(), flags) } + unsafe { Self::realloc(None, layout, Layout::new::<()>(), flags, N= one) } + } + + /// Allocate memory based on `layout`, `flags` and `nid`. + /// + /// On success, returns a buffer represented as `NonNull<[u8]>` that s= atisfies the layout + /// constraints (i.e. minimum size and alignment as specified by `layo= ut`). + /// + /// This function is equivalent to `realloc` when called with `None`. + /// + /// # Guarantees + /// + /// When the return value is `Ok(ptr)`, then `ptr` is + /// - valid for reads and writes for `layout.size()` bytes, until it i= s passed to + /// [`Allocator::free`] or [`Allocator::realloc`], + /// - aligned to `layout.align()`, + /// + /// Additionally, `Flags` are honored as documented in + /// . + fn alloc_node(layout: Layout, flags: Flags, nid: Option) + -> Result, AllocError> { + // SAFETY: Passing `None` to `realloc` is valid by its safety requ= irements and asks for a + // new memory allocation. + unsafe { Self::realloc(None, layout, Layout::new::<()>(), flags, n= id) } } =20 /// Re-allocate an existing memory allocation to satisfy the requested= `layout`. @@ -201,6 +224,7 @@ unsafe fn realloc( layout: Layout, old_layout: Layout, flags: Flags, + nid: Option, ) -> Result, AllocError>; =20 /// Free an existing memory allocation. @@ -216,7 +240,7 @@ unsafe fn free(ptr: NonNull, layout: Layout) { // SAFETY: The caller guarantees that `ptr` points at a valid allo= cation created by this // allocator. We are passing a `Layout` with the smallest possible= alignment, so it is // smaller than or equal to the alignment previously used with thi= s allocation. - let _ =3D unsafe { Self::realloc(Some(ptr), Layout::new::<()>(), l= ayout, Flags(0)) }; + let _ =3D unsafe { Self::realloc(Some(ptr), Layout::new::<()>(), l= ayout, Flags(0), None) }; } } =20 diff --git a/rust/kernel/alloc/allocator.rs b/rust/kernel/alloc/allocator.rs index aa2dfa9dca4c..91b36e128b92 100644 --- a/rust/kernel/alloc/allocator.rs +++ b/rust/kernel/alloc/allocator.rs @@ -58,7 +58,8 @@ fn aligned_size(new_layout: Layout) -> usize { /// /// One of the following: `krealloc`, `vrealloc`, `kvrealloc`. struct ReallocFunc( - unsafe extern "C" fn(*const crate::ffi::c_void, usize, u32) -> *mut cr= ate::ffi::c_void, + unsafe extern "C" fn(*const crate::ffi::c_void, usize, usize, u32, i32) + -> *mut crate::ffi::c_void, ); =20 impl ReallocFunc { @@ -66,7 +67,7 @@ impl ReallocFunc { const KREALLOC: Self =3D Self(bindings::krealloc); =20 // INVARIANT: `vrealloc` satisfies the type invariants. - const VREALLOC: Self =3D Self(bindings::vrealloc); + const VREALLOC: Self =3D Self(bindings::vrealloc_node); =20 // INVARIANT: `kvrealloc` satisfies the type invariants. const KVREALLOC: Self =3D Self(bindings::kvrealloc); @@ -87,6 +88,7 @@ unsafe fn call( layout: Layout, old_layout: Layout, flags: Flags, + nid: Option, ) -> Result, AllocError> { let size =3D aligned_size(layout); let ptr =3D match ptr { @@ -100,6 +102,11 @@ unsafe fn call( None =3D> ptr::null(), }; =20 + let c_nid =3D match nid { + None =3D> bindings::NUMA_NO_NODE, + Some(n) =3D> n, + }; + // SAFETY: // - `self.0` is one of `krealloc`, `vrealloc`, `kvrealloc` and th= us only requires that // `ptr` is NULL or valid. @@ -110,7 +117,7 @@ unsafe fn call( // - Those functions provide the guarantees of this function. let raw_ptr =3D unsafe { // If `size =3D=3D 0` and `ptr !=3D NULL` the memory behind th= e pointer is freed. - self.0(ptr.cast(), size, flags.0).cast() + self.0(ptr.cast(), size, layout.align(), flags.0, c_nid).cast() }; =20 let ptr =3D if size =3D=3D 0 { @@ -134,9 +141,10 @@ unsafe fn realloc( layout: Layout, old_layout: Layout, flags: Flags, + _nid: Option, ) -> Result, AllocError> { // SAFETY: `ReallocFunc::call` has the same safety requirements as= `Allocator::realloc`. - unsafe { ReallocFunc::KREALLOC.call(ptr, layout, old_layout, flags= ) } + unsafe { ReallocFunc::KREALLOC.call(ptr, layout, old_layout, flags= , None) } } } =20 @@ -151,16 +159,11 @@ unsafe fn realloc( layout: Layout, old_layout: Layout, flags: Flags, + nid: Option, ) -> Result, AllocError> { - // TODO: Support alignments larger than PAGE_SIZE. - if layout.align() > bindings::PAGE_SIZE { - pr_warn!("Vmalloc does not support alignments larger than PAGE= _SIZE yet.\n"); - return Err(AllocError); - } - // SAFETY: If not `None`, `ptr` is guaranteed to point to valid me= mory, which was previously // allocated with this `Allocator`. - unsafe { ReallocFunc::VREALLOC.call(ptr, layout, old_layout, flags= ) } + unsafe { ReallocFunc::VREALLOC.call(ptr, layout, old_layout, flags= , nid) } } } =20 @@ -175,15 +178,18 @@ unsafe fn realloc( layout: Layout, old_layout: Layout, flags: Flags, + _nid: Option, ) -> Result, AllocError> { - // TODO: Support alignments larger than PAGE_SIZE. - if layout.align() > bindings::PAGE_SIZE { - pr_warn!("KVmalloc does not support alignments larger than PAG= E_SIZE yet.\n"); - return Err(AllocError); - } + // if the caller wants to have alignment bigger than PAGE_SIZE + // it's only vmalloc we can offer to satisfy that request + let alloc_func =3D if layout.align() > bindings::PAGE_SIZE { + ReallocFunc::VREALLOC + } else { + ReallocFunc::KVREALLOC + }; =20 // SAFETY: If not `None`, `ptr` is guaranteed to point to valid me= mory, which was previously // allocated with this `Allocator`. - unsafe { ReallocFunc::KVREALLOC.call(ptr, layout, old_layout, flag= s) } + unsafe { alloc_func.call(ptr, layout, old_layout, flags, None) } } } diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs index 1a0dd852a468..ef4f977ba012 100644 --- a/rust/kernel/alloc/kvec.rs +++ b/rust/kernel/alloc/kvec.rs @@ -633,6 +633,7 @@ pub fn reserve(&mut self, additional: usize, flags: Fla= gs) -> Result<(), AllocEr layout.into(), self.layout.into(), flags, + None, )? }; =20 @@ -1058,7 +1059,7 @@ pub fn collect(self, flags: Flags) -> Vec { // the type invariant to be smaller than `cap`. Depending on `= realloc` this operation // may shrink the buffer or leave it as it is. ptr =3D match unsafe { - A::realloc(Some(buf.cast()), layout.into(), old_layout.int= o(), flags) + A::realloc(Some(buf.cast()), layout.into(), old_layout.int= o(), flags, None) } { // If we fail to shrink, which likely can't even happen, c= ontinue with the existing // buffer. --=20 2.39.2