KVM: X86: Update mmu->pdptrs only when it is changed
authorLai Jiangshan <laijs@linux.alibaba.com>
Thu, 11 Nov 2021 14:45:26 +0000 (22:45 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 8 Dec 2021 09:25:04 +0000 (04:25 -0500)
It is unchanged in most cases.

Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
Message-Id: <20211111144527.88852-1-jiangshanlai@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/x86.c

index be3b4a0..d4f1dff 100644 (file)
@@ -828,9 +828,12 @@ int load_pdptrs(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, unsigned long cr3)
                }
        }
 
-       memcpy(mmu->pdptrs, pdpte, sizeof(mmu->pdptrs));
-       kvm_register_mark_dirty(vcpu, VCPU_EXREG_PDPTR);
-       kvm_make_request(KVM_REQ_LOAD_MMU_PGD, vcpu);
+       kvm_register_mark_available(vcpu, VCPU_EXREG_PDPTR);
+       if (memcmp(mmu->pdptrs, pdpte, sizeof(mmu->pdptrs))) {
+               memcpy(mmu->pdptrs, pdpte, sizeof(mmu->pdptrs));
+               kvm_register_mark_dirty(vcpu, VCPU_EXREG_PDPTR);
+               kvm_make_request(KVM_REQ_LOAD_MMU_PGD, vcpu);
+       }
        vcpu->arch.pdptrs_from_userspace = false;
 
        return 1;