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(-)

-- 
2.52.0


Reply via email to