[PATCH 17/20] x86/smap: Use named asm operands in smap_{save,restore}()

Josh Poimboeuf posted 20 patches 9 months, 1 week ago
[PATCH 17/20] x86/smap: Use named asm operands in smap_{save,restore}()
Posted by Josh Poimboeuf 9 months, 1 week ago
Use named operands in preparation for using alternative_io().

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

diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
index 2de1e5a75c57..60ea21b4c8b7 100644
--- a/arch/x86/include/asm/smap.h
+++ b/arch/x86/include/asm/smap.h
@@ -40,9 +40,9 @@ static __always_inline unsigned long smap_save(void)
 	unsigned long flags;
 
 	asm volatile ("# smap_save\n\t"
-		      ALTERNATIVE("", "pushf; pop %0; " "clac" "\n\t",
-				  X86_FEATURE_SMAP)
-		      : "=rm" (flags) : : "memory", "cc");
+		      ALTERNATIVE("",
+				  "pushf; pop %[flags]; clac\n\t", X86_FEATURE_SMAP)
+		      : [flags] "=rm" (flags) : : "memory", "cc");
 
 	return flags;
 }
@@ -50,9 +50,9 @@ static __always_inline unsigned long smap_save(void)
 static __always_inline void smap_restore(unsigned long flags)
 {
 	asm volatile ("# smap_restore\n\t"
-		      ALTERNATIVE("", "push %0; popf\n\t",
-				  X86_FEATURE_SMAP)
-		      : : "g" (flags) : "memory", "cc");
+		      ALTERNATIVE("",
+				  "push %[flags]; popf\n\t", X86_FEATURE_SMAP)
+		      : : [flags] "g" (flags) : "memory", "cc");
 }
 
 /* These macros can be used in asm() statements */
-- 
2.48.1
Re: [PATCH 17/20] x86/smap: Use named asm operands in smap_{save,restore}()
Posted by Andrew Cooper 9 months, 1 week ago
On 14/03/2025 9:41 pm, Josh Poimboeuf wrote:
> @@ -50,9 +50,9 @@ static __always_inline unsigned long smap_save(void)
>  static __always_inline void smap_restore(unsigned long flags)
>  {
>  	asm volatile ("# smap_restore\n\t"
> -		      ALTERNATIVE("", "push %0; popf\n\t",
> -				  X86_FEATURE_SMAP)
> -		      : : "g" (flags) : "memory", "cc");
> +		      ALTERNATIVE("",
> +				  "push %[flags]; popf\n\t", X86_FEATURE_SMAP)
> +		      : : [flags] "g" (flags) : "memory", "cc");
>  }
>  
>  /* These macros can be used in asm() statements */

The problem with ASM_CALL_CONSTRAINT and asm_call() is that it's not
just call instructions.  It's any transient stack adjustment.

Peeking forwards the other half of the series, you convert IRET to
asm_call(), but leave these alone.

These need converting, and hopefully someone can think of a better name
than "call" to be used for the wrapper.

~Andrew
Re: [PATCH 17/20] x86/smap: Use named asm operands in smap_{save,restore}()
Posted by Andrew Cooper 9 months, 1 week ago
On 14/03/2025 10:51 pm, Andrew Cooper wrote:
> On 14/03/2025 9:41 pm, Josh Poimboeuf wrote:
>> @@ -50,9 +50,9 @@ static __always_inline unsigned long smap_save(void)
>>  static __always_inline void smap_restore(unsigned long flags)
>>  {
>>  	asm volatile ("# smap_restore\n\t"
>> -		      ALTERNATIVE("", "push %0; popf\n\t",
>> -				  X86_FEATURE_SMAP)
>> -		      : : "g" (flags) : "memory", "cc");
>> +		      ALTERNATIVE("",
>> +				  "push %[flags]; popf\n\t", X86_FEATURE_SMAP)
>> +		      : : [flags] "g" (flags) : "memory", "cc");
>>  }
>>  
>>  /* These macros can be used in asm() statements */
> The problem with ASM_CALL_CONSTRAINT and asm_call() is that it's not
> just call instructions.  It's any transient stack adjustment.
>
> Peeking forwards the other half of the series, you convert IRET to
> asm_call(), but leave these alone.
>
> These need converting, and hopefully someone can think of a better name
> than "call" to be used for the wrapper.

After chatting with Josh, the CALL aspect really is for unwinding
reasons.  This will be fine, until the need for "redzone" arrives.

That said, through both series, there are definitely places which have
ASM_CALL_CONSTRAINT and oughtn't to.

~Andrew