Skip to contentSkip to conversation

devtmpfs: Add missing lockdep annotation

PATCH In review Helge Deller 2 participants 3 messages Aug 11, 2023 – Aug 12, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 devtmpfs: Add missing lockdep annotation

Add the lockdep annotation to the setup_done completer to avoid this kernel warning:

 Backtrace:
  [<000000004030bcd0>] show_stack+0x74/0xb0
  [<000000004146c63c>] dump_stack_lvl+0x104/0x180
  [<000000004146c6ec>] dump_stack+0x34/0x48
  [<000000004040e5b4>] register_lock_class+0xd24/0xd30
  [<000000004040c21c>] __lock_acquire.isra.0+0xb4/0xac8
  [<000000004040cd60>] lock_acquire+0x130/0x298
  [<000000004147095c>] _raw_spin_lock_irq+0x60/0xb8
  [<0000000041474a4c>] wait_for_completion+0xa0/0x2d0
  [<000000004015d9f4>] devtmpfs_init+0x1e0/0x2b8
  [<000000004015d0e4>] driver_init+0x68/0x1b8
  [<0000000040102b68>] kernel_init_freeable+0x4ac/0x7f0
  [<000000004146df68>] kernel_init+0x64/0x3a8
  [<0000000040302020>] ret_from_kernel_thread+0x20/0x28
drivers/base/devtmpfs.c +1 -0
index b848764ef018..f98d58b0225c 100644
@@ -462,6 +462,7 @@ int __init devtmpfs_init(void)
 		return err;
 	}
 
+	init_completion(&setup_done);
 	thread = kthread_run(devtmpfsd, &err, "kdevtmpfs");
 	if (!IS_ERR(thread)) {
 		wait_for_completion(&setup_done);
#1 lore raw
Quoted 25 lines · Helge Deller

Add the lockdep annotation to the setup_done completer to avoid this kernel warning:

 Backtrace:
  [<000000004030bcd0>] show_stack+0x74/0xb0
  [<000000004146c63c>] dump_stack_lvl+0x104/0x180
  [<000000004146c6ec>] dump_stack+0x34/0x48
  [<000000004040e5b4>] register_lock_class+0xd24/0xd30
  [<000000004040c21c>] __lock_acquire.isra.0+0xb4/0xac8
  [<000000004040cd60>] lock_acquire+0x130/0x298
  [<000000004147095c>] _raw_spin_lock_irq+0x60/0xb8
  [<0000000041474a4c>] wait_for_completion+0xa0/0x2d0
  [<000000004015d9f4>] devtmpfs_init+0x1e0/0x2b8
  [<000000004015d0e4>] driver_init+0x68/0x1b8
  [<0000000040102b68>] kernel_init_freeable+0x4ac/0x7f0
  [<000000004146df68>] kernel_init+0x64/0x3a8
  [<0000000040302020>] ret_from_kernel_thread+0x20/0x28
drivers/base/devtmpfs.c +0 -0
index b848764ef018..f98d58b0225c 100644

drivers/base/devtmpfs.c int __init devtmpfs_init(void) · line 468

Quoted 7 lines
drivers/base/devtmpfs.c +1 -0
@@ -462,6 +462,7 @@ int __init devtmpfs_init(void)
 		return err;
 	}
 
+	init_completion(&setup_done);
 	thread = kthread_run(devtmpfsd, &err, "kdevtmpfs");
 	if (!IS_ERR(thread)) {
 		wait_for_completion(&setup_done);

What changed to required this now? What commit id does this fix? Why doesn't the declaration of DECLARE_COMPLETION() initialize this properly for us already?

thanks,

greg k-h

#2 lore raw

* Greg Kroah-Hartman <[email protected]>:

Quoted 29 lines · Helge Deller
Quoted 28 lines

Add the lockdep annotation to the setup_done completer to avoid this kernel warning:

 Backtrace:
  [<000000004030bcd0>] show_stack+0x74/0xb0
  [<000000004146c63c>] dump_stack_lvl+0x104/0x180
  [<000000004146c6ec>] dump_stack+0x34/0x48
  [<000000004040e5b4>] register_lock_class+0xd24/0xd30
  [<000000004040c21c>] __lock_acquire.isra.0+0xb4/0xac8
  [<000000004040cd60>] lock_acquire+0x130/0x298
  [<000000004147095c>] _raw_spin_lock_irq+0x60/0xb8
  [<0000000041474a4c>] wait_for_completion+0xa0/0x2d0
  [<000000004015d9f4>] devtmpfs_init+0x1e0/0x2b8
  [<000000004015d0e4>] driver_init+0x68/0x1b8
  [<0000000040102b68>] kernel_init_freeable+0x4ac/0x7f0
  [<000000004146df68>] kernel_init+0x64/0x3a8
  [<0000000040302020>] ret_from_kernel_thread+0x20/0x28
drivers/base/devtmpfs.c +0 -0
index b848764ef018..f98d58b0225c 100644
@@ -462,6 +462,7 @@ int __init devtmpfs_init(void)
 		return err;
 	}
 
Quoted 8 lines

drivers/base/devtmpfs.c int __init devtmpfs_init(void) · line 468

Quoted 4 lines
drivers/base/devtmpfs.c +1 -0
+	init_completion(&setup_done);
 	thread = kthread_run(devtmpfsd, &err, "kdevtmpfs");
 	if (!IS_ERR(thread)) {
 		wait_for_completion(&setup_done);

What changed to required this now? What commit id does this fix? Why doesn't the declaration of DECLARE_COMPLETION() initialize this properly for us already?

You're right!

The problem is not the missing init_completion() call.

That part of the kernel warning indicates the real problem:
INFO: trying to register non-static key.

Lockdep uses static_obj() to check if the given lock is in "static" memory, aka inside a valid memory region: from &_stext to &_end.

The "setup_done" completer is used at bootup only, and thus located in the __initdata section. And on parisc the __initdata section is outside of the &_stext to &_end range, so the static_obj() check fails.

The patch below fixes it.
I'll send a proper patch to the mailing list in a moment.

Thanks!
Helge

kernel/locking/lockdep.c +9 -0
index 111607d91489..aa99245d8e12 100644
@@ -855,6 +855,15 @@ static int static_obj(const void *obj)
 	if (is_kernel_percpu_address(addr))
 		return 1;
 
+	/*
+	 * in initdata section and used during bootup only?
+	 * NOTE: On some platforms the initdata section is
+	 * outside of the _stext ... _end range.
+	 */
+	if (system_state < SYSTEM_FREEING_INITMEM &&
+		init_section_contains((void*)addr, 1))
+		return 1;
+
 	/*
 	 * module static or percpu var?
 	 */