Linux driver-core infrastructure
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Ruoyu Wang <ruoyuw560@gmail.com>
Cc: Tejun Heo <tj@kernel.org>,
	driver-core@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kernfs: use nofail allocation for global locks
Date: Mon, 8 Jun 2026 14:25:57 +0200	[thread overview]
Message-ID: <2026060819-harvest-sterility-ad7f@gregkh> (raw)
In-Reply-To: <20260608063655.69-1-ruoyuw560@gmail.com>

On Mon, Jun 08, 2026 at 02:36:55PM +0800, Ruoyu Wang wrote:
> kernfs_lock_init() allocates the global kernfs lock storage during init
> and then calls kernfs_mutex_init(), which initializes mutexes through the
> allocated pointer. A WARN_ON() does not stop execution, so allocation
> failure would still dereference NULL.

Yes, but as this never has failed, perhaps it's not a real issue?  :)

> The lock storage is required for kernfs to operate. Use a nofail
> GFP_KERNEL allocation so the init path does not continue without the
> required object.

Have you ever triggered this code path?  If so, how?

> 
> Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
> ---
>  fs/kernfs/mount.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c
> index 6e3217b6e4811..6cf8e71e5bd08 100644
> --- a/fs/kernfs/mount.c
> +++ b/fs/kernfs/mount.c
> @@ -451,8 +451,8 @@ static void __init kernfs_mutex_init(void)
>  
>  static void __init kernfs_lock_init(void)
>  {
> -	kernfs_locks = kmalloc_obj(struct kernfs_global_locks);
> -	WARN_ON(!kernfs_locks);

As this is at boot time, if this fails, and triggers and oops, the
system has much worse problems.  I do not think that:

> +	kernfs_locks = kmalloc_obj(struct kernfs_global_locks,
> +				   GFP_KERNEL | __GFP_NOFAIL);

Will help out any, do you?

thanks,

greg k-h

      reply	other threads:[~2026-06-08 12:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-08  6:36 [PATCH] kernfs: use nofail allocation for global locks Ruoyu Wang
2026-06-08 12:25 ` Greg Kroah-Hartman [this message]

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=2026060819-harvest-sterility-ad7f@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=driver-core@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ruoyuw560@gmail.com \
    --cc=tj@kernel.org \
    /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