All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: zhoumin <teczm@foxmail.com>
Cc: gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org,
	linux-kernel@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: [PATCH] kobject_uevent: add uevent_helper exist check
Date: Sat, 5 Apr 2025 15:52:07 -0700	[thread overview]
Message-ID: <20250405155207.aac347bcdc56e43cb0cae3cb@linux-foundation.org> (raw)
In-Reply-To: <tencent_B971903B40AFCF5878B6532261672A5D6A0A@qq.com>

On Sat,  5 Apr 2025 01:31:02 +0800 zhoumin <teczm@foxmail.com> wrote:

> The kernel creates uevent_helper process for every uevent sent,
> even if the uevent_helper does not exist. Before the rootfs is
> mounted, a large number of events are generated. This change
> introduces uevent_helper existence check to prevent unnecessary
> operations.
> 
> Logs a debug messase before call_usermodehelper_setup.
> e.g.: pr_emerg("action:%s devpath:%s\n", action_string, devpath);
> You will see a large number of uevent_helper processes
> are attempted to be created before the rootfs is mounted.

Is there any measurable reduction in boot time?

> ...
>
> --- a/lib/kobject_uevent.c
> +++ b/lib/kobject_uevent.c
> @@ -28,6 +28,7 @@
>  #include <net/sock.h>
>  #include <net/netlink.h>
>  #include <net/net_namespace.h>
> +#include <linux/namei.h>
>  
>  
>  atomic64_t uevent_seqnum;
> @@ -58,6 +59,23 @@ static const char *kobject_actions[] = {
>  	[KOBJ_UNBIND] =		"unbind",
>  };
>  
> +#ifdef CONFIG_UEVENT_HELPER
> +static int uevent_helper_lookup(void)
> +{
> +	static int ret = -ENOENT;
> +	struct path path;
> +
> +	if (!ret)
> +		return ret;

Cached in a static variable.  So if a uevent helper later becomes
available, we won't know that and a reboot will be needed?

> +
> +	ret = kern_path(uevent_helper, LOOKUP_FOLLOW, &path);

I wonder if this is the official/preferred way of detecting the
presence of a file.

> +	if (!ret)
> +		path_put(&path);
> +
> +	return ret;
> +}
> +#endif
> +
>  static int kobject_action_type(const char *buf, size_t count,
>  			       enum kobject_action *type,
>  			       const char **args)
> @@ -610,7 +628,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
>  
>  #ifdef CONFIG_UEVENT_HELPER
>  	/* call uevent_helper, usually only enabled during early boot */
> -	if (uevent_helper[0] && !kobj_usermode_filter(kobj)) {
> +	if (uevent_helper[0] && !uevent_helper_lookup() && !kobj_usermode_filter(kobj)) {
>  		struct subprocess_info *info;
>  
>  		retval = add_uevent_var(env, "HOME=/");
> -- 
> 2.43.0

  reply	other threads:[~2025-04-05 22:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-04 17:31 [PATCH] kobject_uevent: add uevent_helper exist check zhoumin
2025-04-05 22:52 ` Andrew Morton [this message]
2025-04-06  6:19   ` zhoumin
2025-04-07  7:01     ` Greg KH
2025-04-07  7:00 ` Greg KH
2025-04-07 15:18   ` zhoumin
2025-04-07 15:35     ` Greg KH
2025-04-07 16:22       ` zhoumin

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=20250405155207.aac347bcdc56e43cb0cae3cb@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=dakr@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=teczm@foxmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.