genirq/msi: add wrapper msi allocation API and export msi functions
Subsystems (5)
Nipun Gupta
maintainerPATCH v6 1/2 genirq/msi: add wrapper msi allocation API and export msi functions
SI functions for allocation and free can be directly used by the device drivers without any wrapper provided by bus drivers. So export these MSI functions.
Also, add a wrapper API to allocate MSIs providing only the number of interrupts rather than range for simpler driver usage.
---
No change in v5->v6
Changes in v4->v5:
- updated commit description as per the comments.
- Rebased on 6.9-rc1
Changes in v3->v4:
- No change
Changes in v3:
- New in this patch series. VFIO-CDX uses the new wrapper API msi_domain_alloc_irqs and exported APIs. (This patch is moved from CDX interrupt support to vfio-cdx patch, where these APIs are used).
include/linux/msi.h | 6 ++++++ kernel/irq/msi.c | 2 ++ 2 files changed, 8 insertions(+)
include/linux/msi.h +6 -0
@@ -674,6 +674,12 @@ int platform_device_msi_init_and_alloc_irqs(struct device *dev, unsigned int nvevoid platform_device_msi_free_irqs_all (struct device *dev);bool msi_device_has_isolated_msi (struct device *dev); + +static inline int msi_domain_alloc_irqs (struct device *dev,unsigned int domid,int nirqs) +{ +return msi_domain_alloc_irqs_range (dev, domid,0 , nirqs -1 ); +} +#else /* CONFIG_GENERIC_MSI_IRQ */ static inline bool msi_device_has_isolated_msi (struct device *dev) {
kernel/irq/msi.c +2 -0
@@ -1434,6 +1434,7 @@ int msi_domain_alloc_irqs_range(struct device *dev, unsigned int domid,msi_unlock_descs (dev);return ret; } +EXPORT_SYMBOL_GPL (msi_domain_alloc_irqs_range);/** * msi_domain_alloc_irqs_all_locked - Allocate all interrupts from a MSI interrupt domain
@@ -1680,6 +1681,7 @@ void msi_domain_free_irqs_range(struct device *dev, unsigned int domid,msi_domain_free_irqs_range_locked (dev, domid, first, last);msi_unlock_descs (dev); } +EXPORT_SYMBOL_GPL (msi_domain_free_irqs_all);/** * msi_domain_free_irqs_all_locked - Free all interrupts from a MSI interrupt domain
Signature · 1 line
2.34.1
Nipun Gupta
maintainerPATCH v6 2/2 vfio/cdx: add interrupt support
Support the following ioctls for CDX devices:
- VFIO_DEVICE_GET_IRQ_INFO
- VFIO_DEVICE_SET_IRQS
This allows user to set an eventfd for cdx device interrupts and trigger this interrupt eventfd from userspace.
All CDX device interrupts are MSIs. The MSIs are allocated from the CDX-MSI domain.
---
Changes v5->v6:
- add support for DATA_BOOL
- rename irq_count to msi_count
- fix sending irq_index as 0 in vfio_cdx_set_msi_trigger()
- fix return value in vfio_cdx_ioctl_get_irq_info() when msi are not supported on a CDX device
- reorder data fields in vfio_cdx_region to avoid holes
Changes v4->v5:
- Rebased on 6.9-rc1
Changes v3->v4:
- Added VFIO_IRQ_INFO_NORESIZE flag
Changes v2->v3:
- Use generic MSI alloc/free APIs instead of CDX MSI APIs
- Rebased on Linux 6.8-rc6
Changes v1->v2:
- Rebased on Linux 6.7-rc1
drivers/vfio/cdx/Makefile | 2 +- drivers/vfio/cdx/intr.c | 217 +++++++++++++++++++++++++++++++++++++ drivers/vfio/cdx/main.c | 63 ++++++++++- drivers/vfio/cdx/private.h | 18 +++ 4 files changed, 298 insertions(+), 2 deletions(-) create mode 100644 drivers/vfio/cdx/intr.c
drivers/vfio/cdx/Makefile +1 -1
@@ -5,4 +5,4 @@ obj-$(CONFIG_VFIO_CDX) += vfio-cdx.o -vfio-cdx-objs := main.o +vfio-cdx-objs := main.o intr.o
drivers/vfio/cdx/intr.c new file +217 -0
217 lines not on this page · raw message
drivers/vfio/cdx/main.c +62 -1
87 lines not on this page · raw message
drivers/vfio/cdx/private.h +18 -0
@@ -13,6 +13,14 @@ static inline u64 vfio_cdx_index_to_offset(u32 index)return ((u64)(index) <<VFIO_CDX_OFFSET_SHIFT ); } +struct vfio_cdx_irq { +u32 flags; +u32 count; +int irq_no; +struct eventfd_ctx *trigger; +char *name; +}; +struct vfio_cdx_region {u32 flags;u32 type;
@@ -23,8 +31,18 @@ struct vfio_cdx_region {struct vfio_cdx_device {struct vfio_device vdev;struct vfio_cdx_region *regions; +struct vfio_cdx_irq *cdx_irqs;u32 flags;#define BME_SUPPORT BIT(0) +u32 msi_count; +u8 config_msi; }; +int vfio_cdx_set_irqs_ioctl (struct vfio_cdx_device *vdev, +u32 flags,unsigned int index, +unsigned int start,unsigned int count, +void *data); + +void vfio_cdx_irqs_cleanup (struct vfio_cdx_device *vdev); +#endif /* VFIO_CDX_PRIVATE_H */
Signature · 1 line
2.34.1
Quoted 1 line · On Tue, 23 Apr 2024 16:40:20 +0530 Nipun Gupta <[email protected]> wrote:
SI functions for allocation and free can be directly used by
We lost the ^M in this version.
Quoted 6 lines
the device drivers without any wrapper provided by bus drivers. So export these MSI functions.
Also, add a wrapper API to allocate MSIs providing only the number of interrupts rather than range for simpler driver usage.
Quoted 8 lines
Signed-off-by Nipun Gupta <[email protected]>Reviewed-by Thomas Gleixner <[email protected]>---
No change in
v5->v6Changes in
v4->v5:
- updated commit description as per the comments.
I see in https://lore.kernel.org/all/87edbyfj0d.ffs@tglx/ that Thomas also suggested a new subject:
genirq/msi: Add MSI allocation helper and export MSI functions
I'll address both of these on commit if there are no objections or further comments. Patch 2/ looks ok to me now as well. Thanks,
Alex
Quoted 52 lines
- Rebased on 6.9-rc1
Changes in
v3->v4:
- No changeChanges in v3:
- New in this patch series. VFIO-CDX uses the new wrapper APImsi_domain_alloc_irqsand exported APIs. (This patch is moved from CDX interrupt support to vfio-cdx patch, where these APIs are used).include/linux/msi.h | 6 ++++++ kernel/irq/msi.c | 2 ++ 2 files changed, 8 insertions(+)include/linux/msi.h +6
-0@@ -674,6 +674,12 @@ int platform_device_msi_init_and_alloc_irqs(struct device *dev, unsigned int nvevoid platform_device_msi_free_irqs_all (struct device *dev);bool msi_device_has_isolated_msi (struct device *dev); + +static inline int msi_domain_alloc_irqs (struct device *dev,unsigned int domid,int nirqs) +{ +return msi_domain_alloc_irqs_range (dev, domid,0 , nirqs -1 ); +} +#else /* CONFIG_GENERIC_MSI_IRQ */ static inline bool msi_device_has_isolated_msi (struct device *dev) {kernel/irq/msi.c +2
-0@@ -1434,6 +1434,7 @@ int msi_domain_alloc_irqs_range(struct device *dev, unsigned int domid,msi_unlock_descs (dev);return ret; } +EXPORT_SYMBOL_GPL (msi_domain_alloc_irqs_range);/** * msi_domain_alloc_irqs_all_locked - Allocate all interrupts from a MSI interrupt domain @@ -1680,6 +1681,7 @@ void msi_domain_free_irqs_range(struct device *dev, unsigned int domid,msi_domain_free_irqs_range_locked (dev, domid, first, last);msi_unlock_descs (dev); } +EXPORT_SYMBOL_GPL (msi_domain_free_irqs_all);/** * msi_domain_free_irqs_all_locked - Free all interrupts from a MSI interrupt domain
Quoted 7 lines · Alex Williamson
I see in https://lore.kernel.org/all/87edbyfj0d.ffs@tglx/ that Thomas also suggested a new subject:
genirq/msi: Add MSI allocation helper and export MSI functions
I'll address both of these on commit if there are no objections or further comments. Patch 2/ looks ok to me now as well. Thanks,
No objections from my side.
Alex Williamson
AppliedQuoted 22 lines · On Tue, 23 Apr 2024 15:09:20 -0600 Alex Williamson…
Quoted 1 line · On Tue, 23 Apr 2024 16:40:20 +0530 Nipun Gupta <[email protected]> wrote:
SI functions for allocation and free can be directly used by
We lost the ^M in this version.
Quoted 6 lines
the device drivers without any wrapper provided by bus drivers. So export these MSI functions.
Also, add a wrapper API to allocate MSIs providing only the number of interrupts rather than range for simpler driver usage.
Quoted 8 lines
Signed-off-by Nipun Gupta <[email protected]>Reviewed-by Thomas Gleixner <[email protected]>---
No change in
v5->v6Changes in
v4->v5:
- updated commit description as per the comments.
Quoted 7 lines
I see in https://lore.kernel.org/all/87edbyfj0d.ffs@tglx/ that Thomas also suggested a new subject:
genirq/msi: Add MSI allocation helper and export MSI functions
I'll address both of these on commit if there are no objections or further comments. Patch 2/ looks ok to me now as well. Thanks,
Applied series to vfio next branch for v6.10. Thanks,
Alex