Re: [PATCH v6 18/24] iommu/amd: Init and clear vIOMMU DevID and DomID maps
From: Jason Gunthorpe
Date: Tue Oct 20 2026 - 12:56:55 EST
On Tue, Oct 20, 2026 at 11:00:25PM +0700, Suthikulpanit, Suravee wrote:
>
>
> On 10/16/2026 6:39 AM, Jason Gunthorpe wrote:
> > > Before using a vIOMMU instance, prefill the mapping tables so hardware
> > > never sees an unknown guest ID. Map every gdom_id to the nest parent
> > > domain ID, and write every gdev_id with hdev_id 0. Init cannot be
> > > scoped to IDs in use; INVALIDATE_IOMMU_ALL walks the HW table.
> > >
> > > Yield vfctrl_lock every 256 doorbells so the 128K MMIO loop can
> > > resched. Attach cannot run until viommu->ops is set after init_one().
> > >
> > > On destroy, drain CONTROL0/CONTROL1 WRITE and unmap. Do not rewrite
> > > the full tables: that would start 128K DMA writes into pages about
> > > to be freed. vDevice destroy and nested_domain_free already restored
> > > idle entries.
> > >
> > > Skip VFCTRL access when CONTROL_CMDBUF_EN is already clear, matching
> > > viommu_priv_unmap_free() on the same uninit_one() path.
> > I didn't see any explanation what happens if the guest issues an
> > invalidate to a gdomid without a host domid?
> >
> > This is related to my questions about when the IOTLB is cleaned. Given
> > this patch I would expect that once the mapping is removed the hdomid
> > is cleaned and any invalidations for the gdomid are NOPd
> >
> > If the gdomis is used again it is assigned to a clean hdomid and those
> > NOP'd invalidations don't matter.
> >
> > Is this how it works?
>
> When guest sends INVALIDATE_IOMMU_PAGES command with gDomID to vCmd buffer,
> IOMMU hardware uses the gDomID to index the DomainID mapping table to get
> the hDomID (from the entry w/ v=1). Then it uses the hDomID for actual
> IOMMU TLB invalidation. If the mapping entry has v=0, it would generate
> hardware error in the host Event log.
>
> If the hDomID does not match anything in the IOMMU TLB, it would be a NOP.
> This is the same as when host IOMMU driver submit INVALIDATE_IOMMU_PAGES
> command w/ an unused domainID.
>
> For current implementation, the IOMMU driver prefills the DomainID mapping
> table with nest parent domain ID (hDomID), and restore the same ID when
> mapping is removed. This is to make sure that each mapping entry has valid
> hDomID and not just some random domain ID.
I asked what happens if the gDomID hits an entry with V=0 ?
Presumably something bad to motivate all this extra work.
Jason