From patchwork Wed Oct 28 20:42:38 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 56356 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 n9SKka8J006718 for ; Wed, 28 Oct 2009 20:46:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755603AbZJ1Uq2 (ORCPT ); Wed, 28 Oct 2009 16:46:28 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755569AbZJ1Uq2 (ORCPT ); Wed, 28 Oct 2009 16:46:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20524 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755566AbZJ1UqZ (ORCPT ); Wed, 28 Oct 2009 16:46:25 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9SKkUZu021306 for ; Wed, 28 Oct 2009 16:46:30 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9SKkT29021162; Wed, 28 Oct 2009 16:46:29 -0400 Received: from amt.cnet (vpn-10-90.str.redhat.com [10.32.10.90]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n9SKkRCE021106; Wed, 28 Oct 2009 16:46:28 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 461A958815B; Wed, 28 Oct 2009 18:45:15 -0200 (BRST) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id n9SKjD5O017738; Wed, 28 Oct 2009 18:45:13 -0200 Message-Id: <20091028204359.575032781@amt.cnet> User-Agent: quilt/0.47-1 Date: Wed, 28 Oct 2009 18:42:38 -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: <20091028204237.663479892@amt.cnet> Content-Disposition: inline; filename=irqchip-create X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 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,38 @@ 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; + 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;