From: Sheng Yang <sheng@linux.intel.com>
To: Avi Kivity <avi@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>,
Sheng Yang <sheng@linux.intel.com>
Subject: [PATCH 8/8] KVM: Emulation MSI-X mask bits for assigned devices
Date: Wed, 20 Oct 2010 16:26:32 +0800 [thread overview]
Message-ID: <1287563192-29685-9-git-send-email-sheng@linux.intel.com> (raw)
In-Reply-To: <1287563192-29685-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>
---
Documentation/kvm/api.txt | 22 ++++++++++++++++
arch/x86/kvm/x86.c | 6 ++++
include/linux/kvm.h | 8 +++++-
virt/kvm/assigned-dev.c | 60 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 95 insertions(+), 1 deletions(-)
diff --git a/Documentation/kvm/api.txt b/Documentation/kvm/api.txt
index d82d637..f324a50 100644
--- a/Documentation/kvm/api.txt
+++ b/Documentation/kvm/api.txt
@@ -1087,6 +1087,28 @@ of 4 instructions that make up a hypercall.
If any additional field gets added to this structure later on, a bit for that
additional piece of information will be set in the flags bitmap.
+4.47 KVM_ASSIGN_REG_MSIX_MMIO
+
+Capability: KVM_CAP_DEVICE_MSIX_MASK
+Architectures: x86
+Type: vm ioctl
+Parameters: struct kvm_assigned_msix_mmio (in)
+Returns: 0 on success, !0 on error
+
+struct kvm_assigned_msix_mmio {
+ /* Assigned device's ID */
+ __u32 assigned_dev_id;
+ /* MSI-X table MMIO address */
+ __u64 base_addr;
+ /* Must be 0 */
+ __u32 flags;
+ /* Must be 0, reserved for future use */
+ __u64 reserved;
+};
+
+This ioctl would enable in-kernel MSI-X emulation, which would handle MSI-X
+mask bit in the kernel.
+
5. The kvm_run structure
Application code obtains a pointer to the kvm_run structure by
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index fc62546..ba07a2f 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1927,6 +1927,8 @@ int kvm_dev_ioctl_check_extension(long ext)
case KVM_CAP_X86_ROBUST_SINGLESTEP:
case KVM_CAP_XSAVE:
case KVM_CAP_ENABLE_CAP:
+ case KVM_CAP_DEVICE_MSIX_EXT:
+ case KVM_CAP_DEVICE_MSIX_MASK:
r = 1;
break;
case KVM_CAP_COALESCED_MMIO:
@@ -2717,6 +2719,10 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
return -EINVAL;
switch (cap->cap) {
+ case KVM_CAP_DEVICE_MSIX_EXT:
+ vcpu->kvm->arch.msix_flags_enabled = true;
+ r = 0;
+ break;
default:
r = -EINVAL;
break;
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 0a7bd34..1494ed0 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -540,6 +540,10 @@ 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_EXT 59
+#define KVM_CAP_DEVICE_MSIX_MASK 60
+#endif
#ifdef KVM_CAP_IRQ_ROUTING
@@ -671,6 +675,8 @@ struct kvm_clock_data {
#define KVM_XEN_HVM_CONFIG _IOW(KVMIO, 0x7a, struct kvm_xen_hvm_config)
#define KVM_SET_CLOCK _IOW(KVMIO, 0x7b, struct kvm_clock_data)
#define KVM_GET_CLOCK _IOR(KVMIO, 0x7c, struct kvm_clock_data)
+#define KVM_ASSIGN_REG_MSIX_MMIO _IOW(KVMIO, 0x7d, \
+ struct kvm_assigned_msix_mmio)
/* Available with KVM_CAP_PIT_STATE2 */
#define KVM_GET_PIT2 _IOR(KVMIO, 0x9f, struct kvm_pit_state2)
#define KVM_SET_PIT2 _IOW(KVMIO, 0xa0, struct kvm_pit_state2)
@@ -802,7 +808,7 @@ struct kvm_assigned_msix_mmio {
__u32 assigned_dev_id;
__u64 base_addr;
__u32 flags;
- __u32 reserved[2];
+ __u64 reserved;
};
#endif /* __LINUX_KVM_H */
diff --git a/virt/kvm/assigned-dev.c b/virt/kvm/assigned-dev.c
index 5d2adc4..9573194 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,
@@ -169,6 +171,14 @@ static void deassign_host_irq(struct kvm *kvm,
*/
if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_MSIX) {
int i;
+#ifdef __KVM_HAVE_MSIX
+ if (assigned_dev->msix_mmio_base) {
+ mutex_lock(&kvm->slots_lock);
+ kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS,
+ &assigned_dev->msix_mmio_dev);
+ mutex_unlock(&kvm->slots_lock);
+ }
+#endif
for (i = 0; i < assigned_dev->entries_nr; i++)
disable_irq_nosync(assigned_dev->
host_msix_entries[i].vector);
@@ -318,6 +328,15 @@ static int assigned_device_enable_host_msix(struct kvm *kvm,
goto err;
}
+ if (dev->msix_mmio_base) {
+ mutex_lock(&kvm->slots_lock);
+ r = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS,
+ &dev->msix_mmio_dev);
+ mutex_unlock(&kvm->slots_lock);
+ if (r)
+ goto err;
+ }
+
return 0;
err:
for (i -= 1; i >= 0; i--)
@@ -870,6 +889,31 @@ static const struct kvm_io_device_ops msix_mmio_ops = {
.write = msix_mmio_write,
};
+static int kvm_vm_ioctl_register_msix_mmio(struct kvm *kvm,
+ struct kvm_assigned_msix_mmio *msix_mmio)
+{
+ int r = 0;
+ struct kvm_assigned_dev_kernel *adev;
+
+ mutex_lock(&kvm->lock);
+ adev = kvm_find_assigned_dev(&kvm->arch.assigned_dev_head,
+ msix_mmio->assigned_dev_id);
+ if (!adev) {
+ r = -EINVAL;
+ goto out;
+ }
+ if (msix_mmio->base_addr == 0) {
+ r = -EINVAL;
+ goto out;
+ }
+ adev->msix_mmio_base = msix_mmio->base_addr;
+
+ kvm_iodevice_init(&adev->msix_mmio_dev, &msix_mmio_ops);
+out:
+ mutex_unlock(&kvm->lock);
+
+ return r;
+}
#endif
long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
@@ -982,6 +1026,22 @@ long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
goto out;
break;
}
+ case KVM_ASSIGN_REG_MSIX_MMIO: {
+ struct kvm_assigned_msix_mmio msix_mmio;
+
+ r = -EFAULT;
+ if (copy_from_user(&msix_mmio, argp, sizeof(msix_mmio)))
+ goto out;
+
+ r = -EINVAL;
+ if (msix_mmio.flags != 0 || msix_mmio.reserved != 0)
+ goto out;
+
+ r = kvm_vm_ioctl_register_msix_mmio(kvm, &msix_mmio);
+ if (r)
+ goto out;
+ break;
+ }
#endif
}
out:
--
1.7.0.1
next prev parent reply other threads:[~2010-10-20 8:25 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-20 8:26 [PATCH 0/8][v2] MSI-X mask emulation support for assigned device Sheng Yang
2010-10-20 8:26 ` [PATCH 1/8] PCI: MSI: Move MSI-X entry definition to pci_regs.h Sheng Yang
2010-10-20 11:07 ` Matthew Wilcox
2010-10-20 8:26 ` [PATCH 2/8] irq: Export irq_to_desc() to modules Sheng Yang
2010-10-20 8:26 ` [PATCH 3/8] KVM: x86: Enable ENABLE_CAP capability for x86 Sheng Yang
2010-10-20 8:26 ` [PATCH 4/8] KVM: Move struct kvm_io_device to kvm_host.h Sheng Yang
2010-10-20 8:26 ` [PATCH 5/8] KVM: Add kvm_get_irq_routing_entry() func Sheng Yang
2010-10-20 8:53 ` Avi Kivity
2010-10-20 8:58 ` Sheng Yang
2010-10-20 9:13 ` Sheng Yang
2010-10-20 9:17 ` Sheng Yang
2010-10-20 9:32 ` Avi Kivity
2010-10-20 8:26 ` [PATCH 6/8] KVM: assigned dev: Preparation for mask support in userspace Sheng Yang
2010-10-20 9:30 ` Avi Kivity
2010-10-22 14:53 ` Marcelo Tosatti
2010-10-24 12:19 ` Sheng Yang
2010-10-24 12:23 ` Michael S. Tsirkin
2010-10-28 8:21 ` Sheng Yang
2010-10-20 8:26 ` [PATCH 7/8] KVM: assigned dev: Introduce io_device for MSI-X MMIO accessing Sheng Yang
2010-10-20 9:46 ` Avi Kivity
2010-10-20 10:33 ` Michael S. Tsirkin
2010-10-21 6:46 ` Sheng Yang
2010-10-21 9:27 ` Avi Kivity
2010-10-21 9:24 ` Michael S. Tsirkin
2010-10-21 9:47 ` Avi Kivity
2010-10-21 10:51 ` Michael S. Tsirkin
2010-10-20 22:35 ` Michael S. Tsirkin
2010-10-21 7:44 ` Sheng Yang
2010-10-20 8:26 ` Sheng Yang [this message]
2010-10-20 9:49 ` [PATCH 8/8] KVM: Emulation MSI-X mask bits for assigned devices Avi Kivity
2010-10-20 22:24 ` Michael S. Tsirkin
2010-10-21 8:30 ` Sheng Yang
2010-10-21 8:39 ` Michael S. Tsirkin
2010-10-22 4:42 ` Sheng Yang
2010-10-22 10:17 ` Michael S. Tsirkin
2010-10-22 13:30 ` Sheng Yang
2010-10-22 14:32 ` Michael S. Tsirkin
2010-10-20 9:51 ` [PATCH 0/8][v2] MSI-X mask emulation support for assigned device Avi Kivity
2010-10-20 10:44 ` Michael S. Tsirkin
2010-10-20 10:59 ` Avi Kivity
2010-10-20 13:43 ` Michael S. Tsirkin
2010-10-20 14:58 ` Alex Williamson
2010-10-20 14:58 ` Michael S. Tsirkin
2010-10-20 15:12 ` Alex Williamson
2010-10-20 15:17 ` Avi Kivity
2010-10-20 15:22 ` Alex Williamson
2010-10-20 15:26 ` Avi Kivity
2010-10-20 15:38 ` Alex Williamson
2010-10-20 14:47 ` Alex Williamson
2010-10-20 14:46 ` Michael S. Tsirkin
2010-10-20 15:07 ` Alex Williamson
2010-10-20 15:13 ` Michael S. Tsirkin
2010-10-20 20:13 ` Alex Williamson
2010-10-20 22:06 ` Michael S. Tsirkin
2010-10-20 15:23 ` Avi Kivity
2010-10-20 15:38 ` Alex Williamson
2010-10-20 15:54 ` Avi Kivity
2010-10-20 15:59 ` Michael S. Tsirkin
2010-10-20 16:13 ` Avi Kivity
2010-10-20 17:11 ` Michael S. Tsirkin
2010-10-20 18:31 ` Alex Williamson
2010-10-21 7:41 ` Sheng Yang
2010-10-20 19:02 ` Marcelo Tosatti
2010-10-21 7:10 ` Sheng Yang
2010-10-21 8:21 ` Michael S. Tsirkin
2010-10-20 22:20 ` Michael S. Tsirkin
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=1287563192-29685-9-git-send-email-sheng@linux.intel.com \
--to=sheng@linux.intel.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--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.