Skip to content

Commit 40bcdb1

Browse files
Yishai Hadasawilliam
authored andcommitted
vfio/virtio: Enable live migration once VIRTIO_PCI was configured
Now that the driver supports live migration, only the legacy IO functionality depends on config VIRTIO_PCI_ADMIN_LEGACY. As part of that we introduce a bool configuration option as a sub menu under the driver's main live migration feature named VIRTIO_VFIO_PCI_ADMIN_LEGACY, to control the legacy IO functionality. This will let users configuring the kernel, know which features from the description might be available in the resulting driver. As of that, move the legacy IO into a separate file to be compiled only once CONFIG_VIRTIO_VFIO_PCI_ADMIN_LEGACY was configured and let the live migration depends only on VIRTIO_PCI. Signed-off-by: Yishai Hadas <yishaih@nvidia.com> Link: https://lore.kernel.org/r/20241113115200.209269-8-yishaih@nvidia.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 6cea64b commit 40bcdb1

File tree

5 files changed

+489
-401
lines changed

5 files changed

+489
-401
lines changed

drivers/vfio/pci/virtio/Kconfig

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
config VIRTIO_VFIO_PCI
3-
tristate "VFIO support for VIRTIO NET PCI devices"
4-
depends on VIRTIO_PCI && VIRTIO_PCI_ADMIN_LEGACY
5-
select VFIO_PCI_CORE
6-
help
7-
This provides support for exposing VIRTIO NET VF devices which support
8-
legacy IO access, using the VFIO framework that can work with a legacy
9-
virtio driver in the guest.
10-
Based on PCIe spec, VFs do not support I/O Space.
11-
As of that this driver emulates I/O BAR in software to let a VF be
12-
seen as a transitional device by its users and let it work with
13-
a legacy driver.
14-
15-
If you don't know what to do here, say N.
3+
tristate "VFIO support for VIRTIO NET PCI VF devices"
4+
depends on VIRTIO_PCI
5+
select VFIO_PCI_CORE
6+
help
7+
This provides migration support for VIRTIO NET PCI VF devices
8+
using the VFIO framework. Migration support requires the
9+
SR-IOV PF device to support specific VIRTIO extensions,
10+
otherwise this driver provides no additional functionality
11+
beyond vfio-pci.
12+
13+
Migration support in this driver relies on dirty page tracking
14+
provided by the IOMMU hardware and exposed through IOMMUFD, any
15+
other use cases are dis-recommended.
16+
17+
If you don't know what to do here, say N.
18+
19+
config VIRTIO_VFIO_PCI_ADMIN_LEGACY
20+
bool "Legacy I/O support for VIRTIO NET PCI VF devices"
21+
depends on VIRTIO_VFIO_PCI && VIRTIO_PCI_ADMIN_LEGACY
22+
default y
23+
help
24+
This extends the virtio-vfio-pci driver to support legacy I/O
25+
access, allowing use of legacy virtio drivers with VIRTIO NET
26+
PCI VF devices. Legacy I/O support requires the SR-IOV PF
27+
device to support and enable specific VIRTIO extensions,
28+
otherwise this driver provides no additional functionality
29+
beyond vfio-pci.
30+
31+
If you don't know what to do here, say N.

drivers/vfio/pci/virtio/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
obj-$(CONFIG_VIRTIO_VFIO_PCI) += virtio-vfio-pci.o
33
virtio-vfio-pci-y := main.o migrate.o
4+
virtio-vfio-pci-$(CONFIG_VIRTIO_VFIO_PCI_ADMIN_LEGACY) += legacy_io.o

drivers/vfio/pci/virtio/common.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct virtiovf_migration_file {
7878

7979
struct virtiovf_pci_core_device {
8080
struct vfio_pci_core_device core_device;
81+
#ifdef CONFIG_VIRTIO_VFIO_PCI_ADMIN_LEGACY
8182
u8 *bar0_virtual_buf;
8283
/* synchronize access to the virtual buf */
8384
struct mutex bar_mutex;
@@ -87,6 +88,7 @@ struct virtiovf_pci_core_device {
8788
__le16 pci_cmd;
8889
u8 bar0_virtual_buf_size;
8990
u8 notify_bar;
91+
#endif
9092

9193
/* LM related */
9294
u8 migrate_cap:1;
@@ -105,4 +107,21 @@ void virtiovf_open_migration(struct virtiovf_pci_core_device *virtvdev);
105107
void virtiovf_close_migration(struct virtiovf_pci_core_device *virtvdev);
106108
void virtiovf_migration_reset_done(struct pci_dev *pdev);
107109

110+
#ifdef CONFIG_VIRTIO_VFIO_PCI_ADMIN_LEGACY
111+
int virtiovf_open_legacy_io(struct virtiovf_pci_core_device *virtvdev);
112+
long virtiovf_vfio_pci_core_ioctl(struct vfio_device *core_vdev,
113+
unsigned int cmd, unsigned long arg);
114+
int virtiovf_pci_ioctl_get_region_info(struct vfio_device *core_vdev,
115+
unsigned int cmd, unsigned long arg);
116+
ssize_t virtiovf_pci_core_write(struct vfio_device *core_vdev,
117+
const char __user *buf, size_t count,
118+
loff_t *ppos);
119+
ssize_t virtiovf_pci_core_read(struct vfio_device *core_vdev, char __user *buf,
120+
size_t count, loff_t *ppos);
121+
bool virtiovf_support_legacy_io(struct pci_dev *pdev);
122+
int virtiovf_init_legacy_io(struct virtiovf_pci_core_device *virtvdev);
123+
void virtiovf_release_legacy_io(struct virtiovf_pci_core_device *virtvdev);
124+
void virtiovf_legacy_io_reset_done(struct pci_dev *pdev);
125+
#endif
126+
108127
#endif /* VIRTIO_VFIO_COMMON_H */

0 commit comments

Comments
 (0)