MIPS: Protect current_cpu_data with preempt disable in delay()
PATCH 1/1 MIPS: Protect current_cpu_data with preempt disable in delay()
During machine restart with reboot command, get the following bug info:
BUG: using smp_processor_id() in preemptible [00000000] code: reboot/1989 caller is __udelay+0x14/0x70 Call Trace: [<ffffffff8110ad28>] dump_stack+0x8/0x34 [<ffffffff812dde04>] debug_smp_processor_id+0xf4/0x110 [<ffffffff812d90bc>] __udelay+0x14/0x70 [<ffffffff81378274>] md_notify_reboot+0x12c/0x148 [<ffffffff81161054>] notifier_call_chain+0x64/0xc8 [<ffffffff811614dc>] __blocking_notifier_call_chain+0x64/0xc0 [<ffffffff8115566c>] kernel_restart_prepare+0x1c/0x38 [<ffffffff811556cc>] kernel_restart+0x14/0x50 [<ffffffff8115581c>] SyS_reboot+0x10c/0x1f0 [<ffffffff81103684>] handle_sysn32+0x44/0x84
The root cause is that current_cpu_data is accessed in preemptible context, so protect it with preempt_disable/preempt_enable pair in delay().
--- arch/mips/lib/delay.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
arch/mips/lib/delay.c +5 -1
@@ -41,7 +41,11 @@ EXPORT_SYMBOL(__delay);void __udelay (unsigned long us) { -unsigned int lpj = current_cpu_data.udelay_val; +unsigned int lpj; + +preempt_disable (); + lpj = current_cpu_data.udelay_val; +preempt_enable ();__delay ((us *0x000010c7ull *HZ * lpj) >>32 ); }
Signature · 1 line
1.6.3.3
Quoted 33 lines · Yang Shi
During machine restart with reboot command, get the following bug info:
BUG: using smp_processor_id() in preemptible [00000000] code: reboot/1989 caller is __udelay+0x14/0x70 Call Trace: [<ffffffff8110ad28>] dump_stack+0x8/0x34 [<ffffffff812dde04>] debug_smp_processor_id+0xf4/0x110 [<ffffffff812d90bc>] __udelay+0x14/0x70 [<ffffffff81378274>] md_notify_reboot+0x12c/0x148 [<ffffffff81161054>] notifier_call_chain+0x64/0xc8 [<ffffffff811614dc>] __blocking_notifier_call_chain+0x64/0xc0 [<ffffffff8115566c>] kernel_restart_prepare+0x1c/0x38 [<ffffffff811556cc>] kernel_restart+0x14/0x50 [<ffffffff8115581c>] SyS_reboot+0x10c/0x1f0 [<ffffffff81103684>] handle_sysn32+0x44/0x84The root cause is that
current_cpu_datais accessed in preemptible context, so protect it with preempt_disable/preempt_enable pair indelay().Signed-off-by Yang Shi<[email protected]>--- arch/mips/lib/delay.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)arch/mips/lib/delay.c +0
-0@@ -41,7 +41,11 @@ EXPORT_SYMBOL(__delay);void __udelay (unsigned long us)
arch/mips/lib/delay.c EXPORT_SYMBOL(__delay); · line 51
Quoted 10 lines
arch/mips/lib/delay.c +5
-1{ -unsigned int lpj = current_cpu_data.udelay_val; +unsigned int lpj; + +preempt_disable (); + lpj = current_cpu_data.udelay_val; +preempt_enable ();__delay ((us *0x000010c7ull *HZ * lpj)>>32 ); }
This doesn't seem like the best approach.
Perhaps we should either use raw_current_cpu_data and no preempt_disable(), or if we are concerned about migrating to a CPU with a different lpj value, move the preempt_enable after the call to __delay().
David Daney
Quoted 43 lines · David Daney
Quoted 41 lines · Yang Shi
During machine restart with reboot command, get the following bug info:
BUG: using smp_processor_id() in preemptible [00000000] code: reboot/1989 caller is __udelay+0x14/0x70 Call Trace: [<ffffffff8110ad28>] dump_stack+0x8/0x34 [<ffffffff812dde04>] debug_smp_processor_id+0xf4/0x110 [<ffffffff812d90bc>] __udelay+0x14/0x70 [<ffffffff81378274>] md_notify_reboot+0x12c/0x148 [<ffffffff81161054>] notifier_call_chain+0x64/0xc8 [<ffffffff811614dc>] __blocking_notifier_call_chain+0x64/0xc0 [<ffffffff8115566c>] kernel_restart_prepare+0x1c/0x38 [<ffffffff811556cc>] kernel_restart+0x14/0x50 [<ffffffff8115581c>] SyS_reboot+0x10c/0x1f0 [<ffffffff81103684>] handle_sysn32+0x44/0x84The root cause is that
current_cpu_datais accessed in preemptible context, so protect it with preempt_disable/preempt_enable pair indelay().Signed-off-by Yang Shi<[email protected]>--- arch/mips/lib/delay.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)arch/mips/lib/delay.c +5
-1@@ -41,7 +41,11 @@ EXPORT_SYMBOL(__delay);void __udelay (unsigned long us) { -unsigned int lpj = current_cpu_data.udelay_val; +unsigned int lpj; + +preempt_disable (); + lpj = current_cpu_data.udelay_val; +preempt_enable ();
Quoted 8 lines
arch/mips/lib/delay.c EXPORT_SYMBOL(__delay); · line 51
Quoted 3 lines
arch/mips/lib/delay.c +0
-0__delay ((us *0x000010c7ull *HZ * lpj)>>32 ); }This doesn't seem like the best approach.
Perhaps we should either use
raw_current_cpu_dataand nopreempt_disable(), or if we are concerned about migrating to a CPU with a different lpj value, move thepreempt_enableafter the call to__delay().
Thanks David.
Yes, actually I also has this concern, so this patch is just a rough fix. And I tried raw_current_cpu_data as well, but I'm not sure if it's safe or not. Another proposal is to change cpu_data and current_cpu_data to per CPU variables, of course this is a big change.
Regards,
Yang
Quoted 3 lines
David Daney
Hi folks,
Any advice on this topic?
Thanks,
Yang
Quoted 72 lines · Yang Shi
Quoted 44 lines · David Daney
Quoted 41 lines · Yang Shi
During machine restart with reboot command, get the following bug info:
BUG: using smp_processor_id() in preemptible [00000000] code: reboot/1989 caller is __udelay+0x14/0x70 Call Trace: [<ffffffff8110ad28>] dump_stack+0x8/0x34 [<ffffffff812dde04>] debug_smp_processor_id+0xf4/0x110 [<ffffffff812d90bc>] __udelay+0x14/0x70 [<ffffffff81378274>] md_notify_reboot+0x12c/0x148 [<ffffffff81161054>] notifier_call_chain+0x64/0xc8 [<ffffffff811614dc>] __blocking_notifier_call_chain+0x64/0xc0 [<ffffffff8115566c>] kernel_restart_prepare+0x1c/0x38 [<ffffffff811556cc>] kernel_restart+0x14/0x50 [<ffffffff8115581c>] SyS_reboot+0x10c/0x1f0 [<ffffffff81103684>] handle_sysn32+0x44/0x84The root cause is that
current_cpu_datais accessed in preemptible context, so protect it with preempt_disable/preempt_enable pair indelay().Signed-off-by Yang Shi<[email protected]>--- arch/mips/lib/delay.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)arch/mips/lib/delay.c +5
-1@@ -41,7 +41,11 @@ EXPORT_SYMBOL(__delay);void __udelay (unsigned long us) { -unsigned int lpj = current_cpu_data.udelay_val; +unsigned int lpj; + +preempt_disable (); + lpj = current_cpu_data.udelay_val; +preempt_enable ();Quoted 9 lines
arch/mips/lib/delay.c EXPORT_SYMBOL(__delay); · line 51
Quoted 4 lines
arch/mips/lib/delay.c +0
-0__delay ((us *0x000010c7ull *HZ * lpj)>>32 ); }This doesn't seem like the best approach.
Perhaps we should either use
raw_current_cpu_dataand nopreempt_disable(), or if we are concerned about migrating to a CPU with a different lpj value, move thepreempt_enableafter the call to__delay().Thanks David.
Yes, actually I also has this concern, so this patch is just a rough fix. And I tried
raw_current_cpu_dataas well, but I'm not sure if it's safe or not. Another proposal is to changecpu_dataandcurrent_cpu_datato per CPU variables, of course this is a big change.Regards,
YangQuoted 4 lines
David Daney
Quoted 47 lines · David Daney
Quoted 33 lines · Yang Shi
During machine restart with reboot command, get the following bug info:
BUG: using smp_processor_id() in preemptible [00000000] code: reboot/1989 caller is __udelay+0x14/0x70 Call Trace: [<ffffffff8110ad28>] dump_stack+0x8/0x34 [<ffffffff812dde04>] debug_smp_processor_id+0xf4/0x110 [<ffffffff812d90bc>] __udelay+0x14/0x70 [<ffffffff81378274>] md_notify_reboot+0x12c/0x148 [<ffffffff81161054>] notifier_call_chain+0x64/0xc8 [<ffffffff811614dc>] __blocking_notifier_call_chain+0x64/0xc0 [<ffffffff8115566c>] kernel_restart_prepare+0x1c/0x38 [<ffffffff811556cc>] kernel_restart+0x14/0x50 [<ffffffff8115581c>] SyS_reboot+0x10c/0x1f0 [<ffffffff81103684>] handle_sysn32+0x44/0x84The root cause is that
current_cpu_datais accessed in preemptible context, so protect it with preempt_disable/preempt_enable pair indelay().Signed-off-by Yang Shi<[email protected]>--- arch/mips/lib/delay.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)arch/mips/lib/delay.c +0
-0@@ -41,7 +41,11 @@ EXPORT_SYMBOL(__delay);void __udelay (unsigned long us)arch/mips/lib/delay.c EXPORT_SYMBOL(__delay); · line 51
Quoted 10 lines
arch/mips/lib/delay.c +5
-1{ -unsigned int lpj = current_cpu_data.udelay_val; +unsigned int lpj; + +preempt_disable (); + lpj = current_cpu_data.udelay_val; +preempt_enable ();__delay ((us *0x000010c7ull *HZ * lpj)>>32 ); }This doesn't seem like the best approach.
Quoted 4 lines
Perhaps we should either use
raw_current_cpu_dataand nopreempt_disable(), or if we are concerned about migrating to a CPU with a different lpj value, move thepreempt_enableafter the call to__delay().
Udelay() is supposed to guarantee a minimum delay and when being migrated to another CPU with higher bogomips this guarantee might be violated. So it'd even have to be something like:
void __udelay(unsigned long us)
{
unsigned int lpj = current_cpu_data.udelay_val;
unsigned int lpj;
preempt_disable();
lpj = current_cpu_data.udelay_val;
__delay((us * 0x000010c7ull * HZ * lpj)>> 32);
preempt_enable();
}But preempt_disable() itself is not atomic, so using it from bh or irq context could result in a corrupted preemption counter. So the raw_ version will have to do. I doubt it's much of a problem but at some point we will have to revisit the delay by c0_count patch submitted a while ago. The patch wasn't right but the problem it was addressing is real.
Ralf
Quoted 73 lines · Ralf Baechle
Quoted 48 lines · David Daney
Quoted 34 lines · Yang Shi
During machine restart with reboot command, get the following bug info:
BUG: using smp_processor_id() in preemptible [00000000] code: reboot/1989 caller is __udelay+0x14/0x70 Call Trace: [<ffffffff8110ad28>] dump_stack+0x8/0x34 [<ffffffff812dde04>] debug_smp_processor_id+0xf4/0x110 [<ffffffff812d90bc>] __udelay+0x14/0x70 [<ffffffff81378274>] md_notify_reboot+0x12c/0x148 [<ffffffff81161054>] notifier_call_chain+0x64/0xc8 [<ffffffff811614dc>] __blocking_notifier_call_chain+0x64/0xc0 [<ffffffff8115566c>] kernel_restart_prepare+0x1c/0x38 [<ffffffff811556cc>] kernel_restart+0x14/0x50 [<ffffffff8115581c>] SyS_reboot+0x10c/0x1f0 [<ffffffff81103684>] handle_sysn32+0x44/0x84The root cause is that
current_cpu_datais accessed in preemptible context, so protect it with preempt_disable/preempt_enable pair indelay().Signed-off-by Yang Shi<[email protected]>--- arch/mips/lib/delay.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)arch/mips/lib/delay.c +0
-0@@ -41,7 +41,11 @@ EXPORT_SYMBOL(__delay);void __udelay (unsigned long us)arch/mips/lib/delay.c EXPORT_SYMBOL(__delay); · line 51
Quoted 10 lines
arch/mips/lib/delay.c +5
-1{ -unsigned int lpj = current_cpu_data.udelay_val; +unsigned int lpj; + +preempt_disable (); + lpj = current_cpu_data.udelay_val; +preempt_enable ();__delay ((us *0x000010c7ull *HZ * lpj)>>32 ); }This doesn't seem like the best approach.
Quoted 5 lines
Perhaps we should either use
raw_current_cpu_dataand nopreempt_disable(), or if we are concerned about migrating to a CPU with a different lpj value, move thepreempt_enableafter the call to__delay().
Udelay()is supposed to guarantee a minimum delay and when being migrated to another CPU with higher bogomips this guarantee might be violated. So it'd even have to be something like:void
__udelay(unsigned long us){ unsigned int lpj = current_cpu_data.udelay_val; unsigned int lpj; preempt_disable(); lpj = current_cpu_data.udelay_val; __delay((us * 0x000010c7ull * HZ * lpj)>> 32); preempt_enable(); }
Quoted 7 lines
But
preempt_disable()itself is not atomic, so using it from bh or irq context could result in a corrupted preemption counter. So theraw_version will have to do. I doubt it's much of a problem but at some point we will have to revisit the delay byc0_countpatch submitted a while ago. The patch wasn't right but the problem it was addressing is real.
Thanks Ralf. Do we need raw_ version patch before revisiting the delay by c0_count patch although it's not an ideal fix.
Regards,
Yang
Quoted 3 lines
Ralf