From: Andrew Cooper Date: Thu, 3 Apr 2025 14:37:23 +0000 (+0100) Subject: x86/AMD: Convert wrmsr_amd_safe() to use asm goto() X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=b3d8b3e3f3aa4dcb1cf11acb90cfe368837e9534;p=xen.git x86/AMD: Convert wrmsr_amd_safe() to use asm goto() Bloat-o-meter reports: add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-29 (-29) Function old new delta _probe_mask_msr 99 94 -5 init_amd 2418 2394 -24 but this under-reports because .fixup doesn't contain sized/typed symbols. This also drops two "mov -EFAULT, %reg; jmp ...;" sequences too, so the net saving is -50. wrmsr_amd_safe()'s return value is only checked against 0 (if at all), and because of this, the compiler can now avoid manifesting the 0/-EFAULT constants entirely, and the %[fault] label simply lands on the right basic block. Convert to Xen style while rewriting. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c index 597b0f073d..ce4e1df710 100644 --- a/xen/arch/x86/cpu/amd.c +++ b/xen/arch/x86/cpu/amd.c @@ -74,21 +74,19 @@ static inline int rdmsr_amd_safe(unsigned int msr, unsigned int *lo, } static inline int wrmsr_amd_safe(unsigned int msr, unsigned int lo, - unsigned int hi) + unsigned int hi) { - int err; + asm goto ( "1: wrmsr\n\t" + _ASM_EXTABLE(1b, %l[fault]) + : + : "c" (msr), "a" (lo), "d" (hi), "D" (0x9c5a203a) + : + : fault ); - asm volatile("1: wrmsr\n2:\n" - ".section .fixup,\"ax\"\n" - "3: movl %6,%0\n" - " jmp 2b\n" - ".previous\n" - _ASM_EXTABLE(1b, 3b) - : "=r" (err) - : "c" (msr), "a" (lo), "d" (hi), "D" (0x9c5a203a), - "0" (0), "i" (-EFAULT)); + return 0; - return err; + fault: + return -EFAULT; } static void wrmsr_amd(unsigned int msr, uint64_t val)