Re: [RFC PATCH v2 9/9] iommu/riscv: Add riscv_iommu_attach_dev_nested

From: Gong Shuai

Date: Tue Nov 10 2026 - 07:06:13 EST


Hi Jason,

> On Thu, Nov 05, 2026 at 10:49:44PM +0800, Tan Chi wrote:
> > Hi Shuai and Fei,
> >
> > I noticed a potential issue with fixing the physical DC's PSCID to 0.
> >
> > In QEMU, different VFIO devices can have separate stage-1 HWPTs while
> > sharing the same vIOMMU and stage-2 parent. This means two devices may
> > have different first-stage page table roots but the same host GSCID
> > and PSCID=0.
> >
> > According to the RISC-V IOMMU specification, DC.ta.PSCID identifies
> > the first-stage address space when PDTV=0 and the first stage is not
> > Bare. Could this cause the physical IOMMU to reuse cached translations
> > across different stage-1 address spaces? Even broader invalidations
> > would not prevent such cache aliasing.
> >
> > There also seems to be a related issue in patch 6.
> > riscv_viommu_cache_invalidate() unconditionally forces PSCV=1 and
> > PSCID=0. However, an IOTINVAL.VMA with PSCV=0 also invalidates global
> > mappings, while PSCV=1 excludes them. This appears to narrow the
> > guest's requested invalidation scope and could leave stale global
> > translations cached.
> >
> > One possible approach might be to use the PSCID from the guest-provided
> > DC.ta when allocating the nested domain, and preserve the guest's PSCID
> > and PSCV settings during invalidation while substituting the host GSCID.
> > I'm not sure whether additional considerations are needed for PSCID
> > reuse or domain lifetime, though.
>
> If the guest is issuing invalidations you must always preserve the
> guests "ASID" or whatever your HW calls it. It can be virtualized and
> mapped from a guest view to physical, but it must be preserved and
> physical must be 1:1 with virtual.
>
> Jason

Thanks for clarifying the software responsibility and the 1:1 mapping
requirement. We will not drop this "ASID/PSCID" or collapse it to zero
in the next version.

I have outlined the approaches we are considering in my reply to Tan Chi.
I would very much appreciate your thoughts on which approach would be
preferable for RISC-V, and on any potential pitfalls we should keep in
mind.

Thanks,
Shuai