From nobody Tue Apr 7 17:13:53 2026 Received: from mail-dl1-f49.google.com (mail-dl1-f49.google.com [74.125.82.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34CEB32ED45 for ; Thu, 26 Feb 2026 23:47:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149661; cv=none; b=ZHQ02FkeaMUnY3knWd2KUDrfpMFf8XpzlUk+02E0WN6EPyZI2Gvtg3vSXSz2dX00GewRWzAtImgAgO6t+XMV2FFEGxWXVb449crYKm0TMaahczV14rkTXZqbOZ+BaX9W7IgUjIEHVvqqGgFpfJr6ORFYPe3ktf66cCNDvInSVNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149661; c=relaxed/simple; bh=+710AkSXFh9/JTyVTFsALEm9lZruIYGGtM6C7UvgeXk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=blkFsq6PZeh7f2qQ3J3KJHjKp81CRumIc6jtnn4wi6Psb/NBPgPRu+HE0mspWb22mI3zOFvS98JB+dHQX2FBRp4jBMfwsAHftlAC3QoV7y8abvLgFvbSitzX0qtvzXeCZo++1Dn99MQLbY8ZPgTQLKUt8VIxuuuKJnOW2ik2nJU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cuuQSXaA; arc=none smtp.client-ip=74.125.82.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cuuQSXaA" Received: by mail-dl1-f49.google.com with SMTP id a92af1059eb24-1277d379936so1927022c88.1 for ; Thu, 26 Feb 2026 15:47:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772149659; x=1772754459; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gD9eL4ru9kmWsugqvdoizgO/NNbT0Xc+Ro7IneP1lQM=; b=cuuQSXaANrnVWiqCWz0id9kTO6X3f4pKw2rgMcw1xeQzcMvXZXs72WgrrkH4cS9EE7 cdlP6zKZ/tHsGXh55czoi4OYKGUGfRWCbH206B8o5yksjvAIgBtjntc7wYDdZNOyRQC+ zgO54gh7FfWRVU7Aj6HmkmsxZ3+RdJiOVoDl+8+968x/ed0YmWG0I7D9nL6weaEXRIiT au09ooRFJQZxp/nWxW4ClsryyR+dTU6qCJY904Xs34T06DbE6SKY5Lm7JJmnSM/vMZRa fy4+6xHb2sCAteTvP4dROpv0DwTHFVZfoxqqcCCH7ZqIB7TMCtOfgIvhJNqSkjJNQuT7 LNoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772149659; x=1772754459; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=gD9eL4ru9kmWsugqvdoizgO/NNbT0Xc+Ro7IneP1lQM=; b=ZtaJyHs/d2BIY3effhjL8sfSMtWgZqxTITCwwMPWw4uwhhOwuUKdUFXbx3ciQphszX GOTUljg9mu4Yg4bKNbqzOFU0W0b54Qp9Tw4EQnFNv+ozhPjkboVI8i4MtOJhnaOcT+dp unNQZcbUc4Fj2sWwo/CwUYo5JV7dX/PwfSNuQiEDw+clLELpBS3A3fVEZvt9uh64U71a b55bwqzew93m+sbP4U3Kb/7hZe5xUg8O6G9v2XB+8eRMWIAwkYzJPTt/StGfIYdTi/Nl km6caWHq2IxRL9GqDnXTyW2GyFVLxS/AJV9BoENcYFONLb7Q0WyILDvYy5hLbVA2iJgj 8WeQ== X-Forwarded-Encrypted: i=1; AJvYcCVrEqCe/R/3Yz6yazoCVHfSvI+Jtk0/Sycda1TQ1kOdLqX56YmCqGKfGjYdcffz8+x3FdoIh0QtIQoZDrU=@vger.kernel.org X-Gm-Message-State: AOJu0YwFhyKv3r3v4icfTUQOXQ0rrepyxWSEpk4dCtIOh6lrk6o6s46I j6v8Bvu7x9ItNe7ykauAdDhSbLKumHgbYdkNlZ0FFSk3/hc86fuQwDeP X-Gm-Gg: ATEYQzwjQXIE1MndvjK1gJW2YrvOOfM3AaaL2X+aR2AyrPGt7sAMa2VRF04G3D9mruY QlBlRtpzj5lyAVPklvGC+DX/4aU40NqbCJbXP6KNJVoD2G5Dh39MGFo0ulT0zeCE8cowO90zRDo dMoUu8vop8n+6OPzQd+PMhSmqvSqFn1mwD3UpZn6Utzsz+sv3nOgGA7dIrt4yDI3xIioxg4BOyW 9d7ZtOXELmUOGcF3TB5ze5GUwvVYaB7OVceUlIyD+oner3GyqaiFPxkVIEsX+JSGbRMfj8CNshY aqtq/CFUxfBq1gARRjbMTNmDrUxTf9WrafyKd6WehMhmW6Fmu6vC0bcBW7dlwXZFJeG3+0Ul3cB 3fMAhaOTK9zzBJDwTYFLuzTJWDVmAeIF/iUPmBNSz92GQa4bXxwjLquQh6+++4oNeUATetJp278 8UKtk1TUwonLKbvHExphN/si+jqvfZteTxCn5H3Pku13IuanU+/kSQ+Rx4NHNOY+yVOgx78YuWy Q== X-Received: by 2002:a05:7022:6baa:b0:127:345c:43b2 with SMTP id a92af1059eb24-1278fc1f7d9mr357491c88.28.1772149658648; Thu, 26 Feb 2026 15:47:38 -0800 (PST) Received: from localhost (99-122-55-39.lightspeed.sntcca.sbcglobal.net. [99.122.55.39]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12789a32633sm3973385c88.9.2026.02.26.15.47.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 15:47:38 -0800 (PST) From: Matthew Wood To: Miguel Ojeda , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen Cc: Aaron Tomlin , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Tamir Duberstein , David Gow , =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= , linux-modules@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/8] rust: module_param: add StringParam type for C string parameters Date: Thu, 26 Feb 2026 15:47:27 -0800 Message-ID: <20260226234736.428341-2-thepacketgeek@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260226234736.428341-1-thepacketgeek@gmail.com> References: <20260226234736.428341-1-thepacketgeek@gmail.com> 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 Introduce StringParam, a Copy wrapper around *const c_char that represents a string module parameter whose memory is managed by the kernel parameter subsystem. StringParam provides: - from_ptr(): construct from a raw C string pointer - from_c_str(): construct from a static CStr (for compile-time default values) - null(): construct an unset/empty parameter - as_cstr() / as_bytes(): safe accessors that return None when the pointer is null The type is marked Send + Sync because the underlying pointer is effectively 'static for the module's lifetime =E2=80=94 the kernel guarante= es the string memory remains valid while the module is loaded. This is a prerequisite for wiring string parameters into the module! macro in subsequent patches. Signed-off-by: Matthew Wood --- rust/kernel/module_param.rs | 69 +++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/rust/kernel/module_param.rs b/rust/kernel/module_param.rs index 6a8a7a875643..80fe8643c0ab 100644 --- a/rust/kernel/module_param.rs +++ b/rust/kernel/module_param.rs @@ -6,6 +6,7 @@ =20 use crate::prelude::*; use crate::str::BStr; +use crate::str::CStr; use bindings; use kernel::sync::SetOnce; =20 @@ -106,6 +107,74 @@ fn try_from_param_arg(arg: &BStr) -> Result { impl_int_module_param!(isize); impl_int_module_param!(usize); =20 +/// A module parameter that holds a C string pointer. +/// +/// This type is `Copy` by storing only a raw pointer. The underlying stri= ng +/// memory is managed by the kernel's parameter subsystem. +/// +/// # Safety +/// +/// The pointer is only valid while the module is loaded. The kernel ensur= es +/// the string memory remains valid for the module's lifetime. +#[derive(Copy, Clone)] +#[repr(transparent)] +pub struct StringParam { + ptr: *const c_char, +} + +impl StringParam { + /// Creates a new `StringParam` from a raw pointer. + /// + /// # Safety + /// + /// The pointer must be valid and point to a null-terminated string, + /// or be null for an empty/unset parameter. + pub const unsafe fn from_ptr(ptr: *const c_char) -> Self { + Self { ptr } + } + + /// Creates a `StringParam` from a static `CStr` reference. + /// + /// Useful for compile-time default values in module parameter declara= tions. + pub const fn from_c_str(s: &'static CStr) -> Self { + Self { + ptr: crate::str::as_char_ptr_in_const_context(s), + } + } + + /// Creates a null/empty `StringParam`. + pub const fn null() -> Self { + Self { + ptr: core::ptr::null(), + } + } + + /// Returns `true` if the parameter is null/unset. + pub fn is_null(&self) -> bool { + self.ptr.is_null() + } + + /// Returns the string as a `CStr` reference, if set. + pub fn as_cstr(&self) -> Option<&CStr> { + if self.ptr.is_null() { + None + } else { + // SAFETY: pointer validity is checked above + Some(unsafe { CStr::from_char_ptr(self.ptr) }) + } + } + + /// Returns the string as bytes, if set. + pub fn as_bytes(&self) -> Option<&[u8]> { + self.as_cstr().map(|s| s.to_bytes()) + } +} + +// SAFETY: The pointer is managed by the kernel and is effectively 'static +// for the module's lifetime. +unsafe impl Send for StringParam {} +unsafe impl Sync for StringParam {} + /// A wrapper for kernel parameters. /// /// This type is instantiated by the [`module!`] macro when module paramet= ers are --=20 2.52.0 From nobody Tue Apr 7 17:13:53 2026 Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CEC8F331A5D for ; Thu, 26 Feb 2026 23:47:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149662; cv=none; b=liLGjxhJK0zPsGct18xzNdXBVQ51hLYMnGYYrOOthX7yOEDBhYp0Gb/X8UPW6IYC73v4OrSxDwCf6hMYLGQVpJclPyj+iorDAuB5yHanaksnIC1/T1GCB+wgSBAFp9y5wX7acKHeGN7RP8WtMr1gI2bIpqvviLFLXbBioTsgsWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149662; c=relaxed/simple; bh=muxh3fCFRhSf9Unv2vBe0W+v1Z0hoW/CIg7AHgZRxaA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mlPzmeWzhDDM4NHLC+NlvW0ImNghSSYZp6F2gDHKRYttjk9JuFxai6pbPPkRT0RuuU2W8u5Q0b2fAEkoo1SFivKWFPrnx5vkP3tU4tdBRc9zUCRul/DAGNEI4sZQ42rv6d2ozeO7B5CXZes/m6ijGuDc5Oc3VA2RNGS8UF87YR0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EX/VZ7n4; arc=none smtp.client-ip=74.125.82.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EX/VZ7n4" Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-2bd9a485bd6so2505479eec.1 for ; Thu, 26 Feb 2026 15:47:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772149660; x=1772754460; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iOJAuKmw4q0dzp0Ep92fm1clLy9bI5rwzposWVs1Z0k=; b=EX/VZ7n48a7dg7o4vgOtulAQFW7a9o8lBRcfmJ0uIbupnWZswyr7EOzckc3ZO59nm2 nKdbuYWIVYTmhP+M3cXwh2s7QW4O+W5NTvUdGq0D3lujNhRghg4ABgcE6KdmE9mn/36q A6h9m/P4sl4+Pkj32k+hAFPTCvXi7Y5gzuzXuX//gWB19cyvqEYw19oKmsHDeeC/8/0p KGMbvGkUdHbmWV/ceBFFqvKm/Q28HpqpQTbBIU4eYHgrxi58vPlqBVQtD6yFxrm6chhr cZ+SPiTsqOhwlAQqlK+Wr9OtkUdiQo24XN4Jn/utzAe37IphwIV0KiaEJET+vCmjKYb0 AgHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772149660; x=1772754460; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=iOJAuKmw4q0dzp0Ep92fm1clLy9bI5rwzposWVs1Z0k=; b=a8W/MJ5mXPsPC4PpR406dTDkzQgQ4QKq7DJM+lKP6MdajSN1TUQ6az6Wl8Scjk+l45 ej8euFg15hE9LVCVF32UXVuFnzfyS+RZz1soI9bqe8ZTzgOD2JZX8VDoj8G+VCZI89AH sbqApBvt1sLig3wjTKU9URYvihaNHeYGzUHRhCGTMfWPTcXQSnA9VPAHJ8lR1XpBB/qh q3C9CEuFhgy6a9jO1KmZEs2IFPa03WQpMVrZcclkR9wTjWSzff+kmouVsJnW/FTb1kbP ZJqxwEtqzEC3zyDZ6ezdbaglmpgHI7lO7MC9MAf5nsZYzspc8AW7lkon4EFr2N/oN/bm 4PIw== X-Forwarded-Encrypted: i=1; AJvYcCW3o/5gldUJ5K0jmogi6H74AlqEc40XWXl9rqfzRZlBzgBMATxG7oWPbHiQi6FDz4XzmNqtn8en2bF7DBI=@vger.kernel.org X-Gm-Message-State: AOJu0YxvxDqh3I/hq+rEl42x7W9boHzi1CGJa26Z6E41CTjDwxn+GBjV 8uB3pl1LD5FnN8C3xuWzdOrH7fNb2o+7k2NGM4fOROlP+/WNN3XuQ8U5 X-Gm-Gg: ATEYQzynv1K7Svnub/6uCcXCo2Es+DfUtr/OHidDAyI0NtuITdg39odOcL0r2udDsjz OuBBAoJqVJrlhgYsJQ0sen98gYanqkYC3GlUqe5FmML9ST+t3PC7D1U1GQKzjZK0ldO2WyqTHCv QzmA8i/jB8l+Y91gheqlpRAQv9T4+KHnRveDfQXNbIO5A+exrrQ8xYiQslsI6GaVGGp2/F8QAsh q5ZIbWswg4urct7YcXKaMQLyjB+Oh96WijoUuYOjHjjCIo1qVSQPx00CsHGWo4m6b1vNVEn7HAa HRNDFJEVF49ARv2jUVihDpktjAqjjmHGNCr4Aky5CDvzwkHFQTg/JxGEhdMXo9djBFiVZczu6rw bgIpTj5EBS+vBpJg0RElVbkoKxqa96ZtxHFTo7Z0pq8kOngukZwUA7p/PjHNjg0y+ZpmzKhX82R wXHTeeWBRqMg1h9H8gmiypceh0HKI+awQH5nit4Y3Tk8bu03pwFHgkpVKotzBfS4o6R5BPQJvjX oZZ7h47CGN+ X-Received: by 2002:a05:7022:4583:b0:127:5cda:fb7d with SMTP id a92af1059eb24-1278fc2c5fbmr491168c88.6.1772149659700; Thu, 26 Feb 2026 15:47:39 -0800 (PST) Received: from localhost (99-122-55-39.lightspeed.sntcca.sbcglobal.net. [99.122.55.39]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-127899ea1e5sm4259846c88.7.2026.02.26.15.47.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 15:47:39 -0800 (PST) From: Matthew Wood To: Miguel Ojeda , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen Cc: Aaron Tomlin , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Tamir Duberstein , David Gow , =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= , linux-modules@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/8] rust: module_param: wire StringParam into the module! macro Date: Thu, 26 Feb 2026 15:47:28 -0800 Message-ID: <20260226234736.428341-3-thepacketgeek@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260226234736.428341-1-thepacketgeek@gmail.com> References: <20260226234736.428341-1-thepacketgeek@gmail.com> 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 Add support for `string` as a parameter type in the module! macro. On the runtime side, add: - set_string_param(): an extern "C" callback matching the kernel_param_ops::set signature that stores the raw C string pointer directly into the SetOnce container, avoiding an unnecessary copy-and-parse round-trip. - PARAM_OPS_STRING: a static kernel_param_ops that uses set_string_param as its setter. - ModuleParam impl for StringParam with try_from_param_arg() returning -EINVAL, since string parameters are populated exclusively through the kernel's set callback. On the macro side: - Change the Parameter::ptype field from Ident to syn::Type to support path-qualified types. - Recognize the `string` shorthand and resolve it to the fully qualified ::kernel::module_param::StringParam type during code generation. - Wrap string default values with StringParam::from_c_str(c_str!(...)) to produce a compile-time CStr-backed default. - Route `string` to PARAM_OPS_STRING in param_ops_path(). Signed-off-by: Matthew Wood --- rust/kernel/module_param.rs | 48 +++++++++++++++++++++++++++++++++++++ rust/macros/module.rs | 42 +++++++++++++++++++++++++------- 2 files changed, 81 insertions(+), 9 deletions(-) diff --git a/rust/kernel/module_param.rs b/rust/kernel/module_param.rs index 80fe8643c0ab..67ff6f2ea9c2 100644 --- a/rust/kernel/module_param.rs +++ b/rust/kernel/module_param.rs @@ -86,6 +86,36 @@ pub trait ModuleParam: Sized + Copy { }) } =20 +/// Set a string module parameter from a string. +/// +/// Similar to [`set_param`] but for [`StringParam`]. +/// +/// # Safety +/// +/// Same requirements as [`set_param`]. +unsafe extern "C" fn set_string_param( + val: *const c_char, + param: *const bindings::kernel_param, +) -> c_int { + if val.is_null() { + crate::pr_warn!("Null pointer passed to `module_param::set_string_= param`"); + return EINVAL.to_errno(); + } + + crate::error::from_result(|| { + // SAFETY: val points to a valid C string from the kernel. + let cstr_param =3D unsafe { StringParam::from_ptr(val) }; + + // SAFETY: By function safety requirements, param.arg points to ou= r SetOnce. + let container =3D unsafe { &*((*param).__bindgen_anon_1.arg.cast::= >()) }; + + container + .populate(cstr_param) + .then_some(0) + .ok_or(kernel::error::code::EEXIST) + }) +} + macro_rules! impl_int_module_param { ($ty:ident) =3D> { impl ModuleParam for $ty { @@ -175,6 +205,15 @@ pub fn as_bytes(&self) -> Option<&[u8]> { unsafe impl Send for StringParam {} unsafe impl Sync for StringParam {} =20 +impl ModuleParam for StringParam { + fn try_from_param_arg(_arg: &BStr) -> Result { + // For StringParam, we don't parse here - the kernel's set callback + // directly stores the pointer. This method should not be called + // when using PARAM_OPS_STRING. + Err(EINVAL) + } +} + /// A wrapper for kernel parameters. /// /// This type is instantiated by the [`module!`] macro when module paramet= ers are @@ -249,3 +288,12 @@ 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); + +/// Parameter ops for string parameters. +#[doc(hidden)] +pub static PARAM_OPS_STRING: bindings::kernel_param_ops =3D bindings::kern= el_param_ops { + flags: 0, + set: Some(set_string_param), + get: None, + free: None, +}; diff --git a/rust/macros/module.rs b/rust/macros/module.rs index e16298e520c7..0d76743741fb 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -8,7 +8,8 @@ }; use quote::{ format_ident, - quote, // + quote, + ToTokens, // }; use syn::{ braced, @@ -120,13 +121,15 @@ fn emit_params(&mut self, info: &ModuleInfo) { =20 for param in params { let param_name_str =3D param.name.to_string(); - let param_type_str =3D param.ptype.to_string(); + let param_type_str =3D param.ptype.to_token_stream().to_string= (); + // Clean up the type string for modinfo (remove spaces around = ::) + let param_type_clean =3D param_type_str.replace(" ", ""); =20 let ops =3D param_ops_path(¶m_type_str); =20 // Note: The spelling of these fields is dictated by the user = space // tool `modinfo`. - self.emit_param("parmtype", ¶m_name_str, ¶m_type_str); + self.emit_param("parmtype", ¶m_name_str, ¶m_type_clean= ); self.emit_param("parm", ¶m_name_str, ¶m.description.va= lue()); =20 let static_name =3D format_ident!("__{}_{}_struct", self.modul= e, param.name); @@ -137,14 +140,32 @@ fn emit_params(&mut self, info: &ModuleInfo) { .expect("name contains NUL-terminator"); =20 let param_name =3D ¶m.name; - let param_type =3D ¶m.ptype; let param_default =3D ¶m.default; =20 + // `string` is a shorthand for `StringParam` in the macro =E2= =80=94 resolve to + // the real type for code generation. + let is_str_param =3D param_type_str =3D=3D "string"; + let actual_type: Type =3D if is_str_param { + parse_quote!(::kernel::module_param::StringParam) + } else { + param.ptype.clone() + }; + + // For `string` params the default is always a string literal = which + // gets wrapped with StringParam::from_c_str(kernel::c_str!(..= .)). + let default_expr =3D if is_str_param { + quote! { + ::kernel::module_param::StringParam::from_c_str(::kern= el::c_str!(#param_default)) + } + } else { + quote!(#param_default) + }; + self.param_ts.extend(quote! { #[allow(non_upper_case_globals)] pub(crate) static #param_name: - ::kernel::module_param::ModuleParamAccess<#param_type>= =3D - ::kernel::module_param::ModuleParamAccess::new(#pa= ram_default); + ::kernel::module_param::ModuleParamAccess<#actual_type= > =3D + ::kernel::module_param::ModuleParamAccess::new(#de= fault_expr); =20 const _: () =3D { #[allow(non_upper_case_globals)] @@ -186,7 +207,9 @@ fn emit_params(&mut self, info: &ModuleInfo) { } =20 fn param_ops_path(param_type: &str) -> Path { - match param_type { + let type_name =3D param_type.rsplit("::").next().unwrap_or(param_type)= .trim(); + + match type_name { "i8" =3D> parse_quote!(::kernel::module_param::PARAM_OPS_I8), "u8" =3D> parse_quote!(::kernel::module_param::PARAM_OPS_U8), "i16" =3D> parse_quote!(::kernel::module_param::PARAM_OPS_I16), @@ -197,6 +220,7 @@ fn param_ops_path(param_type: &str) -> Path { "u64" =3D> parse_quote!(::kernel::module_param::PARAM_OPS_U64), "isize" =3D> parse_quote!(::kernel::module_param::PARAM_OPS_ISIZE), "usize" =3D> parse_quote!(::kernel::module_param::PARAM_OPS_USIZE), + "string" =3D> parse_quote!(::kernel::module_param::PARAM_OPS_STRIN= G), t =3D> panic!("Unsupported parameter type {}", t), } } @@ -340,7 +364,7 @@ macro_rules! parse_ordered_fields { =20 struct Parameter { name: Ident, - ptype: Ident, + ptype: Type, default: Expr, description: LitStr, } @@ -349,7 +373,7 @@ impl Parse for Parameter { fn parse(input: ParseStream<'_>) -> Result { let name =3D input.parse()?; input.parse::()?; - let ptype =3D input.parse()?; + let ptype: Type =3D input.parse()?; =20 let fields; braced!(fields in input); --=20 2.52.0 From nobody Tue Apr 7 17:13:53 2026 Received: from mail-dy1-f174.google.com (mail-dy1-f174.google.com [74.125.82.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCADF332EC9 for ; Thu, 26 Feb 2026 23:47:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149663; cv=none; b=DZOO6YlBWtx9RyWEbfdAvur1tXk7bhc07IJnYsuQ3CqsRXMNJTMrAG0a0l4xvBDwCHbVRIK77h95Aiu3xFCQBY1rubVD5HOMPQHv1gR5U5wRgDgIpqhcIFumlrINxbVjVY8FR3eLK9nxF/NeXAEoAZ8XHMelfAOUeeWeuIbn+lE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149663; c=relaxed/simple; bh=PEStsCfUg1vck30VzbuzLY18WcACc8ezhy6sImv5QbA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UCM9e0pxFqLEyyfIr15NgzdVuVfu3V2bSDQpBH/Uhm895IhYBTpRC07p0JqfC0HGav6wOM+2EPHivmvFTiaG6fPFWrxL/GkWg/oy5YeHo6LJTBVuoZbiYY60cyZIWyMZlWxl+IRgiK4OcQoMNJSrNf2qnFnM/QVEC+P8SuWJecM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=S6f06dGg; arc=none smtp.client-ip=74.125.82.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S6f06dGg" Received: by mail-dy1-f174.google.com with SMTP id 5a478bee46e88-2bdc4f2b680so1151189eec.1 for ; Thu, 26 Feb 2026 15:47:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772149661; x=1772754461; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CL8jxHXJRXWZMH+LIIg5DtNI0nPNnxmf0FX4+vNJA2Q=; b=S6f06dGg0w8gcTAjDnQZFXinm4gT7G2IlqeGf9SbOBXlbC4O4laX551x+IMKXow3SR gk+avOwqge1Fhd641eqfxaYQqArsW2l8eeYa58wVU59hHmlxoQ8AK2+KO1WbyzLgduhs ESeLWXaYcQYro+Bq1Ooux5X1w8D6660PJgOU11W8Om0tipiGrKro1NjTDX02hi9hfvKd jxpc7pHYAHPYZatWITDmAikuGW0q4+x1rBfk16uuJzcqgtPy5JL1LwlhFIFwz4RoBbuf v9m6zq3ClKuZJvwuVxO5rddRUTjZS+7gewgKnl+3Mui044CI3irSdlbPOKTRW6dauVuW fA2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772149661; x=1772754461; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=CL8jxHXJRXWZMH+LIIg5DtNI0nPNnxmf0FX4+vNJA2Q=; b=GdL+oguOJVe0U4NYDTZjSaORTUNbhNB2R15QmEjVwGctskC+Zb9cUZ74JC5vkjktbs cUvqTqhORdr/afjmbdW0gSTMGK/rMi4gofMHx+xPy75VMjs+cXv2p1FV+WTf2YcKkjHv CFGx/s//MY+LIy3G2UKuhyS5YAiNVFUXVrQOL9LfwdI581i+1LdH4g6F7TlzaDSp0sQ8 KrpVqSI+MqGRIJsYVLL/OhTgAIXqM2QMN8e5M2QLZ0GgBCMAiW9GEXs586M0nZyeuh/N jN47tWL/2niXVmqkzG0oOj//BwCsfxAR7QCKEWRbk1bqKDXmBPSWYt47Bg8kbDXycpJm 3fgw== X-Forwarded-Encrypted: i=1; AJvYcCXdMK6BJ0tTdj3pXgtZYWljcI+nUpiKRGR0FNMQZcG/Jgzfvh3qD2hk2YQYmUmh4WnlvZZK5g2+G5bHMPM=@vger.kernel.org X-Gm-Message-State: AOJu0Yx/MOP04qbywX84lkBYAg6Qs3C3xrBHnmccrlado/6MPWQ/bcpf tvMGfO3uf/D5LvrnYDksopZMfmw5elhdk4CuaVHdRAWoD5bgJMm6TQEB X-Gm-Gg: ATEYQzyKwQpLKpF88Bpm+U91phy1JDZZ2CK+sgbQFwqDBs8mKHh8kOnKm3ZAGv9P/QT JqWI8w4eOtee3RQagP92BswIjpm4B4i8nZBf1Xs94dUJ5694TJQZgQlSNEa2PXfR42g6tBrtSKQ 3Y4htAxIL9wgH0BaldZNvUYoChpBvHuynvX7g1y+FSe4BgpksrweqhumBmpQFPHnTQArzRXVf1w AEeL2zNF2f63/znbHkk2e3fRhEthmO+4bMGTFAA75qBQq4bKUj9DO8g/DNmFFsJWlI47kte5jUQ mqxjVXflZN09RIwSZg1uLx5o0sSWtD7fIbqd635XBYRfs+3SGapWC1eqOvE+erNYUjL/HaX1Jxx B1+7Vz1yL7b5Z0l3w3wLLAV4wB3DQ8GVXPxNJId6Y7QUX/NwgPaPtGpiO55aFQ8tGXHt5CcLy2s NwgDu7Jy8OIQQ9SYOcmlyQwoXURofpqqQSzc0wz66fUyQNz/uNrBPfJQ0wg7H1NRzvwPpIOCF5X A== X-Received: by 2002:a05:7300:538e:b0:2b0:5b6b:6529 with SMTP id 5a478bee46e88-2bde1ff2aedmr322221eec.39.1772149660935; Thu, 26 Feb 2026 15:47:40 -0800 (PST) Received: from localhost (99-122-55-39.lightspeed.sntcca.sbcglobal.net. [99.122.55.39]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2bdd1f49d96sm2726909eec.27.2026.02.26.15.47.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 15:47:40 -0800 (PST) From: Matthew Wood To: Miguel Ojeda , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen Cc: Aaron Tomlin , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Tamir Duberstein , David Gow , =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= , linux-modules@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/8] samples: rust_minimal: demonstrate string module parameter Date: Thu, 26 Feb 2026 15:47:29 -0800 Message-ID: <20260226234736.428341-4-thepacketgeek@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260226234736.428341-1-thepacketgeek@gmail.com> References: <20260226234736.428341-1-thepacketgeek@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a `test_str` string parameter alongside the existing integer parameter (renamed from `test_parameter` to `test_int` for clarity) in the rust_minimal sample module. The init function now prints both parameters to the kernel log, showing how string parameters are declared, defaulted, and read back via StringParam::as_cstr(). Also add module-level documentation showing usage via insmod and kernel command-line with dotted notation. Signed-off-by: Matthew Wood --- samples/rust/rust_minimal.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/samples/rust/rust_minimal.rs b/samples/rust/rust_minimal.rs index 8eb9583571d7..59955e95e31a 100644 --- a/samples/rust/rust_minimal.rs +++ b/samples/rust/rust_minimal.rs @@ -1,6 +1,23 @@ // SPDX-License-Identifier: GPL-2.0 =20 //! Rust minimal sample. +//! +//! This is a sample module written in Rust. It is intended to be a minimal +//! example of how to write a module in Rust. It does not do anything usef= ul, +//! except print a message when it is loaded and unloaded. +//! +//! It provides examples of how to receive module parameters, which can be= provided +//! by the user when the module is loaded: +//! +//! ``` +//! insmod /lib/modules/$(uname -r)/kernel/samples/rust/rust_minimal.ko te= st_int=3D2 test_str=3Dworld +//! ``` +//! +//! or via kernel cmdline with module dotted notation (when built-in and n= ot built as a module): +//! +//! ``` +//! ... rust_minimal.test_int=3D2 rust_minimal.test_str=3Dworld ... +//! ``` =20 use kernel::prelude::*; =20 @@ -11,10 +28,14 @@ description: "Rust minimal sample", license: "GPL", params: { - test_parameter: i64 { + test_int: i64 { default: 1, description: "This parameter has a default of 1", }, + test_str: string { + default: "hello", + description: "This parameter has a default of hello", + } }, } =20 @@ -26,9 +47,13 @@ impl kernel::Module for RustMinimal { fn init(_module: &'static ThisModule) -> Result { pr_info!("Rust minimal sample (init)\n"); pr_info!("Am I built-in? {}\n", !cfg!(MODULE)); + pr_info!("test_int: {}\n", *module_parameters::test_int.value()); pr_info!( - "test_parameter: {}\n", - *module_parameters::test_parameter.value() + "test_str: {}\n", + module_parameters::test_str + .value() + .as_cstr() + .expect("test_str has a default value") ); =20 let mut numbers =3D KVec::new(); --=20 2.52.0 From nobody Tue Apr 7 17:13:53 2026 Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D13693358CD for ; Thu, 26 Feb 2026 23:47:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149665; cv=none; b=Lf84GCte4cdZBhFO9w5QvF02cAQlcNQSPL+/6W2oArAnZ1XUx0sfdA9VKIv0hgg40n1ptGKJGqOuzPBiHgn1y2tb25aR6cnmx2xntI8FVw7NyOzD2U2X+2C4jd8hkzoLeBXaPhTXvt10493a+2kg1ThNY1g3CzeItt/QKMUWY90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149665; c=relaxed/simple; bh=diXsuT8eJT5nS1aZMe0HRgaFMpWk5Il6lizUmS70zew=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nKDCbFXec5DrEL/L9HquMI9f53Zbj+RUxcQrSi/8SBanrDxjxUjAOQZGggYWULxs/Rashxi0SqpHIGcGflJ512TsT1X5iseyLqJ4rTm6XE+yXEtwKddTSYcLgzW//5yABG1xPXFgnpApicHw7A2zULPsabu59FNggTx8QwXtS8w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MbVjp91i; arc=none smtp.client-ip=74.125.82.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MbVjp91i" Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-2bdbe434b47so3203724eec.1 for ; Thu, 26 Feb 2026 15:47:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772149662; x=1772754462; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q5i5WdejKaPItbRozzcqSDHdFPHSAvpyQt6V3+kxZMw=; b=MbVjp91i58IBWrvZ0bLFpMYkO/UcDLmdXT9lKTCa6RotSYujw4CdXcboon5KWNvbqj vxpSvORZD42q0gbcK8La/s7Mjis8KKRSNQiPJnB84hAY0Gt4e7109nwryPmP/Ul5PMkZ r+H0YR8AM3G1JKA+CcJXUBa3+pbzIn212FiKjAXy5FrHccnQEmEMq8r7xF4bZRf5RFT6 4BiXRcysP1p3gA8jveORAOpc17K66x8ESQqTzYji1FhNVlMF/jkPtI7f2WKbNjqMfJE4 luB2qrmvBzSAWL7iMvaYKTAmH3cfEMfYtH7vFOH9xpMAzS3DeFiB3q6JcYvGXIypVxFh sv+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772149662; x=1772754462; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Q5i5WdejKaPItbRozzcqSDHdFPHSAvpyQt6V3+kxZMw=; b=gBrYT/XKb0eo6D1A5IvRnbBop7Rs63U0h2SJW8zmL8hr778gpz2W2P4BDUB0tU56uF 0joH9UwmI+n5MFq+0KKasKmRzmgmktqtoBtRDOGp2aM+9iF67j60MF2gF3xfKBp0NrmD fGJyTnHIVaETKRThqR9KN2+Cgzagg1ArWPtTgw/uKi7Fip1B06PxqRrquSeSqtoVTcyi cRbdaOznhVxkduPCqmJnFawS9FXlBgYDG37zARmOGVB8ZBc/HUCZhuoUq7NTMEmcT2ht KdZNrHOWqVLS00/3+6rWHllsAl2nVmmsX+6v2GnRpUtemt0WBeN7077E9Z7UiwSQjCVn xQgQ== X-Forwarded-Encrypted: i=1; AJvYcCUVJQHCMcvLbgjowLr0EHnKvAVVQzTZIHXd7lvHOWeqBGtPox4qqMh4+I1C+RuLc3GzyNzVtOJYr98Fyu0=@vger.kernel.org X-Gm-Message-State: AOJu0YwwmB0xvmgI6d8DUy4FoWdy3Ko+uH40yKlrxv0p+Pd0KiauJUt0 kPBOlSZT9pjYMxbQdfwbxha3RXH2H5AgNOdOkQQ2iE+6n98KrKMQyIap X-Gm-Gg: ATEYQzxBQnrtdCX1vILLoFa2NDCCQcRSn/W+IxuZHCaUATL6m+xnPYUolOHCEKO8fPf GQgagqzOfE/qt0qBOzyMLBDP9FJOYiKEOdtbSzmC1VKh+kHSUuce1Qb+4E89YCVJoGELxUPUbLd iHUfrpynHW9WLinnVP7z4lBhAj3JR6R/3MbJ4gw1TlIfEUxKEdvrRAcAH8Q5tJJoWrcaO9H2Mtv rI207fJs82Gr1KWEZaubBY9bKbppWWTa02tGL/TzBB5Jbome/ZJ7t23t2VoteN2RzyLVN8zUqvp QPugxuxFjW9ZzZg9+L93DdPERa59rT6tewR8lN3pV+KmkXMukVx3ObCLlqRGwoam2Ga29HQPLF6 Rqgc/ulXU1YcUAN2sE1jROSQXKwkMoiNAcmMMOpxXHR5WZ6hGhW4FcW2RtrMbHHb30YoepbEyr9 5RKSYnq7Qoj/wbhuoMC1t/LHXRStOZL/NN3HPOX06AZH00q45KS6+OSz4KL0AGNYkW/XCGyro1U A== X-Received: by 2002:a05:693c:2c97:b0:2b8:64ad:ad4d with SMTP id 5a478bee46e88-2bde1d32ceemr413421eec.26.1772149661991; Thu, 26 Feb 2026 15:47:41 -0800 (PST) Received: from localhost (99-122-55-39.lightspeed.sntcca.sbcglobal.net. [99.122.55.39]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2bdd1f23c0csm2819777eec.22.2026.02.26.15.47.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 15:47:41 -0800 (PST) From: Matthew Wood To: Miguel Ojeda , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen Cc: Aaron Tomlin , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Tamir Duberstein , David Gow , =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= , linux-modules@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/8] rust: module_param: add ObsKernelParam type Date: Thu, 26 Feb 2026 15:47:30 -0800 Message-ID: <20260226234736.428341-5-thepacketgeek@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260226234736.428341-1-thepacketgeek@gmail.com> References: <20260226234736.428341-1-thepacketgeek@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add ObsKernelParam, a #[repr(C)] struct that mirrors the C obs_kernel_param structure used by the __setup / early_param infrastructure to register boot-time command-line handlers. The struct contains: - str_: pointer to the null-terminated setup string - setup_func: the callback invoked when the kernel parses the matching command-line token - early: flag distinguishing early_param (1) from __setup (0) Mark it Sync because instances are written at compile time and only read during single-threaded early boot initialization. This type will be used by the module! macro to emit __setup entries in the .init.setup ELF section in subsequent patches. Signed-off-by: Matthew Wood --- rust/kernel/module_param.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/rust/kernel/module_param.rs b/rust/kernel/module_param.rs index 67ff6f2ea9c2..54379a2bba51 100644 --- a/rust/kernel/module_param.rs +++ b/rust/kernel/module_param.rs @@ -26,6 +26,20 @@ pub const fn new(val: bindings::kernel_param) -> Self { // from Rust module. unsafe impl Sync for KernelParam {} =20 +/// Placed in the `.init.setup` ELF section by the `module!` macro. +#[repr(C)] +pub struct ObsKernelParam { + /// Pointer to the null-terminated setup string (e.g., `"netconsole=3D= \0"`). + pub str_: *const c_char, + /// The setup callback function. + pub setup_func: Option c_int>, + /// Whether this is an early parameter (0 for `__setup`, 1 for `early_= param`). + pub early: c_int, +} + +// SAFETY: Only written at compile time, read during single-threaded boot = init. +unsafe impl Sync for ObsKernelParam {} + /// Types that can be used for module parameters. // NOTE: This trait is `Copy` because drop could produce unsoundness durin= g teardown. pub trait ModuleParam: Sized + Copy { --=20 2.52.0 From nobody Tue Apr 7 17:13:53 2026 Received: from mail-dl1-f49.google.com (mail-dl1-f49.google.com [74.125.82.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39C45337B8C for ; Thu, 26 Feb 2026 23:47:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149665; cv=none; b=t+E92yMhDsGIRY5percixBHSN3FpPJypGaEh3o110z24YDS/Ph9wMJL13vLxUftInnuVPxLKCI+3zCmlUIwPpLk26DANzEDZLXctSGLclebzwtL+y6nWt5cwZ14q5hWMcgGuPzYH45BomOcXvHn84taCd0G/7outT96W/5EtLKo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149665; c=relaxed/simple; bh=RHn2hmvCm9HqGAs0R0Q7MI+s5iIBHQPJjHJ3TmmUVZg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ufSTCwrB+GWo83lk+oYQPjG1jnvM5/qoCczF4HBV9CdbA/+fGw0TJkxAcSHlMaM+3o1RtXkRfFmkh+0Cx872cxcP0UWEQVOe5XNUnkp9KdTvybyRkRLnK8/lFOUgNSRdRo0VtzvisRqZStNSr7c0nSOk7yB2PeZFrMgi59M9Ui0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=T5xbapxx; arc=none smtp.client-ip=74.125.82.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="T5xbapxx" Received: by mail-dl1-f49.google.com with SMTP id a92af1059eb24-1271195d2a7so2598258c88.0 for ; Thu, 26 Feb 2026 15:47:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772149663; x=1772754463; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sNVcpj/MlR6xmLdrStuL7mU5hg7ztc2Pvj8nGgrDXrY=; b=T5xbapxxHxmnGx3MweLRwo6oFS9rU/w4h0p6yhze7NFBa1KKwaQJfOQGu8XmUTdJsQ iKU2J8UvnfKTm97ky0id3EbMHfoCQIyMo+u9k4QzZi+jOgZQ10279SpFIjpWFYJEa/vz HoTD4ixtcRN78AS7HaSVhP7UAY4PJlUhCkc1m9Ry+aHHDCD4GxRLcOp166SK565PYYyE wR+ux/xxGSsRZX1+JiwGGCMbXPaTXmTAE2dkTgQkTL3mZAjlGmJ1LaOMfdyz8plNTvnr Bsv63Vcfn6RoIE9UhvPcRXfnwOAGH6tWNkvvBJbK7Xf0k/Hl7qQfCReYougKQZoBWzWm aJrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772149663; x=1772754463; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=sNVcpj/MlR6xmLdrStuL7mU5hg7ztc2Pvj8nGgrDXrY=; b=EksHmohsFzsRF0wx3mkeIjgA3F5oO9WDtzFWUttC+mFhiEPumP1ghr217k+YAR6Lv7 hZyQSjRUs/dCjfw2Q/aZm1XhqomN2Hp30I7CkCXPnc8Bx/bLw+jIKa7xoudj/w3IoRZW UIWSUnxXPyNPIUCo+7RHU7ggEte/+Xg+VRD+Ah4MiJaZJBugaFyI52cHWdle4Y5A7+yd DcdscGRTDqydxPRh1rrDUMCHRmnA/X3/ZHoYlayWYEvDrHINoP7dPQEvJiEVTmXPzNzK 9dyreCSanF2+ABrR9UNP/C5hXGq+g23jVwf6NJz4yhBPyu0tT6OpVTI5a/iULgp6hsR7 cbFg== X-Forwarded-Encrypted: i=1; AJvYcCVwPHHWE++F9uigc2jE1YA7esFhM0ikuP5ubZD/Tk9ZGGIwcd89qC39v9NA6h0TIQ9/uTlOfLfNAzQd968=@vger.kernel.org X-Gm-Message-State: AOJu0YyG6lnD9ClAj5l6yX5hZgDqe+BTSLgjl4ACzU8Z4RXSX205Q4i4 dizawqcm7q/IFJkjkouao6RFyznsSJvxEgXpXAIrkzLvv03bW42mKy0/ X-Gm-Gg: ATEYQzwbD8vCSb2HoUyHFZkqT+lO6LLeTeyIhIjhwbiZvqe5X2dy2Jy5RYeydP0urUD g7kGOGLP/iC2uVmRJjO81W64frg2MwV6nQmyVU4zgC2uXYJ9TI6YMkBIw1c9HEDGVcr3Y4rXTDI YhpxA5Hbf1bfpfbXLeupelgyPJINq7TaEKah0thXsLh5x4/kAJBqKgwcy4hDrVRNPNmH4ak/EMU rzbRAcdvLsDIyCBUuRAwUKLYzy8kpo4Mhi4nDG7wA6JtI6afMJE2qEJemdSI273+t9q3+x8uR2A WM9LzN0OccmlCVAOq5YnNcdiuWf8AVKpOTBbazNwoy1wqGWjsLtf7kMwy0Yq6AhZXrDSxunO6sN kIN9cwTCLVntIlEE96V5X+5Q6K+L8lsfRgKVkbymhDx4eJhRt3XCVTWLUP19CY5GYtjTjlYyeAM tN+M+PjdXcsWdYPZEwryrkfzQM/uLwjr1+9Ap2KQE3U4YFmJvPmGW0ZOn04wt5VlTSJjeBdB/1B w== X-Received: by 2002:a05:7022:6986:b0:124:a4cf:ce90 with SMTP id a92af1059eb24-1278fc288e8mr352535c88.1.1772149663234; Thu, 26 Feb 2026 15:47:43 -0800 (PST) Received: from localhost (99-122-55-39.lightspeed.sntcca.sbcglobal.net. [99.122.55.39]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12789a5312dsm3296029c88.16.2026.02.26.15.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 15:47:42 -0800 (PST) From: Matthew Wood To: Miguel Ojeda , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen Cc: Aaron Tomlin , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Tamir Duberstein , David Gow , =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= , linux-modules@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/8] rust: module_param: add from_setup_arg() to ModuleParam trait Date: Thu, 26 Feb 2026 15:47:31 -0800 Message-ID: <20260226234736.428341-6-thepacketgeek@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260226234736.428341-1-thepacketgeek@gmail.com> References: <20260226234736.428341-1-thepacketgeek@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Extend the ModuleParam trait with from_setup_arg(), which constructs a parameter value from a raw C string pointer received via a __setup callback during early boot. The default implementation converts the pointer to a CStr and delegates to try_from_param_arg(), which handles the parse-from-string path used by integer types. StringParam overrides this method to store the raw pointer directly without parsing, since the pointer originates from static_command_line and remains valid for the kernel's lifetime. Also add ModuleParamAccess::set_value() to allow the __setup callback generated by the module! macro to populate the SetOnce container with first-write-wins semantics. Signed-off-by: Matthew Wood --- rust/kernel/module_param.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/rust/kernel/module_param.rs b/rust/kernel/module_param.rs index 54379a2bba51..5e14dbe03865 100644 --- a/rust/kernel/module_param.rs +++ b/rust/kernel/module_param.rs @@ -45,6 +45,21 @@ unsafe impl Sync for ObsKernelParam {} pub trait ModuleParam: Sized + Copy { /// Parse a parameter argument into the parameter value. fn try_from_param_arg(arg: &BStr) -> Result; + + /// Create a parameter value from a raw `__setup` callback argument. + /// + /// Default implementation: parse the null-terminated C string via + /// [`ModuleParam::try_from_param_arg`]. `StringParam` overrides this = to store the pointer + /// directly. + /// + /// # Safety + /// + /// `val` must point to a valid null-terminated string. + unsafe fn from_setup_arg(val: *const c_char) -> Result { + // SAFETY: Caller guarantees `val` points to a valid null-terminat= ed string. + let cstr =3D unsafe { CStr::from_char_ptr(val) }; + Self::try_from_param_arg(cstr.as_ref()) + } } =20 /// Set the module parameter from a string. @@ -226,6 +241,12 @@ fn try_from_param_arg(_arg: &BStr) -> Result { // when using PARAM_OPS_STRING. Err(EINVAL) } + + unsafe fn from_setup_arg(val: *const c_char) -> Result { + // SAFETY: Caller guarantees `val` points to a valid null-terminat= ed string. + // The pointer comes from `static_command_line` which is valid for= the kernel's lifetime. + Ok(unsafe { StringParam::from_ptr(val) }) + } } =20 /// A wrapper for kernel parameters. @@ -266,6 +287,14 @@ pub fn value(&self) -> &T { pub const fn as_void_ptr(&self) -> *mut c_void { core::ptr::from_ref(self).cast_mut().cast() } + + /// Set the parameter value directly. + /// + /// Returns `true` if successfully set, `false` if already populated + /// (first-write-wins semantics via [`SetOnce`]). + pub fn set_value(&self, val: T) -> bool { + self.value.populate(val) + } } =20 #[doc(hidden)] --=20 2.52.0 From nobody Tue Apr 7 17:13:53 2026 Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70A8333A6EC for ; Thu, 26 Feb 2026 23:47:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149667; cv=none; b=s3xBgwiH9kVRTVlrvbu+la9/afdIj8fXqixCNZVVZjC6CyJejdL55yGXElJogzTE5EbZ4V0KIyjpEANt2XGd3lCl4bcLwOtdpfrRD51IZA/ArRKa0XXB3zFamWmfSTaymEzr4iy2HlC8U+j5xciTzPAUGJ9OZ4GA35Eto86lmjU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149667; c=relaxed/simple; bh=xFtVJPjb1lCf06i8AWnkVR51MqrSe6UEn+2i41YDHgE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hYwah+nRsXWTbIYpXtJERGEGSQrW4/uYhL0IGY/fj/UN/KCcJzAshF3fOsFAnT50hJC+FZ4PN5VyLKYuk6yV1VxpFMexFRT6+QMyclxj279K7S3pu3tdH9NZhlvm7Ns+BdCAVPdVLE0lpfKROD0z+QovAdItAeEZO+m6VT9ob8M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=K9nqjOSA; arc=none smtp.client-ip=74.125.82.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K9nqjOSA" Received: by mail-dy1-f172.google.com with SMTP id 5a478bee46e88-2bdcfbd0779so1699913eec.0 for ; Thu, 26 Feb 2026 15:47:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772149665; x=1772754465; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EpIeoheh9kwABfSNbiyNPrL4mJinCWikDVLVci1HHt8=; b=K9nqjOSAih+SH5bFtlfEcL/2quri6A8287JDxDswMn7HZkmxlZ0QRiwFxjqmEUhi2Z vlQhI0h9PapS2uOqs7oVZJBZaxdJ4qGEpdHPQi8mdEKSVLktvPP0CLzlUTuKj9DZ2mGP fOCaSLlZre906qf3nWTN2i9ahuCXEmO5Ptu4NHKKJ7iIo8HJKXrLooJHqdqZI3T+OCvs ajcHKnxaUgQXlQw/RXIk9EyWlZneH2aTT8Tcux0qC/efNSwP5tRUpWdyLt0suMWUdaiC Ug83Ni+N87mC0m3vsq5pyxVmj6gulTjtFaDBqhWhP11J5v5PdU+VszWpcsB+W9Cmzwvv onqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772149665; x=1772754465; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=EpIeoheh9kwABfSNbiyNPrL4mJinCWikDVLVci1HHt8=; b=DLLZ5GZXMQ2d3P7eCyWDCnBWf29vI9Kyrd7Wor4X11S7pT1PpVnlWdlRxATt2bNS0B jqruy09E8KiS6YC0VB+XJFJQKbLTzhUaLSunDrlBF2FuHP48cUVtaSjAPoL0BOEfJztQ pu3e4oiWTg04TDv03VjXbMN2ytAPyhtXUZwmi6M5R5RSvtS7YK7aViJCcqWSsjHqUBvj zJFI9KRHvhdrdIxrfXn9RGfxlDR4DOLRC6TJypscgI+SgPAI+DgwW2rCMarC4V9eOqka tSGIY8zHCuoK3T3rc35OU5oTAid/ua6nftU9gIdRmuPgTHvbeyMq9lAhnCiNte+fu9sM h8lA== X-Forwarded-Encrypted: i=1; AJvYcCV1LRkTwFnUpL5YJ7bS8okQu/t+tjK2FT1os4GE0teB5bALvsCYMOtSsD4Xm87N6yFT9+h4b24/mv/1hCA=@vger.kernel.org X-Gm-Message-State: AOJu0YwvH19p7aJTRoJTHmQBn7ttdT4dBH9OevtmgzTzgm+hL6dpjMY6 7ehgRkTpWR3x9O8eT+SoeEF33Wye91/Dc/FjnojpylmdFe7zEYVHYeQP X-Gm-Gg: ATEYQzwsSZH7X2Y5vAwO4HjO/SebKOD7TBNfD/gXqPTD2yhowJaJWkmvJ3/+VbsDuyM K4Mmz2lvPhsomJv6oolqthg8OA/ski+/UG5baBMr/H0k8Y6QF5VaGw7uoa92ijPQmWYExOPvLuY k4KOa/AZqyUUKOYrpaYNmiH1FLjw6qKU0DCGoeycaYLr3j6Pr3qQ+Cu8j42VMZGxiadzH0Xs6RC 74iHv7jhgOC1sG3X5faG0IjTi31zYRrQKnrskGwXkdzZTnGJtJWm05ZCV/O4MkYVIEjf5EsUVAF PDkmlIEIcfxtjQcndJR5ST8cHyloYIpVLCsbnhrekuyOeABfVBT6QkHApBDAWjgtz15OyuIk7K7 zBgTrUNh/85jQQ0vFcTZFdJiwDw2KXFjmkN67qnjeKb+jIUkM+lWfrR6tPxsMsiHOFZJKNvHRf5 DruBpuRY2/kXKPTqN/nYLP9EJqRj9YOYlDUiMXpg4ndrR7bAGEiGFheFi9bulIaKAUpoI46qtMc g== X-Received: by 2002:a05:7300:3b24:b0:2ba:75f5:72a2 with SMTP id 5a478bee46e88-2bde1b4def2mr341086eec.2.1772149664426; Thu, 26 Feb 2026 15:47:44 -0800 (PST) Received: from localhost (99-122-55-39.lightspeed.sntcca.sbcglobal.net. [99.122.55.39]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2bdd1f23be8sm2683786eec.20.2026.02.26.15.47.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 15:47:44 -0800 (PST) From: Matthew Wood To: Miguel Ojeda , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen Cc: Aaron Tomlin , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Tamir Duberstein , David Gow , =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= , linux-modules@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/8] rust: macros: add early_param support to module! macro Date: Thu, 26 Feb 2026 15:47:32 -0800 Message-ID: <20260226234736.428341-7-thepacketgeek@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260226234736.428341-1-thepacketgeek@gmail.com> References: <20260226234736.428341-1-thepacketgeek@gmail.com> 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 Allow module parameters to be registered as early boot command-line parameters via the existing __setup infrastructure. Add an optional `early_param` field to the parameter block in the module! macro. When specified, the macro generates: - A setup callback that calls ModuleParam::from_setup_arg() and stores the result via ModuleParamAccess::set_value(). - A static string in .init.rodata with the command-line prefix. - An ObsKernelParam entry in the .init.setup section linking the two together. The generated code is gated behind #[cfg(not(MODULE))] since __setup parameters are only meaningful for built-in modules =E2=80=94 loadable modu= les receive their parameters through the standard module_param mechanism. Signed-off-by: Matthew Wood --- rust/macros/lib.rs | 5 +++ rust/macros/module.rs | 81 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs index 0c36194d9971..83dcc89a425a 100644 --- a/rust/macros/lib.rs +++ b/rust/macros/lib.rs @@ -35,9 +35,14 @@ /// parameter_name: type { /// default: default_value, /// description: "Description", +/// early_param: "cmdline_prefix=3D", // optional /// } /// ``` /// +/// The optional `early_param` field registers the parameter as an early +/// boot command-line parameter via `__setup`. The value is the command-li= ne +/// prefix string (e.g. `"netconsole=3D"`). +/// /// `type` may be one of /// /// - [`i8`] diff --git a/rust/macros/module.rs b/rust/macros/module.rs index 0d76743741fb..4d2e144fa6de 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -38,6 +38,7 @@ struct ModInfoBuilder<'a> { counter: usize, ts: TokenStream, param_ts: TokenStream, + setup_ts: TokenStream, } =20 impl<'a> ModInfoBuilder<'a> { @@ -47,6 +48,7 @@ fn new(module: &'a str) -> Self { counter: 0, ts: TokenStream::new(), param_ts: TokenStream::new(), + setup_ts: TokenStream::new(), } } =20 @@ -204,6 +206,78 @@ fn emit_params(&mut self, info: &ModuleInfo) { }); } } + + fn emit_setup(&mut self, info: &ModuleInfo) { + let Some(params) =3D &info.params else { + return; + }; + + for param in params { + let Some(early_param) =3D ¶m.early_param else { + continue; + }; + + let setup_str_value =3D early_param.value(); + let param_name =3D ¶m.name; + + // Resolve `string` shorthand to the real `StringParam` type. + let param_type_str =3D param.ptype.to_token_stream().to_string= (); + let actual_type: Type =3D if param_type_str =3D=3D "string" { + parse_quote!(::kernel::module_param::StringParam) + } else { + param.ptype.clone() + }; + + // Create identifiers for the generated statics + let setup_fn_name =3D format_ident!("__setup_fn_{}", param_nam= e); + let setup_str_name =3D + format_ident!("__SETUP_STR_{}", param_name.to_string().to_= uppercase()); + let setup_name =3D format_ident!("__SETUP_{}", param_name.to_s= tring().to_uppercase()); + + // The setup string with null terminator + let setup_str_bytes =3D format!("{}\0", setup_str_value); + let setup_str_len =3D setup_str_bytes.len(); + let setup_str_lit =3D Literal::byte_string(setup_str_bytes.as_= bytes()); + + self.setup_ts.extend(quote! { + #[cfg(not(MODULE))] + const _: () =3D { + unsafe extern "C" fn #setup_fn_name( + val: *mut ::kernel::ffi::c_char, + ) -> ::kernel::ffi::c_int { + if val.is_null() { + return 0; + } + // SAFETY: The kernel passes a valid null-terminat= ed string from + // `static_command_line`. + match unsafe { + <#actual_type as ::kernel::module_param::Modul= eParam>::from_setup_arg( + val as *const _ + ) + } { + Ok(v) =3D> { + if module_parameters::#param_name.set_valu= e(v) { 1 } else { 0 } + } + Err(_) =3D> 0, + } + } + + #[link_section =3D ".init.rodata"] + #[used(compiler)] + static #setup_str_name: [u8; #setup_str_len] =3D *#set= up_str_lit; + + #[link_section =3D ".init.setup"] + #[used(compiler)] + static #setup_name: ::kernel::module_param::ObsKernelP= aram =3D + ::kernel::module_param::ObsKernelParam { + str_: #setup_str_name.as_ptr().cast(), + setup_func: ::core::option::Option::Some(#setu= p_fn_name), + early: 0, + }; + }; + }); + } + } } =20 fn param_ops_path(param_type: &str) -> Path { @@ -367,6 +441,7 @@ struct Parameter { ptype: Type, default: Expr, description: LitStr, + early_param: Option, } =20 impl Parse for Parameter { @@ -382,6 +457,7 @@ fn parse(input: ParseStream<'_>) -> Result { from fields; default [required] =3D> fields.parse()?, description [required] =3D> fields.parse()?, + early_param =3D> fields.parse()?, } =20 Ok(Self { @@ -389,6 +465,7 @@ fn parse(input: ParseStream<'_>) -> Result { ptype, default, description, + early_param, }) } } @@ -501,9 +578,11 @@ pub(crate) fn module(info: ModuleInfo) -> Result { modinfo.emit_only_builtin("file", &file, false); =20 modinfo.emit_params(&info); + modinfo.emit_setup(&info); =20 let modinfo_ts =3D modinfo.ts; let params_ts =3D modinfo.param_ts; + let setup_ts =3D modinfo.setup_ts; =20 let ident_init =3D format_ident!("__{ident}_init"); let ident_exit =3D format_ident!("__{ident}_exit"); @@ -678,5 +757,7 @@ unsafe fn __exit() { mod module_parameters { #params_ts } + + #setup_ts }) } --=20 2.52.0 From nobody Tue Apr 7 17:13:53 2026 Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E83D33B962 for ; Thu, 26 Feb 2026 23:47:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149667; cv=none; b=ASyndkXn8FdZawPhKWmhC1tBJhny8P/cE8vCWfJDOAFBreqJhMoxKUs89TBmPg3u+RIb8NukQaKbnws7tBVejWrtq5Pr9hYXHwNLPIfH+uahvMdTZJUPx+IBFSU3DeMCJp5kQxZ70nisaJpCv/Kdrgt3xqnv67LJt3R6Yg+ZtG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149667; c=relaxed/simple; bh=BAjK7gWmE8NiqPCEPZ+0Bww+M+TFsGuQf188GGuI7Ds=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uwQwwvSgUa5oT7ns4gh7kXpb0u55g5nLKs8FprzIzQzBhLzusOmgTeTotBmsrGIUMETLfgE/y00R1j6gNoVX63lax7VDoTUo7snPy8XFjbZ5ZVw1R3kK9ojDWGlIOvs1sBTIbA1WIAmv/zr2UEQtDUB70zSPtIiOEWn+n9pqcNs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fxuvrRSh; arc=none smtp.client-ip=74.125.82.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fxuvrRSh" Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-2bdcfbd0779so1699926eec.0 for ; Thu, 26 Feb 2026 15:47:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772149666; x=1772754466; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gpoHH7pwXOlyNuoaXWey7x0lvhL7U9SeoRRb6VtCgvw=; b=fxuvrRShfPuZ7Rr+Hm8Bxm9iS2163sSdeJ/UcrXVi28FZy4u+Mwvj7uMERRHMReCdP jHh9+thhpxFomJ7FPNjnqkUVdfHwvVX04ifguXiVwQYguS4tLazoflfbLte+7lpzz8z6 6N6GM+J2+hxnkiEcSPCMnHUAMuVYun2F+GeMXr7Q3tMQNIxg2g7du95c8BZKvXVhp4II Oh8RSH3sreziq/gHLwIKjdlgPMmiJ36OhNuIEBJOl/s8cXM59eFEjav8cjlhYVHyFm1P ApvAEtKc1Pyds5gr41DsybndVaDWFyNRj0YqBM12nhfr6z8Pk1NpWCUAJwpsV5cPu6Y1 zr9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772149666; x=1772754466; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=gpoHH7pwXOlyNuoaXWey7x0lvhL7U9SeoRRb6VtCgvw=; b=Y3AyaaLx3HIji96zXzeeyk+//Uhd3pXiEmTP1V+fF3XEz6eBR/BXLGVTHqZjxvILxJ ALxDK3a7FlHEHnfz626Odh4IrlrHNmgDT6qjaPTQ2eqYPh35g9NEir4KgrrphHwhutk+ GVOnOBS/mCHWa3Z8twEHcBZzAorXc9oHsGeAiTDRBelbLB9/LjfhiWufA6C/ba1pwNpQ EWTbtaQvysGMqx0OzrbUWDU5sEYte9j6I4gnrEPkTVRbuuH0e0xymEGkRYdcYXYnyol7 dv5nXqPiShwwfKGU+zvoV4+74Mc8yanWQDBBNE4eNgkcCIUpOVd1U4N/4erF0717oRlQ /rFQ== X-Forwarded-Encrypted: i=1; AJvYcCV2g4fsSC5+ycVoHYgoX5BDe5GqnC3FaTOZaXfWu1QNCQVNAuNzCP7L3mMMMkHoth10/pEJ0OK4Ee43YQU=@vger.kernel.org X-Gm-Message-State: AOJu0YygvIySP9ogX9/iw6wkXja1QzPy+lVO88n7whFjx6ymlwFmTeN0 y7mYfloek0gU1BoX4beqXjqquRLn2E1knZ8zv//Lx8mcjpArcuEYJePI X-Gm-Gg: ATEYQzxCElv3/xH9MIMb9yczXMmXYkURUISgZwl93id1FF/JpPVtguCt3PjXknHjR9T PBEWlMn82Stv3hkQaAX7VRSzTmEr2M/xHHZGRPz/68lHDmj2+j81mb/cbSr3vHWJ9cP2j3Xtkbb yQOoIoXICS87xr9KxMnnZataYAI8IVjW7iFmD/fi00MREcefdSS5Oa3gmhjUDF1kSz4AnHkeD13 vjs+crugO6OE9icn9/WN4mJgUbPk0yYVc2dKt8L5gV+oyFVM8ChY9dCBoXv01bCEbQo7gVrZnQU AoAX2qAcHaYUU6RHSN4dkItEWnXviCIwNue0bqVLpCcV5G+VCQmeZgQC/BLD3wwJD3huVOYr6D+ DOIDhXLT5fsT7WxiZcGcnV83z4Nb1/PhEB6wlFeHHqly3Jr56KyUMYGQ9L6zoHep6oLx7lDFrqE ME0OzPEi9TL6DI/y5Dx2B6dtOMRng1fh5qXl66vkRoHswgfLvbJdXOih8bGRKc5KmOYGidycAQb Q== X-Received: by 2002:a05:7300:640c:b0:2b7:95d5:3a32 with SMTP id 5a478bee46e88-2bde1b4dd2cmr411625eec.1.1772149665577; Thu, 26 Feb 2026 15:47:45 -0800 (PST) Received: from localhost (99-122-55-39.lightspeed.sntcca.sbcglobal.net. [99.122.55.39]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2bdd1bcdd95sm2776586eec.6.2026.02.26.15.47.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 15:47:45 -0800 (PST) From: Matthew Wood To: Miguel Ojeda , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen Cc: Aaron Tomlin , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Tamir Duberstein , David Gow , =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= , linux-modules@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/8] samples: rust_minimal: demonstrate early_param usage Date: Thu, 26 Feb 2026 15:47:33 -0800 Message-ID: <20260226234736.428341-8-thepacketgeek@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260226234736.428341-1-thepacketgeek@gmail.com> References: <20260226234736.428341-1-thepacketgeek@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add an early_param annotation to the test_str parameter in the rust_minimal sample module, registering it as "testing_early_str=3D" on the kernel command line. When the module is built-in, this allows the parameter to be set directly on the boot command line without dotted module notation: testing_early_str=3Dworld Signed-off-by: Matthew Wood --- samples/rust/rust_minimal.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/rust/rust_minimal.rs b/samples/rust/rust_minimal.rs index 59955e95e31a..9fc0c0a864d3 100644 --- a/samples/rust/rust_minimal.rs +++ b/samples/rust/rust_minimal.rs @@ -35,6 +35,8 @@ test_str: string { default: "hello", description: "This parameter has a default of hello", + // This will allow the arg to be used in kernel cmdline withou= t dotted notation + early_param: "testing_early_str=3D", } }, } --=20 2.52.0 From nobody Tue Apr 7 17:13:53 2026 Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9863E33D517 for ; Thu, 26 Feb 2026 23:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149672; cv=none; b=oZA/pw6mhUjtktBDaS2fVRobW88uzwacdcyvptbyz2n6QZNCRyGjHKM8sitrUv84l6uNfo+lOAeo0UI9jqc4syE9lwXt8Z8E+IcoZBmU9NVQ/xYV8ejao925BJgj+bM5BAye4GROprst/xTZ7Ev1DapAtRuz0GQe9MnS3ENOWqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149672; c=relaxed/simple; bh=eHSd6gZAgAs99aURB/P61YrQaeqSUqKmTJDHpVJAJgk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=spmgjRHD1nxZHD9T9BWtRC1LKOth+YU6wy45Ce+X2CwsnfogrTbCwkoxNBc5l6QLCV5ADEViWEY0qwtfOmAZvpNIRWfjPpj3zHjBD56eI5gHxidZN4Mi5/Zp8XtlWS+xHnxi2AQO8m9AUP1xrtk8UYMjLuneA+VO1PTfNv0Ssb4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=d1Yj8Xhi; arc=none smtp.client-ip=74.125.82.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d1Yj8Xhi" Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-2bdc47747e2so1217828eec.0 for ; Thu, 26 Feb 2026 15:47:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772149667; x=1772754467; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=a9Hb2iavLuCFwRbZcUJdleryz74/Q+xg8WkVXrxCwXo=; b=d1Yj8XhiNEDcSEBMYSPG0iltvoIdKiu6FndiVhVCztvqTMN/sLm5yehkw+AbZaL2RT 6gDYQEEdSPjmh7kU9quk2KhOVHvYP4al2ENNvlFxF31NrA9uDeoN/krSBa4Xicaaj3SY FkVkZb1SEh3y7CGEnIH46f+tFbHfFxe8ZfUlmcwXT4oXlMSKtMtcU4i4Ml/HH7dT98nj n20IupGAK7iFGvKdoe79DnElTMpMo3XEDLNxVLlzfCcESZZu1Wm7a58TJxr9q7tapJjy rftfIX6+3GsEq2WEU//+z1iVOZqXpSt7pUvQnYSoVbiNOJgItjQfB+lopPxJJSedmu7k OBIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772149667; x=1772754467; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=a9Hb2iavLuCFwRbZcUJdleryz74/Q+xg8WkVXrxCwXo=; b=wzRhzmz36rIwqMx6NE67aXV4P4hxCabtG7A9T9RkmdNqC8mzCRO39WGy7Xt6JRJEA8 f4Q7mVrHPUzL5IEBEofL5FiQFg9YM+L9EP/nusDgmcq0SM/dP+byXkB+oby4N0ssZKxV nBV8cR9lFcIMorgde82x4O9vCV2dpDgTY14kJEisHnAeh11i/IjG3qvZ3UpMbSqiRkxw NPAdDpIBk+AQG6qqzwb1oq1niY3fcrsP1xjN+SUI4NRhQZbXxGXGGOQEj7K/FX4yzH8R bDFjLTsOpwz2JxiussciF+/42VIJYveG9a9D7YsdKxoSQPLoGtamH57510h47AJWLDwR hEuQ== X-Forwarded-Encrypted: i=1; AJvYcCWclU2T5rUAzN5/6KLLairwS6w/9iZzN1I7ijA37pf/ENQMdiGv0oGXZUunwrBio7gGhkpSKXj7Iyy2iLw=@vger.kernel.org X-Gm-Message-State: AOJu0YyKcCvPQkTREIsFJr/PteDaFkYcYkPC38WQStzag98igmyg5Y1z qACD7e1z/ZVyR0qBncryjRqjYCz570ui7Rn4d0EDpxaKKrwGMLP14xeb X-Gm-Gg: ATEYQzzBCPo+Aqunbs7FjUdLjafSVvp0R8SVNgCAiGVC2gFfBcHJF4EoknBc82wAuzM QEJQwxUPrPzjGa288w8zrsmBawrcV+oS2/bRGLpVoDvE2//S/0XPdNbVKOM7MTlXGvNVLEirow7 Ec8Zgiu2po8FYAJxy3ReNd8o4lGfB6EU7za+/gNo5SF4srpaTyCs95HlZJHA3g2i+kxbiTatG3I iusjBOsXNmX3sZTWimHkImmJ2mXQBhQmHcFLtUIz6xHr5V+iFDbPwsNasC1EAAPRwvOpy/QS7HY bT204tGC51WFlsQObCxY9U1C3zC1zdzTWSA7WSlrhSs33+3fmYahAs/yMiZhpynhoFE63yJyq6z E/WW2GMa7pv6gfQEcH5mpzkdVxe0uE0p0iZ4FWrvueN3QCm9KZoUYEpG+hXj7Kgs4au+kgoFGo5 T2zHQGcVlmbRPVKF3dB66vAsZN3uTKofRstJGxyjUoRKlCr8Gp878M8OHDGK9Wy3tZfCKvf/937 w== X-Received: by 2002:a05:7300:fb89:b0:2ba:72c3:53c0 with SMTP id 5a478bee46e88-2bde16c8443mr353009eec.0.1772149666732; Thu, 26 Feb 2026 15:47:46 -0800 (PST) Received: from localhost (99-122-55-39.lightspeed.sntcca.sbcglobal.net. [99.122.55.39]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2bdd1bce276sm2849248eec.3.2026.02.26.15.47.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 15:47:46 -0800 (PST) From: Matthew Wood To: Miguel Ojeda , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen Cc: Aaron Tomlin , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Tamir Duberstein , David Gow , =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= , linux-modules@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 8/8] rust: macros: add configurable initcall levels to module! macro Date: Thu, 26 Feb 2026 15:47:34 -0800 Message-ID: <20260226234736.428341-9-thepacketgeek@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260226234736.428341-1-thepacketgeek@gmail.com> References: <20260226234736.428341-1-thepacketgeek@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently all Rust modules using the module! macro are placed at initcall level 6 (device_initcall). Some modules need to initialize earlier in the boot sequence to provide services that other subsystems depend on. Add an InitCallLevel enum representing all eight standard initcall levels (pure through late) and map each to its corresponding .initcallN.init ELF section. Expose this as an optional `initcall` field in the module! macro. When omitted, the default remains level 6 (device) so existing modules are unaffected. Example usage: module! { ... initcall: subsys, } This only affects built-in modules; loadable modules always enter through init_module() regardless of the declared level. Signed-off-by: Matthew Wood --- rust/macros/lib.rs | 4 ++++ rust/macros/module.rs | 56 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs index 83dcc89a425a..cfde59e81cdd 100644 --- a/rust/macros/lib.rs +++ b/rust/macros/lib.rs @@ -135,6 +135,10 @@ /// - `alias`: array of ASCII string literals of the alias names of the = kernel module. /// - `firmware`: array of ASCII string literals of the firmware files of /// the kernel module. +/// - `initcall`: initcall level for built-in modules. Valid values are: +/// `pure` (0), `core` (1), `postcore` (2), `arch` (3), `subsys` (4), +/// `fs` (5), `device` (6, the default), and `late` (7). +/// This only affects built-in modules; loadable modules always use `i= nit_module()`. #[proc_macro] pub fn module(input: TokenStream) -> TokenStream { module::module(parse_macro_input!(input)) diff --git a/rust/macros/module.rs b/rust/macros/module.rs index 4d2e144fa6de..1e210fee4506 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -436,6 +436,53 @@ macro_rules! parse_ordered_fields { } } =20 +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum InitCallLevel { + Pure, + Core, + PostCore, + Arch, + Subsys, + Fs, + Device, + Late, +} + +impl InitCallLevel { + fn section(&self) -> &'static str { + match self { + Self::Pure =3D> ".initcall0.init", + Self::Core =3D> ".initcall1.init", + Self::PostCore =3D> ".initcall2.init", + Self::Arch =3D> ".initcall3.init", + Self::Subsys =3D> ".initcall4.init", + Self::Fs =3D> ".initcall5.init", + Self::Device =3D> ".initcall6.init", + Self::Late =3D> ".initcall7.init", + } + } +} + +impl Parse for InitCallLevel { + fn parse(input: ParseStream<'_>) -> Result { + let ident: Ident =3D input.call(Ident::parse_any)?; + match ident.to_string().as_str() { + "pure" =3D> Ok(Self::Pure), + "core" =3D> Ok(Self::Core), + "postcore" =3D> Ok(Self::PostCore), + "arch" =3D> Ok(Self::Arch), + "subsys" =3D> Ok(Self::Subsys), + "fs" =3D> Ok(Self::Fs), + "device" =3D> Ok(Self::Device), + "late" =3D> Ok(Self::Late), + _ =3D> Err(Error::new_spanned( + ident, + "invalid initcall level. Valid values are: pure, core, pos= tcore, arch, subsys, fs, device, late", + )), + } + } +} + struct Parameter { name: Ident, ptype: Type, @@ -480,6 +527,7 @@ pub(crate) struct ModuleInfo { firmware: Option>, imports_ns: Option>, params: Option>, + initcall: Option, } =20 impl Parse for ModuleInfo { @@ -515,6 +563,7 @@ fn parse(input: ParseStream<'_>) -> Result { braced!(list in input); Punctuated::parse_terminated(&list)? }, + initcall =3D> input.parse()?, ); =20 Ok(ModuleInfo { @@ -527,6 +576,7 @@ fn parse(input: ParseStream<'_>) -> Result { firmware, imports_ns, params, + initcall, }) } } @@ -542,6 +592,7 @@ pub(crate) fn module(info: ModuleInfo) -> Result { firmware, imports_ns, params: _, + initcall, } =3D &info; =20 // Rust does not allow hyphens in identifiers, use underscore instead. @@ -587,7 +638,10 @@ pub(crate) fn module(info: ModuleInfo) -> Result { let ident_init =3D format_ident!("__{ident}_init"); let ident_exit =3D format_ident!("__{ident}_exit"); let ident_initcall =3D format_ident!("__{ident}_initcall"); - let initcall_section =3D ".initcall6.init"; + let initcall_section =3D initcall + .as_ref() + .unwrap_or(&InitCallLevel::Device) + .section(); =20 let global_asm =3D format!( r#".section "{initcall_section}", "a" --=20 2.52.0