All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jinjie Ruan" <ruanjinjie@huawei.com>
Cc: "Oliver Upton" <oupton@kernel.org>,
	"Marc Zyngier" <maz@kernel.org>,
	kvmarm@lists.linux.dev
Subject: Re: [PATCH 04/17] arm64: entry: Add entry-specific helpers
Date: Fri, 03 Jul 2026 10:17:50 +0000	[thread overview]
Message-ID: <20260703101751.076651F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260703100135.2512312-5-ruanjinjie@huawei.com>

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

New issues:
- [Medium] The new exception mask abstraction introduces unnecessary system register reads on exception entry that are immediately discarded, causing overhead on hot paths.
- [Medium] exception_exit_restore_mask() fails to restore PMR and ALLINT, directly contradicting its explicit description in the commit message.

Pre-existing issues:
- [High] Missing pmr_sync() barrier on the PMR unmasking path in local_exception_inherit().
--

commit 2feb968bf7f065e9063df058fc7166adcf349514
Author: Jinjie Ruan <ruanjinjie@huawei.com>
Date:   Fri Jul 3 10:01:22 2026 +0000

arm64: entry: Add entry-specific helpers

The existing hacks to bodge pseudo-NMI into the DAIF management code
are convoluted and difficult to maintain. To pave the way for real
hardware NMI support (FEAT_NMI) without compounding the existing
complexity, we need to abstract the low-level exception masking
and unmasking operations into entry-specific helpers.

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
> index 0a21fb97c3ca8..2c87f7c90f628 100644
> --- a/arch/arm64/include/asm/exception_masks.h
> +++ b/arch/arm64/include/asm/exception_masks.h

[ ... ]

> +static __always_inline struct exception_mask el1_sync_entry_unmask_inherit(struct pt_regs *regs)
> +{
> +	struct exception_mask orig;
> +
> +	local_exception_save_mask(&orig);
> +	local_exception_inherit(regs);

[Severity: High]
This is a pre-existing issue, but does local_exception_inherit() miss a
required pmr_sync() barrier?

When el1_sync_entry_unmask_inherit() calls local_exception_inherit(), it
writes regs->pmr to ICC_PMR_EL1 to unmask interrupts:

	if (system_uses_irq_prio_masking())
		gic_write_pmr(regs->pmr);

Unmasking interrupts via PMR typically requires a pmr_sync() barrier (DSB) so
the priority change is immediately visible to the GIC redistributor. Without
this barrier, the redistributor might delay interrupt delivery.

> +
> +	return orig;
> +}

[ ... ]

> +/*
> + * Mask all exceptions, ready to return to interrupted context
> + */
> +static __always_inline void exception_exit_restore_mask(struct exception_mask mask)
> +{
> +	write_sysreg(mask.daif, daif);
> +}

[Severity: Medium]
Does this function fully match its description in the commit message?

The commit message states that exception_exit_restore_mask() restores both
the DAIF and PMR states:

"- exception_exit_restore_mask(): A unified exit-side helper to safely
   restore the hardware exception mask states (DAIF and PMR)..."
   
However, the implementation only restores DAIF and drops the PMR and ALLINT
states. While kernel_exit and eret might handle those separately in practice,
the documented API contract seems inconsistent with the implementation.

> diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
> index 6fdf74ff48352..dc223085e7735 100644
> --- a/arch/arm64/kernel/entry-common.c
> +++ b/arch/arm64/kernel/entry-common.c

[ ... ]

> @@ -824,7 +849,7 @@ static void noinstr el0_interrupt(struct pt_regs *regs,
>  {
>  	arm64_enter_from_user_mode(regs);
>  
> -	write_sysreg(DAIF_PROCCTX_NOIRQ, daif);
> +	irq_entry_unmask_debug_serror(regs);

[Severity: Medium]
Does discarding the return value of irq_entry_unmask_debug_serror()
introduce unnecessary overhead on the hot EL0 interrupt path?

irq_entry_unmask_debug_serror() calls local_exception_save_mask(), which
executes multiple volatile 'mrs' instructions to read DAIF, PMR, and ALLINT.
Since these reads are performed via asm volatile, the compiler cannot optimize
them out even though the returned exception_mask is ignored here.

>  
>  	if (regs->pc & BIT(55))
>  		arm64_apply_bp_hardening();

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

  reply	other threads:[~2026-07-03 10:17 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
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 [this message]
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=20260703101751.076651F000E9@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.