linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] arm64: entry: preparatory cleanup
@ 2020-01-16 18:35 Mark Rutland
  2020-01-16 18:35 ` [PATCH 1/5] arm64: assembler: remove inherit_daif macro Mark Rutland
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Mark Rutland @ 2020-01-16 18:35 UTC (permalink / raw)
  To: linux-arm-kernel, will, catalin.marinas
  Cc: mark.rutland, james.morse, anshuman.khandual

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/20200108185634.1163-1-mark.rutland@arm.com
[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(-)

-- 
2.11.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] arm64: assembler: remove inherit_daif macro
  2020-01-16 18:35 [PATCH 0/5] arm64: entry: preparatory cleanup Mark Rutland
@ 2020-01-16 18:35 ` Mark Rutland
  2020-01-16 18:35 ` [PATCH 2/5] arm64: assembler: remove smp_dmb macro Mark Rutland
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Mark Rutland @ 2020-01-16 18:35 UTC (permalink / raw)
  To: linux-arm-kernel, will, catalin.marinas
  Cc: mark.rutland, james.morse, anshuman.khandual

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.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Will Deacon <will@kernel.org>
---
 arch/arm64/include/asm/assembler.h | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
index b8cf7c85ffa2..5f8a2772baeb 100644
--- a/arch/arm64/include/asm/assembler.h
+++ b/arch/arm64/include/asm/assembler.h
@@ -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)
-- 
2.11.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/5] arm64: assembler: remove smp_dmb macro
  2020-01-16 18:35 [PATCH 0/5] arm64: entry: preparatory cleanup Mark Rutland
  2020-01-16 18:35 ` [PATCH 1/5] arm64: assembler: remove inherit_daif macro Mark Rutland
@ 2020-01-16 18:35 ` Mark Rutland
  2020-01-16 18:35 ` [PATCH 3/5] arm64: entry: mark all entry code as notrace Mark Rutland
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Mark Rutland @ 2020-01-16 18:35 UTC (permalink / raw)
  To: linux-arm-kernel, will, catalin.marinas
  Cc: mark.rutland, james.morse, anshuman.khandual

These 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.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
---
 arch/arm64/include/asm/assembler.h | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
index 5f8a2772baeb..995362adaac0 100644
--- a/arch/arm64/include/asm/assembler.h
+++ b/arch/arm64/include/asm/assembler.h
@@ -80,13 +80,6 @@
 	.endm
 
 /*
- * SMP data memory barrier
- */
-	.macro	smp_dmb, opt
-	dmb	\opt
-	.endm
-
-/*
  * RAS Error Synchronization barrier
  */
 	.macro  esb
-- 
2.11.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/5] arm64: entry: mark all entry code as notrace
  2020-01-16 18:35 [PATCH 0/5] arm64: entry: preparatory cleanup Mark Rutland
  2020-01-16 18:35 ` [PATCH 1/5] arm64: assembler: remove inherit_daif macro Mark Rutland
  2020-01-16 18:35 ` [PATCH 2/5] arm64: assembler: remove smp_dmb macro Mark Rutland
@ 2020-01-16 18:35 ` Mark Rutland
  2020-01-16 18:35 ` [PATCH 4/5] arm64: entry: cleanup el0 svc handler naming Mark Rutland
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Mark Rutland @ 2020-01-16 18:35 UTC (permalink / raw)
  To: linux-arm-kernel, will, catalin.marinas
  Cc: mark.rutland, james.morse, anshuman.khandual

Almost 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.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Will Deacon <will@kernel.org>
---
 arch/arm64/kernel/entry-common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
index 5dce5e56995a..67198142a0fc 100644
--- a/arch/arm64/kernel/entry-common.c
+++ b/arch/arm64/kernel/entry-common.c
@@ -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);
-- 
2.11.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/5] arm64: entry: cleanup el0 svc handler naming
  2020-01-16 18:35 [PATCH 0/5] arm64: entry: preparatory cleanup Mark Rutland
                   ` (2 preceding siblings ...)
  2020-01-16 18:35 ` [PATCH 3/5] arm64: entry: mark all entry code as notrace Mark Rutland
@ 2020-01-16 18:35 ` Mark Rutland
  2020-01-16 18:35 ` [PATCH 5/5] arm64: entry: cleanup sp_el0 manipulation Mark Rutland
  2020-01-17 13:51 ` [PATCH 0/5] arm64: entry: preparatory cleanup Will Deacon
  5 siblings, 0 replies; 7+ messages in thread
From: Mark Rutland @ 2020-01-16 18:35 UTC (permalink / raw)
  To: linux-arm-kernel, will, catalin.marinas
  Cc: mark.rutland, james.morse, anshuman.khandual

For 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.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Will Deacon <will@kernel.org>
---
 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(-)

diff --git a/arch/arm64/include/asm/exception.h b/arch/arm64/include/asm/exception.h
index 4d5f3b5f50cd..b87c6e276ab1 100644
--- a/arch/arm64/include/asm/exception.h
+++ b/arch/arm64/include/asm/exception.h
@@ -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);
 
diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
index 67198142a0fc..fde59981445c 100644
--- a/arch/arm64/kernel/entry-common.c
+++ b/arch/arm64/kernel/entry-common.c
@@ -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);
 
diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c
index 9a9d98a443fc..a12c0c88d345 100644
--- a/arch/arm64/kernel/syscall.c
+++ b/arch/arm64/kernel/syscall.c
@@ -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);
-- 
2.11.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/5] arm64: entry: cleanup sp_el0 manipulation
  2020-01-16 18:35 [PATCH 0/5] arm64: entry: preparatory cleanup Mark Rutland
                   ` (3 preceding siblings ...)
  2020-01-16 18:35 ` [PATCH 4/5] arm64: entry: cleanup el0 svc handler naming Mark Rutland
@ 2020-01-16 18:35 ` Mark Rutland
  2020-01-17 13:51 ` [PATCH 0/5] arm64: entry: preparatory cleanup Will Deacon
  5 siblings, 0 replies; 7+ messages in thread
From: Mark Rutland @ 2020-01-16 18:35 UTC (permalink / raw)
  To: linux-arm-kernel, will, catalin.marinas
  Cc: mark.rutland, james.morse, anshuman.khandual

The 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.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Will Deacon <will@kernel.org>
---
 arch/arm64/kernel/entry.S | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index 7c6a0a41676f..3d7a9c0ab844 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -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
-- 
2.11.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/5] arm64: entry: preparatory cleanup
  2020-01-16 18:35 [PATCH 0/5] arm64: entry: preparatory cleanup Mark Rutland
                   ` (4 preceding siblings ...)
  2020-01-16 18:35 ` [PATCH 5/5] arm64: entry: cleanup sp_el0 manipulation Mark Rutland
@ 2020-01-17 13:51 ` Will Deacon
  5 siblings, 0 replies; 7+ messages in thread
From: Will Deacon @ 2020-01-17 13:51 UTC (permalink / raw)
  To: Mark Rutland
  Cc: catalin.marinas, james.morse, linux-arm-kernel, anshuman.khandual

On Thu, Jan 16, 2020 at 06:35:43PM +0000, Mark Rutland wrote:
> 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
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-01-17 13:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-16 18:35 [PATCH 0/5] arm64: entry: preparatory cleanup Mark Rutland
2020-01-16 18:35 ` [PATCH 1/5] arm64: assembler: remove inherit_daif macro Mark Rutland
2020-01-16 18:35 ` [PATCH 2/5] arm64: assembler: remove smp_dmb macro Mark Rutland
2020-01-16 18:35 ` [PATCH 3/5] arm64: entry: mark all entry code as notrace Mark Rutland
2020-01-16 18:35 ` [PATCH 4/5] arm64: entry: cleanup el0 svc handler naming Mark Rutland
2020-01-16 18:35 ` [PATCH 5/5] arm64: entry: cleanup sp_el0 manipulation Mark Rutland
2020-01-17 13:51 ` [PATCH 0/5] arm64: entry: preparatory cleanup Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).