From: Shashank Balaji <shashank.mahadasyam@sony.com>
To: "Suzuki K Poulose" <suzuki.poulose@arm.com>,
"Mike Leach" <mike.leach@linaro.org>,
"James Clark" <james.clark@linaro.org>,
"Alexander Shishkin" <alexander.shishkin@linux.intel.com>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Danilo Krummrich" <dakr@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Richard Cochran" <richardcochran@gmail.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>
Cc: Rahul Bukte <rahul.bukte@sony.com>,
linux-kernel@vger.kernel.org, coresight@lists.linaro.org,
linux-arm-kernel@lists.infradead.org,
driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org,
linux-doc@vger.kernel.org, Daniel Palmer <daniel.palmer@sony.com>,
Tim Bird <tim.bird@sony.com>
Subject: Re: [PATCH v3 1/4] kernel: param: initialize module_kset on-demand
Date: Fri, 24 Apr 2026 18:16:59 +0900 [thread overview]
Message-ID: <aes1C8oJs3Vxnj6y@JPC00244420> (raw)
In-Reply-To: <20260422-acpi_mod_name-v3-1-a184eff9ff6f@sony.com>
On Wed, Apr 22, 2026 at 06:49:03PM +0900, Shashank Balaji wrote:
> module_kset is initialized in param_sysfs_init(), a subsys_initcall. A number
> of platform drivers register themselves prior to subsys_initcalls. With an
> upcoming patch ("driver core: platform: set mod_name in driver registration")
> that sets their mod_name in struct device_driver, lookup_or_create_module()
> will be called for those drivers, which calls kset_find_object(module_kset, mod_name).
> This fails because module_kset isn't alive yet.
>
> Fix this by initializing module_kset on-demand in lookup_or_create_module().
> Retain the param_sysfs_init() subsys_initcall to ensure that module_kset is
> live after subsys_initcalls (assuming no OOM) for any users who may need it,
> on the off chance that it wasn't init'd on-demand because of no
> pre-subsys_initcall drivers.
>
> This on-demand path can trigger before subsys_initcall. kset_create_and_add()
> be should safe in those contexts because the allocator is up and running by then,
> no userspace to start uevent helper or listen to a uevent socket.
>
> Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Co-developed-by: Rahul Bukte <rahul.bukte@sony.com>
> Signed-off-by: Rahul Bukte <rahul.bukte@sony.com>
> Signed-off-by: Shashank Balaji <shashank.mahadasyam@sony.com>
>
> ---
>
> Patch 3 depends on this patch.
> ---
> kernel/params.c | 41 +++++++++++++++++++++++++----------------
> 1 file changed, 25 insertions(+), 16 deletions(-)
>
> diff --git a/kernel/params.c b/kernel/params.c
> index 74d620bc2521..f25d6fda159c 100644
> --- a/kernel/params.c
> +++ b/kernel/params.c
> @@ -745,6 +745,26 @@ void module_param_sysfs_remove(struct module *mod)
> }
> #endif
>
> +static int uevent_filter(const struct kobject *kobj)
> +{
> + const struct kobj_type *ktype = get_ktype(kobj);
> +
> + if (ktype == &module_ktype)
> + return 1;
> + return 0;
> +}
> +
> +static const struct kset_uevent_ops module_uevent_ops = {
> + .filter = uevent_filter,
> +};
> +
> +static struct kset *__init_or_module ensure_module_kset(void)
> +{
> + if (!module_kset)
> + module_kset = kset_create_and_add("module", &module_uevent_ops, NULL);
> + return module_kset;
> +}
Sashiko's review [1]:
Could this cause a race condition if multiple threads try to initialize
module_kset concurrently?
If asynchronous driver registration triggers this path concurrently before
subsys_initcalls, is it possible for both threads to see module_kset as NULL:
Thread 1
if (!module_kset)
module_kset = kset_create_and_add("module", &module_uevent_ops, NULL);
/* Succeeds and assigns a valid kset */
Thread 2
if (!module_kset)
module_kset = kset_create_and_add("module", &module_uevent_ops, NULL);
/* Fails due to duplicate name and returns NULL */
If Thread 2 overwrites module_kset with NULL after Thread 1 succeeds, wouldn't
this orphan the kset created by Thread 1 and cause all subsequent callers to
fail? Does this initialization need synchronization to prevent this?
While all pre-subsys_initcall platform driver registration happens
synchronously now, on the boot cpu, asynchronous registration may be
introduced in the future which would silently break this patch. Either
way, it would be better to be safe with a mutex.
I also noticed another problem with this patch: kset_create_and_add() is
called as long as module_kset is not set. So in the case of OOM, init
will be attempted as long as it succeeds, even beyond subsys_initcall.
While the current behaviour is to init only in subsys_initcall.
Both of these can be fixed with a DO_ONCE_SLEEPABLE-based
initialization.
[1] https://sashiko.dev/#/patchset/20260422-acpi_mod_name-v3-0-a184eff9ff6f@sony.com?part=1
next prev parent reply other threads:[~2026-04-24 9:17 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 6:02 [PATCH v2 0/2] Enable sysfs module symlink for more built-in drivers Shashank Balaji
2026-04-21 6:02 ` [PATCH v2 1/2] kernel: param: handle NULL module_kset in lookup_or_create_module_kobject() Shashank Balaji
2026-04-21 6:27 ` Greg Kroah-Hartman
2026-04-21 14:59 ` Shashank Balaji
2026-04-21 15:20 ` Greg Kroah-Hartman
2026-04-21 6:02 ` [PATCH v2 2/2] driver core: platform: set mod_name in driver registration Shashank Balaji
2026-04-21 6:24 ` Greg Kroah-Hartman
2026-04-22 9:49 ` [PATCH v3 0/4] Enable sysfs module symlink for more built-in drivers Shashank Balaji
2026-04-22 9:49 ` [PATCH v3 1/4] kernel: param: initialize module_kset on-demand Shashank Balaji
2026-04-24 9:16 ` Shashank Balaji [this message]
2026-04-24 19:26 ` Gary Guo
2026-04-22 9:49 ` [PATCH v3 2/4] coresight: pass THIS_MODULE implicitly through a macro Shashank Balaji
2026-04-22 9:49 ` [PATCH v3 3/4] driver core: platform: set mod_name in driver registration Shashank Balaji
2026-04-22 9:49 ` [PATCH v3 4/4] docs: driver-api: add mod_name argument to __platform_register_drivers() Shashank Balaji
2026-04-22 11:27 ` Greg Kroah-Hartman
2026-04-27 2:41 ` [PATCH v4 0/4] Enable sysfs module symlink for more built-in drivers Shashank Balaji
2026-04-27 2:41 ` [PATCH v4 1/4] kernel: param: initialize module_kset before do_initcalls() Shashank Balaji
2026-04-27 2:41 ` [PATCH v4 2/4] coresight: pass THIS_MODULE implicitly through a macro Shashank Balaji
2026-04-27 2:41 ` [PATCH v4 3/4] driver core: platform: set mod_name in driver registration Shashank Balaji
2026-04-27 2:41 ` [PATCH v4 4/4] docs: driver-api: add mod_name argument to __platform_register_drivers() Shashank Balaji
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=aes1C8oJs3Vxnj6y@JPC00244420 \
--to=shashank.mahadasyam@sony.com \
--cc=a.hindborg@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=alexandre.torgue@foss.st.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=corbet@lwn.net \
--cc=coresight@lists.linaro.org \
--cc=dakr@kernel.org \
--cc=daniel.palmer@sony.com \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=james.clark@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=mcoquelin.stm32@gmail.com \
--cc=mike.leach@linaro.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rahul.bukte@sony.com \
--cc=richardcochran@gmail.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=suzuki.poulose@arm.com \
--cc=tim.bird@sony.com \
--cc=tmgross@umich.edu \
/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