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

Josh Poimboeuf posted 20 patches 10 months, 4 weeks ago
[PATCH 18/20] x86/smap: Use alternative_io() in smap_{save,restore}()
Posted by Josh Poimboeuf 10 months, 4 weeks ago
Use the standard alternative_io() interface.

Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 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,
+		       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,
+		       ARG(),
+		       ARG([flags] "g" (flags)),
+		       ARG("memory", "cc"));
 }
 
 /* These macros can be used in asm() statements */
-- 
2.48.1
Re: [PATCH 18/20] x86/smap: Use alternative_io() in smap_{save,restore}()
Posted by Uros Bizjak 10 months, 4 weeks ago
On Fri, Mar 14, 2025 at 10:42 PM Josh Poimboeuf <jpoimboe@kernel.org> wrote:
>
> Use the standard alternative_io() interface.
>
> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
> ---
>  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.