Skip to content

Commit 244aefb

Browse files
committed
Merge tag 'vfio-v6.8-rc1' of https://github.com/awilliam/linux-vfio
Pull VFIO updates from Alex Williamson: - Add debugfs support, initially used for reporting device migration state (Longfang Liu) - Fixes and support for migration dirty tracking across multiple IOVA regions in the pds-vfio-pci driver (Brett Creeley) - Improved IOMMU allocation accounting visibility (Pasha Tatashin) - Virtio infrastructure and a new virtio-vfio-pci variant driver, which provides emulation of a legacy virtio interfaces on modern virtio hardware for virtio-net VF devices where the PF driver exposes support for legacy admin queues, ie. an emulated IO BAR on an SR-IOV VF to provide driver ABI compatibility to legacy devices (Yishai Hadas & Feng Liu) - Migration fixes for the hisi-acc-vfio-pci variant driver (Shameer Kolothum) - Kconfig dependency fix for new virtio-vfio-pci variant driver (Arnd Bergmann) * tag 'vfio-v6.8-rc1' of https://github.com/awilliam/linux-vfio: (22 commits) vfio/virtio: fix virtio-pci dependency hisi_acc_vfio_pci: Update migration data pointer correctly on saving/resume vfio/virtio: Declare virtiovf_pci_aer_reset_done() static vfio/virtio: Introduce a vfio driver over virtio devices vfio/pci: Expose vfio_pci_core_iowrite/read##size() vfio/pci: Expose vfio_pci_core_setup_barmap() virtio-pci: Introduce APIs to execute legacy IO admin commands virtio-pci: Initialize the supported admin commands virtio-pci: Introduce admin commands virtio-pci: Introduce admin command sending function virtio-pci: Introduce admin virtqueue virtio: Define feature bit for administration virtqueue vfio/type1: account iommu allocations vfio/pds: Add multi-region support vfio/pds: Move seq/ack bitmaps into region struct vfio/pds: Pass region info to relevant functions vfio/pds: Move and rename region specific info vfio/pds: Only use a single SGL for both seq and ack vfio/pds: Fix calculations in pds_vfio_dirty_sync MAINTAINERS: Add vfio debugfs interface doc link ...
2 parents 86c4d58 + 78f70c0 commit 244aefb

34 files changed

Lines changed: 1754 additions & 164 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
What: /sys/kernel/debug/vfio
2+
Date: December 2023
3+
KernelVersion: 6.8
4+
Contact: Longfang Liu <liulongfang@huawei.com>
5+
Description: This debugfs file directory is used for debugging
6+
of vfio devices, it's a common directory for all vfio devices.
7+
Vfio core will create a device subdirectory under this
8+
directory.
9+
10+
What: /sys/kernel/debug/vfio/<device>/migration
11+
Date: December 2023
12+
KernelVersion: 6.8
13+
Contact: Longfang Liu <liulongfang@huawei.com>
14+
Description: This debugfs file directory is used for debugging
15+
of vfio devices that support live migration.
16+
The debugfs of each vfio device that supports live migration
17+
could be created under this directory.
18+
19+
What: /sys/kernel/debug/vfio/<device>/migration/state
20+
Date: December 2023
21+
KernelVersion: 6.8
22+
Contact: Longfang Liu <liulongfang@huawei.com>
23+
Description: Read the live migration status of the vfio device.
24+
The contents of the state file reflects the migration state
25+
relative to those defined in the vfio_device_mig_state enum

MAINTAINERS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23002,6 +23002,7 @@ M: Alex Williamson <alex.williamson@redhat.com>
2300223002
L: kvm@vger.kernel.org
2300323003
S: Maintained
2300423004
T: git https://github.com/awilliam/linux-vfio.git
23005+
F: Documentation/ABI/testing/debugfs-vfio
2300523006
F: Documentation/ABI/testing/sysfs-devices-vfio-dev
2300623007
F: Documentation/driver-api/vfio.rst
2300723008
F: drivers/vfio/
@@ -23037,6 +23038,13 @@ L: kvm@vger.kernel.org
2303723038
S: Maintained
2303823039
F: drivers/vfio/pci/mlx5/
2303923040

23041+
VFIO VIRTIO PCI DRIVER
23042+
M: Yishai Hadas <yishaih@nvidia.com>
23043+
L: kvm@vger.kernel.org
23044+
L: virtualization@lists.linux-foundation.org
23045+
S: Maintained
23046+
F: drivers/vfio/pci/virtio
23047+
2304023048
VFIO PCI DEVICE SPECIFIC DRIVERS
2304123049
R: Jason Gunthorpe <jgg@nvidia.com>
2304223050
R: Yishai Hadas <yishaih@nvidia.com>

drivers/vfio/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ config VFIO_VIRQFD
8080
select EVENTFD
8181
default n
8282

83+
config VFIO_DEBUGFS
84+
bool "Export VFIO internals in DebugFS"
85+
depends on DEBUG_FS
86+
help
87+
Allows exposure of VFIO device internals. This option enables
88+
the use of debugfs by VFIO drivers as required. The device can
89+
cause the VFIO code create a top-level debug/vfio directory
90+
during initialization, and then populate a subdirectory with
91+
entries as required.
92+
8393
source "drivers/vfio/pci/Kconfig"
8494
source "drivers/vfio/platform/Kconfig"
8595
source "drivers/vfio/mdev/Kconfig"

drivers/vfio/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ vfio-$(CONFIG_VFIO_GROUP) += group.o
77
vfio-$(CONFIG_IOMMUFD) += iommufd.o
88
vfio-$(CONFIG_VFIO_CONTAINER) += container.o
99
vfio-$(CONFIG_VFIO_VIRQFD) += virqfd.o
10+
vfio-$(CONFIG_VFIO_DEBUGFS) += debugfs.o
1011

1112
obj-$(CONFIG_VFIO_IOMMU_TYPE1) += vfio_iommu_type1.o
1213
obj-$(CONFIG_VFIO_IOMMU_SPAPR_TCE) += vfio_iommu_spapr_tce.o

drivers/vfio/debugfs.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright (c) 2023, HiSilicon Ltd.
4+
*/
5+
6+
#include <linux/device.h>
7+
#include <linux/debugfs.h>
8+
#include <linux/seq_file.h>
9+
#include <linux/vfio.h>
10+
#include "vfio.h"
11+
12+
static struct dentry *vfio_debugfs_root;
13+
14+
static int vfio_device_state_read(struct seq_file *seq, void *data)
15+
{
16+
struct device *vf_dev = seq->private;
17+
struct vfio_device *vdev = container_of(vf_dev,
18+
struct vfio_device, device);
19+
enum vfio_device_mig_state state;
20+
int ret;
21+
22+
BUILD_BUG_ON(VFIO_DEVICE_STATE_NR !=
23+
VFIO_DEVICE_STATE_PRE_COPY_P2P + 1);
24+
25+
ret = vdev->mig_ops->migration_get_state(vdev, &state);
26+
if (ret)
27+
return -EINVAL;
28+
29+
switch (state) {
30+
case VFIO_DEVICE_STATE_ERROR:
31+
seq_puts(seq, "ERROR\n");
32+
break;
33+
case VFIO_DEVICE_STATE_STOP:
34+
seq_puts(seq, "STOP\n");
35+
break;
36+
case VFIO_DEVICE_STATE_RUNNING:
37+
seq_puts(seq, "RUNNING\n");
38+
break;
39+
case VFIO_DEVICE_STATE_STOP_COPY:
40+
seq_puts(seq, "STOP_COPY\n");
41+
break;
42+
case VFIO_DEVICE_STATE_RESUMING:
43+
seq_puts(seq, "RESUMING\n");
44+
break;
45+
case VFIO_DEVICE_STATE_RUNNING_P2P:
46+
seq_puts(seq, "RUNNING_P2P\n");
47+
break;
48+
case VFIO_DEVICE_STATE_PRE_COPY:
49+
seq_puts(seq, "PRE_COPY\n");
50+
break;
51+
case VFIO_DEVICE_STATE_PRE_COPY_P2P:
52+
seq_puts(seq, "PRE_COPY_P2P\n");
53+
break;
54+
default:
55+
seq_puts(seq, "Invalid\n");
56+
}
57+
58+
return 0;
59+
}
60+
61+
void vfio_device_debugfs_init(struct vfio_device *vdev)
62+
{
63+
struct device *dev = &vdev->device;
64+
65+
vdev->debug_root = debugfs_create_dir(dev_name(vdev->dev),
66+
vfio_debugfs_root);
67+
68+
if (vdev->mig_ops) {
69+
struct dentry *vfio_dev_migration = NULL;
70+
71+
vfio_dev_migration = debugfs_create_dir("migration",
72+
vdev->debug_root);
73+
debugfs_create_devm_seqfile(dev, "state", vfio_dev_migration,
74+
vfio_device_state_read);
75+
}
76+
}
77+
78+
void vfio_device_debugfs_exit(struct vfio_device *vdev)
79+
{
80+
debugfs_remove_recursive(vdev->debug_root);
81+
}
82+
83+
void vfio_debugfs_create_root(void)
84+
{
85+
vfio_debugfs_root = debugfs_create_dir("vfio", NULL);
86+
}
87+
88+
void vfio_debugfs_remove_root(void)
89+
{
90+
debugfs_remove_recursive(vfio_debugfs_root);
91+
vfio_debugfs_root = NULL;
92+
}

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/hisilicon/hisi_acc_vfio_pci.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ static ssize_t hisi_acc_vf_resume_write(struct file *filp, const char __user *bu
694694
size_t len, loff_t *pos)
695695
{
696696
struct hisi_acc_vf_migration_file *migf = filp->private_data;
697+
u8 *vf_data = (u8 *)&migf->vf_data;
697698
loff_t requested_length;
698699
ssize_t done = 0;
699700
int ret;
@@ -715,7 +716,7 @@ static ssize_t hisi_acc_vf_resume_write(struct file *filp, const char __user *bu
715716
goto out_unlock;
716717
}
717718

718-
ret = copy_from_user(&migf->vf_data, buf, len);
719+
ret = copy_from_user(vf_data + *pos, buf, len);
719720
if (ret) {
720721
done = -EFAULT;
721722
goto out_unlock;
@@ -835,7 +836,9 @@ static ssize_t hisi_acc_vf_save_read(struct file *filp, char __user *buf, size_t
835836

836837
len = min_t(size_t, migf->total_length - *pos, len);
837838
if (len) {
838-
ret = copy_to_user(buf, &migf->vf_data, len);
839+
u8 *vf_data = (u8 *)&migf->vf_data;
840+
841+
ret = copy_to_user(buf, vf_data + *pos, len);
839842
if (ret) {
840843
done = -EFAULT;
841844
goto out_unlock;

0 commit comments

Comments
 (0)