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

Jason Gunthorpe
2025-09-29T17:43:12Z

On Mon, Sep 29, 2025 at 10:32:22AM -0700, Samiullah Khawaja wrote:
> On Mon, Sep 29, 2025 at 9:00 AM 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.
> Interesting. So the user should be able to serialize/unserialize HWPTs
> before the Live Update PREPARE event? But what if a device was marked
> for preservation but the user never serialized the attached HWPT,
> would that be considered an error during LUO PREPARE or should iommufd
> serialize the remaining HWPTs here?

yes that would be an error

I also think your patch series is a bit upside down, you should
present the iommufd and core pieces first, then come with a driver
implementation last.

It will be easier to understand the context that having a driver
implementation appear out of no where with no callers..

And everything should be driven by iommufd in this step, the iommu
driver should not be magically auto-preserving itself. Just preserve
the drivers linked to devices being preserved by iommufd.

Jason