Skip to contentSkip to conversation

SError rework to support RAS notifications via SEI

PATCH Superseded James Morse 1 participant 11 messages May 24, 2017 – Jun 14, 2017 arm64

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover SError rework to support RAS notifications via SEI

The rules for when SError should be masked/unmasked are unclear. Today we unmask SError on each CPU during boot, but ignore it thereafter. This means once we enter userspace SError is always masked in the kernel. Because of this, we always blame the next user space process to be scheduled for any SError triggered by the kernel.

When we add an ESB for synchronising RAS events in the context switch code, we won't ever take an SError (it will be deferred and written to a system register), we would need to always explicitly test for an error.

Instead we should unmask SError when running in the kernel, and we should decide an order for masking/unmasking exceptions.

'dai' is memorable and almost what we have today.

This means:
* Masking debug will also mask SError and irq.
* Masking SError will also mask irq.
* Fiq is almost always unmasked. (It's masked by debug as that masks everything)

The entry.S changes are in very small pieces, hopefully this makes the bugs obvious. I intend to merge all the convert-foo patches together once they've been reviewed.

The (expected) changes in behaviour for this series are:
* SError and fiq may be unmasked in the kernel.
* el1_sync exceptions (except debug) inherit their flags, instead of unmasking debug and maybe irq for instruction/data abort. This means EL1's undef/sp_pc/inv may now run with IRQs unmasked.
* el0_sync exceptions (except debug) unmask everything. fpsimd_acc fpsimd_exc and inv now run with interrupts enabled. (This looked like a side effect of some earlier cleanup.)
* kernel_exit explicitly masks all the flags.

With these changes, adding further RAS support that depends on SError handling becomes simpler.

Comments welcome.

James Morse (8):
arm64: explicitly mask all exceptions
arm64: introduce an order for exceptions
arm64: unmask all exceptions on CPU startup
arm64: entry.S: mask all exceptions during kernel_exit
arm64: entry.S: move enable_step_tsk into kernel_exit
arm64: entry.S: convert el1_sync
arm64: entry.S convert el0_sync
arm64: entry.S: convert elX_irq

Xie XiuQi (1):
arm64: entry.S: move SError handling into a C function for future
expansion

 arch/arm64/Kconfig                 |   1 +
 arch/arm64/include/asm/assembler.h |  47 +++++++++------
 arch/arm64/include/asm/irqflags.h  |  65 ++++++++++++++-------
 arch/arm64/kernel/debug-monitors.c |   4 +-
 arch/arm64/kernel/entry.S          | 116 +++++++++++++++++++------------------
 arch/arm64/kernel/hibernate.c      |   4 +-
 arch/arm64/kernel/machine_kexec.c  |   3 +-
 arch/arm64/kernel/setup.c          |   7 ++-
 arch/arm64/kernel/smp.c            |  12 ++--
 arch/arm64/kernel/suspend.c        |   6 +-
 arch/arm64/kernel/traps.c          |  15 ++++-
 arch/arm64/mm/proc.S               |   9 ++-
 12 files changed, 167 insertions(+), 122 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/9 arm64: explicitly mask all exceptions

There are a few places where we want to mask all exceptions. Today we do this in a piecemeal fashion, typically we expect the caller to have masked irqs and the arch code masks debug exceptions, ignoring serror which is probably masked.

Make it clear that 'mask all exceptions' is the intention by adding helpers to do exactly that.

The caller should update trace_hardirqs where appropriate, adding this logic to the mask/unmask helpers causes asm/irqflags.h and linux/irqflag.h to include each other.

---
 arch/arm64/include/asm/assembler.h | 19 +++++++++++++++++++
 arch/arm64/include/asm/irqflags.h  | 34 ++++++++++++++++++++++++++++++++++
 arch/arm64/kernel/hibernate.c      |  4 ++--
 arch/arm64/kernel/machine_kexec.c  |  3 +--
 arch/arm64/kernel/smp.c            |  8 ++------
 arch/arm64/kernel/suspend.c        |  6 +++---
 arch/arm64/kernel/traps.c          |  2 +-
 arch/arm64/mm/proc.S               |  9 ++++-----
 8 files changed, 66 insertions(+), 19 deletions(-)
arch/arm64/include/asm/assembler.h +19 -0
index 1b67c3782d00..896ddd9b21a6 100644
@@ -31,6 +31,25 @@
 #include <asm/ptrace.h>
 #include <asm/thread_info.h>
 
+	.macro save_and_disable_daif, flags
+	.ifnb	\flags
+	mrs	\flags, daif
+	.endif
+	msr	daifset, #0xf
+	.endm
+
+	.macro disable_daif
+	msr	daifset, #0xf
+	.endm
+
+	.macro enable_daif
+	msr	daifclr, #0xf
+	.endm
+
+	.macro	restore_daif, flags:req
+	msr	daif, \flags
+	.endm
+
 /*
  * Enable and disable interrupts.
  */
arch/arm64/include/asm/irqflags.h +34 -0
index 8c581281fa12..937e5615e690 100644
@@ -110,5 +110,39 @@ static inline int arch_irqs_disabled_flags(unsigned long flags)
 		: : "r" (flags) : "memory");				\
 	} while (0)
 
+/*
+ * Mask/unmask/restore all exceptions, including interrupts. If the I bit
+ * is modified the caller should call trace_hardirqs_{on,off}().
+ */
+static inline unsigned long local_mask_daif(void)
+{
+	unsigned long flags;
+	asm volatile(
+		"mrs	%0, daif		// local_mask_daif\n"
+		"msr	daifset, #0xf"
+		: "=r" (flags)
+		:
+		: "memory");
+	return flags;
+}
+
+static inline void local_unmask_daif(void)
+{
+	asm volatile(
+		"msr	daifclr, #0xf		// local_unmask_daif"
+		:
+		:
+		: "memory");
+}
+
+static inline void local_restore_daif(unsigned long flags)
+{
+	asm volatile(
+		"msr	daif, %0		// local_restore_daif"
+	:
+	: "r" (flags)
+	: "memory");
+}
+
 #endif
 #endif
arch/arm64/kernel/hibernate.c +2 -2
index a44e13942d30..e29f85938ef5 100644
@@ -285,7 +285,7 @@ int swsusp_arch_suspend(void)
 		return -EBUSY;
 	}
 
-	local_dbg_save(flags);
+	flags = local_mask_daif();
 
 	if (__cpu_suspend_enter(&state)) {
 		/* make the crash dump kernel image visible/saveable */
@@ -315,7 +315,7 @@ int swsusp_arch_suspend(void)
 		__cpu_suspend_exit();
 	}
 
-	local_dbg_restore(flags);
+	local_restore_daif(flags);
 
 	return ret;
 }
arch/arm64/kernel/machine_kexec.c +1 -2
index 481f54a866c5..24e0df967400 100644
@@ -195,8 +195,7 @@ void machine_kexec(struct kimage *kimage)
 
 	pr_info("Bye!\n");
 
-	/* Disable all DAIF exceptions. */
-	asm volatile ("msr daifset, #0xf" : : : "memory");
+	local_mask_daif();
 
 	/*
 	 * cpu_soft_restart will shutdown the MMU, disable data caches, then
arch/arm64/kernel/smp.c +2 -6
index 6e0e16a3a7d4..9a86a6927edf 100644
@@ -368,10 +368,6 @@ void __cpu_die(unsigned int cpu)
 /*
  * Called from the idle thread for the CPU which has been shutdown.
  *
- * Note that we disable IRQs here, but do not re-enable them
- * before returning to the caller. This is also the behaviour
- * of the other hotplug-cpu capable cores, so presumably coming
- * out of idle fixes this.
  */
 void cpu_die(void)
 {
@@ -379,7 +375,7 @@ void cpu_die(void)
 
 	idle_task_exit();
 
-	local_irq_disable();
+	local_mask_daif();
 
 	/* Tell __cpu_die() that this CPU is now safe to dispose of */
 	(void)cpu_report_death();
@@ -837,7 +833,7 @@ static void ipi_cpu_stop(unsigned int cpu)
 {
 	set_cpu_online(cpu, false);
 
-	local_irq_disable();
+	local_mask_daif();
 
 	while (1)
 		cpu_relax();
arch/arm64/kernel/suspend.c +3 -3
index 1e3be9064cfa..d135c70dec97 100644
@@ -57,7 +57,7 @@ void notrace __cpu_suspend_exit(void)
 	/*
 	 * Restore HW breakpoint registers to sane values
 	 * before debug exceptions are possibly reenabled
-	 * through local_dbg_restore.
+	 * by cpu_suspend()s local_daif_restore() call.
 	 */
 	if (hw_breakpoint_restore)
 		hw_breakpoint_restore(cpu);
@@ -81,7 +81,7 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long))
 	 * updates to mdscr register (saved and restored along with
 	 * general purpose registers) from kernel debuggers.
 	 */
-	local_dbg_save(flags);
+	flags = local_mask_daif();
 
 	/*
 	 * Function graph tracer state gets incosistent when the kernel
@@ -114,7 +114,7 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long))
 	 * restored, so from this point onwards, debugging is fully
 	 * renabled if it was enabled when core started shutdown.
 	 */
-	local_dbg_restore(flags);
+	local_restore_daif(flags);
 
 	return ret;
 }
arch/arm64/kernel/traps.c +1 -1
index 0805b44f986a..52d75e3dcd80 100644
@@ -654,7 +654,7 @@ asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr)
 		esr_get_class_string(esr));
 
 	die("Oops - bad mode", regs, 0);
-	local_irq_disable();
+	local_mask_daif();
 	panic("bad mode");
 }
 
arch/arm64/mm/proc.S +4 -5
index 877d42fb0df6..95233dfc4c39 100644
@@ -109,10 +109,10 @@ ENTRY(cpu_do_resume)
 	/*
 	 * __cpu_setup() cleared MDSCR_EL1.MDE and friends, before unmasking
 	 * debug exceptions. By restoring MDSCR_EL1 here, we may take a debug
-	 * exception. Mask them until local_dbg_restore() in cpu_suspend()
+	 * exception. Mask them until local_daif_restore() in cpu_suspend()
 	 * resets them.
 	 */
-	disable_dbg
+	disable_daif
 	msr	mdscr_el1, x10
 
 	msr	sctlr_el1, x12
@@ -155,8 +155,7 @@ ENDPROC(cpu_do_switch_mm)
  * called by anything else. It can only be executed from a TTBR0 mapping.
  */
 ENTRY(idmap_cpu_replace_ttbr1)
-	mrs	x2, daif
-	msr	daifset, #0xf
+	save_and_disable_daif flags=x2
 
 	adrp	x1, empty_zero_page
 	msr	ttbr1_el1, x1
@@ -169,7 +168,7 @@ ENTRY(idmap_cpu_replace_ttbr1)
 	msr	ttbr1_el1, x0
 	isb
 
-	msr	daif, x2
+	restore_daif x2
 
 	ret
 ENDPROC(idmap_cpu_replace_ttbr1)
Signature · 1 line
2.11.0
#2 lore raw

PATCH 2/9 arm64: introduce an order for exceptions

In reply to James Morse

Lets define an order for masking and unmasking exceptions. 'dai' is memorable and effectively what we have today.

Masking debug exceptions should cause all other exceptions to be masked too. Masking SError should mask irq, but not debug exception. Masking irqs has no side effects for other flags. Keeping to this order makes it easier for entry.S to know which exceptions should be unmasked.

FIQ is never expected, but we mask it when we mask debug exceptions, and unmask it at all other times.

Given masking debug exceptions masks everything, we don't need macros to save/restore that bit independently. Remove them and switch the last caller over to {en,dis}able_daif().

---
 arch/arm64/include/asm/irqflags.h  | 33 +++++++++++++--------------------
 arch/arm64/kernel/debug-monitors.c |  4 ++--
 2 files changed, 15 insertions(+), 22 deletions(-)
arch/arm64/include/asm/irqflags.h +13 -20
index 937e5615e690..e8dd74cbb91a 100644
@@ -21,6 +21,19 @@
 #include <asm/ptrace.h>
 
 /*
+ * Aarch64 has flags for masking: Debug, Asynchronous (serror), Interrupts and
+ * FIQ exceptions, in the 'daif' register. We mask and unmask them in 'dai'
+ * order:
+ * Masking debug exceptions should causes all other exceptions to be masked
+ * too. Masking SError should mask irq, but not debug exceptions. Masking
+ * irqs has no side effects for other flags. Keeping to this order makes it
+ * easier for entry.S to know which exceptions should be unmasked.
+ *
+ * FIQ is never expected, but we mask it when we mask debug exceptions, and
+ * unmask it at all other times.
+ */
+
+/*
  * CPU interrupt mask handling.
  */
 static inline unsigned long arch_local_irq_save(void)
@@ -91,26 +104,6 @@ static inline int arch_irqs_disabled_flags(unsigned long flags)
 }
 
 /*
- * save and restore debug state
- */
-#define local_dbg_save(flags)						\
-	do {								\
-		typecheck(unsigned long, flags);			\
-		asm volatile(						\
-		"mrs    %0, daif		// local_dbg_save\n"	\
-		"msr    daifset, #8"					\
-		: "=r" (flags) : : "memory");				\
-	} while (0)
-
-#define local_dbg_restore(flags)					\
-	do {								\
-		typecheck(unsigned long, flags);			\
-		asm volatile(						\
-		"msr    daif, %0		// local_dbg_restore\n"	\
-		: : "r" (flags) : "memory");				\
-	} while (0)
-
-/*
  * Mask/unmask/restore all exceptions, including interrupts. If the I bit
  * is modified the caller should call trace_hardirqs_{on,off}().
  */
arch/arm64/kernel/debug-monitors.c +2 -2
index d618e25c3de1..56cb27bfa650 100644
@@ -46,9 +46,9 @@ u8 debug_monitors_arch(void)
 static void mdscr_write(u32 mdscr)
 {
 	unsigned long flags;
-	local_dbg_save(flags);
+	flags = local_mask_daif();
 	write_sysreg(mdscr, mdscr_el1);
-	local_dbg_restore(flags);
+	local_restore_daif(flags);
 }
 NOKPROBE_SYMBOL(mdscr_write);
 
Signature · 1 line
2.11.0
#3 lore raw

PATCH 3/9 arm64: unmask all exceptions on CPU startup

In reply to James Morse

Remove the local_{async,fiq}_{en,dis}able macros as they don't respect our newly defined order, and only have one user:
CPU 0 unmasks SError during early boot once it can print an error message.

Debug exceptions are already unmasked by __cpu_setup(), which has also configured MDSCR_EL1 to disable MDE and KDE.

Change the local_async_enable() call to unmask everything except irqs. If we can print an error message about SError, we can do the same for FIQ. The same goes for secondary CPUs only here we are ready to receive interrupts. Just unmask everything.

---
 arch/arm64/include/asm/irqflags.h | 6 ------
 arch/arm64/kernel/setup.c         | 7 ++++---
 arch/arm64/kernel/smp.c           | 4 ++--
 3 files changed, 6 insertions(+), 11 deletions(-)
arch/arm64/include/asm/irqflags.h +0 -6
index e8dd74cbb91a..4f4ebb1f6fd1 100644
@@ -66,12 +66,6 @@ static inline void arch_local_irq_disable(void)
 		: "memory");
 }
 
-#define local_fiq_enable()	asm("msr	daifclr, #1" : : : "memory")
-#define local_fiq_disable()	asm("msr	daifset, #1" : : : "memory")
-
-#define local_async_enable()	asm("msr	daifclr, #4" : : : "memory")
-#define local_async_disable()	asm("msr	daifset, #4" : : : "memory")
-
 /*
  * Save the current interrupt enable state.
  */
arch/arm64/kernel/setup.c +4 -3
index 2c822ef94f34..782add414132 100644
@@ -259,10 +259,11 @@ void __init setup_arch(char **cmdline_p)
 	parse_early_param();
 
 	/*
-	 *  Unmask asynchronous aborts after bringing up possible earlycon.
-	 * (Report possible System Errors once we can report this occurred)
+	 * Unmask asynchronous aborts and fiq after bringing up possible
+	 * earlycon. (Report possible System Errors once we can report this
+	 * occurred).
 	 */
-	local_async_enable();
+	local_restore_daif(PSR_I_BIT);
 
 	/*
 	 * TTBR0 is only used for the identity mapping at this stage. Make it
arch/arm64/kernel/smp.c +2 -2
index 9a86a6927edf..11cd9eff06f3 100644
@@ -271,8 +271,8 @@ asmlinkage void secondary_start_kernel(void)
 	set_cpu_online(cpu, true);
 	complete(&cpu_running);
 
-	local_irq_enable();
-	local_async_enable();
+	trace_hardirqs_on();
+	local_unmask_daif();
 
 	/*
 	 * OK, it's off to the idle thread for us
Signature · 1 line
2.11.0
#4 lore raw

PATCH 4/9 arm64: entry.S: mask all exceptions during kernel_exit

In reply to James Morse

Add a disable_daif call to kernel_exit to mask all exceptions before restoring registers that are overwritten by an exception.

This should be done before we restore sp_el0, as any exception taken from EL1 will assume this register is set correctly.

---
 arch/arm64/kernel/entry.S | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/kernel/entry.S +2 -0
index b738880350f9..fd429d3ba29b 100644
@@ -207,6 +207,8 @@ alternative_else_nop_endif
 2:
 #endif
 
+	disable_daif
+
 	.if	\el == 0
 	ldr	x23, [sp, #S_SP]		// load return stack pointer
 	msr	sp_el0, x23
Signature · 1 line
2.11.0
#5 lore raw

PATCH 5/9 arm64: entry.S: move enable_step_tsk into kernel_exit

In reply to James Morse

enable_step_tsk may enable single-step, so needs to mask debug exceptions to prevent us from single-stepping kernel_exit. This should be the callers problem.

Earlier cleanup (2a2830703a23) moved disable_step_tsk into kernel_entry. enable_step_tsk has two callers, both immediatly before kernel_exit 0. Move the macro call into kernel_exit after local_mask_daif.

enable_step_tsk is now only called with debug exceptions masked. This was the last user of disable_dbg, remove it.

---
 arch/arm64/include/asm/assembler.h | 9 +--------
 arch/arm64/kernel/entry.S          | 7 ++++---
 2 files changed, 5 insertions(+), 11 deletions(-)
arch/arm64/include/asm/assembler.h +1 -8
index 896ddd9b21a6..c6a0d956db8a 100644
@@ -70,13 +70,6 @@
 	msr	daif, \flags
 	.endm
 
-/*
- * Enable and disable debug exceptions.
- */
-	.macro	disable_dbg
-	msr	daifset, #8
-	.endm
-
 	.macro	enable_dbg
 	msr	daifclr, #8
 	.endm
@@ -90,9 +83,9 @@
 9990:
 	.endm
 
+	/* call with daif masked */
 	.macro	enable_step_tsk, flgs, tmp
 	tbz	\flgs, #TIF_SINGLESTEP, 9990f
-	disable_dbg
 	mrs	\tmp, mdscr_el1
 	orr	\tmp, \tmp, #1
 	msr	mdscr_el1, \tmp
arch/arm64/kernel/entry.S +4 -3
index fd429d3ba29b..5fd3d494916d 100644
@@ -212,6 +212,10 @@ alternative_else_nop_endif
 	.if	\el == 0
 	ldr	x23, [sp, #S_SP]		// load return stack pointer
 	msr	sp_el0, x23
+
+	ldr	x1, [tsk, #TSK_TI_FLAGS]
+	enable_step_tsk flgs=x1, tmp=x2
+
 #ifdef CONFIG_ARM64_ERRATUM_845719
 alternative_if ARM64_WORKAROUND_845719
 	tbz	x22, #4, 1f
@@ -752,7 +756,6 @@ ret_fast_syscall:
 	cbnz	x2, ret_fast_syscall_trace
 	and	x2, x1, #_TIF_WORK_MASK
 	cbnz	x2, work_pending
-	enable_step_tsk x1, x2
 	kernel_exit 0
 ret_fast_syscall_trace:
 	enable_irq				// enable interrupts
@@ -767,7 +770,6 @@ work_pending:
 #ifdef CONFIG_TRACE_IRQFLAGS
 	bl	trace_hardirqs_on		// enabled while in userspace
 #endif
-	ldr	x1, [tsk, #TSK_TI_FLAGS]	// re-check for single-step
 	b	finish_ret_to_user
 /*
  * "slow" syscall return path.
@@ -778,7 +780,6 @@ ret_to_user:
 	and	x2, x1, #_TIF_WORK_MASK
 	cbnz	x2, work_pending
 finish_ret_to_user:
-	enable_step_tsk x1, x2
 	kernel_exit 0
 ENDPROC(ret_to_user)
 
Signature · 1 line
2.11.0
#6 lore raw

PATCH 6/9 arm64: entry.S: convert el1_sync

In reply to James Morse

el1_sync unmasks exceptions on a case-by-case basis, debug exceptions are unmasked, unless this was a debug exception. IRQs are unmasked for instruction and data aborts only if the interupted context had irqs unmasked.

Following our 'dai' order, el1_dbg should run with everything masked. For the other cases we can inherit whatever we interrupted.

Add a macro inherit_daif to set daif based on the interrupted pstate.

---
 arch/arm64/include/asm/assembler.h |  6 ++++++
 arch/arm64/kernel/entry.S          | 21 ++++++---------------
 2 files changed, 12 insertions(+), 15 deletions(-)
arch/arm64/include/asm/assembler.h +6 -0
index c6a0d956db8a..187d75f6efd3 100644
@@ -50,6 +50,12 @@
 	msr	daif, \flags
 	.endm
 
+	/* Only on aarch64 pstate, PSR_D_BIT is different for aarch32 */
+	.macro	inherit_daif, pstate:req, tmp:req
+	and	\tmp, \pstate, #(PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT)
+	msr	daif, \tmp
+	.endm
+
 /*
  * Enable and disable interrupts.
  */
arch/arm64/kernel/entry.S +6 -15
index 5fd3d494916d..714e15b1c135 100644
@@ -408,8 +408,13 @@ ENDPROC(el1_error_invalid)
 	.align	6
 el1_sync:
 	kernel_entry 1
+	mrs	x0, far_el1
 	mrs	x1, esr_el1			// read the syndrome register
 	lsr	x24, x1, #ESR_ELx_EC_SHIFT	// exception class
+	cmp	x24, #ESR_ELx_EC_BREAKPT_CUR	// debug exception in EL1
+	b.ge	el1_dbg
+
+	inherit_daif	pstate=x23, tmp=x2
 	cmp	x24, #ESR_ELx_EC_DABT_CUR	// data abort in EL1
 	b.eq	el1_da
 	cmp	x24, #ESR_ELx_EC_IABT_CUR	// instruction abort in EL1
@@ -422,8 +427,6 @@ el1_sync:
 	b.eq	el1_sp_pc
 	cmp	x24, #ESR_ELx_EC_UNKNOWN	// unknown exception in EL1
 	b.eq	el1_undef
-	cmp	x24, #ESR_ELx_EC_BREAKPT_CUR	// debug exception in EL1
-	b.ge	el1_dbg
 	b	el1_inv
 
 el1_ia:
@@ -434,32 +437,22 @@ el1_da:
 	/*
 	 * Data abort handling
 	 */
-	mrs	x3, far_el1
-	enable_dbg
-	// re-enable interrupts if they were enabled in the aborted context
-	tbnz	x23, #7, 1f			// PSR_I_BIT
-	enable_irq
-1:
+	mov	x3, x0
 	clear_address_tag x0, x3
 	mov	x2, sp				// struct pt_regs
 	bl	do_mem_abort
 
-	// disable interrupts before pulling preserved data off the stack
-	disable_irq
 	kernel_exit 1
 el1_sp_pc:
 	/*
 	 * Stack or PC alignment exception handling
 	 */
-	mrs	x0, far_el1
-	enable_dbg
 	mov	x2, sp
 	b	do_sp_pc_abort
 el1_undef:
 	/*
 	 * Undefined instruction
 	 */
-	enable_dbg
 	mov	x0, sp
 	b	do_undefinstr
 el1_dbg:
@@ -469,13 +462,11 @@ el1_dbg:
 	cmp	x24, #ESR_ELx_EC_BRK64		// if BRK64
 	cinc	x24, x24, eq			// set bit '0'
 	tbz	x24, #0, el1_inv		// EL1 only
-	mrs	x0, far_el1
 	mov	x2, sp				// struct pt_regs
 	bl	do_debug_exception
 	kernel_exit 1
 el1_inv:
 	// TODO: add support for undefined instructions in kernel mode
-	enable_dbg
 	mov	x0, sp
 	mov	x2, x1
 	mov	x1, #BAD_SYNC
Signature · 1 line
2.11.0
#7 lore raw

PATCH 7/9 arm64: entry.S convert el0_sync

In reply to James Morse

el0_sync also unmasks exceptions on a case-by-case basis, debug exceptions are unmasked, unless this was a debug exception. Irqs are unmasked for some exception types but not for others.

el0_dbg should run with everything masked, for the other cases we can unmask everything. This changes the behaviour of fpsimd_{acc,exc} and el0_inv, which previously ran with irqs masked.

All of these exception types call ct_user_exit after unmasking interrupts. Move this into the switch statement. el0_dbg needs to do this itself once it has finished its work, el0_svc needs to pass a flag to restore the syscall args.

This patch removed the last user of enable_dbg_and_irq, remove it.

---
 arch/arm64/include/asm/assembler.h |  9 --------
 arch/arm64/kernel/entry.S          | 46 +++++++++++++-------------------------
 2 files changed, 16 insertions(+), 39 deletions(-)
arch/arm64/include/asm/assembler.h +0 -9
index 187d75f6efd3..f09934ddc13b 100644
@@ -99,15 +99,6 @@
 	.endm
 
 /*
- * Enable both debug exceptions and interrupts. This is likely to be
- * faster than two daifclr operations, since writes to this register
- * are self-synchronising.
- */
-	.macro	enable_dbg_and_irq
-	msr	daifclr, #(8 | 2)
-	.endm
-
-/*
  * SMP data memory barrier
  */
 	.macro	smp_dmb, opt
arch/arm64/kernel/entry.S +16 -30

136 lines not on this page · raw message

Signature · 1 line
2.11.0
#8 lore raw

PATCH 8/9 arm64: entry.S: convert elX_irq

In reply to James Morse

Following our 'dai' order, irqs should be processed with debug and serror exceptions unmasked.

Add a helper to unmask these two, (and fiq for good measure).

---
 arch/arm64/include/asm/assembler.h | 4 ++++
 arch/arm64/kernel/entry.S          | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)
arch/arm64/include/asm/assembler.h +4 -0
index f09934ddc13b..725086b3b267 100644
@@ -56,6 +56,10 @@
 	msr	daif, \tmp
 	.endm
 
+	.macro enable_da_f
+	msr	daifclr, #(8 | 4 | 1)
+	.endm
+
 /*
  * Enable and disable interrupts.
  */
arch/arm64/kernel/entry.S +2 -2
index d0befb45aa8f..bd1100105212 100644
@@ -476,7 +476,7 @@ ENDPROC(el1_sync)
 	.align	6
 el1_irq:
 	kernel_entry 1
-	enable_dbg
+	enable_da_f
 #ifdef CONFIG_TRACE_IRQFLAGS
 	bl	trace_hardirqs_off
 #endif
@@ -676,7 +676,7 @@ ENDPROC(el0_sync)
 el0_irq:
 	kernel_entry 0
 el0_irq_naked:
-	enable_dbg
+	enable_da_f
 #ifdef CONFIG_TRACE_IRQFLAGS
 	bl	trace_hardirqs_off
 #endif
Signature · 1 line
2.11.0
#9 lore raw

PATCH 9/9 arm64: entry.S: move SError handling into a C function for future expansion

In reply to James Morse

From: Xie XiuQi <[email protected]>

Today SError is taken using the inv_entry macro that ends up in bad_mode.

SError can be used by the RAS Extensions to notify either the OS or firmware of CPU problems, some of which may have been corrected.

To allow this handling to be added, add a do_serror() C function that panic()s. Without the RAS features added by v8.2 we can't do any better. In particular the ARM-ARM's D1.14.4 "Prioritization and recognition of interrupts" allows an IRQ to be taken before SError if both are pending.

Add the entry.S boiler plate to save/restore the CPU registers and unmask debug exceptions. Future patches may change do_serror() to return if the SError Interrupt was notification of a corrected error.

[Split out of a bigger patch, added compat path, renamed, enabled debug
exceptions]

---
 arch/arm64/Kconfig        |  1 +
 arch/arm64/kernel/entry.S | 36 +++++++++++++++++++++++++++++-------
 arch/arm64/kernel/traps.c | 13 +++++++++++++
 3 files changed, 43 insertions(+), 7 deletions(-)
arch/arm64/Kconfig +1 -0
index 3dcd7ec69bca..5813ecc8a3b9 100644
@@ -92,6 +92,7 @@ config ARM64
 	select HAVE_IRQ_TIME_ACCOUNTING
 	select HAVE_MEMBLOCK
 	select HAVE_MEMBLOCK_NODE_MAP if NUMA
+	select HAVE_NMI
 	select HAVE_PATA_PLATFORM
 	select HAVE_PERF_EVENTS
 	select HAVE_PERF_REGS
arch/arm64/kernel/entry.S +29 -7
index bd1100105212..1f7cf906445d 100644
@@ -329,18 +329,18 @@ ENTRY(vectors)
 	ventry	el1_sync			// Synchronous EL1h
 	ventry	el1_irq				// IRQ EL1h
 	ventry	el1_fiq_invalid			// FIQ EL1h
-	ventry	el1_error_invalid		// Error EL1h
+	ventry	el1_serror			// Error EL1h
 
 	ventry	el0_sync			// Synchronous 64-bit EL0
 	ventry	el0_irq				// IRQ 64-bit EL0
 	ventry	el0_fiq_invalid			// FIQ 64-bit EL0
-	ventry	el0_error_invalid		// Error 64-bit EL0
+	ventry	el0_serror			// Error 64-bit EL0
 
 #ifdef CONFIG_COMPAT
 	ventry	el0_sync_compat			// Synchronous 32-bit EL0
 	ventry	el0_irq_compat			// IRQ 32-bit EL0
 	ventry	el0_fiq_invalid_compat		// FIQ 32-bit EL0
-	ventry	el0_error_invalid_compat	// Error 32-bit EL0
+	ventry	el0_serror_compat		// Error 32-bit EL0
 #else
 	ventry	el0_sync_invalid		// Synchronous 32-bit EL0
 	ventry	el0_irq_invalid			// IRQ 32-bit EL0
@@ -380,10 +380,6 @@ ENDPROC(el0_error_invalid)
 el0_fiq_invalid_compat:
 	inv_entry 0, BAD_FIQ, 32
 ENDPROC(el0_fiq_invalid_compat)
-
-el0_error_invalid_compat:
-	inv_entry 0, BAD_ERROR, 32
-ENDPROC(el0_error_invalid_compat)
 #endif
 
 el1_sync_invalid:
@@ -592,6 +588,10 @@ el0_svc_compat:
 el0_irq_compat:
 	kernel_entry 0, 32
 	b	el0_irq_naked
+
+el0_serror_compat:
+	kernel_entry 0, 32
+	b	el0_serror_naked
 #endif
 
 el0_da:
@@ -690,6 +690,28 @@ el0_irq_naked:
 	b	ret_to_user
 ENDPROC(el0_irq)
 
+el1_serror:
+	kernel_entry 1
+	mrs	x1, esr_el1
+	enable_dbg
+	mov	x0, sp
+	bl	do_serror
+	kernel_exit 1
+ENDPROC(el1_serror)
+
+el0_serror:
+	kernel_entry 0
+el0_serror_naked:
+	mrs	x1, esr_el1
+	enable_dbg
+	mov	x0, sp
+	bl	do_serror
+	enable_daif
+	ct_user_exit
+	b	ret_to_user
+ENDPROC(el0_serror)
+
+
 /*
  * Register switch for AArch64. The callee-saved registers need to be saved
  * and restored. On entry:
arch/arm64/kernel/traps.c +13 -0
index 52d75e3dcd80..ef008103dcca 100644
@@ -683,6 +683,19 @@ asmlinkage void bad_el0_sync(struct pt_regs *regs, int reason, unsigned int esr)
 	force_sig_info(info.si_signo, &info, current);
 }
 
+asmlinkage void do_serror(struct pt_regs *regs, unsigned int esr)
+{
+	nmi_enter();
+
+	console_verbose();
+
+	pr_crit("SError Interrupt on CPU%d, code 0x%08x -- %s\n",
+		smp_processor_id(), esr, esr_get_class_string(esr));
+	__show_regs(regs);
+
+	panic("Asynchronous SError Interrupt");
+}
+
 void __pte_error(const char *file, int line, unsigned long val)
 {
 	pr_err("%s:%d: bad pte %016lx.\n", file, line, val);
Signature · 1 line
2.11.0
#10 lore raw

[PATCH 10/9] arm64: cpufeature: Detect CPU RAS Extensions

In reply to James Morse

From: Xie XiuQi <[email protected]>

ARM's v8.2 Extensions add support for Reliability, Availability and Serviceability (RAS). On CPUs with these extensions system software can use additional barriers to isolate errors and determine if faults are pending.

Add cpufeature detection and a barrier in the context-switch code. There is no need to use alternatives for this as CPUs that don't support this feature will treat the instruction as a nop.

Platform level RAS support may require additional firmware support.

[Rebased, added esb and config option, reworded commit message]

---
Now that SError is unmasked when __switch_to() is run, we can add an ESB to isolate any pending faults to the affected process.

 arch/arm64/Kconfig               | 16 ++++++++++++++++
 arch/arm64/include/asm/barrier.h |  1 +
 arch/arm64/include/asm/cpucaps.h |  3 ++-
 arch/arm64/include/asm/sysreg.h  |  2 ++
 arch/arm64/kernel/cpufeature.c   | 13 +++++++++++++
 arch/arm64/kernel/process.c      |  3 +++
 6 files changed, 37 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +16 -0
index 5813ecc8a3b9..ef9cc108170f 100644
@@ -941,6 +941,22 @@ config ARM64_UAO
 	  regular load/store instructions if the cpu does not implement the
 	  feature.
 
+config ARM64_RAS_EXTN
+	bool "Enable support for RAS CPU Extensions"
+	default y
+	help
+	  CPUs that support the Reliability, Availability and Serviceability
+	  (RAS) Extensions, part of ARMv8.2 are able to track faults and
+	  errors, classify them and report them to software.
+
+	  On CPUs with these extensions system software can use additional
+	  barriers to determine if faults are pending and read the
+	  classification from a new set of registers.
+
+	  Selecting this feature will allow the kernel to use these barriers
+	  and access the new registers if the system supports the extension.
+	  Platform RAS features may additionally depend on firmware support.
+
 endmenu
 
 config ARM64_MODULE_CMODEL_LARGE
arch/arm64/include/asm/barrier.h +1 -0
index 0fe7e43b7fbc..8b0a0eb67625 100644
@@ -30,6 +30,7 @@
 #define isb()		asm volatile("isb" : : : "memory")
 #define dmb(opt)	asm volatile("dmb " #opt : : : "memory")
 #define dsb(opt)	asm volatile("dsb " #opt : : : "memory")
+#define esb()		asm volatile("hint #16"  : : : "memory")
 
 #define mb()		dsb(sy)
 #define rmb()		dsb(ld)
arch/arm64/include/asm/cpucaps.h +2 -1
index b3aab8a17868..ab311eaf83db 100644
@@ -38,7 +38,8 @@
 #define ARM64_WORKAROUND_REPEAT_TLBI		17
 #define ARM64_WORKAROUND_QCOM_FALKOR_E1003	18
 #define ARM64_WORKAROUND_858921			19
+#define ARM64_HAS_RAS_EXTN			20
 
-#define ARM64_NCAPS				20
+#define ARM64_NCAPS				21
 
 #endif /* __ASM_CPUCAPS_H */
arch/arm64/include/asm/sysreg.h +2 -0
index 15c142ce991c..e7d3952a4fa2 100644
@@ -310,6 +310,7 @@
 #define ID_AA64ISAR1_JSCVT_SHIFT	12
 
 /* id_aa64pfr0 */
+#define ID_AA64PFR0_RAS_SHIFT		28
 #define ID_AA64PFR0_GIC_SHIFT		24
 #define ID_AA64PFR0_ASIMD_SHIFT		20
 #define ID_AA64PFR0_FP_SHIFT		16
@@ -318,6 +319,7 @@
 #define ID_AA64PFR0_EL1_SHIFT		4
 #define ID_AA64PFR0_EL0_SHIFT		0
 
+#define ID_AA64PFR0_RAS_V1		0x1
 #define ID_AA64PFR0_FP_NI		0xf
 #define ID_AA64PFR0_FP_SUPPORTED	0x0
 #define ID_AA64PFR0_ASIMD_NI		0xf
arch/arm64/kernel/cpufeature.c +13 -0
index 94b8f7fc3310..672efab887c2 100644
@@ -105,6 +105,7 @@ static const struct arm64_ftr_bits ftr_id_aa64isar1[] = {
 };
 
 static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = {
+	ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_EXACT, ID_AA64PFR0_RAS_SHIFT, 4, 0),
 	ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_EXACT, ID_AA64PFR0_GIC_SHIFT, 4, 0),
 	S_ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_ASIMD_SHIFT, 4, ID_AA64PFR0_ASIMD_NI),
 	S_ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_FP_SHIFT, 4, ID_AA64PFR0_FP_NI),
@@ -867,6 +868,18 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
 		.min_field_value = 0,
 		.matches = has_no_fpsimd,
 	},
+#ifdef CONFIG_ARM64_RAS_EXTN
+	{
+		.desc = "RAS Extension Support",
+		.capability = ARM64_HAS_RAS_EXTN,
+		.def_scope = SCOPE_SYSTEM,
+		.matches = has_cpuid_feature,
+		.sys_reg = SYS_ID_AA64PFR0_EL1,
+		.sign = FTR_UNSIGNED,
+		.field_pos = ID_AA64PFR0_RAS_SHIFT,
+		.min_field_value = ID_AA64PFR0_RAS_V1,
+	},
+#endif /* CONFIG_ARM64_RAS_EXTN */
 	{},
 };
 
arch/arm64/kernel/process.c +3 -0
index ae2a835898d7..01165f9f209d 100644
@@ -358,6 +358,9 @@ __notrace_funcgraph struct task_struct *__switch_to(struct task_struct *prev,
 	 */
 	dsb(ish);
 
+	/* Deliver any pending SError from prev */
+	esb();
+
 	/* the actual thread switch */
 	last = cpu_switch_to(prev, next);
 
Signature · 1 line
2.11.0