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 49FD1C77B7F for ; Thu, 26 Jun 2025 08:36:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2C6D6B00A7; Thu, 26 Jun 2025 04:36:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D038D6B00AA; Thu, 26 Jun 2025 04:36:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C40A46B00AB; Thu, 26 Jun 2025 04:36:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AE9426B00A7 for ; Thu, 26 Jun 2025 04:36:48 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6EFB1104EF8 for ; Thu, 26 Jun 2025 08:36:48 +0000 (UTC) X-FDA: 83596896096.29.A0B0B63 Received: from mailrelay-egress12.pub.mailoutpod2-cph3.one.com (mailrelay-egress12.pub.mailoutpod2-cph3.one.com [46.30.211.187]) by imf19.hostedemail.com (Postfix) with ESMTP id A26CB1A0003 for ; Thu, 26 Jun 2025 08:36:46 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=konsulko.se header.s=rsa1 header.b=WeWVR6F1; dkim=pass header.d=konsulko.se header.s=ed1 header.b=NdjUMegl ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750927006; 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=knXSD5S79O6CdllCbDYQ90STJZQwheeGaY9xHv0HFjs=; b=UCuH8G5OJLmP447K7lHMKRoT7XeSwBBJG5aCLAdsP/WMINiA8DuoqfTLnFIGXjtJ2veglF KQ50OiQcKanAvzkTWIQzCp+FGSdOzFMCGAakRq7/lZn40m6pt/ypZC9s87mbeNx8pQKDuM MJQmadZYCHp7slf/bPmcX+pepdLiGEA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750927006; a=rsa-sha256; cv=none; b=fm4f3SyjU8Asu9X1lixTiJeIKyn98zQwtkQujT43XFjWuFcY6YduGWCP5Mi4iKEVs6bDQ+ brI5JEwaQ5wqQUJIaNUPLPVS6GmVRV+SOqn6XfeDYV/KtKPynfJd7M2XaLebfooMwT0ubs aCsQlMP2e9LBZXUxoMkIF0EUgH3M4NY= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=konsulko.se header.s=rsa1 header.b=WeWVR6F1; dkim=pass header.d=konsulko.se header.s=ed1 header.b=NdjUMegl; spf=none (imf19.hostedemail.com: domain of vitaly.wool@konsulko.se has no SPF policy when checking 46.30.211.187) smtp.mailfrom=vitaly.wool@konsulko.se; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1750927005; x=1751531805; d=konsulko.se; s=rsa1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=knXSD5S79O6CdllCbDYQ90STJZQwheeGaY9xHv0HFjs=; b=WeWVR6F1DZzK9aJJpyYfcIHvevfq/ymYN4+/WB+T2NSKYkVk112r00ki4TkOSV8S4FFOf43Iln9U8 XYzyjXchohDKzwDDgj5taaKCx6fDS/0ezC36rhEka/SidbkcgPrFTxLFk24LDusZfOyCCklwyLOCjj LZ/ZjHTtNvdd2KiZoJaTPt2WlcQgqEARtYRsWZlLjwgUUUF+PWNfYPogid3tWhselQXnEPDdqSOwVE qI6cJwQ+7Wpt+UoJDs0kr1bTPTT8eaSWRTr5M9zKkyfpYTqXGD9NfnT7p65RayVOestCOScj7prnhh F0hFSec7ZmBYJsoobDgb5mhi/7aULwA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1750927005; x=1751531805; d=konsulko.se; s=ed1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=knXSD5S79O6CdllCbDYQ90STJZQwheeGaY9xHv0HFjs=; b=NdjUMegl0YpZPkrK+HYEkoohulFB3JW2aImrbECIF8X6VuzFRs6P7g14qMhgbHaHca8xNKcZYgrJD 1LBOE/FBQ== X-HalOne-ID: aff13161-5268-11f0-bfae-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 aff13161-5268-11f0-bfae-494313b7f784; Thu, 26 Jun 2025 08:36:44 +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 v4 3/4] rust: support large alignments in allocations Date: Thu, 26 Jun 2025 10:36:42 +0200 Message-Id: <20250626083642.3596388-1-vitaly.wool@konsulko.se> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250626083516.3596197-1-vitaly.wool@konsulko.se> References: <20250626083516.3596197-1-vitaly.wool@konsulko.se> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A26CB1A0003 X-Stat-Signature: 7ts15hxg6q9ecbdmc9c39nhz864y7ent X-Rspam-User: X-HE-Tag: 1750927006-218384 X-HE-Meta: U2FsdGVkX1+bwF1OG4ikQSSbRP4n6LfUeyINiyeOXrdld1PMzoTIco4AfhIkIMq7T2O173Fu5hHWwRgvLGiHliNSEOcx2yItqOrAO+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=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 (Kmalloc support for large alignments is limited to the requested size, which is a reasonable limitation anyway). Signed-off-by: Vitaly Wool --- rust/helpers/slab.c | 4 ++-- rust/helpers/vmalloc.c | 4 ++-- rust/kernel/alloc/allocator.rs | 16 ++-------------- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/rust/helpers/slab.c b/rust/helpers/slab.c index a842bfbddcba..5e9e8dd2bba0 100644 --- a/rust/helpers/slab.c +++ b/rust/helpers/slab.c @@ -3,13 +3,13 @@ #include 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 align, gfp_t flags) { return krealloc(objp, new_size, flags); } 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) { return kvrealloc(p, size, flags); } diff --git a/rust/helpers/vmalloc.c b/rust/helpers/vmalloc.c index 80d34501bbc0..4618c0b79283 100644 --- a/rust/helpers/vmalloc.c +++ b/rust/helpers/vmalloc.c @@ -3,7 +3,7 @@ #include void * __must_check __realloc_size(2) -rust_helper_vrealloc(const void *p, size_t size, gfp_t flags) +rust_helper_vrealloc(const void *p, size_t size, unsigned long align, gfp_t flags) { - return vrealloc(p, size, flags); + return vrealloc_node(p, size, align, flags, NUMA_NO_NODE); } diff --git a/rust/kernel/alloc/allocator.rs b/rust/kernel/alloc/allocator.rs index aa2dfa9dca4c..a0d78c497974 100644 --- a/rust/kernel/alloc/allocator.rs +++ b/rust/kernel/alloc/allocator.rs @@ -58,7 +58,7 @@ 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 crate::ffi::c_void, + unsafe extern "C" fn(*const crate::ffi::c_void, usize, usize, u32) -> *mut crate::ffi::c_void, ); impl ReallocFunc { @@ -110,7 +110,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).cast() + self.0(ptr.cast(), size, layout.align(), flags.0).cast() }; let ptr = if size == 0 { @@ -152,12 +152,6 @@ unsafe fn realloc( old_layout: Layout, flags: Flags, ) -> 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) } @@ -176,12 +170,6 @@ unsafe fn realloc( old_layout: Layout, flags: Flags, ) -> 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) } -- 2.39.2