From patchwork Thu Jun 8 13:34:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9775461 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 7EBED60350 for ; Thu, 8 Jun 2017 14:05:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CF8328543 for ; Thu, 8 Jun 2017 14:05:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F08528558; Thu, 8 Jun 2017 14:05:51 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E119028543 for ; Thu, 8 Jun 2017 14:05:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=bxzrwhfX9Rbqo2AGWLiC9qu31BB/VLL220VD3gY77Do=; b=Ixb9k8Sz4IBAEJ1sApHFvfJDhm cf3KX8D3WC6cH7D5/U5H4xrtIm0zwwHEvWatF8DAG8w7MDVte6/R+NXkLnilvq9PXi5NoblZuHf1O P1yC5mWATc1e2iL8LgwUQkVOxas+AtgMDl18hEKHQsZ2pUoiQkxz+5sM4cCODU7SVl2YjMnihnka4 LrX730J1zR0DKN5p356ldqr+ZmM269cDt6L9i9xiL5wAq3RXxD/3ZU05HSUmj7LJRAm+mbGdyIV2Z GSCquoGa8CoFxFePxOWRvAweEy0m8Xw+xg7X4XecnGMN3dd9EWtOyEOLZVQyRiIsaZex+KOBgCxi6 3s0rnjgg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dIy4K-0006DF-Jz; Thu, 08 Jun 2017 14:05:48 +0000 Received: from merlin.infradead.org ([205.233.59.134]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dIy49-0005xk-Ki for linux-arm-kernel@bombadil.infradead.org; Thu, 08 Jun 2017 14:05:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=GxKUZKnizKxfk9Hq8tz+qqPoubbvPBEqA7hQ8b/GsIA=; b=cW2YJnCbpY8QUiGHZ/lL4/3zt +esiCzKkXFl5bNfq92NU3ug0uNwxaIUK33w5VjTc33p9F9goLWBjE8rrCPXSvEMBdYWQ8NT4M2wvy i/xnBUptXTVStLN5cd0qWZzoEZCFHanBsHOBSdO57stP+qul+hRhiJ2+iSpgnzmKZihAduzw4NJnp j154zYh6ea92H4V1TdQ/xdtOCJ39frWL0catxLNYCeROBwTb5K3o+xnDRndi/cphthg3WKWYVlLgP /AUzAZO7wL+pD+ZZEoVrJzLWy31SrTNz1Jpw0X5oEgVhS2bWSCUryC5fU4uuIvAdPl1IVccbkWuQ1 Ie9oB9nww==; Received: from mail-wm0-f52.google.com ([74.125.82.52]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dIxbp-0006oD-Fg for linux-arm-kernel@lists.infradead.org; Thu, 08 Jun 2017 13:36:22 +0000 Received: by mail-wm0-f52.google.com with SMTP id x70so77672401wme.0 for ; Thu, 08 Jun 2017 06:36:01 -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=GxKUZKnizKxfk9Hq8tz+qqPoubbvPBEqA7hQ8b/GsIA=; b=UQHyvjNN5qYG0DULWe0FOV3SuPedCJmg4PaW3AnMVi5cvyBBYVqnKb2PZdbQJrHgaf 8k9xFjB3rfYYHdMPK6pDQdQQvvgTZ7k1qxGIirI02agc2zjudtl9U+dM2zyiJvwCMmpV YoH/M0CfxX3Zg60vX23dRjtJmWtjozdcD6PWI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GxKUZKnizKxfk9Hq8tz+qqPoubbvPBEqA7hQ8b/GsIA=; b=ulCVHZ0RGzeJInQeUUv0HQY3+kTHMU6HsyxuAN7XGeNbKobAkh9w260QjsN6cN5A/x b5Z+0dBbDAj3PYgDk/TIesVOfPUkey8CYcw8olkm9eonPVaHS9eSgrFpoC0p4C7Rxwm3 Q6TxPnHDMA0YmYxRzNDfrIJByyOaMjoWAjowOskpmM8Q7wOHVtCWBR7JFZPrhyeGKZzt FNMbuAFIKEEURZSxu/qBFZnsLLbGNAvXSMxyqfIkRoNQP1MCh+HlgFFkwKY+FIqX0fcR HS+Zj8kmvcVePwQ6gRllqBzb95+zJE2iop5BQVMQVydgYDi6ixFxqluCHbuKExjcqsFo y57Q== X-Gm-Message-State: AODbwcD6QI6lI5WfZJ46f376Y5ticEdhrVGp0Npte/YdlLd0EVGOWBZr zmdVrk6hz12cBg4FXfldpQ== X-Received: by 10.80.148.119 with SMTP id q52mr28892535eda.174.1496928899567; Thu, 08 Jun 2017 06:34:59 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id i38sm3981285eda.18.2017.06.08.06.34.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Jun 2017 06:34:58 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 9/9] KVM: arm/arm64: Don't assume initialized vgic when setting PMU IRQ Date: Thu, 8 Jun 2017 15:34:46 +0200 Message-Id: <20170608133446.3875-10-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170608133446.3875-1-cdall@linaro.org> References: <20170608133446.3875-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170608_093621_641356_C3C885CA X-CRM114-Status: GOOD ( 11.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier , Peter Maydell , kvm@vger.kernel.org, Christoffer Dall 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 The PMU IRQ number is set through the VCPU device's KVM_SET_DEVICE_ATTR ioctl handler for the KVM_ARM_VCPU_PMU_V3_IRQ attribute, but there is no enforced or stated requirement that this must happen after initializing the VGIC. As a result, calling vgic_valid_spi() which relies on the nr_spis being set during the VGIC init can incorrectly fail. Introduce irq_is_spi, which determines if an IRQ number is within the SPI range without verifying it against the actual VGIC properties. Signed-off-by: Christoffer Dall --- include/kvm/arm_vgic.h | 2 ++ virt/kvm/arm/pmu.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index 131668f..a2ae9d2 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -39,6 +39,8 @@ #define KVM_IRQCHIP_NUM_PINS (1020 - 32) #define irq_is_ppi(irq) ((irq) >= VGIC_NR_SGIS && (irq) < VGIC_NR_PRIVATE_IRQS) +#define irq_is_spi(irq) ((irq) >= VGIC_NR_PRIVATE_IRQS && \ + (irq) <= VGIC_MAX_SPI) enum vgic_type { VGIC_V2, /* Good ol' GICv2 */ diff --git a/virt/kvm/arm/pmu.c b/virt/kvm/arm/pmu.c index 26a42a9..87cb325 100644 --- a/virt/kvm/arm/pmu.c +++ b/virt/kvm/arm/pmu.c @@ -547,7 +547,7 @@ int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr) return -EFAULT; /* The PMU overflow interrupt can be a PPI or a valid SPI. */ - if (!(irq_is_ppi(irq) || vgic_valid_spi(vcpu->kvm, irq))) + if (!(irq_is_ppi(irq) || irq_is_spi(irq))) return -EINVAL; if (!pmu_irq_is_valid(vcpu->kvm, irq))