From patchwork Thu Oct 29 15:44:15 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 56481 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 n9TFmIHu015784 for ; Thu, 29 Oct 2009 15:48:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755370AbZJ2PsI (ORCPT ); Thu, 29 Oct 2009 11:48:08 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755399AbZJ2PsI (ORCPT ); Thu, 29 Oct 2009 11:48:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49835 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755372AbZJ2PsF (ORCPT ); Thu, 29 Oct 2009 11:48:05 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9TFmBZl007494 for ; Thu, 29 Oct 2009 11:48:11 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9TFmAOQ021377; Thu, 29 Oct 2009 11:48:10 -0400 Received: from amt.cnet (vpn-10-38.str.redhat.com [10.32.10.38]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n9TFm8mn003283; Thu, 29 Oct 2009 11:48:09 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id AEA59674076; Thu, 29 Oct 2009 13:46:41 -0200 (BRST) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id n9TFkeCe008789; Thu, 29 Oct 2009 13:46:40 -0200 Message-Id: <20091029154553.611799715@amt.cnet> User-Agent: quilt/0.47-1 Date: Thu, 29 Oct 2009 13:44:15 -0200 From: Marcelo Tosatti To: avi@redhat.com Cc: kvm@vger.kernel.org, mst@redhat.com, gleb@redhat.com, Marcelo Tosatti Subject: [patch 1/3] KVM: x86: disallow multiple KVM_CREATE_IRQCHIP References: <20091029154414.686484229@amt.cnet> Content-Disposition: inline; filename=irqchip-create X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Index: kvm/arch/x86/kvm/x86.c =================================================================== --- kvm.orig/arch/x86/kvm/x86.c +++ kvm/arch/x86/kvm/x86.c @@ -2362,25 +2362,39 @@ long kvm_arch_vm_ioctl(struct file *filp if (r) goto out; break; - case KVM_CREATE_IRQCHIP: + case KVM_CREATE_IRQCHIP: { + struct kvm_pic *vpic; + + mutex_lock(&kvm->lock); + r = -EEXIST; + if (kvm->arch.vpic) + goto create_irqchip_unlock; r = -ENOMEM; - kvm->arch.vpic = kvm_create_pic(kvm); - if (kvm->arch.vpic) { + vpic = kvm_create_pic(kvm); + if (vpic) { r = kvm_ioapic_init(kvm); if (r) { - kfree(kvm->arch.vpic); - kvm->arch.vpic = NULL; - goto out; + kfree(vpic); + goto create_irqchip_unlock; } } else - goto out; + goto create_irqchip_unlock; + smp_wmb(); + kvm->arch.vpic = vpic; + smp_wmb(); r = kvm_setup_default_irq_routing(kvm); if (r) { + mutex_lock(&kvm->irq_lock); kfree(kvm->arch.vpic); kfree(kvm->arch.vioapic); - goto out; + kvm->arch.vpic = NULL; + kvm->arch.vioapic = NULL; + mutex_unlock(&kvm->irq_lock); } + create_irqchip_unlock: + mutex_unlock(&kvm->lock); break; + } case KVM_CREATE_PIT: u.pit_config.flags = KVM_PIT_SPEAKER_DUMMY; goto create_pit; Index: kvm/arch/x86/kvm/irq.h =================================================================== --- kvm.orig/arch/x86/kvm/irq.h +++ kvm/arch/x86/kvm/irq.h @@ -86,7 +86,11 @@ static inline struct kvm_pic *pic_irqchi static inline int irqchip_in_kernel(struct kvm *kvm) { - return pic_irqchip(kvm) != NULL; + int ret; + + ret = (pic_irqchip(kvm) != NULL); + smp_rmb(); + return ret; } void kvm_pic_reset(struct kvm_kpic_state *s);