Re: [RFC PATCH 08/15] iommu/vt-d: Implement live update preserve_iommu_context

From: Jason Gunthorpe

Date: Mon Sep 29 2025 - 11:57:25 EST


On Sun, Sep 28, 2025 at 07:06:16PM +0000, Samiullah Khawaja wrote:
> +static int unpreserve_iommu_context(struct intel_iommu *iommu, int end)
> +{
> + struct context_entry *context;
> + int i;
> +
> + if (end < 0)
> + end = ROOT_ENTRY_NR;
> +
> + for (i = 0; i < end; i++) {
> + context = iommu_context_addr(iommu, i, 0, 0);
> + if (context)
> + WARN_ON_ONCE(kho_unpreserve_folio(virt_to_folio(context)));

Wrong function. IIRC all of these allocations came from iommu-pages.c
and have struct page metadata.

iommu-pages needs to participate in restoring them and put back it's
struct page information.

> static int preserve_iommu_state(struct intel_iommu *iommu,
> struct iommu_unit_ser *ser)
> {
> - pr_warn("Not implemented\n");
> - return 0;
> + int ret;
> +
> + spin_lock(&iommu->lock);
> + ret = preserve_iommu_context(iommu);
> + if (ret)
> + goto error;
> +
> + ret = kho_preserve_folio(virt_to_folio(iommu->root_entry));
> + if (ret) {
> + unpreserve_iommu_context(iommu, -1);
> + goto error;
> + }
> +
> + ser->phys_addr = iommu->reg_phys;
> + ser->root_table = __pa(iommu->root_entry);
> + atomic_set(&iommu->preserved, 1);

Why all these atomics??

Also most probably this should all be flowing through the core code as
I think the core code has to genericall prevent attach/detach/probe
from happing once serialization has started.

Jason