From: fangyu.yu@linux.alibaba.com
To: jgg@nvidia.com
Cc: alex@ghiti.fr, andrew.jones@oss.qualcomm.com,
aou@eecs.berkeley.edu, fangyu.yu@linux.alibaba.com,
gsh517025@gmail.com, guoren@kernel.org, iommu@lists.linux.dev,
jgg@ziepe.ca, joro@8bytes.org, jroedel@suse.de,
kvm-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-riscv@lists.infradead.org, palmer@dabbelt.com,
pjw@kernel.org, robin.murphy@arm.com, tomasz.jeznach@linux.dev,
will@kernel.org, zong.li@sifive.com
Subject: Re: [RFC PATCH v2 3/4] iommu/riscv: Add guest IMSIC GPA mapping helpers
Date: Fri, 16 Oct 2026 11:01:38 +0800 [thread overview]
Message-ID: <20261016030138.91675-1-fangyu.yu@linux.alibaba.com> (raw)
In-Reply-To: <179210803193.58760.10996339526486124321.b4-reply@b4>
>> From: Fangyu Yu <fangyu.yu@linux.alibaba.com>
>>
>> IOMMU implementations without the MSI_FLAT capability translate MSI
>> writes through the second-stage page table, so IRQ forwarding on them
>> will need guest IMSIC pages mapped into the second-stage domain.
>>
>> Add an xarray to the MSI table that tracks the HPA installed for each
>> mapped guest IMSIC GPA, and two helpers for use with the MSI table lock
>> held: riscv_iommu_msi_table_map_gpa() installs the initial 4 KiB
>> mapping, and riscv_iommu_msi_table_replace_gpa() repoints the leaf PTE
>> when a vCPU's VS-file host page moves, using the generic page table
>> replace_leaf op instead of walking the table in the driver.
>>
>> Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
>> ---
>> drivers/iommu/riscv/iommu.c | 43 +++++++++++++++++++++++++++++++++++++
>> drivers/iommu/riscv/iommu.h | 12 +++++++++++
>> 2 files changed, 55 insertions(+)
>>
>> diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c
>> index e2e77469ea3c..88e131ce96c1 100644
>> --- a/drivers/iommu/riscv/iommu.c
>> +++ b/drivers/iommu/riscv/iommu.c
>> @@ -1217,6 +1217,42 @@ void riscv_iommu_msi_table_inval_all(struct riscv_iommu_msi_table *msi_table)
>> riscv_iommu_iotlb_inval(domain, &gather);
>> }
>>
>> +int riscv_iommu_msi_table_map_gpa(struct riscv_iommu_msi_table *msi_table,
>> + dma_addr_t gpa, phys_addr_t hpa)
>> +{
>> + struct riscv_iommu_domain *domain =
>> + container_of(msi_table, struct riscv_iommu_domain, msi_table);
>> + const int prot = IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO;
>> +
>> + /* Guest IMSIC GPA mapping only exists in second-stage translations. */
>> + if (!domain->gscid)
>> + return -EOPNOTSUPP;
>> +
>> + return iommu_map(&domain->domain, gpa, hpa, IMSIC_MMIO_PAGE_SZ, prot,
>> + GFP_ATOMIC);
>> +}
>
>Andrew has moved well past a v3
>
>I shouldn't be seeing code in iommu or irq drivers directly mapping into
>domains. That doesn't work, Andrew's latest series don't do this.
>
>It still needs to use the SW_MSI mechanism and related.
>
Andrew has posted two patch series in the community: one is the
MSI remap v6 series[1], and another is the IRQ bypass v3 series[2].
I think you are referring to the MSI remap v6 series. My patch was
based on the IRQ bypass v3 series, and I added this patch on top
of it.
[1] https://lore.kernel.org/linux-iommu/179209292714.4133959.5997128071302263244.b4-review@b4/T/#t
[2] https://lore.kernel.org/linux-riscv/20260928143113.49838-1-andrew.jones@oss.qualcomm.com/
>Nothing in the commit messages clearly explained what this is actually for
>without having to go dig up the riscv manuals again. Please explain how the
>interrupt translation works and what actual user visible problem this is
>trying to solve is.
>
The interrupt translation is based on Andrew's irq bypass patch
description.
RISC-V IOMMU defines an optional MSI page table feature, which can
be used to implement irq bypass by translating the vIMSIC GPA to
the pIMSIC HPA.
My patch complements that design. If the RISC-V IOMMU hardware does
not implement the MSI page table, then the second-stage page table
can be used instead to map vIMSIC GPA to pIMSIC HPA.
Thanks,
Fangyu
>--
>Jason
next prev parent reply other threads:[~2026-10-16 3:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 14:11 [RFC PATCH v2 0/4] iommu/riscv: Add irqbypass support without MSI page table fangyu.yu
2026-10-14 14:11 ` [RFC PATCH v2 1/4] iommupt: Add replace_leaf to atomically swap a leaf OA fangyu.yu
2026-10-14 14:11 ` [RFC PATCH v2 2/4] iommu/riscv: Extract IRQ forwarding payload validation fangyu.yu
2026-10-14 14:11 ` [RFC PATCH v2 3/4] iommu/riscv: Add guest IMSIC GPA mapping helpers fangyu.yu
2026-10-15 23:47 ` Jason Gunthorpe
2026-10-16 3:01 ` fangyu.yu [this message]
2026-10-14 14:11 ` [RFC PATCH v2 4/4] iommu/riscv: Support IRQ forwarding without MSI page tables fangyu.yu
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=20261016030138.91675-1-fangyu.yu@linux.alibaba.com \
--to=fangyu.yu@linux.alibaba.com \
--cc=alex@ghiti.fr \
--cc=andrew.jones@oss.qualcomm.com \
--cc=aou@eecs.berkeley.edu \
--cc=gsh517025@gmail.com \
--cc=guoren@kernel.org \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=jroedel@suse.de \
--cc=kvm-riscv@lists.infradead.org \
--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=tomasz.jeznach@linux.dev \
--cc=will@kernel.org \
--cc=zong.li@sifive.com \
/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®