From patchwork Tue Jul 14 14:30:40 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 35557 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n6EEVKVK013008 for ; Tue, 14 Jul 2009 14:31:22 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754922AbZGNObC (ORCPT ); Tue, 14 Jul 2009 10:31:02 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754909AbZGNObA (ORCPT ); Tue, 14 Jul 2009 10:31:00 -0400 Received: from mx2.redhat.com ([66.187.237.31]:40178 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754853AbZGNOat (ORCPT ); Tue, 14 Jul 2009 10:30:49 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n6EEUn0x028923 for ; Tue, 14 Jul 2009 10:30:49 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n6EEUmZQ020574; Tue, 14 Jul 2009 10:30:48 -0400 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n6EEUlKE005299; Tue, 14 Jul 2009 10:30:47 -0400 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id D9DB61336CE; Tue, 14 Jul 2009 17:30:45 +0300 (IDT) From: Gleb Natapov To: kvm@vger.kernel.org Cc: mtosatti@redhat.com Subject: [PATCH 05/10] Protect irq_sources_bitmap by kvm->lock instead of kvm->irq_lock Date: Tue, 14 Jul 2009 17:30:40 +0300 Message-Id: <1247581845-7625-6-git-send-email-gleb@redhat.com> In-Reply-To: <1247581845-7625-1-git-send-email-gleb@redhat.com> References: <1247581845-7625-1-git-send-email-gleb@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 --- 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 472653c..59021da 100644 --- a/arch/x86/kvm/i8254.c +++ b/arch/x86/kvm/i8254.c @@ -611,7 +611,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)); + 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,