From: Andrew Jones <andrew.jones@oss.qualcomm.com>
To: linux-riscv@lists.infradead.org, iommu@lists.linux.dev
Cc: linux-kernel@vger.kernel.org, tomasz.jeznach@linux.dev,
tjeznach@rivosinc.com, jgg@ziepe.ca, jgg@nvidia.com,
joro@8bytes.org, will@kernel.org, robin.murphy@arm.com,
pjw@kernel.org, palmer@dabbelt.com, anup@brainfault.org,
tglx@kernel.org, kevin.tian@intel.com,
fangyu.yu@linux.alibaba.com
Subject: [PATCH v6 00/16] iommu/riscv: Enable MSI remapping, IOMMU_DMA and VFIO
Date: Fri, 25 Sep 2026 17:16:43 +0200 [thread overview]
Message-ID: <20260925151659.419512-1-andrew.jones@oss.qualcomm.com> (raw)
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. v2 through
v4[2] instead introduced a RISC-V IOMMU IRQ domain which pre-mapped every
possible IMSIC target and maintained a domain-local PA-to-IOVA table. The
v4 discussion with Jason identified a simpler way to handle the RISC-V
requirement that the MSI target address changes with interrupt affinity:
extend the existing iommu_dma_prepare_msi() model to prepare an ordered
list of MSI targets as one contiguous IOVA range. That resulted in v5[3],
a complete redesign around that approach. This is v6, which just has a few
minor updates to v5.
The IMSIC driver now builds an array containing the supervisor IMSIC page
for every possible CPU, indexed by logical CPU number. When allocating an
IRQ, it passes the complete array to iommu_dma_prepare_msi_list(). The new
API maps the ordered physical address list into one contiguous IOVA range
through either DMA-IOMMU or iommufd, then caches the base IOVA and mapping
granule in the MSI descriptor. MSI composition can therefore select the
target for the current CPU with simple arithmetic, including during an
affinity change, without allocating memory or consulting IOMMU-owned state
in atomic context.
DMA-IOMMU extends its existing per-page MSI cache to recognize and reuse
complete ranges. iommufd grows its software-MSI bitmap on demand, bounds
allocations to the reserved MSI window, and prepares, installs, rolls back,
and replays a range as one unit. This keeps the descriptor's contiguous
IOVA valid across iommufd paging-domain replacement without exposing a
partially installed range.
Unlike v4, v5 and v6 have no RISC-V IOMMU IRQ domain, no domain-local
IMSIC mapping table, and no IOMMU lookup during MSI composition. The IMSIC
IRQ domain owns the target list and message composition, while the IOMMU
layers only provide the mappings. Devices which do not need IOMMU MSI
translation keep using physical MSI addresses through the same IMSIC path.
The series also carries the remaining plumbing needed for RISC-V PCIe
device assignment through VFIO/KVM: VFIO type1 and KVM_VFIO are enabled
for RISC-V, defconfig enables IOMMUFD/VFIO as modules with cdev
support, and the generic VFIO/iommufd selftests can be built for RISC-V.
The RISC-V IOMMU specification does not provide MSI data validation, so
VFIO device assignment requires the applicable allow_unsafe_interrupts=1
module parameter. Direct MSI routing to guest interrupt files (irqbypass)
is not yet supported by this series and will be posted separately on top.
LLM-based coding assistants were used during development for code
exploration, patch review, test execution, and drafting and editing
commit messages and this cover letter. I reviewed and finalized all
resulting code and text. Per-patch Assisted-by tags are omitted in
light of ongoing discussions about simplifying coding-assistant
attribution.
Thanks,
drew
[1] https://lore.kernel.org/all/20260508212339.381933-1-andrew.jones@oss.qualcomm.com/
[2] https://lore.kernel.org/all/20260820214150.545737-1-andrew.jones@oss.qualcomm.com/
[3] https://lore.kernel.org/all/20260831145943.313726-1-andrew.jones@oss.qualcomm.com/
v6:
- Rebased on latest linux-iommu/next, dropping the now upstream
cache-coherency capability patch
- Picked up some r-b and t-b tags -- Thanks!
- Addressed Anup's comments
- Moved the SW MSI window from 128 MiB to 16 MiB to avoid kvmtool's
guest IMSIC window, and documented the limitations of using a fixed
window in the patch's commit message
Andrew Jones (13):
iommu/dma: Prepare MSI physical address lists
iommufd: Convert struct iommufd_sw_msi_maps to a growable bitmap
iommufd: Split software MSI map lookup and allocation
iommufd: Bound software MSI mappings to the reserved range
iommufd: Prepare software MSI maps for address lists
iommufd: Install software MSI map ranges atomically
iommufd: Prepare software MSI installation for address lists
iommu/dma: Introduce iommu_dma_prepare_msi_list()
iommu/riscv: Reserve an MSI IOVA window for iommufd
irqchip/riscv-imsic: Add MSI address list
irqchip/riscv-imsic: Support IOMMU MSI address lists
riscv: defconfig: Enable IOMMUFD and VFIO
selftests/vfio: Allow building on RISC-V
Tomasz Jeznach (3):
iommu/dma: Enable IOMMU_DMA for 64-bit RISC-V
vfio: enable IOMMU_TYPE1 for RISC-V
RISC-V: KVM: Enable KVM_VFIO interfaces on RISC-V arch
arch/riscv/configs/defconfig | 4 +
arch/riscv/kvm/Kconfig | 1 +
drivers/iommu/Kconfig | 2 +-
drivers/iommu/dma-iommu.c | 117 ++++++--
drivers/iommu/dma-iommu.h | 13 +-
drivers/iommu/iommu-priv.h | 7 +-
drivers/iommu/iommu.c | 109 +++++--
drivers/iommu/iommufd/device.c | 20 +-
drivers/iommu/iommufd/driver.c | 315 +++++++++++++++++----
drivers/iommu/iommufd/hw_pagetable.c | 1 +
drivers/iommu/iommufd/io_pagetable.c | 9 +-
drivers/iommu/iommufd/iommufd_private.h | 51 +++-
drivers/iommu/riscv/iommu.c | 20 ++
drivers/iommu/riscv/iommu.h | 4 +
drivers/irqchip/Kconfig | 1 +
drivers/irqchip/irq-riscv-imsic-platform.c | 24 +-
drivers/irqchip/irq-riscv-imsic-state.c | 54 ++++
drivers/irqchip/irq-riscv-imsic-state.h | 3 +
drivers/vfio/Kconfig | 2 +-
include/linux/iommu.h | 8 +
include/linux/irqchip/riscv-imsic.h | 6 +
tools/testing/selftests/vfio/Makefile | 2 +-
22 files changed, 646 insertions(+), 127 deletions(-)
--
2.43.0
next reply other threads:[~2026-09-25 15:17 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 15:16 Andrew Jones [this message]
2026-09-25 15:16 ` [PATCH v6 01/16] iommu/dma: Prepare MSI physical address lists Andrew Jones
2026-10-02 16:21 ` Robin Murphy
2026-10-03 12:03 ` Andrew Jones
2026-10-03 12:10 ` Jason Gunthorpe
2026-09-25 15:16 ` [PATCH v6 02/16] iommufd: Convert struct iommufd_sw_msi_maps to a growable bitmap Andrew Jones
2026-10-15 19:35 ` Jason Gunthorpe
2026-09-25 15:16 ` [PATCH v6 03/16] iommufd: Split software MSI map lookup and allocation Andrew Jones
2026-09-25 15:16 ` [PATCH v6 04/16] iommufd: Bound software MSI mappings to the reserved range Andrew Jones
2026-09-25 15:16 ` [PATCH v6 05/16] iommufd: Prepare software MSI maps for address lists Andrew Jones
2026-09-25 15:16 ` [PATCH v6 06/16] iommufd: Install software MSI map ranges atomically Andrew Jones
2026-09-25 15:16 ` [PATCH v6 07/16] iommufd: Prepare software MSI installation for address lists Andrew Jones
2026-09-28 10:23 ` Andrew Jones
2026-09-25 15:16 ` [PATCH v6 08/16] iommu/dma: Introduce iommu_dma_prepare_msi_list() Andrew Jones
2026-09-25 15:16 ` [PATCH v6 09/16] iommu/riscv: Reserve an MSI IOVA window for iommufd Andrew Jones
2026-10-15 19:35 ` Jason Gunthorpe
2026-10-15 19:51 ` Nicolin Chen
2026-10-22 14:40 ` Andrew Jones
2026-09-25 15:16 ` [PATCH v6 10/16] irqchip/riscv-imsic: Add MSI address list Andrew Jones
2026-09-25 15:51 ` Anup Patel
2026-10-15 21:33 ` Thomas Gleixner
2026-09-28 3:27 ` Nutty.Liu
2026-09-28 10:20 ` Andrew Jones
2026-10-15 21:32 ` Thomas Gleixner
2026-09-25 15:16 ` [PATCH v6 11/16] irqchip/riscv-imsic: Support IOMMU MSI address lists Andrew Jones
2026-09-25 15:52 ` Anup Patel
2026-09-28 3:18 ` Nutty.Liu
2026-10-15 21:32 ` Thomas Gleixner
2026-09-25 15:16 ` [PATCH v6 12/16] iommu/dma: Enable IOMMU_DMA for 64-bit RISC-V Andrew Jones
2026-09-28 3:17 ` Nutty.Liu
2026-09-25 15:16 ` [PATCH v6 13/16] vfio: enable IOMMU_TYPE1 for RISC-V Andrew Jones
2026-09-25 15:16 ` [PATCH v6 14/16] RISC-V: KVM: Enable KVM_VFIO interfaces on RISC-V arch Andrew Jones
2026-09-25 15:51 ` Anup Patel
2026-09-25 15:16 ` [PATCH v6 15/16] riscv: defconfig: Enable IOMMUFD and VFIO Andrew Jones
2026-09-28 3:17 ` Nutty.Liu
2026-09-25 15:16 ` [PATCH v6 16/16] selftests/vfio: Allow building on RISC-V Andrew Jones
2026-09-28 3:16 ` Nutty.Liu
2026-09-28 10:24 ` [PATCH v6 00/16] iommu/riscv: Enable MSI remapping, IOMMU_DMA and VFIO Andrew Jones
2026-10-15 19:35 ` Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260925151659.419512-1-andrew.jones@oss.qualcomm.com \
--to=andrew.jones@oss.qualcomm.com \
--cc=anup@brainfault.org \
--cc=fangyu.yu@linux.alibaba.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=robin.murphy@arm.com \
--cc=tglx@kernel.org \
--cc=tjeznach@rivosinc.com \
--cc=tomasz.jeznach@linux.dev \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®