kernfs: use nofail allocation for global locks
Subsystems (2)
PATCH 1/1 kernfs: use nofail allocation for global locks
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.
--- fs/kernfs/mount.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/kernfs/mount.c +2 -2
@@ -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 (); }
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerQuoted 4 lines · Ruoyu Wang
kernfs_lock_init()allocates the global kernfs lock storage during init and then callskernfs_mutex_init(), which initializes mutexes through the allocated pointer. AWARN_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? :)
Quoted 3 lines
The lock storage is required for kernfs to operate. Use a nofail
GFP_KERNELallocation so the init path does not continue without the required object.
Have you ever triggered this code path? If so, how?
Quoted 11 lines
Signed-off-by Ruoyu Wang <[email protected]>--- fs/kernfs/mount.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/kernfs/mount.c +0
-0
fs/kernfs/mount.c static void __init kernfs_mutex_init(void) · line 455
Quoted 5 lines
fs/kernfs/mount.c +0
-2@@ -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:
fs/kernfs/mount.c static void __init kernfs_mutex_init(void) · line 455
Quoted 2 lines
fs/kernfs/mount.c +2
-0+ kernfs_locks = kmalloc_obj(struct kernfs_global_locks, +GFP_KERNEL | __GFP_NOFAIL);
Will help out any, do you?
thanks,
greg k-h