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 99259C54ED1 for ; Sat, 28 Jun 2025 10:26:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3CDA58D0002; Sat, 28 Jun 2025 06:26:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 37E578D0001; Sat, 28 Jun 2025 06:26:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2BB108D0002; Sat, 28 Jun 2025 06:26:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1B7E48D0001 for ; Sat, 28 Jun 2025 06:26:35 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9F3EF1D71EB for ; Sat, 28 Jun 2025 10:26:34 +0000 (UTC) X-FDA: 83604430308.18.826F375 Received: from mailrelay4-3.pub.mailoutpod3-cph3.one.com (mailrelay4-3.pub.mailoutpod3-cph3.one.com [46.30.212.3]) by imf29.hostedemail.com (Postfix) with ESMTP id CA22412000A for ; Sat, 28 Jun 2025 10:26:32 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=konsulko.se header.s=rsa1 header.b=QSZ+lYJi; dkim=pass header.d=konsulko.se header.s=ed1 header.b=NuIaGDGg ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751106393; a=rsa-sha256; cv=none; b=0Vj0mteEuNNpxPtR8STCsbOYqIvCgh4Dvw0PgIGs9rOTYShSLZfGttiK7kPRLmO+yDSqlo EQJtKfL6LRQRcBEg0E0tOv6VVPC7dv8fI8vRtQ684371rR3zf2ng+SWB7Fgd/0J1vjgK6W /Q+h/Ftad1gVH4oVgOrQSxKgeBv2xMQ= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=konsulko.se header.s=rsa1 header.b=QSZ+lYJi; dkim=pass header.d=konsulko.se header.s=ed1 header.b=NuIaGDGg; dmarc=none; spf=none (imf29.hostedemail.com: domain of vitaly.wool@konsulko.se has no SPF policy when checking 46.30.212.3) smtp.mailfrom=vitaly.wool@konsulko.se ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751106393; 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=xlhdGuz/Z+dkJo2xYiSj4xZE1JqckJSK1NBWLMJ0VOE=; b=qLpiJSItHa4Ewxy5SpAsnPsis0mhbtqenlxAcfoF+V8qBMXoWFPjVxFAEMtBHg1uzMIPZw Ubc/7jSTfFUdI2exkSKY8sYR+t2KkfI5tmeEylrjQ6pwwtrEQx4W0V0nJUhXYR76zi8ZYB HtLMpZkcFJ572XxKMXf+uJzaN2TfV1k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1751106390; x=1751711190; d=konsulko.se; s=rsa1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=xlhdGuz/Z+dkJo2xYiSj4xZE1JqckJSK1NBWLMJ0VOE=; b=QSZ+lYJiZSB7Toib+iyiSJ3/SIzdf98oKheYebvFNLbjGPu8zBZE2g7L5gOuiAPO4E7A90ZoPAIJE 6matMIx8TFsgWmyt3HIIySVFKoSE3hkywtECygbxMCT1u67m4QY2GypMiGmblTtgCsMeQ8ujIbkA7B S5hkwzBE+tzBGCsrwxuowfMXp9xzYw+dmrzZLseZo/5C2sFtiHx3ZHe6sqYEBna47HXkgDsI0lqu+F T1f4HsOLmTC0Zrvgi/jjIdZTZa3nuw5JsOeU3tNyf9vX5+TEPvvSYSi+6QuXcuj2a79UU+taGa9zV7 gKsLpnBifkaSwOft3eGF2QRWV1kQXFA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1751106390; x=1751711190; d=konsulko.se; s=ed1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=xlhdGuz/Z+dkJo2xYiSj4xZE1JqckJSK1NBWLMJ0VOE=; b=NuIaGDGgweqG2u/jIxj6mcXd/5JQk5UQSVMztjkrY8ddwsuy+pc/9KcXSDnDjnWYikhdkRmzsvHdj MSJLU5HDg== X-HalOne-ID: 59c0416d-540a-11f0-8548-29b2d794c87d Received: from slottsdator.home (host-90-238-19-233.mobileonline.telia.com [90.238.19.233]) by mailrelay4.pub.mailoutpod3-cph3.one.com (Halon) with ESMTPSA id 59c0416d-540a-11f0-8548-29b2d794c87d; Sat, 28 Jun 2025 10:26:30 +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 v8 4/4] rust: support large alignments in allocations Date: Sat, 28 Jun 2025 12:26:26 +0200 Message-Id: <20250628102626.2542946-1-vitaly.wool@konsulko.se> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250628102315.2542656-1-vitaly.wool@konsulko.se> References: <20250628102315.2542656-1-vitaly.wool@konsulko.se> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: k14454hszrmg4f96bwj9zi55zeptonm5 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: CA22412000A X-Rspam-User: X-HE-Tag: 1751106392-369228 X-HE-Meta: U2FsdGVkX18J6EbHpSIu6zZdQxCiumqdfgq2RIxyc2NwETkJyTJgQqnoDnPLFgmISJTR2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ogofilter, 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 | 28 ++++++++-------------------- 3 files changed, 17 insertions(+), 26 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 2e86e9839a1b..58e5bf78c159 100644 --- a/rust/kernel/alloc/allocator.rs +++ b/rust/kernel/alloc/allocator.rs @@ -59,19 +59,19 @@ 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, crate::ffi::c_int, + *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 /// @@ -113,7 +113,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 { @@ -157,12 +157,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) } @@ -182,12 +176,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