mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kernfs: use nofail allocation for global locks
@ 2026-06-08  6:36 Ruoyu Wang
  2026-06-08 12:25 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Ruoyu Wang @ 2026-06-08  6:36 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Tejun Heo, driver-core, linux-kernel, Ruoyu Wang

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.

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.

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);
+	kernfs_locks = kmalloc_obj(struct kernfs_global_locks,
+				   GFP_KERNEL | __GFP_NOFAIL);
 
 	kernfs_mutex_init();
 }
-- 
2.51.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] kernfs: use nofail allocation for global locks
  2026-06-08  6:36 [PATCH] kernfs: use nofail allocation for global locks Ruoyu Wang
@ 2026-06-08 12:25 ` Greg Kroah-Hartman
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2026-06-08 12:25 UTC (permalink / raw)
  To: Ruoyu Wang; +Cc: Tejun Heo, driver-core, linux-kernel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-08 12:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-08  6:36 [PATCH] kernfs: use nofail allocation for global locks Ruoyu Wang
2026-06-08 12:25 ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®