From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gregory Haskins Subject: [PATCH] qemu-kvm: add irqfd support Date: Thu, 23 Apr 2009 11:21:32 -0400 Message-ID: <20090423151901.14204.72341.stgit@dev.haskins.net> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: avi@redhat.com To: kvm@vger.kernel.org Return-path: Received: from victor.provo.novell.com ([137.65.250.26]:46005 "EHLO victor.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751749AbZDWPVq (ORCPT ); Thu, 23 Apr 2009 11:21:46 -0400 Sender: kvm-owner@vger.kernel.org List-ID: (applies to kvm-userspace.git 84474e4f39) This adds userspace support for the irqfd mechanism in the kernel, published here: http://lkml.org/lkml/2009/4/23/328 There are no current users, though the future virtual-bus v4 has plans to adopt it. Signed-off-by: Gregory Haskins --- libkvm/libkvm.c | 29 +++++++++++++++++++++++++++++ libkvm/libkvm.h | 13 +++++++++++++ 2 files changed, 42 insertions(+), 0 deletions(-) diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c index 0610e3f..9aa8215 100644 --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "libkvm.h" #if defined(__x86_64__) || defined(__i386__) @@ -1440,3 +1441,31 @@ int kvm_assign_set_msix_entry(kvm_context_t kvm, return ret; } #endif + +static int assign_irqfd(kvm_context_t kvm, int fd, int gsi) +{ + int r; + struct kvm_irqfd data = { + .fd = fd, + .gsi = gsi, + }; + + r = ioctl(kvm->vm_fd, KVM_ASSIGN_IRQFD, &data); + if (r == -1) + r = -errno; + return r; +} + +int kvm_irqfd(kvm_context_t kvm, int gsi) +{ + int fd; + + if (!kvm_check_extension(kvm, KVM_CAP_IRQFD)) + return -ENOENT; + + fd = eventfd(0, 0); + if (fd < 0) + return fd; + + return assign_irqfd(kvm, fd, gsi); +} diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h index ce6f054..404c028 100644 --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -856,6 +856,19 @@ int kvm_commit_irq_routes(kvm_context_t kvm); */ int kvm_get_irq_route_gsi(kvm_context_t kvm); +/*! + * \brief Create a file descriptor for injecting interrupts + * + * Creates an eventfd based file-descriptor that maps to a specific GSI + * in the guest. eventfd compliant signaling (write() from userspace, or + * eventfd_signal() from kernelspace) will cause the GSI to inject + * itself into the guest at the next available window. + * + * \param kvm Pointer to the current kvm_context + * \param gsi GSI to assign to this fd + */ +int kvm_irqfd(kvm_context_t kvm, int gsi); + #ifdef KVM_CAP_DEVICE_MSIX int kvm_assign_set_msix_nr(kvm_context_t kvm, struct kvm_assigned_msix_nr *msix_nr);