Hi Tan Chi,

Thanks for the review.

> Hi Shuai and Fei,
> 
> On 10/29/2026 1:47 PM, Gong Shuai wrote:
> > +    if (s->accel_state->viommu) {
> > +        goto done;
> > +    }
> >
> > +    if (!riscv_iommu_accel_alloc_viommu(s, idev, errp)) {
> > +        error_append_hint(errp, "Unable to alloc vIOMMU: idev devid 0x%x: 
> > ",
> > +                          idev->devid);
> > +        return false;
> > +    }
> 
> And in riscv_iommu_accel_alloc_viommu():
> 
> > +    /* Attach a HWPT based on ddtp.iommu_mode value */
> > +    hwpt_id = riscv_iommu_accel_ddtp_hwpt(s, accel);
> > +    if (!host_iommu_device_iommufd_attach_hwpt(idev, IOMMU_NO_PASID, 
> > hwpt_id,
> > +                                               errp)) {
> > +        goto free_bypass_hwpt;
> > +    }
> 
> It looks like only the first VFIO device is attached to the abort/bypass
> HWPT. Subsequent devices in different IOMMU groups may remain attached
> to their original Stage-2 parent HWPT, potentially allowing DMA even
> when DDTP.Mode is OFF.

Your analysis is correct. A later device takes the "goto done"
path and stays on its S2 parent. A device in that state can still
DMA with GPA -> HPA translation while DDTP.Mode is Off, which the
spec says must abort.

The RFC design and our testing were based on a single-device
model, so this never showed up. We only started exercising
multiple groups/devices recently, while reproducing the kernel
issue you pointed out [1]. Before any DMA is issued, the guest
IOMMU driver programs DDTP and sends an IODIR.INVAL_DDT, and
each device's domain attach sends a per-device one. QEMU
handles both by re-fetching the guest DC and attaching the
matching nested HWPT, so by the time the DMA starts the window
is already closed. That explains why the test passes; it just
does not cover the window you found. Still, the gap is real
and needs to be fixed.

> 
> Maybe we can follow ARM SMMUv3 and reattach all VFIO devices to the
> appropriate abort/bypass HWPT during reset.

Thanks for the suggestion, I'll try that in the next version.

[1] 
https://lore.kernel.org/linux-riscv/[email protected]/

Thanks,
Shuai

> 
> Thanks,
> Tan Chi
> 

Reply via email to