From: Vincent Chen Date: Mon, 27 Dec 2021 03:05:14 +0000 (+0800) Subject: KVM: RISC-V: Avoid spurious virtual interrupts after clearing hideleg CSR X-Git-Tag: v6.6.17~8235^2~146^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=33e5b5746cc2336660c8710ba109d9a3923627b5;p=platform%2Fkernel%2Flinux-rpi.git KVM: RISC-V: Avoid spurious virtual interrupts after clearing hideleg CSR When the last VM is terminated, the host kernel will invoke function hardware_disable_nolock() on each CPU to disable the related virtualization functions. Here, RISC-V currently only clears hideleg CSR and hedeleg CSR. This behavior will cause the host kernel to receive spurious interrupts if hvip CSR has pending interrupts and the corresponding enable bits in vsie CSR are asserted. To avoid it, hvip CSR and vsie CSR must be cleared before clearing hideleg CSR. Fixes: 99cdc6c18c2d ("RISC-V: Add initial skeletal KVM support") Signed-off-by: Vincent Chen Reviewed-by: Anup Patel Signed-off-by: Anup Patel --- diff --git a/arch/riscv/kvm/main.c b/arch/riscv/kvm/main.c index 421ecf4..2e5ca43 100644 --- a/arch/riscv/kvm/main.c +++ b/arch/riscv/kvm/main.c @@ -58,6 +58,14 @@ int kvm_arch_hardware_enable(void) void kvm_arch_hardware_disable(void) { + /* + * After clearing the hideleg CSR, the host kernel will receive + * spurious interrupts if hvip CSR has pending interrupts and the + * corresponding enable bits in vsie CSR are asserted. To avoid it, + * hvip CSR and vsie CSR must be cleared before clearing hideleg CSR. + */ + csr_write(CSR_VSIE, 0); + csr_write(CSR_HVIP, 0); csr_write(CSR_HEDELEG, 0); csr_write(CSR_HIDELEG, 0); }