Skip to content

Commit b213812

Browse files
suomilewissean-jc
authored andcommitted
KVM: selftests: Move XGETBV and XSETBV helpers to common code
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>
1 parent 55cd57b commit b213812

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

tools/testing/selftests/kvm/include/x86_64/processor.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,24 @@ static inline void set_cr4(uint64_t val)
510510
__asm__ __volatile__("mov %0, %%cr4" : : "r" (val) : "memory");
511511
}
512512

513+
static inline u64 xgetbv(u32 index)
514+
{
515+
u32 eax, edx;
516+
517+
__asm__ __volatile__("xgetbv;"
518+
: "=a" (eax), "=d" (edx)
519+
: "c" (index));
520+
return eax | ((u64)edx << 32);
521+
}
522+
523+
static inline void xsetbv(u32 index, u64 value)
524+
{
525+
u32 eax = value;
526+
u32 edx = value >> 32;
527+
528+
__asm__ __volatile__("xsetbv" :: "a" (eax), "d" (edx), "c" (index));
529+
}
530+
513531
static inline struct desc_ptr get_gdt(void)
514532
{
515533
struct desc_ptr gdt;

tools/testing/selftests/kvm/x86_64/amx_test.c

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,6 @@ struct xtile_info {
6565

6666
static struct xtile_info xtile;
6767

68-
static inline u64 __xgetbv(u32 index)
69-
{
70-
u32 eax, edx;
71-
72-
asm volatile("xgetbv;"
73-
: "=a" (eax), "=d" (edx)
74-
: "c" (index));
75-
return eax + ((u64)edx << 32);
76-
}
77-
78-
static inline void __xsetbv(u32 index, u64 value)
79-
{
80-
u32 eax = value;
81-
u32 edx = value >> 32;
82-
83-
asm volatile("xsetbv" :: "a" (eax), "d" (edx), "c" (index));
84-
}
85-
8668
static inline void __ldtilecfg(void *cfg)
8769
{
8870
asm volatile(".byte 0xc4,0xe2,0x78,0x49,0x00"
@@ -160,10 +142,10 @@ static void init_regs(void)
160142
set_cr4(cr4);
161143
GUEST_ASSERT(this_cpu_has(X86_FEATURE_OSXSAVE));
162144

163-
xcr0 = __xgetbv(0);
145+
xcr0 = xgetbv(0);
164146
xcr0 |= XFEATURE_MASK_XTILE;
165-
__xsetbv(0x0, xcr0);
166-
GUEST_ASSERT((__xgetbv(0) & XFEATURE_MASK_XTILE) == XFEATURE_MASK_XTILE);
147+
xsetbv(0x0, xcr0);
148+
GUEST_ASSERT((xgetbv(0) & XFEATURE_MASK_XTILE) == XFEATURE_MASK_XTILE);
167149
}
168150

169151
static void __attribute__((__flatten__)) guest_code(struct tile_config *amx_cfg,

0 commit comments

Comments
 (0)