Re: [PATCH v7 1/6] x86/bugs: Add asm helpers for executing VERW

From: Pawan Gupta
Date: Fri Feb 09 2024 - 16:20:13 EST


On Fri, Feb 09, 2024 at 08:57:04PM +0100, Borislav Petkov wrote:
> On Fri, Feb 09, 2024 at 11:06:02AM -0800, Pawan Gupta wrote:
> > (Though, there was a comment on avoiding the macro alltogether, to which
> > I replied that it complicates 32-bit.)
>
> Hmm, so this seems to build the respective entry_{32,64}.S TUs fine:
>
> ---
> diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
> index e81cabcb758f..7d1e5fe66495 100644
> --- a/arch/x86/include/asm/nospec-branch.h
> +++ b/arch/x86/include/asm/nospec-branch.h
> @@ -313,12 +313,9 @@
> *
> * Note: Only the memory operand variant of VERW clears the CPU buffers.
> */
> -.macro EXEC_VERW
> - verw _ASM_RIP(mds_verw_sel)
> -.endm
>
> .macro CLEAR_CPU_BUFFERS
> - ALTERNATIVE "", __stringify(EXEC_VERW), X86_FEATURE_CLEAR_CPU_BUF
> + ALTERNATIVE "", __stringify(verw _ASM_RIP(mds_verw_sel)), X86_FEATURE_CLEAR_CPU_BUF
> .endm

> +.macro CLEAR_CPU_BUFFERS
> + ALTERNATIVE "", __stringify(EXEC_VERW), X86_FEATURE_CLEAR_CPU_BUF
> +.endm

This works, thanks.

My mistake that I tried your earlier suggestion without playing with it:

> > +.macro CLEAR_CPU_BUFFERS
> > + ALTERNATIVE "", __stringify(EXEC_VERW), X86_FEATURE_CLEAR_CPU_BUF
> > +.endm
>
> Why can't this simply be:
>
> .macro CLEAR_CPU_BUFFERS
> ALTERNATIVE "", "verw mds_verw_sel(%rip)", X86_FEATURE_CLEAR_CPU_BUF
> .endm
>
> without that silly EXEC_VERW macro?
>
> --
> Regards/Gruss,
> Boris.