* [PATCH 1/1] rust: module_param: support bool parameters
2026-04-11 13:02 [PATCH 0/1] rust: module_param: support bool parameters Wenzhao Liao
@ 2026-04-11 13:02 ` Wenzhao Liao
2026-04-11 13:20 ` [PATCH 0/1] " Greg KH
1 sibling, 0 replies; 3+ messages in thread
From: Wenzhao Liao @ 2026-04-11 13:02 UTC (permalink / raw)
To: mcgrof, petr.pavlu, da.gomez, samitolvanen, ojeda, linux-modules,
rust-for-linux
Cc: atomlin, boqun, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl,
tmgross, dakr, linux-kernel
Add support for parsing boolean module parameters in the Rust
module! macro.
Currently, only integer types are supported by the `module_param!`
macros. This patch implements the `ModuleParam` trait for `bool`
by delegating the string parsing to the existing C implementation
via `kstrtobool_bytes()`. It also wires up `PARAM_OPS_BOOL` so that
the Rust parameter system correctly links to the C `param_ops_bool`
structure.
For demonstration and verification, a boolean parameter is added
to `samples/rust/rust_minimal.rs`.
Assisted-by: Codex:GPT-5
Signed-off-by: Wenzhao Liao <wenzhaoliao@ruc.edu.cn>
---
rust/kernel/module_param.rs | 9 ++++++++-
rust/macros/lib.rs | 1 +
rust/macros/module.rs | 1 +
samples/rust/rust_minimal.rs | 8 ++++++++
4 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/rust/kernel/module_param.rs b/rust/kernel/module_param.rs
index 6a8a7a875643..04ce9eda6731 100644
--- a/rust/kernel/module_param.rs
+++ b/rust/kernel/module_param.rs
@@ -5,7 +5,7 @@
//! C header: [`include/linux/moduleparam.h`](srctree/include/linux/moduleparam.h)
use crate::prelude::*;
-use crate::str::BStr;
+use crate::str::{kstrtobool_bytes, BStr};
use bindings;
use kernel::sync::SetOnce;
@@ -106,6 +106,12 @@ fn try_from_param_arg(arg: &BStr) -> Result<Self> {
impl_int_module_param!(isize);
impl_int_module_param!(usize);
+impl ModuleParam for bool {
+ fn try_from_param_arg(arg: &BStr) -> Result<Self> {
+ kstrtobool_bytes(arg)
+ }
+}
+
/// A wrapper for kernel parameters.
///
/// This type is instantiated by the [`module!`] macro when module parameters are
@@ -180,3 +186,4 @@ macro_rules! make_param_ops {
make_param_ops!(PARAM_OPS_U64, u64);
make_param_ops!(PARAM_OPS_ISIZE, isize);
make_param_ops!(PARAM_OPS_USIZE, usize);
+make_param_ops!(PARAM_OPS_BOOL, bool);
diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs
index 0c36194d9971..95bc3f066b49 100644
--- a/rust/macros/lib.rs
+++ b/rust/macros/lib.rs
@@ -52,6 +52,7 @@
/// - [`u64`]
/// - [`isize`]
/// - [`usize`]
+/// - [`bool`]
///
/// C header: [`include/linux/moduleparam.h`](srctree/include/linux/moduleparam.h)
///
diff --git a/rust/macros/module.rs b/rust/macros/module.rs
index e16298e520c7..feafa0c1623c 100644
--- a/rust/macros/module.rs
+++ b/rust/macros/module.rs
@@ -197,6 +197,7 @@ fn param_ops_path(param_type: &str) -> Path {
"u64" => parse_quote!(::kernel::module_param::PARAM_OPS_U64),
"isize" => parse_quote!(::kernel::module_param::PARAM_OPS_ISIZE),
"usize" => parse_quote!(::kernel::module_param::PARAM_OPS_USIZE),
+ "bool" => parse_quote!(::kernel::module_param::PARAM_OPS_BOOL),
t => panic!("Unsupported parameter type {}", t),
}
}
diff --git a/samples/rust/rust_minimal.rs b/samples/rust/rust_minimal.rs
index 8eb9583571d7..fedf5be1f713 100644
--- a/samples/rust/rust_minimal.rs
+++ b/samples/rust/rust_minimal.rs
@@ -15,6 +15,10 @@
default: 1,
description: "This parameter has a default of 1",
},
+ test_bool_parameter: bool {
+ default: false,
+ description: "This boolean parameter defaults to false",
+ },
},
}
@@ -30,6 +34,10 @@ fn init(_module: &'static ThisModule) -> Result<Self> {
"test_parameter: {}\n",
*module_parameters::test_parameter.value()
);
+ pr_info!(
+ "test_bool_parameter: {}\n",
+ *module_parameters::test_bool_parameter.value()
+ );
let mut numbers = KVec::new();
numbers.push(72, GFP_KERNEL)?;
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH 0/1] rust: module_param: support bool parameters
2026-04-11 13:02 [PATCH 0/1] rust: module_param: support bool parameters Wenzhao Liao
2026-04-11 13:02 ` [PATCH 1/1] " Wenzhao Liao
@ 2026-04-11 13:20 ` Greg KH
1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2026-04-11 13:20 UTC (permalink / raw)
To: Wenzhao Liao
Cc: mcgrof, petr.pavlu, da.gomez, samitolvanen, ojeda, linux-modules,
rust-for-linux, atomlin, boqun, gary, bjorn3_gh, lossin,
a.hindborg, aliceryhl, tmgross, dakr, linux-kernel
On Sat, Apr 11, 2026 at 09:02:53AM -0400, Wenzhao Liao wrote:
> Sorry for the earlier noise and for our unfamiliarity with parts of the
> kernel submission process, which created extra burden for maintainers.
>
> This patch adds boolean module parameter support to the Rust `module!`
> parameter path.
>
> It implements `ModuleParam` for `bool` and wires `PARAM_OPS_BOOL` into
> the Rust module parameter machinery, so Rust-side parsing reuses the
> existing kernel `kstrtobool()` semantics through `kstrtobool_bytes()`
> instead of introducing a separate parser. A boolean parameter is also
> added to `samples/rust/rust_minimal.rs` as a small reference user and
> build-time validation point.
What driver needs this feature? Module options should be very rare
going forward as they are 1990's technology and do not fit the "modern"
kernel model at all.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread