Re: [PATCH v2 2/3] KVM: SVM: Do all per-VM AVIC initialization during vCPU precreation phase

From: Naveen N Rao

Date: Fri Jul 03 2026 - 13:17:23 EST


On Tue, Jun 30, 2026 at 02:01:55PM -0700, Sean Christopherson wrote:
> Move all per-VM AVIC initialization from VM creation to vCPU pre-creation,
> i.e. defer allocating the logical ID table and adding the VM to the GA Log
> list until vCPUs are created. This will allow removing the VM from the GA
> Log list before vCPUs are destroyed without needing yet another kvm_x86_ops
> hook (.vm_pre_destroy() is very intentionally called if and only if VM
> creation fully succeeds).
>
> As a bonus, this re-unites physical and logic table allocation, and avoids
> allocating a logical table in the unlikely scenario that userspace creates
> a VM without an in-kernel local APIC.
>
> Another bonus to hooking .vcpu_precreate() is that there is no need to
> unwind on failure, as the VM has already been created, i.e. KVM will run
> through all phases of VM destruction. In fact, unwinding is undesirable,
> as KVM tries to keep VM-wide behavior idempotent/sticky across creaton of
> multiple vCPUs.
>
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> ---
> arch/x86/kvm/svm/avic.c | 94 +++++++++++++++++++++++++----------------
> arch/x86/kvm/svm/svm.c | 6 ---
> 2 files changed, 57 insertions(+), 43 deletions(-)

This takes the cleanup one step ahead by removing avic_vm_init(). Good!

With the prototype for avic_vm_init() removed:
Reviewed-by: Naveen N Rao (AMD) <naveen@xxxxxxxxxx>


- Naveen