kvm: call kvm_arch_destroy_vm if vm creation fails
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v3 Latest3 patches 10 repliesIn review
- v21 patch 3 repliesSuperseded
- v11 patch 5 repliesSuperseded
Patches in v3 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | kvm: Don't clear reference count on kvm_create_vm() error pathvirt/ | +6 | 1 reply | |
| 2/3 | kvm: Allocate memslots and buses before calling kvm_arch_init_vmvirt/ | +21 | 2 replies | |
| 3/3 | kvm: call kvm_arch_destroy_vm if vm creation failsvirt/ | +6 | 7 replies |
Reviews trailers per patch
All 3 patches have a Reviewed-by or Acked-by.
| Patch | Junaid Shahid | Sean Christopherson |
|---|---|---|
| 1/3 | R-b | Reviewed-and-tested-by |
| 2/3 | R-b | |
| 3/3 | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
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