OpenCloudOS-Kernel/arch/riscv/kvm
Yong-Xuan Wang 24f855a88c RISCV: KVM: update external interrupt atomically for IMSIC swfile
[ Upstream commit 4ad9843e1ea088bd2529290234c6c4c6374836a7 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-01-10 17:16:59 +01:00
..
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 RISC-V: KVM: return ENOENT in *_one_reg() when reg is unknown 2023-08-08 17:25:42 +05:30
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 2024-01-10 17:16:59 +01:00
main.c RISC-V: KVM: Implement guest external interrupt line management 2023-06-18 21:24:33 +05:30
mmu.c Common KVM changes for 6.6: 2023-08-31 13:19:55 -04:00
tlb.c RISC-V: KVM: use bitmap_zero() API 2023-06-06 08:51:50 +05:30
vcpu.c KVM: riscv: Add KVM_GET_REG_LIST API support 2023-08-09 12:15:25 +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 RISC-V: KVM: return ENOENT in *_one_reg() when reg is unknown 2023-08-08 17:25:42 +05:30
vcpu_insn.c RISC-V: KVM: Initial skeletal support for AIA 2023-04-21 17:45:48 +05:30
vcpu_onereg.c RISC-V: KVM: Fix riscv_vcpu_get_isa_ext_single() for missing extensions 2023-09-21 15:04:01 +05:30
vcpu_pmu.c RISC-V: KVM: Support firmware events 2023-02-07 20:36:06 +05:30
vcpu_sbi.c RISC-V: KVM: return ENOENT in *_one_reg() when reg is unknown 2023-08-08 17:25:42 +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: Increment firmware pmu events 2023-02-07 20:36:08 +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 RISC-V: KVM: Improve vector save/restore functions 2023-08-08 17:26:05 +05:30
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