From patchwork Sat Dec 13 11:17:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 42210 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D1DB421772 for ; Sat, 13 Dec 2014 11:20:29 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id bs8sf2085054wib.6 for ; Sat, 13 Dec 2014 03:20:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=nlwxqTiNa/pjl6tEYNOmYYlGh08wbZwpagz+6r77XbA=; b=m5HZPree3JpKQnuN94ejw0LG7wZYoFMbxgamzxt0ct4v7h7o65Y8SoZlaiwYTgrIdC 1lSVcTDE/C3Rb9ouB8Ebw2HXarhYDq7jYtiUYB31PnrfdeJk2FxqYZOWLCUf89WrHbfm nf4mLhzra5aEZagh6puMoQPSSJdQnEAveaUOUAfkLjLoBqBSwyZkOqOLMQw6o98rhBEX jdJxaGampYZwYidoF4O4PxS0BZ3LqNrS5KxEMeR7+auuyXLhq9cgD6OxNRfA0rM81zkz Rr/pVbYOrZt55riZDDctttXWWRaGKnZ7SgV33eGHet5uq+gyDgi0/QwL1x4iRYgBtzcg HxDQ== X-Gm-Message-State: ALoCoQnVi0T+KGKODE2G3pPRupjJXhxBVkkNyk0K6/VdAdajYQ9a9F2ka+2yY3m2MhyF6+4lYdgI X-Received: by 10.112.204.71 with SMTP id kw7mr122887lbc.13.1418469629151; Sat, 13 Dec 2014 03:20:29 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.106 with SMTP id x10ls411253laj.58.gmail; Sat, 13 Dec 2014 03:20:28 -0800 (PST) X-Received: by 10.152.42.169 with SMTP id p9mr20147189lal.94.1418469628813; Sat, 13 Dec 2014 03:20:28 -0800 (PST) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id q2si3865986lbb.130.2014.12.13.03.20.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 13 Dec 2014 03:20:28 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by mail-la0-f44.google.com with SMTP id gd6so7367244lab.31 for ; Sat, 13 Dec 2014 03:20:28 -0800 (PST) X-Received: by 10.112.170.36 with SMTP id aj4mr20022023lbc.3.1418469628677; Sat, 13 Dec 2014 03:20:28 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.142.69 with SMTP id ru5csp232093lbb; Sat, 13 Dec 2014 03:20:27 -0800 (PST) X-Received: by 10.68.255.227 with SMTP id at3mr34746266pbd.40.1418469626867; Sat, 13 Dec 2014 03:20:26 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id op2si5778054pbb.76.2014.12.13.03.20.26 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Dec 2014 03:20:26 -0800 (PST) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Xzkil-0007EU-Qn; Sat, 13 Dec 2014 11:18:47 +0000 Received: from mail-lb0-f174.google.com ([209.85.217.174]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Xzkh2-0006HQ-5V for linux-arm-kernel@lists.infradead.org; Sat, 13 Dec 2014 11:17:01 +0000 Received: by mail-lb0-f174.google.com with SMTP id 10so7090566lbg.19 for ; Sat, 13 Dec 2014 03:16:38 -0800 (PST) X-Received: by 10.152.3.100 with SMTP id b4mr19438233lab.68.1418469398085; Sat, 13 Dec 2014 03:16:38 -0800 (PST) Received: from localhost.localdomain (188-178-240-98-static.dk.customer.tdc.net. [188.178.240.98]) by mx.google.com with ESMTPSA id b4sm1096765lbp.17.2014.12.13.03.16.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 13 Dec 2014 03:16:37 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 6/6] arm/arm64: KVM: Require in-kernel vgic for the arch timers Date: Sat, 13 Dec 2014 12:17:29 +0100 Message-Id: <1418469449-13277-7-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.1.2.330.g565301e.dirty In-Reply-To: <1418469449-13277-1-git-send-email-christoffer.dall@linaro.org> References: <1418469449-13277-1-git-send-email-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141213_031700_425398_9D74B057 X-CRM114-Status: GOOD ( 20.64 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.217.174 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.217.174 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Christoffer Dall , kvm@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: christoffer.dall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 It is curently possible to run a VM with architected timers support without creating an in-kernel VGIC, which will result in interrupts from the virtual timer going nowhere. To address this issue, move the architected timers initialization to the time when we run a VCPU for the first time, and then only initialize (and enable) the architected timers if we have a properly created and initialized in-kernel VGIC. When injecting interrupts from the virtual timer to the vgic, the current setup should ensure that this never calls an on-demand init of the VGIC, which is the only call path that could return an error from kvm_vgic_inject_irq(), so capture the return value and raise a warning if there's an error there. We also change the kvm_timer_init() function from returning an int to be a void function, since the function always succeeds. Signed-off-by: Christoffer Dall --- arch/arm/kvm/arm.c | 15 +++++++++++---- include/kvm/arm_arch_timer.h | 2 +- virt/kvm/arm/arch_timer.c | 15 ++++++++++----- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index d4da244..06f0431 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -127,8 +127,6 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) if (ret) goto out_free_stage2_pgd; - kvm_timer_init(kvm); - /* Mark the initial VMID generation invalid */ kvm->arch.vmid_gen = 0; @@ -424,6 +422,7 @@ static void update_vttbr(struct kvm *kvm) static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu) { + struct kvm *kvm = vcpu->kvm; int ret; if (likely(vcpu->arch.has_run_once)) @@ -435,12 +434,20 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu) * Map the VGIC hardware resources before running a vcpu the first * time on this VM. */ - if (unlikely(!vgic_ready(vcpu->kvm))) { - ret = kvm_vgic_map_resources(vcpu->kvm); + if (unlikely(!vgic_ready(kvm))) { + ret = kvm_vgic_map_resources(kvm); if (ret) return ret; } + /* + * Initialize the Architected Timers only if we have an in-kernel VGIC + * and it has been properly initialized, since we cannot handle + * interrupts from the virtual timer with a userspace vgic. + */ + if (irqchip_in_kernel(kvm) && vgic_initialized(kvm)) + kvm_timer_init(kvm); + return 0; } diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h index ad9db60..c9bd045 100644 --- a/include/kvm/arm_arch_timer.h +++ b/include/kvm/arm_arch_timer.h @@ -60,7 +60,7 @@ struct arch_timer_cpu { #ifdef CONFIG_KVM_ARM_TIMER int kvm_timer_hyp_init(void); -int kvm_timer_init(struct kvm *kvm); +void kvm_timer_init(struct kvm *kvm); void kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu, const struct kvm_irq_level *irq); void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu); diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index 22fa819..48ce5cb 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -61,12 +61,14 @@ static void timer_disarm(struct arch_timer_cpu *timer) static void kvm_timer_inject_irq(struct kvm_vcpu *vcpu) { + int ret; struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; timer->cntv_ctl |= ARCH_TIMER_CTRL_IT_MASK; - kvm_vgic_inject_irq(vcpu->kvm, vcpu->vcpu_id, - timer->irq->irq, - timer->irq->level); + ret = kvm_vgic_inject_irq(vcpu->kvm, vcpu->vcpu_id, + timer->irq->irq, + timer->irq->level); + WARN_ON(ret); } static irqreturn_t kvm_arch_timer_handler(int irq, void *dev_id) @@ -307,12 +309,15 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu) timer_disarm(timer); } -int kvm_timer_init(struct kvm *kvm) +void kvm_timer_init(struct kvm *kvm) { + if (kvm->arch.timer.enabled) + return; + if (timecounter && wqueue) { kvm->arch.timer.cntvoff = kvm_phys_timer_read(); kvm->arch.timer.enabled = 1; } - return 0; + return; }