Skip to content

Commit a133052

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: selftests: Fix irqfd_test for non-x86 architectures
The KVM_IRQFD ioctl fails if no irqchip is present in-kernel, which isn't too surprising as there's not much KVM can do for an IRQ if it cannot resolve a destination. As written the irqfd_test assumes that a 'default' VM created in selftests has an in-kernel irqchip created implicitly. That may be the case on x86 but it isn't necessarily true on other architectures. Add an arch predicate indicating if 'default' VMs get an irqchip and make the irqfd_test depend on it. Work around arm64 VGIC initialization requirements by using vm_create_with_one_vcpu(), ignoring the created vCPU as it isn't used for the test. Reported-by: Sebastian Ott <sebott@redhat.com> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org> Acked-by: Sean Christopherson <seanjc@google.com> Fixes: 7e9b231 ("KVM: selftests: Add a KVM_IRQFD test to verify uniqueness requirements") Signed-off-by: Oliver Upton <oliver.upton@linux.dev> Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent cc43093 commit a133052

6 files changed

Lines changed: 33 additions & 3 deletions

File tree

tools/testing/selftests/kvm/include/kvm_util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,4 +1273,6 @@ bool vm_is_gpa_protected(struct kvm_vm *vm, vm_paddr_t paddr);
12731273

12741274
uint32_t guest_get_vcpuid(void);
12751275

1276+
bool kvm_arch_has_default_irqchip(void);
1277+
12761278
#endif /* SELFTEST_KVM_UTIL_H */

tools/testing/selftests/kvm/irqfd_test.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,19 @@ static void juggle_eventfd_primary(struct kvm_vm *vm, int eventfd)
8989
int main(int argc, char *argv[])
9090
{
9191
pthread_t racing_thread;
92+
struct kvm_vcpu *unused;
9293
int r, i;
9394

94-
/* Create "full" VMs, as KVM_IRQFD requires an in-kernel IRQ chip. */
95-
vm1 = vm_create(1);
96-
vm2 = vm_create(1);
95+
TEST_REQUIRE(kvm_arch_has_default_irqchip());
96+
97+
/*
98+
* Create "full" VMs, as KVM_IRQFD requires an in-kernel IRQ chip. Also
99+
* create an unused vCPU as certain architectures (like arm64) need to
100+
* complete IRQ chip initialization after all possible vCPUs for a VM
101+
* have been created.
102+
*/
103+
vm1 = vm_create_with_one_vcpu(&unused, NULL);
104+
vm2 = vm_create_with_one_vcpu(&unused, NULL);
97105

98106
WRITE_ONCE(__eventfd, kvm_new_eventfd());
99107

tools/testing/selftests/kvm/lib/arm64/processor.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,3 +725,8 @@ void kvm_arch_vm_release(struct kvm_vm *vm)
725725
if (vm->arch.has_gic)
726726
close(vm->arch.gic_fd);
727727
}
728+
729+
bool kvm_arch_has_default_irqchip(void)
730+
{
731+
return request_vgic && kvm_supports_vgic_v3();
732+
}

tools/testing/selftests/kvm/lib/kvm_util.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,3 +2344,8 @@ bool vm_is_gpa_protected(struct kvm_vm *vm, vm_paddr_t paddr)
23442344
pg = paddr >> vm->page_shift;
23452345
return sparsebit_is_set(region->protected_phy_pages, pg);
23462346
}
2347+
2348+
__weak bool kvm_arch_has_default_irqchip(void)
2349+
{
2350+
return false;
2351+
}

tools/testing/selftests/kvm/lib/s390/processor.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,8 @@ void vcpu_arch_dump(FILE *stream, struct kvm_vcpu *vcpu, uint8_t indent)
221221
void assert_on_unhandled_exception(struct kvm_vcpu *vcpu)
222222
{
223223
}
224+
225+
bool kvm_arch_has_default_irqchip(void)
226+
{
227+
return true;
228+
}

tools/testing/selftests/kvm/lib/x86/processor.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,3 +1318,8 @@ bool sys_clocksource_is_based_on_tsc(void)
13181318

13191319
return ret;
13201320
}
1321+
1322+
bool kvm_arch_has_default_irqchip(void)
1323+
{
1324+
return true;
1325+
}

0 commit comments

Comments
 (0)