KVM RISC-V APLIC fixes
Subsystems (4)
cover KVM RISC-V APLIC fixes
Few fixes for KVM RISC-V in-kernel APLIC emulation which were discovered during Linux AIA driver patch reviews.
These patches can also be found in the riscv_kvm_aplic_fixes_v1 branch at: https://github.com/avpatel/linux.git
Anup Patel (2):
RISC-V: KVM: Fix APLIC setipnum_le/be write emulation
RISC-V: KVM: Fix APLIC in_clrip[x] read emulation
arch/riscv/kvm/aia_aplic.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 RISC-V: KVM: Fix APLIC setipnum_le/be write emulation
The writes to setipnum_le/be register for APLIC in MSI-mode have special consideration for level-triggered interrupts as-per the section "4.9.2 Special consideration for level-sensitive interrupt sources" of the RISC-V AIA specification.
Particularly, the below text from the RISC-V AIA specification defines the behaviour of writes to setipnum_le/be register for level-triggered interrupts:
"A second option is for the interrupt service routine to write the APLIC?s source identity number for the interrupt to the domain?s setipnum register just before exiting. This will cause the interrupt?s pending bit to be set to one again if the source is still asserting an interrupt, but not if the source is not asserting an interrupt."
Fix setipnum_le/be write emulation for in-kernel APLIC by implementing the above behaviour in aplic_write_pending() function.
--- arch/riscv/kvm/aia_aplic.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
arch/riscv/kvm/aia_aplic.c +13 -3
@@ -137,11 +137,21 @@ static void aplic_write_pending(struct aplic *aplic, u32 irq, bool pending)raw_spin_lock_irqsave (&irqd->lock, flags); sm = irqd->sourcecfg &APLIC_SOURCECFG_SM_MASK ; -if (!pending && - ((sm ==APLIC_SOURCECFG_SM_LEVEL_HIGH ) || - (sm ==APLIC_SOURCECFG_SM_LEVEL_LOW ))) +if (sm ==APLIC_SOURCECFG_SM_INACTIVE ) goto skip_write_pending; +if (sm ==APLIC_SOURCECFG_SM_LEVEL_HIGH || + sm ==APLIC_SOURCECFG_SM_LEVEL_LOW ) { +if (!pending) + goto skip_write_pending; +if ((irqd->state &APLIC_IRQ_STATE_INPUT ) && + sm ==APLIC_SOURCECFG_SM_LEVEL_LOW ) + goto skip_write_pending; +if (!(irqd->state &APLIC_IRQ_STATE_INPUT ) && + sm ==APLIC_SOURCECFG_SM_LEVEL_HIGH ) + goto skip_write_pending; + } +if (pending) irqd->state |=APLIC_IRQ_STATE_PENDING ;else
Signature · 1 line
2.34.1
PATCH 2/2 RISC-V: KVM: Fix APLIC in_clrip[x] read emulation
In reply to Anup PatelThe reads to APLIC in_clrip[x] registers returns rectified input values of the interrupt sources.
A rectified input value of an interrupt source is defined by the section "4.5.2 Source configurations (sourcecfg[1]?sourcecfg[1023])" of the RISC-V AIA specification as:
rectified input value = (incoming wire value) XOR (source is inverted)
Update the riscv_aplic_input() implementation to match the above.
--- arch/riscv/kvm/aia_aplic.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
arch/riscv/kvm/aia_aplic.c +18 -3
@@ -197,16 +197,31 @@ static void aplic_write_enabled(struct aplic *aplic, u32 irq, bool enabled)static bool aplic_read_input (struct aplic *aplic,u32 irq) { -bool ret; -unsigned long flags; +u32 sourcecfg, sm, raw_input, irq_inverted;struct aplic_irq *irqd; +unsigned long flags; +bool ret = false;if (!irq || aplic->nr_irqs <= irq)return false; irqd = &aplic->irqs[irq];raw_spin_lock_irqsave (&irqd->lock, flags); - ret = (irqd->state &APLIC_IRQ_STATE_INPUT ) ? true : false; + + sourcecfg = irqd->sourcecfg; +if (sourcecfg &APLIC_SOURCECFG_D ) + goto skip; + + sm = sourcecfg &APLIC_SOURCECFG_SM_MASK ; +if (sm ==APLIC_SOURCECFG_SM_INACTIVE ) + goto skip; + + raw_input = (irqd->state &APLIC_IRQ_STATE_INPUT ) ?1 :0 ; + irq_inverted = (sm ==APLIC_SOURCECFG_SM_LEVEL_LOW || + sm ==APLIC_SOURCECFG_SM_EDGE_FALL ) ?1 :0 ; + ret = !!(raw_input ^ irq_inverted); + +skip:raw_spin_unlock_irqrestore (&irqd->lock, flags);return ret;
Signature · 1 line
2.34.1
Hi,
As you mentioned as below, riscv's aia patch in
https://github.com/avpatel/linux.git
Why is this series of patches not merged into upstream?
? 2024/3/21 16:50, Anup Patel ??:
Quoted 13 lines
Few fixes for KVM RISC-V in-kernel APLIC emulation which were discovered during Linux AIA driver patch reviews.
These patches can also be found in the
riscv_kvm_aplic_fixes_v1branch at: https://github.com/avpatel/linux.gitAnup Patel (2):
RISC-V: KVM: Fix APLIC setipnum_le/be write emulation
RISC-V: KVM: Fix APLIC in_clrip[x] read emulationarch/riscv/kvm/aia_aplic.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-)
Anup Patel
maintainerQuoted 9 lines · On Fri, Mar 22, 2024 at 5:05?PM Bing Fan <[email protected]> wrote:
Hi,
As you mentioned as below, riscv's aia patch in
https://github.com/avpatel/linux.gitWhy is this series of patches not merged into upstream?
This will be sent as part of Linux-6.9-rcX fixes (after 1-2 weeks).
Regards,
Anup
Quoted 16 lines
? 2024/3/21 16:50, Anup Patel ??:
Quoted 13 lines
Few fixes for KVM RISC-V in-kernel APLIC emulation which were discovered during Linux AIA driver patch reviews.
These patches can also be found in the
riscv_kvm_aplic_fixes_v1branch at: https://github.com/avpatel/linux.gitAnup Patel (2):
RISC-V: KVM: Fix APLIC setipnum_le/be write emulation
RISC-V: KVM: Fix APLIC in_clrip[x] read emulationarch/riscv/kvm/aia_aplic.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-)
Anup Patel
maintainerQuoted 10 lines · On Thu, Mar 21, 2024 at 2:20?PM Anup Patel <[email protected]> wrote:
Few fixes for KVM RISC-V in-kernel APLIC emulation which were discovered during Linux AIA driver patch reviews.
These patches can also be found in the
riscv_kvm_aplic_fixes_v1branch at: https://github.com/avpatel/linux.gitAnup Patel (2):
RISC-V: KVM: Fix APLIC setipnum_le/be write emulation
RISC-V: KVM: Fix APLIC in_clrip[x] read emulation
Queued this series for Linux-6.9 fixes.
Thanks,
Anup
Quoted 7 lines
arch/riscv/kvm/aia_aplic.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-)--
2.34.1