kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/5] Simplify the module and kconfig structure in vfio
@ 2022-10-17 18:38 Jason Gunthorpe
  2022-10-17 18:38 ` [PATCH v3 1/5] vfio/pci: Move all the SPAPR PCI specific logic to vfio_pci_core.ko Jason Gunthorpe
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Jason Gunthorpe @ 2022-10-17 18:38 UTC (permalink / raw)
  To: Alex Williamson, Cornelia Huck, kvm

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/0-v2-18daead6a41e+98-vfio_modules_jgg@nvidia.com
 - 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/0-v1-10a2dba77915+c23-vfio_modules_jgg@nvidia.com

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

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
-- 
2.38.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 1/5] vfio/pci: Move all the SPAPR PCI specific logic to vfio_pci_core.ko
  2022-10-17 18:38 [PATCH v3 0/5] Simplify the module and kconfig structure in vfio Jason Gunthorpe
@ 2022-10-17 18:38 ` Jason Gunthorpe
  2022-10-18  6:03   ` Christoph Hellwig
  2022-10-17 18:38 ` [PATCH v3 2/5] vfio/spapr: Move VFIO_CHECK_EXTENSION into tce_iommu_ioctl() Jason Gunthorpe
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Jason Gunthorpe @ 2022-10-17 18:38 UTC (permalink / raw)
  To: Alex Williamson, Cornelia Huck, kvm

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.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 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(-)

diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index badc9d828cac20..c8b8a7a03eae7e 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -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);
diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_priv.h
index 5e4fa69aee16c1..13c0858eb5df28 100644
--- a/drivers/vfio/pci/vfio_pci_priv.h
+++ b/drivers/vfio/pci/vfio_pci_priv.h
@@ -100,5 +100,4 @@ static inline bool vfio_pci_is_vga(struct pci_dev *pdev)
 {
 	return (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA;
 }
-
 #endif
diff --git a/drivers/vfio/vfio_spapr_eeh.c b/drivers/vfio/vfio_spapr_eeh.c
index 67f55ac1d459cc..c9d102aafbcd11 100644
--- a/drivers/vfio/vfio_spapr_eeh.c
+++ b/drivers/vfio/vfio_spapr_eeh.c
@@ -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)
 {
diff --git a/include/linux/vfio.h b/include/linux/vfio.h
index e7cebeb875dd1a..e8a5a9cdb9067f 100644
--- a/include/linux/vfio.h
+++ b/include/linux/vfio.h
@@ -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)
-- 
2.38.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 2/5] vfio/spapr: Move VFIO_CHECK_EXTENSION into tce_iommu_ioctl()
  2022-10-17 18:38 [PATCH v3 0/5] Simplify the module and kconfig structure in vfio Jason Gunthorpe
  2022-10-17 18:38 ` [PATCH v3 1/5] vfio/pci: Move all the SPAPR PCI specific logic to vfio_pci_core.ko Jason Gunthorpe
@ 2022-10-17 18:38 ` Jason Gunthorpe
  2022-10-18  6:03   ` Christoph Hellwig
  2022-10-18 16:42   ` Philippe Mathieu-Daudé
  2022-10-17 18:38 ` [PATCH v3 3/5] vfio: Move vfio_spapr_iommu_eeh_ioctl into vfio_iommu_spapr_tce.c Jason Gunthorpe
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 13+ messages in thread
From: Jason Gunthorpe @ 2022-10-17 18:38 UTC (permalink / raw)
  To: Alex Williamson, Cornelia Huck, kvm

The 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().

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/vfio_iommu_spapr_tce.c | 10 ++++------
 drivers/vfio/vfio_spapr_eeh.c       |  6 ------
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c
index 169f07ac162d9c..73cec2beae70b1 100644
--- a/drivers/vfio/vfio_iommu_spapr_tce.c
+++ b/drivers/vfio/vfio_iommu_spapr_tce.c
@@ -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;
 	}
 
 	/*
diff --git a/drivers/vfio/vfio_spapr_eeh.c b/drivers/vfio/vfio_spapr_eeh.c
index c9d102aafbcd11..221b1b637e18b0 100644
--- a/drivers/vfio/vfio_spapr_eeh.c
+++ b/drivers/vfio/vfio_spapr_eeh.c
@@ -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)
-- 
2.38.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 3/5] vfio: Move vfio_spapr_iommu_eeh_ioctl into vfio_iommu_spapr_tce.c
  2022-10-17 18:38 [PATCH v3 0/5] Simplify the module and kconfig structure in vfio Jason Gunthorpe
  2022-10-17 18:38 ` [PATCH v3 1/5] vfio/pci: Move all the SPAPR PCI specific logic to vfio_pci_core.ko Jason Gunthorpe
  2022-10-17 18:38 ` [PATCH v3 2/5] vfio/spapr: Move VFIO_CHECK_EXTENSION into tce_iommu_ioctl() Jason Gunthorpe
@ 2022-10-17 18:38 ` Jason Gunthorpe
  2022-10-18  6:06   ` Christoph Hellwig
  2022-10-17 18:38 ` [PATCH v3 4/5] vfio: Remove CONFIG_VFIO_SPAPR_EEH Jason Gunthorpe
  2022-10-17 18:38 ` [PATCH v3 5/5] vfio: Fold vfio_virqfd.ko into vfio.ko Jason Gunthorpe
  4 siblings, 1 reply; 13+ messages in thread
From: Jason Gunthorpe @ 2022-10-17 18:38 UTC (permalink / raw)
  To: Alex Williamson, Cornelia Huck, kvm

As 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.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 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

diff --git a/drivers/vfio/Makefile b/drivers/vfio/Makefile
index b693a1169286f8..50b8e8e3fb10dd 100644
--- a/drivers/vfio/Makefile
+++ b/drivers/vfio/Makefile
@@ -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/
diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c
index 73cec2beae70b1..3ea0e7b75c2455 100644
--- a/drivers/vfio/vfio_iommu_spapr_tce.c
+++ b/drivers/vfio/vfio_iommu_spapr_tce.c
@@ -773,6 +773,68 @@ static long tce_iommu_create_default_window(struct tce_container *container)
 	return ret;
 }
 
+static long vfio_spapr_ioctl_eeh_pe_op(struct iommu_group *group,
+				       unsigned long arg)
+{
+	struct eeh_pe *pe;
+	struct vfio_eeh_pe_op op;
+	unsigned long minsz;
+	long ret = -EINVAL;
+
+	pe = eeh_iommu_group_to_pe(group);
+	if (!pe)
+		return -ENODEV;
+
+	minsz = offsetofend(struct vfio_eeh_pe_op, op);
+	if (copy_from_user(&op, (void __user *)arg, minsz))
+		return -EFAULT;
+	if (op.argsz < minsz || op.flags)
+		return -EINVAL;
+
+	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;
+	case VFIO_EEH_PE_UNFREEZE_IO:
+		ret = eeh_pe_set_option(pe, EEH_OPT_THAW_MMIO);
+		break;
+	case VFIO_EEH_PE_UNFREEZE_DMA:
+		ret = eeh_pe_set_option(pe, EEH_OPT_THAW_DMA);
+		break;
+	case VFIO_EEH_PE_GET_STATE:
+		ret = eeh_pe_get_state(pe);
+		break;
+	case VFIO_EEH_PE_RESET_DEACTIVATE:
+		ret = eeh_pe_reset(pe, EEH_RESET_DEACTIVATE, true);
+		break;
+	case VFIO_EEH_PE_RESET_HOT:
+		ret = eeh_pe_reset(pe, EEH_RESET_HOT, true);
+		break;
+	case VFIO_EEH_PE_RESET_FUNDAMENTAL:
+		ret = eeh_pe_reset(pe, EEH_RESET_FUNDAMENTAL, true);
+		break;
+	case VFIO_EEH_PE_CONFIGURE:
+		ret = eeh_pe_configure(pe);
+		break;
+	case VFIO_EEH_PE_INJECT_ERR:
+		minsz = offsetofend(struct vfio_eeh_pe_op, err.mask);
+		if (op.argsz < minsz)
+			return -EINVAL;
+		if (copy_from_user(&op, (void __user *)arg, minsz))
+			return -EFAULT;
+
+		ret = eeh_pe_inject_err(pe, op.err.type, op.err.func,
+					op.err.addr, op.err.mask);
+		break;
+	default:
+		ret = -EINVAL;
+	}
+	return ret;
+}
+
 static long tce_iommu_ioctl(void *iommu_data,
 				 unsigned int cmd, unsigned long arg)
 {
@@ -1044,8 +1106,7 @@ static long tce_iommu_ioctl(void *iommu_data,
 
 		ret = 0;
 		list_for_each_entry(tcegrp, &container->group_list, next) {
-			ret = vfio_spapr_iommu_eeh_ioctl(tcegrp->grp,
-					cmd, arg);
+			ret = vfio_spapr_ioctl_eeh_pe_op(tcegrp->grp, arg);
 			if (ret)
 				return ret;
 		}
diff --git a/drivers/vfio/vfio_spapr_eeh.c b/drivers/vfio/vfio_spapr_eeh.c
deleted file mode 100644
index 221b1b637e18b0..00000000000000
--- a/drivers/vfio/vfio_spapr_eeh.c
+++ /dev/null
@@ -1,88 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * EEH functionality support for VFIO devices. The feature is only
- * available on sPAPR compatible platforms.
- *
- * Copyright Gavin Shan, IBM Corporation 2014.
- */
-
-#include <linux/module.h>
-#include <linux/uaccess.h>
-#include <linux/vfio.h>
-#include <asm/eeh.h>
-
-#define DRIVER_VERSION	"0.1"
-#define DRIVER_AUTHOR	"Gavin Shan, IBM Corporation"
-#define DRIVER_DESC	"VFIO IOMMU SPAPR EEH"
-
-long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group,
-				unsigned int cmd, unsigned long arg)
-{
-	struct eeh_pe *pe;
-	struct vfio_eeh_pe_op op;
-	unsigned long minsz;
-	long ret = -EINVAL;
-
-	switch (cmd) {
-	case VFIO_EEH_PE_OP:
-		pe = eeh_iommu_group_to_pe(group);
-		if (!pe)
-			return -ENODEV;
-
-		minsz = offsetofend(struct vfio_eeh_pe_op, op);
-		if (copy_from_user(&op, (void __user *)arg, minsz))
-			return -EFAULT;
-		if (op.argsz < minsz || op.flags)
-			return -EINVAL;
-
-		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;
-		case VFIO_EEH_PE_UNFREEZE_IO:
-			ret = eeh_pe_set_option(pe, EEH_OPT_THAW_MMIO);
-			break;
-		case VFIO_EEH_PE_UNFREEZE_DMA:
-			ret = eeh_pe_set_option(pe, EEH_OPT_THAW_DMA);
-			break;
-		case VFIO_EEH_PE_GET_STATE:
-			ret = eeh_pe_get_state(pe);
-			break;
-		case VFIO_EEH_PE_RESET_DEACTIVATE:
-			ret = eeh_pe_reset(pe, EEH_RESET_DEACTIVATE, true);
-			break;
-		case VFIO_EEH_PE_RESET_HOT:
-			ret = eeh_pe_reset(pe, EEH_RESET_HOT, true);
-			break;
-		case VFIO_EEH_PE_RESET_FUNDAMENTAL:
-			ret = eeh_pe_reset(pe, EEH_RESET_FUNDAMENTAL, true);
-			break;
-		case VFIO_EEH_PE_CONFIGURE:
-			ret = eeh_pe_configure(pe);
-			break;
-		case VFIO_EEH_PE_INJECT_ERR:
-			minsz = offsetofend(struct vfio_eeh_pe_op, err.mask);
-			if (op.argsz < minsz)
-				return -EINVAL;
-			if (copy_from_user(&op, (void __user *)arg, minsz))
-				return -EFAULT;
-
-			ret = eeh_pe_inject_err(pe, op.err.type, op.err.func,
-						op.err.addr, op.err.mask);
-			break;
-		default:
-			ret = -EINVAL;
-		}
-	}
-
-	return ret;
-}
-EXPORT_SYMBOL_GPL(vfio_spapr_iommu_eeh_ioctl);
-
-MODULE_VERSION(DRIVER_VERSION);
-MODULE_LICENSE("GPL v2");
-MODULE_AUTHOR(DRIVER_AUTHOR);
-MODULE_DESCRIPTION(DRIVER_DESC);
diff --git a/include/linux/vfio.h b/include/linux/vfio.h
index e8a5a9cdb9067f..bd9faaab85de18 100644
--- a/include/linux/vfio.h
+++ b/include/linux/vfio.h
@@ -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
  */
-- 
2.38.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 4/5] vfio: Remove CONFIG_VFIO_SPAPR_EEH
  2022-10-17 18:38 [PATCH v3 0/5] Simplify the module and kconfig structure in vfio Jason Gunthorpe
                   ` (2 preceding siblings ...)
  2022-10-17 18:38 ` [PATCH v3 3/5] vfio: Move vfio_spapr_iommu_eeh_ioctl into vfio_iommu_spapr_tce.c Jason Gunthorpe
@ 2022-10-17 18:38 ` Jason Gunthorpe
  2022-10-18  6:08   ` Christoph Hellwig
  2022-10-17 18:38 ` [PATCH v3 5/5] vfio: Fold vfio_virqfd.ko into vfio.ko Jason Gunthorpe
  4 siblings, 1 reply; 13+ messages in thread
From: Jason Gunthorpe @ 2022-10-17 18:38 UTC (permalink / raw)
  To: Alex Williamson, Cornelia Huck, kvm

We don't need a kconfig symbol for this, just directly test CONFIG_EEH in
the one remaining place that needs it.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/Kconfig             | 5 -----
 drivers/vfio/pci/vfio_pci_core.c | 6 +++---
 2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/vfio/Kconfig b/drivers/vfio/Kconfig
index 86c381ceb9a1e9..d25b91adfd64cd 100644
--- a/drivers/vfio/Kconfig
+++ b/drivers/vfio/Kconfig
@@ -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
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index c8b8a7a03eae7e..6fe6b27475b75a 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -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
 
-- 
2.38.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 5/5] vfio: Fold vfio_virqfd.ko into vfio.ko
  2022-10-17 18:38 [PATCH v3 0/5] Simplify the module and kconfig structure in vfio Jason Gunthorpe
                   ` (3 preceding siblings ...)
  2022-10-17 18:38 ` [PATCH v3 4/5] vfio: Remove CONFIG_VFIO_SPAPR_EEH Jason Gunthorpe
@ 2022-10-17 18:38 ` Jason Gunthorpe
  4 siblings, 0 replies; 13+ messages in thread
From: Jason Gunthorpe @ 2022-10-17 18:38 UTC (permalink / raw)
  To: Alex Williamson, Cornelia Huck, kvm

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.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 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(-)

diff --git a/drivers/vfio/Kconfig b/drivers/vfio/Kconfig
index d25b91adfd64cd..0b8d53f63c7e5c 100644
--- a/drivers/vfio/Kconfig
+++ b/drivers/vfio/Kconfig
@@ -21,7 +21,7 @@ config VFIO_IOMMU_SPAPR_TCE
 	default VFIO
 
 config VFIO_VIRQFD
-	tristate
+	bool
 	select EVENTFD
 	default n
 
diff --git a/drivers/vfio/Makefile b/drivers/vfio/Makefile
index 50b8e8e3fb10dd..0721ed4831c92f 100644
--- a/drivers/vfio/Makefile
+++ b/drivers/vfio/Makefile
@@ -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/
diff --git a/drivers/vfio/vfio.h b/drivers/vfio/vfio.h
index bcad54bbab08c4..a7113b4baaa242 100644
--- a/drivers/vfio/vfio.h
+++ b/drivers/vfio/vfio.h
@@ -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
diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
index 2d168793d4e1ce..97d7b88c8fe1f4 100644
--- a/drivers/vfio/vfio_main.c
+++ b/drivers/vfio/vfio_main.c
@@ -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);
diff --git a/drivers/vfio/virqfd.c b/drivers/vfio/virqfd.c
index 414e98d82b02e5..497a17b3786568 100644
--- a/drivers/vfio/virqfd.c
+++ b/drivers/vfio/virqfd.c
@@ -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 <alex.williamson@redhat.com>"
-#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);
-- 
2.38.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 1/5] vfio/pci: Move all the SPAPR PCI specific logic to vfio_pci_core.ko
  2022-10-17 18:38 ` [PATCH v3 1/5] vfio/pci: Move all the SPAPR PCI specific logic to vfio_pci_core.ko Jason Gunthorpe
@ 2022-10-18  6:03   ` Christoph Hellwig
  0 siblings, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2022-10-18  6:03 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Alex Williamson, Cornelia Huck, kvm

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 2/5] vfio/spapr: Move VFIO_CHECK_EXTENSION into tce_iommu_ioctl()
  2022-10-17 18:38 ` [PATCH v3 2/5] vfio/spapr: Move VFIO_CHECK_EXTENSION into tce_iommu_ioctl() Jason Gunthorpe
@ 2022-10-18  6:03   ` Christoph Hellwig
  2022-10-18 16:42   ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2022-10-18  6:03 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Alex Williamson, Cornelia Huck, kvm

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 3/5] vfio: Move vfio_spapr_iommu_eeh_ioctl into vfio_iommu_spapr_tce.c
  2022-10-17 18:38 ` [PATCH v3 3/5] vfio: Move vfio_spapr_iommu_eeh_ioctl into vfio_iommu_spapr_tce.c Jason Gunthorpe
@ 2022-10-18  6:06   ` Christoph Hellwig
  2022-10-21 19:39     ` Jason Gunthorpe
  0 siblings, 1 reply; 13+ messages in thread
From: Christoph Hellwig @ 2022-10-18  6:06 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Alex Williamson, Cornelia Huck, kvm

> +	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.

> - * Copyright Gavin Shan, IBM Corporation 2014.

This notice needs to move over to vfio_iommu_spapr_tce.c.

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 4/5] vfio: Remove CONFIG_VFIO_SPAPR_EEH
  2022-10-17 18:38 ` [PATCH v3 4/5] vfio: Remove CONFIG_VFIO_SPAPR_EEH Jason Gunthorpe
@ 2022-10-18  6:08   ` Christoph Hellwig
  2022-10-21 19:46     ` Jason Gunthorpe
  0 siblings, 1 reply; 13+ messages in thread
From: Christoph Hellwig @ 2022-10-18  6:08 UTC (permalink / raw)
  To: Jason Gunthorpe, Russell Currey, Oliver O'Halloran,
	Alexey Kardashevskiy
  Cc: Alex Williamson, Cornelia Huck, kvm, linuxppc-dev

> +#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.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 2/5] vfio/spapr: Move VFIO_CHECK_EXTENSION into tce_iommu_ioctl()
  2022-10-17 18:38 ` [PATCH v3 2/5] vfio/spapr: Move VFIO_CHECK_EXTENSION into tce_iommu_ioctl() Jason Gunthorpe
  2022-10-18  6:03   ` Christoph Hellwig
@ 2022-10-18 16:42   ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2022-10-18 16:42 UTC (permalink / raw)
  To: Jason Gunthorpe, Alex Williamson, Cornelia Huck, kvm

On 17/10/22 20:38, Jason Gunthorpe wrote:
> The 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().
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>   drivers/vfio/vfio_iommu_spapr_tce.c | 10 ++++------
>   drivers/vfio/vfio_spapr_eeh.c       |  6 ------
>   2 files changed, 4 insertions(+), 12 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 3/5] vfio: Move vfio_spapr_iommu_eeh_ioctl into vfio_iommu_spapr_tce.c
  2022-10-18  6:06   ` Christoph Hellwig
@ 2022-10-21 19:39     ` Jason Gunthorpe
  0 siblings, 0 replies; 13+ messages in thread
From: Jason Gunthorpe @ 2022-10-21 19:39 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Alex Williamson, Cornelia Huck, kvm

On Mon, Oct 17, 2022 at 11:06:19PM -0700, Christoph Hellwig wrote:
> > +	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

> > - * Copyright Gavin Shan, IBM Corporation 2014.
> 
> This notice needs to move over to vfio_iommu_spapr_tce.c.

Ok

Thanks,
Jason 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 4/5] vfio: Remove CONFIG_VFIO_SPAPR_EEH
  2022-10-18  6:08   ` Christoph Hellwig
@ 2022-10-21 19:46     ` Jason Gunthorpe
  0 siblings, 0 replies; 13+ messages in thread
From: Jason Gunthorpe @ 2022-10-21 19:46 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Russell Currey, Oliver O'Halloran, Alexey Kardashevskiy,
	Alex Williamson, Cornelia Huck, kvm, linuxppc-dev

On Mon, Oct 17, 2022 at 11:08:35PM -0700, Christoph Hellwig wrote:
> > +#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.

Yes, it does read better, done

Thanks,
Jason

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-10-21 19:46 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-17 18:38 [PATCH v3 0/5] Simplify the module and kconfig structure in vfio Jason Gunthorpe
2022-10-17 18:38 ` [PATCH v3 1/5] vfio/pci: Move all the SPAPR PCI specific logic to vfio_pci_core.ko Jason Gunthorpe
2022-10-18  6:03   ` Christoph Hellwig
2022-10-17 18:38 ` [PATCH v3 2/5] vfio/spapr: Move VFIO_CHECK_EXTENSION into tce_iommu_ioctl() Jason Gunthorpe
2022-10-18  6:03   ` Christoph Hellwig
2022-10-18 16:42   ` Philippe Mathieu-Daudé
2022-10-17 18:38 ` [PATCH v3 3/5] vfio: Move vfio_spapr_iommu_eeh_ioctl into vfio_iommu_spapr_tce.c Jason Gunthorpe
2022-10-18  6:06   ` Christoph Hellwig
2022-10-21 19:39     ` Jason Gunthorpe
2022-10-17 18:38 ` [PATCH v3 4/5] vfio: Remove CONFIG_VFIO_SPAPR_EEH Jason Gunthorpe
2022-10-18  6:08   ` Christoph Hellwig
2022-10-21 19:46     ` Jason Gunthorpe
2022-10-17 18:38 ` [PATCH v3 5/5] vfio: Fold vfio_virqfd.ko into vfio.ko Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).