From nobody Fri Oct 3 10:12:42 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1153B2F9C53; Tue, 2 Sep 2025 09:56:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806999; cv=none; b=Mo0H6J12Qkg/JAPFF7M8cyQHbllFYXRyJQKWItLSmQU7KHthKOyZjGcxBZ2T5hbMA9j+MxjPIfdAr8skjT+6wWo4D4HhcOKkro1TEsbGPipn6qdtNHiHe8TM8/98eKXYZ6JOVfYSCfJEPAjcTal/la8fY6UgU5SwCmYeJ/OQMuE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806999; c=relaxed/simple; bh=DnQWptRm6OEtyKtyeEKDg0SEKWvOGMP22Avp/Fwe/FE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mSLjjp+ew7zfhmn8+BjmsB8pHssxGiX9wQrXSK+Jlger9NId+N1jTY9gbH/4ERzgAsCZo/XxhNlnGQCisAUgIcVGZlta4qUo4QeUgwxySxltehn5eg/fhCEN2HeI+hktp7luyfNkxG3SZ+yRjgUJSLUy5AZY2o3zq/UmRAGFdkg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=G/K5XsYw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="G/K5XsYw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9814EC4CEF5; Tue, 2 Sep 2025 09:56:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756806998; bh=DnQWptRm6OEtyKtyeEKDg0SEKWvOGMP22Avp/Fwe/FE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=G/K5XsYwsSlDy0eQzES0lr5HMCwlwYBiRvK/jS/Ac1nr9D9rkG9VC+JoHfiMuv2zZ Vkv18qsHvFKefruzdVlvO19vCHJ/Yt0dqb2uLKSCk53S4w0P+USp8exNoS5/aL0muf jjdspS5fBkFz2JyiZ/wDIum28/+o0XYssRc2mckyAO1co/v8sIfQYJO8IZ33mmOj34 TlNuhWJbpMiy3FJ0P14hc05Zkf8N63NcmvuVgEhn60nPTUcKXCffI4yp6sHDKwVAOS FoD/+p1fL2CdBQqHf/nv7RXThCKHwl30jJlKuW0a4QiAIK1jhNLoAQWH0icHbNmAi+ UYDIbqEq2E8hg== From: Andreas Hindborg Date: Tue, 02 Sep 2025 11:54:55 +0200 Subject: [PATCH v7 01/17] rust: str: normalize imports in `str.rs` 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 Message-Id: <20250902-rnull-up-v6-16-v7-1-b5212cc89b98@kernel.org> References: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> In-Reply-To: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> To: Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe , Breno Leitao Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg , Daniel Almeida X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=931; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=DnQWptRm6OEtyKtyeEKDg0SEKWvOGMP22Avp/Fwe/FE=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBotr75SEkZ/zMMjxiWlubx6xDXiKsLDbKtLyt1b Pg9fCcCt8uJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCaLa++QAKCRDhuBo+eShj d+tUEACgTEeKLSJtbBn4EfAn/gVPBerY8hixSfWNUIUsb+sXCVWVze0QiuJOk0GOd0m1Wtonqvb bi6M6AUcsDeXNrpK3CCddi9DGhvvU4zrQtBgF3OrAonxsS8456B3bsXbGfPkEyB9e9HOiPy2J4d M6Xvzz3pAqYrHRlHF12GZm/96sjYC4t0jannMWis8u7LvCRTf8mPUgGgFj3LRlgWupagm3UcLA+ gM02vavwJB3eFFuiYTgkp+Vff9b2SQbHtpZGyJo5U6cF34J0klHiYYsLGcRd3v70qPzXn4pALrb F0oj7gRJ1qmZnWNeCkGwJ0ILCdIj9hlnBa5cyd6Yijl1yI6sTz3p3gCknsCEskybC1b6d8FunD9 3lYnqU4bKJtPUFsHKeFeqlEHSgFD8SBzrtyJN0sR1qbdHM1XXyG3CVKeQvv1S02t2GxLn6Fmf3c 6w05GpHqA9QYxWI6XhwXFzmQuAdPUyKEf4LXpPXcUWw/j2f37Q5O1zWfVOAMbOxnyGVMdOyJI9E anBXDn9I+2X4VhUVaTAzykqy67gMRIOH2nL3s8HrV28671mHpX3FCgvSXVXyfIzSCOgCfmhHojL REeSCquAemXyRYAxKjPktxipMYSzYzjfv9lDwiYOKmCt80v6zXwZgbKF81ISgF/5a5zcDPj3Mv0 7M299b2FfdhJkCA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Clean up imports in `str.rs`. This makes future code manipulation more manageable. Reviewed-by: Alice Ryhl Reviewed-by: Daniel Almeida Signed-off-by: Andreas Hindborg --- rust/kernel/str.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index 6c892550c0ba..082790b7a621 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -2,12 +2,13 @@ =20 //! String representations. =20 -use crate::alloc::{flags::*, AllocError, KVec}; -use crate::fmt::{self, Write}; +use crate::{ + alloc::{flags::*, AllocError, KVec}, + fmt::{self, Write}, + prelude::*, +}; use core::ops::{self, Deref, DerefMut, Index}; =20 -use crate::prelude::*; - /// Byte string without UTF-8 validity guarantee. #[repr(transparent)] pub struct BStr([u8]); --=20 2.47.2 From nobody Fri Oct 3 10:12:42 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2193B2F361D; Tue, 2 Sep 2025 09:55:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806959; cv=none; b=Nm9d06OoYEwqFuzg+jV7oR/YZCcV/khcFupyTc9XhPjtKT1lgdWSC9eQmYkdkrvuYRZ/2SJPVriAcukv98YRgHQ+8k/TO4rtq/POY4I6ek9xasO+RLAZV8Rcm2iT+q6uKgaHhFW8m0IRqGApnXwfPAMt07SdR4kynMQmBpsUMHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806959; c=relaxed/simple; bh=IrL/8CVvNpNsvWx/imrKJj4WMBwbgrl/umfTbfpllO4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LPwsvdCe+LLnwcOCfqZK2zb/9Cj5oHbf2UH8ViMY3Gj/XVTj06rdaTUe0fYS1sJIzviio25EAV4xpvpTje8tTlSTfTMAL3LVcSkZrCVuyx0nQ9SHJ/PlGyb5jqKaDwgmKtrOyMNeIABRMnum+9fdG9byuRjcSZrSgs1l45YfQZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U9vxmmsC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="U9vxmmsC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 200F7C4CEF7; Tue, 2 Sep 2025 09:55:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756806958; bh=IrL/8CVvNpNsvWx/imrKJj4WMBwbgrl/umfTbfpllO4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=U9vxmmsC3tp+pFf5yW0izGduhGdZ4NKPs5JzudT7ypEEKw6kiPVYQpnnvARuNEx0M SIMpiYKkpzty7UG9ygmycmU2wWUo7Amk8IKiFzPk21EyhgVeE7nSHTlfBB9K90tGu6 LCe7GbC6jhq9r9kEKLp4UgZbfSaylsEpBKm3lvqJ9KTOQkrAv++cuoxo3I2b1/+XDe WAyucytgfyyhOrp590EomvCl0CGyua956IcyefCxVQJLuJseRMzLDWdnaw7A9LY/3p +axzQNl7mQHxTgN9C4F9aS723RZ5bM6EI9leyTmzbd3YtZirGza7/5GFHdmPNVu25Y dZA9XGkIWY6iQ== From: Andreas Hindborg Date: Tue, 02 Sep 2025 11:54:56 +0200 Subject: [PATCH v7 02/17] rust: str: allow `str::Formatter` to format into `&mut [u8]`. 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 Message-Id: <20250902-rnull-up-v6-16-v7-2-b5212cc89b98@kernel.org> References: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> In-Reply-To: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> To: Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe , Breno Leitao Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg , Daniel Almeida X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2390; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=IrL/8CVvNpNsvWx/imrKJj4WMBwbgrl/umfTbfpllO4=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBotr761I3BRpi697BRKP63oG0wjqocLEh0FQTQQ fLGuOvUBJKJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCaLa++gAKCRDhuBo+eShj d1CfEACQ+tDMq+ZwtJ1m3FbP3fXlmgVY/Q47HuQ6Lpaa9c4Y5+9ZPXqp2ngtf4pYJF2ekmZNtwd OF+zVyBnWgXWVFaNs74aEMQvbd689/e+ABSsd0z13xNUkM+jyGMCdKmMKkEWA3XuTtcrZ/exODp 9HDWVdctrnMoW2TmHjIrj/5w33xPbP96dT5yLHFBTvwVAd3a/lMmzdw1ANEduVutIb71g1DvECD tz7IhWRVYQNUGY4JZaI7GLIuVdU7nBNO22TcUQf02pDpSmjhJhncNOJXnVNtC4KB10M++ftrTxs ag8FTxQGKEQmIZXiCbVBjLIXQMx5bSP92AkZnHhrJV4wmXnkpDrQEZ5ZCjLyJ5OjWcsbx6AJ+IY KBhhAgKNQrn0IXCcwSOz7JDkTGmb0s8AK/d0pmelGXYQ6wO/90fJPP2J4GgFA4Vy0VA0MyUCwV9 xBQ3m4y9O+z5gwCjuTwFAgSQsb8W4GZfBCsz333ylsl8MPhgtnKpPrhPBNHCKSTgsPD8pPPiFvZ wuqsVWakUwclEM55NqlX4cIB/3zaj+ok4zgjcvnG14WaEuDEwuTbRgHH6R0JNp5GYfakVFyLKT4 TzXa24a0dzvoz20AA8UNrVL1lUECkiMJdLUvi7wyD+9lfzqJ9HMaBrWSDlJneLmp5fbb/aSq7tO JMXy+LVt0tFDRXQ== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Improve `Formatter` so that it can write to an array or slice buffer. Reviewed-by: Daniel Almeida Reviewed-by: Alice Ryhl Signed-off-by: Andreas Hindborg --- rust/kernel/str.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index 082790b7a621..76632da357a6 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -7,7 +7,10 @@ fmt::{self, Write}, prelude::*, }; -use core::ops::{self, Deref, DerefMut, Index}; +use core::{ + marker::PhantomData, + ops::{self, Deref, DerefMut, Index}, +}; =20 /// Byte string without UTF-8 validity guarantee. #[repr(transparent)] @@ -825,9 +828,9 @@ fn write_str(&mut self, s: &str) -> fmt::Result { /// Allows formatting of [`fmt::Arguments`] into a raw buffer. /// /// Fails if callers attempt to write more than will fit in the buffer. -pub(crate) struct Formatter(RawFormatter); +pub(crate) struct Formatter<'a>(RawFormatter, PhantomData<&'a mut ()>); =20 -impl Formatter { +impl Formatter<'_> { /// Creates a new instance of [`Formatter`] with the given buffer. /// /// # Safety @@ -836,11 +839,19 @@ impl Formatter { /// for the lifetime of the returned [`Formatter`]. pub(crate) unsafe fn from_buffer(buf: *mut u8, len: usize) -> Self { // SAFETY: The safety requirements of this function satisfy those = of the callee. - Self(unsafe { RawFormatter::from_buffer(buf, len) }) + Self(unsafe { RawFormatter::from_buffer(buf, len) }, PhantomData) + } + + /// Create a new [`Self`] instance. + #[expect(dead_code)] + pub(crate) fn new(buffer: &mut [u8]) -> Self { + // SAFETY: `buffer` is valid for writes for the entire length for + // the lifetime of `Self`. + unsafe { Formatter::from_buffer(buffer.as_mut_ptr(), buffer.len())= } } } =20 -impl Deref for Formatter { +impl Deref for Formatter<'_> { type Target =3D RawFormatter; =20 fn deref(&self) -> &Self::Target { @@ -848,7 +859,7 @@ fn deref(&self) -> &Self::Target { } } =20 -impl fmt::Write for Formatter { +impl fmt::Write for Formatter<'_> { fn write_str(&mut self, s: &str) -> fmt::Result { self.0.write_str(s)?; =20 --=20 2.47.2 From nobody Fri Oct 3 10:12:42 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9AA202F3C23; Tue, 2 Sep 2025 09:56:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806968; cv=none; b=aaTt4FQtec9qXiMMAsuzJxjIj4c1u2HCM6KgTvwG8BP+mFUVqsqVi4hmAHDwmJqi0rDkABnsNPaS4JXjG8UIbAb81nLDpfMw3OAwR4J3Yl6RvZoEoPezD/XPgjLSzFCJrLWvragMZJaXVR9pJw38m34tFX4htt7ksFnvQW6tXKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806968; c=relaxed/simple; bh=xhASc7MyrF6ZWmGALrZff+ftLIcqdjV2w4QxOR2K+jQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TgfO1jqQn4v+B4hGMXPLqkR+bxDIKFgY4p6uMTDBWwLrubZUa0hQ8mIjBB3QNL3VecB92K5xabYnU1a8zdilV3PKAIsuRPZuPA+6AFa5wLwsE46pg2hzqNIqns9KkNxc0dFIrKo6nBrlygo+ukUnwI9p79a2l1IKhEoWgO8L+NE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JaiunMUo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JaiunMUo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6B47C4CEED; Tue, 2 Sep 2025 09:56:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756806968; bh=xhASc7MyrF6ZWmGALrZff+ftLIcqdjV2w4QxOR2K+jQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=JaiunMUorhrb9n+7c/+66hbeNwr/l6n5hwYrS+OnG9MKqgcj7xsIsdYeulWNIXR3P jbeEvdrvKL6A6G3r29asxuNtXUE9LsTHkaYOa2R0knDHce6zO8di5iL/tukwXmDO00 7QuVhl9FLixPFSLzWSFZ84l15257PKR+5CpSZMoq980UqtFRrV5lFLUmtm2RTr8eXA ThN7NwNpcMul+m9EfSV+EXL0RrBZlTXl9QmftVCCdxw8+GvUrJEIFtcU4KYf48KcTX jIlPeJHqJsSH45WFASi//3qHZzsrcQ6buee+mrpOhwwGgXaICjBPtiemEy6G0iGU4s tV0lBY739WcLg== From: Andreas Hindborg Date: Tue, 02 Sep 2025 11:54:57 +0200 Subject: [PATCH v7 03/17] rust: str: expose `str::{Formatter, RawFormatter}` publicly. 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 Message-Id: <20250902-rnull-up-v6-16-v7-3-b5212cc89b98@kernel.org> References: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> In-Reply-To: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> To: Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe , Breno Leitao Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg , Daniel Almeida X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2064; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=xhASc7MyrF6ZWmGALrZff+ftLIcqdjV2w4QxOR2K+jQ=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBotr773NZpjhJkGgNmPnNTJA76nsMoe76epzxcg FehD1w1rTeJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCaLa++wAKCRDhuBo+eShj d1M3D/4syDxQdfkxcNkio+Sau7pIerdaNfCa0Zw33/p39M+WuzE9jUHu56w/EE1ZRkd35dpvtQs iTCoqCYog5LVJVgYXR/TwmYjAm4FqQiaUL10W84CdG681SZXQkLqcv87BDIazOWufrKxtJuSRMW WKeMtxk5AJ1s1ggP0/+ITEkRXzRkQ8jpYslogfZNAaLPo5HGXsqvO1bRMYGOfbIhaF8v9zIiNL0 ViDDFaaF+voqQm7o7qSsBKbZNFnSphdAS/Hr75xWO6Y7mhl0RCuS4XwpWh+TR3RrF3oWlDfH0PY MVwBXTR45b6WvD0YHiAIjTGSrUfPooWhX+Houqb+acVrUt5EhiFvRQjhvSRnYNNI6IlS82LdnWZ gBIJ6N723lkjrAywbcZMDc0b7AEa3+Joqmtb45De7wdklFWqAGw8/5NeLndHz1YNyh4rsCmsYrl 26Ca5NUgoR7AHtoOP7gkS/qLwCxNnwsmLQN7lGgvTAFYGIZ9Q/LFUG5mM3Im+WQ5R35Wb9AmQN+ GdZaVu62V+Qa6z+tw0WaK5jpmyDJHXgfWJr2QBJ1OOk1/GB5mNb0wenOBMhzPo//Zd8mFYK+0Oy PJYGvtdOATcJxiueiZuUnIC1NnXdpwm+hOVC8zRzJn5UFFJAwl1WXW0cbm7WJuHkplPz4c05fsK WLvTfAcN5ZKRBQw== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 rnull is going to make use of `str::Formatter` and `str::RawFormatter`, so expose them with public visibility. Reviewed-by: Alice Ryhl Reviewed-by: Daniel Almeida Signed-off-by: Andreas Hindborg --- rust/kernel/str.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index 76632da357a6..46cdc85dad63 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -736,7 +736,7 @@ fn test_bstr_debug() -> Result { /// /// The memory region between `pos` (inclusive) and `end` (exclusive) is v= alid for writes if `pos` /// is less than `end`. -pub(crate) struct RawFormatter { +pub struct RawFormatter { // Use `usize` to use `saturating_*` functions. beg: usize, pos: usize, @@ -794,7 +794,7 @@ pub(crate) fn pos(&self) -> *mut u8 { } =20 /// Returns the number of bytes written to the formatter. - pub(crate) fn bytes_written(&self) -> usize { + pub fn bytes_written(&self) -> usize { self.pos - self.beg } } @@ -828,7 +828,7 @@ fn write_str(&mut self, s: &str) -> fmt::Result { /// Allows formatting of [`fmt::Arguments`] into a raw buffer. /// /// Fails if callers attempt to write more than will fit in the buffer. -pub(crate) struct Formatter<'a>(RawFormatter, PhantomData<&'a mut ()>); +pub struct Formatter<'a>(RawFormatter, PhantomData<&'a mut ()>); =20 impl Formatter<'_> { /// Creates a new instance of [`Formatter`] with the given buffer. @@ -843,8 +843,7 @@ pub(crate) unsafe fn from_buffer(buf: *mut u8, len: usi= ze) -> Self { } =20 /// Create a new [`Self`] instance. - #[expect(dead_code)] - pub(crate) fn new(buffer: &mut [u8]) -> Self { + pub fn new(buffer: &mut [u8]) -> Self { // SAFETY: `buffer` is valid for writes for the entire length for // the lifetime of `Self`. unsafe { Formatter::from_buffer(buffer.as_mut_ptr(), buffer.len())= } --=20 2.47.2 From nobody Fri Oct 3 10:12:42 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2C88F2E5412; Tue, 2 Sep 2025 09:55:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806933; cv=none; b=ChYwRN2KQItbs0gh0pk60HN+zW82gXhB2wKuTsxjAf6JmPfVRuXkDhMboGuy8i7S/EYDEtNJUOud46rsf2D9HcbHIvJaR8sYBT/dsXJSCsCtwmGOMpDA6Z/7oMobQ2ju/fXJuFXlu5Gu+xrkDYYx52fwgcuSxBd+oQU9d5uLeLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806933; c=relaxed/simple; bh=vipqlYY6O+HI8HCAO+GyfEa49mZe/gTyx2DU5+fC7G8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M8lgJyZrK1WPWLVwNQ8g8q84kL25hHbVjdZcvd6TIsleOuF3KKmu7tL6KARrvqwpzgxZ3FyZE6l1mephVIkeiCNmBYQEHV77q5ux7t+wd3oAcP25qwX9x5B266VRGmEDvXonevIxdBcQ6CQrsKaEGhsgIkdU9NvYfjkNLye4kuY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mXGOcorj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mXGOcorj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 908D0C4CEED; Tue, 2 Sep 2025 09:55:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756806932; bh=vipqlYY6O+HI8HCAO+GyfEa49mZe/gTyx2DU5+fC7G8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=mXGOcorjYYunTLKayMB8otxsrtPF++SLHAEYKdc56DJxlBQC+VeaJdPizub/IpUEJ l1vot1Pazn8M8qpRJDhYD5NrDWhmVELGJQcSTROJvBEvXJ8p+82BR7EVDEWts+TUpT M9XF5aq+7dxa9VyVRrNX6aNLaNXefdvsFqI+us4ewxar8a28HyIKsG7RKZz2yh6PFA vfjf9eoMRByxzG7kfXBJxTa6bc/DBvnqkvKcciRSkOVkpS2WLgtv5V/LVifV0e5yV0 1O/HgKqamPWHtb2KaVgAZQvykWLbyiz3BVKQLbpYZIF89T3hd5fzj6G4+11fRC/dJu BdyO/hvolLmbQ== From: Andreas Hindborg Date: Tue, 02 Sep 2025 11:54:58 +0200 Subject: [PATCH v7 04/17] rust: str: introduce `NullTerminatedFormatter` 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 Message-Id: <20250902-rnull-up-v6-16-v7-4-b5212cc89b98@kernel.org> References: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> In-Reply-To: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> To: Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe , Breno Leitao Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg , Daniel Almeida X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2636; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=vipqlYY6O+HI8HCAO+GyfEa49mZe/gTyx2DU5+fC7G8=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBotr78P7RWlhh3LZjfg/zSaOl3/ULIeC8XSBg6R WriczEieiuJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCaLa+/AAKCRDhuBo+eShj d85FD/9lgcr6JFiftAbDoyBrJLly3m8r4Gxt2Y1rZLpBFPLCG+r5kQwX9fbK39HxI53I7Zm4sAh 0aWVuRc3r4S+uXqjhU2rYhrg16aYPnmkjW1HN65R7+o7pyq6QckbaAgViGdsU4ruy+P0OVxZQI9 WWT9G+vNJ4Ezy5l7LQuyEPJlpchoIp99X8gydSvdMSodwdsZVGr6M5ojo0aldqD8GTv1azBdIRK TI6vYztEzfyFEa4FD5Cqy0iAISb3NcPnN2ckaTsVZVtAYrHMo1vTFympTe9QzxA9WOfSspZ4PD6 isyy1CjhdQ4hh3fiIu0SmBGFOvv8XpM+MPOgg1oxkeNmb5VdwaRrZDraHfvyYxXL4xUobkkbVor vJp5MtOfqxydVSSnWpXXD8uDNw49XLbuCrbG/TCh1BbQ5uK6fTxw7CI1MuICFWAmTxlGz6F62FK rgfYuncAxdVa9FZQEphPTmMnX/PkezVopJQT7Rrs2Goziv1vgthnSf9gfKKwTgSrD5kdj1YBAjr bTbh0bi7juPC8zF5QFIWbqsSKiHLqmDGlFtj0cvjEgwLLgK74rdJ1kVjKptQit3Qp2F76IYcHzR W4Ofth99Dl7b2acH6yFnVwKIejGi0m/jdYBAt303ceh4drC7SKdVxUwIWtavQxoiCMe/nFoWt5g 8+3lvBQVNI6tYnQ== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add `NullTerminatedFormatter`, a formatter that writes a null terminated string to an array or slice buffer. Because this type needs to manage the trailing null marker, the existing formatters cannot be used to implement this type. Reviewed-by: Alice Ryhl Reviewed-by: Daniel Almeida Signed-off-by: Andreas Hindborg --- rust/kernel/str.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index 46cdc85dad63..d8326f7bc9c1 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -871,6 +871,55 @@ fn write_str(&mut self, s: &str) -> fmt::Result { } } =20 +/// A mutable reference to a byte buffer where a string can be written int= o. +/// +/// The buffer will be automatically null terminated after the last writte= n character. +/// +/// # Invariants +/// +/// * The first byte of `buffer` is always zero. +/// * The length of `buffer` is at least 1. +pub(crate) struct NullTerminatedFormatter<'a> { + buffer: &'a mut [u8], +} + +impl<'a> NullTerminatedFormatter<'a> { + /// Create a new [`Self`] instance. + #[expect(dead_code)] + pub(crate) fn new(buffer: &'a mut [u8]) -> Option> { + *(buffer.first_mut()?) =3D 0; + + // INVARIANT: + // - We wrote zero to the first byte above. + // - If buffer was not at least length 1, `buffer.first_mut()` wo= uld return None. + Some(Self { buffer }) + } +} + +impl Write for NullTerminatedFormatter<'_> { + fn write_str(&mut self, s: &str) -> fmt::Result { + let bytes =3D s.as_bytes(); + let len =3D bytes.len(); + + // We want space for a zero. By type invariant, buffer length is a= lways at least 1, so no + // underflow. + if len > self.buffer.len() - 1 { + return Err(fmt::Error); + } + + let buffer =3D core::mem::take(&mut self.buffer); + // We break the zero start invariant for a short while. + buffer[..len].copy_from_slice(bytes); + // INVARIANT: We checked above that buffer will have size at least= 1 after this assignment. + self.buffer =3D &mut buffer[len..]; + + // INVARIANT: We write zero to the first byte of the buffer. + self.buffer[0] =3D 0; + + Ok(()) + } +} + /// An owned string that is guaranteed to have exactly one `NUL` byte, whi= ch is at the end. /// /// Used for interoperability with kernel APIs that take C strings. --=20 2.47.2 From nobody Fri Oct 3 10:12:42 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7AD702F747A; Tue, 2 Sep 2025 09:56:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806995; cv=none; b=RDwSAE5/SCN15VB/k/hvsP4e0LZz9y9DrjnoQ2pk2PxYxIbN7mWfBRc8m356Ica6opkzbODhsc07sn+CLhrek+NI+16t09NmaJ0T8UH4+0kbtIJDtLqBUEbyG8Xj4Q9Tvo4toSVK6FQmT19O2/1EU9nppIlapkRz8PJZkkkcwy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806995; c=relaxed/simple; bh=PA2GD1ivE6Vnr85r4kVB0yNi08FXMSJYufL38ad/0LA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ApFoTx/7xPIVYXxslktApje7zM0hv1Qf9QljTDohAkRkW0kEVpW/OMH10105pAomY/H852RVjkeE9WA9B4+w7HsY6ZG8CtWa/kwrw8a5tAkrgOwnlV6SifLzQIlyFRxoVBu1AKxjvwOFDbE9XRP5RbBrewz8dkKugLr3U5iDn0k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m1/R2Qqz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m1/R2Qqz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E18A3C4CEED; Tue, 2 Sep 2025 09:56:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756806995; bh=PA2GD1ivE6Vnr85r4kVB0yNi08FXMSJYufL38ad/0LA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=m1/R2QqzD5hyXp4MZasOnKHRVFrY3nX4WGUqhsZvgxNuIvTRnShMRVIDOJUtLoJou DoV+/7jLgBon4qimx0AkcWwcx1MW6FNJ/6ytcnGSrCXxHvqtIL9sUQVGKPNf05z/YD Qb26bRrnqWcbEt92OC6+CwY6wBWCfzkxHeQ3s3vjY9xWZYQvHgOoHebv43uF7yiuWx JRNdIrxJ1i834VuI/XxS3jgr2ZdVrHrT6YgoqTwbETP9ElBTuiW45ruSyXrn9zINfR h7nGu3ZNlnVdYyoGL0GHTmoKOm1XYDpRIbnG0CAdYx0siNadpCBAKeBDJOeQ60Qw+E t6pCAz1v0jttQ== From: Andreas Hindborg Date: Tue, 02 Sep 2025 11:54:59 +0200 Subject: [PATCH v7 05/17] rust: str: introduce `kstrtobool` function 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 Message-Id: <20250902-rnull-up-v6-16-v7-5-b5212cc89b98@kernel.org> References: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> In-Reply-To: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> To: Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe , Breno Leitao Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg , Daniel Almeida X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4167; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=PA2GD1ivE6Vnr85r4kVB0yNi08FXMSJYufL38ad/0LA=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBotr79HmUgz6G4EBNPl0dxD+hrow3LluSvmaZ7b DUemhcllo6JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCaLa+/QAKCRDhuBo+eShj d7f3EAC4hPem+YJYIxRpY9Smx8FEBMRBSZc6i+RAphuzs2bA5MVN0sGrE7SsNaXNWpp8Mp5hZP4 piq6lWQJGH7WgD56FYlAAWzfYYJxVClE8MRYK5/47hA5Mf0jkvQUeLUoSBvTD/EXdoKTe7OMLwP LQWJclK3CDKw53T+tGgYCw0TYiRXxoWAqMV8bNNbfSAK6TsLa9To8NaKRkX7y/h1gK/LtvQ0WSP jrVNLxIGJv1CuFGwIhJWBABfHN0kuOcbY3YA1R0k2KeDWFO71iIzy3iQnt2hXBY9YnhiKiwTSQx EaqG8XYmeBIivFZPHb/TKUknh94OHCEx1sb2hIyftiaKtyvs+FodCjRFWhrpa9cHPwYiLXzHwHT 8Pl5kew8rW4oNODzqfzZIbAMiqURVpbic9uIABYgnGh3mY8JTh9797SCiQKR51waIEmhY67uYDB pyCsg47gHPhNiBJBiLeMB1q2RFHnHHs6ZCh279spjTo+Ri1CoBsZR1Xx5l9lTDZE56enisp8TKE FzK+8M3/Xyjg71ZqdIM8o5m6/i3RH5Qu6dsL38/xE574jthnCU4fxcvnl78xTCTN6uIcCI8J1z9 wkfGjRwj36z/zwZ3k/PntVEAWG15i/w1NxNvZmxLYFO00iVlboYlaCIbZnULBrZvJYtLiBY63nG 5YrSZc+/LVBO4yQ== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add a Rust wrapper for the kernel's `kstrtobool` function that converts common user inputs into boolean values. Reviewed-by: Daniel Almeida Signed-off-by: Andreas Hindborg Reviewed-by: Alice Ryhl --- rust/kernel/str.rs | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 79 insertions(+) diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index d8326f7bc9c1..d2f9ebc94b75 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -4,6 +4,7 @@ =20 use crate::{ alloc::{flags::*, AllocError, KVec}, + error::{to_result, Result}, fmt::{self, Write}, prelude::*, }; @@ -920,6 +921,84 @@ fn write_str(&mut self, s: &str) -> fmt::Result { } } =20 +/// # Safety +/// +/// - `string` must point to a null terminated string that is valid for re= ad. +unsafe fn kstrtobool_raw(string: *const u8) -> Result { + let mut result: bool =3D false; + + // SAFETY: + // - By function safety requirement, `string` is a valid null-terminat= ed string. + // - `result` is a valid `bool` that we own. + to_result(unsafe { bindings::kstrtobool(string, &mut result) })?; + Ok(result) +} + +/// Convert common user inputs into boolean values using the kernel's `kst= rtobool` function. +/// +/// This routine returns `Ok(bool)` if the first character is one of 'YyTt= 1NnFf0', or +/// \[oO\]\[NnFf\] for "on" and "off". Otherwise it will return `Err(EINVA= L)`. +/// +/// # Examples +/// +/// ``` +/// # use kernel::{c_str, str::kstrtobool}; +/// +/// // Lowercase +/// assert_eq!(kstrtobool(c_str!("true")), Ok(true)); +/// assert_eq!(kstrtobool(c_str!("tr")), Ok(true)); +/// assert_eq!(kstrtobool(c_str!("t")), Ok(true)); +/// assert_eq!(kstrtobool(c_str!("twrong")), Ok(true)); +/// assert_eq!(kstrtobool(c_str!("false")), Ok(false)); +/// assert_eq!(kstrtobool(c_str!("f")), Ok(false)); +/// assert_eq!(kstrtobool(c_str!("yes")), Ok(true)); +/// assert_eq!(kstrtobool(c_str!("no")), Ok(false)); +/// assert_eq!(kstrtobool(c_str!("on")), Ok(true)); +/// assert_eq!(kstrtobool(c_str!("off")), Ok(false)); +/// +/// // Camel case +/// assert_eq!(kstrtobool(c_str!("True")), Ok(true)); +/// assert_eq!(kstrtobool(c_str!("False")), Ok(false)); +/// assert_eq!(kstrtobool(c_str!("Yes")), Ok(true)); +/// assert_eq!(kstrtobool(c_str!("No")), Ok(false)); +/// assert_eq!(kstrtobool(c_str!("On")), Ok(true)); +/// assert_eq!(kstrtobool(c_str!("Off")), Ok(false)); +/// +/// // All caps +/// assert_eq!(kstrtobool(c_str!("TRUE")), Ok(true)); +/// assert_eq!(kstrtobool(c_str!("FALSE")), Ok(false)); +/// assert_eq!(kstrtobool(c_str!("YES")), Ok(true)); +/// assert_eq!(kstrtobool(c_str!("NO")), Ok(false)); +/// assert_eq!(kstrtobool(c_str!("ON")), Ok(true)); +/// assert_eq!(kstrtobool(c_str!("OFF")), Ok(false)); +/// +/// // Numeric +/// assert_eq!(kstrtobool(c_str!("1")), Ok(true)); +/// assert_eq!(kstrtobool(c_str!("0")), Ok(false)); +/// +/// // Invalid input +/// assert_eq!(kstrtobool(c_str!("invalid")), Err(EINVAL)); +/// assert_eq!(kstrtobool(c_str!("2")), Err(EINVAL)); +/// ``` +pub fn kstrtobool(string: &CStr) -> Result { + // SAFETY: + // - The pointer returned by `CStr::as_char_ptr` is guaranteed to be + // null terminated. + // - `string` is live and thus the string is valid for read. + unsafe { kstrtobool_raw(string.as_char_ptr()) } +} + +/// Convert `&[u8]` to `bool` by deferring to [`kernel::str::kstrtobool`]. +/// +/// Only considers at most the first two bytes of `bytes`. +pub fn kstrtobool_bytes(bytes: &[u8]) -> Result { + // `ktostrbool` only considers the first two bytes of the input. + let stack_string =3D [*bytes.first().unwrap_or(&0), *bytes.get(1).unwr= ap_or(&0), 0]; + // SAFETY: `stack_string` is null terminated and it is live on the sta= ck so + // it is valid for read. + unsafe { kstrtobool_raw(stack_string.as_ptr()) } +} + /// An owned string that is guaranteed to have exactly one `NUL` byte, whi= ch is at the end. /// /// Used for interoperability with kernel APIs that take C strings. --=20 2.47.2 From nobody Fri Oct 3 10:12:42 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 142C62EF657; Tue, 2 Sep 2025 09:55:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806944; cv=none; b=dCNoUngCDsa8sWkZrINzekcDI3CBroo6iMdshbmCeoEaHc5yN7q9QCb6x6I1uynC6cKYpjgj3zzYGLGunQAZblsxXHVJDKxhUUYjm661zkVVodnouN8O6pd+7Zxgcu58FXGqwdnzHZ6fU2e3eYIWL82kpQOglQ2QKmb5mjIT3IQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806944; c=relaxed/simple; bh=nwKi1FGptwRfXIELQTuMx2CYoPiscRWnpzAnP5fcCw4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BLJ82vLSFR6qTWu8vwaWxCsn5hSZNZUNc+Zh8aQ6pVzktK5cxbodAMonRBoTmMjznnfGLpRSarqAbdxLx8yJnkqCaVgVBC5YC0w5yQZ2fztuJZ7KlmXepXzagdZnvfLdQU7AnNyEUAHc+UIT0ld35qPnB8H2K1Y1/idW4qC/zU4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HnTiX9CV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HnTiX9CV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78D1DC4CEF5; Tue, 2 Sep 2025 09:55:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756806943; bh=nwKi1FGptwRfXIELQTuMx2CYoPiscRWnpzAnP5fcCw4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HnTiX9CVzwT/BoVDHWh0NnYwjx5NSS7a4yXI5nhM/SfOlp+tMgeVkJ2ZMPBkKUEyN K5r6xxH0otPBBDcL702IREHPQBzm+j71uhC6W/oGcVLiJyFEqWxaPkHiPmbyhVPKgT cVm+ruWWCEj8W2IBGbpHxl0j7mvlIEZYd72s96WslaTUSXf3M8orQjRI7bxnikqtem BzcoEtfYCpLLub9/zeu5sCoF7xq8Khcct6WQTWzw0HbOK7N7yxy8uL9bIr16fAEEJr /0bpHIgKN6BTuE6VoWgtND9xcm9BS0oLHtrxIjNBY4/wPiqnIirE4Ny2RCR7Tv+xQg +6Eq/o4RpgQhQ== From: Andreas Hindborg Date: Tue, 02 Sep 2025 11:55:00 +0200 Subject: [PATCH v7 06/17] rust: configfs: re-export `configfs_attrs` from `configfs` module 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 Message-Id: <20250902-rnull-up-v6-16-v7-6-b5212cc89b98@kernel.org> References: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> In-Reply-To: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> To: Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe , Breno Leitao Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg , Daniel Almeida X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1232; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=nwKi1FGptwRfXIELQTuMx2CYoPiscRWnpzAnP5fcCw4=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBotr7+i+yQ3swVe5U9MLrSxaZg5jxxn784e/SvU q+ylRqmmC+JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCaLa+/gAKCRDhuBo+eShj d3iuD/9L8zSZvRa4HWcj9rN3REcp2gI7x5Z59IyF5rjRNVv+DbZE3RVAmoQutGL4FVjkxHKRPDa oIRP0+w2azN3CS3t+aNNBvsLZ+nSS6q5OCxUo1W523ZrKqBHFAxb1DctxBYTSTKG1IrsIAXDHNA w5yHzibzWChVdBrXz8yZ5aN2av36kCkBJ/4H/JVYRaI7Pa/WVtgCEtieGCeCHOo0x2V5iTTFpLu +UsYONTfZmnSAJEAZJYfxvfaoF6XYHUGEk8EZWTtv0mYnJAVli+tmz0PetzuCGbX6F8oCCi6qk/ QqTGUgO/mwaOYIP+egJJssAsgAuxDVsHEWBDJxtutHiuh9zsCeJ5iTLx8+roTd3G906wvMek9hv T0Qmu/EOsXIkPBIVXY98KjFfez6ajw8rO8LEmJ6Bluke7m3ZvUpyuCDcQXzyc1nWMa/g/4baE5x /mSZIpMwQBevLsv3/zzN6snBmdP5K5T2Q65lEyMomb6meRTvsjohP0ogf4H3trybXBdv5R9P0M4 GmmilFnDOofcZ+lGBb3Zn7u1zpFZ2ZOfFjWwVRnvMZymw+B0+wGEkkRNCLLjMn//by3RBUa0Cyu h6saa7xuDBWCm4UGzhZhxoXymx/vO01V20hkwNsbCRIOlbZ9dNG7t86my99nqxChhCNsH7dSfhx MginnAqqtuuSkbg== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Re-export `configfs_attrs` from `configfs` module, so that users can import the macro from the `configfs` module rather than the root of the `kernel` crate. Also update users to import from the new path. Reviewed-by: Alice Ryhl Reviewed-by: Daniel Almeida Signed-off-by: Andreas Hindborg --- rust/kernel/configfs.rs | 2 ++ samples/rust/rust_configfs.rs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/rust/kernel/configfs.rs b/rust/kernel/configfs.rs index 2736b798cdc6..318a2f073d1c 100644 --- a/rust/kernel/configfs.rs +++ b/rust/kernel/configfs.rs @@ -1039,3 +1039,5 @@ macro_rules! configfs_attrs { }; =20 } + +pub use crate::configfs_attrs; diff --git a/samples/rust/rust_configfs.rs b/samples/rust/rust_configfs.rs index af04bfa35cb2..ad364fb93e53 100644 --- a/samples/rust/rust_configfs.rs +++ b/samples/rust/rust_configfs.rs @@ -5,7 +5,7 @@ use kernel::alloc::flags; use kernel::c_str; use kernel::configfs; -use kernel::configfs_attrs; +use kernel::configfs::configfs_attrs; use kernel::new_mutex; use kernel::page::PAGE_SIZE; use kernel::prelude::*; --=20 2.47.2 From nobody Fri Oct 3 10:12:42 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 307712EFDB7; Tue, 2 Sep 2025 09:56:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806983; cv=none; b=dQzeiTDrPr0y89V6csxNxo4esgXekMmtZrhOEiDw400evFQx5OyR38s07hPep7O+8su2PjkDUpyh170mNIgF6cq3hl9Uw1Z6Jx3XpFjRfvCQQrLzyUenJQ70gkpqIYoADwpro7q+ZlSzLjyjK1EbK6IiD20lREeid81yxDXjtXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806983; c=relaxed/simple; bh=IorSNq8bDFCuUxmsqyPpldQ/kj+0H+QjukXF6SExSLU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fwEjFhpi0YUwcR4aT9Usb0hyKFTEV1UfPVlf7K+Amm/2JxteifmvBN5SYCHvJ0C+5kortv7sUfqTgmqKlF8CDGWbHdlAnVMihJ1XAnkJf3j/go0b7mUfc2Rnq6BHI3oBPTkHYjdUXxRM1xd5FfJrm933YhezzdLXC1BsOz9Jwv0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WL1cnGHE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WL1cnGHE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F368C4CEED; Tue, 2 Sep 2025 09:56:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756806983; bh=IorSNq8bDFCuUxmsqyPpldQ/kj+0H+QjukXF6SExSLU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WL1cnGHEhqQZrPwsVedZEVINUE+NaF37SCoy6A6HhUZq0YRxlUI0+rmM/UuZOtiZf 2i4T7I8RyE+yHhLEBPVO4YntWEWhxyago9wcbk6iOrt0pUx6bc32ANs38oyKw1GQpL U8id0MxX1ljr86B3DDpXEznEJMIsy9S/lsZ79I3fkRpmBqIPaqiAK5UETckuk1+TdL IZDpBnyIFcOrCwuXUCOEBc4eqNg/o+zdFg0u2yK7OZDQlg8inxaz3CnNOvFbqmigOt 1MjQZOIdYPRzqKm7LVTEiIoTfJVssBoDxJiaKv1JgfiI//D2tSXqBk6kZedY6A2vJw P+d0fNaE3n81A== From: Andreas Hindborg Date: Tue, 02 Sep 2025 11:55:01 +0200 Subject: [PATCH v7 07/17] rust: block: normalize imports for `gen_disk.rs` 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 Message-Id: <20250902-rnull-up-v6-16-v7-7-b5212cc89b98@kernel.org> References: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> In-Reply-To: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> To: Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe , Breno Leitao Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg , Daniel Almeida X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1184; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=IorSNq8bDFCuUxmsqyPpldQ/kj+0H+QjukXF6SExSLU=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBotr7/T9AybLo0yTdjc2xqJFr0ZCmIyrcy7GdeA x9Y+8kuTHSJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCaLa+/wAKCRDhuBo+eShj d+YWEACX4L3b5NzVQXiqKxshBZEsO7AjbHqycBhW+Pr/wtbrN+1WnwseqKD3bdq9vUt+jQq3b+j JSDlS8uJvyMApTh4txv0S0WRdGna2xObbNxYjlT+Q9gskFAlmdbnzpyVzoOVHyZkt90J7Yns2/U lCM1BcqOHylBvZl1eh92+2wJnU+DyMxpmyXIxChqFBzzB5k+4rFBmTatB6exvxuY8zu8F066iQX sflZhkKNRBwNbCg1XGBYVLPTiDmchSHGFWIcDdMVh6snTf6vS+CI2AERzDqn0R5oesi+HWbp/Fm rfywLeLysoAJn6HkxcFZgjgAbVrTtE60hSAsV5hcJJUK2AlYrQizwAYSckzt57HGkOXYzUp2Uil 43dfG3cu9gjqx9Upnzur1cK8PwWcMc1LrEmJ8gENsWuidAyzYB7zXG6T6ew5xXmIindHn7TgEBJ gsdIXhOAmeZACsiOJTJ0A7CrgheN0dRg9DXHHJeJt6Y9qWCvUCeIOlkuSHw0m33PYAxyaGzkx7P UGfiDxyxipplsBuJkqNxIpCBjDWObg594tF47Ge5JRWIMw+OYsKOBr2wkrjp6u0p7a553x5M473 xc+0WuWpgYj0WWwyTVbHT/lVIXN83kqdYlAfEPKf6X6KwtL7z8OtIZ5K9P+K/w/IzEmwugYO2so Dlr65RvJzauK6lw== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Clean up the import statements in `gen_disk.rs` to make the code easier to maintain. Reviewed-by: Alice Ryhl Reviewed-by: Daniel Almeida Signed-off-by: Andreas Hindborg --- rust/kernel/block/mq/gen_disk.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_di= sk.rs index cd54cd64ea88..679ee1bb2195 100644 --- a/rust/kernel/block/mq/gen_disk.rs +++ b/rust/kernel/block/mq/gen_disk.rs @@ -5,9 +5,13 @@ //! C header: [`include/linux/blkdev.h`](srctree/include/linux/blkdev.h) //! C header: [`include/linux/blk_mq.h`](srctree/include/linux/blk_mq.h) =20 -use crate::block::mq::{raw_writer::RawWriter, Operations, TagSet}; -use crate::{bindings, error::from_err_ptr, error::Result, sync::Arc}; -use crate::{error, static_lock_class}; +use crate::{ + bindings, + block::mq::{raw_writer::RawWriter, Operations, TagSet}, + error::{self, from_err_ptr, Result}, + static_lock_class, + sync::Arc, +}; use core::fmt::{self, Write}; =20 /// A builder for [`GenDisk`]. --=20 2.47.2 From nobody Fri Oct 3 10:12:42 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A5DB32E5412; Tue, 2 Sep 2025 09:55:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806936; cv=none; b=FPyEsn7e3k4W5+GVwYSPNpHFmxvvz7FJwgr48boZgOMZ1uOLv17dze7k7AUrSSjrTmS85HtxXb3KrF/RnCroA0+WdVVXVVf2skCjoWquw5KECnlI/twYgmk7ypeS8kFZvsRG+K7OsvwsvIi2aNV8P1FFqz01uIh8mqx0SIgDXYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806936; c=relaxed/simple; bh=rOUQXRZ83o80AuQ37m2uEGiiSyGCYlN8hLzAd5IY00A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ctWbPC0Az/OxWSGcMA1zVW+d75u5F8KCYW0BrEjTAyXQxN3iIv2R5KBeJ4moCzbUwI69+a70R9Gm+FIO6ENVCG+KRlv4rL5nW8hEgN+831brg2wH9GEt0A0FK9g3yifhlqloiaMeFucJvkf2Y0b5fNyPIqNBfq6KRcp3DwjJUhU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sc3v+sD7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sc3v+sD7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47129C4CEF5; Tue, 2 Sep 2025 09:55:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756806936; bh=rOUQXRZ83o80AuQ37m2uEGiiSyGCYlN8hLzAd5IY00A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=sc3v+sD76Cfp91bar+8hY2uR2Vll3pz0hhxpiWvWMHa/4fyLD9hZ68YqjeNTAiJ3n rkRj1HfUQgFEO/MxuOlVNDS5Urkz9zxZtKnEqjxFioxafp0Y2kNKoPnDPQ4hayNMFi IXBnH/jnduiZrN8BjVih5Fd6PLg+36rsz3kGWrnJF5vRpE9XsIMuAHhpCl9cKuE8FO WxNZkY9Xwx5T525dhCTVyVR5yTarNENPcdlLng9ndrgVcKl+Gj0C1s9s/MLf3tBEGr 6/ooT17fvibx9xJlXG8eOwzmb6VabtmhQ9D9qZu6Upp68MfzqKUb0pm1IMnF9mWv8b G0HDNCgJlrAww== From: Andreas Hindborg Date: Tue, 02 Sep 2025 11:55:02 +0200 Subject: [PATCH v7 08/17] rust: block: use `NullTerminatedFormatter` 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 Message-Id: <20250902-rnull-up-v6-16-v7-8-b5212cc89b98@kernel.org> References: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> In-Reply-To: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> To: Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe , Breno Leitao Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg , Daniel Almeida X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2961; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=rOUQXRZ83o80AuQ37m2uEGiiSyGCYlN8hLzAd5IY00A=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBotr8A5Ei+YAWjlEujbD5s51yKCLiyheQdKiXgd 4WJLo1hCROJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCaLa/AAAKCRDhuBo+eShj dzUkD/0VhEDq9QT2aNlifacumpaLB2zsg3v2zXvg9bKAAIFZWZBN+txR+cnPpAaz/AdXhty/eBG 5R15sViSwzIKUn4H1FI5/VhBimnj0Th2/4oqszYCH2tvIrrVdmF4cCrl1nCJRrNoMePTKGIV5Et u4cf9xmzgLmdRajLmE96VeV76/qxyyFRlXAVZzUjQ7u2IgxBaZxCnvE4G6IEqHzE1bKfM3Coe/O Ua843TgDUu6D9xCTzy+8ISMFnSdZ4kHCdGbav5WdCyNgKWrc+WfE3W8MF26Bkem0uHyl9Na2b3g gpxfMSrgQyj6nfQm8Pnk5guH+A6QVY2gO/2Y+pp2Fc0ihLFQl0WgVf+vrRh2UVppxEc1s0Ml/OO je6zv8Pw+juxm47//hvsbeY1hW3k1Vbpm0dWBHy//79XtGJw818s1Ms6UJz1ugXEOHpIYXoCsp6 Tzdf8bmIWh1G7uCvoqQPUNa+1eHdsKezNYnVgmwxggcL1MDLeORWQGq+CZ3biWRhlFhWnDMyUh1 +c8mMWQpN0wxK5PfCn81Vphcv516zNODd+n85nSFisbaReBSXRhUAr/kHvmjGeO4cDnncsmXG4Q uh8FDnga+Zl/m09MR/+euCtpcQXlJpmcCrdLcV7X/IjSv3EJSDfnf16h3Qa7tQm2FsIdlYSnCgb 00i47XTSSLv5riQ== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Use the new `NullTerminatedFormatter` to write the name of a `GenDisk` to the name buffer. This new formatter automatically adds a trailing null marker after the written characters, so we don't need to append that at the call site any longer. Reviewed-by: Alice Ryhl Reviewed-by: Daniel Almeida Signed-off-by: Andreas Hindborg --- rust/kernel/block/mq/gen_disk.rs | 12 +++++++----- rust/kernel/block/mq/raw_writer.rs | 1 + rust/kernel/str.rs | 1 - 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_di= sk.rs index 679ee1bb2195..20f1d46c774d 100644 --- a/rust/kernel/block/mq/gen_disk.rs +++ b/rust/kernel/block/mq/gen_disk.rs @@ -7,9 +7,11 @@ =20 use crate::{ bindings, - block::mq::{raw_writer::RawWriter, Operations, TagSet}, + block::mq::{Operations, TagSet}, error::{self, from_err_ptr, Result}, + prelude::*, static_lock_class, + str::NullTerminatedFormatter, sync::Arc, }; use core::fmt::{self, Write}; @@ -143,14 +145,14 @@ pub fn build( // SAFETY: `gendisk` is a valid pointer as we initialized it above unsafe { (*gendisk).fops =3D &TABLE }; =20 - let mut raw_writer =3D RawWriter::from_array( + let mut writer =3D NullTerminatedFormatter::new( // SAFETY: `gendisk` points to a valid and initialized instanc= e. We // have exclusive access, since the disk is not added to the V= FS // yet. unsafe { &mut (*gendisk).disk_name }, - )?; - raw_writer.write_fmt(name)?; - raw_writer.write_char('\0')?; + ) + .ok_or(EINVAL)?; + writer.write_fmt(name)?; =20 // SAFETY: `gendisk` points to a valid and initialized instance of // `struct gendisk`. `set_capacity` takes a lock to synchronize th= is diff --git a/rust/kernel/block/mq/raw_writer.rs b/rust/kernel/block/mq/raw_= writer.rs index 7e2159e4f6a6..0aef55703e71 100644 --- a/rust/kernel/block/mq/raw_writer.rs +++ b/rust/kernel/block/mq/raw_writer.rs @@ -24,6 +24,7 @@ fn new(buffer: &'a mut [u8]) -> Result> { Ok(Self { buffer, pos: 0 }) } =20 + #[expect(dead_code)] pub(crate) fn from_array( a: &'a mut [crate::ffi::c_char; N], ) -> Result> { diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index d2f9ebc94b75..5c74e5f77601 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -886,7 +886,6 @@ pub(crate) struct NullTerminatedFormatter<'a> { =20 impl<'a> NullTerminatedFormatter<'a> { /// Create a new [`Self`] instance. - #[expect(dead_code)] pub(crate) fn new(buffer: &'a mut [u8]) -> Option> { *(buffer.first_mut()?) =3D 0; =20 --=20 2.47.2 From nobody Fri Oct 3 10:12:42 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 60C052EC0A6; Tue, 2 Sep 2025 09:55:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806941; cv=none; b=JzSr0dYpHUofce824auud7HDyNWYk2QL8ukDs+FX1Ezrsu7qCS7euNLhok6C8n1jRuLdyYd4cElb35fErRFb7vDgFvbxJaR35MIrFNNHmYyKgCGIuhQX0NpnL80SncF3N2ZuGGEj9fC70mIKe2+nimae6OzvKTDQRk0XPzyCsXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806941; c=relaxed/simple; bh=Ccx5zgSLlbSIiXofZb52HFU6BY4bx1BMin6k8F+fBLU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iLV9sKM5VqspwaGl5Trzki61OXpatSIxyQ7fDUjvkmRHUf1njCKtX5YpxFZoR2Znr4lfveEiRl1LuNbbyjePPRXkL9gKHukjpGaYgTTk/tHckaHMSlh3pAHWg1opp19BgdwLgeibOBwFsANpiycE+3gN+zatYtBsV4Yx07zVo7Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dxqv/w0i; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dxqv/w0i" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8EC8C4CEED; Tue, 2 Sep 2025 09:55:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756806939; bh=Ccx5zgSLlbSIiXofZb52HFU6BY4bx1BMin6k8F+fBLU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dxqv/w0i80AdDS6EklP0g/qQpG4WtZwrifySVJkOXA7grhyBKrGahzM2ere+UJoZd lCz9/OXd2+xEFOyK12Tn4A4oIM57x1T2UGMj2Uacu2MjXQujjVhTXs+zY8ZYv5orxr 5rnADlpJcSCo5vXyUL7F7Oe1D+9vuMFum7VJoWXGxs5PSR++JEHyG0zmlGVtbvRCTB evjKvFJIFmx7xHQSay3EScLd0hI4IB/llfpqNhp8ZVwUi8igu3qkhB+EIVWVkRImoA 6/joGdNcGxZZgAaiZYbE0ofXPCfpyq7SinD4rsfiNNRlypoBqXH3Y9YXqkVESYdvBx TfSyso/+cemQw== From: Andreas Hindborg Date: Tue, 02 Sep 2025 11:55:03 +0200 Subject: [PATCH v7 09/17] rust: block: remove `RawWriter` 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 Message-Id: <20250902-rnull-up-v6-16-v7-9-b5212cc89b98@kernel.org> References: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> In-Reply-To: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> To: Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe , Breno Leitao Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg , Daniel Almeida X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2507; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=Ccx5zgSLlbSIiXofZb52HFU6BY4bx1BMin6k8F+fBLU=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBotr8BMQQLj0yN+Xma3LafyoSW49KGgCCJaKdiC IwDwwjBIYiJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCaLa/AQAKCRDhuBo+eShj d5GsEACYnYVWaMdu+NvEExxfgA7yFObB0KyUrgg/BaDPSa6ua1f4WumVBsiFzzuJPCo2HbRoIEe Yq3YHs2BHIh0bTnpiIg/kYDPrQmhrE9FXKOiqSBdaZ+7oOinX0/Aj03iqMPGtkR76jYJmEEXVbJ obSgDU+6H23DEBzl6bhenR5qUehP+uoqlCA5TN+AN82jWuOSx4Ol3Lfd/LLBmMeY+m2XTSnD7Vd G66XVLjBm/nXTXAfQTdLLNrSNotg/Yn/+pM5YeOX1g64a5oX7WH+ZrFvE67R1soJjpgXF8WD8iP 3P2DOFO3CfjaggxUfo+ZWBK9k9TLSdLR2xidTiiSD1tw3RYpIv6rLVz5oX0lK2StFpFHHGV9lrB XDx2wmd4FCLW5IEy/OALxmG9F5De7sosplvtJ2V7TBss3q1jDM0BF2aIs227ErmYLtfUw+LalUY nqNNaNwvlK39Dv8BQk4X7ADA//2zVgWRMdhtLJrWI3Ipz3SKjFC09wi6CIhXwZjVFqhm4GwLYQa bxcIet7L5q0lFCm62Zzrp2Oyi5XckvJBkQGL1+zzmr7sz2cOrOftX6D9BCWLbus7GcaGyaAy0/T LmwdDmD839Clj1QIjrQDCGcPo5Emmpngd2v9DRHB8lFjbnvE4j9fVq4gzH8eRFwQJ4/sqSz2MN9 O0iTtuEFY9bwR7g== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 `RawWriter` is now dead code, so remove it. Reviewed-by: Alice Ryhl Reviewed-by: Daniel Almeida Signed-off-by: Andreas Hindborg --- rust/kernel/block/mq.rs | 1 - rust/kernel/block/mq/raw_writer.rs | 56 ----------------------------------= ---- 2 files changed, 57 deletions(-) diff --git a/rust/kernel/block/mq.rs b/rust/kernel/block/mq.rs index 831445d37181..98fa0d6bc8f7 100644 --- a/rust/kernel/block/mq.rs +++ b/rust/kernel/block/mq.rs @@ -89,7 +89,6 @@ =20 pub mod gen_disk; mod operations; -mod raw_writer; mod request; mod tag_set; =20 diff --git a/rust/kernel/block/mq/raw_writer.rs b/rust/kernel/block/mq/raw_= writer.rs deleted file mode 100644 index 0aef55703e71..000000000000 --- a/rust/kernel/block/mq/raw_writer.rs +++ /dev/null @@ -1,56 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 - -use core::fmt::{self, Write}; - -use crate::error::Result; -use crate::prelude::EINVAL; - -/// A mutable reference to a byte buffer where a string can be written int= o. -/// -/// # Invariants -/// -/// `buffer` is always null terminated. -pub(crate) struct RawWriter<'a> { - buffer: &'a mut [u8], - pos: usize, -} - -impl<'a> RawWriter<'a> { - /// Create a new `RawWriter` instance. - fn new(buffer: &'a mut [u8]) -> Result> { - *(buffer.last_mut().ok_or(EINVAL)?) =3D 0; - - // INVARIANT: We null terminated the buffer above. - Ok(Self { buffer, pos: 0 }) - } - - #[expect(dead_code)] - pub(crate) fn from_array( - a: &'a mut [crate::ffi::c_char; N], - ) -> Result> { - Self::new( - // SAFETY: the buffer of `a` is valid for read and write as `u= 8` for - // at least `N` bytes. - unsafe { core::slice::from_raw_parts_mut(a.as_mut_ptr().cast::= (), N) }, - ) - } -} - -impl Write for RawWriter<'_> { - fn write_str(&mut self, s: &str) -> fmt::Result { - let bytes =3D s.as_bytes(); - let len =3D bytes.len(); - - // We do not want to overwrite our null terminator - if self.pos + len > self.buffer.len() - 1 { - return Err(fmt::Error); - } - - // INVARIANT: We are not overwriting the last byte - self.buffer[self.pos..self.pos + len].copy_from_slice(bytes); - - self.pos +=3D len; - - Ok(()) - } -} --=20 2.47.2 From nobody Fri Oct 3 10:12:42 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 916638F49; Tue, 2 Sep 2025 09:56:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806964; cv=none; b=I0cZ8WHccAjx8giIp+MTgxX9TM6AwcmT20yHNSFZpc3Fp3/4zL3cy8xfhUBJEwJxcclEtyLJn4OBb3DUNynj61JH79G8nxMFhqfwfqAiu0tuBc5sFtuiHcu1UOL3gWAzU0zD+oFBEQCunBCZ4SSlE/5Egts1W+gAZcL5DG6nNDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806964; c=relaxed/simple; bh=OfpvNSrrUeZHTWGA2qHRRXa1nwQ1xGGBIsoZwm6M11A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aJXDbMQ2sDOqPrRcBjYepj7MA4V/fH1+v2M1E9aKZOh2byHrqQspGkQ/fMpVy3BFvBsyqC27YTDZ14lkq0iBATo7UzLdPgGpz6PTosTGO40A1+LRcmtJ6ETTFMxRV6KXHpOU/0fzcRbAwrp60Zrv8t/qrkIJ2OVWlnw/oasYBOc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cLe8MisJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cLe8MisJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CA03C4CEED; Tue, 2 Sep 2025 09:55:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756806964; bh=OfpvNSrrUeZHTWGA2qHRRXa1nwQ1xGGBIsoZwm6M11A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=cLe8MisJD8zMRHnHg0kTCgwq+inur4tADPn9jUz4uleXC/7kYiQFEhJYTan82dM28 5lp4r3SZzfaRJllHvKyrF7QztKKvvIyxJvlQ/n8yK6ajd+ZGzLeAr9DS7InKx5CY7t U8F4MQsQQyhNQIcmg6z/gcgKCR8+bOMX0qP1daOv+8NIK/2AduxJCmQGYjEBbSVTgs 8eQnymFmi63PvaNDqcLkrSp0h5btbAI1sw88SkcIc7BT7ztCjeb939tkQjkR1pyUA7 MtQ7+1qWVOHetpBbsVibqSmvMoOFXIOY0oHrc3RDkCNGlx3BhMijC3jJ63GiVLWZtD 4hOdL+x5E9ITw== From: Andreas Hindborg Date: Tue, 02 Sep 2025 11:55:04 +0200 Subject: [PATCH v7 10/17] rust: block: remove trait bound from `mq::Request` definition 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 Message-Id: <20250902-rnull-up-v6-16-v7-10-b5212cc89b98@kernel.org> References: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> In-Reply-To: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> To: Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe , Breno Leitao Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg , Daniel Almeida X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=963; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=OfpvNSrrUeZHTWGA2qHRRXa1nwQ1xGGBIsoZwm6M11A=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBotr8ClyPWiVj9Ma+0aLYhbK9Pr+52/bIFG1Krr h9wNMmQXU+JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCaLa/AgAKCRDhuBo+eShj d4zmD/9u5rY85pIQ+Oq7IeAYvUfbvsK0GBMpf+Aw0lSFWdzJyMNkALE2XOfBtzn9nwVyZhgg6U6 J0aSG35zlQhUToi0EpovoQGjAhO4WLedWpVno66bWi4gWaaamlhDR/zf9vf/cuUCqXk4FpK/9Wi XL3kEV8kg0UnPxzdAnmxV8CeyYZUgMUeqNiEjFWpF0F51zzkrt6bezj4M3OSz762WzOxBrYLuqg tPRkAgkUIIoGiLPe1DG1RtPgmd9qY1yWJZ6oRv2F6uwN4f3h8BhXoGoU7r9oFjnwaH8Z031JkNn 9Xo5jUzi6NrSk6oLxg0v4iMtGHRwfTDi6ZORu93Ow3XDhAlxgKWV/nabIRN2CpOrt7WfJs/uJ7W 6KQ6QTvXJgC4vTwL5HC78Pip+5njaLpu8JvgVJvPOw4ZJEmxop/MZIbuCTr4jcw/TyT9VrbgtWx eHUyHfuhfqjrR7tT6xmbk+ePv+7twwgqP85AkBuHfKvxdrA8arFFZi3rYUelkVyv32TMonNtnZG VQcoad3IqE5hkzKgdbFfPG6gv4SwYY3DStWlRj+Mxktan34Qahqw+DbTiU3tRYoH/kgk5WNKPoB wl9PcNxJFHZjJnYrJlsuVUdGmhyfNKObTmP6leacYVFaPH+hkM2nHAazQNlF/IGji+V4HXhbTUR YOxNdSc3AbbBlyA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Remove the trait bound `T:Operations` from `mq::Request`. The bound is not required, so remove it to reduce complexity. Reviewed-by: Alice Ryhl Reviewed-by: Daniel Almeida Signed-off-by: Andreas Hindborg --- rust/kernel/block/mq/request.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/kernel/block/mq/request.rs b/rust/kernel/block/mq/request= .rs index fefd394f064a..f723d74091c1 100644 --- a/rust/kernel/block/mq/request.rs +++ b/rust/kernel/block/mq/request.rs @@ -53,7 +53,7 @@ /// [`struct request`]: srctree/include/linux/blk-mq.h /// #[repr(transparent)] -pub struct Request(Opaque, PhantomData); +pub struct Request(Opaque, PhantomData); =20 impl Request { /// Create an [`ARef`] from a [`struct request`] pointer. --=20 2.47.2 From nobody Fri Oct 3 10:12:42 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 BF5F32ED873; Tue, 2 Sep 2025 09:55:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806949; cv=none; b=dO29aiE6vtl39Gaqyxn/wssbRwQPhPO27TSqMydMw4hT6GzPmisSc+cuoqF0eYsJveW+DtUyap3ISc60A8hESPkAy1cqLT0EwOL2c1fuH9x1mrmX+ZbcTPdQjECZvxJsJatFWKpLXdkMNImH/ssC2FTAdjbPZrvDqfq119cYAtE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806949; c=relaxed/simple; bh=5CeGT7OlLAwJ+n1eYK2YzNXyyrj/zX7cdxpv5cnx/wQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rLNCLQ98IKiHByi246mzA4Cpfqxmm3abm6D3jgMs2pvsalfL4sBISDn9uRC8zjDgmzJ7T2pcCpFuxKIs9RLMzX6Gy+2iKFv342GMouq94MIsq7nww+iv7qW5Q9UkLJRlruLvJgTQZTGJxncS6jmO0dyxciuX6m4Kr6uXK08FcOw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NGkFaXtD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NGkFaXtD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29F2FC4CEF7; Tue, 2 Sep 2025 09:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756806947; bh=5CeGT7OlLAwJ+n1eYK2YzNXyyrj/zX7cdxpv5cnx/wQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NGkFaXtDYROSoorv26I+Obr4udAKVmi2ap0zcj2jL0QcFzK79pxqlQmB/B8EGe3Oo /klizut9Em/TL+wJJbpURr4c2y8UdHbbCa8qYR8tZ7sPn12INPPVR7yFfrLGUUWO2d +cBEM0NxirQQK8PV9l7Dg38XSg872ik3IucF2BWBjgm1qrZ1uiDrySNpokh7x4FESu R+ih/wG/HGvUGWrs6pItSenoVF4VUc9fAZ03wm0UflCqHgz0KjdhiHiMUWbywKZ3Ct 7oPWNtzomt4Qx+P/g2HqPLaVjEhz13VLtbhHYNic0yGQWdg66HYZ2+gSxutLqVamtU jVP4jOAFkveHQ== From: Andreas Hindborg Date: Tue, 02 Sep 2025 11:55:05 +0200 Subject: [PATCH v7 11/17] rust: block: add block related constants 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 Message-Id: <20250902-rnull-up-v6-16-v7-11-b5212cc89b98@kernel.org> References: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> In-Reply-To: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> To: Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe , Breno Leitao Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg , Daniel Almeida X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1110; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=5CeGT7OlLAwJ+n1eYK2YzNXyyrj/zX7cdxpv5cnx/wQ=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBotr8DpXUlLvBi5GBvjmorCapQWZ7gRCkj5msQP d1SM7HF+R2JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCaLa/AwAKCRDhuBo+eShj d1ghEAChXQKR8qxW7URDo2QAuBfIybQwxVb14/7oblaHobyj4KVlMk7uSkdN8tDSTXR/ciNbYdy S0jS2socVsGdgBNfOtfCzaszz0v7UVWKNcnSPE5WwYat5tu35MWqq44HNrnMyyHuxzxVgjcVJct lyOoBoRblOHRxB7Jppjf+z8Nr2SKYzaK3uIyB0Mfdv8tb+KCYlAuZpR44pD606k6XLZMGvDZ36x zojOqoAuOBx1Oja95XymouwVFpVOm5nGozB3oB5JpxHBUmBA794W/jDQin+2bIkh5NBpb/RUlWs C+knMHYJRdqGMfqKytmoWFselxDpo7aL8T0TgbHTZgK6BNQmmMLD/udhTFeUUdSiGWU3Yyc+CfH 2wC0woMAPDUhykFHZqZMY0NTXUbnDr4Rv1bfCax3nYrb1b8uhJZaIGwGxL7FhXYIuDSe4LyF25n EiQqDkAy+rS7lhm8fS43xcTWSpjdxF4wfgdA7XjIzgUhAWNjx0nm4IUAUZfzCyUAHegJern/UC2 N4dtm3OvLG/Jz/08paLouGomJXDM0DEg7pqRb41914m0HfN8QTDkNy7/u1sBCpi4z3qpU5eweiL jPFcHJPjBQOXG/tMHbmijpV3SHk7G+ljolcRZrfgYdVqLXdc+tSIU3gPSPhrvCETz3+UgofKEnT JgLWOFoxsmov6uA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add a few block subsystem constants to the rust `kernel::block` name space. This makes it easier to access the constants from rust code. Reviewed-by: Alice Ryhl Reviewed-by: Daniel Almeida Signed-off-by: Andreas Hindborg --- rust/kernel/block.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/rust/kernel/block.rs b/rust/kernel/block.rs index 150f710efe5b..32c8d865afb6 100644 --- a/rust/kernel/block.rs +++ b/rust/kernel/block.rs @@ -3,3 +3,16 @@ //! Types for working with the block layer. =20 pub mod mq; + +/// Bit mask for masking out [`SECTOR_SIZE`]. +pub const SECTOR_MASK: u32 =3D bindings::SECTOR_MASK; + +/// Sectors are size `1 << SECTOR_SHIFT`. +pub const SECTOR_SHIFT: u32 =3D bindings::SECTOR_SHIFT; + +/// Size of a sector. +pub const SECTOR_SIZE: u32 =3D bindings::SECTOR_SIZE; + +/// The difference between the size of a page and the size of a sector, +/// expressed as a power of two. +pub const PAGE_SECTORS_SHIFT: u32 =3D bindings::PAGE_SECTORS_SHIFT; --=20 2.47.2 From nobody Fri Oct 3 10:12:42 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 967492F4A09; Tue, 2 Sep 2025 09:56:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806973; cv=none; b=AqXWIREL0Q6MQg5BaBHsvLVrvO7aE/CxAzNW5Zd3N1l7gVuvZYsaxXtjlkcUNfbMr9LZTpO8sl818QMSZkp3buQh7u6mBtip+j+xOm7CK5HwKGgk6cnaoGWHOJPghdUT2oZBNM+sXfDTcq1WtJlpp7Lh5cH6/KNzUjeUAYRiAkA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806973; c=relaxed/simple; bh=pIuBZvrIaCfOxk5R8QT6fU57Jtv4V7ScNiWvZ/2peFE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cBnoZ+KY6Kl1cJ0iH4JKpB4n9G+Fi1ggk9FcV2xDbmxWdJSu/39iFIh/4IxV0PRNZNeo120QuT3TdyT+RZXRG9WFobu6bpAJBH4y3IbjpzJTPtNPIp4u8BMCzAJOmAuQ5vgumHlix3XId7qGwYeTWA283f7j3c+5k9a9tS6aeGI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ndSbxD6i; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ndSbxD6i" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24E3AC4CEED; Tue, 2 Sep 2025 09:56:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756806973; bh=pIuBZvrIaCfOxk5R8QT6fU57Jtv4V7ScNiWvZ/2peFE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ndSbxD6iB3kGoDhL7VTkbdea5vVoNd0p6dev48Q8fxyuMe8Ty8cGWsSQF6Mzg+VIp 8+MBB/v+2eG6MInm8UuSzx0sKHVFDDwtK7ush1EBrI263F7FO2mp9jTgRqTUP8As79 9rqd9YssJMdsqj8u2m/D8KLFdGuqhyxWwq2JSM2TyVvqYeySmEUZ7V4c9Oz0uuSq9I 42JRHu0Bwuz3YWm894t9UIqdpNSGMk5jsUqWrDNEN2SyBAfdAUTDXRJOlfEvAJvySz h8zz7yiwp34Z3vdt1QvFi6tu9xj0AVid1v3nNfTpreIwtjT4agOVkjjFBkQ/TJxJr7 G6D3zBKH36+Mw== From: Andreas Hindborg Date: Tue, 02 Sep 2025 11:55:06 +0200 Subject: [PATCH v7 12/17] rnull: move driver to separate directory 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 Message-Id: <20250902-rnull-up-v6-16-v7-12-b5212cc89b98@kernel.org> References: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> In-Reply-To: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> To: Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe , Breno Leitao Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg , Daniel Almeida X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3780; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=pIuBZvrIaCfOxk5R8QT6fU57Jtv4V7ScNiWvZ/2peFE=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBotr8EMrtCGQJaSfg5FNjqv7eu4cedktkAzfTYV udhcYHI2NmJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCaLa/BAAKCRDhuBo+eShj dyykEACyYN9nV7NnY266IMC+HwV7lYYDnvjpQEPehKkSbW9IGOMntwX4Izin3vdqj9UnDPgtxqr qMcw/h7owGs4zx3GgQBSR/2myqRbuVGsgazSCzAZ8hZ1D/7BUBPbYO7WOEzrEn7qc9typ2Hq/vx xd10lirFdV5Ujs5LaEMv1cucK225LWL9bF6aelykSmkLZsejXsFOpNiLS9J8nCXwSi9o38Ph8+u lEQ8Q8Gjv3ZgL2yF3aiBcjJSwPwJj1h6t1P6GwA+kmaVmVwsjfjsxpiTNrWFf0eYDVMgxnDLHGC n/6/T5JmuTq6ckh/qChmOr0Ute5Dnlcitmj/HIOaeebKbmy9gtxh9LHP4hnjC8KmVpAbHP2RTLB HYerZRE0IeialIemkc8cKwjwow/LL2Maht53Xk7831JQm1WTQrSvCOrOHD2MUS8qWOMn81tcS+r H8vd9KLb7kNI5ryBRS4fj9obzsGEIAXz1r6qyZQTLw7sYtryEBvt9JsTNiyahV8WgYnVCbBtrlE NNpz1XA4Lo0jk38eCMA7bmpbDxuEb3arDjzNf8FjEVwh87EJ+6kU3Q6zlTEOvImidg7/aLOCa8A 49Q5yehIuQheUPJtWFaO70YhgkuSXC+VONq8WcA8pNogcD1+QEQ/gP6fsYiStl7dsd+sFzlQkUx f53psD4978/5IAA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 The rust null block driver is about to gain some additional modules. Rather than pollute the current directory, move the driver to a subdirectory. Reviewed-by: Alice Ryhl Reviewed-by: Daniel Almeida Signed-off-by: Andreas Hindborg --- MAINTAINERS | 2 +- drivers/block/Kconfig | 10 +--------- drivers/block/Makefile | 4 +--- drivers/block/rnull/Kconfig | 13 +++++++++++++ drivers/block/rnull/Makefile | 3 +++ drivers/block/{ =3D> rnull}/rnull.rs | 0 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index daf520a13bdf..d5addcc4b132 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4343,7 +4343,7 @@ W: https://rust-for-linux.com B: https://github.com/Rust-for-Linux/linux/issues C: https://rust-for-linux.zulipchat.com/#narrow/stream/Block T: git https://github.com/Rust-for-Linux/linux.git rust-block-next -F: drivers/block/rnull.rs +F: drivers/block/rnull/ F: rust/kernel/block.rs F: rust/kernel/block/ =20 diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig index df38fb364904..77d694448990 100644 --- a/drivers/block/Kconfig +++ b/drivers/block/Kconfig @@ -17,6 +17,7 @@ menuconfig BLK_DEV if BLK_DEV =20 source "drivers/block/null_blk/Kconfig" +source "drivers/block/rnull/Kconfig" =20 config BLK_DEV_FD tristate "Normal floppy disk support" @@ -311,15 +312,6 @@ config VIRTIO_BLK This is the virtual block driver for virtio. It can be used with QEMU based VMMs (like KVM or Xen). Say Y or M. =20 -config BLK_DEV_RUST_NULL - tristate "Rust null block driver (Experimental)" - depends on RUST - help - This is the Rust implementation of the null block driver. For now it - is only a minimal stub. - - If unsure, say N. - config BLK_DEV_RBD tristate "Rados block device (RBD)" depends on INET && BLOCK diff --git a/drivers/block/Makefile b/drivers/block/Makefile index a695ce74ef22..2d8096eb8cdf 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -9,9 +9,6 @@ # needed for trace events ccflags-y +=3D -I$(src) =20 -obj-$(CONFIG_BLK_DEV_RUST_NULL) +=3D rnull_mod.o -rnull_mod-y :=3D rnull.o - obj-$(CONFIG_MAC_FLOPPY) +=3D swim3.o obj-$(CONFIG_BLK_DEV_SWIM) +=3D swim_mod.o obj-$(CONFIG_BLK_DEV_FD) +=3D floppy.o @@ -38,6 +35,7 @@ obj-$(CONFIG_ZRAM) +=3D zram/ obj-$(CONFIG_BLK_DEV_RNBD) +=3D rnbd/ =20 obj-$(CONFIG_BLK_DEV_NULL_BLK) +=3D null_blk/ +obj-$(CONFIG_BLK_DEV_RUST_NULL) +=3D rnull/ =20 obj-$(CONFIG_BLK_DEV_UBLK) +=3D ublk_drv.o obj-$(CONFIG_BLK_DEV_ZONED_LOOP) +=3D zloop.o diff --git a/drivers/block/rnull/Kconfig b/drivers/block/rnull/Kconfig new file mode 100644 index 000000000000..6dc5aff96bf4 --- /dev/null +++ b/drivers/block/rnull/Kconfig @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Rust null block device driver configuration + +config BLK_DEV_RUST_NULL + tristate "Rust null block driver (Experimental)" + depends on RUST + help + This is the Rust implementation of the null block driver. Like + the C version, the driver allows the user to create virutal block + devices that can be configured via various configuration options. + + If unsure, say N. diff --git a/drivers/block/rnull/Makefile b/drivers/block/rnull/Makefile new file mode 100644 index 000000000000..11cfa5e615dc --- /dev/null +++ b/drivers/block/rnull/Makefile @@ -0,0 +1,3 @@ + +obj-$(CONFIG_BLK_DEV_RUST_NULL) +=3D rnull_mod.o +rnull_mod-y :=3D rnull.o diff --git a/drivers/block/rnull.rs b/drivers/block/rnull/rnull.rs similarity index 100% rename from drivers/block/rnull.rs rename to drivers/block/rnull/rnull.rs --=20 2.47.2 From nobody Fri Oct 3 10:12:42 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3D2772F1FCD; Tue, 2 Sep 2025 09:55:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806951; cv=none; b=AqaXyG+H7/LqZHLlkoFaNCVB3321EnLvXrkpdcsKaHURBT6YI3/STc9SehaEtcgEgqZ8reoCjryLlJxmdbL/ouEkSKXdj/zDN+ShDWjgmzY3nLTQvjY9QXAWhAFofEyGOetiLww6CsUl1J6WeIaS6vhv+KI3zxEBW3UBnZW0T3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806951; c=relaxed/simple; bh=fPtLqPDGStsMXbu60xANaWKwVC7jEMMSV/rPKwvnnWs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uxj9UK4Ulw0eHnIwDRUKT1sjV3HIwaqA/EM5as+0vapY2kU5E2gk+83HTw/WF9B6Ejd0hCtc6L5SIpmqygmB/ra7CIJycdnlYmAU2Tc0GkWUqO1G/wFnuJewz9EB7CQgnkvTUx4snzFQqI0/Hd6K3HBDlq9qg8cANXv5rNfzB0Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LyRyQTd5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LyRyQTd5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D87C8C4CEED; Tue, 2 Sep 2025 09:55:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756806950; bh=fPtLqPDGStsMXbu60xANaWKwVC7jEMMSV/rPKwvnnWs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LyRyQTd5T6Wle3MmyKyXP+17NWFoGzS2lAERi2pUecgpR45KymNoD72/Use7BmCyH LQqJD3Mx4m502vaLKgGqq9FNhOxRD3M5rx5UAS7IZhcrQ2SffOj+U2/MCm9YTTz7xt aWlXOVkqGUTryDSTSCqK63DjqVJrb56jLmOsFItZyKTUvZj9P9Jw+MFRCJvl8BTyxj p98Ic+R80CgK0N3u1L7dFe/gMA6Q48YjoeaXoFIPuZFjUBQsNxUvTe6DP6Hw+N6H3+ VlNqp0X2bF0ZvqQeX8bcOiKf4WpmYBpqNQOSeHwexa+CRxAX9VuVnyy1b5f9MTyFuK eIgqPKp1ExDxA== From: Andreas Hindborg Date: Tue, 02 Sep 2025 11:55:07 +0200 Subject: [PATCH v7 13/17] rnull: enable configuration via `configfs` 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 Message-Id: <20250902-rnull-up-v6-16-v7-13-b5212cc89b98@kernel.org> References: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> In-Reply-To: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> To: Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe , Breno Leitao Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg , Daniel Almeida X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=10609; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=fPtLqPDGStsMXbu60xANaWKwVC7jEMMSV/rPKwvnnWs=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBotr8FyuToaKcvyBqHvnv+l/O0AuUSsgJLPdAa2 de7guT4pWKJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCaLa/BQAKCRDhuBo+eShj d/jqD/9XU1SLZsKQeFDo+H8Uc5JZ2lZ01GWtIasmmKqamRB1E9//SNoQz1BV9HAu39Me2YNkA6v S+gtA7Iwp74qRGNkQMUdB+lIUBwP0yTtgqw7s3QB35MY1S/ZpR70L3UKSzahjSwmbG561KH6rAc 0g4cEtCTADBO6jybNO/kkSXeeJ9HW0oJ7YTmtlqDklX7caGjSGX4LFTmGi8oVrt09iNY5uSPWCW e5hgd6XAuesMF1SR949z7BW9PpQxSYx8lsx1uKA9H3Ynxj6wDGdX33TQ+h4q/Q5dYjv7bFG130h yOZdsETZV8I0YNtrAN6/aS+wGuVDkU6lNwmkVTviOohUb4ytiovcE0h9dM+D/sOzTW/z06y74AT uSqF5+xugGG8Rv9TDN9OTbYctpnHK/NA22RqXG997hUfLs4KFubxtVLh7xKgUGoX+hBbEXKlToX KKKqzm4OMdjrlAgV6a7bfUh+xb7t0RYaUcODwv/nzkMU5vkCxE4iGMv6rjplbb1mBqAouusTewa Yir/37aXUlCRO4Rn+tXTi3qOhVMx0M8x0zGxZn8J4/y/k8S5aHAFMjVIvQ3vYXQcgrvIyGAyt+L TiP2fq3lU5scPrs/+wZ63Tplf/Mm1RDu1cMbTagLZsj5/40Ue+rwW1zdC6jdQtuRqZULPTalhDC iO9m8c/i7vRBkYg== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow rust null block devices to be configured and instantiated via `configfs`. Reviewed-by: Daniel Almeida Reviewed-by: Alice Ryhl Signed-off-by: Andreas Hindborg --- drivers/block/rnull/Kconfig | 2 +- drivers/block/rnull/configfs.rs | 207 +++++++++++++++++++++++++++++++++++= ++++ drivers/block/rnull/rnull.rs | 59 +++++------ rust/kernel/block/mq/gen_disk.rs | 2 +- 4 files changed, 240 insertions(+), 30 deletions(-) diff --git a/drivers/block/rnull/Kconfig b/drivers/block/rnull/Kconfig index 6dc5aff96bf4..7bc5b376c128 100644 --- a/drivers/block/rnull/Kconfig +++ b/drivers/block/rnull/Kconfig @@ -4,7 +4,7 @@ =20 config BLK_DEV_RUST_NULL tristate "Rust null block driver (Experimental)" - depends on RUST + depends on RUST && CONFIGFS_FS help This is the Rust implementation of the null block driver. Like the C version, the driver allows the user to create virutal block diff --git a/drivers/block/rnull/configfs.rs b/drivers/block/rnull/configfs= .rs new file mode 100644 index 000000000000..46710a1e1af4 --- /dev/null +++ b/drivers/block/rnull/configfs.rs @@ -0,0 +1,207 @@ +// SPDX-License-Identifier: GPL-2.0 + +use super::{NullBlkDevice, THIS_MODULE}; +use core::fmt::Write; +use kernel::{ + block::mq::gen_disk::{GenDisk, GenDiskBuilder}, + c_str, + configfs::{self, AttributeOperations}, + configfs_attrs, new_mutex, + page::PAGE_SIZE, + prelude::*, + str::{kstrtobool_bytes, CString}, + sync::Mutex, +}; +use pin_init::PinInit; + +pub(crate) fn subsystem() -> impl PinInit, Error> { + let item_type =3D configfs_attrs! { + container: configfs::Subsystem, + data: Config, + child: DeviceConfig, + attributes: [ + features: 0, + ], + }; + + kernel::configfs::Subsystem::new(c_str!("rnull"), item_type, try_pin_i= nit!(Config {})) +} + +#[pin_data] +pub(crate) struct Config {} + +#[vtable] +impl AttributeOperations<0> for Config { + type Data =3D Config; + + fn show(_this: &Config, page: &mut [u8; PAGE_SIZE]) -> Result { + let mut writer =3D kernel::str::Formatter::new(page); + writer.write_str("blocksize,size,rotational\n")?; + Ok(writer.bytes_written()) + } +} + +#[vtable] +impl configfs::GroupOperations for Config { + type Child =3D DeviceConfig; + + fn make_group( + &self, + name: &CStr, + ) -> Result, Error>> { + let item_type =3D configfs_attrs! { + container: configfs::Group, + data: DeviceConfig, + attributes: [ + // Named for compatibility with C null_blk + power: 0, + blocksize: 1, + rotational: 2, + size: 3, + ], + }; + + Ok(configfs::Group::new( + name.try_into()?, + item_type, + // TODO: cannot coerce new_mutex!() to impl PinInit<_, Error>,= so put mutex inside + try_pin_init!( DeviceConfig { + data <- new_mutex!(DeviceConfigInner { + powered: false, + block_size: 4096, + rotational: false, + disk: None, + capacity_mib: 4096, + name: name.try_into()?, + }), + }), + )) + } +} + +#[pin_data] +pub(crate) struct DeviceConfig { + #[pin] + data: Mutex, +} + +#[pin_data] +struct DeviceConfigInner { + powered: bool, + name: CString, + block_size: u32, + rotational: bool, + capacity_mib: u64, + disk: Option>, +} + +#[vtable] +impl configfs::AttributeOperations<0> for DeviceConfig { + type Data =3D DeviceConfig; + + fn show(this: &DeviceConfig, page: &mut [u8; PAGE_SIZE]) -> Result { + let mut writer =3D kernel::str::Formatter::new(page); + + if this.data.lock().powered { + writer.write_str("1\n")?; + } else { + writer.write_str("0\n")?; + } + + Ok(writer.bytes_written()) + } + + fn store(this: &DeviceConfig, page: &[u8]) -> Result { + let power_op =3D kstrtobool_bytes(page)?; + let mut guard =3D this.data.lock(); + + if !guard.powered && power_op { + guard.disk =3D Some(NullBlkDevice::new( + &guard.name, + guard.block_size, + guard.rotational, + guard.capacity_mib, + )?); + guard.powered =3D true; + } else if guard.powered && !power_op { + drop(guard.disk.take()); + guard.powered =3D false; + } + + Ok(()) + } +} + +#[vtable] +impl configfs::AttributeOperations<1> for DeviceConfig { + type Data =3D DeviceConfig; + + fn show(this: &DeviceConfig, page: &mut [u8; PAGE_SIZE]) -> Result { + let mut writer =3D kernel::str::Formatter::new(page); + writer.write_fmt(fmt!("{}\n", this.data.lock().block_size))?; + Ok(writer.bytes_written()) + } + + fn store(this: &DeviceConfig, page: &[u8]) -> Result { + if this.data.lock().powered { + return Err(EBUSY); + } + + let text =3D core::str::from_utf8(page)?.trim(); + let value =3D text.parse::().map_err(|_| EINVAL)?; + + GenDiskBuilder::validate_block_size(value)?; + this.data.lock().block_size =3D value; + Ok(()) + } +} + +#[vtable] +impl configfs::AttributeOperations<2> for DeviceConfig { + type Data =3D DeviceConfig; + + fn show(this: &DeviceConfig, page: &mut [u8; PAGE_SIZE]) -> Result { + let mut writer =3D kernel::str::Formatter::new(page); + + if this.data.lock().rotational { + writer.write_str("1\n")?; + } else { + writer.write_str("0\n")?; + } + + Ok(writer.bytes_written()) + } + + fn store(this: &DeviceConfig, page: &[u8]) -> Result { + if this.data.lock().powered { + return Err(EBUSY); + } + + this.data.lock().rotational =3D kstrtobool_bytes(page)?; + + Ok(()) + } +} + +#[vtable] +impl configfs::AttributeOperations<3> for DeviceConfig { + type Data =3D DeviceConfig; + + fn show(this: &DeviceConfig, page: &mut [u8; PAGE_SIZE]) -> Result { + let mut writer =3D kernel::str::Formatter::new(page); + writer.write_fmt(fmt!("{}\n", this.data.lock().capacity_mib))?; + Ok(writer.bytes_written()) + } + + fn store(this: &DeviceConfig, page: &[u8]) -> Result { + if this.data.lock().powered { + return Err(EBUSY); + } + + let text =3D core::str::from_utf8(page)?.trim(); + let value =3D text.parse::().map_err(|_| EINVAL)?; + + this.data.lock().capacity_mib =3D value; + Ok(()) + } +} diff --git a/drivers/block/rnull/rnull.rs b/drivers/block/rnull/rnull.rs index d07e76ae2c13..8690ff5f974f 100644 --- a/drivers/block/rnull/rnull.rs +++ b/drivers/block/rnull/rnull.rs @@ -1,28 +1,25 @@ // SPDX-License-Identifier: GPL-2.0 =20 //! This is a Rust implementation of the C null block driver. -//! -//! Supported features: -//! -//! - blk-mq interface -//! - direct completion -//! - block size 4k -//! -//! The driver is not configurable. + +mod configfs; =20 use kernel::{ - alloc::flags, - block::mq::{ + block::{ self, - gen_disk::{self, GenDisk}, - Operations, TagSet, + mq::{ + self, + gen_disk::{self, GenDisk}, + Operations, TagSet, + }, }, error::Result, - new_mutex, pr_info, + pr_info, prelude::*, - sync::{Arc, Mutex}, + sync::Arc, types::ARef, }; +use pin_init::PinInit; =20 module! { type: NullBlkModule, @@ -35,33 +32,39 @@ #[pin_data] struct NullBlkModule { #[pin] - _disk: Mutex>, + configfs_subsystem: kernel::configfs::Subsystem, } =20 impl kernel::InPlaceModule for NullBlkModule { fn init(_module: &'static ThisModule) -> impl PinInit { pr_info!("Rust null_blk loaded\n"); =20 - // Use a immediately-called closure as a stable `try` block - let disk =3D /* try */ (|| { - let tagset =3D Arc::pin_init(TagSet::new(1, 256, 1), flags::GF= P_KERNEL)?; - - gen_disk::GenDiskBuilder::new() - .capacity_sectors(4096 << 11) - .logical_block_size(4096)? - .physical_block_size(4096)? - .rotational(false) - .build(format_args!("rnullb{}", 0), tagset) - })(); - try_pin_init!(Self { - _disk <- new_mutex!(disk?, "nullb:disk"), + configfs_subsystem <- configfs::subsystem(), }) } } =20 struct NullBlkDevice; =20 +impl NullBlkDevice { + fn new( + name: &CStr, + block_size: u32, + rotational: bool, + capacity_mib: u64, + ) -> Result> { + let tagset =3D Arc::pin_init(TagSet::new(1, 256, 1), GFP_KERNEL)?; + + gen_disk::GenDiskBuilder::new() + .capacity_sectors(capacity_mib << (20 - block::SECTOR_SHIFT)) + .logical_block_size(block_size)? + .physical_block_size(block_size)? + .rotational(rotational) + .build(fmt!("{}", name.to_str()?), tagset) + } +} + #[vtable] impl Operations for NullBlkDevice { #[inline(always)] diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_di= sk.rs index 20f1d46c774d..6b1b846874db 100644 --- a/rust/kernel/block/mq/gen_disk.rs +++ b/rust/kernel/block/mq/gen_disk.rs @@ -51,7 +51,7 @@ pub fn rotational(mut self, rotational: bool) -> Self { =20 /// Validate block size by verifying that it is between 512 and `PAGE_= SIZE`, /// and that it is a power of two. - fn validate_block_size(size: u32) -> Result { + pub fn validate_block_size(size: u32) -> Result { if !(512..=3Dbindings::PAGE_SIZE as u32).contains(&size) || !size.= is_power_of_two() { Err(error::code::EINVAL) } else { --=20 2.47.2 From nobody Fri Oct 3 10:12:42 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 BC1E02EFD87; Tue, 2 Sep 2025 09:56:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806987; cv=none; b=mHgvsmjYVz1n2usyE2H1MSZ70gdm5BT0lJdCpY/iWEY3U71ikh0j82WbylR/oB8TcsjTj0fbIEHUCo7Hm+4mnkMm9dA3p5TcupVBSa698khwLBWioAwqF51r1N3Ryvx0Vm/ZJV+/SMs9gSv0ZHWIHklszdrxemUuW5e/Ddu3CRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806987; c=relaxed/simple; bh=FG1VNwc+aiZdHMw5FUZZPe+D7cA4Ib1P36m8f0+W2JQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FrRZ/NCpzj241+ti/wNumseXUzDCyV+hpOeovaSjZ3CljOMuHKS5NOKtCb6hhnTLdFUjvayoz0G4JiCKoGCoH357kUcuSe7m+SAqvxBabon3CC95hG33T2KdOeGkI2vGv1Bn3a797WAyNaTJUTOO6dmT+jLZmxDz50lPaUO9fHA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vJuECx3d; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="vJuECx3d" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8D88C4CEED; Tue, 2 Sep 2025 09:56:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756806987; bh=FG1VNwc+aiZdHMw5FUZZPe+D7cA4Ib1P36m8f0+W2JQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=vJuECx3dCr4a7/qbQmBFw+0OUSS1NXQczQSBoFPR55eoGs9Zd62C6u8ahtjZB6eYp HaWN++6JDqB0peOpKm3fqIl1ka77aoVY61O21ROqhP8vu2piw00pIe0ZmNi0HjMCQt CSIHNzuImkKzKNZiTFx71y4u/S269ltgfHDIs9iEhbj4hy54TWYS3Z16HF3Gt5K7ip zGzl7pYEOQVMX7lCymGcCFdlBYeR27V0KWaNRBYPWq6fIR6quIaKPXV1uxdWi3zuGl nXT3rushQKWjMmfvwgZvj6uvJEhBvmNbmRyYSYxIi2Vx04glu5xnLyJQxrdVTIP4NS +7I6sE0rNLUug== From: Andreas Hindborg Date: Tue, 02 Sep 2025 11:55:08 +0200 Subject: [PATCH v7 14/17] rust: block: add `GenDisk` private data support 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 Message-Id: <20250902-rnull-up-v6-16-v7-14-b5212cc89b98@kernel.org> References: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> In-Reply-To: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> To: Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe , Breno Leitao Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg , Daniel Almeida X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=10628; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=FG1VNwc+aiZdHMw5FUZZPe+D7cA4Ib1P36m8f0+W2JQ=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBotr8G8wb9KKgOQLGn2/x++mr6TpgZ0WJ+EdXVe mz3jtKUZW6JAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCaLa/BgAKCRDhuBo+eShj d3aFEACqelXfSm+/5FD7zFN0QWX+wxxKKLSFqdhRZTFoRkdq3W49nQFOQQya4ogkGyHvVjEFPPB gvz56+AhMuMU1fK9HWPafiXACoXHMt088aSPyH6D+ax2MR4Cs0LcmKp7mYiji7+aLlboAbA+w6x UT55sivXrULEv85Fmk2TVQjyWYfQ9PEHp8aBZKxEVU4gIe03/Nfqe1HS0VG04C0yubr4lkkDg6K j8cDo1nPTJbvW9f0g7nDpzhS40fE1NwWMT679mCto78kKbNZNUsJbVdMhtLvnHH92COWBuFjdwX zFa9pngpoYKagjXECJnOvl1N7VjIEdHZvYyydJpl+lpvrFKVrZMA2cjLArCjrVc6OfwzPF6Ooab YY5XWmeSHUi/pX4Rcl9BhU/4b9MLQKuv/1K9v4DsPY1qVlXMThvDOM8RkEADT1OUnkr0a+Wbprr p2BTSgYPQLFcvXcPA2GYSsyKOije9ZV2RtfSHGpM4RrNkvTYaQmfyrwQubmn2gXlatYD/OjakvV 14YLElpfKEJcuWhncpOVrlwozis7wW+qBFPLodnO6j6IWurKbeQGhVTr2h8gAyas9er417l+Nuu 2WoLhBvPPqhd7vB5YHiT+EYg/lQBaYm8qEtUjX+ynI3Zg5OO+N/jimfcjImjfgiQKv3q5U7H8uO WkwKVQQj61U0PJg== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow users of the rust block device driver API to install private data in the `GenDisk` structure. Reviewed-by: Alice Ryhl Reviewed-by: Daniel Almeida Signed-off-by: Andreas Hindborg --- drivers/block/rnull/rnull.rs | 8 ++++--- rust/kernel/block/mq.rs | 7 +++--- rust/kernel/block/mq/gen_disk.rs | 32 ++++++++++++++++++++++---- rust/kernel/block/mq/operations.rs | 46 ++++++++++++++++++++++++++++++----= ---- 4 files changed, 74 insertions(+), 19 deletions(-) diff --git a/drivers/block/rnull/rnull.rs b/drivers/block/rnull/rnull.rs index 8690ff5f974f..8255236bc550 100644 --- a/drivers/block/rnull/rnull.rs +++ b/drivers/block/rnull/rnull.rs @@ -61,14 +61,16 @@ fn new( .logical_block_size(block_size)? .physical_block_size(block_size)? .rotational(rotational) - .build(fmt!("{}", name.to_str()?), tagset) + .build(fmt!("{}", name.to_str()?), tagset, ()) } } =20 #[vtable] impl Operations for NullBlkDevice { + type QueueData =3D (); + #[inline(always)] - fn queue_rq(rq: ARef>, _is_last: bool) -> Result { + fn queue_rq(_queue_data: (), rq: ARef>, _is_last: bo= ol) -> Result { mq::Request::end_ok(rq) .map_err(|_e| kernel::error::code::EIO) // We take no refcounts on the request, so we expect to be abl= e to @@ -79,5 +81,5 @@ fn queue_rq(rq: ARef>, _is_last: bool) = -> Result { Ok(()) } =20 - fn commit_rqs() {} + fn commit_rqs(_queue_data: ()) {} } diff --git a/rust/kernel/block/mq.rs b/rust/kernel/block/mq.rs index 98fa0d6bc8f7..6e546f4f3d1c 100644 --- a/rust/kernel/block/mq.rs +++ b/rust/kernel/block/mq.rs @@ -69,20 +69,21 @@ //! //! #[vtable] //! impl Operations for MyBlkDevice { +//! type QueueData =3D (); //! -//! fn queue_rq(rq: ARef>, _is_last: bool) -> Result { +//! fn queue_rq(_queue_data: (), rq: ARef>, _is_last: bo= ol) -> Result { //! Request::end_ok(rq); //! Ok(()) //! } //! -//! fn commit_rqs() {} +//! fn commit_rqs(_queue_data: ()) {} //! } //! //! let tagset: Arc> =3D //! Arc::pin_init(TagSet::new(1, 256, 1), flags::GFP_KERNEL)?; //! let mut disk =3D gen_disk::GenDiskBuilder::new() //! .capacity_sectors(4096) -//! .build(format_args!("myblk"), tagset)?; +//! .build(format_args!("myblk"), tagset, ())?; //! //! # Ok::<(), kernel::error::Error>(()) //! ``` diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_di= sk.rs index 6b1b846874db..46ec80269970 100644 --- a/rust/kernel/block/mq/gen_disk.rs +++ b/rust/kernel/block/mq/gen_disk.rs @@ -13,6 +13,7 @@ static_lock_class, str::NullTerminatedFormatter, sync::Arc, + types::{ForeignOwnable, ScopeGuard}, }; use core::fmt::{self, Write}; =20 @@ -98,7 +99,14 @@ pub fn build( self, name: fmt::Arguments<'_>, tagset: Arc>, + queue_data: T::QueueData, ) -> Result> { + let data =3D queue_data.into_foreign(); + let recover_data =3D ScopeGuard::new(|| { + // SAFETY: T::QueueData was created by the call to `into_forei= gn()` above + drop(unsafe { T::QueueData::from_foreign(data) }); + }); + // SAFETY: `bindings::queue_limits` contain only fields that are v= alid when zeroed. let mut lim: bindings::queue_limits =3D unsafe { core::mem::zeroed= () }; =20 @@ -113,7 +121,7 @@ pub fn build( bindings::__blk_mq_alloc_disk( tagset.raw_tag_set(), &mut lim, - core::ptr::null_mut(), + data, static_lock_class!().as_ptr(), ) })?; @@ -167,8 +175,12 @@ pub fn build( }, )?; =20 + recover_data.dismiss(); + // INVARIANT: `gendisk` was initialized above. // INVARIANT: `gendisk` was added to the VFS via `device_add_disk`= above. + // INVARIANT: `gendisk.queue.queue_data` is set to `data` in the c= all to + // `__blk_mq_alloc_disk` above. Ok(GenDisk { _tagset: tagset, gendisk, @@ -180,9 +192,10 @@ pub fn build( /// /// # Invariants /// -/// - `gendisk` must always point to an initialized and valid `struct gend= isk`. -/// - `gendisk` was added to the VFS through a call to -/// `bindings::device_add_disk`. +/// - `gendisk` must always point to an initialized and valid `struct gen= disk`. +/// - `gendisk` was added to the VFS through a call to +/// `bindings::device_add_disk`. +/// - `self.gendisk.queue.queuedata` is initialized by a call to `Foreign= Ownable::into_foreign`. pub struct GenDisk { _tagset: Arc>, gendisk: *mut bindings::gendisk, @@ -194,9 +207,20 @@ unsafe impl Send for GenDisk = {} =20 impl Drop for GenDisk { fn drop(&mut self) { + // SAFETY: By type invariant of `Self`, `self.gendisk` points to a= valid + // and initialized instance of `struct gendisk`, and, `queuedata` = was + // initialized with the result of a call to + // `ForeignOwnable::into_foreign`. + let queue_data =3D unsafe { (*(*self.gendisk).queue).queuedata }; + // SAFETY: By type invariant, `self.gendisk` points to a valid and // initialized instance of `struct gendisk`, and it was previously= added // to the VFS. unsafe { bindings::del_gendisk(self.gendisk) }; + + // SAFETY: `queue.queuedata` was created by `GenDiskBuilder::build= ` with + // a call to `ForeignOwnable::into_foreign` to create `queuedata`. + // `ForeignOwnable::from_foreign` is only called here. + drop(unsafe { T::QueueData::from_foreign(queue_data) }); } } diff --git a/rust/kernel/block/mq/operations.rs b/rust/kernel/block/mq/oper= ations.rs index c2b98f507bcb..9e31d24e1164 100644 --- a/rust/kernel/block/mq/operations.rs +++ b/rust/kernel/block/mq/operations.rs @@ -6,14 +6,15 @@ =20 use crate::{ bindings, - block::mq::request::RequestDataWrapper, - block::mq::Request, + block::mq::{request::RequestDataWrapper, Request}, error::{from_result, Result}, prelude::*, - types::ARef, + types::{ARef, ForeignOwnable}, }; use core::{marker::PhantomData, sync::atomic::AtomicU64, sync::atomic::Ord= ering}; =20 +type ForeignBorrowed<'a, T> =3D ::Borrowed<'a>; + /// Implement this trait to interface blk-mq as block devices. /// /// To implement a block device driver, implement this trait as described = in the @@ -26,12 +27,20 @@ /// [module level documentation]: kernel::block::mq #[macros::vtable] pub trait Operations: Sized { + /// Data associated with the `struct request_queue` that is allocated = for + /// the `GenDisk` associated with this `Operations` implementation. + type QueueData: ForeignOwnable; + /// Called by the kernel to queue a request with the driver. If `is_la= st` is /// `false`, the driver is allowed to defer committing the request. - fn queue_rq(rq: ARef>, is_last: bool) -> Result; + fn queue_rq( + queue_data: ForeignBorrowed<'_, Self::QueueData>, + rq: ARef>, + is_last: bool, + ) -> Result; =20 /// Called by the kernel to indicate that queued requests should be su= bmitted. - fn commit_rqs(); + fn commit_rqs(queue_data: ForeignBorrowed<'_, Self::QueueData>); =20 /// Called by the kernel to poll the device for completed requests. On= ly /// used for poll queues. @@ -70,7 +79,7 @@ impl OperationsVTable { /// promise to not access the request until the driver calls /// `bindings::blk_mq_end_request` for the request. unsafe extern "C" fn queue_rq_callback( - _hctx: *mut bindings::blk_mq_hw_ctx, + hctx: *mut bindings::blk_mq_hw_ctx, bd: *const bindings::blk_mq_queue_data, ) -> bindings::blk_status_t { // SAFETY: `bd.rq` is valid as required by the safety requirement = for @@ -88,10 +97,20 @@ impl OperationsVTable { // reference counted by `ARef` until then. let rq =3D unsafe { Request::aref_from_raw((*bd).rq) }; =20 + // SAFETY: `hctx` is valid as required by this function. + let queue_data =3D unsafe { (*(*hctx).queue).queuedata }; + + // SAFETY: `queue.queuedata` was created by `GenDiskBuilder::build= ` with + // a call to `ForeignOwnable::into_foreign` to create `queuedata`. + // `ForeignOwnable::from_foreign` is only called when the tagset is + // dropped, which happens after we are dropped. + let queue_data =3D unsafe { T::QueueData::borrow(queue_data) }; + // SAFETY: We have exclusive access and we just set the refcount a= bove. unsafe { Request::start_unchecked(&rq) }; =20 let ret =3D T::queue_rq( + queue_data, rq, // SAFETY: `bd` is valid as required by the safety requirement= for // this function. @@ -110,9 +129,18 @@ impl OperationsVTable { /// /// # Safety /// - /// This function may only be called by blk-mq C infrastructure. - unsafe extern "C" fn commit_rqs_callback(_hctx: *mut bindings::blk_mq_= hw_ctx) { - T::commit_rqs() + /// This function may only be called by blk-mq C infrastructure. The c= aller + /// must ensure that `hctx` is valid. + unsafe extern "C" fn commit_rqs_callback(hctx: *mut bindings::blk_mq_h= w_ctx) { + // SAFETY: `hctx` is valid as required by this function. + let queue_data =3D unsafe { (*(*hctx).queue).queuedata }; + + // SAFETY: `queue.queuedata` was created by `GenDisk::try_new()` w= ith a + // call to `ForeignOwnable::into_foreign()` to create `queuedata`. + // `ForeignOwnable::from_foreign()` is only called when the tagset= is + // dropped, which happens after we are dropped. + let queue_data =3D unsafe { T::QueueData::borrow(queue_data) }; + T::commit_rqs(queue_data) } =20 /// This function is called by the C kernel. It is not currently --=20 2.47.2 From nobody Fri Oct 3 10:12:42 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 430BE2F747A; Tue, 2 Sep 2025 09:56:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806991; cv=none; b=DY14zTUOyjQ3A8jazRNxCTBJx8S66JUll8c/UBCZMphG47UhT3XYmY1caV73C9aqnV7geCGRlxCroEpAVX9ihJvlgsFeC5cshqQ0JjSJ8bKMbabxZKC2UVzKpV3s/m+VqjE8Z0peQ+vS1hu+2l/HeIWLI6cWVtmzZWQinlys9g8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806991; c=relaxed/simple; bh=hixYhOSo78Opw3JCXq3T7Ep1Lb7kHadQhoAfotnnjUc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ez+s2AuZjzcW9vkA44PSx1Vo1GmhOghHaaNpy7jaoq0rLBXqvmcyMcPhCfgEMO9GcdrzwIH8ii/KNWBnBEsWIYW7Rg/f9StHjdD3CnNTZFMxXjaYP/JgTor+yih/2gpK/F4egh328GtHGJpCFOcAYta7orQAqpLeKBvNsdC/xSk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OsHblFPX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OsHblFPX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1EBCC4CEED; Tue, 2 Sep 2025 09:56:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756806991; bh=hixYhOSo78Opw3JCXq3T7Ep1Lb7kHadQhoAfotnnjUc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OsHblFPXfz01Qew8I3kdGqcfhrJRAr8lB396dsqdp0M5e9CbS7Jmw355Hq3DGKrSq hEPaOj/jXJZDWgK1JqHDhfAhEU/Er4siaAcYwjo0B3QqdoMZQUfkOoRRLruqaGOIPz giFqgo9IjZJWBU/QOgJzWkctP8oIlc8wf6d5cPxu27saLTL4oFucFZZ8qvhZmN6pJp nV5+1LCsH9F8KJgVs8OFAKzrbDDTE2E6pI1u/5fVJB490PKEy9hh4zJr20BftR1j/7 aR4n3tw2QJKQijr5QcxzdxzbPZMRnfpZMlujVfHRZWCj+/7wAyFJnJASKn2rMfR+cR C4HzVTjtCtWWQ== From: Andreas Hindborg Date: Tue, 02 Sep 2025 11:55:09 +0200 Subject: [PATCH v7 15/17] rust: block: mq: fix spelling in a safety comment 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 Message-Id: <20250902-rnull-up-v6-16-v7-15-b5212cc89b98@kernel.org> References: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> In-Reply-To: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> To: Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe , Breno Leitao Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg , Daniel Almeida X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1036; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=hixYhOSo78Opw3JCXq3T7Ep1Lb7kHadQhoAfotnnjUc=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBotr8Gae24Vv0iFDvJMLbTGRD84ZTe/kukacaQe MW+AqJRfveJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCaLa/BgAKCRDhuBo+eShj d4U3D/4gJIkgF55T6ecHFdtVubLkVr34NYS5iGEeDxCP/xHnthRVmGcfgkll2bNRGS8EM8/AGgf 6t2PYXZSionkEVrtMynNSokrYPX3WmLX8hN1CiCPoPcr5h4GaccVuUAoObTNOYE/G87M4bJS0cq W1ksrOB+0H90a+t4an3+alJMHP6rTw4K7KRZzrOm/wjC9nEYEoCB+g7P+rZCFiac40JxnEQHpNQ kd6hi3Bhgb1MjkCZfZ3uvb6t3bhSFAetUaISlkKerYawlPhPsw7CEdXBSwozkHR0YX5+bjF6Huo /ZLhiEh+At2RB8QAWA6/bl2g6XDLpE6ExXin6SJa7uCDhWI6H/pjpw4kPqPDbo6fbk1BvSURMaU ODZ7NNmgcLJmjhAdXcUTkmo59DxW28kzjJFiP2x5hUQAv5wnkbM9w2laCrYtjIGln5/cSffjXKH YE/e/YhNmZulQ9k/Quk3EbpGeZgSnBRhpVcIWU8vPEXS6+znWhFNOS2GBAYaV13Jui6Je5hgmLw HpSSFWY9yOJhWHh1Nu7pxPh/x0LGI3CjqzaTbalpABeXUOie7NuBD59gFkCWGf4MmrSOshY/0Yc oEs1IyuuFxXp9/5T0ohxfrZRoY79cGfKlW4PxY8MT2VSLN3BggLPirMNL3rpur6xjcxfuQK12Id 3QRVX5cX2kw34+w== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add code block quotes to a safety comment. Reviewed-by: Alice Ryhl Reviewed-by: Daniel Almeida Signed-off-by: Andreas Hindborg --- rust/kernel/block/mq/request.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/kernel/block/mq/request.rs b/rust/kernel/block/mq/request= .rs index f723d74091c1..3848cfe63f77 100644 --- a/rust/kernel/block/mq/request.rs +++ b/rust/kernel/block/mq/request.rs @@ -148,7 +148,7 @@ pub(crate) unsafe fn wrapper_ptr(this: *mut Self) -> No= nNull // valid allocation. let wrapper_ptr =3D unsafe { bindings::blk_mq_rq_to_pdu(request_ptr).cast::() }; - // SAFETY: By C API contract, wrapper_ptr points to a valid alloca= tion + // SAFETY: By C API contract, `wrapper_ptr` points to a valid allo= cation // and is not null. unsafe { NonNull::new_unchecked(wrapper_ptr) } } --=20 2.47.2 From nobody Fri Oct 3 10:12:42 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 051922F1FE7; Tue, 2 Sep 2025 09:55:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806955; cv=none; b=KBvL4cdaCRZt2EMN84XS0v85dXzPqbhIQ9ITxU3vkhRMKJ4SHifmSZ6+xDSvrOXZ1MA8F8Ny6ch8GgixmQlihhDmGAfq6LmuJZVpybpeb8ePSMg9D1cJkvAsdXFTZU+5AE8eGlA3cKGQL0B0ETsP9sQz/HNnQQllbyR3k8NGHds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806955; c=relaxed/simple; bh=YwUF3HJQztP31Vw7ZaxJ69OuXp+5+j2Zu1cR8QzNe+g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HkjmrcZ/7N/QR1+kzVGhgAlpc7FjoZOuR6pyCNryHV5sujXkRAH8cB8H0uhQShrgZ6P/7vdhCc0B40BreamY1KUbd5ChXdlv4aK29d5cAsZAsPZd7hiQZWV+R5xDcz1dhe3gNbqwJvLVqVUkfH/zoqabb6K8OLIOYihWb+ckUv4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ck9dwNAN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ck9dwNAN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FFA2C4CEED; Tue, 2 Sep 2025 09:55:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756806954; bh=YwUF3HJQztP31Vw7ZaxJ69OuXp+5+j2Zu1cR8QzNe+g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Ck9dwNANve8Ne07xu+AirZzR2EBbPSww8ib2Vc8HjgubaHxLCmRmMZ1hCtNta5ipZ PwY+nMPI7lp/yvz6I2fpQz1GZ+4pH8h4P2VZzkcv/z9D0gy5Xokj9hAtxDfrO0zIa8 +5lsuG404qojoocZrC6Sp+6qhK6MJ4AJba1OBNoso1PneKZckOiyKiUs58w1tkfsFu nkZ0t6KLNCMbjNPoMERvwyHf4iwXjM4w1/rb/5gAJCAPWmdrAIF2aNY895V9nbP+GO yvY5dpHycAe2i/7b64wMtPyWItWvPh7BkDJZeM+c/b9XMPB+u6B2bcz93Ho9HsxluF 4N1zDc+WaJ3zw== From: Andreas Hindborg Date: Tue, 02 Sep 2025 11:55:10 +0200 Subject: [PATCH v7 16/17] rust: block: add remote completion to `Request` 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 Message-Id: <20250902-rnull-up-v6-16-v7-16-b5212cc89b98@kernel.org> References: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> In-Reply-To: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> To: Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe , Breno Leitao Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg , Daniel Almeida X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=5096; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=YwUF3HJQztP31Vw7ZaxJ69OuXp+5+j2Zu1cR8QzNe+g=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBotr8HVoiFEohNXcMvJ10o1RLWE0ZZxSrQFCEj7 KsX6wNYVOuJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCaLa/BwAKCRDhuBo+eShj d432D/4zM1sRmiacMnsFNRMn96mFZy6dtbiRextv5n51Q1z+n+WKRdCnPqqkm9nDvocudZE8PQ/ OIJOfwZCMsDwUnDUhFU3TzR+61GK0PhdxslCeBy6LrHnWZqw+mjsm5WSXV94EehtZCsejiedItR 4hsKAjFt+dYfWkEOQBSyyang5iott/7IyABtmM4iAHnvLGxrLp+/xPfk4217EyvtS8oOOWK40EJ 7YUhy0U2T53IyTZ1bbhgZv3eH/gTQGqtHVKK7sMrBeuz+vCAR7Br15qgdLsWC5MvdhPk6BkKPK6 CTYs/TzSw9Jl8JvrUGKwIJqld+rpTwwoIAALQnnS8LFDCvA3yNmOyCS4T02cyzSS9fiIIfxDG+e SNmRWhccoF5f7m1Ppx6gj3mmSf+ljv9gUXXFpXJ37/LZNYRhVCUr7iHUpo+po3eiY37siNQ7toz 6+yGzbUWAvszqfwGpQXTDH0kCFRK6irveEKzSh3IAnHP+b6x0pZhDBGDTg2CgY7MwJzNLwDAiWX V4h62DDs3Jxvzfe6SbOfePNwb4I6/9hP1dKeDG3DNm3sJLBJLUFVj92hxVEiMCKW2zogFzHofzu 1ZKdzyVrGAMekKGQASkz+6dZupYftF6jCTsbkGxSCQ7XJhQIj7ypEe8SzlNKW6GrZKHBtLWe3A/ m/vRrgl4jESHYpQ== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Allow users of rust block device driver API to schedule completion of requests via `blk_mq_complete_request_remote`. Reviewed-by: Alice Ryhl Reviewed-by: Daniel Almeida Signed-off-by: Andreas Hindborg --- drivers/block/rnull/rnull.rs | 9 +++++++++ rust/kernel/block/mq.rs | 6 ++++++ rust/kernel/block/mq/operations.rs | 19 +++++++++++++++---- rust/kernel/block/mq/request.rs | 17 +++++++++++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/drivers/block/rnull/rnull.rs b/drivers/block/rnull/rnull.rs index 8255236bc550..a19c55717c4f 100644 --- a/drivers/block/rnull/rnull.rs +++ b/drivers/block/rnull/rnull.rs @@ -82,4 +82,13 @@ fn queue_rq(_queue_data: (), rq: ARef>= , _is_last: bool) -> Res } =20 fn commit_rqs(_queue_data: ()) {} + + fn complete(rq: ARef>) { + mq::Request::end_ok(rq) + .map_err(|_e| kernel::error::code::EIO) + // We take no refcounts on the request, so we expect to be abl= e to + // end the request. The request reference must be unique at th= is + // point, and so `end_ok` cannot fail. + .expect("Fatal error - expected to be able to end request"); + } } diff --git a/rust/kernel/block/mq.rs b/rust/kernel/block/mq.rs index 6e546f4f3d1c..c0ec06b84355 100644 --- a/rust/kernel/block/mq.rs +++ b/rust/kernel/block/mq.rs @@ -77,6 +77,12 @@ //! } //! //! fn commit_rqs(_queue_data: ()) {} +//! +//! fn complete(rq: ARef>) { +//! Request::end_ok(rq) +//! .map_err(|_e| kernel::error::code::EIO) +//! .expect("Fatal error - expected to be able to end request"= ); +//! } //! } //! //! let tagset: Arc> =3D diff --git a/rust/kernel/block/mq/operations.rs b/rust/kernel/block/mq/oper= ations.rs index 9e31d24e1164..d098a8a3e434 100644 --- a/rust/kernel/block/mq/operations.rs +++ b/rust/kernel/block/mq/operations.rs @@ -42,6 +42,9 @@ fn queue_rq( /// Called by the kernel to indicate that queued requests should be su= bmitted. fn commit_rqs(queue_data: ForeignBorrowed<'_, Self::QueueData>); =20 + /// Called by the kernel when the request is completed. + fn complete(rq: ARef>); + /// Called by the kernel to poll the device for completed requests. On= ly /// used for poll queues. fn poll() -> bool { @@ -143,13 +146,21 @@ impl OperationsVTable { T::commit_rqs(queue_data) } =20 - /// This function is called by the C kernel. It is not currently - /// implemented, and there is no way to exercise this code path. + /// This function is called by the C kernel. A pointer to this functio= n is + /// installed in the `blk_mq_ops` vtable for the driver. /// /// # Safety /// - /// This function may only be called by blk-mq C infrastructure. - unsafe extern "C" fn complete_callback(_rq: *mut bindings::request) {} + /// This function may only be called by blk-mq C infrastructure. `rq` = must + /// point to a valid request that has been marked as completed. The po= intee + /// of `rq` must be valid for write for the duration of this function. + unsafe extern "C" fn complete_callback(rq: *mut bindings::request) { + // SAFETY: This function can only be dispatched through + // `Request::complete`. We leaked a refcount then which we pick ba= ck up + // now. + let aref =3D unsafe { Request::aref_from_raw(rq) }; + T::complete(aref); + } =20 /// This function is called by the C kernel. A pointer to this functio= n is /// installed in the `blk_mq_ops` vtable for the driver. diff --git a/rust/kernel/block/mq/request.rs b/rust/kernel/block/mq/request= .rs index 3848cfe63f77..f7f757f7459f 100644 --- a/rust/kernel/block/mq/request.rs +++ b/rust/kernel/block/mq/request.rs @@ -135,6 +135,23 @@ pub fn end_ok(this: ARef) -> Result<(), ARef> { Ok(()) } =20 + /// Complete the request by scheduling `Operations::complete` for + /// execution. + /// + /// The function may be scheduled locally, via SoftIRQ or remotely via= IPMI. + /// See `blk_mq_complete_request_remote` in [`blk-mq.c`] for details. + /// + /// [`blk-mq.c`]: srctree/block/blk-mq.c + pub fn complete(this: ARef) { + let ptr =3D ARef::into_raw(this).cast::().as_pt= r(); + // SAFETY: By type invariant, `self.0` is a valid `struct request` + if !unsafe { bindings::blk_mq_complete_request_remote(ptr) } { + // SAFETY: We released a refcount above that we can reclaim he= re. + let this =3D unsafe { Request::aref_from_raw(ptr) }; + T::complete(this); + } + } + /// Return a pointer to the [`RequestDataWrapper`] stored in the priva= te area /// of the request structure. /// --=20 2.47.2 From nobody Fri Oct 3 10:12:42 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CD0922EFD87; Tue, 2 Sep 2025 09:56:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806978; cv=none; b=fdKYFDVeLolKcCA6Y+aWZTU65uiz0lfK2VaZAfq0Qta9S5xl9KEirVbms7DaPQ2B5q5BlHSgXEmSlD7kA4O3wZuTJH07wyOJuUgnkUbC6Rky9yZYDw+7iXX17Jxf38n+Kd6f8RbdCOYIjQTwC1sRTcYEKbzU795G92EOHDTjeTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756806978; c=relaxed/simple; bh=aP8rjJy/aucU/AdvUODqarq27NqARAu9QR2SBF7RTRs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lLFvmjhwnHxD001OrQx9Boau8ckrK+20dlslzxsYLGvuRFw7jqqtPQf/V9RzJY+4zx7dGBwnp13XZ9VcFE6lrggYyE/UsMA9L+7VVZNZ3m+K9idSyXW34c87i32n3RYIFie3HlGKUo8B8IBukU/gV1EpuNMxMl5WCx0SP69ctXc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q5V1zOvK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="q5V1zOvK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDFADC4CEED; Tue, 2 Sep 2025 09:56:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756806978; bh=aP8rjJy/aucU/AdvUODqarq27NqARAu9QR2SBF7RTRs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=q5V1zOvK66uXPBVXkTZAGq2iioQokxkC4nWSiQJjAQb+TNt6LorkfQja9Du5E4dZh WDZpdhhLzfl7IgBGJO0QP68IWialXEXvv9pxm52ErY7moNUK8jvP911AT/QpbmoxUt cGOmcjQhodpkuSNsxSPzeqj17lEJIueXt3StNigIxRAKBIEhg2zUMsCFIfUJaGn+rx 0sifpYLLtwhp9NMKaDqyXXu9xWQDVaHCIpp9gs7accLAjjc8xFmO5IiKAsGpHdKG4y 7ktvew5XKqisobTcvVczvI0nRTaPK+1UnCq9wNv3Sht5qcboHo8mwoxRvBttm9yPbG Eehv74/5KqtXQ== From: Andreas Hindborg Date: Tue, 02 Sep 2025 11:55:11 +0200 Subject: [PATCH v7 17/17] rnull: add soft-irq completion support 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 Message-Id: <20250902-rnull-up-v6-16-v7-17-b5212cc89b98@kernel.org> References: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> In-Reply-To: <20250902-rnull-up-v6-16-v7-0-b5212cc89b98@kernel.org> To: Boqun Feng , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Jens Axboe , Breno Leitao Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg , Daniel Almeida X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=6432; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=aP8rjJy/aucU/AdvUODqarq27NqARAu9QR2SBF7RTRs=; b=owEBbQKS/ZANAwAIAeG4Gj55KGN3AcsmYgBotr8IjCY/BdHMZ8XJPjj87NQsvEdfa7Mg1jHq7 bfQXYRKm0yJAjMEAAEIAB0WIQQSwflHVr98KhXWwBLhuBo+eShjdwUCaLa/CAAKCRDhuBo+eShj d8kqEACDbS/6X7I8dK6VSVaSFhS2Ylq/gIAKfVNieEzjfUJ5TX1+SGgo8UsqzY9bXWbIuH0Pyip 8PVho4RQiTAjnyzIuTQIzjqxLThq899ASeTejTVNaJ6+XeU/8QwZ+GeQALzYl6HqNw1Apnsl3wj 5Psrx8ICZQtS4pyppo7+GYw6l1REJ+Uo/GWDZVrVKsofi+UB/o9crUXnxLvUGaHKyBovxeUVc8q SrjMpJKPgICW2zdM0A182JSzwO/FZ2XN1NK5eMUfvLb7tPWhAT4rJ0P4Pm4nvrf9VdXQA5SMnLI Z5rU+a7j0CuXQiwn5F/n6q4/wPleqN+NuGPdauRgdbniBMAe/lvnGABThW5lSCxTY3Iw4HGRrbT vkkGz14i+UGQ5/t3/t26DMsiyLvnNYD/1OUwi7wRLyPeJYXjfRBjKPxH7jlxQBU3fRgAycOgdY1 Ew8AztcmGIJUR+TvH07j20Mo5+GSQxUh8R2dwY89vMwh2bBaG3rf0FDZDttlTtJzoNuUuTcBrUz Dx8gnmBQ3Tb0hONgiBOoKHSSRu7zKx8ED5e/Pi/ibFv/EWHjeHsy/yplk41XbLq7u8WhglYTl0P odUukwtDLyL314zJcQ9HE3RwgGBkMcrc7ZiJ4mDDV07k3tdrhM6UMl35/M2HqePPE0rgCJgHp6Q SdLTo0l4pCpiLzQ== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 rnull currently only supports direct completion. Add option for completing requests across CPU nodes via soft IRQ or IPI. Reviewed-by: Alice Ryhl Reviewed-by: Daniel Almeida Signed-off-by: Andreas Hindborg --- drivers/block/rnull/configfs.rs | 59 +++++++++++++++++++++++++++++++++++++= ++-- drivers/block/rnull/rnull.rs | 32 ++++++++++++++-------- 2 files changed, 78 insertions(+), 13 deletions(-) diff --git a/drivers/block/rnull/configfs.rs b/drivers/block/rnull/configfs= .rs index 46710a1e1af4..8498e9bae6fd 100644 --- a/drivers/block/rnull/configfs.rs +++ b/drivers/block/rnull/configfs.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 =20 use super::{NullBlkDevice, THIS_MODULE}; -use core::fmt::Write; +use core::fmt::{Display, Write}; use kernel::{ block::mq::gen_disk::{GenDisk, GenDiskBuilder}, c_str, @@ -36,7 +36,7 @@ impl AttributeOperations<0> for Config { =20 fn show(_this: &Config, page: &mut [u8; PAGE_SIZE]) -> Result { let mut writer =3D kernel::str::Formatter::new(page); - writer.write_str("blocksize,size,rotational\n")?; + writer.write_str("blocksize,size,rotational,irqmode\n")?; Ok(writer.bytes_written()) } } @@ -58,6 +58,7 @@ fn make_group( blocksize: 1, rotational: 2, size: 3, + irqmode: 4, ], }; =20 @@ -72,6 +73,7 @@ fn make_group( rotational: false, disk: None, capacity_mib: 4096, + irq_mode: IRQMode::None, name: name.try_into()?, }), }), @@ -79,6 +81,34 @@ fn make_group( } } =20 +#[derive(Debug, Clone, Copy)] +pub(crate) enum IRQMode { + None, + Soft, +} + +impl TryFrom for IRQMode { + type Error =3D kernel::error::Error; + + fn try_from(value: u8) -> Result { + match value { + 0 =3D> Ok(Self::None), + 1 =3D> Ok(Self::Soft), + _ =3D> Err(EINVAL), + } + } +} + +impl Display for IRQMode { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Self::None =3D> f.write_str("0")?, + Self::Soft =3D> f.write_str("1")?, + } + Ok(()) + } +} + #[pin_data] pub(crate) struct DeviceConfig { #[pin] @@ -92,6 +122,7 @@ struct DeviceConfigInner { block_size: u32, rotational: bool, capacity_mib: u64, + irq_mode: IRQMode, disk: Option>, } =20 @@ -121,6 +152,7 @@ fn store(this: &DeviceConfig, page: &[u8]) -> Result { guard.block_size, guard.rotational, guard.capacity_mib, + guard.irq_mode, )?); guard.powered =3D true; } else if guard.powered && !power_op { @@ -205,3 +237,26 @@ fn store(this: &DeviceConfig, page: &[u8]) -> Result { Ok(()) } } + +#[vtable] +impl configfs::AttributeOperations<4> for DeviceConfig { + type Data =3D DeviceConfig; + + fn show(this: &DeviceConfig, page: &mut [u8; PAGE_SIZE]) -> Result { + let mut writer =3D kernel::str::Formatter::new(page); + writer.write_fmt(fmt!("{}\n", this.data.lock().irq_mode))?; + Ok(writer.bytes_written()) + } + + fn store(this: &DeviceConfig, page: &[u8]) -> Result { + if this.data.lock().powered { + return Err(EBUSY); + } + + let text =3D core::str::from_utf8(page)?.trim(); + let value =3D text.parse::().map_err(|_| EINVAL)?; + + this.data.lock().irq_mode =3D IRQMode::try_from(value)?; + Ok(()) + } +} diff --git a/drivers/block/rnull/rnull.rs b/drivers/block/rnull/rnull.rs index a19c55717c4f..1ec694d7f1a6 100644 --- a/drivers/block/rnull/rnull.rs +++ b/drivers/block/rnull/rnull.rs @@ -4,6 +4,7 @@ =20 mod configfs; =20 +use configfs::IRQMode; use kernel::{ block::{ self, @@ -53,35 +54,44 @@ fn new( block_size: u32, rotational: bool, capacity_mib: u64, + irq_mode: IRQMode, ) -> Result> { let tagset =3D Arc::pin_init(TagSet::new(1, 256, 1), GFP_KERNEL)?; =20 + let queue_data =3D Box::new(QueueData { irq_mode }, GFP_KERNEL)?; + gen_disk::GenDiskBuilder::new() .capacity_sectors(capacity_mib << (20 - block::SECTOR_SHIFT)) .logical_block_size(block_size)? .physical_block_size(block_size)? .rotational(rotational) - .build(fmt!("{}", name.to_str()?), tagset, ()) + .build(fmt!("{}", name.to_str()?), tagset, queue_data) } } =20 +struct QueueData { + irq_mode: IRQMode, +} + #[vtable] impl Operations for NullBlkDevice { - type QueueData =3D (); + type QueueData =3D KBox; =20 #[inline(always)] - fn queue_rq(_queue_data: (), rq: ARef>, _is_last: bo= ol) -> Result { - mq::Request::end_ok(rq) - .map_err(|_e| kernel::error::code::EIO) - // We take no refcounts on the request, so we expect to be abl= e to - // end the request. The request reference must be unique at th= is - // point, and so `end_ok` cannot fail. - .expect("Fatal error - expected to be able to end request"); - + fn queue_rq(queue_data: &QueueData, rq: ARef>, _is_l= ast: bool) -> Result { + match queue_data.irq_mode { + IRQMode::None =3D> mq::Request::end_ok(rq) + .map_err(|_e| kernel::error::code::EIO) + // We take no refcounts on the request, so we expect to be= able to + // end the request. The request reference must be unique a= t this + // point, and so `end_ok` cannot fail. + .expect("Fatal error - expected to be able to end request"= ), + IRQMode::Soft =3D> mq::Request::complete(rq), + } Ok(()) } =20 - fn commit_rqs(_queue_data: ()) {} + fn commit_rqs(_queue_data: &QueueData) {} =20 fn complete(rq: ARef>) { mq::Request::end_ok(rq) --=20 2.47.2