kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86: KVM, fix lock imbalance
@ 2010-07-07 13:02 Jiri Slaby
  2010-07-07 13:05 ` Ingo Molnar
  0 siblings, 1 reply; 7+ messages in thread
From: Jiri Slaby @ 2010-07-07 13:02 UTC (permalink / raw)
  To: avi
  Cc: jirislaby, linux-kernel, Marcelo Tosatti, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin, x86, Gleb Natapov,
	Michael S. Tsirkin, Gregory Haskins, kvm

Stanse found that there is an omitted unlock in kvm_create_pit in one fail
path. Add proper unlock there.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Avi Kivity <avi@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Cc: Gleb Natapov <gleb@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Gregory Haskins <ghaskins@novell.com>
Cc: kvm@vger.kernel.org
---
 arch/x86/kvm/i8254.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
index 467cc47..70db4d4 100644
--- a/arch/x86/kvm/i8254.c
+++ b/arch/x86/kvm/i8254.c
@@ -696,6 +696,7 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
 
 	pit->wq = create_singlethread_workqueue("kvm-pit-wq");
 	if (!pit->wq) {
+		mutex_unlock(&pit->pit_state.lock);
 		kfree(pit);
 		return NULL;
 	}
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] x86: KVM, fix lock imbalance
  2010-07-07 13:02 [PATCH] x86: KVM, fix lock imbalance Jiri Slaby
@ 2010-07-07 13:05 ` Ingo Molnar
  2010-07-07 13:07   ` Jiri Slaby
  0 siblings, 1 reply; 7+ messages in thread
From: Ingo Molnar @ 2010-07-07 13:05 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: avi, linux-kernel, Marcelo Tosatti, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, x86, Gleb Natapov, Michael S. Tsirkin,
	Gregory Haskins, kvm


* Jiri Slaby <jirislaby@gmail.com> wrote:

> Stanse found that there is an omitted unlock in kvm_create_pit in one fail
> path. Add proper unlock there.
> 
> Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
> Cc: Avi Kivity <avi@redhat.com>
> Cc: Marcelo Tosatti <mtosatti@redhat.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: x86@kernel.org
> Cc: Gleb Natapov <gleb@redhat.com>
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> Cc: Gregory Haskins <ghaskins@novell.com>
> Cc: kvm@vger.kernel.org
> ---
>  arch/x86/kvm/i8254.c |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
> index 467cc47..70db4d4 100644
> --- a/arch/x86/kvm/i8254.c
> +++ b/arch/x86/kvm/i8254.c
> @@ -696,6 +696,7 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
>  
>  	pit->wq = create_singlethread_workqueue("kvm-pit-wq");
>  	if (!pit->wq) {
> +		mutex_unlock(&pit->pit_state.lock);
>  		kfree(pit);
>  		return NULL;
>  	}

A cleanliness comment: why is that tear-down/dealloc sequence open-coded? It 
should be at the end of the function, with goto labels, like we do it in 
similar cases.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] x86: KVM, fix lock imbalance
  2010-07-07 13:05 ` Ingo Molnar
@ 2010-07-07 13:07   ` Jiri Slaby
  2010-07-07 13:12     ` Jiri Slaby
  2010-07-07 13:21     ` Avi Kivity
  0 siblings, 2 replies; 7+ messages in thread
From: Jiri Slaby @ 2010-07-07 13:07 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: avi, linux-kernel, Marcelo Tosatti, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, x86, Gleb Natapov, Michael S. Tsirkin,
	Gregory Haskins, kvm

On 07/07/2010 03:05 PM, Ingo Molnar wrote:
> 
> * Jiri Slaby <jirislaby@gmail.com> wrote:
> 
>> Stanse found that there is an omitted unlock in kvm_create_pit in one fail
>> path. Add proper unlock there.
>>
>> Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
>> Cc: Avi Kivity <avi@redhat.com>
>> Cc: Marcelo Tosatti <mtosatti@redhat.com>
>> Cc: Thomas Gleixner <tglx@linutronix.de>
>> Cc: Ingo Molnar <mingo@redhat.com>
>> Cc: "H. Peter Anvin" <hpa@zytor.com>
>> Cc: x86@kernel.org
>> Cc: Gleb Natapov <gleb@redhat.com>
>> Cc: "Michael S. Tsirkin" <mst@redhat.com>
>> Cc: Gregory Haskins <ghaskins@novell.com>
>> Cc: kvm@vger.kernel.org
>> ---
>>  arch/x86/kvm/i8254.c |    1 +
>>  1 files changed, 1 insertions(+), 0 deletions(-)
>>
>> diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
>> index 467cc47..70db4d4 100644
>> --- a/arch/x86/kvm/i8254.c
>> +++ b/arch/x86/kvm/i8254.c
>> @@ -696,6 +696,7 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
>>  
>>  	pit->wq = create_singlethread_workqueue("kvm-pit-wq");
>>  	if (!pit->wq) {
>> +		mutex_unlock(&pit->pit_state.lock);
>>  		kfree(pit);
>>  		return NULL;
>>  	}
> 
> A cleanliness comment: why is that tear-down/dealloc sequence open-coded? It 
> should be at the end of the function, with goto labels, like we do it in 
> similar cases.

Because the lock is around a block only. I usually don't create a goto
fail-paths in these cases. Do you want one?

thanks,
-- 
js

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] x86: KVM, fix lock imbalance
  2010-07-07 13:07   ` Jiri Slaby
@ 2010-07-07 13:12     ` Jiri Slaby
  2010-07-07 13:21     ` Avi Kivity
  1 sibling, 0 replies; 7+ messages in thread
From: Jiri Slaby @ 2010-07-07 13:12 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: avi, linux-kernel, Marcelo Tosatti, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, x86, Gleb Natapov, Michael S. Tsirkin,
	Gregory Haskins, kvm

On 07/07/2010 03:07 PM, Jiri Slaby wrote:
>>> --- a/arch/x86/kvm/i8254.c
>>> +++ b/arch/x86/kvm/i8254.c
>>> @@ -696,6 +696,7 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
>>>  
>>>  	pit->wq = create_singlethread_workqueue("kvm-pit-wq");
>>>  	if (!pit->wq) {
>>> +		mutex_unlock(&pit->pit_state.lock);
>>>  		kfree(pit);
>>>  		return NULL;
>>>  	}
>>
>> A cleanliness comment: why is that tear-down/dealloc sequence open-coded? It 
>> should be at the end of the function, with goto labels, like we do it in 
>> similar cases.
> 
> Because the lock is around a block only. I usually don't create a goto
> fail-paths in these cases.

To be more precise what I mean by that:
if ()
  return;

lock();
...
if () { [single if inside the crit section]
  unlock();
  return;
}
...
unlock()

...
if ()
  return;
...
if ()
  return;

-- 
js

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] x86: KVM, fix lock imbalance
  2010-07-07 13:07   ` Jiri Slaby
  2010-07-07 13:12     ` Jiri Slaby
@ 2010-07-07 13:21     ` Avi Kivity
  2010-07-07 14:10       ` Ingo Molnar
  1 sibling, 1 reply; 7+ messages in thread
From: Avi Kivity @ 2010-07-07 13:21 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: Ingo Molnar, linux-kernel, Marcelo Tosatti, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin, x86, Gleb Natapov,
	Michael S. Tsirkin, Gregory Haskins, kvm

On 07/07/2010 04:07 PM, Jiri Slaby wrote:
>
>> A cleanliness comment: why is that tear-down/dealloc sequence open-coded? It
>> should be at the end of the function, with goto labels, like we do it in
>> similar cases.
>>      
> Because the lock is around a block only. I usually don't create a goto
> fail-paths in these cases. Do you want one?
>    

In any case, the patch is a minimal fix, so I'll apply it.  Any clean 
ups can go on top.

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] x86: KVM, fix lock imbalance
  2010-07-07 13:21     ` Avi Kivity
@ 2010-07-07 14:10       ` Ingo Molnar
  2010-07-07 14:14         ` Avi Kivity
  0 siblings, 1 reply; 7+ messages in thread
From: Ingo Molnar @ 2010-07-07 14:10 UTC (permalink / raw)
  To: Avi Kivity
  Cc: Jiri Slaby, linux-kernel, Marcelo Tosatti, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin, x86, Gleb Natapov,
	Michael S. Tsirkin, Gregory Haskins, kvm


* Avi Kivity <avi@redhat.com> wrote:

> On 07/07/2010 04:07 PM, Jiri Slaby wrote:
> >
> >>A cleanliness comment: why is that tear-down/dealloc sequence open-coded? It
> >>should be at the end of the function, with goto labels, like we do it in
> >>similar cases.
> >Because the lock is around a block only. I usually don't create a goto
> >fail-paths in these cases. Do you want one?
> 
> In any case, the patch is a minimal fix, so I'll apply it.  Any clean ups 
> can go on top.

The reason the pattern caught my attention is that it is one of the typical 
cases where goto labels help prevent similar bugs. I.e. had it been clean to 
begin with the bug might not have happened.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] x86: KVM, fix lock imbalance
  2010-07-07 14:10       ` Ingo Molnar
@ 2010-07-07 14:14         ` Avi Kivity
  0 siblings, 0 replies; 7+ messages in thread
From: Avi Kivity @ 2010-07-07 14:14 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Jiri Slaby, linux-kernel, Marcelo Tosatti, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin, x86, Gleb Natapov,
	Michael S. Tsirkin, Gregory Haskins, kvm

On 07/07/2010 05:10 PM, Ingo Molnar wrote:
>
>> In any case, the patch is a minimal fix, so I'll apply it.  Any clean ups
>> can go on top.
>>      
> The reason the pattern caught my attention is that it is one of the typical
> cases where goto labels help prevent similar bugs. I.e. had it been clean to
> begin with the bug might not have happened.
>    

Agreed.

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-07-07 14:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-07 13:02 [PATCH] x86: KVM, fix lock imbalance Jiri Slaby
2010-07-07 13:05 ` Ingo Molnar
2010-07-07 13:07   ` Jiri Slaby
2010-07-07 13:12     ` Jiri Slaby
2010-07-07 13:21     ` Avi Kivity
2010-07-07 14:10       ` Ingo Molnar
2010-07-07 14:14         ` Avi Kivity

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).