public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Gregory Haskins <ghaskins@novell.com>
To: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, mst@redhat.com, avi@redhat.com,
	paulmck@linux.vnet.ibm.com, davidel@xmailserver.org,
	rusty@rustcorp.com.au
Subject: [KVM PATCH v5 4/4] KVM: add irqfd DEASSIGN feature
Date: Thu, 25 Jun 2009 09:28:32 -0400	[thread overview]
Message-ID: <20090625132832.26748.35406.stgit@dev.haskins.net> (raw)
In-Reply-To: <20090625132441.26748.641.stgit@dev.haskins.net>

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 <ghaskins@novell.com>
CC: Michael S. Tsirkin <mst@redhat.com>
---

 include/linux/kvm.h |    2 ++
 virt/kvm/eventfd.c  |   56 +++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 56 insertions(+), 2 deletions(-)

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 ca21e8a..2d4549c 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -180,8 +180,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;
@@ -303,6 +303,58 @@ irqfd_shutdown(struct _irqfd *irqfd)
 	irqfd_release(irqfd);
 }
 
+/*
+ * assumes kvm->irqfds.lock is held
+ */
+static struct _irqfd *
+irqfd_find(struct kvm *kvm, int fd, int gsi)
+{
+	struct _irqfd *irqfd, *tmp, *ret = ERR_PTR(-ENOENT);
+	struct eventfd_ctx *eventfd;
+
+	eventfd = eventfd_ctx_fdget(fd);
+	if (IS_ERR(eventfd))
+		return ERR_PTR(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);
+			ret = irqfd;
+			break;
+		}
+	}
+
+	spin_unlock_irq(&kvm->irqfds.lock);
+	eventfd_ctx_put(eventfd);
+
+	return ret;
+}
+
+static int
+kvm_irqfd_deassign(struct kvm *kvm, int fd, int gsi)
+{
+	struct _irqfd *irqfd;
+
+	irqfd = irqfd_find(kvm, fd, gsi);
+	if (IS_ERR(irqfd))
+		return PTR_ERR(irqfd);
+
+	irqfd_shutdown(irqfd);
+
+	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);
+}
+
 void
 kvm_irqfd_release(struct kvm *kvm)
 {


  parent reply	other threads:[~2009-06-25 13:29 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-25 13:28 [KVM PATCH v5 0/4] irqfd fixes and enhancements Gregory Haskins
2009-06-25 13:28 ` [KVM PATCH v5 1/4] kvm: prepare irqfd for having interrupts disabled during eventfd->release Gregory Haskins
2009-06-25 13:28 ` [KVM PATCH v5 2/4] eventfd - revised interface and cleanups (4th rev) Gregory Haskins
2009-06-25 13:28 ` [KVM PATCH v5 3/4] KVM: Fix races in irqfd using new eventfd_kref_get interface Gregory Haskins
2009-06-26 14:05   ` Gregory Haskins
2009-06-28 11:06   ` Michael S. Tsirkin
2009-06-28 12:50     ` Gregory Haskins
2009-06-28 13:18       ` Michael S. Tsirkin
2009-06-28 13:25         ` Avi Kivity
2009-06-25 13:28 ` Gregory Haskins [this message]
2009-06-28 10:46   ` [KVM PATCH v5 4/4] KVM: add irqfd DEASSIGN feature Michael S. Tsirkin
2009-06-28 12:39     ` Gregory Haskins
2009-06-25 13:59 ` [KVM PATCH v5 0/4] irqfd fixes and enhancements Gregory Haskins
2009-06-25 16:44   ` Davide Libenzi
2009-06-28 11:03   ` Avi Kivity
2009-06-28 12:59     ` Gregory Haskins
2009-06-28 13:40       ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090625132832.26748.35406.stgit@dev.haskins.net \
    --to=ghaskins@novell.com \
    --cc=avi@redhat.com \
    --cc=davidel@xmailserver.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=rusty@rustcorp.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox