KVM: selftests: Move XGETBV and XSETBV helpers to common code
authorAaron Lewis <aaronlewis@google.com>
Wed, 5 Apr 2023 00:45:17 +0000 (17:45 -0700)
committerSean Christopherson <seanjc@google.com>
Tue, 11 Apr 2023 17:19:03 +0000 (10:19 -0700)
The instructions XGETBV and XSETBV are useful to other tests.  Move
them to processor.h to make them more broadly available.

No functional change intended.

Reviewed-by: Jim Mattson <jmattson@google.com>
Signed-off-by: Aaron Lewis <aaronlewis@google.com>
Reviewed-by: Mingwei Zhang <mizhang@google.com>
[sean: reword shortlog]
Reviewed-by: Aaron Lewis <aaronlewis@google.com>
Tested-by: Aaron Lewis <aaronlewis@google.com>
Link: https://lore.kernel.org/r/20230405004520.421768-4-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/include/x86_64/processor.h
tools/testing/selftests/kvm/x86_64/amx_test.c

index 3538fa6db72d804e38ef1fea2c503a8c373ce03a..f6061fe7057f7e6b40aabf0fbd54ca0a60e5aa00 100644 (file)
@@ -510,6 +510,24 @@ static inline void set_cr4(uint64_t val)
        __asm__ __volatile__("mov %0, %%cr4" : : "r" (val) : "memory");
 }
 
+static inline u64 xgetbv(u32 index)
+{
+       u32 eax, edx;
+
+       __asm__ __volatile__("xgetbv;"
+                    : "=a" (eax), "=d" (edx)
+                    : "c" (index));
+       return eax | ((u64)edx << 32);
+}
+
+static inline void xsetbv(u32 index, u64 value)
+{
+       u32 eax = value;
+       u32 edx = value >> 32;
+
+       __asm__ __volatile__("xsetbv" :: "a" (eax), "d" (edx), "c" (index));
+}
+
 static inline struct desc_ptr get_gdt(void)
 {
        struct desc_ptr gdt;
index 5c82d7e6f552725de2bb8f0e3d6d8207e2b7d059..af1ef6f79d32e235ea089849a738f07ed4ac518a 100644 (file)
@@ -65,24 +65,6 @@ struct xtile_info {
 
 static struct xtile_info xtile;
 
-static inline u64 __xgetbv(u32 index)
-{
-       u32 eax, edx;
-
-       asm volatile("xgetbv;"
-                    : "=a" (eax), "=d" (edx)
-                    : "c" (index));
-       return eax + ((u64)edx << 32);
-}
-
-static inline void __xsetbv(u32 index, u64 value)
-{
-       u32 eax = value;
-       u32 edx = value >> 32;
-
-       asm volatile("xsetbv" :: "a" (eax), "d" (edx), "c" (index));
-}
-
 static inline void __ldtilecfg(void *cfg)
 {
        asm volatile(".byte 0xc4,0xe2,0x78,0x49,0x00"
@@ -160,10 +142,10 @@ static void init_regs(void)
        set_cr4(cr4);
        GUEST_ASSERT(this_cpu_has(X86_FEATURE_OSXSAVE));
 
-       xcr0 = __xgetbv(0);
+       xcr0 = xgetbv(0);
        xcr0 |= XFEATURE_MASK_XTILE;
-       __xsetbv(0x0, xcr0);
-       GUEST_ASSERT((__xgetbv(0) & XFEATURE_MASK_XTILE) == XFEATURE_MASK_XTILE);
+       xsetbv(0x0, xcr0);
+       GUEST_ASSERT((xgetbv(0) & XFEATURE_MASK_XTILE) == XFEATURE_MASK_XTILE);
 }
 
 static void __attribute__((__flatten__)) guest_code(struct tile_config *amx_cfg,