All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sheng Yang <sheng@linux.intel.com>
To: Avi Kivity <avi@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org, Sheng Yang <sheng@linux.intel.com>
Subject: [PATCH 1/3] KVM: Emulation MSI-X mask bits for assigned devices
Date: Tue, 28 Sep 2010 17:44:10 +0800	[thread overview]
Message-ID: <1285667052-24907-2-git-send-email-sheng@linux.intel.com> (raw)
In-Reply-To: <1285667052-24907-1-git-send-email-sheng@linux.intel.com>

This patch enable per-vector mask for assigned devices using MSI-X.

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
---
 arch/x86/kvm/x86.c       |    1 +
 include/linux/kvm.h      |    9 ++++++++-
 include/linux/kvm_host.h |    1 +
 virt/kvm/assigned-dev.c  |   39 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 8412c91..e6933e6 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1927,6 +1927,7 @@ int kvm_dev_ioctl_check_extension(long ext)
 	case KVM_CAP_DEBUGREGS:
 	case KVM_CAP_X86_ROBUST_SINGLESTEP:
 	case KVM_CAP_XSAVE:
+	case KVM_CAP_DEVICE_MSIX_MASK:
 		r = 1;
 		break;
 	case KVM_CAP_COALESCED_MMIO:
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 919ae53..f2b7cdc 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -540,6 +540,9 @@ struct kvm_ppc_pvinfo {
 #endif
 #define KVM_CAP_PPC_GET_PVINFO 57
 #define KVM_CAP_PPC_IRQ_LEVEL 58
+#ifdef __KVM_HAVE_MSIX
+#define KVM_CAP_DEVICE_MSIX_MASK 59
+#endif
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -787,11 +790,15 @@ struct kvm_assigned_msix_nr {
 };
 
 #define KVM_MAX_MSIX_PER_DEV		256
+
+#define KVM_MSIX_FLAG_MASK	1
+
 struct kvm_assigned_msix_entry {
 	__u32 assigned_dev_id;
 	__u32 gsi;
 	__u16 entry; /* The index of entry in the MSI-X table */
-	__u16 padding[3];
+	__u16 flags;
+	__u16 padding[2];
 };
 
 #endif /* __LINUX_KVM_H */
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 0b89d00..a43405c 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -415,6 +415,7 @@ struct kvm_irq_ack_notifier {
 };
 
 #define KVM_ASSIGNED_MSIX_PENDING		0x1
+#define KVM_ASSIGNED_MSIX_MASK			0x2
 struct kvm_guest_msix_entry {
 	u32 vector;
 	u16 entry;
diff --git a/virt/kvm/assigned-dev.c b/virt/kvm/assigned-dev.c
index 7c98928..15b8c32 100644
--- a/virt/kvm/assigned-dev.c
+++ b/virt/kvm/assigned-dev.c
@@ -17,6 +17,8 @@
 #include <linux/pci.h>
 #include <linux/interrupt.h>
 #include <linux/slab.h>
+#include <linux/irqnr.h>
+
 #include "irq.h"
 
 static struct kvm_assigned_dev_kernel *kvm_find_assigned_dev(struct list_head *head,
@@ -666,6 +668,30 @@ msix_nr_out:
 	return r;
 }
 
+static void update_msix_mask(struct kvm_assigned_dev_kernel *assigned_dev,
+			     int index)
+{
+	int irq;
+
+	if (!assigned_dev->dev->msix_enabled ||
+	    !(assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_MSIX))
+		return;
+
+	irq = assigned_dev->host_msix_entries[index].vector;
+
+	ASSERT(irq != 0);
+
+	if (assigned_dev->guest_msix_entries[index].flags &
+			KVM_ASSIGNED_MSIX_MASK)
+		disable_irq(irq);
+	else {
+		enable_irq(irq);
+		if (assigned_dev->guest_msix_entries[index].flags &
+				KVM_ASSIGNED_MSIX_PENDING)
+			schedule_work(&assigned_dev->interrupt_work);
+	}
+}
+
 static int kvm_vm_ioctl_set_msix_entry(struct kvm *kvm,
 				       struct kvm_assigned_msix_entry *entry)
 {
@@ -688,6 +714,19 @@ static int kvm_vm_ioctl_set_msix_entry(struct kvm *kvm,
 			adev->guest_msix_entries[i].entry = entry->entry;
 			adev->guest_msix_entries[i].vector = entry->gsi;
 			adev->host_msix_entries[i].entry = entry->entry;
+			if ((entry->flags & KVM_MSIX_FLAG_MASK) &&
+					!(adev->guest_msix_entries[i].flags &
+					KVM_ASSIGNED_MSIX_MASK)) {
+				adev->guest_msix_entries[i].flags |=
+					KVM_ASSIGNED_MSIX_MASK;
+				update_msix_mask(adev, i);
+			} else if (!(entry->flags & KVM_MSIX_FLAG_MASK) &&
+					(adev->guest_msix_entries[i].flags &
+					KVM_ASSIGNED_MSIX_MASK)) {
+				adev->guest_msix_entries[i].flags &=
+					~KVM_ASSIGNED_MSIX_MASK;
+				update_msix_mask(adev, i);
+			}
 			break;
 		}
 	if (i == adev->entries_nr) {
-- 
1.7.0.1


  reply	other threads:[~2010-09-28  9:44 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-28  9:44 [PATCH 0/3] Emulate MSI-X mask bits for assigned devices Sheng Yang
2010-09-28  9:44 ` Sheng Yang [this message]
2010-09-28 13:36   ` [PATCH 1/3] KVM: Emulation " Michael S. Tsirkin
2010-09-29  1:17     ` Sheng Yang
2010-09-30 16:25       ` Marcelo Tosatti
2010-09-29  8:36   ` Avi Kivity
2010-09-30  5:41     ` Sheng Yang
2010-10-03 13:03       ` Avi Kivity
2010-10-11  9:32         ` Sheng Yang
2010-09-30 16:18   ` Marcelo Tosatti
2010-10-11  9:49     ` Sheng Yang
2010-10-11 17:11       ` Marcelo Tosatti
2010-10-03 11:12   ` Michael S. Tsirkin
2010-10-11  9:28     ` Sheng Yang
2010-10-11 10:01       ` Michael S. Tsirkin
2010-10-12  6:49         ` Sheng Yang
2010-10-12 18:28           ` Michael S. Tsirkin
2010-10-13  1:03             ` Sheng Yang
2010-10-13 10:35               ` Michael S. Tsirkin
2010-10-12 18:30           ` Michael S. Tsirkin
2010-10-13  0:58             ` Sheng Yang
2010-10-13 12:03               ` Michael S. Tsirkin
2010-09-28  9:44 ` [PATCH 2/3] qemu-kvm: device assignment: Some clean up for MSI-X code Sheng Yang
2010-09-28  9:44 ` [PATCH 3/3] qemu-kvm: device assignment: emulate MSI-X mask bits Sheng Yang
2010-09-30 16:44 ` [PATCH 0/3] Emulate MSI-X mask bits for assigned devices Marcelo Tosatti
2010-10-11  9:34   ` Sheng Yang

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=1285667052-24907-2-git-send-email-sheng@linux.intel.com \
    --to=sheng@linux.intel.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.