From: Paolo Bonzini <pbonzini@redhat.com>
To: Wanpeng Li <kernellwp@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kvm <kvm@vger.kernel.org>,
"Radim Krčmář" <rkrcmar@redhat.com>,
"Sean Christopherson" <sean.j.christopherson@intel.com>,
"Vitaly Kuznetsov" <vkuznets@redhat.com>,
"Wanpeng Li" <wanpengli@tencent.com>,
"Jim Mattson" <jmattson@google.com>,
"Joerg Roedel" <joro@8bytes.org>
Subject: Re: [PATCH 2/2] KVM: Fix rcu splat if vm creation fails
Date: Mon, 4 Nov 2019 13:26:57 +0100 [thread overview]
Message-ID: <9e88b51b-9b37-3f14-8d98-0bb3ddbe6378@redhat.com> (raw)
In-Reply-To: <CANRm+CyLiP_EncGnpMug9hbJYO+hC0DT2a-p5mOKUKHnUadO9w@mail.gmail.com>
On 04/11/19 13:25, Wanpeng Li wrote:
> On Mon, 4 Nov 2019 at 20:21, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> On 04/11/19 13:16, Wanpeng Li wrote:
>>>> I don't understand this one, hasn't
>>>>
>>>> WARN_ON_ONCE(!refcount_dec_and_test(&kvm->users_count));
>>>>
>>>> decreased the conut already? With your patch the refcount would then
>>>> underflow.
>>>
>>> r = kvm_arch_init_vm(kvm, type);
>>> if (r)
>>> goto out_err_no_arch_destroy_vm;
>>>
>>> out_err_no_disable:
>>> kvm_arch_destroy_vm(kvm);
>>> WARN_ON_ONCE(!refcount_dec_and_test(&kvm->users_count));
>>> out_err_no_arch_destroy_vm:
>>>
>>> So, if kvm_arch_init_vm() fails, we will not execute
>>> WARN_ON_ONCE(!refcount_dec_and_test(&kvm->users_count));
>>
>> Uuh of course. But I'd rather do the opposite: move the refcount_set
>> earlier so that refcount_dec_and_test can be moved after
>> no_arch_destroy_vm. Moving the refcount_set is not strictly necessary,
>> but avoids the introduction of yet another label.
>>
>> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
>> index e22ff63e5b1a..e7a07132cd7f 100644
>> --- a/virt/kvm/kvm_main.c
>> +++ b/virt/kvm/kvm_main.c
>> @@ -650,6 +650,7 @@ static struct kvm *kvm_create_vm(unsigned long type)
>> if (init_srcu_struct(&kvm->irq_srcu))
>> goto out_err_no_irq_srcu;
>>
>> + refcount_set(&kvm->users_count, 1);
>> for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) {
>> struct kvm_memslots *slots = kvm_alloc_memslots();
>>
>> @@ -667,7 +668,6 @@ static struct kvm *kvm_create_vm(unsigned long type)
>> goto out_err_no_arch_destroy_vm;
>> }
>>
>> - refcount_set(&kvm->users_count, 1);
>> r = kvm_arch_init_vm(kvm, type);
>> if (r)
>> goto out_err_no_arch_destroy_vm;
>> @@ -696,8 +696,8 @@ static struct kvm *kvm_create_vm(unsigned long type)
>> hardware_disable_all();
>> out_err_no_disable:
>> kvm_arch_destroy_vm(kvm);
>> - WARN_ON_ONCE(!refcount_dec_and_test(&kvm->users_count));
>> out_err_no_arch_destroy_vm:
>> + WARN_ON_ONCE(!refcount_dec_and_test(&kvm->users_count));
>> for (i = 0; i < KVM_NR_BUSES; i++)
>> kfree(kvm_get_bus(kvm, i));
>> for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++)
>
> Good point, I will handle these two patches later.
No problem, I can send v2 after testing.
Paolo
next prev parent reply other threads:[~2019-11-04 12:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-04 6:27 [PATCH 1/2] KVM: Fix NULL-ptr defer after kvm_create_vm fails Wanpeng Li
2019-11-04 6:27 ` [PATCH 2/2] KVM: Fix rcu splat if vm creation fails Wanpeng Li
2019-11-04 11:18 ` Paolo Bonzini
2019-11-04 12:16 ` Wanpeng Li
2019-11-04 12:21 ` Paolo Bonzini
2019-11-04 12:25 ` Wanpeng Li
2019-11-04 12:26 ` Paolo Bonzini [this message]
2019-11-04 11:19 ` [PATCH 1/2] KVM: Fix NULL-ptr defer after kvm_create_vm fails Paolo Bonzini
2019-11-06 8:29 ` Christian Borntraeger
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=9e88b51b-9b37-3f14-8d98-0bb3ddbe6378@redhat.com \
--to=pbonzini@redhat.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kernellwp@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rkrcmar@redhat.com \
--cc=sean.j.christopherson@intel.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.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
all inboxes | Powered by JetHome®