Skip to content

rust: module parameter extensions

Matthew Wood linux-modules lkml rust-for-linux 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest8 patches 8 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8rust: module_param: add StringParam type for C string parametersrust/kernel/module_param.rs+69 -02 replies
2/8rust: module_param: wire StringParam into the module! macrorust/kernel/module_param.rs rust/macros/module.rs+81 -94 replies
3/8samples: rust_minimal: demonstrate string module parametersamples/rust/rust_minimal.rs+28 -30 replies
4/8rust: module_param: add ObsKernelParam typerust/kernel/module_param.rs+14 -00 replies
5/8rust: module_param: add from_setup_arg() to ModuleParam traitrust/kernel/module_param.rs+29 -00 replies
6/8rust: macros: add early_param support to module! macrorust/macros/lib.rs rust/macros/module.rs+86 -01 reply
7/8samples: rust_minimal: demonstrate early_param usagesamples/rust/rust_minimal.rs+2 -00 replies
8/8rust: macros: add configurable initcall levels to module! macrorust/macros/lib.rs rust/macros/module.rs+59 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/8] rust: module parameter extensions

This series extends the Rust module! macro with three capabilities that are available to C modules but currently missing from the Rust
abstractions: string parameters, early boot command-line parameters, and configurable initcall levels.

The existing Rust module parameter infrastructure supports integer types (i8..u64, isize, usize) but has no way to accept string values. Additionally, built-in Rust modules cannot register parameters for early boot command-line parsing (__setup / early_param), and all Rust modules are hard-coded to initcall level 6 (device_initcall) with no way to control initialization ordering.

String parameter support (patches 1-3):

Introduce StringParam, a Copy wrapper around *const c_char whose memory is managed by the kernel parameter subsystem. Wire it into the module! macro as the string parameter type with a dedicated kernel_param_ops (PARAM_OPS_STRING) that stores the pointer directly into a SetOnce<StringParam> container. The rust_minimal sample is updated to demonstrate usage.

An earlier implementation of string parameter support was proposed in:

      https://github.com/Rust-for-Linux/linux/pull/110/

This series takes a different approach for StringParam by storing the raw C string pointer directly rather than copying the string data, since the kernel guarantees the backing memory remains valid for the module's lifetime. This avoids allocation in the parameter setter and keeps StringParam as a simple Copy type consistent with the existing integer parameter design.

Early boot parameter support (patches 4-7):

Add ObsKernelParam (mirroring the C obs_kernel_param), extend the ModuleParam trait with from_setup_arg() for constructing parameter values from raw __setup callback arguments, and integrate an optional early_param field into the module! macro. When specified, the macro emits a __setup entry in the .init.setup ELF section, gated behind #[cfg(not(MODULE))] since this mechanism is only meaningful for built-in modules.

Configurable initcall levels (patch 8):

Add an optional initcall field to the module! macro that accepts any of the eight standard levels (pure through late). The default remains level 6 (device) so existing modules are unaffected.

Matthew Wood (8):
rust: module_param: add StringParam type for C string parameters
rust: module_param: wire StringParam into the module! macro
samples: rust_minimal: demonstrate string module parameter
rust: module_param: add ObsKernelParam type
rust: module_param: add from_setup_arg() to ModuleParam trait
rust: macros: add early_param support to module! macro
samples: rust_minimal: demonstrate early_param usage
rust: macros: add configurable initcall levels to module! macro

 rust/kernel/module_param.rs  | 160 +++++++++++++++++++++++++++++++
 rust/macros/lib.rs           |   9 ++
 rust/macros/module.rs        | 179 +++++++++++++++++++++++++++++++++--
 samples/rust/rust_minimal.rs |  33 ++++++-
 4 files changed, 368 insertions(+), 13 deletions(-)
Signature · 1 line
2.52.0