Skip to content

Commit 9008975

Browse files
committed
csky: Fixup CONFIG_PREEMPT panic
log: [    0.13373200] Calibrating delay loop... [    0.14077600] ------------[ cut here ]------------ [    0.14116700] WARNING: CPU: 0 PID: 0 at kernel/sched/core.c:3790 preempt_count_add+0xc8/0x11c [    0.14348000] DEBUG_LOCKS_WARN_ON((preempt_count() < 0))Modules linked in: [    0.14395100] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.6.0 #7 [    0.14410800] [    0.14427400] Call Trace: [    0.14450700] [<807cd226>] dump_stack+0x8a/0xe4 [    0.14473500] [<80072792>] __warn+0x10e/0x15c [    0.14495900] [<80072852>] warn_slowpath_fmt+0x72/0xc0 [    0.14518600] [<800a5240>] preempt_count_add+0xc8/0x11c [    0.14544900] [<807ef918>] _raw_spin_lock+0x28/0x68 [    0.14572600] [<800e0eb8>] vprintk_emit+0x84/0x2d8 [    0.14599000] [<800e113a>] vprintk_default+0x2e/0x44 [    0.14625100] [<800e2042>] vprintk_func+0x12a/0x1d0 [    0.14651300] [<800e1804>] printk+0x30/0x48 [    0.14677600] [<80008052>] lockdep_init+0x12/0xb0 [    0.14703800] [<80002080>] start_kernel+0x558/0x7f8 [    0.14730000] [<800052bc>] csky_start+0x58/0x94 [    0.14756600] irq event stamp: 34 [    0.14775100] hardirqs last  enabled at (33): [<80067370>] ret_from_exception+0x2c/0x72 [    0.14793700] hardirqs last disabled at (34): [<800e0eae>] vprintk_emit+0x7a/0x2d8 [    0.14812300] softirqs last  enabled at (32): [<800655b0>] __do_softirq+0x578/0x6d8 [    0.14830800] softirqs last disabled at (25): [<8007b3b8>] irq_exit+0xec/0x128 The preempt_count of reg could be destroyed after csky_do_IRQ without reload from memory. After reference to other architectures (arm64, riscv), we move preempt entry into ret_from_exception and disable irq at the beginning of ret_from_exception instead of RESTORE_ALL. Signed-off-by: Guo Ren <[email protected]> Reported-by: Lu Baoquan <[email protected]>
1 parent 9cb1fd0 commit 9008975

File tree

3 files changed

+11
-27
lines changed

3 files changed

+11
-27
lines changed

arch/csky/abiv1/inc/abi/entry.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
.endm
8181

8282
.macro RESTORE_ALL
83-
psrclr ie
8483
ldw lr, (sp, 4)
8584
ldw a0, (sp, 8)
8685
mtcr a0, epc

arch/csky/abiv2/inc/abi/entry.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
.endm
6464

6565
.macro RESTORE_ALL
66-
psrclr ie
6766
ldw tls, (sp, 0)
6867
ldw lr, (sp, 4)
6968
ldw a0, (sp, 8)

arch/csky/kernel/entry.S

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ ENTRY(ret_from_fork)
208208
jbsr syscall_trace_exit
209209

210210
ret_from_exception:
211+
psrclr ie
211212
ld syscallid, (sp, LSAVE_PSR)
212213
btsti syscallid, 31
213-
bt 1f
214214

215215
/*
216216
* Load address of current->thread_info, Then get address of task_struct
@@ -220,11 +220,20 @@ ret_from_exception:
220220
bmaski r10, THREAD_SHIFT
221221
andn r9, r10
222222

223+
bt 1f
223224
ldw r12, (r9, TINFO_FLAGS)
224225
andi r12, (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | _TIF_UPROBE)
225226
cmpnei r12, 0
226227
bt exit_work
227228
1:
229+
#ifdef CONFIG_PREEMPTION
230+
ldw r12, (r9, TINFO_PREEMPT)
231+
cmpnei r12, 0
232+
bt 2f
233+
jbsr preempt_schedule_irq /* irq en/disable is done inside */
234+
2:
235+
#endif
236+
228237
#ifdef CONFIG_TRACE_IRQFLAGS
229238
ld r10, (sp, LSAVE_PSR)
230239
btsti r10, 6
@@ -241,6 +250,7 @@ exit_work:
241250
btsti r12, TIF_NEED_RESCHED
242251
bt work_resched
243252

253+
psrset ie
244254
mov a0, sp
245255
mov a1, r12
246256
jmpi do_notify_resume
@@ -291,34 +301,10 @@ ENTRY(csky_irq)
291301
jbsr trace_hardirqs_off
292302
#endif
293303

294-
#ifdef CONFIG_PREEMPTION
295-
mov r9, sp /* Get current stack pointer */
296-
bmaski r10, THREAD_SHIFT
297-
andn r9, r10 /* Get thread_info */
298-
299-
/*
300-
* Get task_struct->stack.preempt_count for current,
301-
* and increase 1.
302-
*/
303-
ldw r12, (r9, TINFO_PREEMPT)
304-
addi r12, 1
305-
stw r12, (r9, TINFO_PREEMPT)
306-
#endif
307304

308305
mov a0, sp
309306
jbsr csky_do_IRQ
310307

311-
#ifdef CONFIG_PREEMPTION
312-
subi r12, 1
313-
stw r12, (r9, TINFO_PREEMPT)
314-
cmpnei r12, 0
315-
bt 2f
316-
ldw r12, (r9, TINFO_FLAGS)
317-
btsti r12, TIF_NEED_RESCHED
318-
bf 2f
319-
jbsr preempt_schedule_irq /* irq en/disable is done inside */
320-
#endif
321-
2:
322308
jmpi ret_from_exception
323309

324310
/*

0 commit comments

Comments
 (0)