rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Alexey Gladkov" <legion@kernel.org>
Cc: "Nathan Chancellor" <nathan@kernel.org>,
	"Nicolas Schier" <nicolas.schier@linux.dev>,
	"Masahiro Yamada" <masahiroy@kernel.org>,
	"Petr Pavlu" <petr.pavlu@suse.com>,
	"Luis Chamberlain" <mcgrof@kernel.org>,
	"Sami Tolvanen" <samitolvanen@google.com>,
	"Daniel Gomez" <da.gomez@samsung.com>,
	<linux-kernel@vger.kernel.org>, <linux-modules@vger.kernel.org>,
	<linux-kbuild@vger.kernel.org>, "Miguel Ojeda" <ojeda@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	<rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH v6 6/9] modpost: Add modname to mod_device_table alias
Date: Thu, 14 Aug 2025 15:26:53 +0200	[thread overview]
Message-ID: <DC26OG2L7OMH.31RE7460D4DHU@kernel.org> (raw)
In-Reply-To: <15724fb8669dae64e3c8d31ab620f977984b2177.1755170493.git.legion@kernel.org>

On Thu Aug 14, 2025 at 3:07 PM CEST, Alexey Gladkov wrote:
> At this point, if a symbol is compiled as part of the kernel,
> information about which module the symbol belongs to is lost.
>
> To save this it is possible to add the module name to the alias name.
> It's not very pretty, but it's possible for now.
>
> Cc: Miguel Ojeda <ojeda@kernel.org>
> Cc: Andreas Hindborg <a.hindborg@kernel.org>
> Cc: Danilo Krummrich <dakr@kernel.org>
> Cc: Alex Gaynor <alex.gaynor@gmail.com>
> Cc: rust-for-linux@vger.kernel.org
> Signed-off-by: Alexey Gladkov <legion@kernel.org>
> ---
>  include/linux/module.h   | 14 +++++++++++++-
>  rust/kernel/device_id.rs |  8 ++++----
>  scripts/mod/file2alias.c | 18 ++++++++++++++----
>  3 files changed, 31 insertions(+), 9 deletions(-)
>
> diff --git a/include/linux/module.h b/include/linux/module.h
> index 3319a5269d28..e31ee29fac6b 100644
> --- a/include/linux/module.h
> +++ b/include/linux/module.h
> @@ -244,10 +244,22 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name);
>  /* What your module does. */
>  #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
>  
> +/*
> + * Format: __mod_device_table__kmod_<modname>__<type>__<name>
> + * Parts of the string `__kmod_` and `__` are used as delimiters when parsing
> + * a symbol in file2alias.c
> + */
> +#define __mod_device_table(type, name)	\
> +	__PASTE(__mod_device_table__,	\
> +	__PASTE(__KBUILD_MODNAME,	\
> +	__PASTE(__,			\
> +	__PASTE(type,			\
> +	__PASTE(__, name)))))
> +
>  #ifdef MODULE
>  /* Creates an alias so file2alias.c can find device table. */
>  #define MODULE_DEVICE_TABLE(type, name)					\
> -static typeof(name) __mod_device_table__##type##__##name		\
> +static typeof(name) __mod_device_table(type, name)			\
>    __attribute__ ((used, alias(__stringify(name))))
>  #else  /* !MODULE */
>  #define MODULE_DEVICE_TABLE(type, name)
> diff --git a/rust/kernel/device_id.rs b/rust/kernel/device_id.rs
> index 70d57814ff79..62c42da12e9d 100644
> --- a/rust/kernel/device_id.rs
> +++ b/rust/kernel/device_id.rs
> @@ -195,10 +195,10 @@ macro_rules! module_device_table {
>      ($table_type: literal, $module_table_name:ident, $table_name:ident) => {
>          #[rustfmt::skip]
>          #[export_name =
> -            concat!("__mod_device_table__", $table_type,
> -                    "__", module_path!(),
> -                    "_", line!(),
> -                    "_", stringify!($table_name))
> +            concat!("__mod_device_table__", line!(),

Why do we have line!() between "__mod_device_table__" and "__kmod_", while the
format is defined as "__mod_device_table__kmod_<modname>__<type>__<name>" above?

The previous logic was to create a unique name with
using "<module_path>_<line>_<table_name>" as "<name>". So, I think this should
actually be:

	concat!("__mod_device_table__kmod_",
		module_path!(),
		"__", $table_type,
		"__", stringify!($table_name),
		"_", line!())

rather than the below.

> +                    "__kmod_", module_path!(),
> +                    "__", $table_type,
> +                    "__", stringify!($table_name))
>          ]
>          static $module_table_name: [::core::mem::MaybeUninit<u8>; $table_name.raw_ids().size()] =
>              unsafe { ::core::mem::transmute_copy($table_name.raw_ids()) };

  reply	other threads:[~2025-08-14 13:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1755170493.git.legion@kernel.org>
2025-08-14 13:07 ` [PATCH v6 6/9] modpost: Add modname to mod_device_table alias Alexey Gladkov
2025-08-14 13:26   ` Danilo Krummrich [this message]
2025-08-14 13:54     ` Alexey Gladkov
2025-08-14 14:03       ` Danilo Krummrich
2025-08-14 21:46         ` Alexey Gladkov
2025-08-14 22:17           ` Danilo Krummrich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DC26OG2L7OMH.31RE7460D4DHU@kernel.org \
    --to=dakr@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=da.gomez@samsung.com \
    --cc=legion@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nicolas.schier@linux.dev \
    --cc=ojeda@kernel.org \
    --cc=petr.pavlu@suse.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=samitolvanen@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).