Commit bfff0f60 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini
Browse files

KVM: selftests: Consolidate KVM_{G,S}ET_ONE_REG helpers



Rework vcpu_{g,s}et_reg() to provide the APIs that tests actually want to
use, and drop the three "one-off" implementations that cropped up due to
the poor API.

Ignore the handful of direct KVM_{G,S}ET_ONE_REG calls that don't fit the
APIs for one reason or another.

No functional change intended.

Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 45f56808
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -242,7 +242,7 @@ static int debug_version(struct kvm_vcpu *vcpu)
{
	uint64_t id_aa64dfr0;

	get_reg(vcpu->vm, vcpu->id, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1), &id_aa64dfr0);
	vcpu_get_reg(vcpu->vm, vcpu->id, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1), &id_aa64dfr0);
	return id_aa64dfr0 & 0xf;
}

+1 −1
Original line number Diff line number Diff line
@@ -458,7 +458,7 @@ static void run_test(struct vcpu_config *c)
		bool reject_reg = false;
		int ret;

		ret = __vcpu_ioctl(vm, 0, KVM_GET_ONE_REG, &reg);
		ret = __vcpu_get_reg(vm, 0, reg_list->reg[i], &addr);
		if (ret) {
			printf("%s: Failed to get ", config_name(c));
			print_reg(c, reg.id);
+6 −26
Original line number Diff line number Diff line
@@ -141,26 +141,6 @@ static void guest_code(void)
	GUEST_DONE();
}

static int set_fw_reg(struct kvm_vm *vm, uint64_t id, uint64_t val)
{
	struct kvm_one_reg reg = {
		.id = id,
		.addr = (uint64_t)&val,
	};

	return __vcpu_ioctl(vm, 0, KVM_SET_ONE_REG, &reg);
}

static void get_fw_reg(struct kvm_vm *vm, uint64_t id, uint64_t *addr)
{
	struct kvm_one_reg reg = {
		.id = id,
		.addr = (uint64_t)addr,
	};

	vcpu_ioctl(vm, 0, KVM_GET_ONE_REG, &reg);
}

struct st_time {
	uint32_t rev;
	uint32_t attr;
@@ -196,18 +176,18 @@ static void test_fw_regs_before_vm_start(struct kvm_vm *vm)
		const struct kvm_fw_reg_info *reg_info = &fw_reg_info[i];

		/* First 'read' should be an upper limit of the features supported */
		get_fw_reg(vm, reg_info->reg, &val);
		vcpu_get_reg(vm, 0, reg_info->reg, &val);
		TEST_ASSERT(val == FW_REG_ULIMIT_VAL(reg_info->max_feat_bit),
			"Expected all the features to be set for reg: 0x%lx; expected: 0x%lx; read: 0x%lx\n",
			reg_info->reg, FW_REG_ULIMIT_VAL(reg_info->max_feat_bit), val);

		/* Test a 'write' by disabling all the features of the register map */
		ret = set_fw_reg(vm, reg_info->reg, 0);
		ret = __vcpu_set_reg(vm, 0, reg_info->reg, 0);
		TEST_ASSERT(ret == 0,
			"Failed to clear all the features of reg: 0x%lx; ret: %d\n",
			reg_info->reg, errno);

		get_fw_reg(vm, reg_info->reg, &val);
		vcpu_get_reg(vm, 0, reg_info->reg, &val);
		TEST_ASSERT(val == 0,
			"Expected all the features to be cleared for reg: 0x%lx\n", reg_info->reg);

@@ -216,7 +196,7 @@ static void test_fw_regs_before_vm_start(struct kvm_vm *vm)
		 * Avoid this check if all the bits are occupied.
		 */
		if (reg_info->max_feat_bit < 63) {
			ret = set_fw_reg(vm, reg_info->reg, BIT(reg_info->max_feat_bit + 1));
			ret = __vcpu_set_reg(vm, 0, reg_info->reg, BIT(reg_info->max_feat_bit + 1));
			TEST_ASSERT(ret != 0 && errno == EINVAL,
			"Unexpected behavior or return value (%d) while setting an unsupported feature for reg: 0x%lx\n",
			errno, reg_info->reg);
@@ -237,7 +217,7 @@ static void test_fw_regs_after_vm_start(struct kvm_vm *vm)
		 * Before starting the VM, the test clears all the bits.
		 * Check if that's still the case.
		 */
		get_fw_reg(vm, reg_info->reg, &val);
		vcpu_get_reg(vm, 0, reg_info->reg, &val);
		TEST_ASSERT(val == 0,
			"Expected all the features to be cleared for reg: 0x%lx\n",
			reg_info->reg);
@@ -247,7 +227,7 @@ static void test_fw_regs_after_vm_start(struct kvm_vm *vm)
		 * the registers and should return EBUSY. Set the registers and check for
		 * the expected errno.
		 */
		ret = set_fw_reg(vm, reg_info->reg, FW_REG_ULIMIT_VAL(reg_info->max_feat_bit));
		ret = __vcpu_set_reg(vm, 0, reg_info->reg, FW_REG_ULIMIT_VAL(reg_info->max_feat_bit));
		TEST_ASSERT(ret != 0 && errno == EBUSY,
		"Unexpected behavior or return value (%d) while setting a feature while VM is running for reg: 0x%lx\n",
		errno, reg_info->reg);
+3 −3
Original line number Diff line number Diff line
@@ -102,8 +102,8 @@ static void assert_vcpu_reset(struct kvm_vcpu *vcpu)
{
	uint64_t obs_pc, obs_x0;

	get_reg(vcpu->vm, vcpu->id, ARM64_CORE_REG(regs.pc), &obs_pc);
	get_reg(vcpu->vm, vcpu->id, ARM64_CORE_REG(regs.regs[0]), &obs_x0);
	vcpu_get_reg(vcpu->vm, vcpu->id, ARM64_CORE_REG(regs.pc), &obs_pc);
	vcpu_get_reg(vcpu->vm, vcpu->id, ARM64_CORE_REG(regs.regs[0]), &obs_x0);

	TEST_ASSERT(obs_pc == CPU_ON_ENTRY_ADDR,
		    "unexpected target cpu pc: %lx (expected: %lx)",
@@ -143,7 +143,7 @@ static void host_test_cpu_on(void)
	 */
	vcpu_power_off(target);

	get_reg(vm, target->id, KVM_ARM64_SYS_REG(SYS_MPIDR_EL1), &target_mpidr);
	vcpu_get_reg(vm, target->id, KVM_ARM64_SYS_REG(SYS_MPIDR_EL1), &target_mpidr);
	vcpu_args_set(vm, source->id, 1, target_mpidr & MPIDR_HWID_BITMASK);
	enter_guest(source);

+1 −17
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
/*
 * KVM_ARM64_SYS_REG(sys_reg_id): Helper macro to convert
 * SYS_* register definitions in asm/sysreg.h to use in KVM
 * calls such as get_reg() and set_reg().
 * calls such as vcpu_get_reg() and vcpu_set_reg().
 */
#define KVM_ARM64_SYS_REG(sys_reg_id)			\
	ARM64_SYS_REG(sys_reg_Op0(sys_reg_id),		\
@@ -47,22 +47,6 @@

#define MPIDR_HWID_BITMASK (0xff00fffffful)

static inline void get_reg(struct kvm_vm *vm, uint32_t vcpuid, uint64_t id, uint64_t *addr)
{
	struct kvm_one_reg reg;
	reg.id = id;
	reg.addr = (uint64_t)addr;
	vcpu_ioctl(vm, vcpuid, KVM_GET_ONE_REG, &reg);
}

static inline void set_reg(struct kvm_vm *vm, uint32_t vcpuid, uint64_t id, uint64_t val)
{
	struct kvm_one_reg reg;
	reg.id = id;
	reg.addr = (uint64_t)&val;
	vcpu_ioctl(vm, vcpuid, KVM_SET_ONE_REG, &reg);
}

void aarch64_vcpu_setup(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_vcpu_init *init);
struct kvm_vcpu *aarch64_vcpu_add(struct kvm_vm *vm, uint32_t vcpu_id,
				  struct kvm_vcpu_init *init, void *guest_code);
Loading