Commit b213812d authored by Aaron Lewis's avatar Aaron Lewis Committed by Sean Christopherson
Browse files

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: default avatarJim Mattson <jmattson@google.com>
Signed-off-by: default avatarAaron Lewis <aaronlewis@google.com>
Reviewed-by: default avatarMingwei Zhang <mizhang@google.com>
[sean: reword shortlog]
Reviewed-by: default avatarAaron Lewis <aaronlewis@google.com>
Tested-by: default avatarAaron Lewis <aaronlewis@google.com>
Link: https://lore.kernel.org/r/20230405004520.421768-4-seanjc@google.com


Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
parent 55cd57b5
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -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;
+3 −21
Original line number Diff line number Diff line
@@ -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,