Re: [PATCH] x86/asm: Switch clflush alternatives to use %a address operand modifier

From: David Laight

Date: Wed Mar 18 2026 - 11:29:53 EST


On Wed, 18 Mar 2026 10:08:11 +0100
Uros Bizjak <ubizjak@xxxxxxxxx> wrote:

> The inline asm used with alternative_input() specifies the address
> operand for clflush with the "a" input operand constraint and
> explicit "(%[addr])" dereference:
>
> "clflush (%[addr])", [addr] "a" (addr)
>
> This forces the pointer into %rax and manually encodes the memory
> operand in the template. Instead, use the %a address operand
> modifier and relax the constraint from "a" to "r":
>
> "clflush %a[addr]", [addr] "r" (addr)
>
> This lets the compiler choose the register while generating the
> correct addressing mode.

Aren't these two independent changes?
%a saves you having to know how to write the memory reference for the
architecture - so is the same as (%[addr]) (assuming att syntax).
I think the assembler handles the one 'odd' case of (%rbp).

Was there ever a reason for using "a" rather than "r" - it seems an
unusual choice.
I also think there should be a "memory" clobber - but it probably
makes no difference for these two cases.

David

>
> No functional change intended.
>
> Signed-off-by: Uros Bizjak <ubizjak@xxxxxxxxx>
> Acked-by: "Peter Zijlstra (Intel)" <peterz@xxxxxxxxxxxxx>
> Cc: Thomas Gleixner <tglx@xxxxxxxxxx>
> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> Cc: Borislav Petkov <bp@xxxxxxxxx>
> Cc: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
> Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
> ---
> arch/x86/include/asm/mwait.h | 3 ++-
> arch/x86/kernel/process.c | 3 ++-
> 2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
> index e4815e15dc9a..fcb7299b293a 100644
> --- a/arch/x86/include/asm/mwait.h
> +++ b/arch/x86/include/asm/mwait.h
> @@ -116,7 +116,8 @@ static __always_inline void mwait_idle_with_hints(u32 eax, u32 ecx)
> if (static_cpu_has_bug(X86_BUG_MONITOR) || !current_set_polling_and_test()) {
> const void *addr = &current_thread_info()->flags;
>
> - alternative_input("", "clflush (%[addr])", X86_BUG_CLFLUSH_MONITOR, [addr] "a" (addr));
> + alternative_input("", "clflush %a[addr]",
> + X86_BUG_CLFLUSH_MONITOR, [addr] "r" (addr));
> __monitor(addr, 0, 0);
>
> if (need_resched())
> diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
> index 4c718f8adc59..8e295fb19b10 100644
> --- a/arch/x86/kernel/process.c
> +++ b/arch/x86/kernel/process.c
> @@ -921,7 +921,8 @@ static __cpuidle void mwait_idle(void)
> if (!current_set_polling_and_test()) {
> const void *addr = &current_thread_info()->flags;
>
> - alternative_input("", "clflush (%[addr])", X86_BUG_CLFLUSH_MONITOR, [addr] "a" (addr));
> + alternative_input("", "clflush %a[addr]",
> + X86_BUG_CLFLUSH_MONITOR, [addr] "r" (addr));
> __monitor(addr, 0, 0);
> if (need_resched())
> goto out;