]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
LoongArch: KVM: Fully clear some CSRs when VM reboot
authorBibo Mao <maobibo@loongson.cn>
Thu, 24 Apr 2025 12:15:52 +0000 (20:15 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Sat, 26 Apr 2025 01:58:13 +0000 (09:58 +0800)
Some registers such as LOONGARCH_CSR_ESTAT and LOONGARCH_CSR_GINTC are
partly cleared with function _kvm_setcsr(). This comes from the hardware
specification, some bits are read only in VM mode, and however they can
be written in host mode. So they are partly cleared in VM mode, and can
be fully cleared in host mode.

These read only bits show pending interrupt or exception status. When VM
reset, the read-only bits should be cleared, otherwise vCPU will receive
unknown interrupts in boot stage.

Here registers LOONGARCH_CSR_ESTAT/LOONGARCH_CSR_GINTC are fully cleared
in ioctl KVM_REG_LOONGARCH_VCPU_RESET vCPU reset path.

Cc: stable@vger.kernel.org
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
arch/loongarch/kvm/vcpu.c

index 8e427b3796612380f621b1194b70d4974b89adce..2d3c2a2d1d1cb6c4b17721351e59f92c4d406db6 100644 (file)
@@ -902,6 +902,13 @@ static int kvm_set_one_reg(struct kvm_vcpu *vcpu,
                        vcpu->arch.st.guest_addr = 0;
                        memset(&vcpu->arch.irq_pending, 0, sizeof(vcpu->arch.irq_pending));
                        memset(&vcpu->arch.irq_clear, 0, sizeof(vcpu->arch.irq_clear));
+
+                       /*
+                        * When vCPU reset, clear the ESTAT and GINTC registers
+                        * Other CSR registers are cleared with function _kvm_setcsr().
+                        */
+                       kvm_write_sw_gcsr(vcpu->arch.csr, LOONGARCH_CSR_GINTC, 0);
+                       kvm_write_sw_gcsr(vcpu->arch.csr, LOONGARCH_CSR_ESTAT, 0);
                        break;
                default:
                        ret = -EINVAL;