]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
LoongArch: KVM: Deliver interrupt after IN_GUEST_MODE is set
authorBibo Mao <maobibo@loongson.cn>
Thu, 11 Jun 2026 12:46:43 +0000 (20:46 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Thu, 11 Jun 2026 12:46:43 +0000 (20:46 +0800)
Interrupt delivery should be called after IN_GUEST_MODE is set. Other
threads may be posting interrupt however does not send IPI to the vCPU,
since the vCPU is not in IN_GUEST_MODE yet.

Here move function call with kvm_deliver_intr() after IN_GUEST_MODE is
set, and set mode with OUTSIDE_GUEST_MODE with atomic method.

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

index 89aa49df276a1ba09fee597784a1caabfb18b60e..33aefd90d2289d0386ce37123ff373bf6fb23a87 100644 (file)
@@ -299,10 +299,10 @@ static int kvm_pre_enter_guest(struct kvm_vcpu *vcpu)
                 * check vmid before vcpu enter guest
                 */
                local_irq_disable();
-               kvm_deliver_intr(vcpu);
                kvm_deliver_exception(vcpu);
                /* Make sure the vcpu mode has been written */
                smp_store_mb(vcpu->mode, IN_GUEST_MODE);
+               kvm_deliver_intr(vcpu);
                kvm_check_vpid(vcpu);
 
                /*
@@ -339,7 +339,7 @@ static int kvm_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)
        u32 intr = estat & CSR_ESTAT_IS;
        u32 ecode = (estat & CSR_ESTAT_EXC) >> CSR_ESTAT_EXC_SHIFT;
 
-       vcpu->mode = OUTSIDE_GUEST_MODE;
+       smp_store_mb(vcpu->mode, OUTSIDE_GUEST_MODE);
 
        /* Set a default exit reason */
        run->exit_reason = KVM_EXIT_UNKNOWN;