All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/msr: Rework wrmsr_safe() using asm goto()
@ 2025-05-21 14:36 Andrew Cooper
  2025-05-21 14:47 ` Jan Beulich
  2025-05-21 18:00 ` [Eclair false positive] " Andrew Cooper
  0 siblings, 2 replies; 13+ messages in thread
From: Andrew Cooper @ 2025-05-21 14:36 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Jan Beulich, Roger Pau Monné

This avoids needing to hold rc in a register across the WRMSR, and in most
cases removes direct testing and branching based on rc, as the fault label can
be rearranged to directly land on the out-of-line block.

No functional change.

Resolves: https://gitlab.com/xen-project/xen/-/work_items/214
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/include/asm/msr.h | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/xen/arch/x86/include/asm/msr.h b/xen/arch/x86/include/asm/msr.h
index 0d3b1d637488..4c4f18b3a54d 100644
--- a/xen/arch/x86/include/asm/msr.h
+++ b/xen/arch/x86/include/asm/msr.h
@@ -69,20 +69,20 @@ static inline void wrmsr_ns(uint32_t msr, uint32_t lo, uint32_t hi)
 /* wrmsr with exception handling */
 static inline int wrmsr_safe(unsigned int msr, uint64_t val)
 {
-    int rc;
-    uint32_t lo, hi;
-    lo = (uint32_t)val;
-    hi = (uint32_t)(val >> 32);
-
-    __asm__ __volatile__(
-        "1: wrmsr\n2:\n"
-        ".section .fixup,\"ax\"\n"
-        "3: movl %5,%0\n; jmp 2b\n"
-        ".previous\n"
-        _ASM_EXTABLE(1b, 3b)
-        : "=&r" (rc)
-        : "c" (msr), "a" (lo), "d" (hi), "0" (0), "i" (-EFAULT));
-    return rc;
+    uint32_t lo = val, hi = val >> 32;
+
+    asm_inline goto (
+        "1: wrmsr\n\t"
+        _ASM_EXTABLE(1b, %l[fault])
+        :
+        : "a" (lo), "c" (msr), "d" (hi)
+        :
+        : fault );
+
+    return 0;
+
+ fault:
+    return -EFAULT;
 }
 
 static inline uint64_t msr_fold(const struct cpu_user_regs *regs)
-- 
2.39.5



^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-05-26 20:32 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-21 14:36 [PATCH] x86/msr: Rework wrmsr_safe() using asm goto() Andrew Cooper
2025-05-21 14:47 ` Jan Beulich
2025-05-21 18:00 ` [Eclair false positive] " Andrew Cooper
2025-05-21 19:21   ` Nicola Vetrini
2025-05-21 19:43     ` Andrew Cooper
2025-05-21 19:48       ` Nicola Vetrini
2025-05-21 19:50         ` Andrew Cooper
2025-05-22 12:45   ` Nicola Vetrini
2025-05-22 13:49     ` Andrew Cooper
2025-05-25  7:34       ` Nicola Vetrini
2025-05-25 10:52         ` Andrew Cooper
2025-05-25 13:36           ` Nicola Vetrini
2025-05-26 20:32             ` Nicola Vetrini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.