Skip to contentSkip to conversation

x86/asm: Use asm_inline() instead of asm() in alternative_msr_write()

PATCH New Uros Bizjak 1 participant 1 message Mar 14, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/asm: Use asm_inline() instead of asm() in alternative_msr_write()

Use asm_inline() to instruct the compiler that the size of asm() is the minimum size of one instruction, ignoring how many instructions the compiler thinks it is. ALTERNATIVE macro that expands to several pseudo directives causes instruction length estimate to count more than 20 instructions.

bloat-o-meter reports minimal code size increase
(x86_64 defconfig, gcc-14.2.1):

add/remove: 0/1 grow/shrink: 2/0 up/down: 338/-249 (89)

Function old new delta
-----------------------------------------------------
arch_prctl_spec_ctrl_set 339 656 +317
arch_seccomp_spec_mitigate 135 156 +21
ib_prctl_set 249 - -249

Total: Before=21423521, After=21423610, chg +0.00%

The code size increase is due to the compiler inlining more functions that inline alternative_msr_write().

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/include/asm/nospec-branch.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/nospec-branch.h +1 -1
index e8757d7a3582..097ce28aabc5 100644
@@ -510,7 +510,7 @@ enum ssb_mitigation {
 static __always_inline
 void alternative_msr_write(unsigned int msr, u64 val, unsigned int feature)
 {
-	asm volatile(ALTERNATIVE("", "wrmsr", %c[feature])
+	asm_inline volatile(ALTERNATIVE("", "wrmsr", %c[feature])
 		: : "c" (msr),
 		    "a" ((u32)val),
 		    "d" ((u32)(val >> 32)),
Signature · 1 line
2.48.1