Skip to contentSkip to conversation

init/main.c: execute lockdep_init as early as possible

PATCH In review [email protected] 4 participants 10 messages Nov 17, 2011 – Dec 6, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 init/main.c: execute lockdep_init as early as possible

From: Ming Lei <[email protected]>

This patch removes the lockdep warning[1] on ARM platform. The warning is caused by printk inside smp_setup_processor_id.

It is safe to do this because lockdep_init doesn't depend on smp_setup_processor_id, so make printk can be called as early as possible without lockdep complainment.

[1], lockdep warning

[    0.000000] WARNING: lockdep init error! Arch code didn't call
lockdep_init() early enough?
[    0.000000] Call stack leading to lockdep invocation was:
[    0.000000]  [<c00164bc>] save_stack_trace_tsk+0x0/0x90
[    0.000000]  [<ffffffff>] 0xffffffff
---
 init/main.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
init/main.c +1 -2
index 217ed23..2c76efb 100644
@@ -469,13 +469,12 @@ asmlinkage void __init start_kernel(void)
 	char * command_line;
 	extern const struct kernel_param __start___param[], __stop___param[];
 
-	smp_setup_processor_id();
-
 	/*
 	 * Need to run as early as possible, to initialize the
 	 * lockdep hash:
 	 */
 	lockdep_init();
+	smp_setup_processor_id();
 	debug_objects_early_init();
 
 	/*
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH 2/2 lockdep: print lock name for lockdep_init_error

From: Ming Lei <[email protected]>

This patch prints the name of the lock which is acquired before lockdep_init is called, so that user can easily find which lock trigged the lockdep init error warning.

This patch also removes the lockdep_init_error message of "Arch code didn't call lockdep_init() early enough?" since lockdep_init is called in arch independent code now.

---
 kernel/lockdep.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
kernel/lockdep.c +4 -1
index 4e7e672..8141317 100644
@@ -430,6 +430,7 @@ unsigned int max_lockdep_depth;
  * about it later on, in lockdep_info().
  */
 static int lockdep_init_error;
+static const char *lock_init_error;
 static unsigned long lockdep_init_trace_data[20];
 static struct stack_trace lockdep_init_trace = {
 	.max_entries = ARRAY_SIZE(lockdep_init_trace_data),
@@ -651,6 +652,7 @@ look_up_lock_class(struct lockdep_map *lock, unsigned int subclass)
 	if (unlikely(!lockdep_initialized)) {
 		lockdep_init();
 		lockdep_init_error = 1;
+		lock_init_error = lock->name;
 		save_stack_trace(&lockdep_init_trace);
 	}
 #endif
@@ -3965,7 +3967,8 @@ void __init lockdep_info(void)
 
 #ifdef CONFIG_DEBUG_LOCKDEP
 	if (lockdep_init_error) {
-		printk("WARNING: lockdep init error! Arch code didn't call lockdep_init() early enough?\n");
+		printk("WARNING: lockdep init error! lock-%s was acquired"
+			"before lockdep_init\n", lock_init_error);
 		printk("Call stack leading to lockdep invocation was:\n");
 		print_stack_trace(&lockdep_init_trace, 0);
 	}
Signature · 1 line
1.7.5.4
#2 lore raw

Re: [PATCH 2/2] lockdep: print lock name for lockdep_init_error

Quoted 5 lines · On Thu, Nov 17, 2011 at 01:34:32PM +0800, [email protected] wrote:

From: Ming Lei <[email protected]>

This patch prints the name of the lock which is acquired before lockdep_init is called, so that user can easily find which lock trigged the lockdep init error warning.

Should we care about that?

I think lockdep_init() called early enough give more hint. Such as be the first C function called by arch.

Thanks,
Yong

Quoted 48 lines

This patch also removes the lockdep_init_error message of "Arch code didn't call lockdep_init() early enough?" since lockdep_init is called in arch independent code now.

---
 kernel/lockdep.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
kernel/lockdep.c +4 -1
index 4e7e672..8141317 100644
@@ -430,6 +430,7 @@ unsigned int max_lockdep_depth;
  * about it later on, in lockdep_info().
  */
 static int lockdep_init_error;
+static const char *lock_init_error;
 static unsigned long lockdep_init_trace_data[20];
 static struct stack_trace lockdep_init_trace = {
 	.max_entries = ARRAY_SIZE(lockdep_init_trace_data),
@@ -651,6 +652,7 @@ look_up_lock_class(struct lockdep_map *lock, unsigned int subclass)
 	if (unlikely(!lockdep_initialized)) {
 		lockdep_init();
 		lockdep_init_error = 1;
+		lock_init_error = lock->name;
 		save_stack_trace(&lockdep_init_trace);
 	}
 #endif
@@ -3965,7 +3967,8 @@ void __init lockdep_info(void)
 
 #ifdef CONFIG_DEBUG_LOCKDEP
 	if (lockdep_init_error) {
-		printk("WARNING: lockdep init error! Arch code didn't call lockdep_init() early enough?\n");
+		printk("WARNING: lockdep init error! lock-%s was acquired"
+			"before lockdep_init\n", lock_init_error);
 		printk("Call stack leading to lockdep invocation was:\n");
 		print_stack_trace(&lockdep_init_trace, 0);
 	}
Signature · 7 lines
1.7.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Signature · 1 line
Only stand for myself
author
#3 lore raw

Re: [PATCH 2/2] lockdep: print lock name for lockdep_init_error

Hi,

Thanks for your review.

Quoted 8 lines · Yong Zhang
Quoted 5 lines · On Thu, Nov 17, 2011 at 01:34:32PM +0800, [email protected] wrote:

From: Ming Lei <[email protected]>

This patch prints the name of the lock which is acquired before lockdep_init is called, so that user can easily find which lock trigged the lockdep init error warning.

Should we care about that?

Yes, we should, see below.

Quoted 3 lines

I think lockdep_init() called early enough give more hint. Such as be the first C function called by arch.

Maybe not early enough, before start_kernel is executed, arch asm code still can call some C function, can't it?

The patch is just an improvement on original lockdep_init_error detect, plus fix on incorrect debug message.

thanks,

Signature · 1 line
Ming Lei
#4 lore raw

Re: [PATCH 2/2] lockdep: print lock name for lockdep_init_error

Quoted 14 lines · Ming Lei

Hi,

Thanks for your review.

Quoted 8 lines · Yong Zhang
Quoted 5 lines · On Thu, Nov 17, 2011 at 01:34:32PM +0800, [email protected] wrote:

From: Ming Lei <[email protected]>

This patch prints the name of the lock which is acquired before lockdep_init is called, so that user can easily find which lock trigged the lockdep init error warning.

Should we care about that?

Quoted 8 lines

Yes, we should, see below.

Quoted 3 lines

I think lockdep_init() called early enough give more hint. Such as be the first C function called by arch.

Maybe not early enough, before start_kernel is executed, arch asm code still can call some C function, can't it?

To me that still means 'Arch code didn't call lockdep_init() early enough'.

But anyway, let Peter/Ingo decide it.

Thanks,
Yong

#5 lore raw

Re: [PATCH 2/2] lockdep: print lock name for lockdep_init_error

Quoted 6 lines · Yong Zhang

On Thu, Nov 17, 2011 at 04:01:16PM +0800, Ming Lei wrote:

To me that still means 'Arch code didn't call lockdep_init() early enough'.

But anyway, let Peter/Ingo decide it.

I kinda like the hint as to what might have ran too early, so I've queued it.

#6 lore raw

Re: [PATCH 2/2] lockdep: print lock name for lockdep_init_error

In reply to [email protected]
Quoted 20 lines · On 17/11/11 16:34, [email protected] wrote:

From: Ming Lei <[email protected]>

This patch prints the name of the lock which is acquired before lockdep_init is called, so that user can easily find which lock trigged the lockdep init error warning.

This patch also removes the lockdep_init_error message of "Arch code didn't call lockdep_init() early enough?" since lockdep_init is called in arch independent code now.

---
 kernel/lockdep.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
kernel/lockdep.c +0 -0
index 4e7e672..8141317 100644

kernel/lockdep.c unsigned int max_lockdep_depth; · line 433

Quoted 4 lines
kernel/lockdep.c +1 -0
@@ -430,6 +430,7 @@ unsigned int max_lockdep_depth;
  * about it later on, in lockdep_info().
  */
 static int lockdep_init_error;
+static const char *lock_init_error;

You can now remove lockdep_init_error and just test against lock_init_error below instead.

~Ryan

Quoted 21 lines
kernel/lockdep.c +3 -1
 static unsigned long lockdep_init_trace_data[20];
 static struct stack_trace lockdep_init_trace = {
 	.max_entries = ARRAY_SIZE(lockdep_init_trace_data),
@@ -651,6 +652,7 @@ look_up_lock_class(struct lockdep_map *lock, unsigned int subclass)
 	if (unlikely(!lockdep_initialized)) {
 		lockdep_init();
 		lockdep_init_error = 1;
+		lock_init_error = lock->name;
 		save_stack_trace(&lockdep_init_trace);
 	}
 #endif
@@ -3965,7 +3967,8 @@ void __init lockdep_info(void)
 
 #ifdef CONFIG_DEBUG_LOCKDEP
 	if (lockdep_init_error) {
-		printk("WARNING: lockdep init error! Arch code didn't call lockdep_init() early enough?\n");
+		printk("WARNING: lockdep init error! lock-%s was acquired"
+			"before lockdep_init\n", lock_init_error);
 		printk("Call stack leading to lockdep invocation was:\n");
 		print_stack_trace(&lockdep_init_trace, 0);
 	}
#7 lore raw

[tip:core/locking] lockdep: Print lock name in lockdep_init_error()

In reply to [email protected]
Commit-ID:  81140acc66322dcde8346dabdf1ab4c229fce8d4
Gitweb:     http://git.kernel.org/tip/81140acc66322dcde8346dabdf1ab4c229fce8d4
Author:     Ming Lei <[email protected]>
AuthorDate: Thu, 17 Nov 2011 13:34:32 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 6 Dec 2011 08:16:55 +0100

lockdep: Print lock name in lockdep_init_error()

This patch prints the name of the lock which is acquired before lockdep_init() is called, so that users can easily find which lock triggered the lockdep init error warning.

This patch also removes the lockdep_init_error() message of "Arch code didn't call lockdep_init() early enough?" since lockdep_init() is called in arch independent code now.

---
 kernel/lockdep.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
kernel/lockdep.c +4 -1
index 54cc0dc..e69d633 100644
@@ -431,6 +431,7 @@ unsigned int max_lockdep_depth;
  * about it later on, in lockdep_info().
  */
 static int lockdep_init_error;
+static const char *lock_init_error;
 static unsigned long lockdep_init_trace_data[20];
 static struct stack_trace lockdep_init_trace = {
 	.max_entries = ARRAY_SIZE(lockdep_init_trace_data),
@@ -657,6 +658,7 @@ look_up_lock_class(struct lockdep_map *lock, unsigned int subclass)
 	if (unlikely(!lockdep_initialized)) {
 		lockdep_init();
 		lockdep_init_error = 1;
+		lock_init_error = lock->name;
 		save_stack_trace(&lockdep_init_trace);
 	}
 #endif
@@ -3978,7 +3980,8 @@ void __init lockdep_info(void)
 
 #ifdef CONFIG_DEBUG_LOCKDEP
 	if (lockdep_init_error) {
-		printk("WARNING: lockdep init error! Arch code didn't call lockdep_init() early enough?\n");
+		printk("WARNING: lockdep init error! lock-%s was acquired"
+			"before lockdep_init\n", lock_init_error);
 		printk("Call stack leading to lockdep invocation was:\n");
 		print_stack_trace(&lockdep_init_trace, 0);
 	}
Reviewed-by on v1 1/2
#8 lore raw
In reply to [email protected]
Quoted 9 lines · On Thu, Nov 17, 2011 at 01:34:31PM +0800, [email protected] wrote:

From: Ming Lei <[email protected]>

This patch removes the lockdep warning[1] on ARM platform. The warning is caused by printk inside smp_setup_processor_id.

It is safe to do this because lockdep_init doesn't depend on smp_setup_processor_id, so make printk can be called as early as possible without lockdep complainment.

Quoted 8 lines

[1], lockdep warning

[    0.000000] WARNING: lockdep init error! Arch code didn't call
lockdep_init() early enough?
[    0.000000] Call stack leading to lockdep invocation was:
[    0.000000]  [<c00164bc>] save_stack_trace_tsk+0x0/0x90
[    0.000000]  [<ffffffff>] 0xffffffff

Seems start_kernel() is the first C function called in arm. IOW, this may be the simplest way for your issue.

Quoted 31 lines
---
 init/main.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
init/main.c +1 -2
index 217ed23..2c76efb 100644
@@ -469,13 +469,12 @@ asmlinkage void __init start_kernel(void)
 	char * command_line;
 	extern const struct kernel_param __start___param[], __stop___param[];
 
-	smp_setup_processor_id();
-
 	/*
 	 * Need to run as early as possible, to initialize the
 	 * lockdep hash:
 	 */
 	lockdep_init();
+	smp_setup_processor_id();
 	debug_objects_early_init();
 
 	/*
Signature · 7 lines
1.7.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Signature · 1 line
Only stand for myself
#9 lore raw

[tip:core/locking] init/main.c: Execute lockdep_init() as early as possible

In reply to [email protected]
Commit-ID:  73839c5b2eacc15cb0aa79c69b285fc659fa8851
Gitweb:     http://git.kernel.org/tip/73839c5b2eacc15cb0aa79c69b285fc659fa8851
Author:     Ming Lei <[email protected]>
AuthorDate: Thu, 17 Nov 2011 13:34:31 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 6 Dec 2011 08:16:53 +0100

init/main.c: Execute lockdep_init() as early as possible

This patch fixes a lockdep warning on ARM platforms:

  [    0.000000] WARNING: lockdep init error! Arch code didn't call lockdep_init() early enough?
  [    0.000000] Call stack leading to lockdep invocation was:
  [    0.000000]  [<c00164bc>] save_stack_trace_tsk+0x0/0x90
  [    0.000000]  [<ffffffff>] 0xffffffff

The warning is caused by printk inside smp_setup_processor_id().

It is safe to do this because lockdep_init() doesn't depend on smp_setup_processor_id(), so improve things that printk can be called as early as possible without lockdep complaint.

---
 init/main.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
init/main.c +1 -2
index 217ed23..2c76efb 100644
@@ -469,13 +469,12 @@ asmlinkage void __init start_kernel(void)
 	char * command_line;
 	extern const struct kernel_param __start___param[], __stop___param[];
 
-	smp_setup_processor_id();
-
 	/*
 	 * Need to run as early as possible, to initialize the
 	 * lockdep hash:
 	 */
 	lockdep_init();
+	smp_setup_processor_id();
 	debug_objects_early_init();
 
 	/*