From patchwork Wed Jun 25 09:28:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 32464 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f200.google.com (mail-yk0-f200.google.com [209.85.160.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6014A20C88 for ; Wed, 25 Jun 2014 09:29:36 +0000 (UTC) Received: by mail-yk0-f200.google.com with SMTP id 20sf2299753yks.11 for ; Wed, 25 Jun 2014 02:29:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=XKra5y64rAp9tjQaqwnxkfR3Jnv7ltGNxymhI0WgjvE=; b=SYfdL3vBYzzjyh33vAqYNx73jJhj1Ug5PDvzhUbx2NQdRdOykji4FwG3BFkjxQQ1iu oiEbe55WzSLrwJvPR+AVgJbyeqt8WK0uy15dLxzY5OAVHcJ5KyT+i10beAfL+J7d2xu4 UsABQSeW4Cof/X9ufJ1/ZUC+GI/M1VSBSs0tFSMnBFGTx98keq29wPbqHEn7ryqjOQfo MKYxrjEECHkKSkWNV6MqWvfTjX6v6qPbZGzOyISz9pdbAf64o9tjsj/F4S8kdMBziIvy 7bzphiWr/rbJjEteOjnofSgy2sAKiaejZFxW9hY13jzEE6vlIml8gNOkVoYwl2VfR9HO EA2A== X-Gm-Message-State: ALoCoQkf3CpSpdVHcoVaUbZO/gMQo0oeRW3J2q/ziKNspExDpjW8tHE9/P3IHBKRxwxhOjP4RANg X-Received: by 10.58.19.227 with SMTP id i3mr3590581vee.2.1403688576187; Wed, 25 Jun 2014 02:29:36 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.105.54 with SMTP id b51ls2781726qgf.48.gmail; Wed, 25 Jun 2014 02:29:36 -0700 (PDT) X-Received: by 10.58.119.75 with SMTP id ks11mr5996466veb.20.1403688576107; Wed, 25 Jun 2014 02:29:36 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id n9si1901654vex.51.2014.06.25.02.29.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 25 Jun 2014 02:29:36 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id lf12so1586367vcb.4 for ; Wed, 25 Jun 2014 02:29:36 -0700 (PDT) X-Received: by 10.220.122.132 with SMTP id l4mr676208vcr.41.1403688576022; Wed, 25 Jun 2014 02:29:36 -0700 (PDT) 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.221.37.5 with SMTP id tc5csp274392vcb; Wed, 25 Jun 2014 02:29:35 -0700 (PDT) X-Received: by 10.66.141.76 with SMTP id rm12mr9931032pab.138.1403688575305; Wed, 25 Jun 2014 02:29:35 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ey6si4298534pab.138.2014.06.25.02.29.34; Wed, 25 Jun 2014 02:29:34 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755722AbaFYJ3Z (ORCPT + 27 others); Wed, 25 Jun 2014 05:29:25 -0400 Received: from fw-tnat.austin.arm.com ([217.140.110.23]:51407 "EHLO collaborate-mta1.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755523AbaFYJ3E (ORCPT ); Wed, 25 Jun 2014 05:29:04 -0400 Received: from e102391-lin.cambridge.arm.com (e102391-lin.cambridge.arm.com [10.1.209.143]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 61F5713FB65; Wed, 25 Jun 2014 04:29:03 -0500 (CDT) From: Marc Zyngier To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Will Deacon , Catalin Marinas , Thomas Gleixner , eric.auger@linaro.org, Christoffer Dall Subject: [RFC PATCH 9/9] KVM: arm: timer: make the interrupt state part of the timer state Date: Wed, 25 Jun 2014 10:28:50 +0100 Message-Id: <1403688530-23273-10-git-send-email-marc.zyngier@arm.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1403688530-23273-1-git-send-email-marc.zyngier@arm.com> References: <1403688530-23273-1-git-send-email-marc.zyngier@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: marc.zyngier@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 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 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , In order to remove the crude hack where we sneak the masked bit into the timer's control register, make use of the forwarded interrupt API to save/restore the active state of the interrupt. Signed-off-by: Marc Zyngier --- include/kvm/arm_arch_timer.h | 3 +++ virt/kvm/arm/arch_timer.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h index 6d9aedd..6a69f42 100644 --- a/include/kvm/arm_arch_timer.h +++ b/include/kvm/arm_arch_timer.h @@ -53,6 +53,9 @@ struct arch_timer_cpu { /* Background timer active */ bool armed; + /* Is interrupt active at the distributor level */ + u32 irq_active; + /* Timer IRQ */ const struct kvm_irq_level *irq; #endif diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index 22fa819..57817c5 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -63,7 +63,7 @@ static void kvm_timer_inject_irq(struct kvm_vcpu *vcpu) { struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; - timer->cntv_ctl |= ARCH_TIMER_CTRL_IT_MASK; + timer->irq_active = IRQ_FWD_STATE_ACTIVE; kvm_vgic_inject_irq(vcpu->kvm, vcpu->vcpu_id, timer->irq->irq, timer->irq->level); @@ -117,6 +117,16 @@ void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu) * populate the CPU timer again. */ timer_disarm(timer); + + if (timer->irq_active) { + int ret; + + ret = irq_set_fwd_state(host_vtimer_irq, + timer->irq_active, + IRQ_FWD_STATE_ACTIVE); + if (ret) + kvm_err("unable to restore timer state"); + } } /** @@ -130,8 +140,16 @@ void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu) { struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; cycle_t cval, now; + int ret; u64 ns; + ret = irq_get_fwd_state(host_vtimer_irq, &timer->irq_active, + IRQ_FWD_STATE_ACTIVE); + if (ret) + kvm_err("unable to retrieve timer state"); + if (timer->irq_active) + irq_set_fwd_state(host_vtimer_irq, 0, IRQ_FWD_STATE_ACTIVE); + if ((timer->cntv_ctl & ARCH_TIMER_CTRL_IT_MASK) || !(timer->cntv_ctl & ARCH_TIMER_CTRL_ENABLE)) return; @@ -166,6 +184,12 @@ void kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu, * vcpu timer irq number when the vcpu is reset. */ timer->irq = irq; + + /* + * Tell the VGIC that the virtual interrupt is tied to a + * physical interrupt. We do that once per VCPU. + */ + vgic_map_phys_irq(vcpu, irq->irq, host_vtimer_irq); } void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu) @@ -290,6 +314,10 @@ int kvm_timer_hyp_init(void) } kvm_info("%s IRQ%d\n", np->name, ppi); + + /* Tell the GIC we're forwarding the interrupt to a guest */ + irqd_set_irq_forwarded(irq_get_irq_data(host_vtimer_irq)); + on_each_cpu(kvm_timer_init_interrupt, NULL, 1); goto out; @@ -305,6 +333,7 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu) struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; timer_disarm(timer); + vgic_unmap_phys_irq(vcpu, timer->irq->irq, host_vtimer_irq); } int kvm_timer_init(struct kvm *kvm)