Skip to content

kvm: call kvm_arch_destroy_vm if vm creation fails

Jim Mattson kvm 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 10 repliesIn review
  2. v21 patch 3 repliesSuperseded
  3. v11 patch 5 repliesSuperseded

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3kvm: Don't clear reference count on kvm_create_vm() error pathvirt/kvm/kvm_main.c+6 -21 reply
2/3kvm: Allocate memslots and buses before calling kvm_arch_init_vmvirt/kvm/kvm_main.c+21 -192 replies
3/3kvm: call kvm_arch_destroy_vm if vm creation failsvirt/kvm/kvm_main.c+6 -47 replies

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchJunaid ShahidSean Christopherson
1/3R-b Reviewed-and-tested-by
2/3R-b
3/3R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/3] kvm: call kvm_arch_destroy_vm if vm creation fails

Beginning with commit 44a95dae1d229a ("KVM: x86: Detect and Initialize AVIC support"), AMD's version of kvm_arch_init_vm() will allocate memory if the module parameter, avic, is enabled. (Note that this module parameter is disabled by default.) However, there are many possible failure exits from kvm_create_vm() *after* the call to kvm_arch_init_vm(), and the memory allocated by kvm_arch_init_vm() was leaked on these failure paths.

The obvious solution is to call kvm_arch_destroy_vm() on these failure paths, since it will free the memory allocated by kvm_arch_init_vm(). However, kvm_arch_destroy_vm() may reference memslots and buses that were allocated later in kvm_create_vm(). So, before we can call kvm_arch_destroy_vm() on the failure paths out of kvm_create_vm(), we need to hoist the memslot and bus allocation up before the call to kvm_arch_init_vm().

The call to clear the reference count on (some) failure paths out of kvm_create_vm() just added to the potential confusion. By sinking the call to set the reference count below any possible failure exits, we can eliminate the call to clear the reference count on the failure paths.

v1 -> v2: Call kvm_arch_destroy_vm before refcount_set v2 -> v3: Added two preparatory changes

Jim Mattson (2):
kvm: Don't clear reference count on kvm_create_vm() error path
kvm: Allocate memslots and buses before calling kvm_arch_init_vm

John Sperbeck (1):
kvm: call kvm_arch_destroy_vm if vm creation fails

 virt/kvm/kvm_main.c | 52 ++++++++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 22 deletions(-)
Signature · 1 line
2.24.0.rc0.303.g954a862665-goog