diff --git a/drivers/vfio/Kconfig b/drivers/vfio/Kconfig index 9d7d9265089a3a..07e5b65ee53c48 100644 --- a/drivers/vfio/Kconfig +++ b/drivers/vfio/Kconfig @@ -3,7 +3,7 @@ menuconfig VFIO tristate "VFIO Non-Privileged userspace driver framework" select IOMMU_API depends on IOMMUFD || !IOMMUFD - select VFIO_IOMMU_TYPE1 if MMU && (X86 || S390 || ARM || ARM64) + select VFIO_CONTAINER if IOMMUFD=n help VFIO provides a framework for secure userspace device drivers. See Documentation/driver-api/vfio.rst for more details. @@ -11,25 +11,26 @@ menuconfig VFIO If you don't know what to do here, say N. if VFIO +config VFIO_CONTAINER + bool "Support for the VFIO container /dev/vfio/vfio" + default y + help + The VFIO container is the classic interface to VFIO. + If N is selected here then IOMMUFD will provide the + character device. + + Unless testing IOMMUFD say N here. + +if VFIO_CONTAINER config VFIO_IOMMU_TYPE1 tristate - default n + default MMU && (X86 || S390 || ARM || ARM64) config VFIO_IOMMU_SPAPR_TCE tristate 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 - default n - config VFIO_NOIOMMU bool "VFIO No-IOMMU support" help @@ -43,6 +44,17 @@ config VFIO_NOIOMMU this mode since there is no IOMMU to provide DMA translation. If you don't know what to do here, say N. +endif + +config VFIO_SPAPR_EEH + tristate + depends on EEH && VFIO_IOMMU_SPAPR_TCE + default VFIO + +config VFIO_VIRQFD + tristate + select EVENTFD + default n source "drivers/vfio/pci/Kconfig" source "drivers/vfio/platform/Kconfig" diff --git a/drivers/vfio/Makefile b/drivers/vfio/Makefile index 1ffaceb5db0d70..d7866da53e7c80 100644 --- a/drivers/vfio/Makefile +++ b/drivers/vfio/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 vfio_virqfd-y := virqfd.o -vfio-y += vfio_container.o +vfio-$(CONFIG_VFIO_CONTAINER) += vfio_container.o vfio-y += vfio_main.o vfio-$(CONFIG_IOMMUFD) += vfio_iommufd.o diff --git a/drivers/vfio/vfio.h b/drivers/vfio/vfio.h index 6daa444d9aae51..6e854249ebdd41 100644 --- a/drivers/vfio/vfio.h +++ b/drivers/vfio/vfio.h @@ -49,7 +49,9 @@ struct vfio_group { struct list_head device_list; struct mutex device_lock; struct list_head vfio_next; +#if IS_ENABLED(CONFIG_VFIO_CONTAINER) struct list_head container_next; +#endif enum vfio_group_type type; unsigned int dev_counter; struct rw_semaphore group_rwsem; @@ -59,6 +61,7 @@ struct vfio_group { struct iommufd_ctx *iommufd; }; +#if IS_ENABLED(CONFIG_VFIO_CONTAINER) /* events for the backend driver notify callback */ enum vfio_iommu_notify_type { VFIO_IOMMU_CONTAINER_CLOSE = 0, @@ -125,6 +128,74 @@ int vfio_container_dma_rw(struct vfio_device *device, dma_addr_t iova, int __init vfio_container_init(void); void vfio_container_cleanup(void); +#else +static inline struct vfio_container * +vfio_container_from_file(struct file *filep) +{ + return NULL; +} + +static inline int vfio_container_use(struct vfio_group *group); +{ + return -EOPNOTSUPP; +} + +static inline void vfio_container_unuse(struct vfio_group *group) +{ +} + +static inline int vfio_container_attach_group(struct vfio_group *group, + struct vfio_container *container) +{ + return -EOPNOTSUPP; +} + +static inline void vfio_container_detatch_group(struct vfio_group *group) +{ +} + +static inline void vfio_container_register_device(struct vfio_device *device) +{ +} + +static inline void vfio_container_unregister_device(struct vfio_device *device) +{ +} + +static inline long +vfio_container_ioctl_check_extension(struct vfio_container *container, + unsigned long arg) +{ + return -EOPNOTSUPP; +} + +static inline int vfio_container_pin_pages(struct vfio_device *device, + dma_addr_t iova, int npage, int prot, + struct page **pages) +{ + return -EOPNOTSUPP; +} + +static inline void vfio_container_unpin_pages(struct vfio_device *device, + dma_addr_t iova, int npage) +{ +} + +static inline int vfio_container_dma_rw(struct vfio_device *device, + dma_addr_t iova, void *data, size_t len, + bool write) +{ + return -EOPNOTSUPP; +} + +static inline int vfio_container_init(void) +{ + return 0; +} +static inline void vfio_container_cleanup(void) +{ +} +#endif #if IS_ENABLED(CONFIG_IOMMUFD) int vfio_iommufd_bind(struct vfio_device *device, struct iommufd_ctx *ictx);