Re: [RFC PATCH 13/15] iommufd: Persist iommu domains for live update

Pasha Tatashin
2025-09-30T15:10:39Z

On Tue, Sep 30, 2025 at 9:59 AM Jason Gunthorpe <jgg@ziepe.ca> wrote:
>
> On Tue, Sep 30, 2025 at 09:07:48AM -0400, Pasha Tatashin wrote:
> > On Mon, Sep 29, 2025 at 12:00 PM Jason Gunthorpe <jgg@ziepe.ca> wrote:
> > >
> > > On Sun, Sep 28, 2025 at 07:06:21PM +0000, Samiullah Khawaja wrote:
> > > > +static int iommufd_save_ioas(struct iommufd_ctx *ictx,
> > > > + struct iommufd_lu *iommufd_lu)
> > > > +{
> > > > + struct iommufd_hwpt_paging *hwpt_paging;
> > > > + struct iommufd_ioas *ioas = NULL;
> > > > + struct iommufd_object *obj;
> > > > + unsigned long index;
> > > > + int rc;
> > > > +
> > > > + /* Iterate each ioas. */
> > > > + xa_for_each(&ictx->objects, index, obj) {
> > > > + if (obj->type != IOMMUFD_OBJ_IOAS)
> > > > + continue;
> > >
> > > Wrong locking
> > >
> > > > +
> > > > + ioas = (struct iommufd_ioas *)obj;
> > > > + mutex_lock(&ioas->mutex);
> > > > +
> > > > + /*
> > > > + * TODO: Iterate over each device of this iommufd and only save
> > > > + * hwpt/domain if the device is persisted.
> > > > + */
> > > > + list_for_each_entry(hwpt_paging, &ioas->hwpt_list, hwpt_item) {
> > > > + if (!hwpt_paging->common.domain)
> > > > + continue;
> > >
> > > I don't think this should be automatic. The user should directly
> > > serialize/unserialize HWPTs by ID.
> >
> > Why not? Live Updated uAPI is handled through FDs, and both iommufd
> > and vfiofd have to be preserved; I assume we can automatically
> > determine the hwpt to be preserved through dependencies. Why would we
> > delegate this to the user?
>
> There are HWPTs outside the IOAS so it is inconsisent.
>
> We are not going to reconstruct the IOAS.
>
> The IDR ids of the HWPT may not be available on restore (we cannot
> make this ABI), so without userspace expressly labeling them and
> recovering the new IDR ids it doesn't work.
>
> Finally we expect to discard the preserved HWPTs and replace them we
> rebuilt ones at least as a first step. Userspace needs to sequence all
> of this..

The way LUOv4 is implemented, "LUO sessions" are always participating
LU. Once a user adds file descriptors to a session, that session and
its contents are automatically carried across multiple consecutive
live updates. The user only needs to act if they explicitly want to
remove an FD and opt-out of preservation, or close session. This is
consistent and convenient for long-running VM that should survive by
default.

I was hoping for a similar "preserve by default" or "opt-in-once"
model for iommufd objects that are put into the LUO session to avoid a
flurry of IOCTLs to re-register before every single live update.

On the other hand, userspace still has to issue IOCTLs after retrieval
to bring the restored FDs and associated objects back to a workable
state. Perhaps, we could do something like "Yes, I'm actively using
this object again, so please preserve it if another live update
happens." ?

Pasha