mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yunhong Jiang <yunhong.jiang@linux.intel.com>
To: alex.williamson@redhat.com, pbonzini@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/5] KVM: Extract the irqfd_wakeup_pollin/irqfd_wakeup_pollup
Date: Thu,  3 Dec 2015 10:22:48 -0800	[thread overview]
Message-ID: <1449166972-8894-2-git-send-email-yunhong.jiang@linux.intel.com> (raw)
In-Reply-To: <1449166972-8894-1-git-send-email-yunhong.jiang@linux.intel.com>

Separate the irqfd_wakeup_pollin/irqfd_wakeup_pollup from the
irqfd_wakeup, so that we can reuse the logic for MSI fastpath injection.

Signed-off-by: Yunhong Jiang <yunhong.jiang@linux.intel.com>
---
 virt/kvm/eventfd.c | 86 ++++++++++++++++++++++++++++++++----------------------
 1 file changed, 51 insertions(+), 35 deletions(-)

diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index 46dbc0a7dfc1..c31d43b762db 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -180,6 +180,53 @@ int __attribute__((weak)) kvm_arch_set_irq_inatomic(
 	return -EWOULDBLOCK;
 }
 
+static int
+irqfd_wakeup_pollin(struct kvm_kernel_irqfd *irqfd)
+{
+	struct kvm *kvm = irqfd->kvm;
+	struct kvm_kernel_irq_routing_entry irq;
+	unsigned seq;
+	int idx, ret;
+
+	idx = srcu_read_lock(&kvm->irq_srcu);
+	do {
+		seq = read_seqcount_begin(&irqfd->irq_entry_sc);
+		irq = irqfd->irq_entry;
+	} while (read_seqcount_retry(&irqfd->irq_entry_sc, seq));
+	/* An event has been signaled, inject an interrupt */
+	ret = kvm_arch_set_irq_inatomic(&irq, kvm,
+				KVM_USERSPACE_IRQ_SOURCE_ID, 1,
+				false);
+	srcu_read_unlock(&kvm->irq_srcu, idx);
+
+	return ret;
+}
+
+static int
+irqfd_wakeup_pollup(struct kvm_kernel_irqfd *irqfd)
+{
+	struct kvm *kvm = irqfd->kvm;
+	unsigned long flags;
+
+	spin_lock_irqsave(&kvm->irqfds.lock, flags);
+
+	/*
+	 * We must check if someone deactivated the irqfd before
+	 * we could acquire the irqfds.lock since the item is
+	 * deactivated from the KVM side before it is unhooked from
+	 * the wait-queue.  If it is already deactivated, we can
+	 * simply return knowing the other side will cleanup for us.
+	 * We cannot race against the irqfd going away since the
+	 * other side is required to acquire wqh->lock, which we hold
+	 */
+	if (irqfd_is_active(irqfd))
+		irqfd_deactivate(irqfd);
+
+	spin_unlock_irqrestore(&kvm->irqfds.lock, flags);
+
+	return 0;
+}
+
 /*
  * Called with wqh->lock held and interrupts disabled
  */
@@ -189,45 +236,14 @@ irqfd_wakeup(wait_queue_t *wait, unsigned mode, int sync, void *key)
 	struct kvm_kernel_irqfd *irqfd =
 		container_of(wait, struct kvm_kernel_irqfd, wait);
 	unsigned long flags = (unsigned long)key;
-	struct kvm_kernel_irq_routing_entry irq;
-	struct kvm *kvm = irqfd->kvm;
-	unsigned seq;
-	int idx;
 
-	if (flags & POLLIN) {
-		idx = srcu_read_lock(&kvm->irq_srcu);
-		do {
-			seq = read_seqcount_begin(&irqfd->irq_entry_sc);
-			irq = irqfd->irq_entry;
-		} while (read_seqcount_retry(&irqfd->irq_entry_sc, seq));
-		/* An event has been signaled, inject an interrupt */
-		if (kvm_arch_set_irq_inatomic(&irq, kvm,
-					      KVM_USERSPACE_IRQ_SOURCE_ID, 1,
-					      false) == -EWOULDBLOCK)
+	if (flags & POLLIN)
+		if (irqfd_wakeup_pollin(irqfd) == -EWOULDBLOCK)
 			schedule_work(&irqfd->inject);
-		srcu_read_unlock(&kvm->irq_srcu, idx);
-	}
 
-	if (flags & POLLHUP) {
+	if (flags & POLLHUP)
 		/* The eventfd is closing, detach from KVM */
-		unsigned long flags;
-
-		spin_lock_irqsave(&kvm->irqfds.lock, flags);
-
-		/*
-		 * We must check if someone deactivated the irqfd before
-		 * we could acquire the irqfds.lock since the item is
-		 * deactivated from the KVM side before it is unhooked from
-		 * the wait-queue.  If it is already deactivated, we can
-		 * simply return knowing the other side will cleanup for us.
-		 * We cannot race against the irqfd going away since the
-		 * other side is required to acquire wqh->lock, which we hold
-		 */
-		if (irqfd_is_active(irqfd))
-			irqfd_deactivate(irqfd);
-
-		spin_unlock_irqrestore(&kvm->irqfds.lock, flags);
-	}
+		irqfd_wakeup_pollup(irqfd);
 
 	return 0;
 }
-- 
1.8.3.1


  reply	other threads:[~2015-12-03 18:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-03 18:22 [PATCH 0/5] Threaded MSI interrupt for VFIO PCI device Yunhong Jiang
2015-12-03 18:22 ` Yunhong Jiang [this message]
2015-12-03 18:22 ` [PATCH 2/5] VIRT: Support runtime irq_bypass consumer Yunhong Jiang
2015-12-16 19:48   ` Alex Williamson
2015-12-03 18:22 ` [PATCH 3/5] VFIO: Support threaded interrupt handling on VFIO Yunhong Jiang
2015-12-16 19:49   ` Alex Williamson
2015-12-03 18:22 ` [PATCH 4/5] KVM: Add the irq handling consumer Yunhong Jiang
2015-12-04  0:33   ` kbuild test robot
2015-12-03 18:22 ` [PATCH 5/5] KVM: Expose x86 kvm_arch_set_irq_inatomic() Yunhong Jiang
2015-12-03 18:55 ` [PATCH 0/5] Threaded MSI interrupt for VFIO PCI device Alex Williamson
2015-12-03 22:31   ` Yunhong Jiang
2015-12-16 17:56 ` Paolo Bonzini
2015-12-16 19:15   ` Alex Williamson
2015-12-16 21:55     ` Paolo Bonzini
2016-01-06  7:42       ` Yunhong Jiang
2016-01-06  7:40     ` Yunhong Jiang

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=1449166972-8894-2-git-send-email-yunhong.jiang@linux.intel.com \
    --to=yunhong.jiang@linux.intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@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

Powered by JetHome