Commit e84183f6 authored by Paolo Bonzini's avatar Paolo Bonzini
Browse files

Merge tag 'kvm-x86-selftests-6.3' of https://github.com/kvm-x86/linux into HEAD

KVM selftests changes for 6.3:

 - Cache the CPU vendor (AMD vs. Intel) and use the info to emit the correct
   hypercall instruction instead of relying on KVM to patch in VMMCALL

 - A variety of one-off cleanups and fixes
parents 157ed9cb 695fa5a6
Loading
Loading
Loading
Loading
+26 −4
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@

#include "../kvm_util.h"

extern bool host_cpu_is_intel;
extern bool host_cpu_is_amd;

#define NMI_VECTOR		0x02

#define X86_EFLAGS_FIXED	 (1u << 1)
@@ -555,6 +558,28 @@ static inline uint32_t this_cpu_model(void)
	return x86_model(this_cpu_fms());
}

static inline bool this_cpu_vendor_string_is(const char *vendor)
{
	const uint32_t *chunk = (const uint32_t *)vendor;
	uint32_t eax, ebx, ecx, edx;

	cpuid(0, &eax, &ebx, &ecx, &edx);
	return (ebx == chunk[0] && edx == chunk[1] && ecx == chunk[2]);
}

static inline bool this_cpu_is_intel(void)
{
	return this_cpu_vendor_string_is("GenuineIntel");
}

/*
 * Exclude early K5 samples with a vendor string of "AMDisbetter!"
 */
static inline bool this_cpu_is_amd(void)
{
	return this_cpu_vendor_string_is("AuthenticAMD");
}

static inline uint32_t __this_cpu_has(uint32_t function, uint32_t index,
				      uint8_t reg, uint8_t lo, uint8_t hi)
{
@@ -691,9 +716,6 @@ static inline void cpu_relax(void)
		"hlt\n"	\
		)

bool is_intel_cpu(void);
bool is_amd_cpu(void);

struct kvm_x86_state *vcpu_save_state(struct kvm_vcpu *vcpu);
void vcpu_load_state(struct kvm_vcpu *vcpu, struct kvm_x86_state *state);
void kvm_x86_state_cleanup(struct kvm_x86_state *state);
@@ -717,7 +739,7 @@ static inline void vcpu_msrs_set(struct kvm_vcpu *vcpu, struct kvm_msrs *msrs)
	int r = __vcpu_ioctl(vcpu, KVM_SET_MSRS, msrs);

	TEST_ASSERT(r == msrs->nmsrs,
		    "KVM_GET_MSRS failed, r: %i (failed on MSR %x)",
		    "KVM_SET_MSRS failed, r: %i (failed on MSR %x)",
		    r, r < 0 || r >= msrs->nmsrs ? -1 : msrs->entries[r].index);
}
static inline void vcpu_debugregs_get(struct kvm_vcpu *vcpu,
+1 −9
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ static void stats_test(int stats_fd)
				    "Bucket size of stats (%s) is not zero",
				    pdesc->name);
		}
		size_data += pdesc->size * sizeof(*stats_data);
		size_data = max(size_data, pdesc->offset + pdesc->size * sizeof(*stats_data));
	}

	/*
@@ -149,14 +149,6 @@ static void stats_test(int stats_fd)
	TEST_ASSERT(size_data >= header.num_desc * sizeof(*stats_data),
		    "Data size is not correct");

	/* Check stats offset */
	for (i = 0; i < header.num_desc; ++i) {
		pdesc = get_stats_descriptor(stats_desc, i, &header);
		TEST_ASSERT(pdesc->offset < size_data,
			    "Invalid offset (%u) for stats: %s",
			    pdesc->offset, pdesc->name);
	}

	/* Allocate memory for stats data */
	stats_data = malloc(size_data);
	TEST_ASSERT(stats_data, "Allocate memory for stats data");
+2 −0
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ static void elfhdr_get(const char *filename, Elf64_Ehdr *hdrp)
		"  hdrp->e_shentsize: %x\n"
		"  expected: %zx",
		hdrp->e_shentsize, sizeof(Elf64_Shdr));
	close(fd);
}

/* VM ELF Load
@@ -190,4 +191,5 @@ void kvm_vm_elf_load(struct kvm_vm *vm, const char *filename)
				phdr.p_filesz);
		}
	}
	close(fd);
}
+1 −1
Original line number Diff line number Diff line
@@ -127,7 +127,7 @@ void guest_modes_cmdline(const char *arg)
		mode_selected = true;
	}

	mode = strtoul(optarg, NULL, 10);
	mode = atoi_non_negative("Guest mode ID", arg);
	TEST_ASSERT(mode < NUM_VM_MODES, "Guest mode ID %d too big", mode);
	guest_modes[mode].enabled = true;
}
+0 −3
Original line number Diff line number Diff line
@@ -1942,9 +1942,6 @@ vm_paddr_t vm_phy_page_alloc(struct kvm_vm *vm, vm_paddr_t paddr_min,
	return vm_phy_pages_alloc(vm, 1, paddr_min, memslot);
}

/* Arbitrary minimum physical address used for virtual translation tables. */
#define KVM_GUEST_PAGE_TABLE_MIN_PADDR 0x180000

vm_paddr_t vm_alloc_page_table(struct kvm_vm *vm)
{
	return vm_phy_page_alloc(vm, KVM_GUEST_PAGE_TABLE_MIN_PADDR,
Loading