From patchwork Tue May 16 18:45:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9729515 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 2ED9360386 for ; Tue, 16 May 2017 18:47:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2123E1FFB9 for ; Tue, 16 May 2017 18:47:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 14A4F28631; Tue, 16 May 2017 18:47:42 +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=unavailable 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 B316A1FFB9 for ; Tue, 16 May 2017 18:47:41 +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=IvE0x75jvjYZzkfVn1gqgy5W1wATa1SGf2U5r3WKW0M=; b=fnd2UYQiKlLsmnWTgznt/Ns5mb /QKPtYxZltQQPxS7052FBL3rTkus0c/CNs1huXbfzknnXtoCl6K9TmuG1XfF1Tl1FPN85zILp09Kq Pq4K1bkgB6FIDevofqdrBSz9OOwruTFh7BcopauVVt9/VrD+/q+LZ9ajyZlr5Kev3KPIEzXONcy9o iTX03VkHU+K4gnS6HhEPtPoEB37cvYqla0CK+lpQ/y0I+QOCHwbqYqOc1gr1cH6Vh95jOkwgrqHjY hw+S4lqW003byznlmwAfp1QSimIgyjpBAFjvAglWagBVtVRDnNLZ9/12tKtlxg7ih6eZc2b5bW5z9 YsbGXQQA==; 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 1dAhVT-0003bB-DF; Tue, 16 May 2017 18:47:39 +0000 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dAhUZ-0002OR-2s for linux-arm-kernel@lists.infradead.org; Tue, 16 May 2017 18:46:46 +0000 Received: by mail-wm0-x229.google.com with SMTP id u65so131014711wmu.1 for ; Tue, 16 May 2017 11:46:24 -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=ek4lnkylpjgkunV560dO4/eBBLVBShYeUluTIInFFHs=; b=Vu/f/Hlq0aLgAV5f8WThT5kmIOc2tYRxuN/RSgogL/R7Fpk+Z4YEpn62lPsHUXMsfO hdAuk1I4L0wo8fSdAR+hu8c4A/jTNo/WfwYydgpjbF2OS2v/UY5s2zo2kS33tjIv8cJD EoESHn2Ilf3IiCLs4O2unYKmfB0uliXbDNk9g= 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=ek4lnkylpjgkunV560dO4/eBBLVBShYeUluTIInFFHs=; b=Rv1kGs2Il4IPnRBLc81Md7H1+cH9hDEZphQ2hfw33C1GI2HfILc2l6DVOPd9BF3nrb hemJtZtMg2n7m7lU56dau6e3vS4I2jm6FH0a3mmjKeNbWY1LGIINDdHLaHFRCkvH0Mxf Yhi19uV7JUXoEJKR5ZJxaa/QcyLe2zAXLMWvq5MsJtj4R7sdV81J+cYzBEWmgZCGkFmK rMrFmy2JVrx+x6/hgNWsSYNLGcWbRi/NCE6aPLvXjIA7rHga3Ww6HLt7CyXohQLLATo0 EcIFHqnqFfyV4TdKCJNyYWUfCe4QTYruRSLYO+IJNeBLbwJrKO1CMfsgwfWnUeveDf0k S90Q== X-Gm-Message-State: AODbwcBrem1QReNLA9Mrl7BmZ8pDKeScHBRMq7bzs5/kvawNziF4vZ0P D8bjvclg/EUDeeLB X-Received: by 10.80.161.71 with SMTP id 65mr79503edj.69.1494960383004; Tue, 16 May 2017 11:46:23 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id c2sm25102edc.34.2017.05.16.11.46.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 May 2017 11:46:22 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 7/9] KVM: arm/arm64: Check if irq lines to the GIC are already used Date: Tue, 16 May 2017 20:45:54 +0200 Message-Id: <20170516184556.26785-8-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170516184556.26785-1-cdall@linaro.org> References: <20170516184556.26785-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170516_114643_426028_F214DB46 X-CRM114-Status: GOOD ( 14.20 ) 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 , Christoffer Dall , Alexander Graf , kvm@vger.kernel.org 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 We check if other in-kernel devices have already been connected to the GIC for a particular interrupt line when possible. For the PMU, we can do this whenever setting the PMU interrupt number from userspace. For the timers, we have to wait until we try to enable the timer, because we have a concept of default IRQ numbers that userspace shouldn't have to work around in the initialization phase. Signed-off-by: Christoffer Dall --- virt/kvm/arm/arch_timer.c | 18 ++++++++++-------- virt/kvm/arm/pmu.c | 7 +++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index d3d1dce..528acf0 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -618,20 +618,22 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu) kvm_vgic_unmap_phys_irq(vcpu, vtimer->irq.irq); } -static bool timer_irqs_are_valid(struct kvm *kvm) +static bool timer_irqs_are_valid(struct kvm_vcpu *vcpu) { - struct kvm_vcpu *vcpu; int vtimer_irq, ptimer_irq; - int i; + int i, ret; - vcpu = kvm_get_vcpu(kvm, 0); vtimer_irq = vcpu_vtimer(vcpu)->irq.irq; - ptimer_irq = vcpu_ptimer(vcpu)->irq.irq; + ret = kvm_vgic_set_owner(vcpu, vtimer_irq, vcpu_vtimer(vcpu)); + if (ret) + return false; - if (vtimer_irq == ptimer_irq) + ptimer_irq = vcpu_ptimer(vcpu)->irq.irq; + ret = kvm_vgic_set_owner(vcpu, ptimer_irq, vcpu_ptimer(vcpu)); + if (ret) return false; - kvm_for_each_vcpu(i, vcpu, kvm) { + kvm_for_each_vcpu(i, vcpu, vcpu->kvm) { if (vcpu_vtimer(vcpu)->irq.irq != vtimer_irq || vcpu_ptimer(vcpu)->irq.irq != ptimer_irq) return false; @@ -659,7 +661,7 @@ int kvm_timer_enable(struct kvm_vcpu *vcpu) if (!vgic_initialized(vcpu->kvm)) return -ENODEV; - if (!timer_irqs_are_valid(vcpu->kvm)) { + if (!timer_irqs_are_valid(vcpu)) { kvm_debug("incorrectly configured timer irqs\n"); return -EINVAL; } diff --git a/virt/kvm/arm/pmu.c b/virt/kvm/arm/pmu.c index 0cf62b7..c354bd5 100644 --- a/virt/kvm/arm/pmu.c +++ b/virt/kvm/arm/pmu.c @@ -463,6 +463,8 @@ static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu) return -EBUSY; if (irqchip_in_kernel(vcpu->kvm)) { + int ret; + /* * If using the PMU with an in-kernel virtual GIC * implementation, we require the GIC to be already @@ -473,6 +475,11 @@ static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu) if (!kvm_arm_pmu_irq_initialized(vcpu)) return -ENXIO; + + ret = kvm_vgic_set_owner(vcpu, vcpu->arch.pmu.irq_num, + &vcpu->arch.pmu); + if (ret) + return ret; } kvm_pmu_vcpu_reset(vcpu);