Skip to contentSkip to conversation

oprofile: BUG: using smp_processor_id() in preemptible code

PATCH In review Andrea Righi 3 participants 5 messages Sep 20, 2008 – Sep 22, 2008 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 oprofile: BUG: using smp_processor_id() in preemptible code

Add local_irq_save() / local_irq_restore() before setting per cpu variable switch_index, to avoid the following BUG:

[  449.166827] BUG: using smp_processor_id() in preemptible [00000000] code: modprobe/6998
[  449.166848] caller is op_nmi_init+0xf0/0x2b0 [oprofile]
[  449.166855] Pid: 6998, comm: modprobe Not tainted 2.6.27-rc5-mm1 #29
[  449.166860] Call Trace:
[  449.166872]  [<ffffffff80362d67>] debug_smp_processor_id+0xd7/0xe0
[  449.166887]  [<ffffffffa00181c0>] op_nmi_init+0xf0/0x2b0 [oprofile]
[  449.166902]  [<ffffffffa0018000>] oprofile_init+0x0/0x60 [oprofile]
[  449.166915]  [<ffffffffa00180a9>] oprofile_arch_init+0x9/0x30 [oprofile]
[  449.166928]  [<ffffffffa001801e>] oprofile_init+0x1e/0x60 [oprofile]
[  449.166937]  [<ffffffff8020903b>] _stext+0x3b/0x160
[  449.166946]  [<ffffffff80477985>] __mutex_unlock_slowpath+0xe5/0x190
[  449.166955]  [<ffffffff80262c1a>] trace_hardirqs_on_caller+0xca/0x140
[  449.166965]  [<ffffffff8026f7fc>] sys_init_module+0xdc/0x210
[  449.166972]  [<ffffffff8020b7cb>] system_call_fastpath+0x16/0x1b
---
 arch/x86/oprofile/nmi_int.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
arch/x86/oprofile/nmi_int.c +3 -0
index d4c2f2d..2e63357 100644
@@ -520,6 +520,7 @@ int __init op_nmi_init(struct oprofile_operations *ops)
 	__u8 vendor = boot_cpu_data.x86_vendor;
 	__u8 family = boot_cpu_data.x86;
 	char *cpu_type;
+	unsigned long flags;
 	int ret = 0;
 
 	if (!cpu_has_apic)
@@ -580,7 +581,9 @@ int __init op_nmi_init(struct oprofile_operations *ops)
 	register_cpu_notifier(&oprofile_cpu_nb);
 #endif
 	/* default values, can be overwritten by model */
+	local_irq_save(flags);
 	__get_cpu_var(switch_index) = 0;
+	local_irq_restore(flags);
 	ops->create_files = nmi_create_files;
 	ops->setup = nmi_setup;
 	ops->shutdown = nmi_shutdown;
Signature · 1 line
1.5.4.3
#1 lore raw
Quoted 2 lines · Andrea Righi

Add local_irq_save() / local_irq_restore() before setting per cpu variable switch_index, to avoid the following BUG:

that just papers over the bug:

arch/x86/oprofile/nmi_int.c int __init op_nmi_init(struct oprofile_operations *ops) · line 586

Quoted 3 lines
arch/x86/oprofile/nmi_int.c +2 -0
+	local_irq_save(flags);
 	__get_cpu_var(switch_index) = 0;
+	local_irq_restore(flags);

either use __raw_get_cpu_var() if we are for sure not preemptible here, or fix the preemption status of this codepath.

Ingo

Acked-by Robert Richter
#2 lore raw
Quoted 6 lines · Ingo Molnar

Review

Quoted 3 lines
(quoted diff) +2 -0
+	local_irq_save(flags);
 	__get_cpu_var(switch_index) = 0;
+	local_irq_restore(flags);

either use __raw_get_cpu_var() if we are for sure not preemptible here, or fix the preemption status of this codepath.

i've applied the patch below instead to tip/oprofile - agreed?

Ingo

------------>

Quoted 1 line

From 45f197ade73ba95681b9803680c75352fc0a1c0a Mon Sep 17 00:00:00 2001

From: Andrea Righi <[email protected]>
Date: Sat, 20 Sep 2008 12:58:40 +0200
Subject: [PATCH] x86, oprofile: BUG: using smp_processor_id() in preemptible code

Add __raw access before setting per cpu variable switch_index, to avoid the following BUG:

[  449.166827] BUG: using smp_processor_id() in preemptible [00000000] code: modprobe/6998
[  449.166848] caller is op_nmi_init+0xf0/0x2b0 [oprofile]
[  449.166855] Pid: 6998, comm: modprobe Not tainted 2.6.27-rc5-mm1 #29
[  449.166860] Call Trace:
[  449.166872]  [<ffffffff80362d67>] debug_smp_processor_id+0xd7/0xe0
[  449.166887]  [<ffffffffa00181c0>] op_nmi_init+0xf0/0x2b0 [oprofile]
[  449.166902]  [<ffffffffa0018000>] oprofile_init+0x0/0x60 [oprofile]
[  449.166915]  [<ffffffffa00180a9>] oprofile_arch_init+0x9/0x30 [oprofile]
[  449.166928]  [<ffffffffa001801e>] oprofile_init+0x1e/0x60 [oprofile]
[  449.166937]  [<ffffffff8020903b>] _stext+0x3b/0x160
[  449.166946]  [<ffffffff80477985>] __mutex_unlock_slowpath+0xe5/0x190
[  449.166955]  [<ffffffff80262c1a>] trace_hardirqs_on_caller+0xca/0x140
[  449.166965]  [<ffffffff8026f7fc>] sys_init_module+0xdc/0x210
[  449.166972]  [<ffffffff8020b7cb>] system_call_fastpath+0x16/0x1b
---
 arch/x86/oprofile/nmi_int.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/oprofile/nmi_int.c +1 -1
index fb4902b..4108d02 100644
@@ -551,7 +551,7 @@ int __init op_nmi_init(struct oprofile_operations *ops)
 	}
 
 	/* default values, can be overwritten by model */
-	__get_cpu_var(switch_index) = 0;
+	__raw_get_cpu_var(switch_index) = 0;
 	ops->create_files = nmi_create_files;
 	ops->setup = nmi_setup;
 	ops->shutdown = nmi_shutdown;
#3 lore raw
Quoted 11 lines · Ingo Molnar
Quoted 6 lines · Ingo Molnar

Review

Quoted 3 lines
(quoted diff) +2 -0
+	local_irq_save(flags);
 	__get_cpu_var(switch_index) = 0;
+	local_irq_restore(flags);

either use __raw_get_cpu_var() if we are for sure not preemptible here, or fix the preemption status of this codepath.

i've applied the patch below instead to tip/oprofile - agreed?

Quoted 48 lines

Ingo

------------>
From 45f197ade73ba95681b9803680c75352fc0a1c0a Mon Sep 17 00:00:00 2001
From: Andrea Righi <[email protected]>
Date: Sat, 20 Sep 2008 12:58:40 +0200
Subject: [PATCH] x86, oprofile: BUG: using smp_processor_id() in preemptible code

Add __raw access before setting per cpu variable switch_index, to avoid the following BUG:

[  449.166827] BUG: using smp_processor_id() in preemptible [00000000] code: modprobe/6998
[  449.166848] caller is op_nmi_init+0xf0/0x2b0 [oprofile]
[  449.166855] Pid: 6998, comm: modprobe Not tainted 2.6.27-rc5-mm1 #29
[  449.166860] Call Trace:
[  449.166872]  [<ffffffff80362d67>] debug_smp_processor_id+0xd7/0xe0
[  449.166887]  [<ffffffffa00181c0>] op_nmi_init+0xf0/0x2b0 [oprofile]
[  449.166902]  [<ffffffffa0018000>] oprofile_init+0x0/0x60 [oprofile]
[  449.166915]  [<ffffffffa00180a9>] oprofile_arch_init+0x9/0x30 [oprofile]
[  449.166928]  [<ffffffffa001801e>] oprofile_init+0x1e/0x60 [oprofile]
[  449.166937]  [<ffffffff8020903b>] _stext+0x3b/0x160
[  449.166946]  [<ffffffff80477985>] __mutex_unlock_slowpath+0xe5/0x190
[  449.166955]  [<ffffffff80262c1a>] trace_hardirqs_on_caller+0xca/0x140
[  449.166965]  [<ffffffff8026f7fc>] sys_init_module+0xdc/0x210
[  449.166972]  [<ffffffff8020b7cb>] system_call_fastpath+0x16/0x1b
---
 arch/x86/oprofile/nmi_int.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/oprofile/nmi_int.c +1 -1
index fb4902b..4108d02 100644
@@ -551,7 +551,7 @@ int __init op_nmi_init(struct oprofile_operations *ops)
 	}
 
 	/* default values, can be overwritten by model */
-	__get_cpu_var(switch_index) = 0;
+	__raw_get_cpu_var(switch_index) = 0;
 	ops->create_files = nmi_create_files;
 	ops->setup = nmi_setup;
 	ops->shutdown = nmi_shutdown;
Signature · 3 lines
Advanced Micro Devices, Inc.
Operating System Research Center
email: [email protected]
#4 lore raw
In reply to Ingo Molnar
Quoted 11 lines · Ingo Molnar
Quoted 5 lines · Ingo Molnar

Review

Quoted 3 lines
(quoted diff) +2 -0
+	local_irq_save(flags);
 	__get_cpu_var(switch_index) = 0;
+	local_irq_restore(flags);

either use __raw_get_cpu_var() if we are for sure not preemptible here, or fix the preemption status of this codepath.

i've applied the patch below instead to tip/oprofile - agreed?

Ingo

Seems to work fine.

Thanks,
-Andrea

Quoted 45 lines

------------>
From 45f197ade73ba95681b9803680c75352fc0a1c0a Mon Sep 17 00:00:00 2001
From: Andrea Righi <[email protected]>
Date: Sat, 20 Sep 2008 12:58:40 +0200
Subject: [PATCH] x86, oprofile: BUG: using smp_processor_id() in preemptible code

Add __raw access before setting per cpu variable switch_index, to avoid the following BUG:

[  449.166827] BUG: using smp_processor_id() in preemptible [00000000] code: modprobe/6998
[  449.166848] caller is op_nmi_init+0xf0/0x2b0 [oprofile]
[  449.166855] Pid: 6998, comm: modprobe Not tainted 2.6.27-rc5-mm1 #29
[  449.166860] Call Trace:
[  449.166872]  [<ffffffff80362d67>] debug_smp_processor_id+0xd7/0xe0
[  449.166887]  [<ffffffffa00181c0>] op_nmi_init+0xf0/0x2b0 [oprofile]
[  449.166902]  [<ffffffffa0018000>] oprofile_init+0x0/0x60 [oprofile]
[  449.166915]  [<ffffffffa00180a9>] oprofile_arch_init+0x9/0x30 [oprofile]
[  449.166928]  [<ffffffffa001801e>] oprofile_init+0x1e/0x60 [oprofile]
[  449.166937]  [<ffffffff8020903b>] _stext+0x3b/0x160
[  449.166946]  [<ffffffff80477985>] __mutex_unlock_slowpath+0xe5/0x190
[  449.166955]  [<ffffffff80262c1a>] trace_hardirqs_on_caller+0xca/0x140
[  449.166965]  [<ffffffff8026f7fc>] sys_init_module+0xdc/0x210
[  449.166972]  [<ffffffff8020b7cb>] system_call_fastpath+0x16/0x1b
---
 arch/x86/oprofile/nmi_int.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/oprofile/nmi_int.c +1 -1
index fb4902b..4108d02 100644
@@ -551,7 +551,7 @@ int __init op_nmi_init(struct oprofile_operations *ops)
 	}
 
 	/* default values, can be overwritten by model */
-	__get_cpu_var(switch_index) = 0;
+	__raw_get_cpu_var(switch_index) = 0;
 	ops->create_files = nmi_create_files;
 	ops->setup = nmi_setup;
 	ops->shutdown = nmi_shutdown;