From nobody Mon Oct 6 15:15:51 2025 Received: from forward202d.mail.yandex.net (forward202d.mail.yandex.net [178.154.239.219]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B69A194C86; Sun, 20 Jul 2025 09:55:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753005334; cv=none; b=QHr+HZw7bol9tbrywK8owUDQ+h6Zj6qi0dIOoYYmiqw2Yi6JEn3SEC8Lc+1rs6vKKIPb+D9OsmuQhTrUcW2FfWmd88YxFxXF6qQD5f3xk2hU2hBJ/+/7ALpYHvfoezByc4to5UA4IH/WYpoZJCC8lLxBVGxIef4ke5gXb87rIDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753005334; c=relaxed/simple; bh=WkctRXxzP5UMPWQHUPe1aihz7uhRCVep2tbjby4NWu8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NK3oPy/PpbNBZuiNcrgCgI5K1I44/5hU5x+hehLAnemUDqlhOo8vsO1rnjn2ic8B+ARSGMNPk77w7kmnBgJswPtbjfIYJRVMFmSS2DzSfDQppbsAm95qShdahCSvkfxiIWb6wUw/9INCUYSvcM+MkJ4XNFJPjFsbGDKh2cV318M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=onurozkan.dev; spf=pass smtp.mailfrom=onurozkan.dev; dkim=pass (1024-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b=leUnF6WZ; arc=none smtp.client-ip=178.154.239.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b="leUnF6WZ" Received: from forward102d.mail.yandex.net (forward102d.mail.yandex.net [IPv6:2a02:6b8:c41:1300:1:45:d181:d102]) by forward202d.mail.yandex.net (Yandex) with ESMTPS id 078288AE08; Sun, 20 Jul 2025 12:49:05 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-88.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-88.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:e0cb:0:640:3e34:0]) by forward102d.mail.yandex.net (Yandex) with ESMTPS id 4A7E4C0085; Sun, 20 Jul 2025 12:48:55 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-88.klg.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id emMPSZxMxuQ0-qXoac0t1; Sun, 20 Jul 2025 12:48:54 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onurozkan.dev; s=mail; t=1753004934; bh=nElTx2N3XFovKfeAcDgMHY9SjrcZHcGdMY2vfvVQocA=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=leUnF6WZXVuUzVjrCN4LL64aALukOmc+Bc1MyenHcxzjhkHs1MCWQaM2L0fq3t6x2 0t7wFoa6dh5vZuDJ0i95XAYz8OeARpnG/HVwfT/LYuF02tAV9JQhLQKuxSIgUBDUJp tfCtDqiJPejwsMr3VGPBSUBwg+onegncDOOqTACo= Authentication-Results: mail-nwsmtp-smtp-production-main-88.klg.yp-c.yandex.net; dkim=pass header.i=@onurozkan.dev From: =?UTF-8?q?Onur=20=C3=96zkan?= To: rust-for-linux@vger.kernel.org Cc: dakr@kernel.org, ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, linux-kernel@vger.kernel.org, =?UTF-8?q?Onur=20=C3=96zkan?= Subject: [PATCH v1 1/3] rust: make `allocator::aligned_size` a `const fn` Date: Sun, 20 Jul 2025 12:48:36 +0300 Message-ID: <20250720094838.29530-2-work@onurozkan.dev> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250720094838.29530-1-work@onurozkan.dev> References: <20250720094838.29530-1-work@onurozkan.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Makes `allocator::aligned_size` a `const fn` to allow compile-time evaluation. Signed-off-by: Onur =C3=96zkan Reviewed-by: Alice Ryhl Reviewed-by: Benno Lossin --- rust/kernel/alloc/allocator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/kernel/alloc/allocator.rs b/rust/kernel/alloc/allocator.rs index aa2dfa9dca4c..aa2957fd585b 100644 --- a/rust/kernel/alloc/allocator.rs +++ b/rust/kernel/alloc/allocator.rs @@ -44,7 +44,7 @@ pub struct KVmalloc; /// Returns a proper size to alloc a new object aligned to `new_layout`'s = alignment. -fn aligned_size(new_layout: Layout) -> usize { +const fn aligned_size(new_layout: Layout) -> usize { // Customized layouts from `Layout::from_size_align()` can have size <= align, so pad first. let layout =3D new_layout.pad_to_align(); -- 2.50.0 From nobody Mon Oct 6 15:15:51 2025 Received: from forward101d.mail.yandex.net (forward101d.mail.yandex.net [178.154.239.212]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3047A3E47B; Sun, 20 Jul 2025 09:49:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.212 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753004948; cv=none; b=biN3UXPs/EEwTItOJHsGgx3AdFnHNC1mXtN+BPchDNCcl6U3oZSFMiGmYQMUNLdJKyejcr2iLOVNGB0Qz/eKPF0gJbFSTB68vBbVoh/Uv7bMYQ/9LR0wzlVq8FWiokSv1z6kwASvSF0hIy2HNgGXdgIYRT8dwcbQ4AvaSbhcvX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753004948; c=relaxed/simple; bh=5UZq8o2tZMaz57LTKRhjQIIxekTht7F9HPgjC3yqVmc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cGBmMSv31zIoX2IAkXojAPnlY/0nf90064f4dANRbjO5uVaqpWPwbzFG7N3i6ccoLKOg7wD7bPRQwdVenEFd1aN2KNpDC8BM7uyoZ4ItUVoBYej+0WkH57LBMtE3hSYyTkgZ+eX7+hcAyWDpcrUU9FV77oUJhF/1mr2CQ5SleB0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=onurozkan.dev; spf=pass smtp.mailfrom=onurozkan.dev; dkim=pass (1024-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b=KqHOPbq9; arc=none smtp.client-ip=178.154.239.212 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b="KqHOPbq9" Received: from mail-nwsmtp-smtp-production-main-88.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-88.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:e0cb:0:640:3e34:0]) by forward101d.mail.yandex.net (Yandex) with ESMTPS id 756B6C007C; Sun, 20 Jul 2025 12:48:57 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-88.klg.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id emMPSZxMxuQ0-bzqCHCfc; Sun, 20 Jul 2025 12:48:56 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onurozkan.dev; s=mail; t=1753004936; bh=vWhHrl/YmXwHFiS0lkmPC0s7uWQw+igTRt8CUNSHBf0=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=KqHOPbq9QnyddGfd/giTXc2+ZF+C/vMea6INkthfWjsidae0LlLvXS1G+uhrUhVoG OhqmZ2ur6H5hFmAt3wNfm5wVTNk6JrEBF/J7mM87O5feDh0RxB3gHJq6iIXZXa/sV5 g8oE+c0+j6z7vpcd5A0JZ5zNDC+INkxVC/nMDJ9g= Authentication-Results: mail-nwsmtp-smtp-production-main-88.klg.yp-c.yandex.net; dkim=pass header.i=@onurozkan.dev From: =?UTF-8?q?Onur=20=C3=96zkan?= To: rust-for-linux@vger.kernel.org Cc: dakr@kernel.org, ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, linux-kernel@vger.kernel.org, =?UTF-8?q?Onur=20=C3=96zkan?= Subject: [PATCH v1 2/3] rust: make `ArrayLayout::new_unchecked` a `const fn` Date: Sun, 20 Jul 2025 12:48:37 +0300 Message-ID: <20250720094838.29530-3-work@onurozkan.dev> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250720094838.29530-1-work@onurozkan.dev> References: <20250720094838.29530-1-work@onurozkan.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Makes `ArrayLayout::new_unchecked` a `const fn` to allow compile-time evaluation. Signed-off-by: Onur =C3=96zkan Reviewed-by: Alice Ryhl Reviewed-by: Benno Lossin --- rust/kernel/alloc/layout.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/kernel/alloc/layout.rs b/rust/kernel/alloc/layout.rs index 93ed514f7cc7..52cbf61c4539 100644 --- a/rust/kernel/alloc/layout.rs +++ b/rust/kernel/alloc/layout.rs @@ -80,7 +80,7 @@ pub const fn new(len: usize) -> Result= { /// # Safety /// /// `len` must be a value, for which `len * size_of::() <=3D isize:= :MAX` is true. - pub unsafe fn new_unchecked(len: usize) -> Self { + pub const unsafe fn new_unchecked(len: usize) -> Self { // INVARIANT: By the safety requirements of this function // `len * size_of::() <=3D isize::MAX`. Self { -- 2.50.0 From nobody Mon Oct 6 15:15:51 2025 Received: from forward205d.mail.yandex.net (forward205d.mail.yandex.net [178.154.239.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AFBE1DE3C0; Sun, 20 Jul 2025 09:55:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.216 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753005356; cv=none; b=NnFkZAZOC87gp8sERERODcYtw8RBK+vCP206AOjNzbUUG66pcN7wO+pHqG8COgzCTcv7MrfAHnzlplexzLczisaFc1SGroyDQgwKlsgRTmXt7UM8BPdlZV9AJZh9B2FTdLEC1Q+UVN3xHaVR29Nazkj/G2LzwKC91ZOOtanqllQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753005356; c=relaxed/simple; bh=GFa0YFh7rnF36crYZ8kQlad566/j64nA1pXdu2g/StA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mLA9kBjqtmxEN9Zcpc73kQKe60DmjK8fzIekcSaxe+P3P2PJZa5dt23Lp1LbUYRMcRV/DUga3eau2+1DyhLH0xglK0bcba2GrBHPkZAISIa0AqHI0IGb92FpzuAgOTnUKTW1y/5wS4Ysc/T++argF3OKZav09ZeDVWYR1iRp/LY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=onurozkan.dev; spf=pass smtp.mailfrom=onurozkan.dev; dkim=pass (1024-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b=c8a8UGXM; arc=none smtp.client-ip=178.154.239.216 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b="c8a8UGXM" Received: from forward102d.mail.yandex.net (forward102d.mail.yandex.net [IPv6:2a02:6b8:c41:1300:1:45:d181:d102]) by forward205d.mail.yandex.net (Yandex) with ESMTPS id 10393890AA; Sun, 20 Jul 2025 12:49:07 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-88.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-88.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:e0cb:0:640:3e34:0]) by forward102d.mail.yandex.net (Yandex) with ESMTPS id 8C357C0093; Sun, 20 Jul 2025 12:48:59 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-88.klg.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id emMPSZxMxuQ0-BcJnzjcu; Sun, 20 Jul 2025 12:48:58 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onurozkan.dev; s=mail; t=1753004938; bh=xZmvch/RB2Pm8dA1QtMTs0vcuWppyiPWJBKMFB4UoSQ=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=c8a8UGXMIKhfXy5TBIbNo8NIsy7/e+w0j6q4yaOX5iyKCSR0QsEGzq3yWzMZxwuE8 5hNAMPbv4HbA497L+QrOZyKUoYYIlgbCKihHXQaUkHKYH6s4FHTkUGcCeyi5nJa1KI 376hH/jswNrU7XFy/oK/y38ZDWeDmQVeJjmjAW50= Authentication-Results: mail-nwsmtp-smtp-production-main-88.klg.yp-c.yandex.net; dkim=pass header.i=@onurozkan.dev From: =?UTF-8?q?Onur=20=C3=96zkan?= To: rust-for-linux@vger.kernel.org Cc: dakr@kernel.org, ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, linux-kernel@vger.kernel.org, =?UTF-8?q?Onur=20=C3=96zkan?= Subject: [PATCH v1 3/3] rust: make `kvec::Vec` functions `const fn` Date: Sun, 20 Jul 2025 12:48:38 +0300 Message-ID: <20250720094838.29530-4-work@onurozkan.dev> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250720094838.29530-1-work@onurozkan.dev> References: <20250720094838.29530-1-work@onurozkan.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Makes various `kvec::Vec` functions `const fn` to allow compile-time evaluation. Signed-off-by: Onur =C3=96zkan Reviewed-by: Alice Ryhl Reviewed-by: Benno Lossin --- rust/kernel/alloc/kvec.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs index 1a0dd852a468..af6e2564a194 100644 --- a/rust/kernel/alloc/kvec.rs +++ b/rust/kernel/alloc/kvec.rs @@ -174,7 +174,7 @@ const fn is_zst() -> bool { /// Returns the number of elements that can be stored within the vecto= r without allocating /// additional memory. - pub fn capacity(&self) -> usize { + pub const fn capacity(&self) -> usize { if const { Self::is_zst() } { usize::MAX } else { @@ -184,7 +184,7 @@ pub fn capacity(&self) -> usize { /// Returns the number of elements stored within the vector. #[inline] - pub fn len(&self) -> usize { + pub const fn len(&self) -> usize { self.len } @@ -195,7 +195,7 @@ pub fn len(&self) -> usize { /// - `additional` must be less than or equal to `self.capacity - self= .len`. /// - All elements within the interval [`self.len`,`self.len + additio= nal`) must be initialized. #[inline] - pub unsafe fn inc_len(&mut self, additional: usize) { + pub const unsafe fn inc_len(&mut self, additional: usize) { // Guaranteed by the type invariant to never underflow. debug_assert!(additional <=3D self.capacity() - self.len()); // INVARIANT: By the safety requirements of this method this repre= sents the exact number of @@ -244,7 +244,7 @@ pub fn as_mut_ptr(&mut self) -> *mut T { /// Returns a raw pointer to the vector's backing buffer, or, if `T` i= s a ZST, a dangling raw /// pointer. #[inline] - pub fn as_ptr(&self) -> *const T { + pub const fn as_ptr(&self) -> *const T { self.ptr.as_ptr() } @@ -260,7 +260,7 @@ pub fn as_ptr(&self) -> *const T { /// assert!(!v.is_empty()); /// ``` #[inline] - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.len() =3D=3D 0 } -- 2.50.0