Re: [PATCH v3 10/18] iommu/vt-d: Restore IOMMU state and reclaimed domain ids
From: Baolu Lu
Date: Mon Jun 22 2026 - 01:16:23 EST
On 6/15/26 07:37, Samiullah Khawaja wrote:
During boot fetch the preserved state of IOMMU unit and if found then
restore the state.
- Reuse the root_table that was preserved in the previous kernel.
- Reclaim the domain ids of the preserved domains for each preserved
devices so these are not acquired by another domain.
Signed-off-by: Samiullah Khawaja<skhawaja@xxxxxxxxxx>
---
drivers/iommu/intel/iommu.c | 87 +++++++++++++++++++++++---------
drivers/iommu/intel/iommu.h | 7 +++
drivers/iommu/intel/liveupdate.c | 60 ++++++++++++++++++++++
3 files changed, 130 insertions(+), 24 deletions(-)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 26258861e3bf..cd40e274482b 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -990,15 +990,16 @@ static void disable_dmar_iommu(struct intel_iommu *iommu)
iommu_disable_translation(iommu);
}
-static void free_dmar_iommu(struct intel_iommu *iommu)
+static void free_dmar_iommu(struct intel_iommu *iommu, struct iommu_hw_ser *iommu_ser)
{
if (iommu->copied_tables) {
bitmap_free(iommu->copied_tables);
iommu->copied_tables = NULL;
}
- /* free context mapping */
- free_context_table(iommu);
+ /* free context mapping if there is no serialized state. */
+ if (!iommu_ser)
+ free_context_table(iommu);
if (ecap_prs(iommu->ecap))
intel_iommu_finish_prq(iommu);
disable_dmar_iommu() and free_dmar_iommu() are always paired in the
code. How about merging them into a single helper that is aware of iommu
preservation? Something like the following?
static void release_dmar_iommu(struct intel_iommu *iommu)
{
struct iommu_hw_ser *iommu_ser =
iommu_get_preserved_data(iommu->reg_phys, IOMMU_INTEL);
/*
* All iommu domains must have been detached from the devices,
* hence there should be no domain IDs in use.
*/
if (WARN_ON(!ida_is_empty(&iommu->domain_ida)))
return;
if ((iommu->gcmd & DMA_GCMD_TE) && !iommu_ser)
iommu_disable_translation(iommu);
if (iommu->copied_tables) {
bitmap_free(iommu->copied_tables);
iommu->copied_tables = NULL;
}
/* free context mapping if there is no serialized state. */
if (!iommu_ser)
free_context_table(iommu);
if (ecap_prs(iommu->ecap))
intel_iommu_finish_prq(iommu);
}
Thanks,
baolu