All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jinjie Ruan" <ruanjinjie@huawei.com>
Cc: kvmarm@lists.linux.dev, "Marc Zyngier" <maz@kernel.org>,
	"Oliver Upton" <oupton@kernel.org>
Subject: Re: [PATCH 02/17] arm64: Rework exception masking into abstract logical mask
Date: Fri, 03 Jul 2026 10:15:55 +0000	[thread overview]
Message-ID: <20260703101555.E5FB71F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260703100135.2512312-3-ruanjinjie@huawei.com>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

New issues:
- [High] The `pmr` and `allint` fields of `struct exception_mask` are left uninitialized when hardware features are disabled, causing Undefined Behavior and KMSAN panics.
- [High] Missing `__always_inline` on exception mask helpers leads to noinstr violations.
- [High] `arm64_make_errctx_mask` incorrectly masks pseudo-NMIs during SError handling.
- [High] Unnecessary `pmr_sync()` (DSB barrier) executes unconditionally on masked restore paths.

Pre-existing issues:
- [High] Missing `isb()` after writing to the control-plane system register `mdscr_el1`.
--

commit 464598f1f40c66ead1ff67f84cc61270622c7aa4
Author: Jinjie Ruan <ruanjinjie@huawei.com>

arm64: Rework exception masking into abstract logical mask

The current pseudo-NMI implementation in arm64 bodges the GICv3 PMR state
into the DAIF management code. Introduce a new abstract exception_mask
that explicitly treats DAIF, PMR, and ALLINT as separate elements to cleanly
track the exact hardware masking state.

Link: https://lore.kernel.org/linux-arm-kernel/Y5c9SLeJacLYHmP7@FVFF77S0Q05N/

> diff --git a/arch/arm64/include/asm/exception_masks.h b/arch/arm64/include/asm/exception_masks.h
> new file mode 100644
> index 0000000000000..0a21fb97c3ca8
> --- /dev/null
> +++ b/arch/arm64/include/asm/exception_masks.h
> @@ -0,0 +1,141 @@
[ ... ]
> +static inline struct exception_mask arm64_make_procctx_mask(void)
> +{
> +	struct exception_mask mask;
> +
> +	mask.daif = DAIF_PROCCTX;
> +	if (system_uses_irq_prio_masking())
> +		mask.pmr = GIC_PRIO_IRQON;

[Severity: High]
Does this leave the pmr field in the returned mask uninitialized when
system_uses_irq_prio_masking() is false? Returning this struct by value
might propagate garbage data and trigger use-of-uninitialized-value KMSAN
panics during exception entry paths.

> +
> +	mask.allint = 0;
> +
> +	return mask;
> +}
> +
> +static inline struct exception_mask arm64_make_errctx_mask(void)
> +{
> +	struct exception_mask mask;
> +
> +	mask.daif = DAIF_ERRCTX;
> +	if (system_uses_irq_prio_masking())
> +		mask.pmr = GIC_PRIO_IRQON | GIC_PRIO_PSR_I_SET;

[Severity: High]
Could this construction inadvertently mask pseudo-NMIs during system error
handling? By statically setting mask.daif = DAIF_ERRCTX, the I-bit is left
set, which masks NMIs at the CPU PSTATE level. The legacy code cleared the
I-bit and set PMR to GIC_PRIO_IRQOFF to allow NMIs while blocking normal
IRQs.

> +
> +	mask.allint = 0;
> +
> +	return mask;
> +}
[ ... ]
> +/* Mask all exceptions immediately */
> +static inline void local_exception_mask(void)
> +{

[Severity: High]
Should local_exception_mask() be marked __always_inline? If the compiler
decides not to inline it, calling it from noinstr exception entry and exit
paths (like arm64_exit_to_kernel_mode) violates noinstr constraints and
can lead to recursive panics when tracing is enabled.

> +	WARN_ON(system_has_prio_mask_debugging() &&
> +		(read_sysreg_s(SYS_ICC_PMR_EL1) == (GIC_PRIO_IRQOFF |
> +						    GIC_PRIO_PSR_I_SET)));
[ ... ]
> +static inline void local_exception_save_mask(struct exception_mask *mask)
> +{
> +	mask->daif = read_sysreg(daif);
> +	if (system_uses_irq_prio_masking())
> +		mask->pmr = gic_read_pmr();

[Severity: High]
Is it possible this conditionally populates the mask and leaves the pmr field
uninitialized when hardware priority masking is disabled? Since the caller
might return this struct by value, it could propagate uninitialized memory.

> +
> +	mask->allint = 0;
> +}
[ ... ]
> +static inline void local_exception_restore(const struct exception_mask mask)
> +{

[Severity: High]
Could the lack of __always_inline on local_exception_restore() also cause
noinstr violations? Similar to local_exception_mask(), compiler heuristics
deciding to out-of-line this function would break the noinstr invariant
during exception handling.

> +	bool irq_disabled = mask.daif & PSR_I_BIT;
[ ... ]
> +	if (!irq_disabled)
> +		trace_hardirqs_on();
> +
> +	if (system_uses_irq_prio_masking()) {
> +		gic_write_pmr(mask.pmr);
> +		pmr_sync();
> +	}

[Severity: High]
Is this pmr_sync() execution necessary when interrupts remain disabled?
The legacy code placed the synchronization barrier inside the !irq_disabled
branch, as writing to the pmr register to mask interrupts is
architecturally self-synchronizing. Executing a pipeline-draining dsb
instruction unconditionally adds overhead on masked restore paths like
kernel exception exits.

> +
> +	write_sysreg(mask.daif, daif);
[ ... ]
> diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
> index 29307642f4c90..5b53034428e46 100644
> --- a/arch/arm64/kernel/debug-monitors.c
> +++ b/arch/arm64/kernel/debug-monitors.c
[ ... ]
> @@ -40,10 +40,11 @@ u8 debug_monitors_arch(void)
>   */
>  static void mdscr_write(u64 mdscr)
>  {
> -	unsigned long flags;
> -	flags = local_daif_save();
> +	struct exception_mask mask;
> +
> +	mask = local_exception_save_and_mask();
>  	write_sysreg(mdscr, mdscr_el1);

[Severity: High]
This is a pre-existing issue, but does mdscr_write() require a subsequent
isb() before returning after writing to the control-plane system register
mdscr_el1? Without synchronization, the cpu pipeline might operate under an
undefined debug configuration for several cycles when reached via debug
mechanisms like ptrace.

> -	local_daif_restore(flags);
> +	local_exception_restore(mask);
>  }
>  NOKPROBE_SYMBOL(mdscr_write);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260703100135.2512312-1-ruanjinjie@huawei.com?part=2

  reply	other threads:[~2026-07-03 10:15 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-03 10:01 [PATCH 00/17] arm64: Support FEAT_NMI and Rework Exception Masking Jinjie Ruan
2026-07-03 10:01 ` [PATCH 01/17] arm64: Move DAIF macros to ptrace.h and use them centrally Jinjie Ruan
2026-07-03 16:44   ` Breno Leitao
2026-07-06 12:57     ` Jinjie Ruan
2026-07-03 10:01 ` [PATCH 02/17] arm64: Rework exception masking into abstract logical mask Jinjie Ruan
2026-07-03 10:15   ` sashiko-bot [this message]
2026-07-03 13:38   ` Leonardo Bras
2026-07-06 13:00     ` Jinjie Ruan
2026-07-06 13:02       ` Leonardo Bras
2026-07-03 13:48   ` Leonardo Bras
2026-07-06 13:15     ` Jinjie Ruan
2026-07-06 13:43       ` Leonardo Bras
2026-07-07  8:39         ` Jinjie Ruan
2026-07-03 10:01 ` [PATCH 03/17] arm64: entry: arm64: entry: Move DAIF masking for EL1 exit to C code Jinjie Ruan
2026-07-03 10:01 ` [PATCH 04/17] arm64: entry: Add entry-specific helpers Jinjie Ruan
2026-07-03 10:17   ` sashiko-bot
2026-07-03 10:01 ` [PATCH 05/17] arm64: Introduce helpers for restoring standard exception masks Jinjie Ruan
2026-07-03 10:01 ` [PATCH 06/17] arm64/booting: Document boot requirements for FEAT_NMI Jinjie Ruan
2026-07-03 10:15   ` sashiko-bot
2026-07-03 10:01 ` [PATCH 07/17] arm64/sysreg: Add definitions for immediate versions of MSR ALLINT Jinjie Ruan
2026-07-03 10:18   ` sashiko-bot
2026-07-03 10:01 ` [PATCH 08/17] arm64/hyp-stub: Enable access to ALLINT Jinjie Ruan
2026-07-03 10:16   ` sashiko-bot
2026-07-03 10:01 ` [PATCH 09/17] arm64/idreg: Add an override for FEAT_NMI Jinjie Ruan
2026-07-03 10:20   ` sashiko-bot
2026-07-03 10:01 ` [PATCH 10/17] arm64/cpufeature: Detect PE support " Jinjie Ruan
2026-07-03 10:01 ` [PATCH 11/17] KVM: arm64: Hide FEAT_NMI from guests Jinjie Ruan
2026-07-03 10:13   ` sashiko-bot
2026-07-03 10:01 ` [PATCH 12/17] arm64/nmi: Manage masking for superpriority interrupts along with DAIF Jinjie Ruan
2026-07-03 10:27   ` sashiko-bot
2026-07-03 10:01 ` [PATCH 13/17] arm64/entry: Don't call preempt_schedule_irq() with NMIs masked Jinjie Ruan
2026-07-03 10:01 ` [PATCH 14/17] arm64/irq: Document handling of FEAT_NMI in irqflags.h Jinjie Ruan
2026-07-03 10:01 ` [PATCH 15/17] arm64/nmi: Add handling of superpriority interrupts as NMIs Jinjie Ruan
2026-07-03 10:19   ` sashiko-bot
2026-07-03 10:01 ` [PATCH 16/17] arm64/nmi: Add Kconfig for NMI Jinjie Ruan
2026-07-03 10:28   ` sashiko-bot
2026-07-03 10:01 ` [PATCH 17/17] irqchip/gic-v3: Implement FEAT_GICv3_NMI support Jinjie Ruan
2026-07-03 10:25   ` sashiko-bot
2026-07-03 14:15 ` [PATCH 00/17] arm64: Support FEAT_NMI and Rework Exception Masking Mark Rutland
2026-07-06  1:10   ` Jinjie Ruan

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=20260703101555.E5FB71F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=ruanjinjie@huawei.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.