From patchwork Thu Jun 8 13:34:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9775039 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 F0F0760393 for ; Thu, 8 Jun 2017 13:35:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2B2B26538 for ; Thu, 8 Jun 2017 13:35:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D77B827031; Thu, 8 Jun 2017 13:35:07 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F9EC26538 for ; Thu, 8 Jun 2017 13:35:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752422AbdFHNfF (ORCPT ); Thu, 8 Jun 2017 09:35:05 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:36733 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752247AbdFHNfD (ORCPT ); Thu, 8 Jun 2017 09:35:03 -0400 Received: by mail-wm0-f50.google.com with SMTP id 7so138097699wmo.1 for ; Thu, 08 Jun 2017 06:34:57 -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=DKyF3MRSs7SuL8+FcScqI0OZF6WiIEBWfRyK/eJqRP8=; b=FJ17mlPgcWSCwnTwRzcq8xvkDit1WRcOiEtg5GayEQD5RFUfI3XUbI17ecBBFjZBYL +mC+Q1bm/2E+tOefcWabGaHnNDX2vtMTqVseVob31PV1PqXGC/ueq0B7BHoVGObQtyqO UEhpl1EK26hwXi0k8I7D4jKNBoPQgZrvkrYGE= 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=DKyF3MRSs7SuL8+FcScqI0OZF6WiIEBWfRyK/eJqRP8=; b=eBbrNPr6z1LqZ+Yn3ToCC4Tjogr0NG2TM5u7LvyBZ8k2HIKWYDqRaGv6Mtk+T+Gc5M KR9GRM3S0pQIiixQIIPOVwKCADBthU1st3nMBOOm5OdMwuzcmYPUbWyhLLCh5zaU9gno Gh1DS8CY1osYWjIYgR0UMOKBEjnfHtwKiBnIPyXZrYSbgYCiyuhSSQMQyLeNenO+4/wC bJjqOMIx3vYZECqgiy94DEEaPGz+cxj6Hg4mWW2h1cOvxgwKsRL0Z6tlITfQ1eqyZDc/ 1Ckrl/m5Jr24ETpf51vSnCo/qzLaRjQjRc0udRO6O0ZTRYkVd8TqGv6bb0+NZR82niTG dF4Q== X-Gm-Message-State: AODbwcBVjZ/kg9Ho58FBhemb0my+r60oILR1hgb/+zpsXXkEJaJqr1Xn zNxa5Q+hxoCa+xaT0Y3KBg== X-Received: by 10.80.151.221 with SMTP id f29mr17184928edb.126.1496928897162; Thu, 08 Jun 2017 06:34:57 -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.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Jun 2017 06:34:55 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, Marc Zyngier , Peter Maydell , Christoffer Dall Subject: [PATCH v3 7/9] KVM: arm/arm64: Check if irq lines to the GIC are already used Date: Thu, 8 Jun 2017 15:34:44 +0200 Message-Id: <20170608133446.3875-8-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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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 Reviewed-by: Marc Zyngier --- 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 e03da1a..07f6f9b 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 574feff..3f08669 100644 --- a/virt/kvm/arm/pmu.c +++ b/virt/kvm/arm/pmu.c @@ -480,6 +480,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 @@ -490,6 +492,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; } vcpu->arch.pmu.created = true;