linux-stable/arch/riscv/kvm
Yong-Xuan Wang 4ad9843e1e RISCV: KVM: update external interrupt atomically for IMSIC swfile
The emulated IMSIC update the external interrupt pending depending on
the value of eidelivery and topei. It might lose an interrupt when it
is interrupted before setting the new value to the pending status.

For example, when VCPU0 sends an IPI to VCPU1 via IMSIC:

VCPU0                           VCPU1

                                CSRSWAP topei = 0
                                The VCPU1 has claimed all the external
                                interrupt in its interrupt handler.

                                topei of VCPU1's IMSIC = 0

set pending in VCPU1's IMSIC

topei of VCPU1' IMSIC = 1

set the external interrupt
pending of VCPU1

                                clear the external interrupt pending
                                of VCPU1

When the VCPU1 switches back to VS mode, it exits the interrupt handler
because the result of CSRSWAP topei is 0. If there are no other external
interrupts injected into the VCPU1's IMSIC, VCPU1 will never know this
pending interrupt unless it initiative read the topei.

If the interruption occurs between updating interrupt pending in IMSIC
and updating external interrupt pending of VCPU, it will not cause a
problem. Suppose that the VCPU1 clears the IPI pending in IMSIC right
after VCPU0 sets the pending, the external interrupt pending of VCPU1
will not be set because the topei is 0. But when the VCPU1 goes back to
VS mode, the pending IPI will be reported by the CSRSWAP topei, it will
not lose this interrupt.

So we only need to make the external interrupt updating procedure as a
critical section to avoid the problem.

Fixes: db8b7e97d6 ("RISC-V: KVM: Add in-kernel virtualization of AIA IMSIC")
Tested-by: Roy Lin <roy.lin@sifive.com>
Tested-by: Wayling Chen <wayling.chen@sifive.com>
Co-developed-by: Vincent Chen <vincent.chen@sifive.com>
Signed-off-by: Vincent Chen <vincent.chen@sifive.com>
Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
Signed-off-by: Anup Patel <anup@brainfault.org>
2023-12-13 11:59:52 +05:30
..
Kconfig RISC-V: KVM: Skeletal in-kernel AIA irqchip support 2023-06-18 21:24:40 +05:30
Makefile RISC-V: KVM: Factor-out ONE_REG related code to its own source file 2023-08-08 17:25:29 +05:30
aia.c riscv: Rearrange hwcap.h and cpufeature.h 2023-11-09 10:15:51 -08:00
aia_aplic.c RISC-V: KVM: Expose APLIC registers as attributes of AIA irqchip 2023-06-18 21:24:50 +05:30
aia_device.c RISC-V: KVM: Remove unneeded semicolon 2023-06-20 10:48:38 +05:30
aia_imsic.c RISCV: KVM: update external interrupt atomically for IMSIC swfile 2023-12-13 11:59:52 +05:30
main.c riscv: Rearrange hwcap.h and cpufeature.h 2023-11-09 10:15:51 -08:00
mmu.c Common KVM changes for 6.6: 2023-08-31 13:19:55 -04:00
tlb.c riscv: Rearrange hwcap.h and cpufeature.h 2023-11-09 10:15:51 -08:00
vcpu.c RISC-V: KVM: Allow some SBI extensions to be disabled by default 2023-10-20 16:50:33 +05:30
vcpu_exit.c RISC-V: KVM: Redirect AMO load/store misaligned traps to guest 2023-06-06 09:04:11 +05:30
vcpu_fp.c riscv: Rearrange hwcap.h and cpufeature.h 2023-11-09 10:15:51 -08:00
vcpu_insn.c RISC-V: KVM: Initial skeletal support for AIA 2023-04-21 17:45:48 +05:30
vcpu_onereg.c RISC-V Patches for the 6.7 Merge Window, Part 2 2023-11-10 09:23:17 -08:00
vcpu_pmu.c RISC-V: KVM: Support firmware events 2023-02-07 20:36:06 +05:30
vcpu_sbi.c RISC-V: KVM: Forward SBI DBCN extension to user-space 2023-10-20 16:50:36 +05:30
vcpu_sbi_base.c RISC-V: KVM: Add ONE_REG interface to enable/disable SBI extensions 2023-04-21 17:38:44 +05:30
vcpu_sbi_hsm.c RISC-V: KVM: Modify SBI extension handler to return SBI error code 2023-02-07 20:35:45 +05:30
vcpu_sbi_pmu.c RISC-V: KVM: Add SBI PMU extension support 2023-02-07 20:35:53 +05:30
vcpu_sbi_replace.c RISC-V: KVM: Forward SBI DBCN extension to user-space 2023-10-20 16:50:36 +05:30
vcpu_sbi_v01.c RISC-V: KVM: Modify SBI extension handler to return SBI error code 2023-02-07 20:35:45 +05:30
vcpu_switch.S RISC-V: KVM: Refine __kvm_riscv_switch_to() implementation 2022-03-11 19:02:22 +05:30
vcpu_timer.c RISC-V: KVM: do not EOPNOTSUPP in set KVM_REG_RISCV_TIMER_REG 2023-08-08 17:25:49 +05:30
vcpu_vector.c riscv: Rearrange hwcap.h and cpufeature.h 2023-11-09 10:15:51 -08:00
vm.c RISC-V: KVM: Skeletal in-kernel AIA irqchip support 2023-06-18 21:24:40 +05:30
vmid.c RISC-V: KVM: Drop the _MASK suffix from hgatp.VMID mask defines 2023-04-21 17:45:44 +05:30