KVM: selftests: Convert vgic_init away from vm_create_default_with_vcpus()
Use a combination of vm_create(), vm_create_with_vcpus(), and vm_vcpu_add() to convert vgic_init from vm_create_default_with_vcpus(), and away from referncing vCPUs by ID. Thus continues the march toward total annihilation of "default" helpers. Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
f3443bed29
commit
45f568084a
@ -66,19 +66,21 @@ static void guest_code(void)
|
||||
}
|
||||
|
||||
/* we don't want to assert on run execution, hence that helper */
|
||||
static int run_vcpu(struct kvm_vm *vm, uint32_t vcpuid)
|
||||
static int run_vcpu(struct kvm_vcpu *vcpu)
|
||||
{
|
||||
ucall_init(vm, NULL);
|
||||
ucall_init(vcpu->vm, NULL);
|
||||
|
||||
return __vcpu_run(vm, vcpuid) ? -errno : 0;
|
||||
return __vcpu_run(vcpu->vm, vcpu->id) ? -errno : 0;
|
||||
}
|
||||
|
||||
static struct vm_gic vm_gic_create_with_vcpus(uint32_t gic_dev_type, uint32_t nr_vcpus)
|
||||
static struct vm_gic vm_gic_create_with_vcpus(uint32_t gic_dev_type,
|
||||
uint32_t nr_vcpus,
|
||||
struct kvm_vcpu *vcpus[])
|
||||
{
|
||||
struct vm_gic v;
|
||||
|
||||
v.gic_dev_type = gic_dev_type;
|
||||
v.vm = vm_create_default_with_vcpus(nr_vcpus, 0, 0, guest_code, NULL);
|
||||
v.vm = vm_create_with_vcpus(nr_vcpus, guest_code, vcpus);
|
||||
v.gic_fd = kvm_create_device(v.vm, gic_dev_type);
|
||||
|
||||
return v;
|
||||
@ -322,18 +324,19 @@ static void subtest_v3_redist_regions(struct vm_gic *v)
|
||||
*/
|
||||
static void test_vgic_then_vcpus(uint32_t gic_dev_type)
|
||||
{
|
||||
struct kvm_vcpu *vcpus[NR_VCPUS];
|
||||
struct vm_gic v;
|
||||
int ret, i;
|
||||
|
||||
v = vm_gic_create_with_vcpus(gic_dev_type, 1);
|
||||
v = vm_gic_create_with_vcpus(gic_dev_type, 1, vcpus);
|
||||
|
||||
subtest_dist_rdist(&v);
|
||||
|
||||
/* Add the rest of the VCPUs */
|
||||
for (i = 1; i < NR_VCPUS; ++i)
|
||||
vm_vcpu_add(v.vm, i, guest_code);
|
||||
vcpus[i] = vm_vcpu_add(v.vm, i, guest_code);
|
||||
|
||||
ret = run_vcpu(v.vm, 3);
|
||||
ret = run_vcpu(vcpus[3]);
|
||||
TEST_ASSERT(ret == -EINVAL, "dist/rdist overlap detected on 1st vcpu run");
|
||||
|
||||
vm_gic_destroy(&v);
|
||||
@ -342,14 +345,15 @@ static void test_vgic_then_vcpus(uint32_t gic_dev_type)
|
||||
/* All the VCPUs are created before the VGIC KVM device gets initialized */
|
||||
static void test_vcpus_then_vgic(uint32_t gic_dev_type)
|
||||
{
|
||||
struct kvm_vcpu *vcpus[NR_VCPUS];
|
||||
struct vm_gic v;
|
||||
int ret;
|
||||
|
||||
v = vm_gic_create_with_vcpus(gic_dev_type, NR_VCPUS);
|
||||
v = vm_gic_create_with_vcpus(gic_dev_type, NR_VCPUS, vcpus);
|
||||
|
||||
subtest_dist_rdist(&v);
|
||||
|
||||
ret = run_vcpu(v.vm, 3);
|
||||
ret = run_vcpu(vcpus[3]);
|
||||
TEST_ASSERT(ret == -EINVAL, "dist/rdist overlap detected on 1st vcpu run");
|
||||
|
||||
vm_gic_destroy(&v);
|
||||
@ -357,37 +361,38 @@ static void test_vcpus_then_vgic(uint32_t gic_dev_type)
|
||||
|
||||
static void test_v3_new_redist_regions(void)
|
||||
{
|
||||
struct kvm_vcpu *vcpus[NR_VCPUS];
|
||||
void *dummy = NULL;
|
||||
struct vm_gic v;
|
||||
uint64_t addr;
|
||||
int ret;
|
||||
|
||||
v = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, NR_VCPUS);
|
||||
v = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, NR_VCPUS, vcpus);
|
||||
subtest_v3_redist_regions(&v);
|
||||
kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
|
||||
KVM_DEV_ARM_VGIC_CTRL_INIT, NULL);
|
||||
|
||||
ret = run_vcpu(v.vm, 3);
|
||||
ret = run_vcpu(vcpus[3]);
|
||||
TEST_ASSERT(ret == -ENXIO, "running without sufficient number of rdists");
|
||||
vm_gic_destroy(&v);
|
||||
|
||||
/* step2 */
|
||||
|
||||
v = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, NR_VCPUS);
|
||||
v = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, NR_VCPUS, vcpus);
|
||||
subtest_v3_redist_regions(&v);
|
||||
|
||||
addr = REDIST_REGION_ATTR_ADDR(1, 0x280000, 0, 2);
|
||||
kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
|
||||
KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION, &addr);
|
||||
|
||||
ret = run_vcpu(v.vm, 3);
|
||||
ret = run_vcpu(vcpus[3]);
|
||||
TEST_ASSERT(ret == -EBUSY, "running without vgic explicit init");
|
||||
|
||||
vm_gic_destroy(&v);
|
||||
|
||||
/* step 3 */
|
||||
|
||||
v = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, NR_VCPUS);
|
||||
v = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, NR_VCPUS, vcpus);
|
||||
subtest_v3_redist_regions(&v);
|
||||
|
||||
ret = __kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
|
||||
@ -402,7 +407,7 @@ static void test_v3_new_redist_regions(void)
|
||||
kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
|
||||
KVM_DEV_ARM_VGIC_CTRL_INIT, NULL);
|
||||
|
||||
ret = run_vcpu(v.vm, 3);
|
||||
ret = run_vcpu(vcpus[3]);
|
||||
TEST_ASSERT(!ret, "vcpu run");
|
||||
|
||||
vm_gic_destroy(&v);
|
||||
@ -414,21 +419,22 @@ static void test_v3_typer_accesses(void)
|
||||
uint64_t addr;
|
||||
int ret, i;
|
||||
|
||||
v.vm = vm_create_default(0, 0, guest_code);
|
||||
v.vm = vm_create(DEFAULT_GUEST_PHY_PAGES);
|
||||
(void)vm_vcpu_add(v.vm, 0, guest_code);
|
||||
|
||||
v.gic_fd = kvm_create_device(v.vm, KVM_DEV_TYPE_ARM_VGIC_V3);
|
||||
|
||||
vm_vcpu_add(v.vm, 3, guest_code);
|
||||
(void)vm_vcpu_add(v.vm, 3, guest_code);
|
||||
|
||||
v3_redist_reg_get_errno(v.gic_fd, 1, GICR_TYPER, EINVAL,
|
||||
"attempting to read GICR_TYPER of non created vcpu");
|
||||
|
||||
vm_vcpu_add(v.vm, 1, guest_code);
|
||||
(void)vm_vcpu_add(v.vm, 1, guest_code);
|
||||
|
||||
v3_redist_reg_get_errno(v.gic_fd, 1, GICR_TYPER, EBUSY,
|
||||
"read GICR_TYPER before GIC initialized");
|
||||
|
||||
vm_vcpu_add(v.vm, 2, guest_code);
|
||||
(void)vm_vcpu_add(v.vm, 2, guest_code);
|
||||
|
||||
kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
|
||||
KVM_DEV_ARM_VGIC_CTRL_INIT, NULL);
|
||||
@ -467,6 +473,21 @@ static void test_v3_typer_accesses(void)
|
||||
vm_gic_destroy(&v);
|
||||
}
|
||||
|
||||
static struct vm_gic vm_gic_v3_create_with_vcpuids(int nr_vcpus,
|
||||
uint32_t vcpuids[])
|
||||
{
|
||||
struct vm_gic v;
|
||||
int i;
|
||||
|
||||
v.vm = vm_create(DEFAULT_GUEST_PHY_PAGES);
|
||||
for (i = 0; i < nr_vcpus; i++)
|
||||
vm_vcpu_add(v.vm, vcpuids[i], guest_code);
|
||||
|
||||
v.gic_fd = kvm_create_device(v.vm, KVM_DEV_TYPE_ARM_VGIC_V3);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test GICR_TYPER last bit with new redist regions
|
||||
* rdist regions #1 and #2 are contiguous
|
||||
@ -483,9 +504,7 @@ static void test_v3_last_bit_redist_regions(void)
|
||||
struct vm_gic v;
|
||||
uint64_t addr;
|
||||
|
||||
v.vm = vm_create_default_with_vcpus(6, 0, 0, guest_code, vcpuids);
|
||||
|
||||
v.gic_fd = kvm_create_device(v.vm, KVM_DEV_TYPE_ARM_VGIC_V3);
|
||||
v = vm_gic_v3_create_with_vcpuids(ARRAY_SIZE(vcpuids), vcpuids);
|
||||
|
||||
kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
|
||||
KVM_DEV_ARM_VGIC_CTRL_INIT, NULL);
|
||||
@ -519,9 +538,7 @@ static void test_v3_last_bit_single_rdist(void)
|
||||
struct vm_gic v;
|
||||
uint64_t addr;
|
||||
|
||||
v.vm = vm_create_default_with_vcpus(6, 0, 0, guest_code, vcpuids);
|
||||
|
||||
v.gic_fd = kvm_create_device(v.vm, KVM_DEV_TYPE_ARM_VGIC_V3);
|
||||
v = vm_gic_v3_create_with_vcpuids(ARRAY_SIZE(vcpuids), vcpuids);
|
||||
|
||||
kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
|
||||
KVM_DEV_ARM_VGIC_CTRL_INIT, NULL);
|
||||
@ -542,11 +559,12 @@ static void test_v3_last_bit_single_rdist(void)
|
||||
/* Uses the legacy REDIST region API. */
|
||||
static void test_v3_redist_ipa_range_check_at_vcpu_run(void)
|
||||
{
|
||||
struct kvm_vcpu *vcpus[NR_VCPUS];
|
||||
struct vm_gic v;
|
||||
int ret, i;
|
||||
uint64_t addr;
|
||||
|
||||
v = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, 1);
|
||||
v = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, 1, vcpus);
|
||||
|
||||
/* Set space for 3 redists, we have 1 vcpu, so this succeeds. */
|
||||
addr = max_phys_size - (3 * 2 * 0x10000);
|
||||
@ -559,13 +577,13 @@ static void test_v3_redist_ipa_range_check_at_vcpu_run(void)
|
||||
|
||||
/* Add the rest of the VCPUs */
|
||||
for (i = 1; i < NR_VCPUS; ++i)
|
||||
vm_vcpu_add(v.vm, i, guest_code);
|
||||
vcpus[i] = vm_vcpu_add(v.vm, i, guest_code);
|
||||
|
||||
kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
|
||||
KVM_DEV_ARM_VGIC_CTRL_INIT, NULL);
|
||||
|
||||
/* Attempt to run a vcpu without enough redist space. */
|
||||
ret = run_vcpu(v.vm, 2);
|
||||
ret = run_vcpu(vcpus[2]);
|
||||
TEST_ASSERT(ret && errno == EINVAL,
|
||||
"redist base+size above PA range detected on 1st vcpu run");
|
||||
|
||||
@ -574,11 +592,12 @@ static void test_v3_redist_ipa_range_check_at_vcpu_run(void)
|
||||
|
||||
static void test_v3_its_region(void)
|
||||
{
|
||||
struct kvm_vcpu *vcpus[NR_VCPUS];
|
||||
struct vm_gic v;
|
||||
uint64_t addr;
|
||||
int its_fd, ret;
|
||||
|
||||
v = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, NR_VCPUS);
|
||||
v = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, NR_VCPUS, vcpus);
|
||||
its_fd = kvm_create_device(v.vm, KVM_DEV_TYPE_ARM_VGIC_ITS);
|
||||
|
||||
addr = 0x401000;
|
||||
@ -618,11 +637,12 @@ static void test_v3_its_region(void)
|
||||
*/
|
||||
int test_kvm_device(uint32_t gic_dev_type)
|
||||
{
|
||||
struct kvm_vcpu *vcpus[NR_VCPUS];
|
||||
struct vm_gic v;
|
||||
uint32_t other;
|
||||
int ret;
|
||||
|
||||
v.vm = vm_create_default_with_vcpus(NR_VCPUS, 0, 0, guest_code, NULL);
|
||||
v.vm = vm_create_with_vcpus(NR_VCPUS, guest_code, vcpus);
|
||||
|
||||
/* try to create a non existing KVM device */
|
||||
ret = __kvm_test_create_device(v.vm, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user