From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2A59C83F04 for ; Wed, 2 Jul 2025 16:09:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5EAB8900006; Wed, 2 Jul 2025 12:09:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 59A638E0002; Wed, 2 Jul 2025 12:09:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 489E3900006; Wed, 2 Jul 2025 12:09:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 35B058E0002 for ; Wed, 2 Jul 2025 12:09:27 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 063F05875A for ; Wed, 2 Jul 2025 16:09:27 +0000 (UTC) X-FDA: 83619809574.07.B12AB8A Received: from mailrelay1-3.pub.mailoutpod3-cph3.one.com (mailrelay1-3.pub.mailoutpod3-cph3.one.com [46.30.212.0]) by imf15.hostedemail.com (Postfix) with ESMTP id 39C24A0012 for ; Wed, 2 Jul 2025 16:09:24 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=konsulko.se header.s=rsa1 header.b=6WROcM2D; dkim=pass header.d=konsulko.se header.s=ed1 header.b=dQPUYuCn ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751472565; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gALnPztzwr59zDTT061QlxUWux/AzyL/kG1HsRDCKCA=; b=Ivl9DrE/w2enbk8QRNwir5AMeKIc41ttE3OV4714HA/4SjUjid5PA/C1SzEDt+kAnGuD5s +GpbC5RICo7CZepwsbx2SRY+O/LlW6wOF3hZ5YCogNGy5XaImmvmlZ7CWb2Co0sc6gIC4m 89SDqOG7hHBGFhNzsy5EGLn6ktCDmgs= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=konsulko.se header.s=rsa1 header.b=6WROcM2D; dkim=pass header.d=konsulko.se header.s=ed1 header.b=dQPUYuCn; spf=none (imf15.hostedemail.com: domain of vitaly.wool@konsulko.se has no SPF policy when checking 46.30.212.0) smtp.mailfrom=vitaly.wool@konsulko.se; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751472565; a=rsa-sha256; cv=none; b=OoZpT5TGFWkiakgUPulibb9ljGw2yXkn4K9tlsT79IyiKQY5EhxRNWSUY2hYkb0qgcYTts vElU+WEsc783PdMDogqqZ59fXXjvFDLLgx9+3RgLo4XPyzc2dQWCCMdAVy1THfrACuHzDO D0OAd/t1u2KrdTpNjjmbHWOHFjI7HUc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1751472564; x=1752077364; d=konsulko.se; s=rsa1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=gALnPztzwr59zDTT061QlxUWux/AzyL/kG1HsRDCKCA=; b=6WROcM2DLPsHrpKb49sbmLJLoAnNEZzzsNFVn4HpXFH2oTiJz1jayjOJQn3m23WDnT4bD9nB9P7v3 Cx/b99i8L8evsyjIvvnL28jRGu9lSJGNMdwsflPFm76r0I1oF5weHc0wU8qsHcep10Ak+v1luAAnth Xqfps3LLH4OwNQVHoowwPcNsqCIGlPDJ4qLI6CJbNYGQexxDTuGjny0+JC26AchRenPPDzgeKUb8cx AdE5yvnSMIvcwnRB0bKHttLPetfqw2HCs3Aw4k6OEMYLORNrSOrsHwC3nSBHi77BtcmSI7rnenhTa0 FijH7kR5qGSAXnFXcbW+zw2S69Lvh+A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1751472564; x=1752077364; d=konsulko.se; s=ed1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=gALnPztzwr59zDTT061QlxUWux/AzyL/kG1HsRDCKCA=; b=dQPUYuCnHuYFEszxvpCEW2oq5+ZNWdHr8saktkE8JByP3BM+uCoVrzoOhA8l8h0HhzlQBysnwsPdW 1IvTTlaDA== X-HalOne-ID: e9e51555-575e-11f0-918f-152d8afab6bc Received: from slottsdator.home (host-90-238-19-233.mobileonline.telia.com [90.238.19.233]) by mailrelay1.pub.mailoutpod3-cph3.one.com (Halon) with ESMTPSA id e9e51555-575e-11f0-918f-152d8afab6bc; Wed, 02 Jul 2025 16:09:23 +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 v10 4/4] rust: support large alignments in allocations Date: Wed, 2 Jul 2025 18:09:21 +0200 Message-Id: <20250702160921.3610168-1-vitaly.wool@konsulko.se> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250702160758.3609992-1-vitaly.wool@konsulko.se> References: <20250702160758.3609992-1-vitaly.wool@konsulko.se> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 39C24A0012 X-Stat-Signature: d4tzah5xsprtqq13ideq7wozih1cqa81 X-HE-Tag: 1751472564-741442 X-HE-Meta: U2FsdGVkX19I6NbA1VWw3//CrqwpESO4mor/FFdqImysQwNPZGCc2wLPwSievqifegwzK4vQVrIe/wfCWYuf7XDetceh1Oq3K0hiIOjRrQvD7baw4BQsggBGpvYoa+pPOGQo84WZ4LTSLiYGc3280Psjk2/kTX/zf7R1N08BSoGjG32e3r4l30glWVduWYXEkPA8flp2YE6gGYvU2WRmZ9PD9fe9tqte+DNU8CdcyqDtTMwKFn86H3Ha0u6OXBPV9LP4gEg0TwWvOVl7YjrrVbcR1ZaD57OK6uCbAjPYzEQ+mzcCj2DCFiRCPdqi6WWfPlMnaNvbclaw9gHTV3OlP5tEH8sOnbfC0IOKeSZMRA7P88VnNzbIsKS7n3WVBw3a2M14q/akzi42aGpMSAnsOMJ8BaENZclkI0DZfAHRLCZlR637mox8iQmMt6NjhKoeavsdhLPAzgD95D6Jzs3rcltYQQ6rz7VOp9AzlFuNzUw6e9NOG0GYdRb0umVgvHX0KQ3cfpnNSqWfSulj5ZC9TawafAY5JQvySnuP9fmAVfvq5hblLrIO1gxCLMvn1OvIEbwFJk4KA+uKQVih8w/dAInyTzBgXmbt+ms/bbDZ6C9yVl3dZ+kRtY3dLMtHzhuUGqEf6M8fReHMK37V6rKQWYjMT3m2e4sJf0OiG9eJtE3gBpwqMjCPd14Lx/pq8noSktTNPQ3IGisIO0aCREre48LbrIK6pDuizLTmK/PaaSQnwX5wBF2g7wUzJzRzekcRuljMTFGv4XxvhTVsw/QrgKe1qgESEDOxt+bZng2KzxMfZQz5v0AJJUOA67Q45mBS3cmUgaR/qbbYfsDxpJBzsL7pnZ4BfKMB3ReY28MIuBCnoYHs+ykWbfjGlU5xsdgReQrWrgyetkhu6r8TNoIWdeDAj1+5h27fxU4PW6d4rjn4INJeWg5PSxmdiatpdHpzadXyDtFpJ2HHffL1Le8 AGTxIcmn ocsZYTJ8QghDOg7We9yoeVQKsWzcuArDtESVZdqwjAB9bgheSw0b01WwH432lbly2Q7U9YXZhr/wbSbINxKqS+CFG2lBWJxkSa4B4LZtwRkNF/fkfH2xzmcdtJwE64hxs0BG8 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add support for large (> PAGE_SIZE) alignments in Rust allocators. All the preparations on the C side are already done, we just need to add bindings for _node_align() functions and start using those. Signed-off-by: Vitaly Wool --- rust/helpers/slab.c | 10 ++++++---- rust/helpers/vmalloc.c | 5 +++-- rust/kernel/alloc/allocator.rs | 27 ++++++++------------------- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/rust/helpers/slab.c b/rust/helpers/slab.c index 8472370a4338..d729be798f31 100644 --- a/rust/helpers/slab.c +++ b/rust/helpers/slab.c @@ -3,13 +3,15 @@ #include void * __must_check __realloc_size(2) -rust_helper_krealloc_node(const void *objp, size_t new_size, gfp_t flags, int node) +rust_helper_krealloc_node_align(const void *objp, size_t new_size, unsigned long align, + gfp_t flags, int node) { - return krealloc_node(objp, new_size, flags, node); + return krealloc_node_align(objp, new_size, align, flags, node); } void * __must_check __realloc_size(2) -rust_helper_kvrealloc_node(const void *p, size_t size, gfp_t flags, int node) +rust_helper_kvrealloc_node_align(const void *p, size_t size, unsigned long align, + gfp_t flags, int node) { - return kvrealloc_node(p, size, flags, node); + return kvrealloc_node_align(p, size, align, flags, node); } diff --git a/rust/helpers/vmalloc.c b/rust/helpers/vmalloc.c index 62d30db9a1a6..7d7f7336b3d2 100644 --- a/rust/helpers/vmalloc.c +++ b/rust/helpers/vmalloc.c @@ -3,7 +3,8 @@ #include void * __must_check __realloc_size(2) -rust_helper_vrealloc_node(const void *p, size_t size, gfp_t flags, int node) +rust_helper_vrealloc_node_align(const void *p, size_t size, unsigned long align, + gfp_t flags, int node) { - return vrealloc_node(p, size, flags, node); + return vrealloc_node_align(p, size, align, flags, node); } diff --git a/rust/kernel/alloc/allocator.rs b/rust/kernel/alloc/allocator.rs index 15d737fe89ed..1a54513533cf 100644 --- a/rust/kernel/alloc/allocator.rs +++ b/rust/kernel/alloc/allocator.rs @@ -61,20 +61,21 @@ struct ReallocFunc( unsafe extern "C" fn( *const crate::ffi::c_void, usize, + crate::ffi::c_ulong, u32, crate::ffi::c_int, ) -> *mut crate::ffi::c_void, ); impl ReallocFunc { - // INVARIANT: `krealloc_node` satisfies the type invariants. - const KREALLOC: Self = Self(bindings::krealloc_node); + // INVARIANT: `krealloc_node_align` satisfies the type invariants. + const KREALLOC: Self = Self(bindings::krealloc_node_align); - // INVARIANT: `vrealloc_node` satisfies the type invariants. - const VREALLOC: Self = Self(bindings::vrealloc_node); + // INVARIANT: `vrealloc_node_align` satisfies the type invariants. + const VREALLOC: Self = Self(bindings::vrealloc_node_align); - // INVARIANT: `kvrealloc_node` satisfies the type invariants. - const KVREALLOC: Self = Self(bindings::kvrealloc_node); + // INVARIANT: `kvrealloc_node_align` satisfies the type invariants. + const KVREALLOC: Self = Self(bindings::kvrealloc_node_align); /// # Safety /// @@ -116,7 +117,7 @@ unsafe fn call( // - Those functions provide the guarantees of this function. let raw_ptr = unsafe { // If `size == 0` and `ptr != NULL` the memory behind the pointer is freed. - self.0(ptr.cast(), size, flags.0, nid.0).cast() + self.0(ptr.cast(), size, layout.align(), flags.0, nid.0).cast() }; let ptr = if size == 0 { @@ -160,12 +161,6 @@ unsafe fn realloc_node( flags: Flags, nid: NumaNode, ) -> 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 memory, which was previously // allocated with this `Allocator`. unsafe { ReallocFunc::VREALLOC.call(ptr, layout, old_layout, flags, nid) } @@ -185,12 +180,6 @@ unsafe fn realloc_node( flags: Flags, nid: NumaNode, ) -> Result, AllocError> { - // TODO: Support alignments larger than PAGE_SIZE. - if layout.align() > bindings::PAGE_SIZE { - pr_warn!("KVmalloc does not support alignments larger than PAGE_SIZE yet.\n"); - return Err(AllocError); - } - // SAFETY: If not `None`, `ptr` is guaranteed to point to valid memory, which was previously // allocated with this `Allocator`. unsafe { ReallocFunc::KVREALLOC.call(ptr, layout, old_layout, flags, nid) } -- 2.39.2