* [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough
@ 2010-11-16 21:30 Jan Kiszka
2010-11-16 21:30 ` [PATCH v5-light 1/6] KVM: Clear assigned guest IRQ on release Jan Kiszka
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: Jan Kiszka @ 2010-11-16 21:30 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm, Alex Williamson, Michael S. Tsirkin
This is the rebased light version of the previous series, i.e. without
PCI-2.3-based IRQ masking or any SRCU conversion. PCI-2.3 support is
under rework to explore options for automatic mode switches.
Jan Kiszka (6):
KVM: Clear assigned guest IRQ on release
KVM: Switch assigned device IRQ forwarding to threaded handler
KVM: Refactor IRQ names of assigned devices
KVM: Save/restore state of assigned PCI device
KVM: Clean up kvm_vm_ioctl_assigned_device
KVM: Document device assigment API
Documentation/kvm/api.txt | 178 +++++++++++++++++++++++++++++++++++++++++++++
include/linux/kvm_host.h | 13 +---
virt/kvm/assigned-dev.c | 125 ++++++++++++--------------------
3 files changed, 227 insertions(+), 89 deletions(-)
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v5-light 1/6] KVM: Clear assigned guest IRQ on release
2010-11-16 21:30 [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough Jan Kiszka
@ 2010-11-16 21:30 ` Jan Kiszka
2010-11-16 21:30 ` [PATCH v5-light 2/6] KVM: Switch assigned device IRQ forwarding to threaded handler Jan Kiszka
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Jan Kiszka @ 2010-11-16 21:30 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti
Cc: kvm, Alex Williamson, Michael S. Tsirkin, Jan Kiszka
From: Jan Kiszka <jan.kiszka@siemens.com>
When we deassign a guest IRQ, clear the potentially asserted guest line.
There might be no chance for the guest to do this, specifically if we
switch from INTx to MSI mode.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
virt/kvm/assigned-dev.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/virt/kvm/assigned-dev.c b/virt/kvm/assigned-dev.c
index 7c98928..ecc4419 100644
--- a/virt/kvm/assigned-dev.c
+++ b/virt/kvm/assigned-dev.c
@@ -141,6 +141,9 @@ static void deassign_guest_irq(struct kvm *kvm,
kvm_unregister_irq_ack_notifier(kvm, &assigned_dev->ack_notifier);
assigned_dev->ack_notifier.gsi = -1;
+ kvm_set_irq(assigned_dev->kvm, assigned_dev->irq_source_id,
+ assigned_dev->guest_irq, 0);
+
if (assigned_dev->irq_source_id != -1)
kvm_free_irq_source_id(kvm, assigned_dev->irq_source_id);
assigned_dev->irq_source_id = -1;
--
1.7.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v5-light 2/6] KVM: Switch assigned device IRQ forwarding to threaded handler
2010-11-16 21:30 [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough Jan Kiszka
2010-11-16 21:30 ` [PATCH v5-light 1/6] KVM: Clear assigned guest IRQ on release Jan Kiszka
@ 2010-11-16 21:30 ` Jan Kiszka
2010-11-16 21:30 ` [PATCH v5-light 3/6] KVM: Refactor IRQ names of assigned devices Jan Kiszka
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Jan Kiszka @ 2010-11-16 21:30 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti
Cc: kvm, Alex Williamson, Michael S. Tsirkin, Jan Kiszka
From: Jan Kiszka <jan.kiszka@siemens.com>
This improves the IRQ forwarding for assigned devices: By using the
kernel's threaded IRQ scheme, we can get rid of the latency-prone work
queue and simplify the code in the same run.
Moreover, we no longer have to hold assigned_dev_lock while raising the
guest IRQ, which can be a lenghty operation as we may have to iterate
over all VCPUs. The lock is now only used for synchronizing masking vs.
unmasking of INTx-type IRQs, thus is renames to intx_lock.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
include/linux/kvm_host.h | 12 +----
virt/kvm/assigned-dev.c | 107 +++++++++++++++-------------------------------
2 files changed, 36 insertions(+), 83 deletions(-)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 2d63f2c..9fe7fef 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -470,16 +470,8 @@ struct kvm_irq_ack_notifier {
void (*irq_acked)(struct kvm_irq_ack_notifier *kian);
};
-#define KVM_ASSIGNED_MSIX_PENDING 0x1
-struct kvm_guest_msix_entry {
- u32 vector;
- u16 entry;
- u16 flags;
-};
-
struct kvm_assigned_dev_kernel {
struct kvm_irq_ack_notifier ack_notifier;
- struct work_struct interrupt_work;
struct list_head list;
int assigned_dev_id;
int host_segnr;
@@ -490,13 +482,13 @@ struct kvm_assigned_dev_kernel {
bool host_irq_disabled;
struct msix_entry *host_msix_entries;
int guest_irq;
- struct kvm_guest_msix_entry *guest_msix_entries;
+ struct msix_entry *guest_msix_entries;
unsigned long irq_requested_type;
int irq_source_id;
int flags;
struct pci_dev *dev;
struct kvm *kvm;
- spinlock_t assigned_dev_lock;
+ spinlock_t intx_lock;
};
struct kvm_irq_mask_notifier {
diff --git a/virt/kvm/assigned-dev.c b/virt/kvm/assigned-dev.c
index ecc4419..1d77ce1 100644
--- a/virt/kvm/assigned-dev.c
+++ b/virt/kvm/assigned-dev.c
@@ -55,58 +55,31 @@ static int find_index_from_host_irq(struct kvm_assigned_dev_kernel
return index;
}
-static void kvm_assigned_dev_interrupt_work_handler(struct work_struct *work)
+static irqreturn_t kvm_assigned_dev_thread(int irq, void *dev_id)
{
- struct kvm_assigned_dev_kernel *assigned_dev;
- int i;
+ struct kvm_assigned_dev_kernel *assigned_dev = dev_id;
+ u32 vector;
+ int index;
- assigned_dev = container_of(work, struct kvm_assigned_dev_kernel,
- interrupt_work);
+ if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_INTX) {
+ spin_lock(&assigned_dev->intx_lock);
+ disable_irq_nosync(irq);
+ assigned_dev->host_irq_disabled = true;
+ spin_unlock(&assigned_dev->intx_lock);
+ }
- spin_lock_irq(&assigned_dev->assigned_dev_lock);
if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_MSIX) {
- struct kvm_guest_msix_entry *guest_entries =
- assigned_dev->guest_msix_entries;
- for (i = 0; i < assigned_dev->entries_nr; i++) {
- if (!(guest_entries[i].flags &
- KVM_ASSIGNED_MSIX_PENDING))
- continue;
- guest_entries[i].flags &= ~KVM_ASSIGNED_MSIX_PENDING;
+ index = find_index_from_host_irq(assigned_dev, irq);
+ if (index >= 0) {
+ vector = assigned_dev->
+ guest_msix_entries[index].vector;
kvm_set_irq(assigned_dev->kvm,
- assigned_dev->irq_source_id,
- guest_entries[i].vector, 1);
+ assigned_dev->irq_source_id, vector, 1);
}
} else
kvm_set_irq(assigned_dev->kvm, assigned_dev->irq_source_id,
assigned_dev->guest_irq, 1);
- spin_unlock_irq(&assigned_dev->assigned_dev_lock);
-}
-
-static irqreturn_t kvm_assigned_dev_intr(int irq, void *dev_id)
-{
- unsigned long flags;
- struct kvm_assigned_dev_kernel *assigned_dev =
- (struct kvm_assigned_dev_kernel *) dev_id;
-
- spin_lock_irqsave(&assigned_dev->assigned_dev_lock, flags);
- if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_MSIX) {
- int index = find_index_from_host_irq(assigned_dev, irq);
- if (index < 0)
- goto out;
- assigned_dev->guest_msix_entries[index].flags |=
- KVM_ASSIGNED_MSIX_PENDING;
- }
-
- schedule_work(&assigned_dev->interrupt_work);
-
- if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_GUEST_INTX) {
- disable_irq_nosync(irq);
- assigned_dev->host_irq_disabled = true;
- }
-
-out:
- spin_unlock_irqrestore(&assigned_dev->assigned_dev_lock, flags);
return IRQ_HANDLED;
}
@@ -114,7 +87,6 @@ out:
static void kvm_assigned_dev_ack_irq(struct kvm_irq_ack_notifier *kian)
{
struct kvm_assigned_dev_kernel *dev;
- unsigned long flags;
if (kian->gsi == -1)
return;
@@ -127,12 +99,12 @@ static void kvm_assigned_dev_ack_irq(struct kvm_irq_ack_notifier *kian)
/* The guest irq may be shared so this ack may be
* from another device.
*/
- spin_lock_irqsave(&dev->assigned_dev_lock, flags);
+ spin_lock(&dev->intx_lock);
if (dev->host_irq_disabled) {
enable_irq(dev->host_irq);
dev->host_irq_disabled = false;
}
- spin_unlock_irqrestore(&dev->assigned_dev_lock, flags);
+ spin_unlock(&dev->intx_lock);
}
static void deassign_guest_irq(struct kvm *kvm,
@@ -155,28 +127,19 @@ static void deassign_host_irq(struct kvm *kvm,
struct kvm_assigned_dev_kernel *assigned_dev)
{
/*
- * In kvm_free_device_irq, cancel_work_sync return true if:
- * 1. work is scheduled, and then cancelled.
- * 2. work callback is executed.
- *
- * The first one ensured that the irq is disabled and no more events
- * would happen. But for the second one, the irq may be enabled (e.g.
- * for MSI). So we disable irq here to prevent further events.
+ * We disable irq here to prevent further events.
*
* Notice this maybe result in nested disable if the interrupt type is
* INTx, but it's OK for we are going to free it.
*
* If this function is a part of VM destroy, please ensure that till
* now, the kvm state is still legal for probably we also have to wait
- * interrupt_work done.
+ * on a currently running IRQ handler.
*/
if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_MSIX) {
int i;
for (i = 0; i < assigned_dev->entries_nr; i++)
- disable_irq_nosync(assigned_dev->
- host_msix_entries[i].vector);
-
- cancel_work_sync(&assigned_dev->interrupt_work);
+ disable_irq(assigned_dev->host_msix_entries[i].vector);
for (i = 0; i < assigned_dev->entries_nr; i++)
free_irq(assigned_dev->host_msix_entries[i].vector,
@@ -188,8 +151,7 @@ static void deassign_host_irq(struct kvm *kvm,
pci_disable_msix(assigned_dev->dev);
} else {
/* Deal with MSI and INTx */
- disable_irq_nosync(assigned_dev->host_irq);
- cancel_work_sync(&assigned_dev->interrupt_work);
+ disable_irq(assigned_dev->host_irq);
free_irq(assigned_dev->host_irq, (void *)assigned_dev);
@@ -268,8 +230,9 @@ static int assigned_device_enable_host_intx(struct kvm *kvm,
* on the same interrupt line is not a happy situation: there
* are going to be long delays in accepting, acking, etc.
*/
- if (request_irq(dev->host_irq, kvm_assigned_dev_intr,
- 0, "kvm_assigned_intx_device", (void *)dev))
+ if (request_threaded_irq(dev->host_irq, NULL, kvm_assigned_dev_thread,
+ IRQF_ONESHOT, "kvm_assigned_intx_device",
+ (void *)dev))
return -EIO;
return 0;
}
@@ -287,8 +250,8 @@ static int assigned_device_enable_host_msi(struct kvm *kvm,
}
dev->host_irq = dev->dev->irq;
- if (request_irq(dev->host_irq, kvm_assigned_dev_intr, 0,
- "kvm_assigned_msi_device", (void *)dev)) {
+ if (request_threaded_irq(dev->host_irq, NULL, kvm_assigned_dev_thread,
+ 0, "kvm_assigned_msi_device", (void *)dev)) {
pci_disable_msi(dev->dev);
return -EIO;
}
@@ -313,10 +276,10 @@ static int assigned_device_enable_host_msix(struct kvm *kvm,
return r;
for (i = 0; i < dev->entries_nr; i++) {
- r = request_irq(dev->host_msix_entries[i].vector,
- kvm_assigned_dev_intr, 0,
- "kvm_assigned_msix_device",
- (void *)dev);
+ r = request_threaded_irq(dev->host_msix_entries[i].vector,
+ NULL, kvm_assigned_dev_thread,
+ 0, "kvm_assigned_msix_device",
+ (void *)dev);
if (r)
goto err;
}
@@ -557,12 +520,10 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
match->host_devfn = assigned_dev->devfn;
match->flags = assigned_dev->flags;
match->dev = dev;
- spin_lock_init(&match->assigned_dev_lock);
+ spin_lock_init(&match->intx_lock);
match->irq_source_id = -1;
match->kvm = kvm;
match->ack_notifier.irq_acked = kvm_assigned_dev_ack_irq;
- INIT_WORK(&match->interrupt_work,
- kvm_assigned_dev_interrupt_work_handler);
list_add(&match->list, &kvm->arch.assigned_dev_head);
@@ -654,9 +615,9 @@ static int kvm_vm_ioctl_set_msix_nr(struct kvm *kvm,
r = -ENOMEM;
goto msix_nr_out;
}
- adev->guest_msix_entries = kzalloc(
- sizeof(struct kvm_guest_msix_entry) *
- entry_nr->entry_nr, GFP_KERNEL);
+ adev->guest_msix_entries =
+ kzalloc(sizeof(struct msix_entry) * entry_nr->entry_nr,
+ GFP_KERNEL);
if (!adev->guest_msix_entries) {
kfree(adev->host_msix_entries);
r = -ENOMEM;
--
1.7.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v5-light 3/6] KVM: Refactor IRQ names of assigned devices
2010-11-16 21:30 [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough Jan Kiszka
2010-11-16 21:30 ` [PATCH v5-light 1/6] KVM: Clear assigned guest IRQ on release Jan Kiszka
2010-11-16 21:30 ` [PATCH v5-light 2/6] KVM: Switch assigned device IRQ forwarding to threaded handler Jan Kiszka
@ 2010-11-16 21:30 ` Jan Kiszka
2010-11-16 21:30 ` [PATCH v5-light 4/6] KVM: Save/restore state of assigned PCI device Jan Kiszka
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Jan Kiszka @ 2010-11-16 21:30 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti
Cc: kvm, Alex Williamson, Michael S. Tsirkin, Jan Kiszka
From: Jan Kiszka <jan.kiszka@siemens.com>
Cosmetic change, but it helps to correlate IRQs with PCI devices.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
include/linux/kvm_host.h | 1 +
virt/kvm/assigned-dev.c | 11 ++++++-----
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 9fe7fef..4bd663d 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -489,6 +489,7 @@ struct kvm_assigned_dev_kernel {
struct pci_dev *dev;
struct kvm *kvm;
spinlock_t intx_lock;
+ char irq_name[32];
};
struct kvm_irq_mask_notifier {
diff --git a/virt/kvm/assigned-dev.c b/virt/kvm/assigned-dev.c
index 1d77ce1..7623408 100644
--- a/virt/kvm/assigned-dev.c
+++ b/virt/kvm/assigned-dev.c
@@ -231,8 +231,7 @@ static int assigned_device_enable_host_intx(struct kvm *kvm,
* are going to be long delays in accepting, acking, etc.
*/
if (request_threaded_irq(dev->host_irq, NULL, kvm_assigned_dev_thread,
- IRQF_ONESHOT, "kvm_assigned_intx_device",
- (void *)dev))
+ IRQF_ONESHOT, dev->irq_name, (void *)dev))
return -EIO;
return 0;
}
@@ -251,7 +250,7 @@ static int assigned_device_enable_host_msi(struct kvm *kvm,
dev->host_irq = dev->dev->irq;
if (request_threaded_irq(dev->host_irq, NULL, kvm_assigned_dev_thread,
- 0, "kvm_assigned_msi_device", (void *)dev)) {
+ 0, dev->irq_name, (void *)dev)) {
pci_disable_msi(dev->dev);
return -EIO;
}
@@ -278,8 +277,7 @@ static int assigned_device_enable_host_msix(struct kvm *kvm,
for (i = 0; i < dev->entries_nr; i++) {
r = request_threaded_irq(dev->host_msix_entries[i].vector,
NULL, kvm_assigned_dev_thread,
- 0, "kvm_assigned_msix_device",
- (void *)dev);
+ 0, dev->irq_name, (void *)dev);
if (r)
goto err;
}
@@ -336,6 +334,9 @@ static int assign_host_irq(struct kvm *kvm,
if (dev->irq_requested_type & KVM_DEV_IRQ_HOST_MASK)
return r;
+ snprintf(dev->irq_name, sizeof(dev->irq_name), "kvm:%s",
+ pci_name(dev->dev));
+
switch (host_irq_type) {
case KVM_DEV_IRQ_HOST_INTX:
r = assigned_device_enable_host_intx(kvm, dev);
--
1.7.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v5-light 4/6] KVM: Save/restore state of assigned PCI device
2010-11-16 21:30 [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough Jan Kiszka
` (2 preceding siblings ...)
2010-11-16 21:30 ` [PATCH v5-light 3/6] KVM: Refactor IRQ names of assigned devices Jan Kiszka
@ 2010-11-16 21:30 ` Jan Kiszka
2010-11-16 21:30 ` [PATCH v5-light 5/6] KVM: Clean up kvm_vm_ioctl_assigned_device Jan Kiszka
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Jan Kiszka @ 2010-11-16 21:30 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti
Cc: kvm, Alex Williamson, Michael S. Tsirkin, Jan Kiszka
From: Jan Kiszka <jan.kiszka@siemens.com>
The guest may change states that pci_reset_function does not touch. So
we better save/restore the assigned device across guest usage.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
virt/kvm/assigned-dev.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/virt/kvm/assigned-dev.c b/virt/kvm/assigned-dev.c
index 7623408..d389207 100644
--- a/virt/kvm/assigned-dev.c
+++ b/virt/kvm/assigned-dev.c
@@ -197,7 +197,8 @@ static void kvm_free_assigned_device(struct kvm *kvm,
{
kvm_free_assigned_irq(kvm, assigned_dev);
- pci_reset_function(assigned_dev->dev);
+ __pci_reset_function(assigned_dev->dev);
+ pci_restore_state(assigned_dev->dev);
pci_release_regions(assigned_dev->dev);
pci_disable_device(assigned_dev->dev);
@@ -514,6 +515,7 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
}
pci_reset_function(dev);
+ pci_save_state(dev);
match->assigned_dev_id = assigned_dev->assigned_dev_id;
match->host_segnr = assigned_dev->segnr;
@@ -544,6 +546,7 @@ out:
mutex_unlock(&kvm->lock);
return r;
out_list_del:
+ pci_restore_state(dev);
list_del(&match->list);
pci_release_regions(dev);
out_disable:
--
1.7.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v5-light 5/6] KVM: Clean up kvm_vm_ioctl_assigned_device
2010-11-16 21:30 [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough Jan Kiszka
` (3 preceding siblings ...)
2010-11-16 21:30 ` [PATCH v5-light 4/6] KVM: Save/restore state of assigned PCI device Jan Kiszka
@ 2010-11-16 21:30 ` Jan Kiszka
2010-11-16 21:30 ` [PATCH v5-light 6/6] KVM: Document device assigment API Jan Kiszka
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Jan Kiszka @ 2010-11-16 21:30 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti
Cc: kvm, Alex Williamson, Michael S. Tsirkin, Jan Kiszka
From: Jan Kiszka <jan.kiszka@siemens.com>
Any arch not supporting device assigment will also not build
assigned-dev.c. So testing for KVM_CAP_DEVICE_DEASSIGNMENT is pointless.
KVM_CAP_ASSIGN_DEV_IRQ is unconditinally set. Moreover, add a default
case for dispatching the ioctl.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
virt/kvm/assigned-dev.c | 9 ++++-----
1 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/virt/kvm/assigned-dev.c b/virt/kvm/assigned-dev.c
index d389207..ae72ae6 100644
--- a/virt/kvm/assigned-dev.c
+++ b/virt/kvm/assigned-dev.c
@@ -674,7 +674,7 @@ long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
unsigned long arg)
{
void __user *argp = (void __user *)arg;
- int r = -ENOTTY;
+ int r;
switch (ioctl) {
case KVM_ASSIGN_PCI_DEVICE: {
@@ -692,7 +692,6 @@ long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
r = -EOPNOTSUPP;
break;
}
-#ifdef KVM_CAP_ASSIGN_DEV_IRQ
case KVM_ASSIGN_DEV_IRQ: {
struct kvm_assigned_irq assigned_irq;
@@ -715,8 +714,6 @@ long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
goto out;
break;
}
-#endif
-#ifdef KVM_CAP_DEVICE_DEASSIGNMENT
case KVM_DEASSIGN_PCI_DEVICE: {
struct kvm_assigned_pci_dev assigned_dev;
@@ -728,7 +725,6 @@ long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
goto out;
break;
}
-#endif
#ifdef KVM_CAP_IRQ_ROUTING
case KVM_SET_GSI_ROUTING: {
struct kvm_irq_routing routing;
@@ -781,6 +777,9 @@ long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
break;
}
#endif
+ default:
+ r = -ENOTTY;
+ break;
}
out:
return r;
--
1.7.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v5-light 6/6] KVM: Document device assigment API
2010-11-16 21:30 [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough Jan Kiszka
` (4 preceding siblings ...)
2010-11-16 21:30 ` [PATCH v5-light 5/6] KVM: Clean up kvm_vm_ioctl_assigned_device Jan Kiszka
@ 2010-11-16 21:30 ` Jan Kiszka
2010-11-17 3:01 ` [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough Alex Williamson
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Jan Kiszka @ 2010-11-16 21:30 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti
Cc: kvm, Alex Williamson, Michael S. Tsirkin, Jan Kiszka
From: Jan Kiszka <jan.kiszka@siemens.com>
Adds API documentation for KVM_[DE]ASSIGN_PCI_DEVICE,
KVM_[DE]ASSIGN_DEV_IRQ, KVM_SET_GSI_ROUTING, KVM_ASSIGN_SET_MSIX_NR, and
KVM_ASSIGN_SET_MSIX_ENTRY.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
Documentation/kvm/api.txt | 178 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 178 insertions(+), 0 deletions(-)
diff --git a/Documentation/kvm/api.txt b/Documentation/kvm/api.txt
index b336266..e1a9297 100644
--- a/Documentation/kvm/api.txt
+++ b/Documentation/kvm/api.txt
@@ -1085,6 +1085,184 @@ 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_PCI_DEVICE
+
+Capability: KVM_CAP_DEVICE_ASSIGNMENT
+Architectures: x86 ia64
+Type: vm ioctl
+Parameters: struct kvm_assigned_pci_dev (in)
+Returns: 0 on success, -1 on error
+
+Assigns a host PCI device to the VM.
+
+struct kvm_assigned_pci_dev {
+ __u32 assigned_dev_id;
+ __u32 busnr;
+ __u32 devfn;
+ __u32 flags;
+ __u32 segnr;
+ union {
+ __u32 reserved[11];
+ };
+};
+
+The PCI device is specified by the triple segnr, busnr, and devfn.
+Identification in succeeding service requests is done via assigned_dev_id. The
+following flags are specified:
+
+/* Depends on KVM_CAP_IOMMU */
+#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
+
+4.48 KVM_DEASSIGN_PCI_DEVICE
+
+Capability: KVM_CAP_DEVICE_DEASSIGNMENT
+Architectures: x86 ia64
+Type: vm ioctl
+Parameters: struct kvm_assigned_pci_dev (in)
+Returns: 0 on success, -1 on error
+
+Ends PCI device assignment, releasing all associated resources.
+
+See KVM_CAP_DEVICE_ASSIGNMENT for the data structure. Only assigned_dev_id is
+used in kvm_assigned_pci_dev to identify the device.
+
+4.49 KVM_ASSIGN_DEV_IRQ
+
+Capability: KVM_CAP_ASSIGN_DEV_IRQ
+Architectures: x86 ia64
+Type: vm ioctl
+Parameters: struct kvm_assigned_irq (in)
+Returns: 0 on success, -1 on error
+
+Assigns an IRQ to a passed-through device.
+
+struct kvm_assigned_irq {
+ __u32 assigned_dev_id;
+ __u32 host_irq;
+ __u32 guest_irq;
+ __u32 flags;
+ union {
+ struct {
+ __u32 addr_lo;
+ __u32 addr_hi;
+ __u32 data;
+ } guest_msi;
+ __u32 reserved[12];
+ };
+};
+
+The following flags are defined:
+
+#define KVM_DEV_IRQ_HOST_INTX (1 << 0)
+#define KVM_DEV_IRQ_HOST_MSI (1 << 1)
+#define KVM_DEV_IRQ_HOST_MSIX (1 << 2)
+
+#define KVM_DEV_IRQ_GUEST_INTX (1 << 8)
+#define KVM_DEV_IRQ_GUEST_MSI (1 << 9)
+#define KVM_DEV_IRQ_GUEST_MSIX (1 << 10)
+
+It is not valid to specify multiple types per host or guest IRQ. However, the
+IRQ type of host and guest can differ or can even be null.
+
+4.50 KVM_DEASSIGN_DEV_IRQ
+
+Capability: KVM_CAP_ASSIGN_DEV_IRQ
+Architectures: x86 ia64
+Type: vm ioctl
+Parameters: struct kvm_assigned_irq (in)
+Returns: 0 on success, -1 on error
+
+Ends an IRQ assignment to a passed-through device.
+
+See KVM_ASSIGN_DEV_IRQ for the data structure. The target device is specified
+by assigned_dev_id, flags must correspond to the IRQ type specified on
+KVM_ASSIGN_DEV_IRQ. Partial deassignment of host or guest IRQ is allowed.
+
+4.51 KVM_SET_GSI_ROUTING
+
+Capability: KVM_CAP_IRQ_ROUTING
+Architectures: x86 ia64
+Type: vm ioctl
+Parameters: struct kvm_irq_routing (in)
+Returns: 0 on success, -1 on error
+
+Sets the GSI routing table entries, overwriting any previously set entries.
+
+struct kvm_irq_routing {
+ __u32 nr;
+ __u32 flags;
+ struct kvm_irq_routing_entry entries[0];
+};
+
+No flags are specified so far, the corresponding field must be set to zero.
+
+struct kvm_irq_routing_entry {
+ __u32 gsi;
+ __u32 type;
+ __u32 flags;
+ __u32 pad;
+ union {
+ struct kvm_irq_routing_irqchip irqchip;
+ struct kvm_irq_routing_msi msi;
+ __u32 pad[8];
+ } u;
+};
+
+/* gsi routing entry types */
+#define KVM_IRQ_ROUTING_IRQCHIP 1
+#define KVM_IRQ_ROUTING_MSI 2
+
+No flags are specified so far, the corresponding field must be set to zero.
+
+struct kvm_irq_routing_irqchip {
+ __u32 irqchip;
+ __u32 pin;
+};
+
+struct kvm_irq_routing_msi {
+ __u32 address_lo;
+ __u32 address_hi;
+ __u32 data;
+ __u32 pad;
+};
+
+4.52 KVM_ASSIGN_SET_MSIX_NR
+
+Capability: KVM_CAP_DEVICE_MSIX
+Architectures: x86 ia64
+Type: vm ioctl
+Parameters: struct kvm_assigned_msix_nr (in)
+Returns: 0 on success, -1 on error
+
+Set the number of MSI-X interrupts for an assigned device. This service can
+only be called once in the lifetime of an assigned device.
+
+struct kvm_assigned_msix_nr {
+ __u32 assigned_dev_id;
+ __u16 entry_nr;
+ __u16 padding;
+};
+
+#define KVM_MAX_MSIX_PER_DEV 256
+
+4.53 KVM_ASSIGN_SET_MSIX_ENTRY
+
+Capability: KVM_CAP_DEVICE_MSIX
+Architectures: x86 ia64
+Type: vm ioctl
+Parameters: struct kvm_assigned_msix_entry (in)
+Returns: 0 on success, -1 on error
+
+Specifies the routing of an MSI-X assigned device interrupt to a GSI. Setting
+the GSI vector to zero means disabling the interrupt.
+
+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];
+};
+
5. The kvm_run structure
Application code obtains a pointer to the kvm_run structure by
--
1.7.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough
2010-11-16 21:30 [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough Jan Kiszka
` (5 preceding siblings ...)
2010-11-16 21:30 ` [PATCH v5-light 6/6] KVM: Document device assigment API Jan Kiszka
@ 2010-11-17 3:01 ` Alex Williamson
2010-11-17 9:02 ` Avi Kivity
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Alex Williamson @ 2010-11-17 3:01 UTC (permalink / raw)
To: Jan Kiszka; +Cc: Avi Kivity, Marcelo Tosatti, kvm, Michael S. Tsirkin
On Tue, 2010-11-16 at 22:30 +0100, Jan Kiszka wrote:
> This is the rebased light version of the previous series, i.e. without
> PCI-2.3-based IRQ masking or any SRCU conversion. PCI-2.3 support is
> under rework to explore options for automatic mode switches.
>
> Jan Kiszka (6):
> KVM: Clear assigned guest IRQ on release
> KVM: Switch assigned device IRQ forwarding to threaded handler
> KVM: Refactor IRQ names of assigned devices
> KVM: Save/restore state of assigned PCI device
> KVM: Clean up kvm_vm_ioctl_assigned_device
> KVM: Document device assigment API
>
> Documentation/kvm/api.txt | 178 +++++++++++++++++++++++++++++++++++++++++++++
> include/linux/kvm_host.h | 13 +---
> virt/kvm/assigned-dev.c | 125 ++++++++++++--------------------
> 3 files changed, 227 insertions(+), 89 deletions(-)
>
Series looks good to me.
Acked-by: Alex Williamson <alex.williamson@redhat.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough
2010-11-16 21:30 [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough Jan Kiszka
` (6 preceding siblings ...)
2010-11-17 3:01 ` [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough Alex Williamson
@ 2010-11-17 9:02 ` Avi Kivity
2010-11-17 11:10 ` Michael S. Tsirkin
2010-11-17 14:56 ` Marcelo Tosatti
9 siblings, 0 replies; 11+ messages in thread
From: Avi Kivity @ 2010-11-17 9:02 UTC (permalink / raw)
To: Jan Kiszka; +Cc: Marcelo Tosatti, kvm, Alex Williamson, Michael S. Tsirkin
On 11/16/2010 11:30 PM, Jan Kiszka wrote:
> This is the rebased light version of the previous series, i.e. without
> PCI-2.3-based IRQ masking or any SRCU conversion. PCI-2.3 support is
> under rework to explore options for automatic mode switches.
>
Looks good, especially the threaded irq - a real winner.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough
2010-11-16 21:30 [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough Jan Kiszka
` (7 preceding siblings ...)
2010-11-17 9:02 ` Avi Kivity
@ 2010-11-17 11:10 ` Michael S. Tsirkin
2010-11-17 14:56 ` Marcelo Tosatti
9 siblings, 0 replies; 11+ messages in thread
From: Michael S. Tsirkin @ 2010-11-17 11:10 UTC (permalink / raw)
To: Jan Kiszka; +Cc: Avi Kivity, Marcelo Tosatti, kvm, Alex Williamson
On Tue, Nov 16, 2010 at 10:30:01PM +0100, Jan Kiszka wrote:
> This is the rebased light version of the previous series, i.e. without
> PCI-2.3-based IRQ masking or any SRCU conversion. PCI-2.3 support is
> under rework to explore options for automatic mode switches.
>
> Jan Kiszka (6):
> KVM: Clear assigned guest IRQ on release
> KVM: Switch assigned device IRQ forwarding to threaded handler
> KVM: Refactor IRQ names of assigned devices
> KVM: Save/restore state of assigned PCI device
> KVM: Clean up kvm_vm_ioctl_assigned_device
> KVM: Document device assigment API
>
> Documentation/kvm/api.txt | 178 +++++++++++++++++++++++++++++++++++++++++++++
> include/linux/kvm_host.h | 13 +---
> virt/kvm/assigned-dev.c | 125 ++++++++++++--------------------
> 3 files changed, 227 insertions(+), 89 deletions(-)
Acked-by: Michael S. Tsirkin <mst@redhat.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough
2010-11-16 21:30 [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough Jan Kiszka
` (8 preceding siblings ...)
2010-11-17 11:10 ` Michael S. Tsirkin
@ 2010-11-17 14:56 ` Marcelo Tosatti
9 siblings, 0 replies; 11+ messages in thread
From: Marcelo Tosatti @ 2010-11-17 14:56 UTC (permalink / raw)
To: Jan Kiszka; +Cc: Avi Kivity, kvm, Alex Williamson, Michael S. Tsirkin
On Tue, Nov 16, 2010 at 10:30:01PM +0100, Jan Kiszka wrote:
> This is the rebased light version of the previous series, i.e. without
> PCI-2.3-based IRQ masking or any SRCU conversion. PCI-2.3 support is
> under rework to explore options for automatic mode switches.
>
> Jan Kiszka (6):
> KVM: Clear assigned guest IRQ on release
> KVM: Switch assigned device IRQ forwarding to threaded handler
> KVM: Refactor IRQ names of assigned devices
> KVM: Save/restore state of assigned PCI device
> KVM: Clean up kvm_vm_ioctl_assigned_device
> KVM: Document device assigment API
>
> Documentation/kvm/api.txt | 178 +++++++++++++++++++++++++++++++++++++++++++++
> include/linux/kvm_host.h | 13 +---
> virt/kvm/assigned-dev.c | 125 ++++++++++++--------------------
> 3 files changed, 227 insertions(+), 89 deletions(-)
Applied, thanks.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2010-11-17 14:56 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-16 21:30 [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough Jan Kiszka
2010-11-16 21:30 ` [PATCH v5-light 1/6] KVM: Clear assigned guest IRQ on release Jan Kiszka
2010-11-16 21:30 ` [PATCH v5-light 2/6] KVM: Switch assigned device IRQ forwarding to threaded handler Jan Kiszka
2010-11-16 21:30 ` [PATCH v5-light 3/6] KVM: Refactor IRQ names of assigned devices Jan Kiszka
2010-11-16 21:30 ` [PATCH v5-light 4/6] KVM: Save/restore state of assigned PCI device Jan Kiszka
2010-11-16 21:30 ` [PATCH v5-light 5/6] KVM: Clean up kvm_vm_ioctl_assigned_device Jan Kiszka
2010-11-16 21:30 ` [PATCH v5-light 6/6] KVM: Document device assigment API Jan Kiszka
2010-11-17 3:01 ` [PATCH v5-light 0/6] KVM: Improve IRQ assignment for device passthrough Alex Williamson
2010-11-17 9:02 ` Avi Kivity
2010-11-17 11:10 ` Michael S. Tsirkin
2010-11-17 14:56 ` Marcelo Tosatti
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.