Skip to content

Commit 3c46979

Browse files
guoren83palmer-dabbelt
authored andcommitted
riscv: Enable LOCKDEP_SUPPORT & fixup TRACE_IRQFLAGS_SUPPORT
Lockdep is needed by proving the spinlocks and rwlocks. To suupport it, we need fixup TRACE_IRQFLAGS_SUPPORT in kernel/entry.S. This patch follow Documentation/irqflags-tracing.txt. Signed-off-by: Guo Ren <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent c159599 commit 3c46979

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

arch/riscv/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ config PGTABLE_LEVELS
179179
default 3 if 64BIT
180180
default 2
181181

182+
config LOCKDEP_SUPPORT
183+
def_bool y
184+
182185
source "arch/riscv/Kconfig.socs"
183186

184187
menu "Platform type"

arch/riscv/kernel/entry.S

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,26 @@ _save_context:
9797
la gp, __global_pointer$
9898
.option pop
9999

100-
la ra, ret_from_exception
100+
#ifdef CONFIG_TRACE_IRQFLAGS
101+
call trace_hardirqs_off
102+
#endif
101103
/*
102104
* MSB of cause differentiates between
103105
* interrupts and exceptions
104106
*/
105107
bge s4, zero, 1f
106108

109+
la ra, ret_from_exception
110+
107111
/* Handle interrupts */
108112
move a0, sp /* pt_regs */
109113
la a1, handle_arch_irq
110114
REG_L a1, (a1)
111115
jr a1
112116
1:
117+
#ifdef CONFIG_TRACE_IRQFLAGS
118+
call trace_hardirqs_on
119+
#endif
113120
/*
114121
* Exceptions run with interrupts enabled or disabled depending on the
115122
* state of SR_PIE in m/sstatus.
@@ -119,6 +126,7 @@ _save_context:
119126
csrs CSR_STATUS, SR_IE
120127

121128
1:
129+
la ra, ret_from_exception
122130
/* Handle syscalls */
123131
li t0, EXC_SYSCALL
124132
beq s4, t0, handle_syscall
@@ -137,6 +145,17 @@ _save_context:
137145
tail do_trap_unknown
138146

139147
handle_syscall:
148+
#ifdef CONFIG_TRACE_IRQFLAGS
149+
/* Recover a0 - a7 for system calls */
150+
REG_L a0, PT_A0(sp)
151+
REG_L a1, PT_A1(sp)
152+
REG_L a2, PT_A2(sp)
153+
REG_L a3, PT_A3(sp)
154+
REG_L a4, PT_A4(sp)
155+
REG_L a5, PT_A5(sp)
156+
REG_L a6, PT_A6(sp)
157+
REG_L a7, PT_A7(sp)
158+
#endif
140159
/* save the initial A0 value (needed in signal handlers) */
141160
REG_S a0, PT_ORIG_A0(sp)
142161
/*
@@ -190,6 +209,9 @@ ret_from_syscall_rejected:
190209
ret_from_exception:
191210
REG_L s0, PT_STATUS(sp)
192211
csrc CSR_STATUS, SR_IE
212+
#ifdef CONFIG_TRACE_IRQFLAGS
213+
call trace_hardirqs_off
214+
#endif
193215
#ifdef CONFIG_RISCV_M_MODE
194216
/* the MPP value is too large to be used as an immediate arg for addi */
195217
li t0, SR_MPP
@@ -216,6 +238,16 @@ resume_userspace:
216238
csrw CSR_SCRATCH, tp
217239

218240
restore_all:
241+
#ifdef CONFIG_TRACE_IRQFLAGS
242+
REG_L s1, PT_STATUS(sp)
243+
andi t0, s1, SR_PIE
244+
beqz t0, 1f
245+
call trace_hardirqs_on
246+
j 2f
247+
1:
248+
call trace_hardirqs_off
249+
2:
250+
#endif
219251
REG_L a0, PT_STATUS(sp)
220252
/*
221253
* The current load reservation is effectively part of the processor's

0 commit comments

Comments
 (0)