Re: [PATCH 13/14] vfio/pci: Preserve the iommufd state of the vfio cdev

Vipin Sharma
2026-03-23T21:17:35Z

On Tue, Feb 03, 2026 at 10:09:47PM +0000, Samiullah Khawaja wrote:
> If the vfio cdev is attached to an iommufd, preserve the state of the
> attached iommufd also. Basically preserve the iommu state of the device
> and also the attached domain. The token returned by the preservation API
> will be used to restore/rebind to the iommufd state after liveupdate.

Lets add token when it is used in restore/rebind patches in future.

> diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio_pci_liveupdate.c
> @@ -49,15 +51,32 @@ static int vfio_pci_liveupdate_preserve(struct liveupdate_file_op_args *args)
> if (vfio_pci_is_intel_display(pdev))
> return -EINVAL;
>
> +#if CONFIG_IOMMU_LIVEUPDATE
> + /* If iommufd is attached, preserve the underlying domain */
> + if (device->iommufd_attached) {
> + int err = iommufd_device_preserve(args->session,
> + device->iommufd_device,
> + &token);
> + if (err < 0)
> + return err;
> + }
> +#endif
> +
> ser = kho_alloc_preserve(sizeof(*ser));
> - if (IS_ERR(ser))
> + if (IS_ERR(ser)) {
> + if (device->iommufd_attached)
> + iommufd_device_unpreserve(args->session,
> + device->iommufd_device, token);
> +
> return PTR_ERR(ser);
> + }

driver/vfio/pci/iommufd.c has all of the code which interacts with
iommufd in VFIO, I think we should follow the convention and add a
function there which can be called from here.

> diff --git a/include/linux/kho/abi/vfio_pci.h b/include/linux/kho/abi/vfio_pci.h
> +/**
> + * struct vfio_iommufd_ser - Serialized state of the attached iommufd.
> + *
> + * @token: The token of the bound iommufd state.
> + */
> +struct vfio_iommufd_ser {
> + u32 token;

This is u32, whereas the token above is u64.