Skip to content

Commit 0214392

Browse files
author
Alex Williamson
committed
Merge branch 'v6.8/vfio/virtio' into v6.8/vfio/next
2 parents 946cff2 + eb61eca commit 0214392

22 files changed

Lines changed: 1385 additions & 36 deletions

MAINTAINERS

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

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

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#define vfio_iowrite8 iowrite8
3939

4040
#define VFIO_IOWRITE(size) \
41-
static int vfio_pci_iowrite##size(struct vfio_pci_core_device *vdev, \
41+
int vfio_pci_core_iowrite##size(struct vfio_pci_core_device *vdev, \
4242
bool test_mem, u##size val, void __iomem *io) \
4343
{ \
4444
if (test_mem) { \
@@ -55,7 +55,8 @@ static int vfio_pci_iowrite##size(struct vfio_pci_core_device *vdev, \
5555
up_read(&vdev->memory_lock); \
5656
\
5757
return 0; \
58-
}
58+
} \
59+
EXPORT_SYMBOL_GPL(vfio_pci_core_iowrite##size);
5960

6061
VFIO_IOWRITE(8)
6162
VFIO_IOWRITE(16)
@@ -65,7 +66,7 @@ VFIO_IOWRITE(64)
6566
#endif
6667

6768
#define VFIO_IOREAD(size) \
68-
static int vfio_pci_ioread##size(struct vfio_pci_core_device *vdev, \
69+
int vfio_pci_core_ioread##size(struct vfio_pci_core_device *vdev, \
6970
bool test_mem, u##size *val, void __iomem *io) \
7071
{ \
7172
if (test_mem) { \
@@ -82,7 +83,8 @@ static int vfio_pci_ioread##size(struct vfio_pci_core_device *vdev, \
8283
up_read(&vdev->memory_lock); \
8384
\
8485
return 0; \
85-
}
86+
} \
87+
EXPORT_SYMBOL_GPL(vfio_pci_core_ioread##size);
8688

8789
VFIO_IOREAD(8)
8890
VFIO_IOREAD(16)
@@ -119,13 +121,13 @@ static ssize_t do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem,
119121
if (copy_from_user(&val, buf, 4))
120122
return -EFAULT;
121123

122-
ret = vfio_pci_iowrite32(vdev, test_mem,
123-
val, io + off);
124+
ret = vfio_pci_core_iowrite32(vdev, test_mem,
125+
val, io + off);
124126
if (ret)
125127
return ret;
126128
} else {
127-
ret = vfio_pci_ioread32(vdev, test_mem,
128-
&val, io + off);
129+
ret = vfio_pci_core_ioread32(vdev, test_mem,
130+
&val, io + off);
129131
if (ret)
130132
return ret;
131133

@@ -141,13 +143,13 @@ static ssize_t do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem,
141143
if (copy_from_user(&val, buf, 2))
142144
return -EFAULT;
143145

144-
ret = vfio_pci_iowrite16(vdev, test_mem,
145-
val, io + off);
146+
ret = vfio_pci_core_iowrite16(vdev, test_mem,
147+
val, io + off);
146148
if (ret)
147149
return ret;
148150
} else {
149-
ret = vfio_pci_ioread16(vdev, test_mem,
150-
&val, io + off);
151+
ret = vfio_pci_core_ioread16(vdev, test_mem,
152+
&val, io + off);
151153
if (ret)
152154
return ret;
153155

@@ -163,13 +165,13 @@ static ssize_t do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem,
163165
if (copy_from_user(&val, buf, 1))
164166
return -EFAULT;
165167

166-
ret = vfio_pci_iowrite8(vdev, test_mem,
167-
val, io + off);
168+
ret = vfio_pci_core_iowrite8(vdev, test_mem,
169+
val, io + off);
168170
if (ret)
169171
return ret;
170172
} else {
171-
ret = vfio_pci_ioread8(vdev, test_mem,
172-
&val, io + off);
173+
ret = vfio_pci_core_ioread8(vdev, test_mem,
174+
&val, io + off);
173175
if (ret)
174176
return ret;
175177

@@ -200,7 +202,7 @@ static ssize_t do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem,
200202
return done;
201203
}
202204

203-
static int vfio_pci_setup_barmap(struct vfio_pci_core_device *vdev, int bar)
205+
int vfio_pci_core_setup_barmap(struct vfio_pci_core_device *vdev, int bar)
204206
{
205207
struct pci_dev *pdev = vdev->pdev;
206208
int ret;
@@ -223,6 +225,7 @@ static int vfio_pci_setup_barmap(struct vfio_pci_core_device *vdev, int bar)
223225

224226
return 0;
225227
}
228+
EXPORT_SYMBOL_GPL(vfio_pci_core_setup_barmap);
226229

227230
ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
228231
size_t count, loff_t *ppos, bool iswrite)
@@ -262,7 +265,7 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
262265
}
263266
x_end = end;
264267
} else {
265-
int ret = vfio_pci_setup_barmap(vdev, bar);
268+
int ret = vfio_pci_core_setup_barmap(vdev, bar);
266269
if (ret) {
267270
done = ret;
268271
goto out;
@@ -363,21 +366,21 @@ static void vfio_pci_ioeventfd_do_write(struct vfio_pci_ioeventfd *ioeventfd,
363366
{
364367
switch (ioeventfd->count) {
365368
case 1:
366-
vfio_pci_iowrite8(ioeventfd->vdev, test_mem,
367-
ioeventfd->data, ioeventfd->addr);
369+
vfio_pci_core_iowrite8(ioeventfd->vdev, test_mem,
370+
ioeventfd->data, ioeventfd->addr);
368371
break;
369372
case 2:
370-
vfio_pci_iowrite16(ioeventfd->vdev, test_mem,
371-
ioeventfd->data, ioeventfd->addr);
373+
vfio_pci_core_iowrite16(ioeventfd->vdev, test_mem,
374+
ioeventfd->data, ioeventfd->addr);
372375
break;
373376
case 4:
374-
vfio_pci_iowrite32(ioeventfd->vdev, test_mem,
375-
ioeventfd->data, ioeventfd->addr);
377+
vfio_pci_core_iowrite32(ioeventfd->vdev, test_mem,
378+
ioeventfd->data, ioeventfd->addr);
376379
break;
377380
#ifdef iowrite64
378381
case 8:
379-
vfio_pci_iowrite64(ioeventfd->vdev, test_mem,
380-
ioeventfd->data, ioeventfd->addr);
382+
vfio_pci_core_iowrite64(ioeventfd->vdev, test_mem,
383+
ioeventfd->data, ioeventfd->addr);
381384
break;
382385
#endif
383386
}
@@ -438,7 +441,7 @@ int vfio_pci_ioeventfd(struct vfio_pci_core_device *vdev, loff_t offset,
438441
return -EINVAL;
439442
#endif
440443

441-
ret = vfio_pci_setup_barmap(vdev, bar);
444+
ret = vfio_pci_core_setup_barmap(vdev, bar);
442445
if (ret)
443446
return ret;
444447

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)