From patchwork Wed Jun 3 20:30:32 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Haskins X-Patchwork-Id: 27734 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 n53KUdLO007780 for ; Wed, 3 Jun 2009 20:30:39 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752791AbZFCUae (ORCPT ); Wed, 3 Jun 2009 16:30:34 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751826AbZFCUae (ORCPT ); Wed, 3 Jun 2009 16:30:34 -0400 Received: from victor.provo.novell.com ([137.65.250.26]:38664 "EHLO victor.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751409AbZFCUad (ORCPT ); Wed, 3 Jun 2009 16:30:33 -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); Wed, 03 Jun 2009 14:30:33 -0600 Received: from dev.haskins.net (localhost [127.0.0.1]) by dev.haskins.net (Postfix) with ESMTP id 1598A464244; Wed, 3 Jun 2009 16:30:32 -0400 (EDT) From: Gregory Haskins Subject: [PATCH v3] qemu-kvm: add iosignalfd support To: kvm@vger.kernel.org Cc: avi@redhat.com Date: Wed, 03 Jun 2009 16:30:32 -0400 Message-ID: <20090603202850.8685.97794.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 An iosignalfd allows an eventfd to attach to a specific PIO/MMIO region in the guest. Any guest-writes to that region will trigger an eventfd signal. [ This userspace patch coorelates to the kvm.git patches, v5, which you can find here: http://lkml.org/lkml/2009/6/3/433, and are based on top of the irqfd userspace patches which have not yet been accepted upstream. ] Signed-off-by: Gregory Haskins --- kvm/libkvm/libkvm.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ kvm/libkvm/libkvm.h | 42 ++++++++++++++++++++++++++++++++ 2 files changed, 110 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 0ada15c..cb558fc 100644 --- a/kvm/libkvm/libkvm.c +++ b/kvm/libkvm/libkvm.c @@ -1493,3 +1493,71 @@ int kvm_irqfd(kvm_context_t kvm, int gsi, int flags) } #endif /* KVM_CAP_IRQFD */ + +#ifdef KVM_CAP_IOSIGNALFD + +#include + +int kvm_assign_iosignalfd(kvm_context_t kvm, unsigned long addr, size_t len, + int fd, void *trigger, int flags) +{ + int r; + int type = flags & IOSIGNALFD_FLAG_PIO; + struct kvm_iosignalfd data = { + .trigger = (__u64)trigger, + .addr = addr, + .len = len, + .fd = fd, + }; + + data.flags |= trigger ? KVM_IOSIGNALFD_FLAG_TRIGGER : 0; + data.flags |= type ? KVM_IOSIGNALFD_FLAG_PIO : 0; + + if (!kvm_check_extension(kvm, KVM_CAP_IOSIGNALFD)) + return -ENOENT; + + r = ioctl(kvm->vm_fd, KVM_IOSIGNALFD, &data); + if (r == -1) + r = -errno; + return r; +} + +int kvm_deassign_iosignalfd(kvm_context_t kvm, unsigned long addr, int fd, + int flags) +{ + int r; + int type = flags & IOSIGNALFD_FLAG_PIO; + struct kvm_iosignalfd data = { + .addr = addr, + .fd = fd, + .flags = KVM_IOSIGNALFD_FLAG_DEASSIGN | + (type ? KVM_IOSIGNALFD_FLAG_PIO : 0), + }; + + if (!kvm_check_extension(kvm, KVM_CAP_IOSIGNALFD)) + return -ENOENT; + + r = ioctl(kvm->vm_fd, KVM_IOSIGNALFD, &data); + if (r == -1) + r = -errno; + return r; +} + +#else /* KVM_CAP_IOSIGNALFD */ + +int kvm_assign_iosignalfd(kvm_context_t kvm, unsigned long addr, size_t len, + int fd, void *trigger, int flags) +{ + return -ENOSYS; +} + +int kvm_deassign_iosignalfd(kvm_context_t kvm, unsigned long addr, int fd, + int flags) +{ + return -ENOSYS; +} + +#endif /* KVM_CAP_IOSIGNALFD */ + + + diff --git a/kvm/libkvm/libkvm.h b/kvm/libkvm/libkvm.h index aca8ed6..65fbe2a 100644 --- a/kvm/libkvm/libkvm.h +++ b/kvm/libkvm/libkvm.h @@ -870,6 +870,48 @@ int kvm_get_irq_route_gsi(kvm_context_t kvm); */ int kvm_irqfd(kvm_context_t kvm, int gsi, int flags); +enum { + iosignalfd_option_pio, +}; + +#define IOSIGNALFD_FLAG_PIO (1 << iosignalfd_option_pio) + +/*! + * \brief Assign an eventfd to an IO port (PIO or MMIO) + * + * Assigns an eventfd based file-descriptor to a specific PIO or MMIO + * address range. Any guest writes to the specified range will generate + * an eventfd signal. + * + * A data-match pointer can be optionally provided in "trigger" and only + * writes which match this value exactly will generate an event. The length + * of the trigger is established by the length of the overall IO range, and + * therefore must be in a natural byte-width for the IO routines of your + * particular architecture (e.g. 1, 2, 4, or 8 bytes on x86_64). + * + * \param kvm Pointer to the current kvm_context + * \param addr The IO address + * \param len The length of the IO region at the address + * \param fd The eventfd file-descriptor + * \param trigger A optional pointer providing data-match token + * \param flags FLAG_PIO: PIO, else MMIO + */ +int kvm_assign_iosignalfd(kvm_context_t kvm, unsigned long addr, size_t len, + int fd, void *trigger, int flags); + +/*! + * \brief Deassign an iosignalfd from a previously registered IO port + * + * Deassigns an iosignalfd previously registered with kvm_assign_iosignalfd() + * + * \param kvm Pointer to the current kvm_context + * \param addr The IO address to deassign + * \param fd The eventfd file-descriptor + * \param flags FLAG_PIO: PIO, else MMIO + */ +int kvm_deassign_iosignalfd(kvm_context_t kvm, unsigned long addr, + int fd, int flags); + #ifdef KVM_CAP_DEVICE_MSIX int kvm_assign_set_msix_nr(kvm_context_t kvm, struct kvm_assigned_msix_nr *msix_nr);