Re: [PATCH v3 02/19] vfio: Move iova_bitmap into iommu core

Joao Martins
2023-10-16T16:55:57Z

On 14/10/2023 01:02, Jason Gunthorpe wrote:
> On Fri, Oct 13, 2023 at 03:51:34PM -0600, Alex Williamson wrote:
>
>> I think Jason is describing this would eventually be in a built-in
>> portion of IOMMUFD, but I think currently that built-in portion is
>> IOMMU. So until we have this IOMMUFD_DRIVER that enables that built-in
>> portion, it seems unnecessarily disruptive to make VFIO select IOMMUFD
>> to get this iova bitmap support. Thanks,
>
> Right, I'm saying Joao may as well make IOMMUFD_DRIVER right now for
> this

So far I have this snip at the end.

Though given that there are struct iommu_domain changes that set a dirty_ops
(which require iova-bitmap). Do we just ifdef around IOMMUFD_DRIVER or we always
include it if CONFIG_IOMMU_API=y ? Thus far I'm going towards the latter

diff --git a/drivers/iommu/iommufd/Kconfig b/drivers/iommu/iommufd/Kconfig
index 99d4b075df49..96ec013d1192 100644
--- a/drivers/iommu/iommufd/Kconfig
+++ b/drivers/iommu/iommufd/Kconfig
@@ -11,6 +11,13 @@ config IOMMUFD

If you don't know what to do here, say N.

+config IOMMUFD_DRIVER
+ bool "IOMMUFD provides iommu drivers supporting functions"
+ default IOMMU_API
+ help
+ IOMMUFD will provides supporting data structures and helpers to IOMMU
+ drivers.
+
if IOMMUFD
config IOMMUFD_VFIO_CONTAINER
bool "IOMMUFD provides the VFIO container /dev/vfio/vfio"
diff --git a/drivers/iommu/iommufd/Makefile b/drivers/iommu/iommufd/Makefile
index 8aeba81800c5..34b446146961 100644
--- a/drivers/iommu/iommufd/Makefile
+++ b/drivers/iommu/iommufd/Makefile
@@ -11,3 +11,4 @@ iommufd-y := \
iommufd-$(CONFIG_IOMMUFD_TEST) += selftest.o

obj-$(CONFIG_IOMMUFD) += iommufd.o
+obj-$(CONFIG_IOMMUFD_DRIVER) += iova_bitmap.o
diff --git a/drivers/vfio/iova_bitmap.c b/drivers/iommu/iommufd/iova_bitmap.c
similarity index 100%
rename from drivers/vfio/iova_bitmap.c
rename to drivers/iommu/iommufd/iova_bitmap.c
diff --git a/drivers/vfio/Kconfig b/drivers/vfio/Kconfig
index 6bda6dbb4878..1db519cce815 100644
--- a/drivers/vfio/Kconfig
+++ b/drivers/vfio/Kconfig
@@ -7,6 +7,7 @@ menuconfig VFIO
select VFIO_GROUP if SPAPR_TCE_IOMMU || IOMMUFD=n
select VFIO_DEVICE_CDEV if !VFIO_GROUP
select VFIO_CONTAINER if IOMMUFD=n
+ select IOMMUFD_DRIVER
help
VFIO provides a framework for secure userspace device drivers.
See Documentation/driver-api/vfio.rst for more details.
diff --git a/drivers/vfio/Makefile b/drivers/vfio/Makefile
index c82ea032d352..68c05705200f 100644
--- a/drivers/vfio/Makefile
+++ b/drivers/vfio/Makefile
@@ -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