Skip to contentSkip to conversation

PCI: dwc: iMSI-RX target address appears unreserved in endpoint IOMMU IOVA domains

BUG? Felipe Infante de Castro 1 participant 1 message Nov 29 PCI

lore
Share & tools
lore
#0 lore raw

Hi all,

During a source audit of DesignWare PCIe host MSI handling on Linux v7.3.6 (drivers/pci/controller/dwc/pcie-designware-host.c and drivers/iommu/dma-iommu.c), we found a potential IOVA/MSI address collision when a DWC host uses its integrated MSI receiver (iMSI-RX) with downstream PCI endpoints behind a translating IOMMU.

No hardware collision has been observed yet (our test platform currently boots at EL1 without an external PCIe IOMMU), so this is a source-audit report seeking confirmation and guidance on the right fix.

Summary of the issue:

When pp->use_imsi_rx is true (no msi-map, msi-parent, or custom ops->msi_init), dw_pcie_msi_host_init() chooses a PCI-visible MSI target address pp->msi_data and programs it into PCIE_MSI_ADDR_LO/HI:

1. 32-bit cfg0_base branch (pcie-designware-host.c:370-373):

     pp->msi_data = pp->cfg0_base (from platform reg "config", not from
     host-bridge ranges).

2. Above-4-GiB cfg0_base branch (pcie-designware-host.c:375-390):
dmam_alloc_coherent(dev, sizeof(u64), &pp->msi_data, GFP_KERNEL), trying a 32-bit coherent mask first.

Per the DesignWare PCIe databook note in dw_pcie_msi_host_init() (r6.21a s3.10.2.3), any incoming PCIe Memory Write TLP targeting MSI_CTRL_ADDR is terminated internally by the iMSI-RX module and never reaches the AXI bus / IOMMU.

When a downstream PCI endpoint attaches to a translating IOMMU domain (IOMMU_DOMAIN_DMA / IOMMU_DOMAIN_DMA_FQ), iommu_dma_init_domain() calls iova_reserve_iommu_regions() (drivers/iommu/dma-iommu.c:553-583):

- iova_reserve_pci_windows() reserves only host-bridge IORESOURCE_MEM

    windows (from ranges) and gaps outside bridge->dma_ranges. Neither
    pp->cfg0_base nor a dmam_alloc_coherent() address lies in
    bridge->windows.
  - Neither pcie-designware-host.c, arm_smmu_get_resv_regions(), nor
    viommu_get_resv_regions() registers an IOMMU_RESV_RESERVED region
    for pp->msi_data.
  - Under iommu_dma_alloc_iova(), PCI devices with pci_32bit_workaround
    allocate top-down from 0xffff_ffff first, even with a 64-bit DMA
    mask.

On a concrete layout we examined (Snapdragon X Elite USB4 tunnelled PCIe root pcie@1c28000 with "config" at 0x4_0010_0000 and ranges at [0x4000_0000, 0x4fff_ffff] and [0x4_1000_0000, 0x4_ffff_ffff]), dmam_alloc_coherent() on the controller platform device (no iommus property of its own, no dma-ranges) allocates a 32-bit RAM address in [0x8080_0000, 0xffff_ffff] -- squarely inside the unreserved [0x5000_0000, 0xffff_ffff] top-down 32-bit IOVA pool handed to downstream endpoints. Any endpoint DMA write to that IOVA risks being swallowed by iMSI-RX as a spurious MSI instead of reaching the SMMU.

Candidate fix direction:

Record the active PCI-visible MSI target (pp->msi_data) on struct pci_host_bridge when pp->use_imsi_rx is enabled in dw_pcie_msi_host_init(), and expose a PAGE_SIZE-aligned IOMMU_RESV_RESERVED region for it in iommu_dma_get_resv_regions() (drivers/iommu/dma-iommu.c:462). That would cover cold discovery, hot-add, rebind, both 32-bit cfg0_base and coherent-allocation paths, and all IOMMU drivers using iommu_dma_get_resv_regions() (arm-smmu-v3, virtio-iommu, etc.), while surfacing the reservation in /sys/kernel/iommu_groups/*/reserved_regions.

Full audit notes:
https://github.com/fidecastro/surface-laptop-7-15in-facts/blob/main/upstream-reports/linux-pci-dwc-imsi-rx-iova.md

Does this look like a real gap in DWC iMSI-RX + dma-iommu, and would a patch along the pci_host_bridge + iommu_dma_get_resv_regions() lines be the right direction?

Best regards,
Felipe Infante de Castro