Re: [PATCH v7 13/18] iommu/vt-d: Handle reattach of the restored domain

From: Samiullah Khawaja

Date: Mon Nov 16 2026 - 15:06:00 EST


On Mon, Nov 16, 2026 at 03:38:14PM +0800, Baolu Lu wrote:
On 11/10/2026 12:08 PM, Samiullah Khawaja wrote:
Reattach the restored domain to the preserved device using restored
domain ID. While reattaching do not setup the context and PASID entries
as those are preserved during liveupdate.

Note that in this phase nothing clears IOMMU_SER_FLAG_INCOMING of the
restored domain or the restored state of the device, so the restored
domain cannot be replaced yet. Replacing it is left to a later phase.

Signed-off-by: Samiullah Khawaja<skhawaja@xxxxxxxxxx>
---
drivers/iommu/intel/iommu.c | 28 ++++--
drivers/iommu/intel/iommu.h | 14 +++
drivers/iommu/intel/liveupdate.c | 141 +++++++++++++++++++++++++++++++
3 files changed, 175 insertions(+), 8 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index b3402fd9fe75..95ec37554360 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -3296,6 +3296,9 @@ static int intel_iommu_attach_device(struct iommu_domain *domain,
{
int ret;
+ if (dev_iommu_restored_state(dev))
+ return intel_iommu_attach_restored_device(domain, dev);

How is the restored domain's type and page table format selected? I
don't see the allocation path using the preserved state to choose
between different domain type and page table format. Could this result
in a mismatch with the hardware configuration?

The restored domain is always a paging domain allocated with the default
flags, as only those can be preserved. With the default flags the driver
picks the page table format from the IOMMU capabilities and
configuration. These stay the same across a live update on the same
machine, so the new kernel always picks the same format. I will record
the default paging domain format in the preserved IOMMU state, and use
it when allocating the restored domain to check if the formats match. I
will also add sanity checks in the HWPT preservation for this.

+
device_block_translation(dev);
ret = paging_domain_compatible(domain, dev);
@@ -3426,7 +3429,8 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev)
info->iommu = iommu;
RB_CLEAR_NODE(&info->node);
if (dev_is_pci(dev)) {
- if (ecap_dev_iotlb_support(iommu->ecap) &&
+ if (!dev_iommu_restored_state(dev) &&
+ ecap_dev_iotlb_support(iommu->ecap) &&
pci_ats_supported(pdev) &&
dmar_ats_supported(pdev, iommu)) {
info->ats_supported = 1;
@@ -3531,12 +3535,16 @@ static void intel_iommu_release_device(struct device *dev)
struct device_domain_info *info = dev_iommu_priv_get(dev);
struct intel_iommu *iommu = info->iommu;
- iommu_disable_pci_pri(info);
- iommu_disable_pci_ats(info);
+ if (!dev_iommu_restored_state(dev)) {
+ iommu_disable_pci_pri(info);
+ iommu_disable_pci_ats(info);

Above changes are not needed for domain reattachment, right? My
understanding is that ATS and PRI are not supported for preserved
devices in this phase. If so, could they be split into a separate patch?

Yes the ATS/PRI should already be disabled for preserved device so this
change is basically a no-op. I will remove this.

- if (info->pasid_enabled) {
- pci_disable_pasid(to_pci_dev(dev));
- info->pasid_enabled = 0;
+ if (info->pasid_enabled) {
+ pci_disable_pasid(to_pci_dev(dev));
+ info->pasid_enabled = 0;
+ }
+ } else {
+ intel_iommu_detach_restored_device(dev);
}
mutex_lock(&iommu->iopf_lock);
@@ -3544,11 +3552,15 @@ static void intel_iommu_release_device(struct device *dev)
device_rbtree_remove(info);
mutex_unlock(&iommu->iopf_lock);
- if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev) &&
+ if (!dev_iommu_restored_state(dev) && sm_supported(iommu) &&
+ !dev_is_real_dma_subdevice(dev) &&
!context_copied(iommu, info->bus, info->devfn))
intel_pasid_teardown_sm_context(dev);
- intel_pasid_free_table(dev);
+ if (!dev_iommu_restored_state(dev))
+ intel_pasid_free_table(dev);
+ else
+ kfree(info->pasid_table);
intel_iommu_debugfs_remove_dev(info);
kfree(info);
}

Thanks,
baolu

Thanks,
Sami