Re: [PATCH v2 09/16] iommu/vt-d: Restore IOMMU state and reclaimed domain ids
From: Pranjal Shrivastava
Date: Wed May 20 2026 - 14:20:26 EST
On Tue, May 19, 2026 at 09:46:52PM +0000, Pranjal Shrivastava wrote:
> On Mon, Apr 27, 2026 at 05:56:26PM +0000, 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 | 55 ++++++++++++++++++++++--------
> > drivers/iommu/intel/iommu.h | 7 ++++
> > drivers/iommu/intel/liveupdate.c | 57 ++++++++++++++++++++++++++++++++
> > 3 files changed, 105 insertions(+), 14 deletions(-)
> >
> > if (translation_pre_enabled(iommu) && !is_kdump_kernel()) {
> > iommu_disable_translation(iommu);
> > @@ -1648,7 +1661,7 @@ static int __init init_dmars(void)
> > * we could share the same root & context tables
> > * among all IOMMU's. Need to Split it later.
> > */
> > - ret = iommu_alloc_root_entry(iommu);
> > + ret = iommu_alloc_root_entry(iommu, iommu_ser);
> > if (ret)
> > goto free_iommu;
> >
> > @@ -1732,8 +1745,12 @@ static int __init init_dmars(void)
> >
> > free_iommu:
> > for_each_active_iommu(iommu, drhd) {
> > - disable_dmar_iommu(iommu);
> > - free_dmar_iommu(iommu);
> > + iommu_ser = iommu_get_preserved_data(iommu->reg_phys, IOMMU_INTEL);
> > +
> > + if (!iommu_ser)
> > + disable_dmar_iommu(iommu);
> > +
> > + free_dmar_iommu(iommu, iommu_ser);
> > }
> >
>
> I'm wondering what happens if init_dmars fails for a preserved iommu?
> Since we have non NULL iommu_ser, we'll skip disable_dmar_iommu and skip
> free_context_table() inside free_dmar_iommu() as well. I'm concerned we
> might leak some resources in this case. If the failure happens after we
> set restored = 1, even a rmmod -> modprobe cycle won't help fix the leak
>
Re-visiting this, I think we don't need to worry as skipping restore is
the intended behaviour.. we don't wanna attempt restore on things that
have already been restored. Please ignore this
Thanks,
Praan