From: fangyu.yu@linux.alibaba.com
To: anup@brainfault.org, paul.walmsley@sifive.com,
palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr,
atishp@atishpatra.org, tjeznach@rivosinc.com, joro@8bytes.org,
will@kernel.org, robin.murphy@arm.com, sunilvl@ventanamicro.com,
rafael.j.wysocki@intel.com, tglx@linutronix.de,
ajones@ventanamicro.com
Cc: guoren@linux.alibaba.com, guoren@kernel.org, kvm@vger.kernel.org,
kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org, iommu@lists.linux.dev,
Fangyu Yu <fangyu.yu@linux.alibaba.com>
Subject: [RFC PATCH 2/6] RISC-V: KVM: Transfer the physical address of MRIF to iommu-ir
Date: Mon, 11 Aug 2025 14:11:00 +0800 [thread overview]
Message-ID: <20250811061104.10326-3-fangyu.yu@linux.alibaba.com> (raw)
In-Reply-To: <20250811061104.10326-1-fangyu.yu@linux.alibaba.com>
From: Fangyu Yu <fangyu.yu@linux.alibaba.com>
According to the RISC-V IOMMU Spec, an IOMMU may optionally
support memory-resident interrupt files (MRIFs).
When the guest interrupt files are used up, we transfer the
physical address of MRIF to iommu-ir, and enable MRIF mode
if the iommu-ir supports.
Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
---
arch/riscv/kvm/aia_imsic.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/arch/riscv/kvm/aia_imsic.c b/arch/riscv/kvm/aia_imsic.c
index 8f5703d9112a..e91164742fd0 100644
--- a/arch/riscv/kvm/aia_imsic.c
+++ b/arch/riscv/kvm/aia_imsic.c
@@ -21,6 +21,8 @@
#define IMSIC_MAX_EIX (IMSIC_MAX_ID / BITS_PER_TYPE(u64))
+static int kvm_riscv_vcpu_irq_update(struct kvm_vcpu *vcpu);
+
struct imsic_mrif_eix {
unsigned long eip[BITS_PER_TYPE(u64) / BITS_PER_LONG];
unsigned long eie[BITS_PER_TYPE(u64) / BITS_PER_LONG];
@@ -717,7 +719,8 @@ void kvm_riscv_vcpu_aia_imsic_release(struct kvm_vcpu *vcpu)
vcpu->arch.aia_context.imsic_addr,
IMSIC_MMIO_PAGE_SZ);
- /* TODO: Purge the IOMMU mapping ??? */
+ /* Update the IOMMU mapping */
+ kvm_riscv_vcpu_irq_update(vcpu);
/*
* At this point, all interrupt producers have been re-directed
@@ -795,13 +798,14 @@ int kvm_arch_update_irqfd_routing(struct kvm *kvm, unsigned int host_irq,
read_lock_irqsave(&imsic->vsfile_lock, flags);
- if (WARN_ON_ONCE(imsic->vsfile_cpu < 0)) {
- read_unlock_irqrestore(&imsic->vsfile_lock, flags);
- goto out;
+ if (imsic->vsfile_cpu < 0) {
+ vcpu_info.hpa = imsic->swfile_pa;
+ vcpu_info.mrif = true;
+ } else {
+ vcpu_info.hpa = imsic->vsfile_pa;
+ vcpu_info.mrif = false;
}
- vcpu_info.hpa = imsic->vsfile_pa;
-
ret = irq_set_vcpu_affinity(host_irq, &vcpu_info);
if (ret) {
read_unlock_irqrestore(&imsic->vsfile_lock, flags);
@@ -844,6 +848,13 @@ static int kvm_riscv_vcpu_irq_update(struct kvm_vcpu *vcpu)
if (!irqfd->producer)
continue;
host_irq = irqfd->producer->irq;
+
+ if (imsic->vsfile_cpu < 0) {
+ vcpu_info.hpa = imsic->swfile_pa;
+ vcpu_info.mrif = true;
+ } else {
+ vcpu_info.mrif = false;
+ }
ret = irq_set_vcpu_affinity(host_irq, &vcpu_info);
if (ret) {
spin_unlock_irq(&kvm->irqfds.lock);
--
2.49.0
next prev parent reply other threads:[~2025-08-11 6:11 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-11 6:10 [RFC PATCH 0/6] iommu/riscv: Add MRIF support fangyu.yu
2025-08-11 6:10 ` [RFC PATCH 1/6] RISC-V: Add more elements to irqbypass vcpu_info fangyu.yu
2025-08-11 6:11 ` fangyu.yu [this message]
2025-08-11 6:11 ` [RFC PATCH 3/6] RISC-V: KVM: Add a xarray to record host irq msg fangyu.yu
2025-08-11 6:11 ` [RFC PATCH 4/6] iommu/riscv: Add irq_mask and irq_ack configure for iommu-ir fangyu.yu
2025-08-11 6:11 ` [RFC PATCH 5/6] iommu/riscv: Add MRIF mode support fangyu.yu
2025-08-11 6:11 ` [RFC PATCH 6/6] RISC-V: KVM: Check the MRIF in notice MSI irq handler fangyu.yu
2026-07-01 4:00 ` [RFC PATCH 0/3] RISC-V: KVM/IOMMU: Fix MRIF irqfd notice handling Zhanpeng Zhang
2026-07-01 4:00 ` [RFC PATCH 1/3] iommu/riscv: Complete MRIF MSI PTE setup Zhanpeng Zhang
2026-07-01 4:00 ` [RFC PATCH 2/3] KVM: Move irqfd arch data into route snapshots Zhanpeng Zhang
2026-07-01 4:00 ` [RFC PATCH 3/3] RISC-V: KVM: Identify MRIF notices from irqfd snapshots Zhanpeng Zhang
2026-07-03 12:38 ` [RFC PATCH 0/3] RISC-V: KVM/IOMMU: Fix MRIF irqfd notice handling 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=20250811061104.10326-3-fangyu.yu@linux.alibaba.com \
--to=fangyu.yu@linux.alibaba.com \
--cc=ajones@ventanamicro.com \
--cc=alex@ghiti.fr \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=atishp@atishpatra.org \
--cc=guoren@kernel.org \
--cc=guoren@linux.alibaba.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=rafael.j.wysocki@intel.com \
--cc=robin.murphy@arm.com \
--cc=sunilvl@ventanamicro.com \
--cc=tglx@linutronix.de \
--cc=tjeznach@rivosinc.com \
--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®