This series adds MSI remapping for IMSIC so a device's MSI target gets
translated the same way its DMA does, allowing RISC-V to enable IOMMU_DMA
and paging domains by default.
v1[1] used get_resv_regions() with IOMMU_RESV_DIRECT_RELAXABLE to identity
map IMSIC pages, but that was rejected as only a workaround, and the
proposal for v2 was to follow ARM's approach. ARM calls
iommu_dma_prepare_msi() once at IRQ-alloc time, caches the IOVA on the
msi_desc, and lets compose replay it via msi_msg_set_addr(). This series
follows that structure by introducing an IRQ domain and a new
iommu_dma_map_msi(). Like iommu_dma_prepare_msi(), it dispatches on the
same domain cookie types. Unlike iommu_dma_prepare_msi(), it returns the
IOVA to the caller instead of caching it on a descriptor. That allows the
caller to collect all IOVAs needed (since IMSIC needs one IOVA per host
IMSIC page). Like ARM, msi_msg_set_addr() is used at compose time to
direct MSIs to the appropriate IOVAs.
The divergence from ARM is required due to where the target address
actually lives. ARM's doorbell PA is fixed per ITS instance (affinity
changes only retarget hardware routing, never the composed address) so
one IOVA cached at alloc time stays valid for the descriptor's lifetime.
IMSIC doesn't have a fixed target, the MSI address itself changes on
irq_set_affinity(), and that runs in atomic context, so mapping a fresh
IOVA isn't an option. This series pre-maps every IMSIC page into a
domain-wide PA-to-IOVA table at first IRQ-alloc time, and compose does an
O(1) lookup to pick the right one.
LLM-based coding assistants were used during development for code
exploration ("super grep" as one of my colleagues calls it), patch review,
test execution, and commit-message iteration, but all resulting code and
commit messages were selected, reviewed, and finalized by me. Per-patch
Assisted-by tags are omitted in light of the ongoing discussion about
simplifying coding-assistant attribution[2].
Thanks,
drew
[1] https://lore.kernel.org/all/20260508212339.381933-1-andrew.jones@oss.qualcomm.com/
[2] https://lore.kernel.org/all/20260701-work-coding-assistants-v1-1-a20a94d1d606@kernel.org/
Andrew Jones (13):
iommufd: Convert struct iommufd_sw_msi_maps to a growable bitmap
iommufd: Add iommufd_sw_map_msi()
iommu/dma: Add iommu_dma_sw_map_msi()
iommu/dma: Add iommu_dma_map_msi()
genirq/msi: Provide DOMAIN_BUS_MSI_REMAP
irqchip/riscv-imsic: Compose MSI updates through the hierarchy
iommu/riscv: Add IRQ domain for interrupt remapping
iommu/riscv: Prepare info->domain for concurrent RCU read access
iommu/riscv: Publish IOMMU_RESV_SW_MSI region for iommufd MSI
remapping
iommu/riscv: Pre-map IMSIC MSI targets
iommu/riscv: Copy MSI IOVA table when replacing an iommufd domain
iommu/riscv: Implement irq_compose_msi_msg for IMSIC remapping
riscv: defconfig: Enable IOMMUFD and VFIO
Tomasz Jeznach (1):
iommu/dma: Enable IOMMU_DMA for 64-bit RISC-V
arch/riscv/configs/defconfig | 3 +
drivers/iommu/Kconfig | 2 +-
drivers/iommu/dma-iommu.c | 39 ++-
drivers/iommu/dma-iommu.h | 12 +
drivers/iommu/iommu-priv.h | 11 +
drivers/iommu/iommu.c | 86 +++++-
drivers/iommu/iommufd/device.c | 3 +-
drivers/iommu/iommufd/driver.c | 97 +++++--
drivers/iommu/iommufd/hw_pagetable.c | 1 +
drivers/iommu/iommufd/iommufd_private.h | 38 ++-
drivers/iommu/riscv/Kconfig | 1 +
drivers/iommu/riscv/Makefile | 2 +-
drivers/iommu/riscv/iommu-ir.c | 298 +++++++++++++++++++++
drivers/iommu/riscv/iommu.c | 91 +++++--
drivers/iommu/riscv/iommu.h | 37 +++
drivers/irqchip/irq-msi-lib.c | 8 +-
drivers/irqchip/irq-riscv-imsic-platform.c | 27 +-
include/linux/iommu.h | 22 ++
include/linux/irqchip/riscv-imsic.h | 7 +
include/linux/irqdomain_defs.h | 1 +
20 files changed, 693 insertions(+), 93 deletions(-)
create mode 100644 drivers/iommu/riscv/iommu-ir.c
--
2.43.0