kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: avi@redhat.com, mst@redhat.com
Cc: gleb@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v8 6/6] kvm: Add de-assert option to KVM_IRQ_ACKFD
Date: Fri, 10 Aug 2012 16:37:56 -0600	[thread overview]
Message-ID: <20120810223754.809.60610.stgit@bling.home> (raw)
In-Reply-To: <20120810223633.809.44188.stgit@bling.home>

It's likely (vfio) that one of the reasons to watch for an IRQ ACK
is to de-assert and re-enable an interrupt.  As the IRQ ACK notfier
is already watching a GSI for an IRQ source ID we can easily couple
these together.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---

 Documentation/virtual/kvm/api.txt |    4 ++++
 arch/x86/kvm/x86.c                |    1 +
 include/linux/kvm.h               |    3 +++
 virt/kvm/eventfd.c                |   14 +++++++++++++-
 4 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index 77b4837..128d4c3 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -2029,6 +2029,10 @@ the eventfd is only triggered when the specified IRQ source ID is
 pending.  On deassign, fd, gsi, and irq_source_id (if provided on assign)
 must be provided.
 
+When KVM_CAP_IRQ_ACKFD_DEASSERT is available the flag
+KVM_IRQ_ACKFD_FLAG_IRQ_DEASSERT may be used on assignment to specify
+that the GSI should be de-asserted prior to eventfd notification.
+This flag requires an IRQ source ID to be provided as described above.
 
 5. The kvm_run structure
 ------------------------
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 3d98e59..691b00d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2178,6 +2178,7 @@ int kvm_dev_ioctl_check_extension(long ext)
 	case KVM_CAP_IRQFD_ASSERT_ONLY:
 	case KVM_CAP_IRQ_ACKFD:
 	case KVM_CAP_IRQ_ACKFD_IRQ_SOURCE_ID:
+	case KVM_CAP_IRQ_ACKFD_DEASSERT:
 		r = 1;
 		break;
 	case KVM_CAP_COALESCED_MMIO:
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 0f53bd5..331631e 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -623,6 +623,7 @@ struct kvm_ppc_smmu_info {
 #define KVM_CAP_IRQFD_ASSERT_ONLY 83
 #define KVM_CAP_IRQ_ACKFD 84
 #define KVM_CAP_IRQ_ACKFD_IRQ_SOURCE_ID 85
+#define KVM_CAP_IRQ_ACKFD_DEASSERT 86
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -712,6 +713,8 @@ struct kvm_irq_source_id {
 #define KVM_IRQ_ACKFD_FLAG_DEASSIGN (1 << 0)
 /* Available with KVM_CAP_IRQ_ACKFD_IRQ_SOURCE_ID */
 #define KVM_IRQ_ACKFD_FLAG_IRQ_SOURCE_ID (1 << 1)
+/* Available with KVM_CAP_IRQ_ACKFD_DEASSERT */
+#define KVM_IRQ_ACKFD_FLAG_DEASSERT (1 << 2)
 
 struct kvm_irq_ackfd {
 	__u32 flags;
diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index ff5c784..ffc6a13 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -682,6 +682,7 @@ kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
 
 struct _irq_ackfd {
 	struct kvm *kvm;
+	bool deassert; /* de-assert on ack? */
 	struct eventfd_ctx *eventfd; /* signaled on ack */
 	struct kvm_irq_ack_notifier notifier;
 	/* Setup/shutdown */
@@ -805,6 +806,10 @@ static void irq_ackfd_acked(struct kvm_irq_ack_notifier *notifier)
 
 	ackfd = container_of(notifier, struct _irq_ackfd, notifier);
 
+	if (ackfd->deassert)
+		kvm_set_irq(ackfd->kvm, ackfd->notifier.irq_source_id,
+			    ackfd->notifier.gsi, 0);
+
 	eventfd_signal(ackfd->eventfd, 1);
 }
 
@@ -845,6 +850,12 @@ static int kvm_assign_irq_ackfd(struct kvm *kvm, struct kvm_irq_ackfd *args)
 		ackfd->notifier.irq_source_id = -1;
 	ackfd->notifier.irq_acked = irq_ackfd_acked;
 
+	ackfd->deassert = args->flags & KVM_IRQ_ACKFD_FLAG_DEASSERT;
+	if (ackfd->deassert && ackfd->notifier.irq_source_id < 0) {
+		ret = -EINVAL;
+		goto fail;
+	}
+
 	/*
 	 * Install our own custom wake-up handling so we are notified via
 	 * a callback whenever someone releases the underlying eventfd
@@ -945,7 +956,8 @@ fail:
 int kvm_irq_ackfd(struct kvm *kvm, struct kvm_irq_ackfd *args)
 {
 	if (args->flags & ~(KVM_IRQ_ACKFD_FLAG_DEASSIGN |
-			    KVM_IRQ_ACKFD_FLAG_IRQ_SOURCE_ID))
+			    KVM_IRQ_ACKFD_FLAG_IRQ_SOURCE_ID |
+			    KVM_IRQ_ACKFD_FLAG_DEASSERT))
 		return -EINVAL;
 
 	if (args->flags & KVM_IRQ_ACKFD_FLAG_DEASSIGN)


  parent reply	other threads:[~2012-08-10 22:37 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-10 22:37 [PATCH v8 0/6] kvm: level irqfd support Alex Williamson
2012-08-10 22:37 ` [PATCH v8 1/6] kvm: Allow filtering of acked irqs Alex Williamson
2012-08-15 12:27   ` Michael S. Tsirkin
2012-08-15 16:47     ` Alex Williamson
2012-08-15 19:24       ` Michael S. Tsirkin
2012-08-10 22:37 ` [PATCH v8 2/6] kvm: Expose IRQ source IDs to userspace Alex Williamson
2012-08-15 12:59   ` Michael S. Tsirkin
2012-08-15 17:05     ` Alex Williamson
2012-08-10 22:37 ` [PATCH v8 3/6] kvm: Add IRQ source ID option to KVM_IRQFD Alex Williamson
2012-08-15 13:49   ` Michael S. Tsirkin
2012-08-15 17:08     ` Alex Williamson
2012-08-10 22:37 ` [PATCH v8 4/6] kvm: Add assert-only " Alex Williamson
2012-08-10 22:37 ` [PATCH v8 5/6] kvm: KVM_IRQ_ACKFD Alex Williamson
2012-08-15 14:05   ` Michael S. Tsirkin
2012-08-15 17:17     ` Alex Williamson
2012-08-10 22:37 ` Alex Williamson [this message]
2012-08-15 14:11   ` [PATCH v8 6/6] kvm: Add de-assert option to KVM_IRQ_ACKFD Michael S. Tsirkin
2012-08-15 17:24     ` Alex Williamson
2012-08-15 14:28 ` [PATCH v8 0/6] kvm: level irqfd support Michael S. Tsirkin
2012-08-15 17:36   ` Alex Williamson
2012-08-15 19:22     ` Michael S. Tsirkin
2012-08-15 19:59       ` Alex Williamson
2012-08-16 12:34         ` Alex Williamson
2012-08-16 12:53           ` Michael S. Tsirkin
2012-08-16 16:29       ` Avi Kivity
2012-08-16 16:36         ` Michael S. Tsirkin
2012-08-16 16:39           ` Avi Kivity
2012-08-16 16:54             ` Michael S. Tsirkin
2012-08-16 16:54               ` Avi Kivity
2012-08-16 17:01                 ` Michael S. Tsirkin
2012-08-16 16:37         ` Alex Williamson
2012-08-16 16:32 ` Avi Kivity
2012-08-16 16:45   ` Alex Williamson

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=20120810223754.809.60610.stgit@bling.home \
    --to=alex.williamson@redhat.com \
    --cc=avi@redhat.com \
    --cc=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).