From: Sean Christopherson <seanjc@google.com>
To: "Naveen N Rao (AMD)" <naveen@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, Dmytro Maluka <dmaluka@chromium.org>,
Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Subject: Re: [PATCH] KVM: SVM: Clear AVIC Physical ID table entry if vCPU creation fails
Date: Fri, 11 Sep 2026 11:55:07 -0700 [thread overview]
Message-ID: <aqROi4Gp_vPvsOtp@google.com> (raw)
In-Reply-To: <20260903062856.2090499-1-naveen@kernel.org>
On Thu, Sep 03, 2026, Naveen N Rao (AMD) wrote:
> diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c
> index 3b037e385523..bc2c699380b3 100644
> --- a/arch/x86/kvm/svm/avic.c
> +++ b/arch/x86/kvm/svm/avic.c
> @@ -885,6 +885,16 @@ int avic_init_vcpu(struct vcpu_svm *svm)
> return ret;
> }
>
> +void avic_vcpu_free(struct kvm_vcpu *vcpu)
> +{
> + u32 max_id = x2avic_enabled ? x2avic_max_physical_id : AVIC_MAX_PHYSICAL_ID;
I don't love the duplicate (triplicate?) code, and looking at the usage in
avic_init_backing_page() with fresh eyes sketched me out. It's "fine", because
KVM will reject vCPU creation if vcpu_id >= kvm->arch.max_vcpu_ids, i.e. checking
only the architectural max won't exceed this max:
return min(kvm->arch.max_vcpu_ids - 1, arch_max);
But it's hard to see that, and I can't think of any reason why being paranoid
during vCPU creation/destruction would be a bad thing.
Assuming it actually works (haven't tested yet), I'll send a v2 with a prep patch
to add:
static bool avic_is_addressable_vcpu(struct kvm_vcpu *vcpu)
{
return (vcpu->vcpu_id * sizeof(u64)) <
PAGE_SIZE << avic_get_physical_id_table_order(vcpu->kvm);
}
and then this code becomes:
void avic_vcpu_free(struct kvm_vcpu *vcpu)
{
struct kvm_svm *kvm_svm = to_kvm_svm(vcpu->kvm);
if (kvm_svm->avic_physical_id_table && avic_is_addressable_vcpu(vcpu))
WRITE_ONCE(kvm_svm->avic_physical_id_table[vcpu->vcpu_id], 0);
}
> + struct kvm_svm *kvm_svm = to_kvm_svm(vcpu->kvm);
> + u32 id = vcpu->vcpu_id;
> +
> + if (kvm_svm->avic_physical_id_table && id <= max_id)
> + WRITE_ONCE(kvm_svm->avic_physical_id_table[id], 0);
> +}
prev parent reply other threads:[~2026-09-11 18:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 6:28 [PATCH] KVM: SVM: Clear AVIC Physical ID table entry if vCPU creation fails Naveen N Rao (AMD)
2026-09-09 3:09 ` Atish Patra
2026-09-11 18:55 ` Sean Christopherson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aqROi4Gp_vPvsOtp@google.com \
--to=seanjc@google.com \
--cc=dmaluka@chromium.org \
--cc=kvm@vger.kernel.org \
--cc=naveen@kernel.org \
--cc=pbonzini@redhat.com \
--cc=suravee.suthikulpanit@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.