Re: [PATCH] MIPS: Do not use smp_processor_id() in preemptible code

2020-07-05 Thread Thomas Bogendoerfer
On Fri, Jul 03, 2020 at 12:11:58PM +0800, Xingxing Su wrote:
> Use preempt_disable() to fix the following bug under CONFIG_DEBUG_PREEMPT.
> 
> [   21.915305] BUG: using smp_processor_id() in preemptible [] code: 
> qemu-system-mip/1056
> [   21.923996] caller is do_ri+0x1d4/0x690
> [   21.927921] CPU: 0 PID: 1056 Comm: qemu-system-mip Not tainted 5.8.0-rc2 #3
> [   21.934913] Stack : 0001 8137 8071cd60 
> a80f926d5ac95694
> [   21.942984] a80f926d5ac95694  9807f0043c88 
> 80f2fe40
> [   21.951054]   0001 
> 
> [   21.959123] 802d60cc 9807f0043dd8 81f4b1e8 
> 81f6
> [   21.967192] 81f6 80fe  
> 
> [   21.975261] f500cce1 0001 0002 
> 
> [   21.983331] 80fe1a40 0006 8077f940 
> 
> [   21.991401] 8146 9807f004 9807f0043c80 
> 00fffba8cf20
> [   21.999471] 8071cd60   
> 
> [   22.007541]   80212ab4 
> a80f926d5ac95694
> [   22.015610] ...
> [   22.018086] Call Trace:
> [   22.020562] [] show_stack+0xa4/0x138
> [   22.025732] [] dump_stack+0xf0/0x150
> [   22.030903] [] check_preemption_disabled+0xf4/0x100
> [   22.037375] [] do_ri+0x1d4/0x690
> [   22.042198] [] handle_ri_int+0x44/0x5c
> [   24.359386] BUG: using smp_processor_id() in preemptible [] code: 
> qemu-system-mip/1072
> [   24.368204] caller is do_ri+0x1a8/0x690
> [   24.372169] CPU: 4 PID: 1072 Comm: qemu-system-mip Not tainted 5.8.0-rc2 #3
> [   24.379170] Stack : 0001 8137 8071cd60 
> a80f926d5ac95694
> [   24.387246] a80f926d5ac95694  98001007ef06bc88 
> 80f2fe40
> [   24.395318]   0001 
> 
> [   24.403389] 802d60cc 98001007ef06bdd8 81f4b818 
> 81f6
> [   24.411461] 81f6 80fe  
> 
> [   24.419533] f500cce1 0001 0002 
> 
> [   24.427603] 80fe 0006 8077f940 
> 0020
> [   24.435673] 81460020 98001007ef068000 98001007ef06bc80 
> 00fff370
> [   24.443745] 8071cd60   
> 
> [   24.451816]   80212ab4 
> a80f926d5ac95694
> [   24.459887] ...
> [   24.462367] Call Trace:
> [   24.464846] [] show_stack+0xa4/0x138
> [   24.470029] [] dump_stack+0xf0/0x150
> [   24.475208] [] check_preemption_disabled+0xf4/0x100
> [   24.481682] [] do_ri+0x1a8/0x690
> [   24.486509] [] handle_ri_int+0x44/0x5c
> 
> Signed-off-by: Xingxing Su 
> ---
>  arch/mips/kernel/traps.c | 8 +---
>  1 file changed, 5 insertions(+), 3 deletions(-)

applied to mips-fixes.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.[ RFC1925, 2.3 ]


[PATCH] MIPS: Do not use smp_processor_id() in preemptible code

2020-07-02 Thread Xingxing Su
Use preempt_disable() to fix the following bug under CONFIG_DEBUG_PREEMPT.

[   21.915305] BUG: using smp_processor_id() in preemptible [] code: 
qemu-system-mip/1056
[   21.923996] caller is do_ri+0x1d4/0x690
[   21.927921] CPU: 0 PID: 1056 Comm: qemu-system-mip Not tainted 5.8.0-rc2 #3
[   21.934913] Stack : 0001 8137 8071cd60 
a80f926d5ac95694
[   21.942984] a80f926d5ac95694  9807f0043c88 
80f2fe40
[   21.951054]   0001 

[   21.959123] 802d60cc 9807f0043dd8 81f4b1e8 
81f6
[   21.967192] 81f6 80fe  

[   21.975261] f500cce1 0001 0002 

[   21.983331] 80fe1a40 0006 8077f940 

[   21.991401] 8146 9807f004 9807f0043c80 
00fffba8cf20
[   21.999471] 8071cd60   

[   22.007541]   80212ab4 
a80f926d5ac95694
[   22.015610] ...
[   22.018086] Call Trace:
[   22.020562] [] show_stack+0xa4/0x138
[   22.025732] [] dump_stack+0xf0/0x150
[   22.030903] [] check_preemption_disabled+0xf4/0x100
[   22.037375] [] do_ri+0x1d4/0x690
[   22.042198] [] handle_ri_int+0x44/0x5c
[   24.359386] BUG: using smp_processor_id() in preemptible [] code: 
qemu-system-mip/1072
[   24.368204] caller is do_ri+0x1a8/0x690
[   24.372169] CPU: 4 PID: 1072 Comm: qemu-system-mip Not tainted 5.8.0-rc2 #3
[   24.379170] Stack : 0001 8137 8071cd60 
a80f926d5ac95694
[   24.387246] a80f926d5ac95694  98001007ef06bc88 
80f2fe40
[   24.395318]   0001 

[   24.403389] 802d60cc 98001007ef06bdd8 81f4b818 
81f6
[   24.411461] 81f6 80fe  

[   24.419533] f500cce1 0001 0002 

[   24.427603] 80fe 0006 8077f940 
0020
[   24.435673] 81460020 98001007ef068000 98001007ef06bc80 
00fff370
[   24.443745] 8071cd60   

[   24.451816]   80212ab4 
a80f926d5ac95694
[   24.459887] ...
[   24.462367] Call Trace:
[   24.464846] [] show_stack+0xa4/0x138
[   24.470029] [] dump_stack+0xf0/0x150
[   24.475208] [] check_preemption_disabled+0xf4/0x100
[   24.481682] [] do_ri+0x1a8/0x690
[   24.486509] [] handle_ri_int+0x44/0x5c

Signed-off-by: Xingxing Su 
---
 arch/mips/kernel/traps.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index 7c32c95..a46ce94 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -723,12 +723,14 @@ static int simulate_loongson3_cpucfg(struct pt_regs *regs,
perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, 0);
 
/* Do not emulate on unsupported core models. */
-   if (!loongson3_cpucfg_emulation_enabled(_cpu_data))
+   preempt_disable();
+   if (!loongson3_cpucfg_emulation_enabled(_cpu_data)) {
+   preempt_enable();
return -1;
-
+   }
regs->regs[rd] = loongson3_cpucfg_read_synthesized(
_cpu_data, sel);
-
+   preempt_enable();
return 0;
}
 
-- 
2.1.0