From: Vladimir Murzin <vladimir.murzin@arm.com>
To: Jinjie Ruan <ruanjinjie@huawei.com>,
"Liao, Chang" <liaochang1@huawei.com>,
linux-arm-kernel@lists.infradead.org
Cc: mark.rutland@arm.com, maz@kernel.org, catalin.marinas@arm.com,
will@kernel.org
Subject: Re: [RFC PATCH 14/36] arm64: interrupts: introduce generic interrupt masking helpers
Date: Thu, 23 Jul 2026 10:36:21 +0100 [thread overview]
Message-ID: <1dd99bf0-c4b0-44ce-86ad-4ad1d0de75a7@arm.com> (raw)
In-Reply-To: <e0f77ad6-fce6-435f-9dd3-e10378cb29b9@huawei.com>
On 7/22/26 10:05, Jinjie Ruan wrote:
>
> On 7/16/2026 5:37 PM, Vladimir Murzin wrote:
>> On 7/15/26 10:30, Liao, Chang wrote:
>>> 在 2026/7/9 20:13, Vladimir Murzin 写道:
>>>> From: Ada Couprie Diaz <ada.coupriediaz@arm.com>
>>>>
>>>> As for the entry code, we want to replace `local_daif_...` helpers
>>>> so that they can properly handle both DAIF and PMR, as well controlling
>>>> their use more strongly.
>>>>
>>>> Introduce new `local_all_irqs_...` helpers to replace them, which should
>>>> only be called in save/restore pairs.
>>>>
>>>> Save the requested interrupt state as well, so we can check for
>>>> inconsistent interrupt masking in between save and restore.
>>>>
>>>> There are two exceptions where it does not make sense to force
>>>> save/restore pairs for modifying the interrupt masks:
>>>> - when initializing a CPU or
>>>> - preparing to turn it off.
>>>>
>>>> As we otherwise want to force save/restore pairs, those cases are
>>>> handled with specific helpers, making clear that they should not be
>>>> used outside of those cases, enforced with `CONFIG_DEBUG_IRQFLAGS`
>>>> enabled.
>>>>
>>>> Signed-off-by: Ada Couprie Diaz <ada.coupriediaz@arm.com>
>>>> Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
>>>> ---
>>>> arch/arm64/include/asm/interrupts/masking.h | 101 ++++++++++++++++++++
>>>> 1 file changed, 101 insertions(+)
>>>> create mode 100644 arch/arm64/include/asm/interrupts/masking.h
>>>>
>>>> diff --git a/arch/arm64/include/asm/interrupts/masking.h b/arch/arm64/include/asm/interrupts/masking.h
>>>> new file mode 100644
>>>> index 000000000000..66ee03f7ab68
>>>> --- /dev/null
>>>> +++ b/arch/arm64/include/asm/interrupts/masking.h
>>>> @@ -0,0 +1,101 @@
>>>> +/* SPDX-License-Identifier: GPL-2.0-only */
>>>> +/*
>>>> + * Copyright (C) 2025 Arm Ltd.
>>>> + */
>>>> +#ifndef __ASM_INTERRUPTS_MASKING_H
>>>> +#define __ASM_INTERRUPTS_MASKING_H
>>>> +
>>>> +#include <asm/arch_gicv3.h>
>>>> +#include <asm/bug.h>
>>>> +#include <asm/cpufeature.h>
>>>> +#include <asm/interrupts/common_flags.h>
>>>> +#include <asm/ptrace.h>
>>>> +
>>>> +typedef struct arm64_exc_hwstates {
>>>> + arm64_exc_hwstate_t saved;
>>>> + arm64_exc_hwstate_t expected;
>>>> +} arm64_exc_hwstates_t;
>>>> +
>>>> +#ifdef CONFIG_DEBUG_IRQFLAGS
>>>> +/* Make sure the CPU init/tear down masking functions are only used once. */
>>>> +static DEFINE_PER_CPU(bool, irqs_masks_cpu_init_done);
>>>> +static DEFINE_PER_CPU(bool, irqs_masks_cpu_final_done);
>>>> +#endif
>>>> +
>>>> +static inline
>>>> +arm64_exc_hwstates_t local_all_irqs_save_mask(arm64_exc_context_t new)
>>>> +{
>>>> + arm64_exc_hwstate_t state = arm64_exc_hwstate_of_context(new);
>>>> + arm64_exc_hwstate_t actual = {.flags = arch_local_save_flags()};
>>>> +
>>>> + if (IS_ENABLED(CONFIG_DEBUG_IRQFLAGS)) {
>>>> + bool pnmi = system_uses_irq_prio_masking();
>>>> +
>>>> + WARN_ON_ONCE(new < CRITICAL_CONTEXT &&
>>>> + actual.daif == DAIF_MASK);
>>>> +
>>>> + WARN_ON_ONCE(new < ERROR_CONTEXT &&
>>>> + actual.daif == DAIF_ERRCTX);
>>>> +
>>>> + WARN_ON_ONCE(new < NONMI_CONTEXT &&
>>>> + pnmi && actual.daif == DAIF_PROCCTX_NOIRQ);
>>>> +
>>>> + WARN_ON_ONCE(new < NOIRQ_CONTEXT &&
>>>> + ((pnmi && actual.pmr == GIC_PRIO_IRQOFF) ||
>>>> + (!pnmi && actual.daif == DAIF_PROCCTX_NOIRQ)));
>>>> + }
>>>> +
>>>> + arm64_update_exc_hwstate(state, actual.pmr != state.pmr);
>>> Is it necessary to compare pmr field unconditionally here, does this function's
>>> usage imply a strict dependency on pseudo NMI?If this function moves forward to
>>> support FEAT_NMI, checking PMR seems unneccesary.
> I also think that this function seems to forcibly require the
> implementation of pseudo NMI and FEAT_NMI.
>
I already revisited that, and I'll propose a reworked interface that
should (I hope) make it less confusing (see my reply to Chang a few
lines below for the idea).
> Can the arm64_update_exc_hwstate() and similar functions pass the target
> exception mask and current exception mask, and the function internally
> performs the check of "update_pmr" or "update_allint"?
>
That would require us to always have the current exception mask
available. There are cases (such as exception entry, or here when we
save the state) where we have it almost for free. However, we may also
encounter cases where we either do not have it or cannot trust it, in
which case we would need an extra hardware state read just to satisfy
the interface.
Obviously this is not set in stone, and we may revisit it later. For
now, though, I'd prefer to keep the interface layered on top of the
basic hardware state operations.
Cheers
Vladimir
>> Yes, it is not necessary, but it is cheap. :) However, I think I need
>> to revisit this approach. More on that below...
>>
>>>> +
>>>> + if (!arch_irqs_disabled_flags(actual.flags))
>>>> + trace_hardirqs_off();
>>>> +
>>>> + return (arm64_exc_hwstates_t){.saved = actual, .expected = state};
>>>> +}
>>>> +
>>>> +static inline void local_all_irqs_restore(arm64_exc_hwstates_t states)
>>>> +{
>>>> + arm64_debug_exc_hwstate(states.expected);
>>>> +
>>>> + if (!arch_irqs_disabled_flags(states.saved.flags))
>>>> + trace_hardirqs_on();
>>>> +
>>>> + arm64_update_exc_hwstate(states.saved, true);
>>> I'm curious why it forces update_pmr to true for this specific path?
>>>
>> We force an update because we cannot fully trust that the HW state
>> matches the expected state. The expected state exists for debug
>> purposes only.
>>
>> In the local_all_irqs_save_mask() case above, we have just read the HW
>> state, so we can use that information to avoid some unnecessary HW
>> updates.
>>
>> I think it would be better to provide two versions of
>> arm64_update_exc_hwstate(): a strong version and a relaxed version,
>> with the strong version being the default. That would let us limit the
>> relaxed version to places where we know it is safe to skip redundant
>> HW updates.
>>
>>
>>>> +}
>>>> +
>>>> +#ifdef CONFIG_DEBUG_IRQFLAGS
>>>> +static inline
>>>> +void local_all_irqs_cpu_init_mask(arm64_exc_context_t context)
>>>> +{
>>>> + WARN_ON(__this_cpu_read(irqs_masks_cpu_init_done));
>>>> + if (context == PROCESS_CONTEXT)
>>>> + trace_hardirqs_on();
>>>> + arm64_update_exc_context(context, true);
>>>> + __this_cpu_write(irqs_masks_cpu_init_done, true);
>>>> + __this_cpu_write(irqs_masks_cpu_final_done, false);
>>>> +}
>>>> +
>>>> +static inline void local_all_irqs_final_mask(void)
>>>> +{
>>>> + WARN_ON(__this_cpu_read(irqs_masks_cpu_final_done));
>>>> + arm64_update_exc_context(CRITICAL_CONTEXT, true);
>>>> + trace_hardirqs_off();
>>>> + __this_cpu_write(irqs_masks_cpu_final_done, true);
>>>> + __this_cpu_write(irqs_masks_cpu_init_done, false);
>>>> +}
>>>> +#else /* CONFIG_DEBUG_IRQFLAGS */
>>>> +static inline
>>>> +void local_all_irqs_cpu_init_mask(arm64_exc_context_t context)
>>>> +{
>>>> + if (context == PROCESS_CONTEXT)
>>>> + trace_hardirqs_on();
>>>> + arm64_update_exc_context(context, true);
>>>> +}
>>>> +
>>>> +static inline void local_all_irqs_final_mask(void)
>>>> +{
>>>> + arm64_update_exc_context(CRITICAL_CONTEXT, true);
>>>> + trace_hardirqs_off();
>>>> +}
>>>> +#endif /* CONFIG_DEBUG_IRQFLAGS */
>>>> +#endif /* __ASM_INTERRUPTS_MASKING_H */
>>> -- BR Liao, Chang
>>>
>> Cheers
>> Vladimir
>>
next prev parent reply other threads:[~2026-07-23 9:36 UTC|newest]
Thread overview: 152+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 12:12 [RFC PATCH 00/36] arm64: Add support for FEAT_NMI Vladimir Murzin
2026-07-09 12:12 ` [RFC PATCH 01/36] arm64: ptrace: Remove INIT_PSTATE_EL2 Vladimir Murzin
2026-07-09 12:36 ` Jinjie Ruan
2026-07-09 12:12 ` [RFC PATCH 02/36] arm64: debug: don't mask DAIF for mdscr_write() Vladimir Murzin
2026-07-09 13:06 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 03/36] arm64: hibernate: mask DAIF before restoring hibernated kernel Vladimir Murzin
2026-07-09 13:19 ` Jinjie Ruan
2026-07-10 3:00 ` Jinjie Ruan
2026-07-14 9:35 ` Vladimir Murzin
2026-07-10 3:28 ` Jinjie Ruan
2026-07-14 9:37 ` Vladimir Murzin
2026-07-14 12:35 ` Jinjie Ruan
2026-07-10 3:40 ` Liao, Chang
2026-07-14 9:42 ` Vladimir Murzin
2026-07-09 12:13 ` [RFC PATCH 04/36] arm64: suspend: rely on daif helpers to handle PMR Vladimir Murzin
2026-07-10 3:41 ` Jinjie Ruan
2026-07-10 4:06 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 05/36] arm64: suspend: Initialize PMR on resume Vladimir Murzin
2026-07-09 12:13 ` [RFC PATCH 06/36] arm64: irq: introduce a helper for GIC priority initialization Vladimir Murzin
2026-07-10 4:16 ` Jinjie Ruan
2026-07-14 9:46 ` Vladimir Murzin
2026-07-10 7:29 ` Jinjie Ruan
2026-07-14 9:56 ` Vladimir Murzin
2026-07-10 7:44 ` Jinjie Ruan
2026-07-14 10:02 ` Vladimir Murzin
2026-07-14 11:05 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 07/36] arm64: entry: mask DAIF before returning from C EL1 handlers Vladimir Murzin
2026-07-10 7:57 ` Jinjie Ruan
2026-07-14 10:13 ` Vladimir Murzin
2026-07-09 12:13 ` [RFC PATCH 08/36] irqchip/gic-v3: make the unmasking of pseudo-NMIs explicit when handling IRQs Vladimir Murzin
2026-07-10 8:04 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 09/36] arm64: irqflags: introduce arm64-specific irqflags type Vladimir Murzin
2026-07-10 8:40 ` Jinjie Ruan
2026-07-14 11:50 ` Vladimir Murzin
2026-07-09 12:13 ` [RFC PATCH 10/36] arm64: irqflags: save and use both DAIF and PMR Vladimir Murzin
2026-07-10 3:53 ` Liao, Chang
2026-07-10 8:11 ` Jinjie Ruan
2026-07-14 9:44 ` Vladimir Murzin
2026-07-14 11:30 ` Liao, Chang
2026-07-10 8:47 ` Jinjie Ruan
2026-07-17 10:30 ` Vladimir Murzin
2026-07-10 9:02 ` Jinjie Ruan
2026-07-17 10:28 ` Vladimir Murzin
2026-07-09 12:13 ` [RFC PATCH 11/36] arm64: interrupts: introduce interrupt masking helpers for entry code Vladimir Murzin
2026-07-10 9:19 ` Jinjie Ruan
2026-07-14 11:54 ` Vladimir Murzin
2026-07-10 9:39 ` Liao, Chang
2026-07-15 10:34 ` Vladimir Murzin
2026-07-10 9:39 ` Jinjie Ruan
2026-07-15 10:39 ` Vladimir Murzin
2026-07-10 9:44 ` Jinjie Ruan
2026-07-15 10:43 ` Vladimir Murzin
2026-07-14 7:33 ` Liao, Chang
2026-07-14 15:45 ` Vladimir Murzin
2026-07-15 6:42 ` Liao, Chang
2026-07-09 12:13 ` [RFC PATCH 12/36] arm64: entry: replace DAIF helpers with entry helpers Vladimir Murzin
2026-07-10 9:36 ` Jinjie Ruan
2026-07-15 12:31 ` Vladimir Murzin
2026-07-22 9:39 ` Jinjie Ruan
2026-07-10 10:01 ` Jinjie Ruan
2026-07-14 12:00 ` Vladimir Murzin
2026-07-14 12:14 ` Liao, Chang
2026-07-09 12:13 ` [RFC PATCH 13/36] arm64: process: Use helper to check exception state Vladimir Murzin
2026-07-10 10:00 ` Jinjie Ruan
2026-07-14 12:46 ` Liao, Chang
2026-07-09 12:13 ` [RFC PATCH 14/36] arm64: interrupts: introduce generic interrupt masking helpers Vladimir Murzin
2026-07-13 8:43 ` Jinjie Ruan
2026-07-14 12:52 ` Vladimir Murzin
2026-07-14 12:45 ` Jinjie Ruan
2026-07-15 12:47 ` Vladimir Murzin
2026-07-14 13:13 ` Liao, Chang
2026-07-15 12:56 ` Vladimir Murzin
2026-07-15 9:30 ` Liao, Chang
2026-07-16 9:37 ` Vladimir Murzin
2026-07-22 9:05 ` Jinjie Ruan
2026-07-23 9:36 ` Vladimir Murzin [this message]
2026-07-09 12:13 ` [RFC PATCH 15/36] arm64: replace local_daif helpers Vladimir Murzin
2026-07-15 9:26 ` Liao, Chang
2026-07-22 8:41 ` Jinjie Ruan
2026-07-23 9:40 ` Vladimir Murzin
2026-07-09 12:13 ` [RFC PATCH 16/36] arm64: cpuidle: use new helpers to bypass interrupt priority masking Vladimir Murzin
2026-07-13 8:28 ` Jinjie Ruan
2026-07-14 12:51 ` Vladimir Murzin
2026-07-22 8:39 ` Jinjie Ruan
2026-07-22 8:38 ` Jinjie Ruan
2026-07-23 9:57 ` Vladimir Murzin
2026-07-09 12:13 ` [RFC PATCH 17/36] arm64: remove daifflags.h Vladimir Murzin
2026-07-22 8:00 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 18/36] arm64: gicv3: remove GIC_PRIO_PSR_I_SET Vladimir Murzin
2026-07-22 8:20 ` Jinjie Ruan
2026-07-22 14:10 ` Vladimir Murzin
2026-07-09 12:13 ` [RFC PATCH 19/36] arm64: cpufeature: Remove system_has_prio_mask_debugging() Vladimir Murzin
2026-07-22 8:24 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 20/36] arm64: irqflags: Switch to CONFIG_DEBUG_IRQFLAGS Vladimir Murzin
2026-07-22 8:23 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 21/36] arm64: Kconfig: Remove CONFIG_ARM64_DEBUG_PRIORITY_MASKING Vladimir Murzin
2026-07-22 8:22 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 22/36] efi/runtime-wrappers: Permit architectures to override IRQ flags checks Vladimir Murzin
2026-07-13 8:27 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 23/36] arm64/efi: Implement override for " Vladimir Murzin
2026-07-13 8:22 ` Jinjie Ruan
2026-07-15 12:00 ` Vladimir Murzin
2026-07-15 12:09 ` Jinjie Ruan
2026-07-15 12:21 ` Vladimir Murzin
2026-07-22 7:52 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 24/36] arm64: booting: Document boot requirements for FEAT_NMI Vladimir Murzin
2026-07-10 2:39 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 25/36] arm64: sysreg: Add definitions for immediate versions of MSR ALLINT Vladimir Murzin
2026-07-14 11:01 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 26/36] arm64: ptrace: Add PSR_ALLINT_BIT Vladimir Murzin
2026-07-10 2:16 ` Jinjie Ruan
2026-07-14 9:30 ` Vladimir Murzin
2026-07-09 12:13 ` [RFC PATCH 27/36] arm64: idreg: Add an override for FEAT_NMI Vladimir Murzin
2026-07-10 2:17 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 28/36] arm64: cpufeature: Detect PE support " Vladimir Murzin
2026-07-10 2:25 ` Jinjie Ruan
2026-07-14 9:33 ` Vladimir Murzin
2026-07-09 12:13 ` [RFC PATCH 29/36] arm64: nmi: Manage masking for superpriority interrupts Vladimir Murzin
2026-07-10 10:04 ` Jinjie Ruan
2026-07-10 10:08 ` Jinjie Ruan
2026-07-14 12:41 ` Vladimir Murzin
2026-07-21 9:58 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 30/36] arm64: irq: Report FEAT_NMI masking local IRQs Vladimir Murzin
2026-07-21 9:06 ` Jinjie Ruan
2026-07-22 13:55 ` Vladimir Murzin
2026-07-23 3:14 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 31/36] arm64: nmi: Add handling of superpriority interrupts as NMIs Vladimir Murzin
2026-07-10 10:13 ` Jinjie Ruan
2026-07-14 16:24 ` Vladimir Murzin
2026-07-15 12:07 ` Jinjie Ruan
2026-07-15 14:08 ` Vladimir Murzin
2026-07-16 9:26 ` Jinjie Ruan
2026-07-21 2:33 ` Jinjie Ruan
2026-07-21 8:33 ` Jinjie Ruan
2026-07-23 10:29 ` Vladimir Murzin
2026-07-09 12:13 ` [RFC PATCH 32/36] arm64: suspend: Always initialise PSTATE.ALLINT Vladimir Murzin
2026-07-13 8:00 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 33/36] arm64/efi: Add ALLINT to IRQ flags checks Vladimir Murzin
2026-07-13 8:03 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 34/36] arm64: kprobes: Disable NMIs Vladimir Murzin
2026-07-13 8:12 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 35/36] arm64: nmi: Add Kconfig for NMI Vladimir Murzin
2026-07-10 2:41 ` Jinjie Ruan
2026-07-14 8:52 ` Jinjie Ruan
2026-07-09 12:13 ` [RFC PATCH 36/36] irqchip/gic-v3: Implement FEAT_GICv3_NMI support Vladimir Murzin
2026-07-21 2:25 ` Jinjie Ruan
2026-07-22 13:39 ` Vladimir Murzin
2026-07-14 8:37 ` [RFC PATCH 00/36] arm64: Add support for FEAT_NMI Jinjie Ruan
[not found] ` <bb6e80db-dd5e-405f-9aa9-2a59fae3a1dc@huawei.com>
2026-07-14 10:32 ` Vladimir Murzin
2026-07-14 15:18 ` Vladimir Murzin
2026-07-23 3:53 ` Jinjie Ruan
2026-07-23 12:25 ` Vladimir Murzin
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=1dd99bf0-c4b0-44ce-86ad-4ad1d0de75a7@arm.com \
--to=vladimir.murzin@arm.com \
--cc=catalin.marinas@arm.com \
--cc=liaochang1@huawei.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=ruanjinjie@huawei.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