All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] hw/vfio: thread vf-token through iommufd bind
@ 2026-09-08 16:07 Tushar Dave
  2026-09-11  5:50 ` Cédric Le Goater
  2026-09-11  8:12 ` Shameer Kolothum Thodi
  0 siblings, 2 replies; 3+ messages in thread
From: Tushar Dave @ 2026-09-08 16:07 UTC (permalink / raw)
  To: alex, clg, qemu-devel, skolothumtho; +Cc: jgg

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.

Signed-off-by: Tushar Dave <tdave@nvidia.com>
---
 hw/vfio/iommufd.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index 242644aa00..de482128bf 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -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);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] hw/vfio: thread vf-token through iommufd bind
  2026-09-08 16:07 [PATCH 1/1] hw/vfio: thread vf-token through iommufd bind Tushar Dave
@ 2026-09-11  5:50 ` Cédric Le Goater
  2026-09-11  8:12 ` Shameer Kolothum Thodi
  1 sibling, 0 replies; 3+ messages in thread
From: Cédric Le Goater @ 2026-09-11  5:50 UTC (permalink / raw)
  To: Tushar Dave, alex, qemu-devel, skolothumtho; +Cc: jgg

On 9/8/26 18:07, Tushar Dave wrote:
> 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.
> 
> Signed-off-by: Tushar Dave <tdave@nvidia.com>
> ---
>   hw/vfio/iommufd.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
> index 242644aa00..de482128bf 100644
> --- a/hw/vfio/iommufd.c
> +++ b/hw/vfio/iommufd.c
> @@ -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);

Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH 1/1] hw/vfio: thread vf-token through iommufd bind
  2026-09-08 16:07 [PATCH 1/1] hw/vfio: thread vf-token through iommufd bind Tushar Dave
  2026-09-11  5:50 ` Cédric Le Goater
@ 2026-09-11  8:12 ` Shameer Kolothum Thodi
  1 sibling, 0 replies; 3+ messages in thread
From: Shameer Kolothum Thodi @ 2026-09-11  8:12 UTC (permalink / raw)
  To: Tushar Dave, alex@shazbot.org, clg@redhat.com,
	qemu-devel@nongnu.org
  Cc: Jason Gunthorpe



> -----Original Message-----
> From: Tushar Dave <tdave@nvidia.com>
> Sent: 08 September 2026 17:08
> To: alex@shazbot.org; clg@redhat.com; qemu-devel@nongnu.org; Shameer
> Kolothum Thodi <skolothumtho@nvidia.com>
> Cc: Jason Gunthorpe <jgg@nvidia.com>
> Subject: [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.
> 
> Signed-off-by: Tushar Dave <tdave@nvidia.com>

Reviewed-by: Shameer Kolothum <skolothumtho@nvidia.com>

Thanks,
Shameer

> ---
>  hw/vfio/iommufd.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
> index 242644aa00..de482128bf 100644
> --- a/hw/vfio/iommufd.c
> +++ b/hw/vfio/iommufd.c
> @@ -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);
> --
> 2.34.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-11  8:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-08 16:07 [PATCH 1/1] hw/vfio: thread vf-token through iommufd bind Tushar Dave
2026-09-11  5:50 ` Cédric Le Goater
2026-09-11  8:12 ` Shameer Kolothum Thodi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.