Re: [PATCH 18/20] x86/smap: Use alternative_io() in smap_{save,restore}()

From: Uros Bizjak
Date: Sat Mar 15 2025 - 05:09:45 EST


On Fri, Mar 14, 2025 at 10:42 PM Josh Poimboeuf <jpoimboe@xxxxxxxxxx> wrote:
>
> Use the standard alternative_io() interface.
>
> Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> ---
> arch/x86/include/asm/smap.h | 18 ++++++++++--------
> 1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
> index 60ea21b4c8b7..8b77ddcb37e7 100644
> --- a/arch/x86/include/asm/smap.h
> +++ b/arch/x86/include/asm/smap.h
> @@ -39,20 +39,22 @@ static __always_inline unsigned long smap_save(void)
> {
> unsigned long flags;
>
> - asm volatile ("# smap_save\n\t"
> - ALTERNATIVE("",
> - "pushf; pop %[flags]; clac\n\t", X86_FEATURE_SMAP)
> - : [flags] "=rm" (flags) : : "memory", "cc");
> + alternative_io("",
> + "pushf; pop %[flags]; clac\n\t", X86_FEATURE_SMAP,

Please merge two lines above (if possible, otherwise put feature
condition in the next line. Please also remove trailing \n\t.

> + ARG([flags] "=rm" (flags)),
> + ARG(),
> + ARG("memory", "cc"));
>
> return flags;
> }
>
> static __always_inline void smap_restore(unsigned long flags)
> {
> - asm volatile ("# smap_restore\n\t"
> - ALTERNATIVE("",
> - "push %[flags]; popf\n\t", X86_FEATURE_SMAP)
> - : : [flags] "g" (flags) : "memory", "cc");
> + alternative_io("",
> + "push %[flags]; popf\n\t", X86_FEATURE_SMAP,

As above.

> + ARG(),
> + ARG([flags] "g" (flags)),

Uh, a build failure waiting to happen here. Please use "rme" instead
of "g". PUSH doesn't support 64bit immediates ("i") on x86_64 ("g"
expands to "rmi").

Thanks,
Uros.