Define some VFIO interfaces for VT-d Posted-Interrupts
Subsystems (3)
cover Define some VFIO interfaces for VT-d Posted-Interrupts
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.
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
This patch set does the following things:
- Define a new VFIO group KVM_DEV_VFIO_INTERRUPT and it's attributes KVM_DEV_VFIO_INTERRUPT_POSTING_IRQ. Qemu can use this interface to configure VT-d PI when guest updates the interrupt configuration (MSI/MSI-X configuration).
- Define a new VFIO API: vfio_msi_get_irq(), which can be used by KVM to get the host irq of the assigned devices. Then KVM can update the associated IRTE for VT-d PI.
Feng Wu (2):
vfio: Add new interrupt group for VFIO
vfio: Add VFIO API vfio_msi_get_irq
Documentation/virtual/kvm/devices/vfio.txt | 8 ++++++++ drivers/vfio/pci/vfio_pci.c | 10 ++++++++++ include/linux/vfio.h | 2 ++ include/uapi/linux/kvm.h | 14 ++++++++++++++ 4 files changed, 34 insertions(+), 0 deletions(-)
RFC PATCH 1/2 vfio: Add new interrupt group for VFIO
Add new group KVM_DEV_VFIO_INTERRUPT and commandKVM_DEV_VFIO_DEVIE_POSTING_IRQ related to it.
This is used for VT-d Posted-Interrupts setup.
--- Documentation/virtual/kvm/devices/vfio.txt | 8 ++++++++ include/uapi/linux/kvm.h | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 0 deletions(-)
Documentation/virtual/kvm/devices/vfio.txt +8 -0
@@ -13,6 +13,7 @@ VFIO-group is held by KVM. Groups: KVM_DEV_VFIO_GROUP + KVM_DEV_VFIO_INTERRUPT KVM_DEV_VFIO_GROUP attributes: KVM_DEV_VFIO_GROUP_ADD: Add a VFIO group to VFIO-KVM device tracking
@@ -20,3 +21,10 @@ KVM_DEV_VFIO_GROUP attributes: For each, kvm_device_attr.addr points to an int32_t file descriptor for the VFIO group. + +KVM_DEV_VFIO_INTERRUPT attributes: + KVM_DEV_VFIO_INTERRUPT_POSTING_IRQ: Set up the interrupt configuration for +VT-d Posted-Interrrupts + +For each, kvm_device_attr.addr points to struct kvm_posted_intr, which +include the needed information for VT-d Posted-Interrupts setup.
include/uapi/linux/kvm.h +14 -0
@@ -943,9 +943,23 @@ struct kvm_device_attr {__u64 addr;/* userspace address of attr data */ }; +struct virq_info { +__u32 index;/* index of the msi/msix entry */ +int virq;/* virq of the interrupt */ +}; + +struct kvm_posted_intr { +__u32 fd;/* file descriptor of the VFIO device */ +__u32 count; +bool msix; +struct virq_info virq_info[0 ]; +}; +#define KVM_DEV_VFIO_GROUP 1#define KVM_DEV_VFIO_GROUP_ADD 1#define KVM_DEV_VFIO_GROUP_DEL 2 +#define KVM_DEV_VFIO_INTERRUPT 2 +#define KVM_DEV_VFIO_INTERRUPT_POSTING_IRQ 1enum kvm_device_type {KVM_DEV_TYPE_FSL_MPIC_20 =1 ,
Signature · 1 line
1.7.1
Re: [RFC PATCH v1 1/2] vfio: Add new interrupt group for VFIO
Quoted 4 lines · Feng Wu
Add new group
KVM_DEV_VFIO_INTERRUPTand commandKVM_DEV_VFIO_DEVIE_POSTING_IRQrelated to it.This is used for VT-d Posted-Interrupts setup.
Eric proposed an interface for ARM forwarded interrupts[1] using group KVM_DEV_VFIO_DEVICE with attributes KVM_DEV_VFIO_DEVICE_ASSIGN_IRQ and KVM_DEV_VFIO_DEVICE_DEASSIGN_IRQ. Why are we proposing yet another group and attributes here? Why can't we re-use the ones Eric proposes?
[1] https://lkml.org/lkml/2014/8/25/258
Quoted 36 lines
Signed-off-by Feng Wu <[email protected]>--- Documentation/virtual/kvm/devices/vfio.txt | 8 ++++++++ include/uapi/linux/kvm.h | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 0 deletions(-)Documentation/virtual/kvm/devices/vfio.txt +8
-0@@ -13,6 +13,7 @@ VFIO-group is held by KVM. Groups: KVM_DEV_VFIO_GROUP + KVM_DEV_VFIO_INTERRUPT KVM_DEV_VFIO_GROUP attributes: KVM_DEV_VFIO_GROUP_ADD: Add a VFIO group to VFIO-KVM device tracking@@ -20,3 +21,10 @@ KVM_DEV_VFIO_GROUP attributes: For each, kvm_device_attr.addr points to an int32_t file descriptor for the VFIO group. + +KVM_DEV_VFIO_INTERRUPT attributes: + KVM_DEV_VFIO_INTERRUPT_POSTING_IRQ: Set up the interrupt configuration for +VT-d Posted-Interrrupts + +For each, kvm_device_attr.addr points to struct kvm_posted_intr, which +include the needed information for VT-d Posted-Interrupts setup.include/uapi/linux/kvm.h +0
-0@@ -943,9 +943,23 @@ struct kvm_device_attr {__u64 addr;/* userspace address of attr data */ };
include/uapi/linux/kvm.h struct kvm_device_attr { · line 954
Quoted 10 lines
include/uapi/linux/kvm.h +9
-0+struct virq_info { +__u32 index;/* index of the msi/msix entry */ +int virq;/* virq of the interrupt */ +}; + +struct kvm_posted_intr { +__u32 fd;/* file descriptor of the VFIO device */ +__u32 count; +bool msix;
Note that MSI-X (as opposed to MSI) is a PCI concept. Being a VFIO interface this should operate at VFIO IRQ index and sub-index.
Quoted 11 lines
include/uapi/linux/kvm.h +5
-0+struct virq_info virq_info[0 ]; +}; +#define KVM_DEV_VFIO_GROUP 1#define KVM_DEV_VFIO_GROUP_ADD 1#define KVM_DEV_VFIO_GROUP_DEL 2 +#define KVM_DEV_VFIO_INTERRUPT 2 +#define KVM_DEV_VFIO_INTERRUPT_POSTING_IRQ 1enum kvm_device_type {KVM_DEV_TYPE_FSL_MPIC_20 =1 ,
Re: [RFC PATCH v1 1/2] vfio: Add new interrupt group for VFIO
Quoted 10 lines · Alex Williamson
Quoted 4 lines · Feng Wu
Add new group
KVM_DEV_VFIO_INTERRUPTand commandKVM_DEV_VFIO_DEVIE_POSTING_IRQrelated to it.This is used for VT-d Posted-Interrupts setup.
Eric proposed an interface for ARM forwarded interrupts[1] using group
KVM_DEV_VFIO_DEVICEwith attributesKVM_DEV_VFIO_DEVICE_ASSIGN_IRQandKVM_DEV_VFIO_DEVICE_DEASSIGN_IRQ. Why are we proposing yet another group and attributes here? Why can't we re-use the ones Eric proposes?
Hi Alex, Feng
I share your point of view about the KVM_DEV_VFIO_DEVICE group. For the attribute (renamed KVM_DEV_VFIO_DEVICE_FORWARD_IRQ in RFC v2) the issue is I specify the kvm_device_attr.addr points to a kvm_arch_forwarded_irq struct. Feng needs another struct - kvm_posted_intr -. An alternative is to merge both structs if it makes sense.
Best Regards
Eric
Quoted 67 lines
[1] https://lkml.org/lkml/2014/8/25/258
Quoted 36 lines
Signed-off-by Feng Wu <[email protected]>--- Documentation/virtual/kvm/devices/vfio.txt | 8 ++++++++ include/uapi/linux/kvm.h | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 0 deletions(-)Documentation/virtual/kvm/devices/vfio.txt +8
-0@@ -13,6 +13,7 @@ VFIO-group is held by KVM. Groups: KVM_DEV_VFIO_GROUP + KVM_DEV_VFIO_INTERRUPT KVM_DEV_VFIO_GROUP attributes: KVM_DEV_VFIO_GROUP_ADD: Add a VFIO group to VFIO-KVM device tracking@@ -20,3 +21,10 @@ KVM_DEV_VFIO_GROUP attributes: For each, kvm_device_attr.addr points to an int32_t file descriptor for the VFIO group. + +KVM_DEV_VFIO_INTERRUPT attributes: + KVM_DEV_VFIO_INTERRUPT_POSTING_IRQ: Set up the interrupt configuration for +VT-d Posted-Interrrupts + +For each, kvm_device_attr.addr points to struct kvm_posted_intr, which +include the needed information for VT-d Posted-Interrupts setup.include/uapi/linux/kvm.h +0
-0@@ -943,9 +943,23 @@ struct kvm_device_attr {__u64 addr;/* userspace address of attr data */ };include/uapi/linux/kvm.h struct kvm_device_attr { · line 954
Quoted 10 lines
include/uapi/linux/kvm.h +9
-0+struct virq_info { +__u32 index;/* index of the msi/msix entry */ +int virq;/* virq of the interrupt */ +}; + +struct kvm_posted_intr { +__u32 fd;/* file descriptor of the VFIO device */ +__u32 count; +bool msix;Note that MSI-X (as opposed to MSI) is a PCI concept. Being a VFIO interface this should operate at VFIO IRQ index and sub-index.
Quoted 11 lines
include/uapi/linux/kvm.h +5
-0+struct virq_info virq_info[0 ]; +}; +#define KVM_DEV_VFIO_GROUP 1#define KVM_DEV_VFIO_GROUP_ADD 1#define KVM_DEV_VFIO_GROUP_DEL 2 +#define KVM_DEV_VFIO_INTERRUPT 2 +#define KVM_DEV_VFIO_INTERRUPT_POSTING_IRQ 1enum kvm_device_type {KVM_DEV_TYPE_FSL_MPIC_20 =1 ,
A message that is not in the archive (sent off-list or not yet received): E959C4978C3B6342920538CF579893F0022A8711@SHSMSX104.ccr.corp.intel.com
Re: [RFC PATCH v1 1/2] vfio: Add new interrupt group for VFIO
Quoted 21 lines · Feng
Quoted 12 lines
-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Thursday, November 20, 2014 11:54 PM
To: Wu, Feng
Cc: [email protected]; [email protected]; eric.auger
Subject: Re: [RFC PATCH v1 1/2] vfio: Add new interrupt group for VFIOQuoted 3 lines · Feng Wu
Add new group
KVM_DEV_VFIO_INTERRUPTand commandKVM_DEV_VFIO_DEVIE_POSTING_IRQrelated to it.Quoted 8 lines
Quoted 1 line
This is used for VT-d Posted-Interrupts setup.
Eric proposed an interface for ARM forwarded interrupts[1] using group
KVM_DEV_VFIO_DEVICEwith attributesKVM_DEV_VFIO_DEVICE_ASSIGN_IRQandKVM_DEV_VFIO_DEVICE_DEASSIGN_IRQ. Why are we proposing yet another group and attributes here? Why can't we re-use the ones Eric proposes?
Quoted 3 lines
I totally agree that I can reuse Eric's proposals. However, as Eric mentioned in his reply, I am using another data structure. So how about adding my own attribute, say,
KVM_DEV_VFIO_DEVICE_POSTING_IRQin groupKVM_DEV_VFIO_DEVICE.
Right, Eric's latest proposal (sorry I picked the v1 links by mistake in my previous reply) includes:
KVM_DEV_VFIO_DEVICE attributes:
KVM_DEV_VFIO_DEVICE_FORWARD_IRQ
KVM_DEV_VFIO_DEVICE_UNFORWARD_IRQ
So I think we'd want to add something similar for posted interrupts, some sort of "start" and "stop" attribute. At the QEMU level we'll want to abstract both of these as opportunistic IRQ accelerators, but at the KVM-VFIO level we probably need to make them distinct using a separate set of attributes. Who knows, maybe one day ARM will support posted interrupts and Intel will support forwarding... I expect the calls from the KVM-VFIO device into VFIO at the kernel level to be largely the same between the different attributes though. Thanks,
Alex
Quoted 75 lines
Quoted 42 lines
[1] https://lkml.org/lkml/2014/8/25/258
Review
Quoted 7 lines
Signed-off-by Feng Wu <[email protected]>--- Documentation/virtual/kvm/devices/vfio.txt | 8 ++++++++ include/uapi/linux/kvm.h | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 0 deletions(-)(quoted diff) +0
-0
b/Documentation/virtual/kvm/devices/vfio.txtDocumentation/virtual/kvm/devices/vfio.txt VFIO-group is held by KVM. · line 19
Quoted 11 lines
index ef51740..bd99176 100644
Documentation/virtual/kvm/devices/vfio.txt +1
-0@@ -13,6 +13,7 @@ VFIO-group is held by KVM. Groups: KVM_DEV_VFIO_GROUP + KVM_DEV_VFIO_INTERRUPT KVM_DEV_VFIO_GROUP attributes: KVM_DEV_VFIO_GROUP_ADD: Add a VFIO group to VFIO-KVM devicetracking
Documentation/virtual/kvm/devices/vfio.txt KVM_DEV_VFIO_GROUP attributes: · line 26
Quoted 7 lines
Documentation/virtual/kvm/devices/vfio.txt +3
-0@@ -20,3 +21,10 @@ KVM_DEV_VFIO_GROUP attributes: For each, kvm_device_attr.addr points to an int32_t file descriptor for the VFIO group. + +KVM_DEV_VFIO_INTERRUPT attributes: + KVM_DEV_VFIO_INTERRUPT_POSTING_IRQ: Set up the interruptconfiguration for
Quoted 12 lines
Documentation/virtual/kvm/devices/vfio.txt +4
-0+VT-d Posted-Interrrupts + +For each, kvm_device_attr.addr points to struct kvm_posted_intr, which +include the needed information for VT-d Posted-Interrupts setup.include/uapi/linux/kvm.h +0
-0@@ -943,9 +943,23 @@ struct kvm_device_attr {__u64 addr;/* userspace address of attr data */ };Quoted 12 lines
include/uapi/linux/kvm.h struct kvm_device_attr { · line 954
Quoted 9 lines
include/uapi/linux/kvm.h +9
-0+struct virq_info { +__u32 index;/* index of the msi/msix entry */ +int virq;/* virq of the interrupt */ +}; + +struct kvm_posted_intr { +__u32 fd;/* file descriptor of the VFIO device */ +__u32 count; +bool msix;Note that MSI-X (as opposed to MSI) is a PCI concept. Being a VFIO interface this should operate at VFIO IRQ index and sub-index.
Yes, I will use VFIO stuff instead.
Thanks,
FengQuoted 14 lines
Quoted 12 lines
include/uapi/linux/kvm.h +5
-0+struct virq_info virq_info[0 ]; +}; +#define KVM_DEV_VFIO_GROUP 1#define KVM_DEV_VFIO_GROUP_ADD 1#define KVM_DEV_VFIO_GROUP_DEL 2 +#define KVM_DEV_VFIO_INTERRUPT 2 +#define KVM_DEV_VFIO_INTERRUPT_POSTING_IRQ 1enum kvm_device_type {KVM_DEV_TYPE_FSL_MPIC_20 =1 ,
RFC PATCH 2/2 vfio: Add VFIO API vfio_msi_get_irq
In reply to Feng WuThis API returns the host irq for the MSI/MSI-X interrrupts.
--- drivers/vfio/pci/vfio_pci.c | 10 ++++++++++ include/linux/vfio.h | 2 ++ 2 files changed, 12 insertions(+), 0 deletions(-)
drivers/vfio/pci/vfio_pci.c +10 -0
@@ -1009,6 +1009,16 @@ put_devs:kfree (devs.devices); } +unsigned int vfio_msi_get_irq (struct vfio_device *device,int vector,bool msix) +{ +struct vfio_pci_device *vdev = + (struct vfio_pci_device *)vfio_device_data (device); +struct pci_dev *pdev = vdev->pdev; + +return msix ? vdev->msix[vector].vector : pdev->irq + vector; +} +EXPORT_SYMBOL_GPL (vfio_msi_get_irq); + static void __exit vfio_pci_cleanup(void) {pci_unregister_driver (&vfio_pci_driver);
include/linux/vfio.h +2 -0
@@ -92,6 +92,8 @@ extern void vfio_unregister_iommu_driver(/* * External user API */ +extern unsigned int vfio_msi_get_irq (struct vfio_device *device,int vector, +bool msix);extern struct vfio_group *vfio_group_get_external_user (struct file *filep);extern void vfio_group_put_external_user (struct vfio_group *group);extern int vfio_external_user_iommu_id (struct vfio_group *group);
Signature · 1 line
1.7.1
Re: [RFC PATCH v1 2/2] vfio: Add VFIO API vfio_msi_get_irq
Quoted 16 lines · Feng Wu
This API returns the host irq for the MSI/MSI-X interrrupts.
Signed-off-by Feng Wu <[email protected]>--- drivers/vfio/pci/vfio_pci.c | 10 ++++++++++ include/linux/vfio.h | 2 ++ 2 files changed, 12 insertions(+), 0 deletions(-)drivers/vfio/pci/vfio_pci.c +0
-0@@ -1009,6 +1009,16 @@ put_devs:kfree (devs.devices); }
drivers/vfio/pci/vfio_pci.c put_devs: · line 1021
Quoted 10 lines
drivers/vfio/pci/vfio_pci.c +10
-0+unsigned int vfio_msi_get_irq (struct vfio_device *device,int vector,bool msix) +{ +struct vfio_pci_device *vdev = + (struct vfio_pci_device *)vfio_device_data (device); +struct pci_dev *pdev = vdev->pdev; + +return msix ? vdev->msix[vector].vector : pdev->irq + vector; +} +EXPORT_SYMBOL_GPL (vfio_msi_get_irq); +
It's difficult to see what you're going to do with this, but it's making the assumption that the vfio_device is a vfio_pci_device, which is the wrong starting point. Eric proposed[1] some VFIO external user interface extensions, that have since been refined in discussion that allows the external user (KVM in this case) access to the struct device where it can get the IRQ vectors itself. We either need to follow that same path for posted interrupts, teaching KVM about struct pci_device in order to extract the IRQ info, or we need to create another vfio external user interface extension that can return IRQ info regardless of the device type. Thanks,
Alex
Quoted 16 lines
drivers/vfio/pci/vfio_pci.c +0
-0static void __exit vfio_pci_cleanup(void) {pci_unregister_driver (&vfio_pci_driver);include/linux/vfio.h +2
-0@@ -92,6 +92,8 @@ extern void vfio_unregister_iommu_driver(/* * External user API */ +extern unsigned int vfio_msi_get_irq (struct vfio_device *device,int vector, +bool msix);extern struct vfio_group *vfio_group_get_external_user (struct file *filep);extern void vfio_group_put_external_user (struct vfio_group *group);extern int vfio_external_user_iommu_id (struct vfio_group *group);
Re: [RFC PATCH v1 2/2] vfio: Add VFIO API vfio_msi_get_irq
Quoted 39 lines · Alex Williamson
Quoted 16 lines · Feng Wu
This API returns the host irq for the MSI/MSI-X interrrupts.
Signed-off-by Feng Wu <[email protected]>--- drivers/vfio/pci/vfio_pci.c | 10 ++++++++++ include/linux/vfio.h | 2 ++ 2 files changed, 12 insertions(+), 0 deletions(-)drivers/vfio/pci/vfio_pci.c +0
-0@@ -1009,6 +1009,16 @@ put_devs:kfree (devs.devices); }drivers/vfio/pci/vfio_pci.c put_devs: · line 1021
Quoted 10 lines
drivers/vfio/pci/vfio_pci.c +10
-0+unsigned int vfio_msi_get_irq (struct vfio_device *device,int vector,bool msix) +{ +struct vfio_pci_device *vdev = + (struct vfio_pci_device *)vfio_device_data (device); +struct pci_dev *pdev = vdev->pdev; + +return msix ? vdev->msix[vector].vector : pdev->irq + vector; +} +EXPORT_SYMBOL_GPL (vfio_msi_get_irq); +It's difficult to see what you're going to do with this, but it's making the assumption that the
vfio_deviceis avfio_pci_device, which is the wrong starting point. Eric proposed[1] some VFIO external user interface extensions, that have since been refined in discussion that allows the external user (KVM in this case) access to the struct device where it can get the IRQ vectors itself. We either need to follow that same path for posted interrupts, teaching KVM about structpci_devicein order to extract the IRQ info, or we need to create another vfio external user interface extension that can return IRQ info regardless of the device type. Thanks,
Quoted 4 lines
Alex
Here is the v2: https://lkml.org/lkml/2014/9/1/347
Best Regards
Eric
Quoted 20 lines
http://lwn.net/Articles/610087/
Quoted 16 lines
drivers/vfio/pci/vfio_pci.c +0
-0static void __exit vfio_pci_cleanup(void) {pci_unregister_driver (&vfio_pci_driver);include/linux/vfio.h +2
-0@@ -92,6 +92,8 @@ extern void vfio_unregister_iommu_driver(/* * External user API */ +extern unsigned int vfio_msi_get_irq (struct vfio_device *device,int vector, +bool msix);extern struct vfio_group *vfio_group_get_external_user (struct file *filep);extern void vfio_group_put_external_user (struct vfio_group *group);extern int vfio_external_user_iommu_id (struct vfio_group *group);