diff mbox

[RFC,v1,2/2] vfio: Add VFIO API vfio_msi_get_irq

Message ID 1416474316-32159-3-git-send-email-feng.wu@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wu, Feng Nov. 20, 2014, 9:05 a.m. UTC
This API returns the host irq for the MSI/MSI-X interrrupts.

Signed-off-by: Feng Wu <feng.wu@intel.com>
---
 drivers/vfio/pci/vfio_pci.c |   10 ++++++++++
 include/linux/vfio.h        |    2 ++
 2 files changed, 12 insertions(+), 0 deletions(-)

Comments

Alex Williamson Nov. 20, 2014, 4:05 p.m. UTC | #1
On Thu, 2014-11-20 at 17:05 +0800, Feng Wu wrote:
> This API returns the host irq for the MSI/MSI-X interrrupts.
> 
> Signed-off-by: Feng Wu <feng.wu@intel.com>
> ---
>  drivers/vfio/pci/vfio_pci.c |   10 ++++++++++
>  include/linux/vfio.h        |    2 ++
>  2 files changed, 12 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
> index 9558da3..4fb9828 100644
> --- a/drivers/vfio/pci/vfio_pci.c
> +++ b/drivers/vfio/pci/vfio_pci.c
> @@ -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);
> +

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


[1] https://lkml.org/lkml/2014/8/25/257

>  static void __exit vfio_pci_cleanup(void)
>  {
>  	pci_unregister_driver(&vfio_pci_driver);
> diff --git a/include/linux/vfio.h b/include/linux/vfio.h
> index d320411..007ca55 100644
> --- a/include/linux/vfio.h
> +++ b/include/linux/vfio.h
> @@ -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);



--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Eric Auger Nov. 20, 2014, 4:12 p.m. UTC | #2
On 11/20/2014 05:05 PM, Alex Williamson wrote:
> On Thu, 2014-11-20 at 17:05 +0800, Feng Wu wrote:
>> This API returns the host irq for the MSI/MSI-X interrrupts.
>>
>> Signed-off-by: Feng Wu <feng.wu@intel.com>
>> ---
>>  drivers/vfio/pci/vfio_pci.c |   10 ++++++++++
>>  include/linux/vfio.h        |    2 ++
>>  2 files changed, 12 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
>> index 9558da3..4fb9828 100644
>> --- a/drivers/vfio/pci/vfio_pci.c
>> +++ b/drivers/vfio/pci/vfio_pci.c
>> @@ -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);
>> +
> 
> 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
> 
> 
> [1] https://lkml.org/lkml/2014/8/25/257

Here is the v2: https://lkml.org/lkml/2014/9/1/347

Best Regards

Eric
> http://lwn.net/Articles/610087/
>>  static void __exit vfio_pci_cleanup(void)
>>  {
>>  	pci_unregister_driver(&vfio_pci_driver);
>> diff --git a/include/linux/vfio.h b/include/linux/vfio.h
>> index d320411..007ca55 100644
>> --- a/include/linux/vfio.h
>> +++ b/include/linux/vfio.h
>> @@ -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);
> 
> 
> 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index 9558da3..4fb9828 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -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);
diff --git a/include/linux/vfio.h b/include/linux/vfio.h
index d320411..007ca55 100644
--- a/include/linux/vfio.h
+++ b/include/linux/vfio.h
@@ -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);