hw/vfio: thread vf-token through iommufd bind
PATCH 1/1 hw/vfio: thread vf-token through iommufd bind
A VF fails to bind through the iommufd/cdev backend when its PF is bound to vfio-pci and requires a matching VF token.
QEMU currently initializes struct vfio_device_bind_iommufd without the token flag or token UUID.
Pass the existing vf-token device property to the IOMMUFD bind ioctl for PCI devices.
--- hw/vfio/iommufd.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
hw/vfio/iommufd.c +10 -0
@@ -155,6 +155,7 @@ static void iommufd_cdev_kvm_device_del(VFIODevice *vbasedev)static bool iommufd_cdev_connect_and_bind (VFIODevice *vbasedev,Error **errp) { +VFIOPCIDevice *vdev =vfio_pci_from_vfio_device (vbasedev);IOMMUFDBackend *iommufd = vbasedev->iommufd;struct vfio_device_bind_iommufd bind = { .argsz =sizeof (bind),
@@ -180,6 +181,15 @@ static bool iommufd_cdev_connect_and_bind(VFIODevice *vbasedev, Error **errp)/* Bind device to iommufd */ bind.iommufd = iommufd->fd; + +/* +* Pass the VF token when binding a PCI device. +*/ +if (vdev && !qemu_uuid_is_null (&vdev->vf_token)) { + bind.flags |=VFIO_DEVICE_BIND_FLAG_TOKEN ; + bind.token_uuid_ptr = (uintptr_t )&vdev->vf_token; + } +if (ioctl (vbasedev->fd,VFIO_DEVICE_BIND_IOMMUFD , &bind)) {error_setg_errno (errp, errno,"error bind device fd=%d to iommufd=%d" , vbasedev->fd, bind.iommufd);
Signature · 1 line
2.34.1
Quoted 32 lines · Tushar Dave
A VF fails to bind through the iommufd/cdev backend when its PF is bound to vfio-pci and requires a matching VF token.
QEMU currently initializes struct
vfio_device_bind_iommufdwithout the token flag or token UUID.Pass the existing vf-token device property to the IOMMUFD bind ioctl for PCI devices.
Signed-off-by Tushar Dave <[email protected]>--- hw/vfio/iommufd.c | 10 ++++++++++ 1 file changed, 10 insertions(+)hw/vfio/iommufd.c +3
-0@@ -155,6 +155,7 @@ static void iommufd_cdev_kvm_device_del(VFIODevice *vbasedev)static bool iommufd_cdev_connect_and_bind (VFIODevice *vbasedev,Error **errp) { +VFIOPCIDevice *vdev =vfio_pci_from_vfio_device (vbasedev);IOMMUFDBackend *iommufd = vbasedev->iommufd;struct vfio_device_bind_iommufd bind = { .argsz =sizeof (bind),@@ -180,6 +181,15 @@ static bool iommufd_cdev_connect_and_bind(VFIODevice *vbasedev, Error **errp)/* Bind device to iommufd */ bind.iommufd = iommufd->fd; + +/*
hw/vfio/iommufd.c static bool iommufd_cdev_connect_and_bind(VFIODevice *vbasedev, Error **errp) · line 195
Quoted 10 lines
hw/vfio/iommufd.c +7
-0+* Pass the VF token when binding a PCI device. +*/ +if (vdev && !qemu_uuid_is_null (&vdev->vf_token)) { + bind.flags |=VFIO_DEVICE_BIND_FLAG_TOKEN ; + bind.token_uuid_ptr = (uintptr_t )&vdev->vf_token; + } +if (ioctl (vbasedev->fd,VFIO_DEVICE_BIND_IOMMUFD , &bind)) {error_setg_errno (errp, errno,"error bind device fd=%d to iommufd=%d" , vbasedev->fd, bind.iommufd);
Thanks,
C.
Quoted 13 lines
-----Original Message-----
From: Tushar Dave <[email protected]>
Sent: 08 September 2026 17:08
To: [email protected]; [email protected]; [email protected]; Shameer Kolothum Thodi <[email protected]>
Cc: Jason Gunthorpe <[email protected]>
Subject: [PATCH 1/1] hw/vfio: thread vf-token through iommufd bindA VF fails to bind through the iommufd/cdev backend when its PF is bound to vfio-pci and requires a matching VF token.
Quoted 7 lines
QEMU currently initializes struct
vfio_device_bind_iommufdwithout the token flag or token UUID.Pass the existing vf-token device property to the IOMMUFD bind ioctl for PCI devices.
Signed-off-by Tushar Dave <[email protected]>
Thanks,
Shameer
Quoted 37 lines
--- hw/vfio/iommufd.c | 10 ++++++++++ 1 file changed, 10 insertions(+)hw/vfio/iommufd.c +1
-0@@ -155,6 +155,7 @@ static void iommufd_cdev_kvm_device_del(VFIODevice *vbasedev)static bool iommufd_cdev_connect_and_bind (VFIODevice *vbasedev,Error **errp) { +VFIOPCIDevice *vdev =vfio_pci_from_vfio_device (vbasedev);IOMMUFDBackend *iommufd = vbasedev->iommufd;struct
vfio_device_bind_iommufdbind = {
.argsz = sizeof(bind),hw/vfio/iommufd.c +9
-0@@ -180,6 +181,15 @@ static booliommufd_cdev_connect_and_bind (VFIODevice *vbasedev, Error **errp)/* Bind device to iommufd */ bind.iommufd = iommufd->fd; + +/* +* Pass the VF token when binding a PCI device. +*/ +if (vdev && !qemu_uuid_is_null (&vdev->vf_token)) { + bind.flags |=VFIO_DEVICE_BIND_FLAG_TOKEN ; + bind.token_uuid_ptr = (uintptr_t )&vdev->vf_token; + } +if (ioctl (vbasedev->fd,VFIO_DEVICE_BIND_IOMMUFD , &bind)) { error_setg_errno(errp, errno, "error bind device fd=%d to iommufd=%d",vbasedev->fd, bind.iommufd);--
2.34.1