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

Samiullah Khawaja
2026-03-23T22:07:37Z

On Mon, Mar 23, 2026 at 02:17:29PM -0700, Vipin Sharma wrote:
>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.

Agreed.
>
>> 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.

I am assuming you meant driver/vfio/iommufd.c as
drivers/vfio/pci/iommufd.c doens't exist.

I see iommufd_ctx and other iommufd_ functions being used directly in
various places outside drivers/vfio/iommufd.c, so there is not a hard
split I think. This will introduce unnecessary indirection I think.
>
>> 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.

Will update.
>
>

Thanks,
Sami