Skip to content

kernel: hold off bus mastering until DMA buffers are (re)mapped#145

Merged
enjoy-digital merged 1 commit into
enjoy-digital:mainfrom
simonerni:pr/kernel-busmaster-teardown
Jul 13, 2026
Merged

kernel: hold off bus mastering until DMA buffers are (re)mapped#145
enjoy-digital merged 1 commit into
enjoy-digital:mainfrom
simonerni:pr/kernel-busmaster-teardown

Conversation

@simonerni

Copy link
Copy Markdown
Contributor

Problem

A device left bus-mastering by an unclean teardown keeps issuing DMA into
stale/freed addresses and faults the IOMMU (IO_PAGE_FAULT) before the driver is
ready. On our setup this escalated to a probe soft-lockup / D3cold wedge that only
a power cycle cleared.

Change

  • Probe: keep pci_clear_master() asserted until after litepcie_dma_init()
    has (re)mapped the DMA buffers and the core is reset; enable bus mastering only
    then, instead of right after reading the version.
  • Remove: pci_clear_master() first, before litepcie_stop_dma(), so the
    device stops issuing new DMA immediately even if the MMIO stop can't reach a
    wedged core. In-flight transactions complete cleanly; only new ones are blocked.

Impact

Eliminates the IOMMU-fault-on-teardown class of wedge (IO_PAGE_FAULT storm +
probe hang). Independent robustness fix, not tied to any streaming feature.

Testing

make -C litex_m2sdr/software/kernel clean all. Verified on hardware across
rmmod/insmod cycles: teardown no longer leaves the device bus-mastering, probe
recovers and re-creates /dev/m2sdr0.

Clear PCI Bus Master Enable at probe until the core has been reset and its DMA
buffers are mapped (enable it only after litepcie_dma_init), and clear it FIRST
on remove before stopping the DMAs. Otherwise a device left bus-mastering by an
unclean teardown DMAs into stale/freed addresses and faults the IOMMU
(IO_PAGE_FAULT) before the driver is ready, which can escalate to a probe
soft-lockup / D3cold wedge that only a power cycle clears. In-flight
transactions complete cleanly; only new ones are blocked.
@enjoy-digital

Copy link
Copy Markdown
Owner

This makes sense, thanks @simonerni!

@enjoy-digital
enjoy-digital merged commit b8beacb into enjoy-digital:main Jul 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants