[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANn89i+3F6O30Tg5kh-+O2nFa3xJMsverm1bTh-K1G0vk=-gig@mail.gmail.com>
Date: Thu, 18 Dec 2025 11:58:25 +0100
From: Eric Dumazet <edumazet@...gle.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: "H. Peter Anvin" <hpa@...or.com>, Thomas Gleixner <tglx@...utronix.de>, Ingo Molnar <mingo@...hat.com>,
Borislav Petkov <bp@...en8.de>, Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
linux-kernel <linux-kernel@...r.kernel.org>, Eric Dumazet <eric.dumazet@...il.com>
Subject: Re: [PATCH] x86/irqflags: Force a register output in native_save_fl()
On Thu, Dec 18, 2025 at 11:22 AM Peter Zijlstra <peterz@...radead.org> 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)
Powered by blists - more mailing lists