Skip to content

Commit 02fe284

Browse files
author
Russell King
committed
ARM: entry: avoid enabling interrupts in prefetch/data abort handlers
Avoid enabling interrupts if the parent context had interrupts enabled in the abort handler assembly code, and move this into the breakpoint/ page/alignment fault handlers instead. This gets rid of some special-casing for the breakpoint fault handlers from the low level abort handler path. Acked-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 8b41861 commit 02fe284

5 files changed

Lines changed: 31 additions & 50 deletions

File tree

‎arch/arm/kernel/entry-armv.S‎

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,15 @@ ENDPROC(__und_invalid)
185185
__dabt_svc:
186186
svc_entry
187187

188-
@
189-
@ get ready to re-enable interrupts if appropriate
190-
@
191-
mrs r9, cpsr
192-
tst r5, #PSR_I_BIT
193-
biceq r9, r9, #PSR_I_BIT
188+
#ifdef CONFIG_TRACE_IRQFLAGS
189+
bl trace_hardirqs_off
190+
#endif
194191

195192
dabt_helper
196193

197194
@
198-
@ set desired IRQ state, then call main handler
195+
@ call main handler
199196
@
200-
debug_entry r1
201-
msr cpsr_c, r9
202197
mov r2, sp
203198
bl do_DataAbort
204199

@@ -211,6 +206,12 @@ __dabt_svc:
211206
@ restore SPSR and restart the instruction
212207
@
213208
ldr r5, [sp, #S_PSR]
209+
#ifdef CONFIG_TRACE_IRQFLAGS
210+
tst r5, #PSR_I_BIT
211+
bleq trace_hardirqs_on
212+
tst r5, #PSR_I_BIT
213+
blne trace_hardirqs_off
214+
#endif
214215
svc_exit r5 @ return from exception
215216
UNWIND(.fnend )
216217
ENDPROC(__dabt_svc)
@@ -307,16 +308,11 @@ ENDPROC(__und_svc)
307308
__pabt_svc:
308309
svc_entry
309310

310-
@
311-
@ re-enable interrupts if appropriate
312-
@
313-
mrs r9, cpsr
314-
tst r5, #PSR_I_BIT
315-
biceq r9, r9, #PSR_I_BIT
311+
#ifdef CONFIG_TRACE_IRQFLAGS
312+
bl trace_hardirqs_off
313+
#endif
316314

317315
pabt_helper
318-
debug_entry r1
319-
msr cpsr_c, r9 @ Maybe enable interrupts
320316
mov r2, sp @ regs
321317
bl do_PrefetchAbort @ call abort handler
322318

@@ -329,6 +325,12 @@ __pabt_svc:
329325
@ restore SPSR and restart the instruction
330326
@
331327
ldr r5, [sp, #S_PSR]
328+
#ifdef CONFIG_TRACE_IRQFLAGS
329+
tst r5, #PSR_I_BIT
330+
bleq trace_hardirqs_on
331+
tst r5, #PSR_I_BIT
332+
blne trace_hardirqs_off
333+
#endif
332334
svc_exit r5 @ return from exception
333335
UNWIND(.fnend )
334336
ENDPROC(__pabt_svc)
@@ -412,11 +414,6 @@ __dabt_usr:
412414
kuser_cmpxchg_check
413415
dabt_helper
414416

415-
@
416-
@ IRQs on, then call the main handler
417-
@
418-
debug_entry r1
419-
enable_irq
420417
mov r2, sp
421418
adr lr, BSYM(ret_from_exception)
422419
b do_DataAbort
@@ -663,8 +660,6 @@ ENDPROC(__und_usr_unknown)
663660
__pabt_usr:
664661
usr_entry
665662
pabt_helper
666-
debug_entry r1
667-
enable_irq @ Enable interrupts
668663
mov r2, sp @ regs
669664
bl do_PrefetchAbort @ call abort handler
670665
UNWIND(.fnend )

‎arch/arm/kernel/entry-header.S‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -165,25 +165,6 @@
165165
.endm
166166
#endif /* !CONFIG_THUMB2_KERNEL */
167167

168-
@
169-
@ Debug exceptions are taken as prefetch or data aborts.
170-
@ We must disable preemption during the handler so that
171-
@ we can access the debug registers safely.
172-
@
173-
.macro debug_entry, fsr
174-
#if defined(CONFIG_HAVE_HW_BREAKPOINT) && defined(CONFIG_PREEMPT)
175-
ldr r4, =0x40f @ mask out fsr.fs
176-
and r5, r4, \fsr
177-
cmp r5, #2 @ debug exception
178-
bne 1f
179-
get_thread_info r10
180-
ldr r6, [r10, #TI_PREEMPT] @ get preempt count
181-
add r11, r6, #1 @ increment it
182-
str r11, [r10, #TI_PREEMPT]
183-
1:
184-
#endif
185-
.endm
186-
187168
/*
188169
* These are the registers used in the syscall handler, and allow us to
189170
* have in theory up to 7 arguments to a function - r0 to r6.

‎arch/arm/kernel/hw_breakpoint.c‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -796,16 +796,18 @@ static void breakpoint_handler(unsigned long unknown, struct pt_regs *regs)
796796

797797
/*
798798
* Called from either the Data Abort Handler [watchpoint] or the
799-
* Prefetch Abort Handler [breakpoint] with preemption disabled.
799+
* Prefetch Abort Handler [breakpoint] with interrupts disabled.
800800
*/
801801
static int hw_breakpoint_pending(unsigned long addr, unsigned int fsr,
802802
struct pt_regs *regs)
803803
{
804804
int ret = 0;
805805
u32 dscr;
806806

807-
/* We must be called with preemption disabled. */
808-
WARN_ON(preemptible());
807+
preempt_disable();
808+
809+
if (interrupts_enabled(regs))
810+
local_irq_enable();
809811

810812
/* We only handle watchpoints and hardware breakpoints. */
811813
ARM_DBG_READ(c1, 0, dscr);
@@ -824,10 +826,6 @@ static int hw_breakpoint_pending(unsigned long addr, unsigned int fsr,
824826
ret = 1; /* Unhandled fault. */
825827
}
826828

827-
/*
828-
* Re-enable preemption after it was disabled in the
829-
* low-level exception handling code.
830-
*/
831829
preempt_enable();
832830

833831
return ret;

‎arch/arm/mm/alignment.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,9 @@ do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
727727
int isize = 4;
728728
int thumb2_32b = 0;
729729

730+
if (interrupts_enabled(regs))
731+
local_irq_enable();
732+
730733
instrptr = instruction_pointer(regs);
731734

732735
fs = get_fs();

‎arch/arm/mm/fault.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
285285
tsk = current;
286286
mm = tsk->mm;
287287

288+
/* Enable interrupts if they were enabled in the parent context. */
289+
if (interrupts_enabled(regs))
290+
local_irq_enable();
291+
288292
/*
289293
* If we're in an interrupt or have no user
290294
* context, we must not take the fault..

0 commit comments

Comments
 (0)