Simplify the module and kconfig structure in vfio
Subsystems (3)
v5 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.
v5:
- Reword commit messages
- Remove whitespace change from drivers/vfio/pci/vfio_pci_priv.h
v4: https://lore.kernel.org/r/[email protected]
- Copy IBM copyright header to vfio_iommu_spapr_tce.c
- Use "return" not "ret = " in vfio_spapr_ioctl_eeh_pe_op()
- Use just "#if IS_ENABLED(CONFIG_EEH)"
v3: https://lore.kernel.org/r/[email protected]
- 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/vfio.h | 13 ++++ drivers/vfio/vfio_iommu_spapr_tce.c | 65 ++++++++++++++--- drivers/vfio/vfio_main.c | 7 ++ drivers/vfio/vfio_spapr_eeh.c | 107 ---------------------------- drivers/vfio/virqfd.c | 17 +---- include/linux/vfio.h | 23 ------ 9 files changed, 91 insertions(+), 164 deletions(-) delete mode 100644 drivers/vfio/vfio_spapr_eeh.c
base-commit: 9abf2313adc1ca1b6180c508c25f22f9395cc780
Signature · 1 line
2.38.1
PATCH v5 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. This eliminates some weird exported symbols that don't need to exist.
--- drivers/vfio/pci/vfio_pci_core.c | 11 +++++++++-- drivers/vfio/vfio_spapr_eeh.c | 13 ------------- include/linux/vfio.h | 11 ----------- 3 files changed, 9 insertions(+), 26 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/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.1
Re: [PATCH v5 1/5] vfio/pci: Move all the SPAPR PCI specific logic to vfio_pci_core.ko
Quoted 11 lines · Jason Gunthorpe
The vfio_spapr_pci_eeh_open/release() functions are one line wrappers around an arch function. Just call them directly. This eliminates some weird exported symbols that don't need to exist.
Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Jason Gunthorpe <[email protected]>--- drivers/vfio/pci/vfio_pci_core.c | 11 +++++++++-- drivers/vfio/vfio_spapr_eeh.c | 13 ------------- include/linux/vfio.h | 11 ----------- 3 files changed, 9 insertions(+), 26 deletions(-)
PATCH v5 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.1
PATCH v5 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 | 55 +++++++++++++++++- drivers/vfio/vfio_spapr_eeh.c | 88 ----------------------------- include/linux/vfio.h | 12 ---- 4 files changed, 53 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 +53 -2
73 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.1
PATCH v5 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 few places that need 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 )#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 )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 )eeh_dev_open (vdev->pdev);#endif
Signature · 1 line
2.38.1
PATCH v5 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.1
Re: [PATCH v5 5/5] vfio: Fold vfio_virqfd.ko into vfio.ko
Quoted 7 lines · Jason Gunthorpe
This 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.
Quoted 8 lines
Signed-off-by Jason Gunthorpe <[email protected]>--- 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(-)
Alex Williamson
AppliedQuoted 44 lines · On Mon, 5 Dec 2022 11:29:15 -0400 Jason Gunthorpe <[email protected]> wrote:
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.
v5:
- Reword commit messages
- Remove whitespace change fromdrivers/vfio/pci/vfio_pci_priv.h
v4: https://lore.kernel.org/r/[email protected]
- Copy IBM copyright header tovfio_iommu_spapr_tce.c
- Use "return" not "ret = " invfio_spapr_ioctl_eeh_pe_op()
- Use just "#ifIS_ENABLED(CONFIG_EEH)"
v3: https://lore.kernel.org/r/[email protected]
- New patch to fold SPAPRVFIO_CHECK_EXTENSIONEEH code into the actual ioctl
- Remove the 'caseVFIO_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]Signed-off-by Jason Gunthorpe <[email protected]>Jason Gunthorpe (5):
vfio/pci: Move all the SPAPR PCI specific logic to vfio_pci_core.ko vfio/spapr: MoveVFIO_CHECK_EXTENSIONintotce_iommu_ioctl()
vfio: Movevfio_spapr_iommu_eeh_ioctlintovfio_iommu_spapr_tce.c
vfio: RemoveCONFIG_VFIO_SPAPR_EEH
vfio: Fold vfio_virqfd.ko into vfio.kodrivers/vfio/Kconfig | 7 +- drivers/vfio/Makefile | 5 +- drivers/vfio/pci/vfio_pci_core.c | 11 ++- drivers/vfio/vfio.h | 13 ++++ drivers/vfio/vfio_iommu_spapr_tce.c | 65 ++++++++++++++--- drivers/vfio/vfio_main.c | 7 ++ drivers/vfio/vfio_spapr_eeh.c | 107 ---------------------------- drivers/vfio/virqfd.c | 17 +---- include/linux/vfio.h | 23 ------ 9 files changed, 91 insertions(+), 164 deletions(-) delete mode 100644 drivers/vfio/vfio_spapr_eeh.c
Quoted 1 line
base-commit:
9abf2313adc1ca1b6180c508c25f22f9395cc780
Applied to vfio next branch for v6.2. Thanks,
Alex