Re: [PATCH v1 10/28] KVM: SVM: Use a static ASID per vCPU

Yosry Ahmed <[email protected]> Fri, 31 Jul 2026 23:18:08 -0700
Newsgroups org.kernel.vger.kvm,org.kernel.vger.linux-kernel
Message-ID <CAO9r8zPiH5hRUVVspiuBdE-91Q17zz8gq=DG=XWji=FbRGQz9A@mail.gmail.com>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 3aac702f45b2b..087d18a5eda69 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -2071,6 +2071,7 @@ static void sev_migrate_from(struct kvm *dst_kvm, struct kvm *src_kvm)
>         kvm_for_each_vcpu(i, dst_vcpu, dst_kvm) {
>                 dst_svm = to_svm(dst_vcpu);
>
> +               dst_svm->asid = dst->asid;

From internal Sashiko:
---
Does this overwrite the destination vCPU's initial ASID without freeing it?

During vCPU creation for the destination VM, before it is marked as an SEV
guest, svm_vcpu_create() allocates a normal TLB tag. When this migration
overwrites dst_svm->asid with the source SEV ASID, the original tag appears
to be leaked.

When the destination VM is eventually destroyed, is_sev_guest(vcpu) will
evaluate to true, preventing the leaked tag from being recovered in
free_asid(). Could this be abused to exhaust the global non-SEV TLB tag pool?
---

Yeah I think this is correct. Looking at the SEV migration selftest,
it seems like the destination VM is not initialized as an SEV VM. We
should probably free the non-SEV ASID before copying the ASID here?


>                 sev_init_vmcb(dst_svm, false);
>
>                 if (!dst->es_active)
> @@ -4816,7 +4817,7 @@ void sev_init_vmcb(struct vcpu_svm *svm, bool init_event)
>         svm->vmcb->control.misc_ctl |= SVM_MISC_ENABLE_SEV;
>         clr_exception_intercept(svm, UD_VECTOR);
>
> -       svm->asid = sev_get_asid(vcpu->kvm);
> +       WARN_ON_ONCE(svm->asid != sev_get_asid(vcpu->kvm));
>         svm->vmcb->control.asid = svm->asid;
>         vmcb_mark_dirty(svm->vmcb, VMCB_ASID);