KVM: selftests: Add kvm_irq_line library function
authorRicardo Koller <ricarkol@google.com>
Tue, 9 Nov 2021 02:38:53 +0000 (18:38 -0800)
committerMarc Zyngier <maz@kernel.org>
Tue, 28 Dec 2021 19:23:23 +0000 (19:23 +0000)
Add an architecture independent wrapper function for the KVM_IRQ_LINE
ioctl.

Signed-off-by: Ricardo Koller <ricarkol@google.com>
Acked-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20211109023906.1091208-5-ricarkol@google.com
tools/testing/selftests/kvm/include/kvm_util.h
tools/testing/selftests/kvm/lib/kvm_util.c

index 6a1a37f30494b327e36c8b54ec9ddd8a6d0996bc..4ba8fd44cf9539d54dba9b8a9427428382299ee4 100644 (file)
@@ -240,6 +240,8 @@ int _kvm_device_access(int dev_fd, uint32_t group, uint64_t attr,
                       void *val, bool write);
 int kvm_device_access(int dev_fd, uint32_t group, uint64_t attr,
                      void *val, bool write);
+void kvm_irq_line(struct kvm_vm *vm, uint32_t irq, int level);
+int _kvm_irq_line(struct kvm_vm *vm, uint32_t irq, int level);
 
 int _vcpu_has_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group,
                          uint64_t attr);
index 8f2e0bb1ef96a4f2103fc89c94a13bde34f09f4a..9f7210c2d75e65710d1c6f16026ef214b7ec9b32 100644 (file)
@@ -2086,6 +2086,27 @@ int vcpu_access_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group,
        return ret;
 }
 
+/*
+ * IRQ related functions.
+ */
+
+int _kvm_irq_line(struct kvm_vm *vm, uint32_t irq, int level)
+{
+       struct kvm_irq_level irq_level = {
+               .irq    = irq,
+               .level  = level,
+       };
+
+       return _vm_ioctl(vm, KVM_IRQ_LINE, &irq_level);
+}
+
+void kvm_irq_line(struct kvm_vm *vm, uint32_t irq, int level)
+{
+       int ret = _kvm_irq_line(vm, irq, level);
+
+       TEST_ASSERT(ret >= 0, "KVM_IRQ_LINE failed, rc: %i errno: %i", ret, errno);
+}
+
 /*
  * VM Dump
  *