KVM: selftests: Fix irqfd_test for non-x86 architectures
PATCH 1/1 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.
--- tools/testing/selftests/kvm/include/kvm_util.h | 2 ++ tools/testing/selftests/kvm/irqfd_test.c | 14 +++++++++++--- tools/testing/selftests/kvm/lib/arm64/processor.c | 5 +++++ tools/testing/selftests/kvm/lib/kvm_util.c | 5 +++++ tools/testing/selftests/kvm/lib/s390/processor.c | 5 +++++ tools/testing/selftests/kvm/lib/x86/processor.c | 5 +++++ 6 files changed, 33 insertions(+), 3 deletions(-)
tools/testing/selftests/kvm/include/kvm_util.h +2 -0
@@ -1268,4 +1268,6 @@ bool vm_is_gpa_protected(struct kvm_vm *vm, vm_paddr_t paddr);uint32_t guest_get_vcpuid (void ); +bool kvm_arch_has_default_irqchip (void ); +#endif /* SELFTEST_KVM_UTIL_H */
tools/testing/selftests/kvm/irqfd_test.c +11 -3
@@ -89,11 +89,19 @@ static void juggle_eventfd_primary(struct kvm_vm *vm, int eventfd)int main (int argc,char *argv[]) {pthread_t racing_thread; +struct kvm_vcpu *unused;int r, i; -/* Create "full" VMs, as KVM_IRQFD requires an in-kernel IRQ chip. */ - vm1 =vm_create (1 ); - vm2 =vm_create (1 ); +TEST_REQUIRE (kvm_arch_has_default_irqchip ()); + +/* +* Create "full" VMs, as KVM_IRQFD requires an in-kernel IRQ chip. Also +* create an unused vCPU as certain architectures (like arm64) need to +* complete IRQ chip initialization after all possible vCPUs for a VM +* have been created. +*/ + vm1 =vm_create_with_one_vcpu (&unused,NULL ); + vm2 =vm_create_with_one_vcpu (&unused,NULL );WRITE_ONCE (__eventfd,kvm_new_eventfd ());
tools/testing/selftests/kvm/lib/arm64/processor.c +5 -0
@@ -725,3 +725,8 @@ void kvm_arch_vm_release(struct kvm_vm *vm)if (vm->arch.has_gic)close (vm->arch.gic_fd); } + +bool kvm_arch_has_default_irqchip (void ) +{ +return request_vgic &&kvm_supports_vgic_v3 (); +}
tools/testing/selftests/kvm/lib/kvm_util.c +5 -0
@@ -2374,3 +2374,8 @@ bool vm_is_gpa_protected(struct kvm_vm *vm, vm_paddr_t paddr) pg = paddr >> vm->page_shift;return sparsebit_is_set (region->protected_phy_pages, pg); } + +__weak bool kvm_arch_has_default_irqchip (void ) +{ +return false; +}
tools/testing/selftests/kvm/lib/s390/processor.c +5 -0
@@ -221,3 +221,8 @@ void vcpu_arch_dump(FILE *stream, struct kvm_vcpu *vcpu, uint8_t indent)void assert_on_unhandled_exception (struct kvm_vcpu *vcpu) { } + +bool kvm_arch_has_default_irqchip (void ) +{ +return true; +}
tools/testing/selftests/kvm/lib/x86/processor.c +5 -0
@@ -1281,3 +1281,8 @@ bool sys_clocksource_is_based_on_tsc(void)return ret; } + +bool kvm_arch_has_default_irqchip (void ) +{ +return true; +}
base-commit: 10fd0285305d0b48e8a3bf15d4f17fc4f3d68cb6
Signature · 1 line
2.39.5
Quoted 9 lines · Oliver Upton
The
KVM_IRQFDioctl 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_testassumes 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.[...]
Applied to fixes, thanks!
[1/1] KVM: selftests: Fix irqfd_test for non-x86 architectures
commit: 3ba969c9415f56c7cc20e9693cb4b5364840b668
Cheers,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.