Skip to content

Commit cac85e4

Browse files
committed
Merge tag 'vfio-v6.3-rc1' of https://github.com/awilliam/linux-vfio
Pull VFIO updates from Alex Williamson: - Remove redundant resource check in vfio-platform (Angus Chen) - Use GFP_KERNEL_ACCOUNT for persistent userspace allocations, allowing removal of arbitrary kernel limits in favor of cgroup control (Yishai Hadas) - mdev tidy-ups, including removing the module-only build restriction for sample drivers, Kconfig changes to select mdev support, documentation movement to keep sample driver usage instructions with sample drivers rather than with API docs, remove references to out-of-tree drivers in docs (Christoph Hellwig) - Fix collateral breakages from mdev Kconfig changes (Arnd Bergmann) - Make mlx5 migration support match device support, improve source and target flows to improve pre-copy support and reduce downtime (Yishai Hadas) - Convert additional mdev sysfs case to use sysfs_emit() (Bo Liu) - Resolve copy-paste error in mdev mbochs sample driver Kconfig (Ye Xingchen) - Avoid propagating missing reset error in vfio-platform if reset requirement is relaxed by module option (Tomasz Duszynski) - Range size fixes in mlx5 variant driver for missed last byte and stricter range calculation (Yishai Hadas) - Fixes to suspended vaddr support and locked_vm accounting, excluding mdev configurations from the former due to potential to indefinitely block kernel threads, fix underflow and restore locked_vm on new mm (Steve Sistare) - Update outdated vfio documentation due to new IOMMUFD interfaces in recent kernels (Yi Liu) - Resolve deadlock between group_lock and kvm_lock, finally (Matthew Rosato) - Fix NULL pointer in group initialization error path with IOMMUFD (Yan Zhao) * tag 'vfio-v6.3-rc1' of https://github.com/awilliam/linux-vfio: (32 commits) vfio: Fix NULL pointer dereference caused by uninitialized group->iommufd docs: vfio: Update vfio.rst per latest interfaces vfio: Update the kdoc for vfio_device_ops vfio/mlx5: Fix range size calculation upon tracker creation vfio: no need to pass kvm pointer during device open vfio: fix deadlock between group lock and kvm lock vfio: revert "iommu driver notify callback" vfio/type1: revert "implement notify callback" vfio/type1: revert "block on invalid vaddr" vfio/type1: restore locked_vm vfio/type1: track locked_vm per dma vfio/type1: prevent underflow of locked_vm via exec() vfio/type1: exclude mdevs from VFIO_UPDATE_VADDR vfio: platform: ignore missing reset if disabled at module init vfio/mlx5: Improve the target side flow to reduce downtime vfio/mlx5: Improve the source side flow upon pre_copy vfio/mlx5: Check whether VF is migratable samples: fix the prompt about SAMPLE_VFIO_MDEV_MBOCHS vfio/mdev: Use sysfs_emit() to instead of sprintf() vfio-mdev: add back CONFIG_VFIO dependency ...
2 parents 84cc667 + d649c34 commit cac85e4

33 files changed

+756
-422
lines changed

Documentation/driver-api/vfio-mediated-device.rst

Lines changed: 1 addition & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ devices as examples, as these devices are the first devices to use this module::
6060
| mdev.ko |
6161
| +-----------+ | mdev_register_parent() +--------------+
6262
| | | +<------------------------+ |
63-
| | | | | nvidia.ko |<-> physical
63+
| | | | | ccw_device.ko|<-> physical
6464
| | | +------------------------>+ | device
6565
| | | | callbacks +--------------+
6666
| | Physical | |
@@ -69,12 +69,6 @@ devices as examples, as these devices are the first devices to use this module::
6969
| | | | | i915.ko |<-> physical
7070
| | | +------------------------>+ | device
7171
| | | | callbacks +--------------+
72-
| | | |
73-
| | | | mdev_register_parent() +--------------+
74-
| | | +<------------------------+ |
75-
| | | | | ccw_device.ko|<-> physical
76-
| | | +------------------------>+ | device
77-
| | | | callbacks +--------------+
7872
| +-----------+ |
7973
+---------------+
8074

@@ -270,106 +264,6 @@ these callbacks are supported in the TYPE1 IOMMU module. To enable them for
270264
other IOMMU backend modules, such as PPC64 sPAPR module, they need to provide
271265
these two callback functions.
272266

273-
Using the Sample Code
274-
=====================
275-
276-
mtty.c in samples/vfio-mdev/ directory is a sample driver program to
277-
demonstrate how to use the mediated device framework.
278-
279-
The sample driver creates an mdev device that simulates a serial port over a PCI
280-
card.
281-
282-
1. Build and load the mtty.ko module.
283-
284-
This step creates a dummy device, /sys/devices/virtual/mtty/mtty/
285-
286-
Files in this device directory in sysfs are similar to the following::
287-
288-
# tree /sys/devices/virtual/mtty/mtty/
289-
/sys/devices/virtual/mtty/mtty/
290-
|-- mdev_supported_types
291-
| |-- mtty-1
292-
| | |-- available_instances
293-
| | |-- create
294-
| | |-- device_api
295-
| | |-- devices
296-
| | `-- name
297-
| `-- mtty-2
298-
| |-- available_instances
299-
| |-- create
300-
| |-- device_api
301-
| |-- devices
302-
| `-- name
303-
|-- mtty_dev
304-
| `-- sample_mtty_dev
305-
|-- power
306-
| |-- autosuspend_delay_ms
307-
| |-- control
308-
| |-- runtime_active_time
309-
| |-- runtime_status
310-
| `-- runtime_suspended_time
311-
|-- subsystem -> ../../../../class/mtty
312-
`-- uevent
313-
314-
2. Create a mediated device by using the dummy device that you created in the
315-
previous step::
316-
317-
# echo "83b8f4f2-509f-382f-3c1e-e6bfe0fa1001" > \
318-
/sys/devices/virtual/mtty/mtty/mdev_supported_types/mtty-2/create
319-
320-
3. Add parameters to qemu-kvm::
321-
322-
-device vfio-pci,\
323-
sysfsdev=/sys/bus/mdev/devices/83b8f4f2-509f-382f-3c1e-e6bfe0fa1001
324-
325-
4. Boot the VM.
326-
327-
In the Linux guest VM, with no hardware on the host, the device appears
328-
as follows::
329-
330-
# lspci -s 00:05.0 -xxvv
331-
00:05.0 Serial controller: Device 4348:3253 (rev 10) (prog-if 02 [16550])
332-
Subsystem: Device 4348:3253
333-
Physical Slot: 5
334-
Control: I/O+ Mem- BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr-
335-
Stepping- SERR- FastB2B- DisINTx-
336-
Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=medium >TAbort-
337-
<TAbort- <MAbort- >SERR- <PERR- INTx-
338-
Interrupt: pin A routed to IRQ 10
339-
Region 0: I/O ports at c150 [size=8]
340-
Region 1: I/O ports at c158 [size=8]
341-
Kernel driver in use: serial
342-
00: 48 43 53 32 01 00 00 02 10 02 00 07 00 00 00 00
343-
10: 51 c1 00 00 59 c1 00 00 00 00 00 00 00 00 00 00
344-
20: 00 00 00 00 00 00 00 00 00 00 00 00 48 43 53 32
345-
30: 00 00 00 00 00 00 00 00 00 00 00 00 0a 01 00 00
346-
347-
In the Linux guest VM, dmesg output for the device is as follows:
348-
349-
serial 0000:00:05.0: PCI INT A -> Link[LNKA] -> GSI 10 (level, high) -> IRQ 10
350-
0000:00:05.0: ttyS1 at I/O 0xc150 (irq = 10) is a 16550A
351-
0000:00:05.0: ttyS2 at I/O 0xc158 (irq = 10) is a 16550A
352-
353-
354-
5. In the Linux guest VM, check the serial ports::
355-
356-
# setserial -g /dev/ttyS*
357-
/dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4
358-
/dev/ttyS1, UART: 16550A, Port: 0xc150, IRQ: 10
359-
/dev/ttyS2, UART: 16550A, Port: 0xc158, IRQ: 10
360-
361-
6. Using minicom or any terminal emulation program, open port /dev/ttyS1 or
362-
/dev/ttyS2 with hardware flow control disabled.
363-
364-
7. Type data on the minicom terminal or send data to the terminal emulation
365-
program and read the data.
366-
367-
Data is loop backed from hosts mtty driver.
368-
369-
8. Destroy the mediated device that you created::
370-
371-
# echo 1 > /sys/bus/mdev/devices/83b8f4f2-509f-382f-3c1e-e6bfe0fa1001/remove
372-
373267
References
374268
==========
375269

Documentation/driver-api/vfio.rst

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,21 @@ VFIO bus driver API
249249

250250
VFIO bus drivers, such as vfio-pci make use of only a few interfaces
251251
into VFIO core. When devices are bound and unbound to the driver,
252-
the driver should call vfio_register_group_dev() and
253-
vfio_unregister_group_dev() respectively::
252+
Following interfaces are called when devices are bound to and
253+
unbound from the driver::
254254

255-
void vfio_init_group_dev(struct vfio_device *device,
256-
struct device *dev,
257-
const struct vfio_device_ops *ops);
258-
void vfio_uninit_group_dev(struct vfio_device *device);
259255
int vfio_register_group_dev(struct vfio_device *device);
256+
int vfio_register_emulated_iommu_dev(struct vfio_device *device);
260257
void vfio_unregister_group_dev(struct vfio_device *device);
261258

262-
The driver should embed the vfio_device in its own structure and call
263-
vfio_init_group_dev() to pre-configure it before going to registration
264-
and call vfio_uninit_group_dev() after completing the un-registration.
259+
The driver should embed the vfio_device in its own structure and use
260+
vfio_alloc_device() to allocate the structure, and can register
261+
@init/@release callbacks to manage any private state wrapping the
262+
vfio_device::
263+
264+
vfio_alloc_device(dev_struct, member, dev, ops);
265+
void vfio_put_device(struct vfio_device *device);
266+
265267
vfio_register_group_dev() indicates to the core to begin tracking the
266268
iommu_group of the specified dev and register the dev as owned by a VFIO bus
267269
driver. Once vfio_register_group_dev() returns it is possible for userspace to
@@ -270,28 +272,64 @@ ready before calling it. The driver provides an ops structure for callbacks
270272
similar to a file operations structure::
271273

272274
struct vfio_device_ops {
273-
int (*open)(struct vfio_device *vdev);
275+
char *name;
276+
int (*init)(struct vfio_device *vdev);
274277
void (*release)(struct vfio_device *vdev);
278+
int (*bind_iommufd)(struct vfio_device *vdev,
279+
struct iommufd_ctx *ictx, u32 *out_device_id);
280+
void (*unbind_iommufd)(struct vfio_device *vdev);
281+
int (*attach_ioas)(struct vfio_device *vdev, u32 *pt_id);
282+
int (*open_device)(struct vfio_device *vdev);
283+
void (*close_device)(struct vfio_device *vdev);
275284
ssize_t (*read)(struct vfio_device *vdev, char __user *buf,
276285
size_t count, loff_t *ppos);
277-
ssize_t (*write)(struct vfio_device *vdev,
278-
const char __user *buf,
279-
size_t size, loff_t *ppos);
286+
ssize_t (*write)(struct vfio_device *vdev, const char __user *buf,
287+
size_t count, loff_t *size);
280288
long (*ioctl)(struct vfio_device *vdev, unsigned int cmd,
281289
unsigned long arg);
282-
int (*mmap)(struct vfio_device *vdev,
283-
struct vm_area_struct *vma);
290+
int (*mmap)(struct vfio_device *vdev, struct vm_area_struct *vma);
291+
void (*request)(struct vfio_device *vdev, unsigned int count);
292+
int (*match)(struct vfio_device *vdev, char *buf);
293+
void (*dma_unmap)(struct vfio_device *vdev, u64 iova, u64 length);
294+
int (*device_feature)(struct vfio_device *device, u32 flags,
295+
void __user *arg, size_t argsz);
284296
};
285297

286298
Each function is passed the vdev that was originally registered
287-
in the vfio_register_group_dev() call above. This allows the bus driver
288-
to obtain its private data using container_of(). The open/release
289-
callbacks are issued when a new file descriptor is created for a
290-
device (via VFIO_GROUP_GET_DEVICE_FD). The ioctl interface provides
291-
a direct pass through for VFIO_DEVICE_* ioctls. The read/write/mmap
292-
interfaces implement the device region access defined by the device's
293-
own VFIO_DEVICE_GET_REGION_INFO ioctl.
299+
in the vfio_register_group_dev() or vfio_register_emulated_iommu_dev()
300+
call above. This allows the bus driver to obtain its private data using
301+
container_of().
302+
303+
::
304+
305+
- The init/release callbacks are issued when vfio_device is initialized
306+
and released.
307+
308+
- The open/close device callbacks are issued when the first
309+
instance of a file descriptor for the device is created (eg.
310+
via VFIO_GROUP_GET_DEVICE_FD) for a user session.
311+
312+
- The ioctl callback provides a direct pass through for some VFIO_DEVICE_*
313+
ioctls.
314+
315+
- The [un]bind_iommufd callbacks are issued when the device is bound to
316+
and unbound from iommufd.
317+
318+
- The attach_ioas callback is issued when the device is attached to an
319+
IOAS managed by the bound iommufd. The attached IOAS is automatically
320+
detached when the device is unbound from iommufd.
321+
322+
- The read/write/mmap callbacks implement the device region access defined
323+
by the device's own VFIO_DEVICE_GET_REGION_INFO ioctl.
324+
325+
- The request callback is issued when device is going to be unregistered,
326+
such as when trying to unbind the device from the vfio bus driver.
294327

328+
- The dma_unmap callback is issued when a range of iovas are unmapped
329+
in the container or IOAS attached by the device. Drivers which make
330+
use of the vfio page pinning interface must implement this callback in
331+
order to unpin pages within the dma_unmap range. Drivers must tolerate
332+
this callback even before calls to open_device().
295333

296334
PPC64 sPAPR implementation note
297335
-------------------------------

Documentation/s390/vfio-ap.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,6 @@ These are the steps:
553553
* ZCRYPT
554554
* S390_AP_IOMMU
555555
* VFIO
556-
* VFIO_MDEV
557556
* KVM
558557

559558
If using make menuconfig select the following to build the vfio_ap module::

MAINTAINERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21882,7 +21882,6 @@ F: tools/testing/selftests/filesystems/fat/
2188221882

2188321883
VFIO DRIVER
2188421884
M: Alex Williamson <[email protected]>
21885-
R: Cornelia Huck <[email protected]>
2188621885
2188721886
S: Maintained
2188821887
T: git https://github.com/awilliam/linux-vfio.git

arch/s390/Kconfig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,9 @@ config EADM_SCH
714714
config VFIO_CCW
715715
def_tristate n
716716
prompt "Support for VFIO-CCW subchannels"
717-
depends on S390_CCW_IOMMU && VFIO_MDEV
717+
depends on S390_CCW_IOMMU
718+
depends on VFIO
719+
select VFIO_MDEV
718720
help
719721
This driver allows usage of I/O subchannels via VFIO-CCW.
720722

@@ -724,8 +726,10 @@ config VFIO_CCW
724726
config VFIO_AP
725727
def_tristate n
726728
prompt "VFIO support for AP devices"
727-
depends on S390_AP_IOMMU && VFIO_MDEV && KVM
729+
depends on S390_AP_IOMMU && KVM
730+
depends on VFIO
728731
depends on ZCRYPT
732+
select VFIO_MDEV
729733
help
730734
This driver grants access to Adjunct Processor (AP) devices
731735
via the VFIO mediated device interface.

arch/s390/configs/debug_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,6 @@ CONFIG_SYNC_FILE=y
594594
CONFIG_VFIO=m
595595
CONFIG_VFIO_PCI=m
596596
CONFIG_MLX5_VFIO_PCI=m
597-
CONFIG_VFIO_MDEV=m
598597
CONFIG_VIRTIO_PCI=m
599598
CONFIG_VIRTIO_BALLOON=m
600599
CONFIG_VIRTIO_INPUT=y

arch/s390/configs/defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,6 @@ CONFIG_SYNC_FILE=y
583583
CONFIG_VFIO=m
584584
CONFIG_VFIO_PCI=m
585585
CONFIG_MLX5_VFIO_PCI=m
586-
CONFIG_VFIO_MDEV=m
587586
CONFIG_VIRTIO_PCI=m
588587
CONFIG_VIRTIO_BALLOON=m
589588
CONFIG_VIRTIO_INPUT=y

drivers/gpu/drm/i915/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ config DRM_I915_GVT_KVMGT
127127
depends on X86
128128
depends on 64BIT
129129
depends on KVM
130-
depends on VFIO_MDEV
130+
depends on VFIO
131131
select DRM_I915_GVT
132132
select KVM_EXTERNAL_WRITE_TRACKING
133+
select VFIO_MDEV
133134

134135
help
135136
Choose this option if you want to enable Intel GVT-g graphics

drivers/vfio/container.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static int vfio_fops_open(struct inode *inode, struct file *filep)
360360
{
361361
struct vfio_container *container;
362362

363-
container = kzalloc(sizeof(*container), GFP_KERNEL);
363+
container = kzalloc(sizeof(*container), GFP_KERNEL_ACCOUNT);
364364
if (!container)
365365
return -ENOMEM;
366366

@@ -376,11 +376,6 @@ static int vfio_fops_open(struct inode *inode, struct file *filep)
376376
static int vfio_fops_release(struct inode *inode, struct file *filep)
377377
{
378378
struct vfio_container *container = filep->private_data;
379-
struct vfio_iommu_driver *driver = container->iommu_driver;
380-
381-
if (driver && driver->ops->notify)
382-
driver->ops->notify(container->iommu_data,
383-
VFIO_IOMMU_CONTAINER_CLOSE);
384379

385380
filep->private_data = NULL;
386381

drivers/vfio/fsl-mc/vfio_fsl_mc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static int vfio_fsl_mc_open_device(struct vfio_device *core_vdev)
2828
int i;
2929

3030
vdev->regions = kcalloc(count, sizeof(struct vfio_fsl_mc_region),
31-
GFP_KERNEL);
31+
GFP_KERNEL_ACCOUNT);
3232
if (!vdev->regions)
3333
return -ENOMEM;
3434

0 commit comments

Comments
 (0)