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 07C17C7EE33 for ; Thu, 26 Jun 2025 12:36:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 330EF6B0098; Thu, 26 Jun 2025 08:36:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3073A6B0099; Thu, 26 Jun 2025 08:36:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 244BF6B009A; Thu, 26 Jun 2025 08:36:13 -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 14C686B0098 for ; Thu, 26 Jun 2025 08:36:13 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BF95212096F for ; Thu, 26 Jun 2025 12:36:12 +0000 (UTC) X-FDA: 83597499384.21.F9D9E57 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf10.hostedemail.com (Postfix) with ESMTP id 0D12BC0011 for ; Thu, 26 Jun 2025 12:36:10 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=btwmvuk+; spf=pass (imf10.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750941371; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bqonUSw169jvgHW32pZmtj4fjSgNJeG7i26pExfc5vk=; b=ZNM5Ek7Acx2Nlerah3niOII1MVpmHEWyd2ateG/Rk0VsM7EiRDjY6hPL7lkqF8J9nc9wth 1LWeqDstVpnpXWs1K2stkK81pxagqE/FBj6pVAlV8JL3CsGH1snHUAQ1Y8mlEP82/ltsJk qQIDnkmXdftpNpmAbtEzqUKJkuiOna4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750941371; a=rsa-sha256; cv=none; b=zbtxU2fEureSBMFqYKNNbMySvBDoOIr1aWGqq1zfN6mtKQWPOvxqJaKDOTAtp62EXIV8Na Yce+asch3mq36hQDKU+AhrpoSQ0Ov/YgIXUXHAZjzSiktmRlEQsCuqlZ0vvoWZVj9/TTOq cNwiw6ZkavW3isBUM/QWI/qme9DYeXE= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=btwmvuk+; spf=pass (imf10.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9D34B5C5531; Thu, 26 Jun 2025 12:33:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31622C4CEEB; Thu, 26 Jun 2025 12:36:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750941369; bh=jkStiqdbqvgUGXirSUwGLlQ14O9y2yDoXve1z9ZZLrc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=btwmvuk+bO9gLYGz+YI78oe3GQAdzrtVOFrnJ+7VpTuBgU3XriDWEyFilP20Dfwff RvsOeFtSvwhyAFH2PLYxk+o+bIkHR8htzLZLIBRNjMfT6xF83FWSSIRF43h6er7wfl Zv2vFPY0Pid0UvAH+qL5nX7zzQg3AY+U+g7ihFrfuMjYYkeI9yUrbHVctfA+TBUS+d j51s/34aOiCU4L7TVyEP7uTFRhKRbLDUdzjjFAhtcLzj+XddOI48odU0jumgah7RT7 R7V8nmlbdSFsV8S/7DG6UaN1FxAxuyC6tKVayouA2hSWo4nRUEzAyRAaI3dxYWv0A5 CzyPtIZVWv5pA== Date: Thu, 26 Jun 2025 14:36:05 +0200 From: Danilo Krummrich To: Vitaly Wool Cc: linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Uladzislau Rezki , Alice Ryhl , rust-for-linux@vger.kernel.org Subject: Re: [PATCH v4 3/4] rust: support large alignments in allocations Message-ID: References: <20250626083516.3596197-1-vitaly.wool@konsulko.se> <20250626083642.3596388-1-vitaly.wool@konsulko.se> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250626083642.3596388-1-vitaly.wool@konsulko.se> X-Rspam-User: X-Stat-Signature: 8hg8wqar8y13bdh3jertdhmdm46phccn X-Rspamd-Queue-Id: 0D12BC0011 X-Rspamd-Server: rspam08 X-HE-Tag: 1750941370-105485 X-HE-Meta: U2FsdGVkX1/FZouJtXsgva1s1shhAHTvTWTPxwrkCkYUgG2OTs8JPPNOMs3hN/WxfVXyykGive2IziBdZ/kSq43O1pUu5hReltZ7fYvTCYXVUUSlo7N5YUCUBD/Ngzqjdpj1qQSmh+wwQ+a943Hn7l+SI7fqtc/VBDTqCODIH+QwdVB5kq5koUcZjz2vEJVIOJ4i5aUqhgU2QUBKTfh/8+CXX6mNaQFK++1CM6gZVlaVI5BtMYXsof13uF7huVB75r1YFhl3M98HyS/xXMKtAorLSXIhMfJP//d4K5z18C0t10hMHS8dLpYxT8SUHJ5JkpaQMAYVIpUxUXiEGygQU6Y3Oq07zg0APMzpDnQYxLAawgQiUTObAB9OWLq7SW0WUBzDM/c6h1xHDv05x6qGwXMe//wS7h608oAICJniQ0CUcrBxOpfJ4TI+c8NgHrxPZf7loqbAHpnzwXrA/UvZb96OuRvSkVVk1bbUGeEDc3OeLtWKISH/09j6ESGix7xziKy35v1JJmZOfdHNpQZvnFyP0UC/X3nBRsAADmFjsj9isRAuIRLdnqRrLMTaJFaJAc15MJyYFuMk4jXgu0UKsrqZN8YByObGMFLgTGAaPiLzcOhCzA7XSHukckTyqqpGlg/TqIVOappEqZqyxllROvNMCo6PsJ/OU8LuT1NPPsRR9VOr4bcMNJsdRBcdfRd4yBslrCuILgaYbDnao3pbr8e3yE4PUdywVEq9uHj21tqLNSI2CasS4T8Gr6jHmbigwYJCr/ENmsdQitccoU/Z5UxrGF+Bc6O8iyjsjYu60s9tZ7VVaYN43j1RcTzTVp2zXUHodcc2WhdRRi0Q5Y6YKFFqNVI5H+xhXEfRu6YBsaHJLtID81D5zoCqFNRLjpK4SOOxU9CpF619dfQu2MmRxPpJ4YDTK1TWpH9fNNlXpPT/Jnv4zxExn9MuwHZ7htOThNRCh4sAgort3VlEpcH DiCeAyFW WynVFVgTvUj4gMGHeJo1GuMHr11aca3yxgxo/mxkOyLVJMf7jnXKpd8L+4w3woSVpmcjJmEyCPDbTv9gGv4GRDV1Nnag0xLoqbU2V4QQXOHX8nrtG6KrDZhRxi7UQkslNwsu5+sxnF27+Uf3itGXRRsTVgDbw4NAxUBJ+qRm6rLQivomcxeuO8O0b2wkBKCES08JODyqJwcBcju8KfqeVfwi3muvR5JUa9yXn9XkGS/5PKCXo4Bl7QS8HiKNMVcMnkKe1YtY7sxM4o7mzofe639jGZIzV7WcLh5k9 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: On Thu, Jun 26, 2025 at 10:36:42AM +0200, Vitaly Wool wrote: > 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); > } I think you forgot to add comments explaining why we have the additional discarded align argument. Also please keep those helpers as they are. You can write an identical inline function in Rust that discards the align argument and calls bindings::krealloc, etc. For instance: unsafe extern "C" fn krealloc_align( ptr: *const c_void, size: usize, _align: c_ulong flags: u32, ) -> *mut c_void { bindings::krealloc(ptr, 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); > } Same here, just make this a "real" helper for vrealloc_node() and create a Rust function vrealloc_align() like in the example above. > 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, Should be c_ulong instead of usize. > ); > > 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); > - } Didn't you propose to use VREALLOC if layout.align() > bindings::PAGE_SIZE? > // 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) }