Re: [PATCH v6 02/18] iommu/pages: Add APIs to preserve/unpreserve/restore iommu pages

From: Baolu Lu

Date: Thu Oct 29 2026 - 21:27:26 EST


On 10/25/2026 10:19 AM, Samiullah Khawaja wrote:
IOMMU pages are allocated/freed using APIs using struct ioptdesc. For
the proper preservation and restoration of ioptdesc add helper
functions.

Reviewed-by: Pranjal Shrivastava<praan@xxxxxxxxxx>
Signed-off-by: Samiullah Khawaja<skhawaja@xxxxxxxxxx>
---
drivers/iommu/iommu-pages.c | 109 ++++++++++++++++++++++++++++++++++--
drivers/iommu/iommu-pages.h | 30 ++++++++++
2 files changed, 135 insertions(+), 4 deletions(-)


[...]

+
+/**
+ * iommu_restore_pages - Restore pages that were preserved in KHO
+ * @phys: Physical address of page to restore
+ */
+void iommu_restore_pages(u64 phys)
+{
+ struct ioptdesc *iopt;
+ struct folio *folio;
+ unsigned long pgcnt;
+ unsigned int order;
+
+ folio = kho_restore_folio(phys);
+ if (!folio)
+ panic("Failed to restore preserved IOMMU page %llx\n", phys);
+
+ iopt = folio_ioptdesc(folio);
+
+ /*
+ * For the restored pages incoherent is set to false as these are not
+ * mapped using the DMA_API. The remapping of these pages using DMA_API
+ * is not needed as these are not going to be written to by the new
+ * kernel.
+ */
+ iopt->incoherent = false;
+
+ order = folio_order(folio);
+ pgcnt = 1UL << order;
+ iommu_folio_update_stats(folio, pgcnt);
+}
+EXPORT_SYMBOL_GPL(iommu_restore_pages);

The pages were charged to the VMM's memcg in the old kernel (iommufd
maps with GFP_KERNEL_ACCOUNT), but after the live update they are no
longer charged to any memcg. I think that's fine, because the restored
tables are immutable and will be replaced by ordinary ones after boot.

This patch looks good to me,

Reviewed-by: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>