Simplify the module and kconfig structure in vfio
Subsystems (3)
v3 cover Simplify the module and kconfig structure in vfio
This series does a little house cleaning to remove the SPAPR exported symbols, presence in the public header file, and reduce the number of modules that comprise VFIO.
v3:
- New patch to fold SPAPR VFIO_CHECK_EXTENSION EEH code into the actual ioctl
- Remove the 'case VFIO_EEH_PE_OP' indenting level
- Just open code the calls and #ifdefs to eeh_dev_open()/release() instead of using inline wrappers
- Rebase to v6.1-rc1
v2: https://lore.kernel.org/r/[email protected]
- Add stubs for vfio_virqfd_init()/vfio_virqfd_exit() so that linking works even if vfio_pci/etc is not selected
v1: https://lore.kernel.org/r/[email protected]
Jason Gunthorpe (5):
vfio/pci: Move all the SPAPR PCI specific logic to vfio_pci_core.ko vfio/spapr: Move VFIO_CHECK_EXTENSION into tce_iommu_ioctl()
vfio: Move vfio_spapr_iommu_eeh_ioctl into vfio_iommu_spapr_tce.c
vfio: Remove CONFIG_VFIO_SPAPR_EEH
vfio: Fold vfio_virqfd.ko into vfio.ko
drivers/vfio/Kconfig | 7 +- drivers/vfio/Makefile | 5 +- drivers/vfio/pci/vfio_pci_core.c | 11 ++- drivers/vfio/pci/vfio_pci_priv.h | 1 - drivers/vfio/vfio.h | 13 ++++ drivers/vfio/vfio_iommu_spapr_tce.c | 75 ++++++++++++++++--- drivers/vfio/vfio_main.c | 7 ++ drivers/vfio/vfio_spapr_eeh.c | 107 ---------------------------- drivers/vfio/virqfd.c | 17 +---- include/linux/vfio.h | 23 ------ 10 files changed, 101 insertions(+), 165 deletions(-) delete mode 100644 drivers/vfio/vfio_spapr_eeh.c
base-commit: 9abf2313adc1ca1b6180c508c25f22f9395cc780
Signature · 1 line
2.38.0
PATCH v3 1/5 vfio/pci: Move all the SPAPR PCI specific logic to vfio_pci_core.ko
The vfio_spapr_pci_eeh_open/release() functions are one line wrappers around an arch function. Just call them directly and move them into vfio_pci_priv.h. This eliminates some weird exported symbols that don't need to exist.
--- drivers/vfio/pci/vfio_pci_core.c | 11 +++++++++-- drivers/vfio/pci/vfio_pci_priv.h | 1 - drivers/vfio/vfio_spapr_eeh.c | 13 ------------- include/linux/vfio.h | 11 ----------- 4 files changed, 9 insertions(+), 27 deletions(-)
drivers/vfio/pci/vfio_pci_core.c +9 -2
@@ -27,6 +27,9 @@#include <linux/vgaarb.h> #include <linux/nospec.h> #include <linux/sched/mm.h> +#if IS_ENABLED (CONFIG_VFIO_SPAPR_EEH ) +#include <asm/eeh.h> +#endif #include "vfio_pci_priv.h"
@@ -686,7 +689,9 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev) vdev->sriov_pf_core_dev->vf_token->users--;mutex_unlock (&vdev->sriov_pf_core_dev->vf_token->lock); } -vfio_spapr_pci_eeh_release (vdev->pdev); +#if IS_ENABLED (CONFIG_VFIO_SPAPR_EEH ) +eeh_dev_release (vdev->pdev); +#endif vfio_pci_core_disable (vdev);mutex_lock (&vdev->igate);
@@ -705,7 +710,9 @@ EXPORT_SYMBOL_GPL(vfio_pci_core_close_device);void vfio_pci_core_finish_enable (struct vfio_pci_core_device *vdev) {vfio_pci_probe_mmaps (vdev); -vfio_spapr_pci_eeh_open (vdev->pdev); +#if IS_ENABLED (CONFIG_VFIO_SPAPR_EEH ) +eeh_dev_open (vdev->pdev); +#endif if (vdev->sriov_pf_core_dev) {mutex_lock (&vdev->sriov_pf_core_dev->vf_token->lock);
drivers/vfio/pci/vfio_pci_priv.h +0 -1
@@ -100,5 +100,4 @@ static inline bool vfio_pci_is_vga(struct pci_dev *pdev) {return (pdev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA ; } -#endif
drivers/vfio/vfio_spapr_eeh.c +0 -13
@@ -15,19 +15,6 @@#define DRIVER_AUTHOR "Gavin Shan, IBM Corporation"#define DRIVER_DESC "VFIO IOMMU SPAPR EEH" -/* We might build address mapping here for "fast" path later */ -void vfio_spapr_pci_eeh_open (struct pci_dev *pdev) -{ -eeh_dev_open (pdev); -} -EXPORT_SYMBOL_GPL (vfio_spapr_pci_eeh_open); - -void vfio_spapr_pci_eeh_release (struct pci_dev *pdev) -{ -eeh_dev_release (pdev); -} -EXPORT_SYMBOL_GPL (vfio_spapr_pci_eeh_release); -long vfio_spapr_iommu_eeh_ioctl (struct iommu_group *group,unsigned int cmd,unsigned long arg) {
include/linux/vfio.h +0 -11
@@ -231,21 +231,10 @@ int vfio_set_irqs_validate_and_prepare(struct vfio_irq_set *hdr, int num_irqs, int max_irq_type, size_t *data_size); -struct pci_dev ;#if IS_ENABLED (CONFIG_VFIO_SPAPR_EEH ) -void vfio_spapr_pci_eeh_open (struct pci_dev *pdev); -void vfio_spapr_pci_eeh_release (struct pci_dev *pdev);long vfio_spapr_iommu_eeh_ioctl (struct iommu_group *group,unsigned int cmd,unsigned long arg);#else -static inline void vfio_spapr_pci_eeh_open (struct pci_dev *pdev) -{ -} - -static inline void vfio_spapr_pci_eeh_release (struct pci_dev *pdev) -{ -} -static inline long vfio_spapr_iommu_eeh_ioctl (struct iommu_group *group,unsigned int cmd,unsigned long arg)
Signature · 1 line
2.38.0
Re: [PATCH v3 1/5] vfio/pci: Move all the SPAPR PCI specific logic to vfio_pci_core.ko
Looks good:
PATCH v3 2/5 vfio/spapr: Move VFIO_CHECK_EXTENSION into tce_iommu_ioctl()
In reply to Jason GunthorpeThe PPC64 kconfig is a bit of a rats nest, but it turns out that if CONFIG_SPAPR_TCE_IOMMU is on then EEH must be too:
config SPAPR_TCE_IOMMU
bool "sPAPR TCE IOMMU Support"
depends on PPC_POWERNV || PPC_PSERIES
select IOMMU_API
help
Enables bits of IOMMU API required by VFIO. The iommu_ops is not implemented as it is not necessary for VFIO.
config PPC_POWERNV
select FORCE_PCI
config PPC_PSERIES
select FORCE_PCI
config EEH
bool depends on (PPC_POWERNV || PPC_PSERIES) && PCI default y
So, just open code the call to eeh_enabled() into tce_iommu_ioctl().
--- drivers/vfio/vfio_iommu_spapr_tce.c | 10 ++++------ drivers/vfio/vfio_spapr_eeh.c | 6 ------ 2 files changed, 4 insertions(+), 12 deletions(-)
drivers/vfio/vfio_iommu_spapr_tce.c +4 -6
@@ -785,14 +785,12 @@ static long tce_iommu_ioctl(void *iommu_data,switch (arg) {case VFIO_SPAPR_TCE_IOMMU :case VFIO_SPAPR_TCE_v2_IOMMU: - ret =1 ; -break ; +return 1 ; +case VFIO_EEH : +return eeh_enabled ();default : - ret =vfio_spapr_iommu_eeh_ioctl (NULL , cmd, arg); -break ; +return 0 ; } - -return (ret <0 ) ?0 : ret; }/*
drivers/vfio/vfio_spapr_eeh.c +0 -6
@@ -24,12 +24,6 @@ long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group,long ret = -EINVAL ;switch (cmd) { -case VFIO_CHECK_EXTENSION : -if (arg ==VFIO_EEH ) - ret =eeh_enabled () ?1 :0 ; -else - ret =0 ; -break ;case VFIO_EEH_PE_OP : pe =eeh_iommu_group_to_pe (group);if (!pe)
Signature · 1 line
2.38.0
Re: [PATCH v3 2/5] vfio/spapr: Move VFIO_CHECK_EXTENSION into tce_iommu_ioctl()
Looks good:
Re: [PATCH v3 2/5] vfio/spapr: Move VFIO_CHECK_EXTENSION into tce_iommu_ioctl()
In reply to Jason GunthorpeQuoted 22 lines · Jason Gunthorpe
The PPC64 kconfig is a bit of a rats nest, but it turns out that if
CONFIG_SPAPR_TCE_IOMMUis on then EEH must be too:config
SPAPR_TCE_IOMMU
bool "sPAPR TCE IOMMU Support"
depends onPPC_POWERNV||PPC_PSERIES
selectIOMMU_API
help
Enables bits of IOMMU API required by VFIO. Theiommu_opsis not implemented as it is not necessary for VFIO.config
PPC_POWERNV
selectFORCE_PCIconfig
PPC_PSERIES
selectFORCE_PCIconfig EEH
bool depends on (PPC_POWERNV || PPC_PSERIES) && PCI default y
Quoted 7 lines
So, just open code the call to
eeh_enabled()intotce_iommu_ioctl().Signed-off-by Jason Gunthorpe <[email protected]>--- drivers/vfio/vfio_iommu_spapr_tce.c | 10 ++++------ drivers/vfio/vfio_spapr_eeh.c | 6 ------ 2 files changed, 4 insertions(+), 12 deletions(-)
PATCH v3 3/5 vfio: Move vfio_spapr_iommu_eeh_ioctl into vfio_iommu_spapr_tce.c
In reply to Jason GunthorpeAs with the previous patch EEH is always enabled if SPAPR_TCE_IOMMU, so move this last bit of code into the main module.
Now that this function only processes VFIO_EEH_PE_OP remove a level of indenting as well, it is only called by a case statement that already checked VFIO_EEH_PE_OP.
This eliminates an unnecessary module and SPAPR code in a global header.
--- drivers/vfio/Makefile | 1 - drivers/vfio/vfio_iommu_spapr_tce.c | 65 ++++++++++++++++++++- drivers/vfio/vfio_spapr_eeh.c | 88 ----------------------------- include/linux/vfio.h | 12 ---- 4 files changed, 63 insertions(+), 103 deletions(-) delete mode 100644 drivers/vfio/vfio_spapr_eeh.c
drivers/vfio/Makefile +0 -1
@@ -10,7 +10,6 @@ vfio-y += vfio_main.o \ obj-$(CONFIG_VFIO_VIRQFD) += vfio_virqfd.o obj-$(CONFIG_VFIO_IOMMU_TYPE1) += vfio_iommu_type1.o obj-$(CONFIG_VFIO_IOMMU_SPAPR_TCE) += vfio_iommu_spapr_tce.o -obj-$(CONFIG_VFIO_SPAPR_EEH) += vfio_spapr_eeh.o obj-$(CONFIG_VFIO_PCI) += pci/ obj-$(CONFIG_VFIO_PLATFORM) += platform/ obj-$(CONFIG_VFIO_MDEV) += mdev/
drivers/vfio/vfio_iommu_spapr_tce.c +63 -2
77 lines not on this page · raw message
drivers/vfio/vfio_spapr_eeh.c deleted +0 -88
88 lines not on this page · raw message
include/linux/vfio.h +0 -12
@@ -231,18 +231,6 @@ int vfio_set_irqs_validate_and_prepare(struct vfio_irq_set *hdr, int num_irqs, int max_irq_type, size_t *data_size); -#if IS_ENABLED (CONFIG_VFIO_SPAPR_EEH ) -long vfio_spapr_iommu_eeh_ioctl (struct iommu_group *group,unsigned int cmd, -unsigned long arg); -#else -static inline long vfio_spapr_iommu_eeh_ioctl (struct iommu_group *group, -unsigned int cmd, -unsigned long arg) -{ -return -ENOTTY ; -} -#endif /* CONFIG_VFIO_SPAPR_EEH */ -/* * IRQfd - generic */
Signature · 1 line
2.38.0
Re: [PATCH v3 3/5] vfio: Move vfio_spapr_iommu_eeh_ioctl into vfio_iommu_spapr_tce.c
drivers/vfio/vfio_iommu_spapr_tce.c static long tce_iommu_create_default_window(struct tce_container *container) · line 800
Quoted 7 lines
drivers/vfio/vfio_iommu_spapr_tce.c +7
-0+switch (op.op) { +case VFIO_EEH_PE_DISABLE : + ret =eeh_pe_set_option (pe,EEH_OPT_DISABLE ); +break ; +case VFIO_EEH_PE_ENABLE : + ret =eeh_pe_set_option (pe,EEH_OPT_ENABLE ); +break ;
This could be simplified a bit more by moving the return from the end of the function into the switch statements.
Quoted 1 line
- * Copyright Gavin Shan, IBM Corporation 2014.
This notice needs to move over to vfio_iommu_spapr_tce.c.
Otherwise looks good:
Re: [PATCH v3 3/5] vfio: Move vfio_spapr_iommu_eeh_ioctl into vfio_iommu_spapr_tce.c
Quoted 10 lines · Christoph Hellwig
drivers/vfio/vfio_iommu_spapr_tce.c static long tce_iommu_create_default_window(struct tce_container *container) · line 800
Quoted 7 lines
drivers/vfio/vfio_iommu_spapr_tce.c +7
-0+switch (op.op) { +case VFIO_EEH_PE_DISABLE : + ret =eeh_pe_set_option (pe,EEH_OPT_DISABLE ); +break ; +case VFIO_EEH_PE_ENABLE : + ret =eeh_pe_set_option (pe,EEH_OPT_ENABLE ); +break ;This could be simplified a bit more by moving the return from the end of the function into the switch statements.
Yes, all the rets can go away
Quoted 3 lines
Quoted 1 line
- * Copyright Gavin Shan, IBM Corporation 2014.
This notice needs to move over to
vfio_iommu_spapr_tce.c.
Ok
Thanks,
Jason
PATCH v3 4/5 vfio: Remove CONFIG_VFIO_SPAPR_EEH
In reply to Jason GunthorpeWe don't need a kconfig symbol for this, just directly test CONFIG_EEH in the one remaining place that needs it.
--- drivers/vfio/Kconfig | 5 ----- drivers/vfio/pci/vfio_pci_core.c | 6 +++--- 2 files changed, 3 insertions(+), 8 deletions(-)
drivers/vfio/Kconfig +0 -5
@@ -20,11 +20,6 @@ config VFIO_IOMMU_SPAPR_TCE depends on SPAPR_TCE_IOMMU default VFIO -config VFIO_SPAPR_EEH - tristate - depends on EEH && VFIO_IOMMU_SPAPR_TCE - default VFIO - config VFIO_VIRQFD tristate select EVENTFD
drivers/vfio/pci/vfio_pci_core.c +3 -3
@@ -27,7 +27,7 @@#include <linux/vgaarb.h> #include <linux/nospec.h> #include <linux/sched/mm.h> -#if IS_ENABLED (CONFIG_VFIO_SPAPR_EEH ) +#if IS_ENABLED (CONFIG_EEH ) &&IS_ENABLED (CONFIG_VFIO_IOMMU_SPAPR_TCE )#include <asm/eeh.h> #endif
@@ -689,7 +689,7 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev) vdev->sriov_pf_core_dev->vf_token->users--;mutex_unlock (&vdev->sriov_pf_core_dev->vf_token->lock); } -#if IS_ENABLED (CONFIG_VFIO_SPAPR_EEH ) +#if IS_ENABLED (CONFIG_EEH ) &&IS_ENABLED (CONFIG_VFIO_IOMMU_SPAPR_TCE )eeh_dev_release (vdev->pdev);#endif vfio_pci_core_disable (vdev);
@@ -710,7 +710,7 @@ EXPORT_SYMBOL_GPL(vfio_pci_core_close_device);void vfio_pci_core_finish_enable (struct vfio_pci_core_device *vdev) {vfio_pci_probe_mmaps (vdev); -#if IS_ENABLED (CONFIG_VFIO_SPAPR_EEH ) +#if IS_ENABLED (CONFIG_EEH ) &&IS_ENABLED (CONFIG_VFIO_IOMMU_SPAPR_TCE )eeh_dev_open (vdev->pdev);#endif
Signature · 1 line
2.38.0
Re: [PATCH v3 4/5] vfio: Remove CONFIG_VFIO_SPAPR_EEH
drivers/vfio/pci/vfio_pci_core.c void vfio_pci_core_close_device(struct vfio_device *core_vdev) · line 692
Quoted 10 lines
drivers/vfio/pci/vfio_pci_core.c +2
-1+#if IS_ENABLED (CONFIG_EEH ) &&IS_ENABLED (CONFIG_VFIO_IOMMU_SPAPR_TCE )#include <asm/eeh.h> #endif @@ -689,7 +689,7 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev) vdev->sriov_pf_core_dev->vf_token->users--;mutex_unlock (&vdev->sriov_pf_core_dev->vf_token->lock); } -#if IS_ENABLED (CONFIG_VFIO_SPAPR_EEH ) +#if IS_ENABLED (CONFIG_EEH ) &&IS_ENABLED (CONFIG_VFIO_IOMMU_SPAPR_TCE )
So while this preserves the existing behavior, I wonder if checking CONFIG_EEH only would make more sense here.
Re: [PATCH v3 4/5] vfio: Remove CONFIG_VFIO_SPAPR_EEH
Quoted 4 lines · Christoph Hellwig
Quoted 4 lines
+#if
IS_ENABLED(CONFIG_EEH)&&IS_ENABLED(CONFIG_VFIO_IOMMU_SPAPR_TCE)
#include <asm/eeh.h>
#endif
Quoted 9 lines
drivers/vfio/pci/vfio_pci_core.c void vfio_pci_core_close_device(struct vfio_device *core_vdev) · line 692
Quoted 6 lines
drivers/vfio/pci/vfio_pci_core.c +1
-1@@ -689,7 +689,7 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev) vdev->sriov_pf_core_dev->vf_token->users--;mutex_unlock (&vdev->sriov_pf_core_dev->vf_token->lock); } -#if IS_ENABLED (CONFIG_VFIO_SPAPR_EEH ) +#if IS_ENABLED (CONFIG_EEH ) &&IS_ENABLED (CONFIG_VFIO_IOMMU_SPAPR_TCE )So while this preserves the existing behavior, I wonder if checking
CONFIG_EEHonly would make more sense here.
Yes, it does read better, done
Thanks,
Jason
PATCH v3 5/5 vfio: Fold vfio_virqfd.ko into vfio.ko
In reply to Jason GunthorpeThis is only 1.8k, putting it in its own module is not really necessary. The kconfig infrastructure is still there to completely remove it for systems that are trying for small footprint.
Put it in the main vfio.ko module now that kbuild can support multiple .c files.
--- drivers/vfio/Kconfig | 2 +- drivers/vfio/Makefile | 4 +--- drivers/vfio/vfio.h | 13 +++++++++++++ drivers/vfio/vfio_main.c | 7 +++++++ drivers/vfio/virqfd.c | 17 +++-------------- 5 files changed, 25 insertions(+), 18 deletions(-)
drivers/vfio/Kconfig +1 -1
@@ -21,7 +21,7 @@ config VFIO_IOMMU_SPAPR_TCE default VFIO config VFIO_VIRQFD - tristate + bool select EVENTFD default n
drivers/vfio/Makefile +1 -3
@@ -1,13 +1,11 @@ # SPDX-License-Identifier: GPL-2.0 -vfio_virqfd-y := virqfd.o - obj-$(CONFIG_VFIO) += vfio.o vfio-y += vfio_main.o \ iova_bitmap.o \ container.o +vfio-$(CONFIG_VFIO_VIRQFD) += virqfd.o -obj-$(CONFIG_VFIO_VIRQFD) += vfio_virqfd.o obj-$(CONFIG_VFIO_IOMMU_TYPE1) += vfio_iommu_type1.o obj-$(CONFIG_VFIO_IOMMU_SPAPR_TCE) += vfio_iommu_spapr_tce.o obj-$(CONFIG_VFIO_PCI) += pci/
drivers/vfio/vfio.h +13 -0
@@ -124,6 +124,19 @@ long vfio_container_ioctl_check_extension(struct vfio_container *container,int __init vfio_container_init (void );void vfio_container_cleanup (void ); +#if IS_ENABLED (CONFIG_VFIO_VIRQFD ) +int __init vfio_virqfd_init (void ); +void vfio_virqfd_exit (void ); +#else +static inline int __init vfio_virqfd_init (void ) +{ +return 0 ; +} +static inline void vfio_virqfd_exit (void ) +{ +} +#endif +#ifdef CONFIG_VFIO_NOIOMMU extern bool vfio_noiommu__read_mostly ;#else
drivers/vfio/vfio_main.c +7 -0
@@ -1814,6 +1814,10 @@ static int __init vfio_init(void)if (ret)return ret; + ret =vfio_virqfd_init (); +if (ret) + goto err_virqfd; +/* /dev/vfio/$GROUP */ vfio.class =class_create (THIS_MODULE ,"vfio" );if (IS_ERR (vfio.class)) {
@@ -1844,6 +1848,8 @@ static int __init vfio_init(void)class_destroy (vfio.class); vfio.class =NULL ; err_group_class: +vfio_virqfd_exit (); +err_virqfd:vfio_container_cleanup ();return ret; }
@@ -1858,6 +1864,7 @@ static void __exit vfio_cleanup(void)class_destroy (vfio.device_class); vfio.device_class =NULL ;class_destroy (vfio.class); +vfio_virqfd_exit ();vfio_container_cleanup (); vfio.class =NULL ;xa_destroy (&vfio_device_set_xa);
drivers/vfio/virqfd.c +3 -14
@@ -12,15 +12,12 @@#include <linux/file.h> #include <linux/module.h> #include <linux/slab.h> - -#define DRIVER_VERSION "0.1" -#define DRIVER_AUTHOR "Alex Williamson <[email protected]>" -#define DRIVER_DESC "IRQFD support for VFIO bus drivers" +#include "vfio.h" static struct workqueue_struct *vfio_irqfd_cleanup_wq;static DEFINE_SPINLOCK (virqfd_lock); -static int __init vfio_virqfd_init (void ) +int __init vfio_virqfd_init (void ) { vfio_irqfd_cleanup_wq =create_singlethread_workqueue ("vfio-irqfd-cleanup" );
@@ -30,7 +27,7 @@ static int __init vfio_virqfd_init(void)return 0 ; } -static void __exit vfio_virqfd_exit(void) +void vfio_virqfd_exit (void ) {destroy_workqueue (vfio_irqfd_cleanup_wq); }
@@ -216,11 +213,3 @@ void vfio_virqfd_disable(struct virqfd **pvirqfd)flush_workqueue (vfio_irqfd_cleanup_wq); }EXPORT_SYMBOL_GPL (vfio_virqfd_disable); - -module_init (vfio_virqfd_init); -module_exit (vfio_virqfd_exit); - -MODULE_VERSION (DRIVER_VERSION ); -MODULE_LICENSE ("GPL v2" ); -MODULE_AUTHOR (DRIVER_AUTHOR ); -MODULE_DESCRIPTION (DRIVER_DESC );
Signature · 1 line
2.38.0