Skip to content

Commit e5a9ec7

Browse files
committed
vfio: Make vfio_container optionally compiled
Add a kconfig CONFIG_VFIO_CONTAINER that controls compiling the container code. If 'n' then only iommufd will provide the container service. All the support for vfio iommu drivers, including type1, will not be built. This allows a compilation check that no inappropriate dependencies between the device/group and container have been created. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Alex Williamson <[email protected]> Tested-by: Alex Williamson <[email protected]> Tested-by: Nicolin Chen <[email protected]> Tested-by: Yi Liu <[email protected]> Tested-by: Lixiao Yang <[email protected]> Tested-by: Matthew Rosato <[email protected]> Tested-by: Yu He <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 81ab989 commit e5a9ec7

File tree

3 files changed

+91
-13
lines changed

3 files changed

+91
-13
lines changed

drivers/vfio/Kconfig

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,27 @@ menuconfig VFIO
33
tristate "VFIO Non-Privileged userspace driver framework"
44
select IOMMU_API
55
depends on IOMMUFD || !IOMMUFD
6-
select VFIO_IOMMU_TYPE1 if MMU && (X86 || S390 || ARM || ARM64)
76
select INTERVAL_TREE
7+
select VFIO_CONTAINER if IOMMUFD=n
88
help
99
VFIO provides a framework for secure userspace device drivers.
1010
See Documentation/driver-api/vfio.rst for more details.
1111

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

1414
if VFIO
15+
config VFIO_CONTAINER
16+
bool "Support for the VFIO container /dev/vfio/vfio"
17+
select VFIO_IOMMU_TYPE1 if MMU && (X86 || S390 || ARM || ARM64)
18+
default y
19+
help
20+
The VFIO container is the classic interface to VFIO for establishing
21+
IOMMU mappings. If N is selected here then IOMMUFD must be used to
22+
manage the mappings.
23+
24+
Unless testing IOMMUFD say Y here.
25+
26+
if VFIO_CONTAINER
1527
config VFIO_IOMMU_TYPE1
1628
tristate
1729
default n
@@ -21,16 +33,6 @@ config VFIO_IOMMU_SPAPR_TCE
2133
depends on SPAPR_TCE_IOMMU
2234
default VFIO
2335

24-
config VFIO_SPAPR_EEH
25-
tristate
26-
depends on EEH && VFIO_IOMMU_SPAPR_TCE
27-
default VFIO
28-
29-
config VFIO_VIRQFD
30-
tristate
31-
select EVENTFD
32-
default n
33-
3436
config VFIO_NOIOMMU
3537
bool "VFIO No-IOMMU support"
3638
help
@@ -44,6 +46,17 @@ config VFIO_NOIOMMU
4446
this mode since there is no IOMMU to provide DMA translation.
4547

4648
If you don't know what to do here, say N.
49+
endif
50+
51+
config VFIO_SPAPR_EEH
52+
tristate
53+
depends on EEH && VFIO_IOMMU_SPAPR_TCE
54+
default VFIO
55+
56+
config VFIO_VIRQFD
57+
tristate
58+
select EVENTFD
59+
default n
4760

4861
source "drivers/vfio/pci/Kconfig"
4962
source "drivers/vfio/platform/Kconfig"

drivers/vfio/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ vfio_virqfd-y := virqfd.o
44
obj-$(CONFIG_VFIO) += vfio.o
55

66
vfio-y += vfio_main.o \
7-
iova_bitmap.o \
8-
container.o
7+
iova_bitmap.o
98
vfio-$(CONFIG_IOMMUFD) += iommufd.o
9+
vfio-$(CONFIG_VFIO_CONTAINER) += container.o
1010

1111
obj-$(CONFIG_VFIO_VIRQFD) += vfio_virqfd.o
1212
obj-$(CONFIG_VFIO_IOMMU_TYPE1) += vfio_iommu_type1.o

drivers/vfio/vfio.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ struct vfio_group {
5555
struct list_head device_list;
5656
struct mutex device_lock;
5757
struct list_head vfio_next;
58+
#if IS_ENABLED(CONFIG_VFIO_CONTAINER)
5859
struct list_head container_next;
60+
#endif
5961
enum vfio_group_type type;
6062
struct mutex group_lock;
6163
struct kvm *kvm;
@@ -64,6 +66,7 @@ struct vfio_group {
6466
struct iommufd_ctx *iommufd;
6567
};
6668

69+
#if IS_ENABLED(CONFIG_VFIO_CONTAINER)
6770
/* events for the backend driver notify callback */
6871
enum vfio_iommu_notify_type {
6972
VFIO_IOMMU_CONTAINER_CLOSE = 0,
@@ -129,6 +132,68 @@ int vfio_container_dma_rw(struct vfio_container *container, dma_addr_t iova,
129132

130133
int __init vfio_container_init(void);
131134
void vfio_container_cleanup(void);
135+
#else
136+
static inline struct vfio_container *
137+
vfio_container_from_file(struct file *filep)
138+
{
139+
return NULL;
140+
}
141+
142+
static inline int vfio_group_use_container(struct vfio_group *group)
143+
{
144+
return -EOPNOTSUPP;
145+
}
146+
147+
static inline void vfio_group_unuse_container(struct vfio_group *group)
148+
{
149+
}
150+
151+
static inline int vfio_container_attach_group(struct vfio_container *container,
152+
struct vfio_group *group)
153+
{
154+
return -EOPNOTSUPP;
155+
}
156+
157+
static inline void vfio_group_detach_container(struct vfio_group *group)
158+
{
159+
}
160+
161+
static inline void vfio_device_container_register(struct vfio_device *device)
162+
{
163+
}
164+
165+
static inline void vfio_device_container_unregister(struct vfio_device *device)
166+
{
167+
}
168+
169+
static inline int vfio_container_pin_pages(struct vfio_container *container,
170+
struct iommu_group *iommu_group,
171+
dma_addr_t iova, int npage, int prot,
172+
struct page **pages)
173+
{
174+
return -EOPNOTSUPP;
175+
}
176+
177+
static inline void vfio_container_unpin_pages(struct vfio_container *container,
178+
dma_addr_t iova, int npage)
179+
{
180+
}
181+
182+
static inline int vfio_container_dma_rw(struct vfio_container *container,
183+
dma_addr_t iova, void *data, size_t len,
184+
bool write)
185+
{
186+
return -EOPNOTSUPP;
187+
}
188+
189+
static inline int vfio_container_init(void)
190+
{
191+
return 0;
192+
}
193+
static inline void vfio_container_cleanup(void)
194+
{
195+
}
196+
#endif
132197

133198
#if IS_ENABLED(CONFIG_IOMMUFD)
134199
int vfio_iommufd_bind(struct vfio_device *device, struct iommufd_ctx *ictx);

0 commit comments

Comments
 (0)