From mboxrd@z Thu Jan 1 00:00:00 1970 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 2BBA73196B7; Wed, 2 Jul 2025 15:38: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=1751470739; cv=none; b=np8b/sW5DJbEghF4od5g8YvHbPTROu6duTZaWhiocK3z97qUc4DYZcmf+9oCav+kGKy0/a1/m5fA6aXaF1WePepJB+sa3PBtBNtqAhs9x7phNRGautxOLmR2e13B3CQJmoGeThuL17+XXMm26M7kSD64dw76Uk3zTQiLbT/EX3Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751470739; c=relaxed/simple; bh=xVqRwiHfOnhpPw+h31gDQIfiWzPQzkTPHDKsQJTenlk=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=Pv1nzqsmuzR3jVEanbzj+2J1YZ8O/m7ucJjfHTEflB+Vd8aw83kZ0ilNxCghBG7YdhxQ7KLShhpi2UeM1jCliEQSzFtoQ8/d3maN8Hkj0DawcANIXe9zt2i04ab9TdwlCiXQgy5TnxFkHVE1GJQL6ljfuAd1YJ39Hzud3/svLbs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UNNpFoMT; 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="UNNpFoMT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B457C4CEE7; Wed, 2 Jul 2025 15:38:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751470738; bh=xVqRwiHfOnhpPw+h31gDQIfiWzPQzkTPHDKsQJTenlk=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=UNNpFoMT8YR6I+KL0brkWV3r48Qq6aJijXKWMfhJl5dLyiaTFKr30H5pyd6lXmdPM 17jhcdm+JMWvHinfRMczrJ7+rHiHLCjTs2xw0dt/MN2jttSNcox/7xGxqlMePQYXNo CJOgqpKkcc2TAstcvS0ZtwFbrBuJWPqDiyPcHPE2Hx2l5ml4+YMsgAm6gKQTBxKDIX 9CNO5ZxEdlPlkd5Jg/Qt8h1n64ikrKluqqs2RXql4H7QfOVE67N8KQH3LnUG6QuxT4 NdhUUkRKnPUa7hE8XpQ/5qAEzvEMagqd95jRpO1sBfktuXWI+F0X0lSzG3sRj658DS O3q2ED3uXfyYw== Precedence: bulk X-Mailing-List: linux-kbuild@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 Date: Wed, 02 Jul 2025 17:38:52 +0200 Message-Id: Cc: "Trevor Gross" , "Adam Bratschi-Kaye" , , , , "Petr Pavlu" , "Sami Tolvanen" , "Daniel Gomez" , "Simona Vetter" , "Greg KH" , "Fiona Behrens" , "Daniel Almeida" , Subject: Re: [PATCH v14 5/7] rust: module: update the module macro with module parameter support From: "Benno Lossin" To: "Andreas Hindborg" , "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Alice Ryhl" , "Masahiro Yamada" , "Nathan Chancellor" , "Luis Chamberlain" , "Danilo Krummrich" , "Nicolas Schier" X-Mailer: aerc 0.20.1 References: <20250702-module-params-v3-v14-0-5b1cc32311af@kernel.org> <20250702-module-params-v3-v14-5-5b1cc32311af@kernel.org> In-Reply-To: <20250702-module-params-v3-v14-5-5b1cc32311af@kernel.org> On Wed Jul 2, 2025 at 3:18 PM CEST, Andreas Hindborg wrote: > Allow module parameters to be declared in the rust `module!` macro. > > Signed-off-by: Andreas Hindborg A few nits below, with those fixed Reviewed-by: Benno Lossin > --- > rust/macros/helpers.rs | 25 +++++++ > rust/macros/lib.rs | 31 +++++++++ > rust/macros/module.rs | 177 +++++++++++++++++++++++++++++++++++++++++++= +++--- > 3 files changed, 223 insertions(+), 10 deletions(-) > + fn emit_params(&mut self, info: &ModuleInfo) { > + let Some(params) =3D &info.params else { > + return; > + }; > + > + for param in params { > + let ops =3D param_ops_path(¶m.ptype); > + > + // Note: The spelling of these fields is dictated by the use= r space > + // tool `modinfo`. > + self.emit_param("parmtype", ¶m.name, ¶m.ptype); > + self.emit_param("parm", ¶m.name, ¶m.description); > + > + write!( > + self.param_buffer, > + " > + pub(crate) static {param_name}: > + ::kernel::module_param::ModuleParamAccess<{param= _type}> =3D > + ::kernel::module_param::ModuleParamAccess::n= ew({param_default}); > + > + #[link_section =3D \"__param\"] > + #[used] > + static __{module_name}_{param_name}_struct: Does it make sense to move this static to a `const _: () =3D {};` block? > + ::kernel::module_param::RacyKernelParam =3D > + ::kernel::module_param::RacyKernelParam::new( > + ::kernel::bindings::kernel_param {{ > + name: if cfg!(MODULE) {{ s/cfg/::core::cfg/ :) Also there seems to only be a 2-space indentation here. > + ::kernel::c_str!(\"{param_name}\").as_by= tes_with_nul() > + }} else {{ > + ::kernel::c_str!(\"{module_name}.{param_= name}\").as_bytes_with_nul() > + }}.as_ptr(), > + // SAFETY: `__this_module` is constructed by= the kernel at load time > + // and will not be freed until the module is= unloaded. > + #[cfg(MODULE)] > + mod_: unsafe {{ > + (&::kernel::bindings::__this_module > + as *const ::kernel::bindings::module= ) > + .cast_mut() > + }}, It doesn't stop with the improvements... https://github.com/Rust-for-Linux/linux/issues/1176 Maybe we should also have one to use it here, but eh we can do that later (and it's not as bad to forget about :) > + #[cfg(not(MODULE))] > + mod_: ::core::ptr::null_mut(), > + ops: &{ops} as *const ::kernel::bindings::ke= rnel_param_ops, ::core::ptr::from_ref(&{ops}) > + perm: 0, // Will not appear in sysfs > + level: -1, > + flags: 0, > + __bindgen_anon_1: > + ::kernel::bindings::kernel_param__bindge= n_ty_1 {{ > + arg: {param_name}.as_void_ptr() > + }}, Formatting? + __bindgen_anon_1: ::kernel::bindings::kernel_p= aram__bindgen_ty_1 {{ + arg: {param_name}.as_void_ptr() + }}, --- Cheers, Benno > + }} > + ); > + ", > + module_name =3D info.name, > + param_type =3D param.ptype, > + param_default =3D param.default, > + param_name =3D param.name, > + ops =3D ops, > + ) > + .unwrap(); > + } > + } > +}