arm64: entry: preparatory cleanup
Mark Rutland
reviewercover arm64: entry: preparatory cleanup
Hi,
While reworking my entry deasmification patches [1], I realised that there are few bits I'm not quite comfortable with and will require a little bit more time to make robust. Mostly that has to do with manipulation of DAIF, irq flags, and the GIC PMR. I'm hoping that I can have the reworked patches ready around v5.6-rc1.
In the mean time, I've split out these preparatory patches in the hope that they can be queued now. These are based on v5.5-rc3, and I've pushed them to my arm64/entry-deasm-prep branch [2,3].
Thanks,
Mark.
[1] https://lore.kernel.org/r/[email protected]
[2] https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/log/?h=arm64/entry-deasm-prep
[3] git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arm64/entry-deasm-prep
Mark Rutland (5):
arm64: assembler: remove inherit_daif macro
arm64: assembler: remove smp_dmb macro
arm64: entry: mark all entry code as notrace
arm64: entry: cleanup el0 svc handler naming
arm64: entry: cleanup sp_el0 manipulation
arch/arm64/include/asm/assembler.h | 13 ------------- arch/arm64/include/asm/exception.h | 4 ++-- arch/arm64/kernel/entry-common.c | 8 ++++---- arch/arm64/kernel/entry.S | 17 +++++++---------- arch/arm64/kernel/syscall.c | 4 ++-- 5 files changed, 15 insertions(+), 31 deletions(-)
Signature · 7 lines
2.11.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Mark Rutland
reviewerPATCH 1/5 arm64: assembler: remove inherit_daif macro
We haven't needed the inherit_daif macro since commit:
ed3768db588291dd ("arm64: entry: convert el1_sync to C")
... which converted all callers to C and the local_daif_inherit function.
Remove the unused macro.
--- arch/arm64/include/asm/assembler.h | 6 ------ 1 file changed, 6 deletions(-)
arch/arm64/include/asm/assembler.h +0 -6
@@ -40,12 +40,6 @@ 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 - /* IRQ is the lowest priority flag, unconditionally unmask the rest. */ .macro enable_da_f msr daifclr, #(8 | 4 | 1)
Signature · 7 lines
2.11.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Mark Rutland
reviewerPATCH 2/5 arm64: assembler: remove smp_dmb macro
In reply to Mark RutlandThese days arm64 kernels are always SMP, and thus smp_dmb is an overly-long way of writing dmb. Naturally, no-one uses it.
Remove the unused macro.
--- arch/arm64/include/asm/assembler.h | 7 ------- 1 file changed, 7 deletions(-)
arch/arm64/include/asm/assembler.h +0 -7
@@ -80,13 +80,6 @@ .endm /* - * SMP data memory barrier - */ - .macro smp_dmb, opt - dmb \opt - .endm - -/* * RAS Error Synchronization barrier */ .macro esb
Signature · 7 lines
2.11.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Mark Rutland
reviewerPATCH 3/5 arm64: entry: mark all entry code as notrace
In reply to Mark RutlandAlmost all functions in entry-common.c are marked notrace, with el1_undef and el1_inv being the only exceptions. We appear to have done this on the assumption that there were no exception registers that we needed to snapshot, and thus it was safe to run trace code that might result in further exceptions and clobber those registers.
However, until we inherit the DAIF flags, our irq flag tracing is stale, and this discrepancy could set off warnings in some configurations. For example if CONFIG_DEBUG_LOCKDEP is selected and a trace function calls into any flag-checking locking routines. Given we don't expect to trigger el1_undef or el1_inv unless something is already wrong, any irqflag warnigns are liable to mask the information we'd actually care about.
Let's keep things simple and mark el1_undef and el1_inv as notrace. Developers can trace do_undefinstr and bad_mode if they really want to monitor these cases.
--- arch/arm64/kernel/entry-common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/entry-common.c +2 -2
@@ -36,14 +36,14 @@ static void notrace el1_pc(struct pt_regs *regs, unsigned long esr) }NOKPROBE_SYMBOL (el1_pc); -static void el1_undef (struct pt_regs *regs) +static void notrace el1_undef(struct pt_regs *regs) {local_daif_inherit (regs);do_undefinstr (regs); }NOKPROBE_SYMBOL (el1_undef); -static void el1_inv (struct pt_regs *regs,unsigned long esr) +static void notrace el1_inv(struct pt_regs *regs, unsigned long esr) {local_daif_inherit (regs);bad_mode (regs,0 , esr);
Signature · 7 lines
2.11.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Mark Rutland
reviewerPATCH 4/5 arm64: entry: cleanup el0 svc handler naming
In reply to Mark RutlandFor most of the exception entry code, <foo>_handler() is the first C function called from the entry assembly in entry-common.c, and external functions handling the bulk of the logic are called do_<foo>().
For consistency, apply this scheme to el0_svc_handler and el0_svc_compat_handler, renaming them to do_el0_svc and do_el0_svc_compat respectively.
There should be no functional change as a result of this patch.
--- arch/arm64/include/asm/exception.h | 4 ++-- arch/arm64/kernel/entry-common.c | 4 ++-- arch/arm64/kernel/syscall.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
arch/arm64/include/asm/exception.h +2 -2
@@ -45,8 +45,8 @@ void do_sysinstr(unsigned int esr, struct pt_regs *regs);void do_sp_pc_abort (unsigned long addr,unsigned int esr,struct pt_regs *regs);void bad_el0_sync (struct pt_regs *regs,int reason,unsigned int esr);void do_cp15instr (unsigned int esr,struct pt_regs *regs); -void el0_svc_handler (struct pt_regs *regs); -void el0_svc_compat_handler (struct pt_regs *regs); +void do_el0_svc (struct pt_regs *regs); +void do_el0_svc_compat (struct pt_regs *regs);void do_el0_ia_bp_hardening (unsigned long addr,unsigned int esr,struct pt_regs *regs);
arch/arm64/kernel/entry-common.c +2 -2
@@ -215,7 +215,7 @@ static void notrace el0_svc(struct pt_regs *regs)if (system_uses_irq_prio_masking ())gic_write_pmr (GIC_PRIO_IRQON |GIC_PRIO_PSR_I_SET ); -el0_svc_handler (regs); +do_el0_svc (regs); }NOKPROBE_SYMBOL (el0_svc);
@@ -281,7 +281,7 @@ static void notrace el0_svc_compat(struct pt_regs *regs)if (system_uses_irq_prio_masking ())gic_write_pmr (GIC_PRIO_IRQON |GIC_PRIO_PSR_I_SET ); -el0_svc_compat_handler (regs); +do_el0_svc_compat (regs); }NOKPROBE_SYMBOL (el0_svc_compat);
arch/arm64/kernel/syscall.c +2 -2
@@ -154,14 +154,14 @@ static inline void sve_user_discard(void)sve_user_disable (); } -void el0_svc_handler (struct pt_regs *regs) +void do_el0_svc (struct pt_regs *regs) {sve_user_discard ();el0_svc_common (regs, regs->regs[8 ], __NR_syscalls, sys_call_table); }#ifdef CONFIG_COMPAT -void el0_svc_compat_handler (struct pt_regs *regs) +void do_el0_svc_compat (struct pt_regs *regs) {el0_svc_common (regs, regs->regs[7 ], __NR_compat_syscalls, compat_sys_call_table);
Signature · 7 lines
2.11.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Mark Rutland
reviewerPATCH 5/5 arm64: entry: cleanup sp_el0 manipulation
In reply to Mark RutlandThe kernel stashes the current task struct in sp_el0 so that this can be acquired consistently/cheaply when required. When we take an exception from EL0 we have to:
1) stash the original sp_el0 value
2) find the current task
3) update sp_el0 with the current task pointer
Currently steps #1 and #2 occur in one place, and step #3 a while later. As the value of sp_el0 is immaterial between these points, let's move them together to make the code clearer and minimize ifdeffery. This necessitates moving the comment for MDSCR_EL1.SS.
There should be no functional change as a result of this patch.
--- arch/arm64/kernel/entry.S | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
arch/arm64/kernel/entry.S +7 -10
@@ -167,9 +167,13 @@ alternative_cb_end .if \el == 0 clear_gp_regs mrs x21, sp_el0 - ldr_this_cpu tsk, __entry_task, x20 // Ensure MDSCR_EL1.SS is clear, - ldr x19, [tsk, #TSK_TI_FLAGS] // since we can unmask debug - disable_step_tsk x19, x20 // exceptions when scheduling. + ldr_this_cpu tsk, __entry_task, x20 + msr sp_el0, tsk + + // Ensure MDSCR_EL1.SS is clear, since we can unmask debug exceptions + // when scheduling. + ldr x19, [tsk, #TSK_TI_FLAGS] + disable_step_tsk x19, x20 apply_ssbd 1, x22, x23
@@ -232,13 +236,6 @@ alternative_else_nop_endif str w21, [sp, #S_SYSCALLNO] .endif - /* - * Set sp_el0 to current thread_info. - */ - .if \el == 0 - msr sp_el0, tsk - .endif - /* Save pmr */ alternative_if ARM64_HAS_IRQ_PRIO_MASKING mrs_s x20, SYS_ICC_PMR_EL1
Signature · 7 lines
2.11.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon
maintainerQuoted 9 lines · Mark Rutland
While reworking my entry deasmification patches [1], I realised that there are few bits I'm not quite comfortable with and will require a little bit more time to make robust. Mostly that has to do with manipulation of DAIF, irq flags, and the GIC PMR. I'm hoping that I can have the reworked patches ready around v5.6-rc1.
In the mean time, I've split out these preparatory patches in the hope that they can be queued now. These are based on v5.5-rc3, and I've pushed them to my arm64/entry-deasm-prep branch [2,3].
Cheers, applied.
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel