Re: [PATCH] x86/irqflags: Force a register output in native_save_fl()
From: Eric Dumazet
Date: Thu Dec 18 2025 - 05:58:53 EST
On Thu, Dec 18, 2025 at 11:22 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Thu, Dec 18, 2025 at 11:15:37AM +0100, Eric Dumazet wrote:
>
> > > >--- a/arch/x86/include/asm/irqflags.h
> > > >+++ b/arch/x86/include/asm/irqflags.h
> > > >@@ -18,14 +18,9 @@ extern __always_inline unsigned long native_save_fl(void)
> > > > {
> > > > unsigned long flags;
> > > >
> > > >- /*
> > > >- * "=rm" is safe here, because "pop" adjusts the stack before
> > > >- * it evaluates its effective address -- this is part of the
> > > >- * documented behavior of the "pop" instruction.
> > > >- */
> > > > asm volatile("# __raw_save_flags\n\t"
> > > > "pushf ; pop %0"
> > > >- : "=rm" (flags)
> > > >+ : "=r" (flags)
> > > > : /* no input */
> > > > : "memory");
> > > >
> > >
> > > Maybe report a bug to the clang team?
> >
> > This has been done 8 years ago. No progress so far...
> >
> > They claim we should use __builtin_ia32_readeflags_u64 /
> > __builtin_ia32_writeeflags_u64, which seems unlikely to please x86
> > maintainers ?
>
> Yeah, because the "rm" thing not being supported properly goes way
> further than just this one case. And it really is abysmal that clang
> hasn't managed to implement it in all that time :/
Let me know if you prefer a V2 with this instead. It saves ~190 bytes
more with clang ;)
Thanks !
diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
index b30e5474c18e1be63b7c69354c26ae6a6cb02731..0209ae149f2b5f9ddacc6c8066a6d3191696ec42
100644
--- a/arch/x86/include/asm/irqflags.h
+++ b/arch/x86/include/asm/irqflags.h
@@ -16,20 +16,11 @@
extern inline unsigned long native_save_fl(void);
extern __always_inline unsigned long native_save_fl(void)
{
- unsigned long flags;
-
- /*
- * "=rm" is safe here, because "pop" adjusts the stack before
- * it evaluates its effective address -- this is part of the
- * documented behavior of the "pop" instruction.
- */
- asm volatile("# __raw_save_flags\n\t"
- "pushf ; pop %0"
- : "=rm" (flags)
- : /* no input */
- : "memory");
-
- return flags;
+#ifdef CONFIG_X86_64
+ return __builtin_ia32_readeflags_u64();
+#else
+ return __builtin_ia32_readeflags_u32();
+#endif
}
static __always_inline void native_irq_disable(void)