mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jinjie Ruan <ruanjinjie@huawei.com>
To: Ada Couprie Diaz <ada.coupriediaz@arm.com>,
	<linux-arm-kernel@lists.infradead.org>
Cc: Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Vladimir Murzin <vladimir.murzin@arm.com>,
	James Morse <james.morse@arm.com>,
	Usama Arif <usama.arif@linux.dev>, Marc Zyngier <maz@kernel.org>,
	Kiryl Shutsemau <kas@kernel.org>,
	Breno Leitao <leitao@debian.org>,
	Doug Anderson <dianders@chromium.org>,
	Linus Walleij <linusw@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Huth <thuth@redhat.com>, Dawei Li <dawei.li@linux.dev>,
	mrigendrachaubey <mrigendra.chaubey@gmail.com>,
	<kernel-team@meta.com>, <linux-kernel@vger.kernel.org>,
	<stable@vger.kernel.org>
Subject: Re: [PATCH v3 2/3] arm64: entry: sdei: save and restore PMR for pseudo-NMI
Date: Mon, 30 Nov 2026 11:35:12 +0800	[thread overview]
Message-ID: <a10363a6-a5a5-4ba6-b0f1-0ef641f83518@huawei.com> (raw)
In-Reply-To: <20261123171557.140944-3-ada.coupriediaz@arm.com>



在 2026/11/24 1:15, Ada Couprie Diaz 写道:
> When using pseudo-NMIs, the PMR affects if IRQs are disabled
> and is not updated by the CPU on exception entry/exit. It must be saved
> and restored to/from pt_regs, as the DAIF bits are, so that
> `regs_irqs_disabled()` can reliably work with pseudo-NMIs.
> 
> We do so in the regular entry path, and set it to a known value
> reflecting that DAIF is masking all interrupts.
> Do the same for SDEI, as it can interrupt the kernel at any point
> and does not mandate firmware to touch PMR, but does mandate masking DAIF.
> 
> This makes `regs_irqs_disabled()` reliable in the SDEI handler with
> pseudo-NMIs enabled, which is critical as the return path to the kernel
> depends on if the interrupted task had IRQs disabled or not.
> This also avoids returning to the interrupted task with a different PMR
> and a possible DAIF/PMR mismatch, as expected by the rest of the kernel.
> 
> Fixes: 133d05186325 ("arm64: Make PMR part of task context")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ada Couprie Diaz <ada.coupriediaz@arm.com>
> ---
>  arch/arm64/kernel/entry-common.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
> index cb122163a68d..91afd1a36ec6 100644
> --- a/arch/arm64/kernel/entry-common.c
> +++ b/arch/arm64/kernel/entry-common.c
> @@ -1067,6 +1067,16 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg)
>  	else if (cpu_has_pan())
>  		set_pstate_pan(0);
>  
> +	/*
> +	 * Regular kernel entry saves and resets the PMR to align with DAIF,
> +	 * but __sdei_asm_handler() does not ; do it now.
> +	 */
> +	if (system_uses_irq_prio_masking()) {
> +		regs->pmr = read_sysreg_s(SYS_ICC_PMR_EL1);
> +		write_sysreg_s(GIC_PRIO_IRQON | GIC_PRIO_PSR_I_SET,
> +				SYS_ICC_PMR_EL1);
> +	}

Reviewed-by: Jinjie Ruan <ruanjinjie@huawei.com>

> +
>  	/*
>  	 * Nothing saved the interrupted context's exception registers on the
>  	 * way in, and it may be in the middle of exception entry or return
> @@ -1110,6 +1120,9 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg)
>  	write_sysreg(far, far_el1);
>  	write_sysreg(vbar, vbar_el1);
>  
> +	if (system_uses_irq_prio_masking())
> +		write_sysreg_s(regs->pmr, SYS_ICC_PMR_EL1);
> +
>  	return ret;
>  }
>  #endif /* CONFIG_ARM_SDE_INTERFACE */


  parent reply	other threads:[~2026-11-30  3:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 17:15 [PATCH v3 0/3] arm64: sdei: fix entry edge cases, pseudo-NMI Ada Couprie Diaz
2026-11-23 17:15 ` [PATCH v3 1/3] arm64: entry: sdei: always set VBAR_EL1 on SDEI entry Ada Couprie Diaz
2026-11-23 17:15 ` [PATCH v3 2/3] arm64: entry: sdei: save and restore PMR for pseudo-NMI Ada Couprie Diaz
2026-11-29 23:01   ` Linus Walleij
2026-11-30  3:35   ` Jinjie Ruan [this message]
2026-11-23 17:15 ` [PATCH v3 3/3] arm64: head: set __entry_task along with task setup Ada Couprie Diaz

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=a10363a6-a5a5-4ba6-b0f1-0ef641f83518@huawei.com \
    --to=ruanjinjie@huawei.com \
    --cc=ada.coupriediaz@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=dawei.li@linux.dev \
    --cc=dianders@chromium.org \
    --cc=james.morse@arm.com \
    --cc=kas@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=leitao@debian.org \
    --cc=linusw@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=mrigendra.chaubey@gmail.com \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=thuth@redhat.com \
    --cc=usama.arif@linux.dev \
    --cc=vladimir.murzin@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

all inboxes | Powered by JetHome®