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 11544C71130 for ; Mon, 7 Jul 2025 16:49:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ABD066B0401; Mon, 7 Jul 2025 12:49:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A947C6B0402; Mon, 7 Jul 2025 12:49:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D1DE6B0403; Mon, 7 Jul 2025 12:49:57 -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 89E6F6B0401 for ; Mon, 7 Jul 2025 12:49:57 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 399C0140135 for ; Mon, 7 Jul 2025 16:49:57 +0000 (UTC) X-FDA: 83638055634.19.0FA12C8 Received: from mailrelay-egress16.pub.mailoutpod3-cph3.one.com (mailrelay-egress16.pub.mailoutpod3-cph3.one.com [46.30.212.3]) by imf16.hostedemail.com (Postfix) with ESMTP id 5853318000B for ; Mon, 7 Jul 2025 16:49:55 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=konsulko.se header.s=rsa1 header.b=l9qKFm4l; dkim=pass header.d=konsulko.se header.s=ed1 header.b=i6SzDl3b ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751906995; 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=rzdRn1Qcob7EAGVu1OyPPS40VD+6WTHhgqmTCL9uZC4=; b=MSBe26Nl3HI65BsV3Yt36Qv1PagAEUma+Cii9S++3EVqT1aija5UB1cG5SqV6Hzlfn3OrT BhclhHtrTKePDADVnjh1zrzVyszgLKSXD8XOW2Vt2Nt4ak4cWzhuHfawr+tP/04k7vi6RQ ts6gSPb5KA53UM4g2zoAyqKU/IamlLg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751906995; a=rsa-sha256; cv=none; b=jIfFm0TPJ2qr8BplAdyUc+aH/vsWwR7n1yB2DxxITErD7CYsAbbjWTbu2DkgKrHNJ5oQOk ODQ+nnwoiyAnDCV13ULdOZO9n2mVekRIac6/+lJ0vJwxAKsEs0ES5KJRf9KiEsBMLzFVlO av9b+/gScbQw8eQqt7RsenaFkfo/N2g= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=konsulko.se header.s=rsa1 header.b=l9qKFm4l; dkim=pass header.d=konsulko.se header.s=ed1 header.b=i6SzDl3b; spf=none (imf16.hostedemail.com: domain of vitaly.wool@konsulko.se has no SPF policy when checking 46.30.212.3) smtp.mailfrom=vitaly.wool@konsulko.se; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1751906993; x=1752511793; d=konsulko.se; s=rsa1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=rzdRn1Qcob7EAGVu1OyPPS40VD+6WTHhgqmTCL9uZC4=; b=l9qKFm4ll2ra2a4udIm8cFCGlWUTXylG5roJgFLliEdsO+9vdk8qnIuZphM/oq/9XC5EDj101gkdS YONGQnDyTw0qq192B3Odl4EZeBOSqHxCjQFup5e9enIOKBwoPjDwhk43XqKz/dXE09ReXa+wPMvzo2 L8r1HB/x3I8UI9WgPEB7FAboS40MTx6olBUqJX5DgiZq4DmqqoCGvxAog+GrQlmd5rY4QOT/zR38XE XlZx6O/jfoCQUXWnAHA70B+vZzwK1+o6eMukFdBrnKBYzdmoL21GwZvMTffzfwwlEnce/EIWsZm0lj AXIXQtXk5/SQM1a0Q+GnrGJh1BlGm8Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1751906993; x=1752511793; d=konsulko.se; s=ed1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=rzdRn1Qcob7EAGVu1OyPPS40VD+6WTHhgqmTCL9uZC4=; b=i6SzDl3bE8grLjZMBMXMlOri/TfS7ySO7zaKi0uSTPP378TwuywPnLZh3Jtm5QdJ1PmPBZcbu84Fk VAZ3aDXDA== X-HalOne-ID: 66528b92-5b52-11f0-97e1-494313b7f784 Received: from localhost.localdomain (host-90-238-19-233.mobileonline.telia.com [90.238.19.233]) by mailrelay6.pub.mailoutpod2-cph3.one.com (Halon) with ESMTPSA id 66528b92-5b52-11f0-97e1-494313b7f784; Mon, 07 Jul 2025 16:49:52 +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 , Vlastimil Babka , rust-for-linux@vger.kernel.org, Vitaly Wool Subject: [PATCH v11 4/4] rust: support large alignments in allocations Date: Mon, 7 Jul 2025 18:49:48 +0200 Message-Id: <20250707164948.631563-1-vitaly.wool@konsulko.se> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250707164755.631374-1-vitaly.wool@konsulko.se> References: <20250707164755.631374-1-vitaly.wool@konsulko.se> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 5853318000B X-Stat-Signature: uz35bh7ex9uksuzsh3x6fn6fekj1u9jj X-HE-Tag: 1751906995-652050 X-HE-Meta: U2FsdGVkX18XVGYImmuf1tt2W1PX+WZLMuXSLyDcrIyNRt2Ffu5e53O3zSAAA/17fit+n7pHKSjVPhyhhUb/ob77La8CBJQiYXtuMxV+bd+J947zxSC824fLW51bComN5DyiLk/EkwA6wtjzADtvaaME7zoT4cxaJ6LW3VYkrB4o+Z/NiCPaB7MFwImpQ5p9ZvEVE1QfcxRCHDtJOtyJolru18WWwD0MMSjECgOBjaB9uK5yh+kJ2yNVAfIcQd1NcfmoJw+ufNtymbY3uzAgSThRQPJlL1uU1oZI39quqefGy6Cu73bZXZYkMMV10Dpje2TVzmWSQkcWUq00W/dzZDmQLWuQLiYHb45v5jLPONDdfhPyBtrtz8k8r1hFuuBjkfxzBp570y8K+UKCZpsaiW9b+0Sc8TkLx4KjcgCsdTv0l6R7aWbFXXxN2T8cKWa+8O1ZtjCWWUQVfrBPRuvwarhqCBkTH3cl9bm9Z2+0LNwSRbe/a8bJP6zl9Csdp2RJHZc92gdZR4xyBDgXmMEOBbW20ps8v+LblDnTlakhSd8XF3RRiknRxsENoREq43HfzFwNWHpITfxsVa1WN97rJlNgu6r4Tg49GMJdJ/Jz0dUXNfeOECojn5PwFGLoPoxLIcgNJQBS53uu4GZw1hP7Q55SZ7SNn2LACFzLF3uh35wEyk6LrSU4GYkZbjCUC1UfAK6l1vF/JGweoRJ3QrwzrYz7HZK7ydN374IAgoKeC1hxSdmhETy706hZRADEnxjtgpSB6aKuOm1qEOstPv2TyBULxx+PfZS5rua4MS7XPa4mBehPYArIekfipCA+1aj/lb9ZWZvw7XEXhVgHhNiX/elk4US0VEvYHvob4+F2kb7RsSea33ZgO+mYzy57WGnDvjN466eNbGr1X87TKVxYO+gyMvny7JWf8vJeVTsL821Amm+NzZmWJrxADniyh3CZq3g9vBISqBo86I4fsZD CrbpbFDZ mfiaE53V6fCElWNS4XxJvKH6pCi0eiXQI10QK13KqOP53JSmJySFs9+kfJSG7cR6E4w0bLDtz5WjfLvCr6lY05ZncWeQVLfYDd30smPdDrORhjAYx1YjRybMrA5yqTpt9+HwW 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 7f9f4900da33..2a61372d878d 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( 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( 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