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

Vipin Sharma
2026-03-24T20:30:31Z

On Mon, Mar 23, 2026 at 10:07:31PM +0000, Samiullah Khawaja wrote:
> 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:
> > > 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.

Yes. sorry, for the wrong path. Sounds good, I misunderstood things.