]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
PCI: dwc: ep: Cache MSI outbound iATU mapping
authorKoichiro Den <den@valinux.co.jp>
Mon, 22 Dec 2025 11:01:44 +0000 (12:01 +0100)
committerManivannan Sadhasivam <mani@kernel.org>
Tue, 23 Dec 2025 11:17:53 +0000 (16:47 +0530)
dw_pcie_ep_raise_msi_irq() currently programs an outbound iATU window
for the MSI target address on every interrupt and tears it down again
via dw_pcie_ep_unmap_addr().

On systems that heavily use the AXI bridge interface (for example when
the integrated eDMA engine is active), this means the outbound iATU
registers are updated while traffic is in flight. The DesignWare
endpoint databook 5.40a - "3.10.6.1 iATU Outbound Programming Overview"
warns that updating iATU registers in this situation is not supported,
and the behavior is undefined.

Under high MSI and eDMA load this pattern results in occasional bogus
outbound transactions and IOMMU faults, on the RC side, such as:

  ipmmu-vmsa eed40000.iommu: Unhandled fault: status 0x00001502 iova 0xfe000000

followed by the system becoming unresponsive. This is the actual output
observed on Renesas R-Car S4, with its ipmmu_hc used with PCIe ch0.

There is no need to reprogram the iATU region used for MSI on every
interrupt. The host-provided MSI address is stable while MSI is enabled,
and the endpoint driver already dedicates a scratch buffer for MSI
generation.

Cache the aligned MSI address and map size, program the outbound iATU
once, and keep the window enabled. Subsequent interrupts only perform a
write to the MSI scratch buffer, avoiding dynamic iATU reprogramming in
the hot path and fixing the lockups seen under load.

dw_pcie_ep_raise_msix_irq() is not modified, as each vector can have a
different msg_addr, and because the msg_addr is allowed to be changed
while the vector is masked. Neither problem is easy to solve with the
current design. Instead, the plan is for the DWC vendor drivers to
transition to dw_pcie_ep_raise_msix_irq_doorbell(), which does not rely
on the iATU.

Signed-off-by: Koichiro Den <den@valinux.co.jp>
[cassel: improve commit message]
Signed-off-by: Niklas Cassel <cassel@kernel.org>
Signed-off-by: Manivannan Sadhasivam <mani@kernel.org>
Link: https://patch.msgid.link/20251222110144.3299523-2-cassel@kernel.org
drivers/pci/controller/dwc/pcie-designware-ep.c
drivers/pci/controller/dwc/pcie-designware.h

index f6c54625486e2aa8fcdacce21eaee91ce049bd3e..1195d401df19eafbab2fb267f5cda3c24ecdfbd1 100644 (file)
@@ -601,6 +601,16 @@ static void dw_pcie_ep_stop(struct pci_epc *epc)
        struct dw_pcie_ep *ep = epc_get_drvdata(epc);
        struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 
+       /*
+        * Tear down the dedicated outbound window used for MSI
+        * generation. This avoids leaking an iATU window across
+        * endpoint stop/start cycles.
+        */
+       if (ep->msi_iatu_mapped) {
+               dw_pcie_ep_unmap_addr(epc, 0, 0, ep->msi_mem_phys);
+               ep->msi_iatu_mapped = false;
+       }
+
        dw_pcie_stop_link(pci);
 }
 
@@ -702,14 +712,37 @@ int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no,
        msg_addr = ((u64)msg_addr_upper) << 32 | msg_addr_lower;
 
        msg_addr = dw_pcie_ep_align_addr(epc, msg_addr, &map_size, &offset);
-       ret = dw_pcie_ep_map_addr(epc, func_no, 0, ep->msi_mem_phys, msg_addr,
-                                 map_size);
-       if (ret)
-               return ret;
 
-       writel(msg_data | (interrupt_num - 1), ep->msi_mem + offset);
+       /*
+        * Program the outbound iATU once and keep it enabled.
+        *
+        * The spec warns that updating iATU registers while there are
+        * operations in flight on the AXI bridge interface is not
+        * supported, so we avoid reprogramming the region on every MSI,
+        * specifically unmapping immediately after writel().
+        */
+       if (!ep->msi_iatu_mapped) {
+               ret = dw_pcie_ep_map_addr(epc, func_no, 0,
+                                         ep->msi_mem_phys, msg_addr,
+                                         map_size);
+               if (ret)
+                       return ret;
+
+               ep->msi_iatu_mapped = true;
+               ep->msi_msg_addr = msg_addr;
+               ep->msi_map_size = map_size;
+       } else if (WARN_ON_ONCE(ep->msi_msg_addr != msg_addr ||
+                               ep->msi_map_size != map_size)) {
+               /*
+                * The host changed the MSI target address or the required
+                * mapping size changed. Reprogramming the iATU at runtime is
+                * unsafe on this controller, so bail out instead of trying to
+                * update the existing region.
+                */
+               return -EINVAL;
+       }
 
-       dw_pcie_ep_unmap_addr(epc, func_no, 0, ep->msi_mem_phys);
+       writel(msg_data | (interrupt_num - 1), ep->msi_mem + offset);
 
        return 0;
 }
@@ -1087,6 +1120,9 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
        struct device *dev = pci->dev;
 
        INIT_LIST_HEAD(&ep->func_list);
+       ep->msi_iatu_mapped = false;
+       ep->msi_msg_addr = 0;
+       ep->msi_map_size = 0;
 
        epc = devm_pci_epc_create(dev, &epc_ops);
        if (IS_ERR(epc)) {
index a3a3f6e89a812346cf1b628845886e25fdef4ccd..f87c67a7a48244385df9a509879b1da3a2990f11 100644 (file)
@@ -482,6 +482,11 @@ struct dw_pcie_ep {
        void __iomem            *msi_mem;
        phys_addr_t             msi_mem_phys;
        struct pci_epf_bar      *epf_bar[PCI_STD_NUM_BARS];
+
+       /* MSI outbound iATU state */
+       bool                    msi_iatu_mapped;
+       u64                     msi_msg_addr;
+       size_t                  msi_map_size;
 };
 
 struct dw_pcie_ops {