From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Jim Mattson <jmattson@google.com>
Cc: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
John Sperbeck <jsperbeck@google.com>,
Junaid Shahid <junaids@google.com>
Subject: Re: [PATCH v3 3/3] kvm: call kvm_arch_destroy_vm if vm creation fails
Date: Thu, 24 Oct 2019 16:29:43 -0700 [thread overview]
Message-ID: <20191024232943.GJ28043@linux.intel.com> (raw)
In-Reply-To: <20191024230327.140935-4-jmattson@google.com>
On Thu, Oct 24, 2019 at 04:03:27PM -0700, Jim Mattson wrote:
> From: John Sperbeck <jsperbeck@google.com>
>
> In kvm_create_vm(), if we've successfully called kvm_arch_init_vm(), but
> then fail later in the function, we need to call kvm_arch_destroy_vm()
> so that it can do any necessary cleanup (like freeing memory).
>
> Fixes: 44a95dae1d229a ("KVM: x86: Detect and Initialize AVIC support")
>
> Signed-off-by: John Sperbeck <jsperbeck@google.com>
> Signed-off-by: Jim Mattson <jmattson@google.com>
> Reviewed-by: Junaid Shahid <junaids@google.com>
> ---
> virt/kvm/kvm_main.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 77819597d7e8e..f8f0106f8d20f 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -649,7 +649,7 @@ static struct kvm *kvm_create_vm(unsigned long type)
> struct kvm_memslots *slots = kvm_alloc_memslots();
>
> if (!slots)
> - goto out_err_no_disable;
> + goto out_err_no_arch_destroy_vm;
> /* Generations must be different for each address space. */
> slots->generation = i;
> rcu_assign_pointer(kvm->memslots[i], slots);
> @@ -659,12 +659,12 @@ static struct kvm *kvm_create_vm(unsigned long type)
> rcu_assign_pointer(kvm->buses[i],
> kzalloc(sizeof(struct kvm_io_bus), GFP_KERNEL_ACCOUNT));
> if (!kvm->buses[i])
> - goto out_err_no_disable;
> + goto out_err_no_arch_destroy_vm;
> }
>
> r = kvm_arch_init_vm(kvm, type);
> if (r)
> - goto out_err_no_disable;
> + goto out_err_no_arch_destroy_vm;
>
> r = hardware_enable_all();
> if (r)
> @@ -685,7 +685,7 @@ static struct kvm *kvm_create_vm(unsigned long type)
>
> /*
> * kvm_get_kvm() isn't legal while the vm is being created
> - * (e.g. in kvm_arch_init_vm).
> + * (e.g. in kvm_arch_init_vm or kvm_arch_destroy_vm).
LOL, even I don't think this one is necessary ;-)
> */
> refcount_set(&kvm->users_count, 1);
>
> @@ -704,6 +704,8 @@ static struct kvm *kvm_create_vm(unsigned long type)
> out_err_no_srcu:
> hardware_disable_all();
> out_err_no_disable:
> + kvm_arch_destroy_vm(kvm);
> +out_err_no_arch_destroy_vm:
> for (i = 0; i < KVM_NR_BUSES; i++)
> kfree(kvm_get_bus(kvm, i));
> for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++)
> --
> 2.24.0.rc0.303.g954a862665-goog
>
next prev parent reply other threads:[~2019-10-24 23:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-24 23:03 [PATCH v3 0/3] kvm: call kvm_arch_destroy_vm if vm creation fails Jim Mattson
2019-10-24 23:03 ` [PATCH v3 1/3] kvm: Don't clear reference count on kvm_create_vm() error path Jim Mattson
2019-10-24 23:15 ` Sean Christopherson
2019-10-24 23:03 ` [PATCH v3 2/3] kvm: Allocate memslots and buses before calling kvm_arch_init_vm Jim Mattson
2019-10-24 23:28 ` Sean Christopherson
2019-10-25 11:30 ` Paolo Bonzini
2019-10-24 23:03 ` [PATCH v3 3/3] kvm: call kvm_arch_destroy_vm if vm creation fails Jim Mattson
2019-10-24 23:29 ` Sean Christopherson [this message]
2019-10-25 11:37 ` Paolo Bonzini
2019-10-25 14:48 ` Sean Christopherson
2019-10-25 14:56 ` Paolo Bonzini
2019-10-25 15:22 ` Sean Christopherson
2019-10-25 15:23 ` Paolo Bonzini
2019-10-25 22:29 ` Sean Christopherson
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=20191024232943.GJ28043@linux.intel.com \
--to=sean.j.christopherson@intel.com \
--cc=jmattson@google.com \
--cc=jsperbeck@google.com \
--cc=junaids@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).