[PATCH V2 0/4] RISC-V: KVM: AIA: Convert HGEI management to fully per-HART

guoren@kernel.org posted 4 patches 1 month, 3 weeks ago
arch/riscv/include/asm/kvm_aia.h        |  2 +-
arch/riscv/kvm/aia.c                    | 66 +++++++++++++++----------
arch/riscv/kvm/aia_device.c             |  4 +-
arch/riscv/kvm/main.c                   |  3 +-
drivers/irqchip/irq-riscv-imsic-state.c | 10 ++--
include/linux/irqchip/riscv-imsic.h     |  6 +--
6 files changed, 53 insertions(+), 38 deletions(-)
[PATCH V2 0/4] RISC-V: KVM: AIA: Convert HGEI management to fully per-HART
Posted by guoren@kernel.org 1 month, 3 weeks ago
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>

This short series converts RISC-V KVM AIA's Hypervisor Guest External
Interrupt (HGEI) line management from a global "one-size-fits-all"
model to a fully per-HART (per-CPU) model. It also performs the
corresponding cleanup in the IMSIC irqchip driver.

The motivation is to properly support heterogeneous RISC-V SoCs
(big.LITTLE, multi-vendor core mixes) where different HARTs may
expose different numbers of guest interrupt files / HGEIE bits.
The old global `kvm_riscv_aia_nr_hgei` and
`imsic_global_config::nr_guest_files` assumptions are no longer
tenable and are removed.

After this series, HGEI allocation, freeing, and interrupt delivery
are completely per-HART, the code is simpler and clearer, and there
are no remaining global assumptions about guest interrupt file
counts.

Changelog:
V2:
 - Add per-HART IMSIC guest files to compute final HGEI count.
 - Add min(local->nr_guest_files, nr_guest_files);

V1:
https://lore.kernel.org/kvm-riscv/20260421145451.1597930-1-guoren@kernel.org/

Guo Ren (Alibaba DAMO Academy) (4):
  RISC-V: KVM: AIA: Make HGEI number and management fully per-CPU
  RISC-V: KVM: AIA: Replace global HGEI count with simple enabled bool
  irqchip/riscv-imsic: Move nr_guest_files to per-HART local config
  RISC-V: KVM: AIA: Use per-HART IMSIC guest files to compute final HGEI
    count

 arch/riscv/include/asm/kvm_aia.h        |  2 +-
 arch/riscv/kvm/aia.c                    | 66 +++++++++++++++----------
 arch/riscv/kvm/aia_device.c             |  4 +-
 arch/riscv/kvm/main.c                   |  3 +-
 drivers/irqchip/irq-riscv-imsic-state.c | 10 ++--
 include/linux/irqchip/riscv-imsic.h     |  6 +--
 6 files changed, 53 insertions(+), 38 deletions(-)

-- 
2.43.0
Re: [PATCH V2 0/4] RISC-V: KVM: AIA: Convert HGEI management to fully per-HART
Posted by Anup Patel 3 weeks, 2 days ago
On Sat, Apr 25, 2026 at 6:29 AM <guoren@kernel.org> wrote:
>
> From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>
>
> This short series converts RISC-V KVM AIA's Hypervisor Guest External
> Interrupt (HGEI) line management from a global "one-size-fits-all"
> model to a fully per-HART (per-CPU) model. It also performs the
> corresponding cleanup in the IMSIC irqchip driver.
>
> The motivation is to properly support heterogeneous RISC-V SoCs
> (big.LITTLE, multi-vendor core mixes) where different HARTs may
> expose different numbers of guest interrupt files / HGEIE bits.
> The old global `kvm_riscv_aia_nr_hgei` and
> `imsic_global_config::nr_guest_files` assumptions are no longer
> tenable and are removed.
>
> After this series, HGEI allocation, freeing, and interrupt delivery
> are completely per-HART, the code is simpler and clearer, and there
> are no remaining global assumptions about guest interrupt file
> counts.
>
> Changelog:
> V2:
>  - Add per-HART IMSIC guest files to compute final HGEI count.
>  - Add min(local->nr_guest_files, nr_guest_files);
>
> V1:
> https://lore.kernel.org/kvm-riscv/20260421145451.1597930-1-guoren@kernel.org/
>
> Guo Ren (Alibaba DAMO Academy) (4):
>   RISC-V: KVM: AIA: Make HGEI number and management fully per-CPU
>   RISC-V: KVM: AIA: Replace global HGEI count with simple enabled bool
>   irqchip/riscv-imsic: Move nr_guest_files to per-HART local config
>   RISC-V: KVM: AIA: Use per-HART IMSIC guest files to compute final HGEI
>     count
>
>  arch/riscv/include/asm/kvm_aia.h        |  2 +-
>  arch/riscv/kvm/aia.c                    | 66 +++++++++++++++----------
>  arch/riscv/kvm/aia_device.c             |  4 +-
>  arch/riscv/kvm/main.c                   |  3 +-
>  drivers/irqchip/irq-riscv-imsic-state.c | 10 ++--
>  include/linux/irqchip/riscv-imsic.h     |  6 +--
>  6 files changed, 53 insertions(+), 38 deletions(-)
>
> --
> 2.43.0
>

I will send out v3 series to avoid some back-n-forth.

Regards,
Anup
Re: Re: [PATCH 3/3] irqchip/riscv-imsic: Remove global nr_guest_files after KVM AIA per-HART conversion
Posted by guoren@kernel.org 1 month, 3 weeks ago
Hi Anup,

> On Wed, Apr 22, 2026 at 8:39 AM Guo Ren <guoren@kernel.org> wrote:
> >
> > Hi all,
> >
> > This patch simply removed `nr_guest_files`, which is suboptimal. For
> > v2, I will keep `nr_guest_files` inside `struct imsic_local_config`
> > (per-HART) and compute the effective HGEI count in
> > `kvm_riscv_aia_enable()` as:
> >
> > min(hgctrl->nr_hgei, lc->nr_guest_files)
> 
> Yes, I was going to comment the exact same thing. Good that you
> realized it early.

Thank you for the feedback. This is V2:

https://lore.kernel.org/kvm-riscv/20260425005916.3321811-1-guoren@kernel.org/

Best Regards
  GUO Ren