This allows us to register an eventfd to be triggered on EOI for the given IRQ. Signed-off-by: Alex Williamson <alex.williamson@xxxxxxxxxx> --- Userspace side of: [PATCH] kvm: Create an eventfd mechanism for EOIs to get to userspace kvm-all.c | 19 +++++++++++++++++++ kvm.h | 10 ++++++++++ kvm/include/linux/kvm.h | 13 +++++++++++++ 3 files changed, 42 insertions(+), 0 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 0e60748..75dbe76 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1349,5 +1349,24 @@ int kvm_set_irqfd(int gsi, int fd, bool assigned) } #endif +#if defined(KVM_EOI_EVENTFD) +int kvm_eoi_eventfd(int gsi, int fd, uint32_t flags) +{ + struct kvm_eoi eoi = { + .fd = fd, + .gsi = gsi, + .flags = flags, + }; + int r; + + if (!kvm_enabled() || !kvm_irqchip_in_kernel()) + return -ENOSYS; + + r = kvm_vm_ioctl(kvm_state, KVM_EOI_EVENTFD, &eoi); + if (r < 0) + return r; + return 0; +} +#endif #undef PAGE_SIZE #include "qemu-kvm.c" diff --git a/kvm.h b/kvm.h index 02280a6..777904a 100644 --- a/kvm.h +++ b/kvm.h @@ -203,6 +203,16 @@ int kvm_set_irqfd(int gsi, int fd, bool assigned) } #endif +#if defined(KVM_EOI_EVENTFD) && defined(CONFIG_KVM) +int kvm_eoi_eventfd(int gsi, int fd, uint32_t flags); +#else +static inline +int kvm_eoi_eventfd(int gsi, int fd, uint32_t flags) +{ + return -ENOSYS; +} +#endif + int kvm_set_ioeventfd_pio_word(int fd, uint16_t adr, uint16_t val, bool assign); int kvm_has_gsi_routing(void); diff --git a/kvm/include/linux/kvm.h b/kvm/include/linux/kvm.h index e46729e..5490f62 100644 --- a/kvm/include/linux/kvm.h +++ b/kvm/include/linux/kvm.h @@ -530,6 +530,7 @@ struct kvm_enable_cap { #ifdef __KVM_HAVE_XCRS #define KVM_CAP_XCRS 56 #endif +#define KVM_CAP_EOI_EVENTFD 60 #ifdef KVM_CAP_IRQ_ROUTING @@ -609,6 +610,16 @@ struct kvm_clock_data { __u32 pad[9]; }; +#define KVM_EOI_EVENTFD_FLAG_DEASSIGN (1 << 0) +#define KVM_EOI_EVENTFD_FLAG_DEASSERT (1 << 1) + +struct kvm_eoi { + __u32 fd; + __u32 gsi; + __u32 flags; + __u8 pad[20]; +}; + /* * ioctls for VM fds */ @@ -663,6 +674,8 @@ struct kvm_clock_data { /* Available with KVM_CAP_PIT_STATE2 */ #define KVM_GET_PIT2 _IOR(KVMIO, 0x9f, struct kvm_pit_state2) #define KVM_SET_PIT2 _IOW(KVMIO, 0xa0, struct kvm_pit_state2) +/* Available with KVM_CAP_EOI_EVENTFD */ +#define KVM_EOI_EVENTFD _IOW(KVMIO, 0xa2, struct kvm_eoi) /* * ioctls for vcpu fds -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html