Skip to content

Commit

Permalink
vfio: Make vfio_container optionally compiled
Browse files Browse the repository at this point in the history
Add a kconfig CONFIG_VFIO_CONTAINER that control compiling the container
code. If 'n' then only iommufd will provide the container service.

This allows a compilation check that no inappropriate dependencies between
the device/group and container have been created.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
  • Loading branch information
jgunthorpe committed Aug 27, 2022
1 parent a1d323c commit e44832b
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 13 deletions.
36 changes: 24 additions & 12 deletions drivers/vfio/Kconfig
Expand Up @@ -3,33 +3,34 @@ 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.

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
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion 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

Expand Down
71 changes: 71 additions & 0 deletions drivers/vfio/vfio.h
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e44832b

Please sign in to comment.