* [PATCH] drivers: base: Set mod->async_probe_requested if needed @ 2026-04-07 16:05 Bart Van Assche 2026-04-28 18:22 ` Danilo Krummrich 0 siblings, 1 reply; 4+ messages in thread From: Bart Van Assche @ 2026-04-07 16:05 UTC (permalink / raw) To: Greg Kroah-Hartman Cc: Rafael J . Wysocki, Danilo Krummrich, driver-core, Bart Van Assche, Luis Chamberlain, Petr Pavlu, Daniel Gomez, Sami Tolvanen, Aaron Tomlin, Igor Pylypiv, Chung-Kai Mei, stable If PROBE_PREFER_ASYNCHRONOUS is set for a device driver, and if loading other kernel modules depends on probing of that device driver to complete, e.g. because it is a storage driver, and if mod->async_probe_requested has not been set, then the async_synchronize_full() call in do_init_module() introduces a delay. Fix this by setting mod->async_probe_requested if PROBE_PREFER_ASYNCHRONOUS has been set. This patch reduces the Pixel 10 boot time by 100 ms. Cc: Luis Chamberlain <mcgrof@kernel.org> Cc: Petr Pavlu <petr.pavlu@suse.com> Cc: Daniel Gomez <da.gomez@kernel.org> Cc: Sami Tolvanen <samitolvanen@google.com> Cc: Aaron Tomlin <atomlin@atomlin.com> Cc: Igor Pylypiv <ipylypiv@google.com> Cc: Chung-Kai Mei <chungkai@google.com> Cc: stable@vger.kernel.org Signed-off-by: Bart Van Assche <bvanassche@acm.org> --- drivers/base/module.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/base/module.c b/drivers/base/module.c index 218aaa096455..e58fc189d389 100644 --- a/drivers/base/module.c +++ b/drivers/base/module.c @@ -39,6 +39,9 @@ int module_add_driver(struct module *mod, const struct device_driver *drv) if (!drv) return 0; + if (mod && drv->probe_type == PROBE_PREFER_ASYNCHRONOUS) + mod->async_probe_requested = true; + if (mod) mk = &mod->mkobj; else if (drv->mod_name) { ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] drivers: base: Set mod->async_probe_requested if needed 2026-04-07 16:05 [PATCH] drivers: base: Set mod->async_probe_requested if needed Bart Van Assche @ 2026-04-28 18:22 ` Danilo Krummrich 2026-04-28 19:39 ` Bart Van Assche 0 siblings, 1 reply; 4+ messages in thread From: Danilo Krummrich @ 2026-04-28 18:22 UTC (permalink / raw) To: Bart Van Assche Cc: Greg Kroah-Hartman, Rafael J . Wysocki, driver-core, Luis Chamberlain, Petr Pavlu, Daniel Gomez, Sami Tolvanen, Aaron Tomlin, Igor Pylypiv, Chung-Kai Mei, stable On Tue Apr 7, 2026 at 6:05 PM CEST, Bart Van Assche wrote: > If PROBE_PREFER_ASYNCHRONOUS is set for a device driver, and if loading > other kernel modules depends on probing of that device driver to > complete, e.g. because it is a storage driver, and if > mod->async_probe_requested has not been set, then the > async_synchronize_full() call in do_init_module() introduces a delay. > Fix this by setting mod->async_probe_requested if > PROBE_PREFER_ASYNCHRONOUS has been set. This patch reduces the Pixel 10 > boot time by 100 ms. > > Cc: Luis Chamberlain <mcgrof@kernel.org> > Cc: Petr Pavlu <petr.pavlu@suse.com> > Cc: Daniel Gomez <da.gomez@kernel.org> > Cc: Sami Tolvanen <samitolvanen@google.com> > Cc: Aaron Tomlin <atomlin@atomlin.com> > Cc: Igor Pylypiv <ipylypiv@google.com> > Cc: Chung-Kai Mei <chungkai@google.com> > Cc: stable@vger.kernel.org Why does this have Cc: stable? I think this is just an improvement and not a regression? If it is a regression, what's the commit that is fixed? > Signed-off-by: Bart Van Assche <bvanassche@acm.org> > --- > drivers/base/module.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/base/module.c b/drivers/base/module.c > index 218aaa096455..e58fc189d389 100644 > --- a/drivers/base/module.c > +++ b/drivers/base/module.c > @@ -39,6 +39,9 @@ int module_add_driver(struct module *mod, const struct device_driver *drv) > if (!drv) > return 0; > > + if (mod && drv->probe_type == PROBE_PREFER_ASYNCHRONOUS) > + mod->async_probe_requested = true; What if userspace did explicitly pass async_probe=0? > + > if (mod) > mk = &mod->mkobj; > else if (drv->mod_name) { ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drivers: base: Set mod->async_probe_requested if needed 2026-04-28 18:22 ` Danilo Krummrich @ 2026-04-28 19:39 ` Bart Van Assche 2026-04-29 21:41 ` Danilo Krummrich 0 siblings, 1 reply; 4+ messages in thread From: Bart Van Assche @ 2026-04-28 19:39 UTC (permalink / raw) To: Danilo Krummrich Cc: Greg Kroah-Hartman, Rafael J . Wysocki, driver-core, Luis Chamberlain, Petr Pavlu, Daniel Gomez, Sami Tolvanen, Aaron Tomlin, Igor Pylypiv, Chung-Kai Mei, stable On 4/28/26 11:22 AM, Danilo Krummrich wrote: > What if userspace did explicitly pass async_probe=0? Does this mean that what the user has configured should take precedence, as in the untested patch below? Thanks, Bart. diff --git a/drivers/base/module.c b/drivers/base/module.c index 218aaa096455..86f1f21a3d23 100644 --- a/drivers/base/module.c +++ b/drivers/base/module.c @@ -39,6 +39,10 @@ int module_add_driver(struct module *mod, const struct device_driver *drv) if (!drv) return 0; + if (mod && drv->probe_type == PROBE_PREFER_ASYNCHRONOUS && + mod->async_probe_requested == PROBE_TYPE_NOT_SET) + mod->async_probe_requested = PROBE_ASYNCHRONOUSLY; + if (mod) mk = &mod->mkobj; else if (drv->mod_name) { diff --git a/include/linux/module.h b/include/linux/module.h index 7566815fabbe..a946ad88c925 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -394,6 +394,12 @@ struct klp_modinfo { }; #endif +enum async_probe_type { + PROBE_TYPE_NOT_SET = 0, + PROBE_SYNCHRONOUSLY, + PROBE_ASYNCHRONOUSLY, +} __packed; + struct module { enum module_state state; @@ -442,7 +448,7 @@ struct module { bool sig_ok; #endif - bool async_probe_requested; + enum async_probe_type async_probe_requested; /* Exception table */ unsigned int num_exentries; @@ -760,7 +766,7 @@ extern void print_modules(void); static inline bool module_requested_async_probing(struct module *module) { - return module && module->async_probe_requested; + return module && module->async_probe_requested == PROBE_ASYNCHRONOUSLY; } static inline bool is_livepatch_module(struct module *mod) diff --git a/kernel/module/main.c b/kernel/module/main.c index 46dd8d25a605..9e2d9c9f65fa 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -3065,8 +3065,30 @@ void flush_module_init_free_work(void) #undef MODULE_PARAM_PREFIX #define MODULE_PARAM_PREFIX "module." /* Default value for module->async_probe_requested */ -static bool async_probe; -module_param(async_probe, bool, 0644); +static enum async_probe_type async_probe; + +static int async_probe_set(const char *val, const struct kernel_param *kp) +{ + bool async; + int ret; + + ret = kstrtobool(val, &async); + if (ret) + return ret; + async_probe = async ? PROBE_ASYNCHRONOUSLY : PROBE_SYNCHRONOUSLY; + return 0; +} + +static int async_probe_get(char *buffer, const struct kernel_param *kp) +{ + return sysfs_emit(buffer, "%d", async_probe == PROBE_ASYNCHRONOUSLY); +} + +static struct kernel_param_ops async_probe_ops = { + .set = async_probe_set, + .get = async_probe_get, +}; +module_param_cb(async_probe, &async_probe_ops, &async_probe, 0644); /* * This is where the real work happens. @@ -3135,7 +3157,7 @@ static noinline int do_init_module(struct module *mod) * See commit 0fdff3ec6d87 ("async, kmod: warn on synchronous * request_module() from async workers") for more details. */ - if (!mod->async_probe_requested) + if (mod->async_probe_requested != PROBE_ASYNCHRONOUSLY) async_synchronize_full(); ftrace_free_mem(mod, mod->mem[MOD_INIT_TEXT].base, @@ -3366,12 +3388,16 @@ static int prepare_coming_module(struct module *mod) static int unknown_module_param_cb(char *param, char *val, const char *modname, void *arg) { + bool async_probe_requested; struct module *mod = arg; int ret; if (strcmp(param, "async_probe") == 0) { - if (kstrtobool(val, &mod->async_probe_requested)) - mod->async_probe_requested = true; + if (kstrtobool(val, &async_probe_requested)) + async_probe_requested = true; + mod->async_probe_requested = async_probe_requested ? + PROBE_ASYNCHRONOUSLY : + PROBE_SYNCHRONOUSLY; return 0; } ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] drivers: base: Set mod->async_probe_requested if needed 2026-04-28 19:39 ` Bart Van Assche @ 2026-04-29 21:41 ` Danilo Krummrich 0 siblings, 0 replies; 4+ messages in thread From: Danilo Krummrich @ 2026-04-29 21:41 UTC (permalink / raw) To: Bart Van Assche Cc: Greg Kroah-Hartman, Rafael J . Wysocki, driver-core, Luis Chamberlain, Petr Pavlu, Daniel Gomez, Sami Tolvanen, Aaron Tomlin, Igor Pylypiv, Chung-Kai Mei, Luis R. Rodriguez, stable (Cc: Luis) On Tue Apr 28, 2026 at 9:39 PM CEST, Bart Van Assche wrote: > On 4/28/26 11:22 AM, Danilo Krummrich wrote: >> What if userspace did explicitly pass async_probe=0? > > Does this mean that what the user has configured should take precedence, > as in the untested patch below? Yes, but my concern actually goes beyond that (sorry for not expressing this properly right away). I think the whole reason the async_probe module parameter exists in the first place is because userspace may rely on the devices being handled by the module to be available directly after returning from the syscall. Even worse, with this patch we would make this user facing behavior dependent on an implementation detail of the driver, i.e. whether it chooses to opt into PROBE_PREFER_ASYNCHRONOUS. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-04-29 21:41 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-04-07 16:05 [PATCH] drivers: base: Set mod->async_probe_requested if needed Bart Van Assche 2026-04-28 18:22 ` Danilo Krummrich 2026-04-28 19:39 ` Bart Van Assche 2026-04-29 21:41 ` Danilo Krummrich
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox