vfio/pci: add support for VF token

VF token was introduced [1] to kernel vfio-pci along with SR-IOV
support [2].  This patch adds support VF token among PF and VF(s). To
passthu PCIe VF to a VM, kernel >= v5.7 needs this.

It can be configured with UUID like:

  -device vfio-pci,host=DDDD:BB:DD:F,vf-token=<uuid>,...

[1] https://lore.kernel.org/linux-pci/158396393244.5601.10297430724964025753.stgit@gimli.home/
[2] https://lore.kernel.org/linux-pci/158396044753.5601.14804870681174789709.stgit@gimli.home/

Cc: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Minwoo Im <minwoo.im@samsung.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Link: https://lore.kernel.org/r/20230320073522epcms2p48f682ecdb73e0ae1a4850ad0712fd780@epcms2p4
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
This commit is contained in:
Minwoo Im 2023-03-20 16:35:22 +09:00 committed by Alex Williamson
parent 271477b59e
commit 2dca1b37a7
2 changed files with 13 additions and 1 deletions

View file

@ -2856,6 +2856,8 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
int groupid; int groupid;
int i, ret; int i, ret;
bool is_mdev; bool is_mdev;
char uuid[UUID_FMT_LEN];
char *name;
if (!vbasedev->sysfsdev) { if (!vbasedev->sysfsdev) {
if (!(~vdev->host.domain || ~vdev->host.bus || if (!(~vdev->host.domain || ~vdev->host.bus ||
@ -2936,7 +2938,15 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
goto error; goto error;
} }
ret = vfio_get_device(group, vbasedev->name, vbasedev, errp); if (!qemu_uuid_is_null(&vdev->vf_token)) {
qemu_uuid_unparse(&vdev->vf_token, uuid);
name = g_strdup_printf("%s vf_token=%s", vbasedev->name, uuid);
} else {
name = vbasedev->name;
}
ret = vfio_get_device(group, name, vbasedev, errp);
g_free(name);
if (ret) { if (ret) {
vfio_put_group(group); vfio_put_group(group);
goto error; goto error;
@ -3268,6 +3278,7 @@ static void vfio_instance_init(Object *obj)
static Property vfio_pci_dev_properties[] = { static Property vfio_pci_dev_properties[] = {
DEFINE_PROP_PCI_HOST_DEVADDR("host", VFIOPCIDevice, host), DEFINE_PROP_PCI_HOST_DEVADDR("host", VFIOPCIDevice, host),
DEFINE_PROP_UUID_NODEFAULT("vf-token", VFIOPCIDevice, vf_token),
DEFINE_PROP_STRING("sysfsdev", VFIOPCIDevice, vbasedev.sysfsdev), DEFINE_PROP_STRING("sysfsdev", VFIOPCIDevice, vbasedev.sysfsdev),
DEFINE_PROP_ON_OFF_AUTO("x-pre-copy-dirty-page-tracking", VFIOPCIDevice, DEFINE_PROP_ON_OFF_AUTO("x-pre-copy-dirty-page-tracking", VFIOPCIDevice,
vbasedev.pre_copy_dirty_page_tracking, vbasedev.pre_copy_dirty_page_tracking,

View file

@ -137,6 +137,7 @@ struct VFIOPCIDevice {
VFIOVGA *vga; /* 0xa0000, 0x3b0, 0x3c0 */ VFIOVGA *vga; /* 0xa0000, 0x3b0, 0x3c0 */
void *igd_opregion; void *igd_opregion;
PCIHostDeviceAddress host; PCIHostDeviceAddress host;
QemuUUID vf_token;
EventNotifier err_notifier; EventNotifier err_notifier;
EventNotifier req_notifier; EventNotifier req_notifier;
int (*resetfn)(struct VFIOPCIDevice *); int (*resetfn)(struct VFIOPCIDevice *);