Skip to contentSkip to conversation

x86/asm: Use "m" operand constraint in WRUSSQ asm template

PATCH Applied Uros Bizjak 2 participants 2 messages Mar 19, 2024 – Mar 20, 2024 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/asm: Use "m" operand constraint in WRUSSQ asm template

The WRUSSQ instruction uses a memory operand, so use "m" operand constraint instead of forcing usage of pointer register using "r" constraint. The generated assembly code improves from:

6ece3: 48 8d 43 f8 lea -0x8(%rbx),%rax
...
6eceb: 66 48 0f 38 f5 18 wrussq %rbx,(%rax)

to:

6ecea: 66 48 0f 38 f5 43 f8 wrussq %rax,-0x8(%rbx)

Cc Yu-cheng Yu <[email protected]>
Cc Rick Edgecombe <[email protected]>
Cc Borislav Petkov (AMD) <[email protected]>
Cc Kees Cook <[email protected]>
Cc Mike Rapoport (IBM) <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc H. Peter Anvin <[email protected]>
---
 arch/x86/include/asm/special_insns.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/special_insns.h +2 -2
index 0ee2ba589492..aec6e2d3aa1d 100644
@@ -205,9 +205,9 @@ static inline void clwb(volatile void *__p)
 #ifdef CONFIG_X86_USER_SHADOW_STACK
 static inline int write_user_shstk_64(u64 __user *addr, u64 val)
 {
-	asm goto("1: wrussq %[val], (%[addr])\n"
+	asm goto("1: wrussq %[val], %[addr]\n"
 			  _ASM_EXTABLE(1b, %l[fail])
-			  :: [addr] "r" (addr), [val] "r" (val)
+			  :: [addr] "m" (*addr), [val] "r" (val)
 			  :: fail);
 	return 0;
 fail:
Signature · 1 line
2.42.0
merge bot Applied
#1 lore raw
The following commit has been merged into the x86/asm branch of tip:

The following commit has been merged into the x86/asm branch of tip:

Commit-ID:     648337147d3550c1ca3d1b500e66dbda12e2d836
Gitweb:        https://git.kernel.org/tip/648337147d3550c1ca3d1b500e66dbda12e2d836
Author:        Uros Bizjak <[email protected]>
AuthorDate:    Tue, 19 Mar 2024 18:16:46 +01:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Wed, 20 Mar 2024 12:04:38 +01:00

x86/asm: Use "m" operand constraint in WRUSSQ asm template

The WRUSSQ instruction uses a memory operand, so use "m" operand constraint instead of forcing usage of pointer register using "r" constraint. The generated assembly code improves from:

6ece3: 48 8d 43 f8 lea -0x8(%rbx),%rax
...
6eceb: 66 48 0f 38 f5 18 wrussq %rbx,(%rax)

to:

6ecea: 66 48 0f 38 f5 43 f8 wrussq %rax,-0x8(%rbx)

---
 arch/x86/include/asm/special_insns.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/special_insns.h +2 -2
index 0ee2ba5..aec6e2d 100644
@@ -205,9 +205,9 @@ static inline void clwb(volatile void *__p)
 #ifdef CONFIG_X86_USER_SHADOW_STACK
 static inline int write_user_shstk_64(u64 __user *addr, u64 val)
 {
-	asm goto("1: wrussq %[val], (%[addr])\n"
+	asm goto("1: wrussq %[val], %[addr]\n"
 			  _ASM_EXTABLE(1b, %l[fail])
-			  :: [addr] "r" (addr), [val] "r" (val)
+			  :: [addr] "m" (*addr), [val] "r" (val)
 			  :: fail);
 	return 0;
 fail: