From: Lorenzo Pieralisi <lpieralisi@kernel.org>
To: Mark Brown <broonie@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Marc Zyngier <maz@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Sami Mujawar <Sami.Mujawar@arm.com>,
Thomas Gleixner <tglx@linutronix.de>,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev
Subject: Re: [PATCH v2 10/14] arm64/nmi: Manage masking for superpriority interrupts along with DAIF
Date: Thu, 8 Dec 2022 18:19:02 +0100 [thread overview]
Message-ID: <Y5IchpFrIB3y8575@lpieralisi> (raw)
In-Reply-To: <20221112151708.175147-11-broonie@kernel.org>
On Sat, Nov 12, 2022 at 03:17:04PM +0000, Mark Brown wrote:
> As we do for pseudo NMIs add code to our DAIF management which keeps
> superpriority interrupts unmasked when we have asynchronous exceptions
> enabled. Since superpriority interrupts are not masked through DAIF like
> pseduo NMIs are we also need to modify the assembler macros for managing
> DAIF to ensure that the masking is done in the assembly code. At present
> users of the assembly macros always mask pseudo NMIs.
>
> There is a difference to the actual handling between pseudo NMIs
> and superpriority interrupts in the assembly save_and_disable_irq and
> restore_irq macros, these cover both interrupts and FIQs using DAIF
> without regard for the use of pseudo NMIs so also mask those but are not
> updated here to mask superpriority interrupts. Given the names it is not
> clear that the behaviour with pseudo NMIs is particularly intentional,
> and in any case these macros are only used in the implementation of
> alternatives for software PAN while hardware PAN has been mandatory
> since v8.1 so it is not anticipated that practical systems with support
> for FEAT_NMI will ever execute the affected code.
>
> This should be a conservative set of masked regions, we may be able to
> relax this in future, but this should represent a good starting point.
I think I found a nasty spot. We are currently not handling ALLINT in
arch_local_irq_enable/disable(). The issue I am facing is that we might
end up preempting in IRQ context with ALLINT set in the exception path
- arm64_preempt_schedule_irq() - which means we are running with all
IRQs masked (that's normal; what's not normal is that local_irq_enable()
does not clear ALLINT, see below).
When we schedule (preempt_schedule_irq()) we do require a
local_irq_enable() to enable IRQs; ALLINT is still set, so
local_irq_enable() does not do what is expected so we are calling
__schedule() with IRQs disabled, which does not seem right.
Now we need to debate what the fix for this can be but nonetheless
it is something to be addressed.
Clearing and setting ALLINT in arch_local_irq_enable()/disable()
seems to solve the issue (now I moved on to debugging something
else, will post the outcome here because this fix does not seem
to fix the issue completely or I am hitting another bug).
Lorenzo
> Signed-off-by: Mark Brown <broonie@kernel.org>
> ---
> arch/arm64/include/asm/assembler.h | 11 +++++++++++
> arch/arm64/include/asm/daifflags.h | 18 ++++++++++++++++++
> 2 files changed, 29 insertions(+)
>
> diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
> index 88d9779a83c0..e85a7e9af9ae 100644
> --- a/arch/arm64/include/asm/assembler.h
> +++ b/arch/arm64/include/asm/assembler.h
> @@ -52,19 +52,30 @@ alternative_else_nop_endif
>
> .macro save_and_disable_daif, flags
> mrs \flags, daif
> + disable_allint
> msr daifset, #0xf
> .endm
>
> .macro disable_daif
> + disable_allint
> msr daifset, #0xf
> .endm
>
> .macro enable_daif
> msr daifclr, #0xf
> + enable_allint
> .endm
>
> .macro restore_daif, flags:req
> msr daif, \flags
> +#ifdef CONFIG_ARM64_NMI
> +alternative_if ARM64_HAS_NMI
> + /* If async exceptions are unmasked we can take NMIs */
> + tbnz \flags, #8, 2004f
> + msr_s SYS_ALLINT_CLR, xzr
> +2004:
> +alternative_else_nop_endif
> +#endif
> .endm
>
> /* IRQ/FIQ are the lowest priority flags, unconditionally unmask the rest. */
> diff --git a/arch/arm64/include/asm/daifflags.h b/arch/arm64/include/asm/daifflags.h
> index b3bed2004342..fda73976068f 100644
> --- a/arch/arm64/include/asm/daifflags.h
> +++ b/arch/arm64/include/asm/daifflags.h
> @@ -10,6 +10,7 @@
> #include <asm/arch_gicv3.h>
> #include <asm/barrier.h>
> #include <asm/cpufeature.h>
> +#include <asm/nmi.h>
> #include <asm/ptrace.h>
>
> #define DAIF_PROCCTX 0
> @@ -35,6 +36,9 @@ static inline void local_daif_mask(void)
> if (system_uses_irq_prio_masking())
> gic_write_pmr(GIC_PRIO_IRQON | GIC_PRIO_PSR_I_SET);
>
> + if (system_uses_nmi())
> + _allint_set();
> +
> trace_hardirqs_off();
> }
>
> @@ -50,6 +54,12 @@ static inline unsigned long local_daif_save_flags(void)
> flags |= PSR_I_BIT | PSR_F_BIT;
> }
>
> + if (system_uses_nmi()) {
> + /* If IRQs are masked with ALLINT, reflect in in the flags */
> + if (read_sysreg_s(SYS_ALLINT) & ALLINT_ALLINT)
> + flags |= PSR_I_BIT | PSR_F_BIT;
> + }
> +
> return flags;
> }
>
> @@ -114,6 +124,10 @@ static inline void local_daif_restore(unsigned long flags)
> gic_write_pmr(pmr);
> }
>
> + /* If we can take asynchronous errors we can take NMIs */
> + if (system_uses_nmi() && !(flags & PSR_A_BIT))
> + _allint_clear();
> +
> write_sysreg(flags, daif);
>
> if (irq_disabled)
> @@ -131,6 +145,10 @@ static inline void local_daif_inherit(struct pt_regs *regs)
> if (interrupts_enabled(regs))
> trace_hardirqs_on();
>
> + /* If we can take asynchronous errors we can take NMIs */
> + if (system_uses_nmi() && !(flags & PSR_A_BIT))
> + _allint_clear();
> +
> if (system_uses_irq_prio_masking())
> gic_write_pmr(regs->pmr_save);
>
> --
> 2.30.2
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
_______________________________________________
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:[~2022-12-08 17:20 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-12 15:16 [PATCH v2 00/14] arm64/nmi: Support for FEAT_NMI Mark Brown
2022-11-12 15:16 ` [PATCH v2 01/14] arm64/booting: Document boot requirements " Mark Brown
2022-11-12 15:16 ` [PATCH v2 02/14] arm64/sysreg: Add definition for ICC_NMIAR1_EL1 Mark Brown
2022-11-12 15:16 ` [PATCH v2 03/14] arm64/sysreg: Add definition of ISR_EL1 Mark Brown
2022-12-05 16:45 ` Marc Zyngier
2022-11-12 15:16 ` [PATCH v2 04/14] arm64/sysreg: Add definitions for immediate versions of MSR ALLINT Mark Brown
2022-12-05 16:38 ` Marc Zyngier
2022-12-05 17:11 ` Mark Brown
2022-12-07 19:18 ` Marc Zyngier
2022-12-07 19:42 ` Mark Brown
2022-11-12 15:16 ` [PATCH v2 05/14] arm64/asm: Introduce assembly macros for managing ALLINT Mark Brown
2022-12-05 17:29 ` Marc Zyngier
2022-12-05 18:24 ` Mark Brown
2022-12-07 19:14 ` Marc Zyngier
2022-11-12 15:17 ` [PATCH v2 06/14] arm64/hyp-stub: Enable access to ALLINT Mark Brown
2022-12-05 17:50 ` Marc Zyngier
2022-11-12 15:17 ` [PATCH v2 07/14] arm64/idreg: Add an override for FEAT_NMI Mark Brown
2022-11-12 15:17 ` [PATCH v2 08/14] arm64/cpufeature: Detect PE support " Mark Brown
2022-12-05 18:03 ` Marc Zyngier
2022-12-05 19:32 ` Mark Brown
2022-12-07 19:06 ` Marc Zyngier
2022-11-12 15:17 ` [PATCH v2 09/14] KVM: arm64: Hide FEAT_NMI from guests Mark Brown
2022-12-05 18:06 ` Marc Zyngier
2022-12-05 19:03 ` Mark Brown
2022-12-07 19:03 ` Marc Zyngier
2022-12-07 19:33 ` Mark Brown
2022-11-12 15:17 ` [PATCH v2 10/14] arm64/nmi: Manage masking for superpriority interrupts along with DAIF Mark Brown
2022-12-05 18:47 ` Marc Zyngier
2022-12-05 20:52 ` Mark Brown
2022-12-08 17:19 ` Lorenzo Pieralisi [this message]
2022-12-12 14:03 ` Mark Brown
2022-12-13 8:37 ` Lorenzo Pieralisi
2022-12-13 13:15 ` Mark Brown
2022-12-15 13:32 ` Marc Zyngier
2022-12-12 14:40 ` Mark Rutland
2022-12-15 13:21 ` Mark Brown
2022-11-12 15:17 ` [PATCH v2 11/14] arm64/irq: Document handling of FEAT_NMI in irqflags.h Mark Brown
2022-11-12 15:17 ` [PATCH v2 12/14] arm64/nmi: Add handling of superpriority interrupts as NMIs Mark Brown
2022-12-07 11:03 ` Marc Zyngier
2022-12-07 13:24 ` Mark Brown
2022-12-07 18:57 ` Marc Zyngier
2022-12-07 19:15 ` Mark Brown
2022-11-12 15:17 ` [PATCH v2 13/14] arm64/nmi: Add Kconfig for NMI Mark Brown
2022-11-12 15:17 ` [PATCH v2 14/14] irqchip/gic-v3: Implement FEAT_GICv3_NMI support Mark Brown
2022-12-07 15:20 ` Marc Zyngier
2022-12-02 18:42 ` [PATCH v2 00/14] arm64/nmi: Support for FEAT_NMI Marc Zyngier
2022-12-03 8:25 ` Lorenzo Pieralisi
2022-12-03 9:45 ` Marc Zyngier
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=Y5IchpFrIB3y8575@lpieralisi \
--to=lpieralisi@kernel.org \
--cc=Sami.Mujawar@arm.com \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=tglx@linutronix.de \
--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).