Skip to contentSkip to conversation

Add VT-d Posted-Interrupts support in QEMU

PATCH New Feng Wu 2 participants 3 messages Nov 10, 2014 KVM

lore
Share & tools
lore

Feng Wu

author
#0 lore raw

PATCH 1/1 Add VT-d Posted-Interrupts support in QEMU

VT-d Posted-Interrupts is an enhancement to CPU side Posted-Interrupt. With VT-d Posted-Interrupts enabled, external interrupts from direct-assigned devices can be delivered to guests without VMM intervention when guest is running in non-root mode.

This patch is used together with the patches in KVM side.

You can find the VT-d Posted-Interrtups Spec. in the following URL:
http://www.intel.com/content/www/us/en/intelligent-systems/intel-technology/vt-directed-io-spec.html

Feng Wu (1):
x86: Update VT-d Posted-Interrupts related information

 hw/i386/kvm/pci-assign.c  |   24 ++++++++++++++++++++++++
 linux-headers/linux/kvm.h |    2 ++
 target-i386/kvm.c         |    5 +++++
 target-i386/kvm_i386.h    |    1 +
 4 files changed, 32 insertions(+), 0 deletions(-)
author
#1 lore raw

PATCH 1/1 x86: Update VT-d Posted-Interrupts related information

VT-d Posted-Interrupts(PI) is an enhancement to CPU side Posted-Interrupt. With VT-d Posted-Interrupts enabled, external interrupts from direct-assigned devices can be delivered to guests without VMM involvement when guest is running in non-root mode.

If VT-d PI is supported by KVM, we need to update the IRTE with the new guest interrtup configuration.

---
 hw/i386/kvm/pci-assign.c  |   24 ++++++++++++++++++++++++
 linux-headers/linux/kvm.h |    2 ++
 target-i386/kvm.c         |    5 +++++
 target-i386/kvm_i386.h    |    1 +
 4 files changed, 32 insertions(+), 0 deletions(-)
hw/i386/kvm/pci-assign.c +24 -0
index bb206da..e55a99b 100644
@@ -1005,6 +1005,12 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev)
         assigned_dev->intx_route.mode = PCI_INTX_DISABLED;
         assigned_dev->intx_route.irq = -1;
         assigned_dev->assigned_irq_type = ASSIGNED_IRQ_MSI;
+
+        if (kvm_check_extension(kvm_state, KVM_CAP_PI)) {
+            if (kvm_device_pi_update(kvm_state, assigned_dev->dev_id) < 0) {
+                perror("assigned_dev_update_msi: kvm_device_pi_update");
+            }
+        }
     } else {
         Error *local_err = NULL;
 
@@ -1029,6 +1035,12 @@ static void assigned_dev_update_msi_msg(PCIDevice *pci_dev)
 
     kvm_irqchip_update_msi_route(kvm_state, assigned_dev->msi_virq[0],
                                  msi_get_message(pci_dev, 0));
+
+    if (kvm_check_extension(kvm_state, KVM_CAP_PI)) {
+        if (kvm_device_pi_update(kvm_state, assigned_dev->dev_id) < 0) {
+            perror("assigned_dev_update_msi_msg: kvm_device_pi_update");
+        }
+    }
 }
 
 static bool assigned_dev_msix_masked(MSIXTableEntry *entry)
@@ -1149,6 +1161,12 @@ static void assigned_dev_update_msix(PCIDevice *pci_dev)
                 perror("assigned_dev_enable_msix: assign irq");
                 return;
             }
+
+            if (kvm_check_extension(kvm_state, KVM_CAP_PI)) {
+                if (kvm_device_pi_update(kvm_state, assigned_dev->dev_id) < 0) {
+                    perror("assigned_dev_update_msix: kvm_device_pi_update");
+                }
+            }
         }
         assigned_dev->intx_route.mode = PCI_INTX_DISABLED;
         assigned_dev->intx_route.irq = -1;
@@ -1618,6 +1636,12 @@ static void assigned_dev_msix_mmio_write(void *opaque, hwaddr addr,
                 if (ret) {
                     error_report("Error updating irq routing entry (%d)", ret);
                 }
+                if (kvm_check_extension(kvm_state, KVM_CAP_PI)) {
+                    if (kvm_device_pi_update(kvm_state, adev->dev_id) < 0) {
+                        perror("assigned_dev_update_msi_msg: "
+                                    "kvm_device_pi_update");
+                    }
+                }
             }
         }
     }
linux-headers/linux/kvm.h +2 -0
index 2669938..b34f3c4 100644
@@ -765,6 +765,7 @@ struct kvm_ppc_smmu_info {
 #define KVM_CAP_PPC_FIXUP_HCALL 103
 #define KVM_CAP_PPC_ENABLE_HCALL 104
 #define KVM_CAP_CHECK_EXTENSION_VM 105
+#define KVM_CAP_PI 106
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -1020,6 +1021,7 @@ struct kvm_s390_ucas_mapping {
 #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_DEV_PI_UPDATE  _IOR(KVMIO,  0x7d, __u32)
 /* 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)
target-i386/kvm.c +5 -0
index ccf36e8..3dd8e5e 100644
@@ -2660,6 +2660,11 @@ int kvm_device_msi_assign(KVMState *s, uint32_t dev_id, int virq)
                                               KVM_DEV_IRQ_GUEST_MSI, virq);
 }
 
+int kvm_device_pi_update(KVMState *s, uint32_t dev_id)
+{
+    return kvm_vm_ioctl(s, KVM_ASSIGN_DEV_PI_UPDATE, &dev_id);
+}
+
 int kvm_device_msi_deassign(KVMState *s, uint32_t dev_id)
 {
     return kvm_deassign_irq_internal(s, dev_id, KVM_DEV_IRQ_GUEST_MSI |
target-i386/kvm_i386.h +1 -0
index cac30fd..c119b3e 100644
@@ -37,4 +37,5 @@ int kvm_device_msix_set_vector(KVMState *s, uint32_t dev_id, uint32_t vector,
 int kvm_device_msix_assign(KVMState *s, uint32_t dev_id);
 int kvm_device_msix_deassign(KVMState *s, uint32_t dev_id);
 
+int kvm_device_pi_update(KVMState *s, uint32_t dev_id);
 #endif
Signature · 1 line
1.7.1
#2 lore raw

Re: [PATCH] x86: Update VT-d Posted-Interrupts related information

Quoted 21 lines · Feng Wu

VT-d Posted-Interrupts(PI) is an enhancement to CPU side Posted-Interrupt. With VT-d Posted-Interrupts enabled, external interrupts from direct-assigned devices can be delivered to guests without VMM involvement when guest is running in non-root mode.

If VT-d PI is supported by KVM, we need to update the IRTE with the new guest interrtup configuration.

---
 hw/i386/kvm/pci-assign.c  |   24 ++++++++++++++++++++++++
 linux-headers/linux/kvm.h |    2 ++
 target-i386/kvm.c         |    5 +++++
 target-i386/kvm_i386.h    |    1 +
 4 files changed, 32 insertions(+), 0 deletions(-)
hw/i386/kvm/pci-assign.c +0 -0
index bb206da..e55a99b 100644

hw/i386/kvm/pci-assign.c static void assigned_dev_update_msi(PCIDevice *pci_dev) · line 1013

Quoted 9 lines
hw/i386/kvm/pci-assign.c +6 -0
@@ -1005,6 +1005,12 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev)
         assigned_dev->intx_route.mode = PCI_INTX_DISABLED;
         assigned_dev->intx_route.irq = -1;
         assigned_dev->assigned_irq_type = ASSIGNED_IRQ_MSI;
+
+        if (kvm_check_extension(kvm_state, KVM_CAP_PI)) {
+            if (kvm_device_pi_update(kvm_state, assigned_dev->dev_id) < 0) {
+                perror("assigned_dev_update_msi: kvm_device_pi_update");
+            }
+        }

I don't really understand this ioctl, we need to call into KVM to set the new IRQ routing anyway, why can't KVM figure out that it needs to update the posted interrupt config at the same time? Also, we'll need to support this through vfio-pci. Thanks,

Alex

Quoted 88 lines
hw/i386/kvm/pci-assign.c +18 -0
     } else {
         Error *local_err = NULL;
 
@@ -1029,6 +1035,12 @@ static void assigned_dev_update_msi_msg(PCIDevice *pci_dev)
 
     kvm_irqchip_update_msi_route(kvm_state, assigned_dev->msi_virq[0],
                                  msi_get_message(pci_dev, 0));
+
+    if (kvm_check_extension(kvm_state, KVM_CAP_PI)) {
+        if (kvm_device_pi_update(kvm_state, assigned_dev->dev_id) < 0) {
+            perror("assigned_dev_update_msi_msg: kvm_device_pi_update");
+        }
+    }
 }
 
 static bool assigned_dev_msix_masked(MSIXTableEntry *entry)
@@ -1149,6 +1161,12 @@ static void assigned_dev_update_msix(PCIDevice *pci_dev)
                 perror("assigned_dev_enable_msix: assign irq");
                 return;
             }
+
+            if (kvm_check_extension(kvm_state, KVM_CAP_PI)) {
+                if (kvm_device_pi_update(kvm_state, assigned_dev->dev_id) < 0) {
+                    perror("assigned_dev_update_msix: kvm_device_pi_update");
+                }
+            }
         }
         assigned_dev->intx_route.mode = PCI_INTX_DISABLED;
         assigned_dev->intx_route.irq = -1;
@@ -1618,6 +1636,12 @@ static void assigned_dev_msix_mmio_write(void *opaque, hwaddr addr,
                 if (ret) {
                     error_report("Error updating irq routing entry (%d)", ret);
                 }
+                if (kvm_check_extension(kvm_state, KVM_CAP_PI)) {
+                    if (kvm_device_pi_update(kvm_state, adev->dev_id) < 0) {
+                        perror("assigned_dev_update_msi_msg: "
+                                    "kvm_device_pi_update");
+                    }
+                }
             }
         }
     }
linux-headers/linux/kvm.h +2 -0
index 2669938..b34f3c4 100644
@@ -765,6 +765,7 @@ struct kvm_ppc_smmu_info {
 #define KVM_CAP_PPC_FIXUP_HCALL 103
 #define KVM_CAP_PPC_ENABLE_HCALL 104
 #define KVM_CAP_CHECK_EXTENSION_VM 105
+#define KVM_CAP_PI 106
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -1020,6 +1021,7 @@ struct kvm_s390_ucas_mapping {
 #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_DEV_PI_UPDATE  _IOR(KVMIO,  0x7d, __u32)
 /* 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)
target-i386/kvm.c +5 -0
index ccf36e8..3dd8e5e 100644
@@ -2660,6 +2660,11 @@ int kvm_device_msi_assign(KVMState *s, uint32_t dev_id, int virq)
                                               KVM_DEV_IRQ_GUEST_MSI, virq);
 }
 
+int kvm_device_pi_update(KVMState *s, uint32_t dev_id)
+{
+    return kvm_vm_ioctl(s, KVM_ASSIGN_DEV_PI_UPDATE, &dev_id);
+}
+
 int kvm_device_msi_deassign(KVMState *s, uint32_t dev_id)
 {
     return kvm_deassign_irq_internal(s, dev_id, KVM_DEV_IRQ_GUEST_MSI |
target-i386/kvm_i386.h +1 -0
index cac30fd..c119b3e 100644
@@ -37,4 +37,5 @@ int kvm_device_msix_set_vector(KVMState *s, uint32_t dev_id, uint32_t vector,
 int kvm_device_msix_assign(KVMState *s, uint32_t dev_id);
 int kvm_device_msix_deassign(KVMState *s, uint32_t dev_id);
 
+int kvm_device_pi_update(KVMState *s, uint32_t dev_id);
 #endif