]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
LoongArch: KVM: Move host CSR_EENTRY save and restore in context switch
authorBibo Mao <maobibo@loongson.cn>
Thu, 9 Apr 2026 10:56:36 +0000 (18:56 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Thu, 9 Apr 2026 10:56:36 +0000 (18:56 +0800)
CSR register LOONGARCH_CSR_EENTRY is shared between host CPU and guest
vCPU, KVM need save and restore LOONGARCH_CSR_EENTRY register. Here move
LOONGARCH_CSR_EENTRY saving in to context switch function rather than VM
entry.

At most time VM enter/exit is much more frequent than vCPU thread context
switch.

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

index fc8f7290cfed4067f52571cc524d8c01aecdf101..3367a9886b63743fd1c527aa6e739e520152a20d 100644 (file)
@@ -320,7 +320,6 @@ static int kvm_pre_enter_guest(struct kvm_vcpu *vcpu)
                 * and it may also clear KVM_REQ_TLB_FLUSH_GPA pending bit
                 */
                kvm_late_check_requests(vcpu);
-               vcpu->arch.host_eentry = csr_read64(LOONGARCH_CSR_EENTRY);
                /* Clear KVM_LARCH_SWCSR_LATEST as CSR will change when enter guest */
                vcpu->arch.aux_inuse &= ~KVM_LARCH_SWCSR_LATEST;
 
@@ -1628,9 +1627,11 @@ static int _kvm_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
         * If not, any old guest state from this vCPU will have been clobbered.
         */
        context = per_cpu_ptr(vcpu->kvm->arch.vmcs, cpu);
-       if (migrated || (context->last_vcpu != vcpu))
+       if (migrated || (context->last_vcpu != vcpu)) {
+               context->last_vcpu = vcpu;
                vcpu->arch.aux_inuse &= ~KVM_LARCH_HWCSR_USABLE;
-       context->last_vcpu = vcpu;
+               vcpu->arch.host_eentry = csr_read64(LOONGARCH_CSR_EENTRY);
+       }
 
        /* Restore timer state regardless */
        kvm_restore_timer(vcpu);