[PATCH 04/20] x86/cpu: Use named asm operands in clflushopt()

Josh Poimboeuf posted 20 patches 9 months, 1 week ago
[PATCH 04/20] x86/cpu: Use named asm operands in clflushopt()
Posted by Josh Poimboeuf 9 months, 1 week ago
Use named operands in preparation for removing the operand numbering
restrictions in alternative_io().

Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 arch/x86/include/asm/special_insns.h | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h
index 21ce480658b1..b905076cf7f6 100644
--- a/arch/x86/include/asm/special_insns.h
+++ b/arch/x86/include/asm/special_insns.h
@@ -176,10 +176,9 @@ static __always_inline void clflush(volatile void *__p)
 
 static inline void clflushopt(volatile void *__p)
 {
-	alternative_io(".byte 0x3e; clflush %0",
-		       ".byte 0x66; clflush %0",
-		       X86_FEATURE_CLFLUSHOPT,
-		       "+m" (*(volatile char __force *)__p));
+	alternative_io(".byte 0x3e; clflush %[val]",
+		       ".byte 0x66; clflush %[val]", X86_FEATURE_CLFLUSHOPT,
+		       [val] "+m" (*(volatile char __force *)__p));
 }
 
 static inline void clwb(volatile void *__p)
-- 
2.48.1
Re: [PATCH 04/20] x86/cpu: Use named asm operands in clflushopt()
Posted by Linus Torvalds 9 months, 1 week ago
On Fri, 14 Mar 2025 at 11:42, Josh Poimboeuf <jpoimboe@kernel.org> wrote:
>
> +       alternative_io(".byte 0x3e; clflush %[val]",
> +                      ".byte 0x66; clflush %[val]", X86_FEATURE_CLFLUSHOPT,
> +                      [val] "+m" (*(volatile char __force *)__p));

Hmm. I think we could just use 'clflushopt', it looks like it exists
in binutils-2.25, which is our minimal version requirement.

But maybe that's a separate cleanup.

             Linus
Re: [PATCH 04/20] x86/cpu: Use named asm operands in clflushopt()
Posted by Josh Poimboeuf 9 months, 1 week ago
On Fri, Mar 14, 2025 at 01:46:00PM -1000, Linus Torvalds wrote:
> On Fri, 14 Mar 2025 at 11:42, Josh Poimboeuf <jpoimboe@kernel.org> wrote:
> >
> > +       alternative_io(".byte 0x3e; clflush %[val]",
> > +                      ".byte 0x66; clflush %[val]", X86_FEATURE_CLFLUSHOPT,
> > +                      [val] "+m" (*(volatile char __force *)__p));
> 
> Hmm. I think we could just use 'clflushopt', it looks like it exists
> in binutils-2.25, which is our minimal version requirement.
> 
> But maybe that's a separate cleanup.

You appear to be correct, I'll add a patch for that.

-- 
Josh
Re: [PATCH 04/20] x86/cpu: Use named asm operands in clflushopt()
Posted by Ingo Molnar 9 months, 1 week ago
* Josh Poimboeuf <jpoimboe@kernel.org> wrote:

> On Fri, Mar 14, 2025 at 01:46:00PM -1000, Linus Torvalds wrote:
> > On Fri, 14 Mar 2025 at 11:42, Josh Poimboeuf <jpoimboe@kernel.org> wrote:
> > >
> > > +       alternative_io(".byte 0x3e; clflush %[val]",
> > > +                      ".byte 0x66; clflush %[val]", X86_FEATURE_CLFLUSHOPT,
> > > +                      [val] "+m" (*(volatile char __force *)__p));
> > 
> > Hmm. I think we could just use 'clflushopt', it looks like it exists
> > in binutils-2.25, which is our minimal version requirement.
> > 
> > But maybe that's a separate cleanup.
> 
> You appear to be correct, I'll add a patch for that.

Please base your series on tip:master or tip:x86/asm, we already 
cleaned this up recently:

   cc2e9e09d1a3 ("x86/asm: Use CLFLUSHOPT and CLWB mnemonics in <asm/special_insns.h>")

Thanks,

	Ingo
Re: [PATCH 04/20] x86/cpu: Use named asm operands in clflushopt()
Posted by Ingo Molnar 9 months, 1 week ago
* Ingo Molnar <mingo@kernel.org> wrote:

> 
> * Josh Poimboeuf <jpoimboe@kernel.org> wrote:
> 
> > On Fri, Mar 14, 2025 at 01:46:00PM -1000, Linus Torvalds wrote:
> > > On Fri, 14 Mar 2025 at 11:42, Josh Poimboeuf <jpoimboe@kernel.org> wrote:
> > > >
> > > > +       alternative_io(".byte 0x3e; clflush %[val]",
> > > > +                      ".byte 0x66; clflush %[val]", X86_FEATURE_CLFLUSHOPT,
> > > > +                      [val] "+m" (*(volatile char __force *)__p));
> > > 
> > > Hmm. I think we could just use 'clflushopt', it looks like it exists
> > > in binutils-2.25, which is our minimal version requirement.
> > > 
> > > But maybe that's a separate cleanup.
> > 
> > You appear to be correct, I'll add a patch for that.
> 
> Please base your series on tip:master or tip:x86/asm, we already 
> cleaned this up recently:
> 
>    cc2e9e09d1a3 ("x86/asm: Use CLFLUSHOPT and CLWB mnemonics in <asm/special_insns.h>")

Also, as a general principle I'd prefer to have .byte conversion to 
mnemonics and named-operands conversions to be separate patches - not 
all named-operands conversions are an improvement, especially very 
short and simple asm() templates are just fine using numeric operands.

Thanks,

	Ingo