]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
vfio: Move iova_bitmap into iommufd
authorJoao Martins <joao.m.martins@oracle.com>
Tue, 24 Oct 2023 13:50:53 +0000 (14:50 +0100)
committerJason Gunthorpe <jgg@nvidia.com>
Tue, 24 Oct 2023 14:58:42 +0000 (11:58 -0300)
Both VFIO and IOMMUFD will need iova bitmap for storing dirties and walking
the user bitmaps, so move to the common dependency into IOMMUFD.  In doing
so, create the symbol IOMMUFD_DRIVER which designates the builtin code that
will be used by drivers when selected. Today this means MLX5_VFIO_PCI and
PDS_VFIO_PCI. IOMMU drivers will do the same (in future patches) when
supporting dirty tracking and select IOMMUFD_DRIVER accordingly.

Given that the symbol maybe be disabled, add header definitions in
iova_bitmap.h for when IOMMUFD_DRIVER=n

Link: https://lore.kernel.org/r/20231024135109.73787-3-joao.m.martins@oracle.com
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Brett Creeley <brett.creeley@amd.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/Kconfig
drivers/iommu/iommufd/Makefile
drivers/iommu/iommufd/iova_bitmap.c [moved from drivers/vfio/iova_bitmap.c with 100% similarity]
drivers/vfio/Makefile
drivers/vfio/pci/mlx5/Kconfig
drivers/vfio/pci/pds/Kconfig
include/linux/iova_bitmap.h

index 2b12b583ef4b1edb8c296f59e7e6d4dcc4ca095e..5cc869db1b79fc3c7d6034cde5ba724970e55f2f 100644 (file)
@@ -7,6 +7,10 @@ config IOMMU_IOVA
 config IOMMU_API
        bool
 
+config IOMMUFD_DRIVER
+       bool
+       default n
+
 menuconfig IOMMU_SUPPORT
        bool "IOMMU Hardware Support"
        depends on MMU
index 8aeba81800c512dc9e9eb1c32b3240080b503db1..34b446146961c29e7b24dc5cc890a5aa557a6ce8 100644 (file)
@@ -11,3 +11,4 @@ iommufd-y := \
 iommufd-$(CONFIG_IOMMUFD_TEST) += selftest.o
 
 obj-$(CONFIG_IOMMUFD) += iommufd.o
+obj-$(CONFIG_IOMMUFD_DRIVER) += iova_bitmap.o
index c82ea032d3521268138811a1cc1b718755c90c26..68c05705200fce8fc9824a8521bbe554e5c130f7 100644 (file)
@@ -1,8 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_VFIO) += vfio.o
 
-vfio-y += vfio_main.o \
-         iova_bitmap.o
+vfio-y += vfio_main.o
 vfio-$(CONFIG_VFIO_DEVICE_CDEV) += device_cdev.o
 vfio-$(CONFIG_VFIO_GROUP) += group.o
 vfio-$(CONFIG_IOMMUFD) += iommufd.o
index 7088edc4fb28d88f5603e8f68462993123eece46..c3ced56b7787650ce8b82039b419413e81deedfa 100644 (file)
@@ -3,6 +3,7 @@ config MLX5_VFIO_PCI
        tristate "VFIO support for MLX5 PCI devices"
        depends on MLX5_CORE
        select VFIO_PCI_CORE
+       select IOMMUFD_DRIVER
        help
          This provides migration support for MLX5 devices using the VFIO
          framework.
index 407b3fd3273381ed5173f7e2ca2b83fe8800dc3b..fff368a8183b25455a534a7a9dffe7db4b0070eb 100644 (file)
@@ -5,6 +5,7 @@ config PDS_VFIO_PCI
        tristate "VFIO support for PDS PCI devices"
        depends on PDS_CORE
        select VFIO_PCI_CORE
+       select IOMMUFD_DRIVER
        help
          This provides generic PCI support for PDS devices using the VFIO
          framework.
index c006cf0a25f3daac2ccc39c67c9a3193245a4077..1c338f5e5b7a62027290b44ad47c4a74d84706ac 100644 (file)
@@ -7,6 +7,7 @@
 #define _IOVA_BITMAP_H_
 
 #include <linux/types.h>
+#include <linux/errno.h>
 
 struct iova_bitmap;
 
@@ -14,6 +15,7 @@ typedef int (*iova_bitmap_fn_t)(struct iova_bitmap *bitmap,
                                unsigned long iova, size_t length,
                                void *opaque);
 
+#if IS_ENABLED(CONFIG_IOMMUFD_DRIVER)
 struct iova_bitmap *iova_bitmap_alloc(unsigned long iova, size_t length,
                                      unsigned long page_size,
                                      u64 __user *data);
@@ -22,5 +24,29 @@ int iova_bitmap_for_each(struct iova_bitmap *bitmap, void *opaque,
                         iova_bitmap_fn_t fn);
 void iova_bitmap_set(struct iova_bitmap *bitmap,
                     unsigned long iova, size_t length);
+#else
+static inline struct iova_bitmap *iova_bitmap_alloc(unsigned long iova,
+                                                   size_t length,
+                                                   unsigned long page_size,
+                                                   u64 __user *data)
+{
+       return NULL;
+}
+
+static inline void iova_bitmap_free(struct iova_bitmap *bitmap)
+{
+}
+
+static inline int iova_bitmap_for_each(struct iova_bitmap *bitmap, void *opaque,
+                                      iova_bitmap_fn_t fn)
+{
+       return -EOPNOTSUPP;
+}
+
+static inline void iova_bitmap_set(struct iova_bitmap *bitmap,
+                                  unsigned long iova, size_t length)
+{
+}
+#endif
 
 #endif