From patchwork Tue Sep 27 18:05:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9352615 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9A4D8600CB for ; Tue, 27 Sep 2016 18:34:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F3FB292AA for ; Tue, 27 Sep 2016 18:34:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 837BC292B2; Tue, 27 Sep 2016 18:34:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 168CF292AA for ; Tue, 27 Sep 2016 18:34:59 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1boxC5-0005fv-K4; Tue, 27 Sep 2016 18:33:29 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1box1e-0005Gx-Ix for linux-arm-kernel@bombadil.infradead.org; Tue, 27 Sep 2016 18:22:42 +0000 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]) by merlin.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bowmQ-0008RF-BR for linux-arm-kernel@lists.infradead.org; Tue, 27 Sep 2016 18:06:58 +0000 Received: by mail-wm0-x22a.google.com with SMTP id w84so190379898wmg.1 for ; Tue, 27 Sep 2016 11:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3bRji74izhSENW2IOrEfQ2z9SqQZPI3xqnHCTJsOUD4=; b=VXR4+sf6JnSmzyvjPcSlXSscIElH8PHtydcPplqSc39qOa0nT6d4KB4v8f6zm/RltD Vjm43Rjx2QdG1m+XoOKyovWFxposCK4rr+fYiwZseCU9SIQnrGsZI84/5DVCetxnj3bT PfY4MqGnJQ14bDM5FcD1FhXdW2Y7QAPZaADxU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3bRji74izhSENW2IOrEfQ2z9SqQZPI3xqnHCTJsOUD4=; b=N9KsHSGbhMfpKCkPQ4UAULYsFp5OV7doRJa+bO2eWAUYYMOjThgt1NcFeJBHIyvpqX Ec/kJyHFI3BSsLY48Y8l28hnV5EOeZgjN2O7m/GnNw8SIqmVTbstWOQqIBF3R5K5qMv9 0PpzQRurIKhSMOH5rs/Js8T52Mpzaq1WyLM2FRmAwB86FQpV0XN3uZs2Qqn3pvN2oCjC xfgwZyyBQHVetcQB2Mu0Cutie4tTjoUYioc7DA3OoWzpaTMl9xRi266yfNjKWIzX7UAG VAKxADicVbAZYnWodEqs2hy7PB+N0w2KLhaK/JY5UBzx2w/Jnu5O5CaS0U9tOPbE7Qli txAQ== X-Gm-Message-State: AA6/9RlbvNE/YdgiXLyd0t4sKVrD8/15GkfDAIy1qikawF1vSx7IumWxLt1iHNSoTCwe0f3G X-Received: by 10.28.5.133 with SMTP id 127mr4087842wmf.128.1474999596157; Tue, 27 Sep 2016 11:06:36 -0700 (PDT) Received: from localhost.localdomain ([94.18.191.146]) by smtp.gmail.com with ESMTPSA id k2sm17932539wmg.23.2016.09.27.11.06.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Sep 2016 11:06:35 -0700 (PDT) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PULL 49/50] KVM: arm64: Require in-kernel irqchip for PMU support Date: Tue, 27 Sep 2016 20:05:57 +0200 Message-Id: <20160927180558.14699-50-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160927180558.14699-1-christoffer.dall@linaro.org> References: <20160927180558.14699-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160927_140658_524353_EC0EC44B X-CRM114-Status: GOOD ( 14.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, Marc Zyngier , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, Christoffer Dall , Shannon Zhao MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP If userspace creates a PMU for the VCPU, but doesn't create an in-kernel irqchip, then we end up in a nasty path where we try to take an uninitialized spinlock, which can lead to all sorts of breakages. Luckily, QEMU always creates the VGIC before the PMU, so we can establish this as ABI and check for the VGIC in the PMU init stage. This can be relaxed at a later time if we want to support PMU with a userspace irqchip. Cc: stable@vger.kernel.org Cc: Shannon Zhao Acked-by: Marc Zyngier Signed-off-by: Christoffer Dall --- Documentation/virtual/kvm/devices/vcpu.txt | 4 +++- virt/kvm/arm/pmu.c | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Documentation/virtual/kvm/devices/vcpu.txt b/Documentation/virtual/kvm/devices/vcpu.txt index c041658..02f5068 100644 --- a/Documentation/virtual/kvm/devices/vcpu.txt +++ b/Documentation/virtual/kvm/devices/vcpu.txt @@ -30,4 +30,6 @@ Returns: -ENODEV: PMUv3 not supported attribute -EBUSY: PMUv3 already initialized -Request the initialization of the PMUv3. +Request the initialization of the PMUv3. This must be done after creating the +in-kernel irqchip. Creating a PMU with a userspace irqchip is currently not +supported. diff --git a/virt/kvm/arm/pmu.c b/virt/kvm/arm/pmu.c index a027569..6e9c40e 100644 --- a/virt/kvm/arm/pmu.c +++ b/virt/kvm/arm/pmu.c @@ -423,6 +423,14 @@ static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu) if (!kvm_arm_support_pmu_v3()) return -ENODEV; + /* + * We currently require an in-kernel VGIC to use the PMU emulation, + * because we do not support forwarding PMU overflow interrupts to + * userspace yet. + */ + if (!irqchip_in_kernel(vcpu->kvm) || !vgic_initialized(vcpu->kvm)) + return -ENODEV; + if (!test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features) || !kvm_arm_pmu_irq_initialized(vcpu)) return -ENXIO;