From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756646AbcCUPTU (ORCPT ); Mon, 21 Mar 2016 11:19:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44844 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756004AbcCUPTS (ORCPT ); Mon, 21 Mar 2016 11:19:18 -0400 Subject: Re: [PATCH] KVM: fix spin_lock_init order on x86 To: Eric Dumazet References: <1458552292-7405-1-git-send-email-pbonzini@redhat.com> <1458571635.10868.18.camel@edumazet-glaptop3.roam.corp.google.com> Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, bp@alien8.de From: Paolo Bonzini Message-ID: <56F010F2.3060306@redhat.com> Date: Mon, 21 Mar 2016 16:19:14 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <1458571635.10868.18.camel@edumazet-glaptop3.roam.corp.google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 21 Mar 2016 15:19:18 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21/03/2016 15:47, Eric Dumazet wrote: > On Mon, 2016-03-21 at 10:24 +0100, Paolo Bonzini wrote: >> kvm_arch_init_vm is now using mmu_lock, causing lockdep to >> complain: > ... >> >> Reported-by: Borislav Petkov >> Signed-off-by: Paolo Bonzini >> --- >> virt/kvm/kvm_main.c | 20 ++++++++++---------- >> 1 file changed, 10 insertions(+), 10 deletions(-) >> >> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c >> index 7ba1d10ffed2..cb45b86a1c48 100644 >> --- a/virt/kvm/kvm_main.c >> +++ b/virt/kvm/kvm_main.c >> @@ -536,6 +536,16 @@ static struct kvm *kvm_create_vm(unsigned long type) >> if (!kvm) >> return ERR_PTR(-ENOMEM); >> >> + spin_lock_init(&kvm->mmu_lock); >> + kvm->mm = current->mm; >> + atomic_inc(&kvm->mm->mm_count); > > current->mm->mm_count is incremented here. > >> + kvm_eventfd_init(kvm); >> + mutex_init(&kvm->lock); >> + mutex_init(&kvm->irq_lock); >> + mutex_init(&kvm->slots_lock); >> + atomic_set(&kvm->users_count, 1); >> + INIT_LIST_HEAD(&kvm->devices); >> + >> r = kvm_arch_init_vm(kvm, type); >> if (r) >> goto out_err_no_disable; > > > But out_err_no_disable wont decrement it in case of an error. > > This is not clear to me where the cleanup is done ? Indeed, a slightly more complex patch is necessary. Will try again, this time not doing this as the first thing in the morning. Paolo >> @@ -568,16 +578,6 @@ static struct kvm *kvm_create_vm(unsigned long type) >> goto out_err; >> } >> >> - spin_lock_init(&kvm->mmu_lock); >> - kvm->mm = current->mm; >> - atomic_inc(&kvm->mm->mm_count); >> - kvm_eventfd_init(kvm); >> - mutex_init(&kvm->lock); >> - mutex_init(&kvm->irq_lock); >> - mutex_init(&kvm->slots_lock); >> - atomic_set(&kvm->users_count, 1); >> - INIT_LIST_HEAD(&kvm->devices); >> - >> r = kvm_init_mmu_notifier(kvm); >> if (r) >> goto out_err; > >