[PATCH] LoongArch: KVM: Set cpu before IN_GUEST_MODE is set

Bibo Mao posted 1 patch 1 month, 4 weeks ago
arch/loongarch/kvm/vcpu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] LoongArch: KVM: Set cpu before IN_GUEST_MODE is set
Posted by Bibo Mao 1 month, 4 weeks ago
In function kvm_make_vcpu_request(), it will send IPI to physical CPU
when vCPU is in IN_GUEST_MODE mode. And physical CPU is set in function
kvm_check_vpid(), and it should be called before IN_GUEST_MODE is set.
Otherwise IPI will send to wrong old physical CPU where vCPU is running.

Fixes: 2fc3bd86db4b ("LoongArch: KVM: Implement basic vcpu interfaces")
Cc: stable@vger.kernel.org
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 arch/loongarch/kvm/vcpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
index 20c207d80e31..fd0dd22a7162 100644
--- a/arch/loongarch/kvm/vcpu.c
+++ b/arch/loongarch/kvm/vcpu.c
@@ -300,10 +300,10 @@ static int kvm_pre_enter_guest(struct kvm_vcpu *vcpu)
 		 */
 		local_irq_disable();
 		kvm_deliver_exception(vcpu);
+		kvm_check_vpid(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);
 
 		/*
 		 * Called after function kvm_check_vpid()

base-commit: 075b74841bd0065a3bda3440873c747938e69b68
-- 
2.39.3
Re: [PATCH] LoongArch: KVM: Set cpu before IN_GUEST_MODE is set
Posted by Huacai Chen 1 month, 3 weeks ago
Applied, thanks.

Huacai

On Tue, Aug 4, 2026 at 4:29 PM Bibo Mao <maobibo@loongson.cn> wrote:
>
> In function kvm_make_vcpu_request(), it will send IPI to physical CPU
> when vCPU is in IN_GUEST_MODE mode. And physical CPU is set in function
> kvm_check_vpid(), and it should be called before IN_GUEST_MODE is set.
> Otherwise IPI will send to wrong old physical CPU where vCPU is running.
>
> Fixes: 2fc3bd86db4b ("LoongArch: KVM: Implement basic vcpu interfaces")
> Cc: stable@vger.kernel.org
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
>  arch/loongarch/kvm/vcpu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
> index 20c207d80e31..fd0dd22a7162 100644
> --- a/arch/loongarch/kvm/vcpu.c
> +++ b/arch/loongarch/kvm/vcpu.c
> @@ -300,10 +300,10 @@ static int kvm_pre_enter_guest(struct kvm_vcpu *vcpu)
>                  */
>                 local_irq_disable();
>                 kvm_deliver_exception(vcpu);
> +               kvm_check_vpid(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);
>
>                 /*
>                  * Called after function kvm_check_vpid()
>
> base-commit: 075b74841bd0065a3bda3440873c747938e69b68
> --
> 2.39.3
>