[PATCH v2 09/39] arm64: replace local_daif helpers

Vladimir Murzin vladimir.murzin at arm.com
Wed Nov 25 06:46:51 PST 2026


On 11/12/26 13:20, Vladimir Murzin wrote:
...
> diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c
> index 681aa2bbc399..b488e04249d0 100644
> --- a/arch/arm64/kernel/acpi.c
> +++ b/arch/arm64/kernel/acpi.c
> @@ -33,7 +33,7 @@
>  #include <acpi/processor.h>
>  #include <asm/cputype.h>
>  #include <asm/cpu_ops.h>
> -#include <asm/daifflags.h>
> +#include <asm/interrupts/masking.h>
>  #include <asm/smp_plat.h>
>  
>  int acpi_noirq = 1;		/* skip ACPI IRQ initialization */
> @@ -388,48 +388,43 @@ void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size)
>   */
>  int apei_claim_sea(struct pt_regs *regs)
>  {
> +	arm64_exc_hwstates_t hwstate;
> +	bool irqs_disabled;
>  	int err = -ENOENT;
> -	bool return_to_irqs_enabled;
> -	unsigned long current_flags;
>  
>  	if (!IS_ENABLED(CONFIG_ACPI_APEI_GHES))
>  		return err;
>  
> -	current_flags = local_daif_save_flags();
> -
> -	/* current_flags isn't useful here as daif doesn't tell us about pNMI */
> -	return_to_irqs_enabled = !irqs_disabled_flags(arch_local_save_flags());
> -
> -	if (regs)
> -		return_to_irqs_enabled = !regs_irqs_disabled(regs);
> -
>  	/*
>  	 * SEA can interrupt SError, mask it and describe this as an NMI so
>  	 * that APEI defers the handling.
>  	 */
> -	local_daif_restore(DAIF_ERRCTX);
> +	hwstate = local_exceptions_save_mask(ERROR_CONTEXT);
>  	nmi_enter();
>  	err = ghes_notify_sea();
>  	nmi_exit();
> +	local_exceptions_restore(hwstate);
> +
> +	if (err)
> +		return err;
>  
>  	/*
>  	 * APEI NMI-like notifications are deferred to irq_work. Unless
>  	 * we interrupted irqs-masked code, we can do that now.
>  	 */
> -	if (!err) {
> -		if (return_to_irqs_enabled) {
> -			local_daif_restore(DAIF_PROCCTX_NOIRQ);
> -			__irq_enter();
> -			irq_work_run();
> -			__irq_exit();
> -		} else {
> -			pr_warn_ratelimited("APEI work queued but not completed\n");
> -			err = -EINPROGRESS;
> -		}
> +	irqs_disabled = regs ? regs_irqs_disabled(regs) : arch_irqs_disabled_flags(hwstate.saved.flags);
> +
> +	if (!irqs_disabled) {
> +		hwstate = local_exceptions_save_mask(NOIRQ_CONTEXT);
> +		__irq_enter();
> +		irq_work_run();
> +		__irq_exit();
> +		local_exceptions_restore(hwstate);
> +	} else {
> +		pr_warn_ratelimited("APEI work queued but not completed\n");
> +		err = -EINPROGRESS;
>  	}
>  
> -	local_daif_restore(current_flags);
> -
>  	return err;
>  }
>  

Shashiko told me what it wrong with this approach and I'm planing to have a look...

...
> diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
> index a707deba6ae7..49914965b790 100644
> --- a/arch/arm64/kernel/setup.c
> +++ b/arch/arm64/kernel/setup.c
> @@ -38,7 +38,7 @@
>  #include <asm/fixmap.h>
>  #include <asm/cpu.h>
>  #include <asm/cputype.h>
> -#include <asm/daifflags.h>
> +#include <asm/interrupts/masking.h>
>  #include <asm/elf.h>
>  #include <asm/cpufeature.h>
>  #include <asm/cpu_ops.h>
> @@ -311,7 +311,7 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p)
>  	 * IRQ and FIQ will be unmasked after the root irqchip has been
>  	 * detected and initialized.
>  	 */
> -	local_daif_restore(DAIF_PROCCTX_NOIRQ);
> +	local_exceptions_cpu_init_mask(NOIRQ_CONTEXT);

Although end result we get is what we want it is not quite
right. First of all NOIRQ_CONTEXT is wrong here since what we really
want here is NONMI_CONTEXT. Secondly, the reason we still get what we
want is not obvious and applies to local_daif_restore() as well - this
code runs before CPU feature discovery, so both helpers cannot do
anything other than updating DAIF.

Interestingly that for boot CPU we build exception state step by step:

 - we start with DAIF (and ALLINT) masked
 
 - unmask DA in setup_arch() so we get daIF (ALLINT still masked)

 - later in smp_prepare_boot_cpu() once boot CPU features are
   discovered we update PMR

 - finally we re-sync the state, allowing pseudo-NMI (and I think it is
   where we should unmask ALLINT), in initIRQ()

Note that for secondary CPUs we are taking different path:

 - we start with DAIF (and ALLINT) masked

 - secondary_start_kernel() updates PMR

 - we unmask DAIF (and I think it is where we should unmask ALLINT) in
   secondary_start_kernel().

So, I'm inclining adding extra changes to make it clear:

- switch to direct DAIF write (plus updating the comment explaining
  gradual build of exception state) in setup_arch()

- once arm64_debug_exc_context() is available add exception state
  checks in init_IRQ() (we expect to arrive there in NONMI_CONTEXT)
  and secondary_start_kernel() (we expect CRITICAL_CONTEXT before we
  transition to PROCESS_CONTEXT)

- that also implies that we cannot unmask ALLINT in CPU feature enable
  callback, so that callback would be removed and ALLINT would be
  unmasked in dedicated flows for boot CPU and secondary CPUs.

Cheers
Vladimir



More information about the linux-arm-kernel mailing list