Skip to content

Commit eb61eca

Browse files
yishaihAlex Williamson
authored andcommitted
vfio/virtio: Introduce a vfio driver over virtio devices
Introduce a vfio driver over virtio devices to support the legacy interface functionality for VFs. Background, from the virtio spec [1]. -------------------------------------------------------------------- In some systems, there is a need to support a virtio legacy driver with a device that does not directly support the legacy interface. In such scenarios, a group owner device can provide the legacy interface functionality for the group member devices. The driver of the owner device can then access the legacy interface of a member device on behalf of the legacy member device driver. For example, with the SR-IOV group type, group members (VFs) can not present the legacy interface in an I/O BAR in BAR0 as expected by the legacy pci driver. If the legacy driver is running inside a virtual machine, the hypervisor executing the virtual machine can present a virtual device with an I/O BAR in BAR0. The hypervisor intercepts the legacy driver accesses to this I/O BAR and forwards them to the group owner device (PF) using group administration commands. -------------------------------------------------------------------- Specifically, this driver adds support for a virtio-net VF to be exposed as a transitional device to a guest driver and allows the legacy IO BAR functionality on top. This allows a VM which uses a legacy virtio-net driver in the guest to work transparently over a VF which its driver in the host is that new driver. The driver can be extended easily to support some other types of virtio devices (e.g virtio-blk), by adding in a few places the specific type properties as was done for virtio-net. For now, only the virtio-net use case was tested and as such we introduce the support only for such a device. Practically, Upon probing a VF for a virtio-net device, in case its PF supports legacy access over the virtio admin commands and the VF doesn't have BAR 0, we set some specific 'vfio_device_ops' to be able to simulate in SW a transitional device with I/O BAR in BAR 0. The existence of the simulated I/O bar is reported later on by overwriting the VFIO_DEVICE_GET_REGION_INFO command and the device exposes itself as a transitional device by overwriting some properties upon reading its config space. Once we report the existence of I/O BAR as BAR 0 a legacy driver in the guest may use it via read/write calls according to the virtio specification. Any read/write towards the control parts of the BAR will be captured by the new driver and will be translated into admin commands towards the device. In addition, any data path read/write access (i.e. virtio driver notifications) will be captured by the driver and forwarded to the physical BAR which its properties were supplied by the admin command VIRTIO_ADMIN_CMD_LEGACY_NOTIFY_INFO upon the probing/init flow. With that code in place a legacy driver in the guest has the look and feel as if having a transitional device with legacy support for both its control and data path flows. [1] oasis-tcs/virtio-spec@03c2d32 Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Yishai Hadas <yishaih@nvidia.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Link: https://lore.kernel.org/r/20231219093247.170936-10-yishaih@nvidia.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 8486ae1 commit eb61eca

6 files changed

Lines changed: 605 additions & 0 deletions

File tree

MAINTAINERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22872,6 +22872,13 @@ L: kvm@vger.kernel.org
2287222872
S: Maintained
2287322873
F: drivers/vfio/pci/mlx5/
2287422874

22875+
VFIO VIRTIO PCI DRIVER
22876+
M: Yishai Hadas <yishaih@nvidia.com>
22877+
L: kvm@vger.kernel.org
22878+
L: virtualization@lists.linux-foundation.org
22879+
S: Maintained
22880+
F: drivers/vfio/pci/virtio
22881+
2287522882
VFIO PCI DEVICE SPECIFIC DRIVERS
2287622883
R: Jason Gunthorpe <jgg@nvidia.com>
2287722884
R: Yishai Hadas <yishaih@nvidia.com>

drivers/vfio/pci/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,6 @@ source "drivers/vfio/pci/hisilicon/Kconfig"
6565

6666
source "drivers/vfio/pci/pds/Kconfig"
6767

68+
source "drivers/vfio/pci/virtio/Kconfig"
69+
6870
endmenu

drivers/vfio/pci/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ obj-$(CONFIG_MLX5_VFIO_PCI) += mlx5/
1313
obj-$(CONFIG_HISI_ACC_VFIO_PCI) += hisilicon/
1414

1515
obj-$(CONFIG_PDS_VFIO_PCI) += pds/
16+
17+
obj-$(CONFIG_VIRTIO_VFIO_PCI) += virtio/

drivers/vfio/pci/virtio/Kconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
config VIRTIO_VFIO_PCI
3+
tristate "VFIO support for VIRTIO NET PCI devices"
4+
depends on 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.

drivers/vfio/pci/virtio/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
obj-$(CONFIG_VIRTIO_VFIO_PCI) += virtio-vfio-pci.o
3+
virtio-vfio-pci-y := main.o

0 commit comments

Comments
 (0)