From patchwork Mon Jun 29 18:29:20 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Haskins X-Patchwork-Id: 33012 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 n5TIV1dS021482 for ; Mon, 29 Jun 2009 18:31:02 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757899AbZF2S3e (ORCPT ); Mon, 29 Jun 2009 14:29:34 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758111AbZF2S3e (ORCPT ); Mon, 29 Jun 2009 14:29:34 -0400 Received: from victor.provo.novell.com ([137.65.250.26]:35038 "EHLO victor.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758221AbZF2S3b (ORCPT ); Mon, 29 Jun 2009 14:29:31 -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); Mon, 29 Jun 2009 12:29:22 -0600 Received: from dev.haskins.net (localhost [127.0.0.1]) by dev.haskins.net (Postfix) with ESMTP id 7ECAE464229; Mon, 29 Jun 2009 14:29:20 -0400 (EDT) From: Gregory Haskins Subject: [KVM PATCH v7 4/5] KVM: add irqfd DEASSIGN feature To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, mst@redhat.com, avi@redhat.com, davidel@xmailserver.org Date: Mon, 29 Jun 2009 14:29:20 -0400 Message-ID: <20090629182920.1886.22941.stgit@dev.haskins.net> In-Reply-To: <20090629181954.1886.20225.stgit@dev.haskins.net> References: <20090629181954.1886.20225.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 DEASSIGN allows us to optionally disassociate an IRQFD from its underlying eventfd without destroying the eventfd in the process. This is useful for conditions like live-migration which may have an eventfd associated with a device and an IRQFD. We need to be able to decouple the guest from the event source while not perturbing the event source itself. Signed-off-by: Gregory Haskins CC: Michael S. Tsirkin --- include/linux/kvm.h | 2 ++ virt/kvm/eventfd.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 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/include/linux/kvm.h b/include/linux/kvm.h index 38ff31e..6710518 100644 --- a/include/linux/kvm.h +++ b/include/linux/kvm.h @@ -490,6 +490,8 @@ struct kvm_x86_mce { }; #endif +#define KVM_IRQFD_FLAG_DEASSIGN (1 << 0) + struct kvm_irqfd { __u32 fd; __u32 gsi; diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c index cb29a85..c1ade4f 100644 --- a/virt/kvm/eventfd.c +++ b/virt/kvm/eventfd.c @@ -151,8 +151,8 @@ irqfd_ptable_queue_proc(struct file *file, wait_queue_head_t *wqh, add_wait_queue(wqh, &irqfd->wait); } -int -kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags) +static int +kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi) { struct _irqfd *irqfd; struct file *file = NULL; @@ -232,6 +232,48 @@ kvm_irqfd_init(struct kvm *kvm) } /* + * shutdown any irqfd's that match fd+gsi + */ +static int +kvm_irqfd_deassign(struct kvm *kvm, int fd, int gsi) +{ + struct _irqfd *irqfd, *tmp; + struct eventfd_ctx *eventfd; + + eventfd = eventfd_ctx_fdget(fd); + if (IS_ERR(eventfd)) + return PTR_ERR(eventfd); + + spin_lock_irq(&kvm->irqfds.lock); + + list_for_each_entry_safe(irqfd, tmp, &kvm->irqfds.items, list) { + if (irqfd->eventfd == eventfd && irqfd->gsi == gsi) + irqfd_deactivate(irqfd); + } + + spin_unlock_irq(&kvm->irqfds.lock); + eventfd_ctx_put(eventfd); + + /* + * Block until we know all outstanding shutdown jobs have completed + * so that we guarantee there will not be any more interrupts on this + * gsi once this deassign function returns. + */ + flush_workqueue(irqfd_cleanup_wq); + + return 0; +} + +int +kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags) +{ + if (flags & KVM_IRQFD_FLAG_DEASSIGN) + return kvm_irqfd_deassign(kvm, fd, gsi); + + return kvm_irqfd_assign(kvm, fd, gsi); +} + +/* * This function is called as the kvm VM fd is being released. Shutdown all * irqfds that still remain open */