From patchwork Thu May 14 17:02:03 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Haskins X-Patchwork-Id: 23797 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n4EH2OcV013978 for ; Thu, 14 May 2009 17:02:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759755AbZENRCT (ORCPT ); Thu, 14 May 2009 13:02:19 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755546AbZENRCT (ORCPT ); Thu, 14 May 2009 13:02:19 -0400 Received: from victor.provo.novell.com ([137.65.250.26]:44560 "EHLO victor.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758531AbZENRCS (ORCPT ); Thu, 14 May 2009 13:02:18 -0400 Received: from dev.haskins.net (prv-ext-foundry1.gns.novell.com [137.65.251.240]) by victor.provo.novell.com with ESMTP (TLS encrypted); Thu, 14 May 2009 11:02:06 -0600 Received: from dev.haskins.net (localhost [127.0.0.1]) by dev.haskins.net (Postfix) with ESMTP id 3169846422B; Thu, 14 May 2009 13:02:03 -0400 (EDT) From: Gregory Haskins Subject: [PATCH v8] qemu-kvm: add irqfd support To: kvm@vger.kernel.org Cc: avi@redhat.com Date: Thu, 14 May 2009 13:02:03 -0400 Message-ID: <20090514170203.11431.54258.stgit@dev.haskins.net> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org irqfd lets you create an eventfd based file-desriptor to inject interrupts to a kvm guest. We associate one gsi per fd for fine-grained routing. Signed-off-by: Gregory Haskins --- kvm/libkvm/libkvm.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ kvm/libkvm/libkvm.h | 26 +++++++++++++++++++++++ 2 files changed, 83 insertions(+), 0 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/kvm/libkvm/libkvm.c b/kvm/libkvm/libkvm.c index ba0a5d1..ccab985 100644 --- a/kvm/libkvm/libkvm.c +++ b/kvm/libkvm/libkvm.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include "libkvm.h" @@ -1444,3 +1445,59 @@ int kvm_assign_set_msix_entry(kvm_context_t kvm, return ret; } #endif + +#ifdef KVM_CAP_IRQFD +static int _kvm_irqfd(kvm_context_t kvm, int fd, int gsi, int flags) +{ + int r; + struct kvm_irqfd data = { + .fd = fd, + .gsi = gsi, + .flags = flags, + }; + + r = ioctl(kvm->vm_fd, KVM_IRQFD, &data); + if (r == -1) + r = -errno; + return r; +} + +int kvm_create_irqfd(kvm_context_t kvm, int gsi, int flags) +{ + int r; + int fd; + + if (!kvm_check_extension(kvm, KVM_CAP_IRQFD)) + return -ENOENT; + + fd = eventfd(0, 0); + if (fd < 0) + return -errno; + + r = _kvm_irqfd(kvm, fd, gsi, 0); + if (r < 0) { + close(fd); + return -errno; + } + + return fd; +} + +int kvm_destroy_irqfd(kvm_context_t kvm, int fd, int gsi, int flags) +{ + return _kvm_irqfd(kvm, fd, gsi, KVM_IRQFD_FLAG_DEASSIGN); +} + +#else /* KVM_CAP_IRQFD */ + +int kvm_create_irqfd(kvm_context_t kvm, int gsi, int flags) +{ + return -ENOENT; +} + +int kvm_destroy_irqfd(kvm_context_t kvm, int fd, int gsi, int flags) +{ + return -ENOENT; +} + +#endif /* KVM_CAP_IRQFD */ diff --git a/kvm/libkvm/libkvm.h b/kvm/libkvm/libkvm.h index 4821a1e..3ccbe3d 100644 --- a/kvm/libkvm/libkvm.h +++ b/kvm/libkvm/libkvm.h @@ -856,6 +856,32 @@ 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 + * \param flags reserved, must be zero + */ +int kvm_create_irqfd(kvm_context_t kvm, int gsi, int flags); + +/*! + * \brief Destroy an irqfd file descriptor + * + * Destroys a file descriptor previously opened with kvm_create_irqfd() + * + * \param kvm Pointer to the current kvm_context + * \param fd fd to close + * \param gsi GSI to close + * \param flags reserved, must be zero + */ +int kvm_destroy_irqfd(kvm_context_t kvm, int fd, int gsi, int flags); + #ifdef KVM_CAP_DEVICE_MSIX int kvm_assign_set_msix_nr(kvm_context_t kvm, struct kvm_assigned_msix_nr *msix_nr);