Skip to contentSkip to conversation

KVM: RISC-V: Avoid spurious virtual interrupts after clearing hideleg CSR

PATCH New Vincent Chen 2 participants 2 messages Dec 27, 2021 – Dec 29, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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")
---
 arch/riscv/kvm/main.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/riscv/kvm/main.c +8 -0
index 421ecf4e6360..18e7a979740c 100644
@@ -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);
 }
Signature · 1 line
2.17.1
maintainer
#1 lore raw

PATCH v2 1/1 KVM: RISC-V: Avoid spurious virtual interrupts after clearing hideleg CSR

Quoted 9 lines · Vincent Chen

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.

Quoted 3 lines
Fixes 99cdc6c18c2d ("RISC-V: Add initial skeletal KVM support")

Queued this patch for 5.17

Thanks,
Anup

Quoted 31 lines
---
 arch/riscv/kvm/main.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/riscv/kvm/main.c +8 -1
index 421ecf4e6360..18e7a979740c 100644
@@ -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);
 }
--

2.17.1

--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv