Re: [PATCH v7 12/18] iommu: Restore and reattach preserved domains to devices
From: Baolu Lu
Date: Mon Nov 16 2026 - 21:29:54 EST
On 11/10/2026 12:08 PM, Samiullah Khawaja wrote:
During default domain setup, restore the preserved domains by restoring
the page tables using restore() iommupt op. Associated the restored
domain with the iommu group of the preserved device, and reattach the
domain to the device.
Signed-off-by: Samiullah Khawaja <skhawaja@xxxxxxxxxx>
---
drivers/iommu/iommu.c | 115 +++++++++++++++++++++++++++++--
drivers/iommu/liveupdate.c | 106 ++++++++++++++++++++++++++++
include/linux/iommu-liveupdate.h | 39 +++++++++++
3 files changed, 253 insertions(+), 7 deletions(-)
[...]
+
+/**
+ * iommu_restore_domain() - Restore a preserved domain for a device
+ * @dev: Target device
+ * @ser: Serialized device state
+ *
+ * Restores or reuses a restored preserved domain for @dev from serialized state
+ * @ser.
+ *
+ * Return: Restored iommu_domain pointer, or ERR_PTR.
+ */
+struct iommu_domain *iommu_restore_domain(struct device *dev,
+ struct iommu_device_ser *ser)
+{
+ struct iommu_domain_ser *domain_ser;
+ struct iommu_flb_obj *flb_obj;
+ struct iommu_domain *domain;
+ struct pt_iommu *pt;
+ int ret;
+
+ ret = iommu_liveupdate_flb_get_incoming(&flb_obj);
+ if (ret)
+ return ERR_PTR(ret);
+
+ mutex_lock(&flb_obj->lock);
+
+ /* Preserved device should have a preserved domain */
+ if (!ser->attachment.domain_phys) {
+ domain = ERR_PTR(-EINVAL);
+ goto out;
+ }
+
+ domain_ser = phys_to_virt(ser->attachment.domain_phys);
+ if (domain_ser->restored_domain) {
+ domain = domain_ser->restored_domain;
+ goto out;
+ }
+
+ domain_ser->hdr.flags |= IOMMU_SER_FLAG_INCOMING;
+ domain = iommu_paging_domain_alloc(dev);
Ah, here it is.
This allocation uses the driver's default. For VT-d, it prefers first-
stage translation when supported. But the preserved domain may be
second-stage, for example if it was allocated for dirty tracking or
nested parent. Would the restore callback then walk the preserved page
table using the wrong format-specific operations?
+ if (IS_ERR(domain))Thanks,
+ goto out;
+
+ pt = iommupt_from_domain(domain);
+ if (!pt) {
+ iommu_domain_free(domain);
+ domain = ERR_PTR(-EOPNOTSUPP);
+ goto out;
+ }
+
+ ret = pt->ops->restore(pt, domain_ser);
+ if (ret) {
+ iommu_domain_free(domain);
+ domain = ERR_PTR(ret);
+ goto out;
+ }
+
+ domain->domain_ser = domain_ser;
+ domain_ser->restored_domain = domain;
+
+out:
+ mutex_unlock(&flb_obj->lock);
+ liveupdate_flb_put_incoming(&iommu_flb);
+ return domain;
+}
diff --git a/include/linux/iommu-liveupdate.h b/include/linux/iommu-liveupdate.h
index fb1e8efac8ec..68c7ebca25f6 100644
--- a/include/linux/iommu-liveupdate.h
+++ b/include/linux/iommu-liveupdate.h
@@ -99,8 +99,31 @@ static inline void *dev_iommu_restored_state(struct device *dev)
return NULL;
}
baolu