public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Gregory Haskins <gregory.haskins@gmail.com>
To: Gleb Natapov <gleb@redhat.com>
Cc: kvm@vger.kernel.org, avi@redhat.com, mtosatti@redhat.com
Subject: Re: [PATCH 1/5] Protect irq_sources_bitmap by kvm->lock instead of kvm->irq_lock
Date: Mon, 13 Jul 2009 10:29:02 -0400	[thread overview]
Message-ID: <4A5B44AE.4000407@gmail.com> (raw)
In-Reply-To: <1247476355-27284-2-git-send-email-gleb@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2676 bytes --]

Gleb Natapov wrote:
> It is already protected by kvm->lock on device assignment path. Just
> take the same lock in the PIT code.
>
> Signed-off-by: Gleb Natapov <gleb@redhat.com>
> ---
>  arch/x86/kvm/i8254.c |    2 ++
>  virt/kvm/irq_comm.c  |    8 ++++----
>  2 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
> index 05e00a8..e1b9016 100644
> --- a/arch/x86/kvm/i8254.c
> +++ b/arch/x86/kvm/i8254.c
> @@ -596,7 +596,9 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
>  	if (!pit)
>  		return NULL;
>  
> +	mutex_lock(&kvm->lock);
>  	pit->irq_source_id = kvm_request_irq_source_id(kvm);
> +	mutex_unlock(&kvm->lock);
>  	if (pit->irq_source_id < 0) {
>  		kfree(pit);
>  		return NULL;
> diff --git a/virt/kvm/irq_comm.c b/virt/kvm/irq_comm.c
> index 6c57e46..ce8fcd3 100644
> --- a/virt/kvm/irq_comm.c
> +++ b/virt/kvm/irq_comm.c
> @@ -210,7 +210,8 @@ int kvm_request_irq_source_id(struct kvm *kvm)
>  	unsigned long *bitmap = &kvm->arch.irq_sources_bitmap;
>  	int irq_source_id;
>  
> -	mutex_lock(&kvm->irq_lock);
> +	WARN_ON(!mutex_is_locked(&kvm->lock));
>   

Shouldn't this be fatal?  (e.g. BUG_ON).  I know the usage between
BUG/WARN is controversial, but it seems to me that something is
completely broken if you expect it to be locked and its not.  Might as
well fail the system, IMO.

Regards,
-Greg

> +
>  	irq_source_id = find_first_zero_bit(bitmap,
>  				sizeof(kvm->arch.irq_sources_bitmap));
>  
> @@ -221,7 +222,6 @@ int kvm_request_irq_source_id(struct kvm *kvm)
>  
>  	ASSERT(irq_source_id != KVM_USERSPACE_IRQ_SOURCE_ID);
>  	set_bit(irq_source_id, bitmap);
> -	mutex_unlock(&kvm->irq_lock);
>  
>  	return irq_source_id;
>  }
> @@ -230,9 +230,10 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)
>  {
>  	int i;
>  
> +	/* during vm destruction this function is called without locking */
> +	WARN_ON(!mutex_is_locked(&kvm->lock) && atomic_read(&kvm->users_count));
>  	ASSERT(irq_source_id != KVM_USERSPACE_IRQ_SOURCE_ID);
>  
> -	mutex_lock(&kvm->irq_lock);
>  	if (irq_source_id < 0 ||
>  	    irq_source_id >= sizeof(kvm->arch.irq_sources_bitmap)) {
>  		printk(KERN_ERR "kvm: IRQ source ID out of range!\n");
> @@ -241,7 +242,6 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)
>  	for (i = 0; i < KVM_IOAPIC_NUM_PINS; i++)
>  		clear_bit(irq_source_id, &kvm->arch.irq_states[i]);
>  	clear_bit(irq_source_id, &kvm->arch.irq_sources_bitmap);
> -	mutex_unlock(&kvm->irq_lock);
>  }
>  
>  void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
>   



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 266 bytes --]

  reply	other threads:[~2009-07-13 14:29 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-13  9:12 [PATCH 0/5][RFC] more fine grained locking for IRQ injection Gleb Natapov
2009-07-13  9:12 ` [PATCH 1/5] Protect irq_sources_bitmap by kvm->lock instead of kvm->irq_lock Gleb Natapov
2009-07-13 14:29   ` Gregory Haskins [this message]
2009-07-13 14:39     ` Gleb Natapov
2009-07-13 14:55       ` Michael S. Tsirkin
2009-07-13 15:01         ` Gleb Natapov
2009-07-13 15:03       ` Gregory Haskins
2009-07-13 15:11         ` Gregory Haskins
2009-07-13 15:19         ` Gleb Natapov
2009-07-13  9:12 ` [PATCH 2/5] Move irq routing to its own locking Gleb Natapov
2009-07-13  9:12 ` [PATCH 3/5] Move irq notifiers lists " Gleb Natapov
2009-07-13 11:45   ` Michael S. Tsirkin
2009-07-13 11:48     ` Gleb Natapov
2009-07-13 14:23       ` Michael S. Tsirkin
2009-07-13 14:37         ` Gleb Natapov
2009-07-13 14:49           ` Michael S. Tsirkin
2009-07-13 15:23             ` Gleb Natapov
2009-07-13 15:32               ` Gregory Haskins
2009-07-13 15:40               ` Michael S. Tsirkin
2009-07-13 16:28                 ` Gleb Natapov
2009-07-13 16:23           ` Marcelo Tosatti
2009-07-13 16:31             ` Marcelo Tosatti
2009-07-13 16:35               ` Gleb Natapov
2009-07-13 16:43                 ` Marcelo Tosatti
2009-07-13  9:12 ` [PATCH 4/5] Move IO APIC to its own lock Gleb Natapov
2009-07-13  9:12 ` [PATCH 5/5] Drop kvm->irq_lock lock Gleb Natapov
2009-07-13 13:23 ` [PATCH 0/5][RFC] more fine grained locking for IRQ injection Michael S. Tsirkin
2009-07-13 13:28   ` Gleb Natapov
2009-07-13 13:53     ` Michael S. Tsirkin
2009-07-13 13:58       ` Gleb Natapov
2009-07-13 14:21         ` Michael S. Tsirkin
2009-07-13 14:33           ` Gleb Natapov
2009-07-13 14:43             ` Michael S. Tsirkin
2009-07-13 15:21               ` Gleb Natapov

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=4A5B44AE.4000407@gmail.com \
    --to=gregory.haskins@gmail.com \
    --cc=avi@redhat.com \
    --cc=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@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