2024-04-11 09:14:00

by Anup Patel

[permalink] [raw]
Subject: [PATCH 0/2] KVM RISC-V HW IMSIC guest files

This series extends the HWACCEL and AUTO modes of AIA in-kernel irqchip
to use HW IMSIC guest files whenever underlying host supports it.

This series depends upon the "Linux RISC-V AIA support" series which
is already queued for Linux-6.10.
(Refer, https://lore.kernel.org/lkml/[email protected]/)

These patches can also be found in the riscv_kvm_aia_hwaccel_v1 branch
at: https://github.com/avpatel/linux.git

Anup Patel (2):
RISC-V: KVM: Share APLIC and IMSIC defines with irqchip drivers
RISC-V: KVM: Use IMSIC guest files when available

arch/riscv/include/asm/kvm_aia_aplic.h | 58 --------------------------
arch/riscv/include/asm/kvm_aia_imsic.h | 38 -----------------
arch/riscv/kvm/aia.c | 35 +++++++++-------
arch/riscv/kvm/aia_aplic.c | 2 +-
arch/riscv/kvm/aia_device.c | 2 +-
arch/riscv/kvm/aia_imsic.c | 2 +-
6 files changed, 24 insertions(+), 113 deletions(-)
delete mode 100644 arch/riscv/include/asm/kvm_aia_aplic.h
delete mode 100644 arch/riscv/include/asm/kvm_aia_imsic.h

--
2.34.1



2024-04-11 09:27:56

by Anup Patel

[permalink] [raw]
Subject: [PATCH 2/2] RISC-V: KVM: Use IMSIC guest files when available

Let us discover and use IMSIC guest files from the IMSIC global
config provided by the IMSIC irqchip driver.

Signed-off-by: Anup Patel <[email protected]>
---
arch/riscv/kvm/aia.c | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/arch/riscv/kvm/aia.c b/arch/riscv/kvm/aia.c
index 8ea51a791371..596209f1a6ff 100644
--- a/arch/riscv/kvm/aia.c
+++ b/arch/riscv/kvm/aia.c
@@ -394,6 +394,8 @@ int kvm_riscv_aia_alloc_hgei(int cpu, struct kvm_vcpu *owner,
{
int ret = -ENOENT;
unsigned long flags;
+ const struct imsic_global_config *gc;
+ const struct imsic_local_config *lc;
struct aia_hgei_control *hgctrl = per_cpu_ptr(&aia_hgei, cpu);

if (!kvm_riscv_aia_available() || !hgctrl)
@@ -409,11 +411,14 @@ int kvm_riscv_aia_alloc_hgei(int cpu, struct kvm_vcpu *owner,

raw_spin_unlock_irqrestore(&hgctrl->lock, flags);

- /* TODO: To be updated later by AIA IMSIC HW guest file support */
- if (hgei_va)
- *hgei_va = NULL;
- if (hgei_pa)
- *hgei_pa = 0;
+ gc = imsic_get_global_config();
+ lc = (gc) ? per_cpu_ptr(gc->local, cpu) : NULL;
+ if (lc && ret > 0) {
+ if (hgei_va)
+ *hgei_va = lc->msi_va + (ret * IMSIC_MMIO_PAGE_SZ);
+ if (hgei_pa)
+ *hgei_pa = lc->msi_pa + (ret * IMSIC_MMIO_PAGE_SZ);
+ }

return ret;
}
@@ -600,9 +605,11 @@ void kvm_riscv_aia_disable(void)
int kvm_riscv_aia_init(void)
{
int rc;
+ const struct imsic_global_config *gc;

if (!riscv_isa_extension_available(NULL, SxAIA))
return -ENODEV;
+ gc = imsic_get_global_config();

/* Figure-out number of bits in HGEIE */
csr_write(CSR_HGEIE, -1UL);
@@ -614,17 +621,17 @@ int kvm_riscv_aia_init(void)
/*
* Number of usable HGEI lines should be minimum of per-HART
* IMSIC guest files and number of bits in HGEIE
- *
- * TODO: To be updated later by AIA IMSIC HW guest file support
*/
- kvm_riscv_aia_nr_hgei = 0;
+ if (gc)
+ kvm_riscv_aia_nr_hgei = min((ulong)kvm_riscv_aia_nr_hgei,
+ BIT(gc->guest_index_bits) - 1);
+ else
+ kvm_riscv_aia_nr_hgei = 0;

- /*
- * Find number of guest MSI IDs
- *
- * TODO: To be updated later by AIA IMSIC HW guest file support
- */
+ /* Find number of guest MSI IDs */
kvm_riscv_aia_max_ids = IMSIC_MAX_ID;
+ if (gc && kvm_riscv_aia_nr_hgei)
+ kvm_riscv_aia_max_ids = gc->nr_guest_ids + 1;

/* Initialize guest external interrupt line management */
rc = aia_hgei_init();
--
2.34.1


2024-05-31 17:48:09

by Anup Patel

[permalink] [raw]
Subject: Re: [PATCH 0/2] KVM RISC-V HW IMSIC guest files

On Thu, Apr 11, 2024 at 2:36 PM Anup Patel <[email protected]> wrote:
>
> This series extends the HWACCEL and AUTO modes of AIA in-kernel irqchip
> to use HW IMSIC guest files whenever underlying host supports it.
>
> This series depends upon the "Linux RISC-V AIA support" series which
> is already queued for Linux-6.10.
> (Refer, https://lore.kernel.org/lkml/[email protected]/)
>
> These patches can also be found in the riscv_kvm_aia_hwaccel_v1 branch
> at: https://github.com/avpatel/linux.git
>
> Anup Patel (2):
> RISC-V: KVM: Share APLIC and IMSIC defines with irqchip drivers
> RISC-V: KVM: Use IMSIC guest files when available

Queued this series for Linux-6.11

Regards,
Anup

>
> arch/riscv/include/asm/kvm_aia_aplic.h | 58 --------------------------
> arch/riscv/include/asm/kvm_aia_imsic.h | 38 -----------------
> arch/riscv/kvm/aia.c | 35 +++++++++-------
> arch/riscv/kvm/aia_aplic.c | 2 +-
> arch/riscv/kvm/aia_device.c | 2 +-
> arch/riscv/kvm/aia_imsic.c | 2 +-
> 6 files changed, 24 insertions(+), 113 deletions(-)
> delete mode 100644 arch/riscv/include/asm/kvm_aia_aplic.h
> delete mode 100644 arch/riscv/include/asm/kvm_aia_imsic.h
>
> --
> 2.34.1
>