From: Mark Rutland <mark.rutland@arm.com>
To: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: keescook@chromium.org, maz@kernel.org, robin.murphy@arm.com,
broonie@kernel.org, james.morse@arm.com,
julien.thierry.kdev@gmail.com, catalin.marinas@arm.com,
labbott@redhat.com, will@kernel.org,
linux-arm-kernel@lists.infradead.org, alex.popov@linux.com
Subject: Re: [PATCH 04/17] arm64: entry: move preempt logic to C
Date: Thu, 9 Jan 2020 12:22:40 +0000 [thread overview]
Message-ID: <20200109122240.GB3112@lakrids.cambridge.arm.com> (raw)
In-Reply-To: <ed7969dc-e3a2-8b25-9383-ba1a60fb641a@arm.com>
On Thu, Jan 09, 2020 at 12:13:13PM +0530, Anshuman Khandual wrote:
> On 01/09/2020 12:26 AM, Mark Rutland wrote:
> > Some of our preeemption logic is in C, while a portion of it is in
> > assembly. Let's pull the remainder of it into C so that it lives in one
> > place.
> >
> > At the same time, let's improve the comments regarding NMI preemption to
> > make it clearer why we cannot preempt from NMIs.
> >
> > Subsequent patches will covert the caller of el1_preempt() to C.
> >
> > Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > Cc: James Morse <james.morse@arm.com>
> > Cc: Julien Thierry <julien.thierry.kdev@gmail.com>
> > Cc: Will Deacon <will@kernel.org>
> > ---
> > arch/arm64/kernel/entry-common.c | 18 +++++++++++++++++-
> > arch/arm64/kernel/entry.S | 13 +------------
> > 2 files changed, 18 insertions(+), 13 deletions(-)
> >
> > diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
> > index 4fa058453468..b93ca2148a20 100644
> > --- a/arch/arm64/kernel/entry-common.c
> > +++ b/arch/arm64/kernel/entry-common.c
> > @@ -8,6 +8,7 @@
> > #include <linux/context_tracking.h>
> > #include <linux/linkage.h>
> > #include <linux/lockdep.h>
> > +#include <linux/preempt.h>
> > #include <linux/ptrace.h>
> > #include <linux/sched/debug.h>
> > #include <linux/thread_info.h>
> > @@ -334,8 +335,23 @@ asmlinkage void notrace el0_sync_compat_handler(struct pt_regs *regs)
> > NOKPROBE_SYMBOL(el0_sync_compat_handler);
> > #endif /* CONFIG_COMPAT */
> >
> > -asmlinkage void __sched arm64_preempt_schedule_irq(void)
> > +asmlinkage void __sched el1_preempt(void)
> > {
> > + if (!IS_ENABLED(CONFIG_PREEMPT) || preempt_count())
> > + return;
>
> IS_ENABLED(CONFIG_PREEMPT) is not really required here as the single
> call site for el1_preempt() is still wrapped around CONFIG_PREEMPT.
> So we should retain any one of them.
Using both was deliberate.
I wanted to avoid ifdeffery here, but also wanted to avoid the
unnecessary bits being build for !CONFIG_PREEMPT buillds, in both this
function and the caller.
In a subsequent patch this'll be made static, and called
unconditionally, where we'll definitely need to IS_ENABLED(). I'll
update the commit message to make this part explicit.
>
> > +
> > + /*
> > + * To avoid nesting NMIs and overflowing the stack, we must leave NMIs
> > + * masked until the exception return. We want to context-switch with
> > + * IRQs masked but NMIs enabled, so cannot preempt an NMI.
> > + *
> > + * PSTATE.{D,A,F} are cleared for IRQ and NMI by el1_irq().
> > + * When gic_handle_irq() handles an NMI, it leaves PSTATE.I set.
> > + * If anything is set in DAIF, this is an NMI.
> > + */
> > + if (system_uses_irq_prio_masking() && read_sysreg(daif) != 0)
>
> In case above CONFIG_PREEMPT gets dropped, preempt_count() can be
> moved here as well.
As above, I'm going to leave this as-is.
I also think it's worth keeping this separate from the early return for
!preempt_count() due to the comment, which is specific to the GIC prio
masking logic.
Thanks,
Mark.
>
> > + return;
> > +
> > lockdep_assert_irqs_disabled();
> >
> > /*
> > diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
> > index 7c6a0a41676f..53ce1877a4aa 100644
> > --- a/arch/arm64/kernel/entry.S
> > +++ b/arch/arm64/kernel/entry.S
> > @@ -606,18 +606,7 @@ el1_irq:
> > irq_handler
> >
> > #ifdef CONFIG_PREEMPT
> > - ldr x24, [tsk, #TSK_TI_PREEMPT] // get preempt count
> > -alternative_if ARM64_HAS_IRQ_PRIO_MASKING
> > - /*
> > - * DA_F were cleared at start of handling. If anything is set in DAIF,
> > - * we come back from an NMI, so skip preemption
> > - */
> > - mrs x0, daif
> > - orr x24, x24, x0
> > -alternative_else_nop_endif
> > - cbnz x24, 1f // preempt count != 0 || NMI return path
> > - bl arm64_preempt_schedule_irq // irq en/disable is done inside
> > -1:
> > + bl el1_preempt
> > #endif
> >
> > #ifdef CONFIG_ARM64_PSEUDO_NMI
> >
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-01-09 12:22 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-08 18:56 [PATCH 00/17] arm64: entry deasmification and cleanup Mark Rutland
2020-01-08 18:56 ` [PATCH 01/17] arm64: entry: mark all entry code as notrace Mark Rutland
2020-01-09 5:21 ` Anshuman Khandual
2020-01-13 15:44 ` Mark Rutland
2020-01-08 18:56 ` [PATCH 02/17] arm64: entry: cleanup el0 svc handler naming Mark Rutland
2020-01-09 5:33 ` Anshuman Khandual
2020-01-08 18:56 ` [PATCH 03/17] arm64: entry: move arm64_preempt_schedule_irq to entry-common.c Mark Rutland
2020-01-09 5:36 ` Anshuman Khandual
2020-01-08 18:56 ` [PATCH 04/17] arm64: entry: move preempt logic to C Mark Rutland
2020-01-09 6:43 ` Anshuman Khandual
2020-01-09 12:22 ` Mark Rutland [this message]
2020-01-08 18:56 ` [PATCH 05/17] arm64: entry: add a call_on_stack helper Mark Rutland
2020-01-09 8:00 ` Anshuman Khandual
2020-01-14 18:24 ` Mark Rutland
2020-01-09 14:30 ` Laura Abbott
2020-01-09 14:46 ` Mark Rutland
2020-01-08 18:56 ` [PATCH 06/17] arm64: entry: convert irq entry to C Mark Rutland
2020-01-08 18:56 ` [PATCH 07/17] arm64: entry: convert error " Mark Rutland
2020-01-09 9:12 ` Anshuman Khandual
2020-01-09 12:49 ` Mark Rutland
2020-01-08 18:56 ` [PATCH 08/17] arm64: entry: Split el0_sync_compat from el0_sync Mark Rutland
2020-01-09 9:50 ` Anshuman Khandual
2020-01-08 18:56 ` [PATCH 09/17] arm64: entry: organise handler stubs consistently Mark Rutland
2020-01-09 10:01 ` Anshuman Khandual
2020-01-08 18:56 ` [PATCH 10/17] arm64: entry: consolidate EL1 return paths Mark Rutland
2020-01-10 3:39 ` Anshuman Khandual
2020-01-10 16:02 ` Mark Rutland
2020-01-08 18:56 ` [PATCH 11/17] stackleak: allow C to call stackleak_erase() Mark Rutland
2020-01-10 3:45 ` Anshuman Khandual
2020-01-10 16:07 ` Mark Rutland
2020-01-27 23:00 ` Kees Cook
2020-01-08 18:56 ` [PATCH 12/17] arm64: debug-monitors: refactor MDSCR manipulation Mark Rutland
2020-01-10 4:35 ` Anshuman Khandual
2020-01-10 16:09 ` Mark Rutland
2020-01-08 18:56 ` [PATCH 13/17] arm64: entry: move common el0 entry/return work to C Mark Rutland
2020-01-09 15:19 ` Mark Rutland
2020-01-08 18:56 ` [PATCH 14/17] arm64: entry: move NO_SYSCALL setup " Mark Rutland
2020-01-10 5:37 ` Anshuman Khandual
2020-01-08 18:56 ` [PATCH 15/17] arm64: entry: move ARM64_ERRATUM_845719 workaround " Mark Rutland
2020-01-08 18:56 ` [PATCH 16/17] arm64: entry: move ARM64_ERRATUM_1418040 " Mark Rutland
2020-01-08 18:56 ` [PATCH 17/17] arm64: entry: cleanup sp_el0 manipulation Mark Rutland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200109122240.GB3112@lakrids.cambridge.arm.com \
--to=mark.rutland@arm.com \
--cc=alex.popov@linux.com \
--cc=anshuman.khandual@arm.com \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=james.morse@arm.com \
--cc=julien.thierry.kdev@gmail.com \
--cc=keescook@chromium.org \
--cc=labbott@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maz@kernel.org \
--cc=robin.murphy@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).