In preparation for dropping the check separately for SEV and non-SEV VMs, duplicate the check between pre_sev_run() and pre_svm_run() (for the non-SEV code path). Opportunistically drop the unconditional dirtying of VMCB_ASID, as it's only needed when the ASID is actually updated in the VMCB, not when TLB_CONTROL is updated (as the code currently reads). No functional change intended. Signed-off-by: Yosry Ahmed --- arch/x86/kvm/svm/sev.c | 6 +++++- arch/x86/kvm/svm/svm.c | 9 +++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index d1f0e42c72b27..0e5046a12a970 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3583,6 +3583,11 @@ int pre_sev_run(struct vcpu_svm *svm, int cpu) /* Assign the asid allocated with this SEV guest */ svm->asid = asid; + if (unlikely(svm->asid != svm->vmcb->control.asid)) { + svm->vmcb->control.asid = asid; + vmcb_mark_dirty(svm->vmcb, VMCB_ASID); + } + /* * Flush guest TLB: * @@ -3595,7 +3600,6 @@ int pre_sev_run(struct vcpu_svm *svm, int cpu) sd->sev_vmcbs[asid] = svm->vmcb; vmcb_set_flush_asid(svm->vmcb); - vmcb_mark_dirty(svm->vmcb, VMCB_ASID); return 0; } diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index aff1aae5a5a32..b8f3f71f70673 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3779,6 +3779,11 @@ static int pre_svm_run(struct kvm_vcpu *vcpu) if (svm->current_vmcb->asid_generation != sd->asid_generation) new_asid(svm, sd); + if (unlikely(svm->asid != svm->vmcb->control.asid)) { + svm->vmcb->control.asid = svm->asid; + vmcb_mark_dirty(svm->vmcb, VMCB_ASID); + } + return 0; } @@ -4515,10 +4520,6 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags) sync_lapic_to_cr8(vcpu); - if (unlikely(svm->asid != svm->vmcb->control.asid)) { - svm->vmcb->control.asid = svm->asid; - vmcb_mark_dirty(svm->vmcb, VMCB_ASID); - } svm->vmcb->save.cr2 = vcpu->arch.cr2; if (guest_cpu_cap_has(vcpu, X86_FEATURE_ERAPS) && -- 2.55.0.229.g6434b31f56-goog