Re: [PATCH] kernfs: use nofail allocation for global locks
From: Greg Kroah-Hartman
Date: Mon Jun 08 2026 - 08:36:59 EST
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@xxxxxxxxx>
> ---
> 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