> From: Jason Gunthorpe <jgg@xxxxxxxxxx> > Sent: Wednesday, March 8, 2023 8:36 AM > > @@ -359,6 +360,76 @@ iommufd_device_do_attach(struct iommufd_device > *idev, > return NULL; > } > > +static struct iommufd_hw_pagetable * > +iommufd_device_do_replace(struct iommufd_device *idev, > + struct iommufd_hw_pagetable *hwpt) > +{ > + struct iommufd_group *igroup = idev->igroup; > + struct iommufd_hw_pagetable *old_hwpt; > + unsigned int num_devices = 0; > + struct iommufd_device *cur; > + int rc; > + > + mutex_lock(&idev->igroup->lock); > + > + if (hwpt == igroup->hwpt) { > + mutex_unlock(&idev->igroup->lock); > + return NULL; > + } > + > + /* Try to upgrade the domain we have */ > + list_for_each_entry(cur, &igroup->device_list, group_item) { > + num_devices++; > + if (cur->enforce_cache_coherency) { > + rc = iommufd_hw_pagetable_enforce_cc(hwpt); > + if (rc) > + goto err_unlock; > + } > + } > + > + old_hwpt = igroup->hwpt; > + if (hwpt->ioas != old_hwpt->ioas) { Do we allow this function to be used as attach/detach? if yes old_hwpt could be NULL here. if no an explicit check on old_hwpt!=NULL is also required. and looks the policy for physical attach is different from the one that Nicoline applies for access. iommufd_access_set_ioas() can behave like normal attach/detach. should be consistent here.