[RFC PATCH 02/36] arm64: debug: don't mask DAIF for mdscr_write()

Jinjie Ruan ruanjinjie at huawei.com
Thu Jul 9 06:06:53 PDT 2026



On 7/9/2026 8:12 PM, Vladimir Murzin wrote:
> From: Ada Couprie Diaz <ada.coupriediaz at arm.com>
> 
> Masking DAIF around the write to MDSCR_EL1 doesn't do anything: we can
> write to sysregs with interrupts unmasked, and writing to PSTATE is
> not a context synchronization event so it does not synchronize it.
> 
> This is done in the context of a general interrupt handling cleanup,
> so it does not address the missing context synchronization for the
> MDSCR_EL1 write, staying consistent with the current state.  This
> should be addressed in a future patch.
> 
> Signed-off-by: Ada Couprie Diaz <ada.coupriediaz at arm.com>
> Signed-off-by: Vladimir Murzin <vladimir.murzin at arm.com>
> ---
>  arch/arm64/kernel/debug-monitors.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
> index 29307642f4c9..e271fbac5f82 100644
> --- a/arch/arm64/kernel/debug-monitors.c
> +++ b/arch/arm64/kernel/debug-monitors.c
> @@ -40,10 +40,7 @@ u8 debug_monitors_arch(void)
>   */
>  static void mdscr_write(u64 mdscr)
>  {
> -	unsigned long flags;
> -	flags = local_daif_save();
>  	write_sysreg(mdscr, mdscr_el1);
> -	local_daif_restore(flags);

commit 478fcb2cdb23 ("arm64: Debugging support") used the
local_dbg_save() to set the DAIF.D bit.

In my opinion, this was originally intended to avoid the debug exception
being triggered immediately when the single-step mode is enabled during
the write of MDSCR_EL1.SS?


+ * MDSCR access routines.
+ */
+static void mdscr_write(u32 mdscr)
+{
+       unsigned long flags;
+       local_dbg_save(flags);
+       asm volatile("msr mdscr_el1, %0" :: "r" (mdscr));
+       local_dbg_restore(flags);
+}


+#define local_dbg_save(flags)
       \
+       do {
       \
+               typecheck(unsigned long, flags);
       \
+               asm volatile(
       \
+               "mrs    %0, daif                        //
local_dbg_save\n"    \
+               "msr    daifset, #8"
       \
+               : "=r" (flags) : : "memory");
       \
+       } while (0)


>  }
>  NOKPROBE_SYMBOL(mdscr_write);
>  




More information about the linux-arm-kernel mailing list