From patchwork Fri Apr 26 07:21:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 2491181 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork2.kernel.org (Postfix) with ESMTP id 37060DF230 for ; Fri, 26 Apr 2013 07:30:18 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UVd6m-0006XU-F0; Fri, 26 Apr 2013 07:30:16 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UVd6j-0003q5-RJ; Fri, 26 Apr 2013 07:30:13 +0000 Received: from mail-pd0-f169.google.com ([209.85.192.169]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UVd6g-0003pj-Ij for linux-arm-kernel@lists.infradead.org; Fri, 26 Apr 2013 07:30:11 +0000 Received: by mail-pd0-f169.google.com with SMTP id 10so2314227pdc.28 for ; Fri, 26 Apr 2013 00:30:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=yIZG7hVtAwok735FHV9979uqFKwkx7ehneuZ2xgBldg=; b=Pza2nsCSx0ueMUTROyvaE/7zhLLxcCueywRfdw+/gMShcIsX4WEhIn1FO8DP4V2Jtm 0MkeiKVss2qEjaLXzHdrMKdCU0kzI56CoBTqrfkqW5GUUqsqY39HX9+EqoW+RxXkZX6s 3N18PHbnMvsQ59hWoffZhUt6NnLbKMxzLzf7q976Ol6TttLV+951rLGv+8rTakZDILGb 7gggjGJ+UBVJypXGhejmRziqt8dsbeDrqC3jkV7J1zCg0cjb2d/EXLFP/xqgl491hQpi W8SG9yoAaNZjTF2RUS7BTo52Qv4pEFk6/T6eKNzuiVclLmu6MvvNMAL2CcIgYKlIgl/R rhWQ== X-Received: by 10.68.252.201 with SMTP id zu9mr41227602pbc.119.1366960947762; Fri, 26 Apr 2013 00:22:27 -0700 (PDT) Received: from pnqlab006.amcc.com ([182.72.18.82]) by mx.google.com with ESMTPSA id z8sm10570216pbt.23.2013.04.26.00.22.24 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 26 Apr 2013 00:22:26 -0700 (PDT) From: Anup Patel To: kvmarm@lists.cs.columbia.edu Subject: [PATCH V2] ARM: KVM: Allow host virtual timer irq number to be different from guest virtual timer irq number Date: Fri, 26 Apr 2013 12:51:50 +0530 Message-Id: <1366960910-27651-1-git-send-email-anup.patel@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQlxtJdF66klv81Og6xpIbygvxH63fGL3E09Eu2bst3svmnZljkBAPvbs6r1TOvTKsN7awo5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130426_033010_700324_8856F92D X-CRM114-Status: GOOD ( 15.25 ) X-Spam-Score: 0.6 (/) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (0.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.192.169 listed in list.dnswl.org] 2.5 SUSPICIOUS_RECIPS Similar addresses in recipient list -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linaro-kernel@lists.linaro.org, Anup Patel , linux-arm-kernel@lists.infradead.org, Pranavkumar Sawargaonkar X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The arch_timer irq numbers (or PPI number) are implementation dependent so, the host virtual timer irq number can be different from guest virtual timer irq number. This patch ensures that host virtual timer irq number is read from DTB and guest virtual timer irq is determined based on guest vcpu target type. Signed-off-by: Pranavkumar Sawargaonkar --- arch/arm/include/asm/kvm_host.h | 1 + arch/arm/kvm/arch_timer.c | 25 ++++++++++++++++++------- arch/arm/kvm/guest.c | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 57cb786..cdc0551 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -43,6 +43,7 @@ struct kvm_vcpu; u32 *kvm_vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num, u32 mode); int kvm_target_cpu(void); +struct kvm_irq_level *kvm_target_timer_irq(struct kvm_vcpu *vcpu); int kvm_reset_vcpu(struct kvm_vcpu *vcpu); void kvm_reset_coprocs(struct kvm_vcpu *vcpu); diff --git a/arch/arm/kvm/arch_timer.c b/arch/arm/kvm/arch_timer.c index 49a7516..521cdb9 100644 --- a/arch/arm/kvm/arch_timer.c +++ b/arch/arm/kvm/arch_timer.c @@ -30,7 +30,7 @@ static struct timecounter *timecounter; static struct workqueue_struct *wqueue; -static struct kvm_irq_level timer_irq = { +static struct kvm_irq_level host_timer_irq = { .level = 1, }; @@ -65,10 +65,21 @@ static void kvm_timer_inject_irq(struct kvm_vcpu *vcpu) { struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; + /* + * The vcpu timer irq number cannont be determined in + * kvm_timer_vcpu_init() because it is called much before + * kvm_vcpu_set_target(). To handle this, we determin + * vcpu timer irq number when we inject the vcpu timer irq + * first time. + */ + if (!timer->irq) { + timer->irq = kvm_target_timer_irq(vcpu); + } + timer->cntv_ctl |= ARCH_TIMER_CTRL_IT_MASK; kvm_vgic_inject_irq(vcpu->kvm, vcpu->vcpu_id, - vcpu->arch.timer_cpu.irq->irq, - vcpu->arch.timer_cpu.irq->level); + timer->irq->irq, + timer->irq->level); } static irqreturn_t kvm_arch_timer_handler(int irq, void *dev_id) @@ -163,12 +174,12 @@ void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu) INIT_WORK(&timer->expired, kvm_timer_inject_irq_work); hrtimer_init(&timer->timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); timer->timer.function = kvm_timer_expire; - timer->irq = &timer_irq; + timer->irq = NULL; } static void kvm_timer_init_interrupt(void *info) { - enable_percpu_irq(timer_irq.irq, 0); + enable_percpu_irq(host_timer_irq.irq, 0); } @@ -182,7 +193,7 @@ static int kvm_timer_cpu_notify(struct notifier_block *self, break; case CPU_DYING: case CPU_DYING_FROZEN: - disable_percpu_irq(timer_irq.irq); + disable_percpu_irq(host_timer_irq.irq); break; } @@ -230,7 +241,7 @@ int kvm_timer_hyp_init(void) goto out; } - timer_irq.irq = ppi; + host_timer_irq.irq = ppi; err = register_cpu_notifier(&kvm_timer_cpu_nb); if (err) { diff --git a/arch/arm/kvm/guest.c b/arch/arm/kvm/guest.c index 152d036..d87b05d 100644 --- a/arch/arm/kvm/guest.c +++ b/arch/arm/kvm/guest.c @@ -36,6 +36,11 @@ struct kvm_stats_debugfs_item debugfs_entries[] = { { NULL } }; +struct kvm_irq_level target_default_timer_irq = { + .irq = 27, + .level = 1, +}; + int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) { return 0; @@ -197,6 +202,16 @@ int __attribute_const__ kvm_target_cpu(void) } } +struct kvm_irq_level *kvm_target_timer_irq(struct kvm_vcpu *vcpu) +{ + switch (vcpu->arch.target) { + case KVM_ARM_TARGET_CORTEX_A15: + return &target_default_timer_irq; + default: + return NULL; + }; +} + int kvm_vcpu_set_target(struct kvm_vcpu *vcpu, const struct kvm_vcpu_init *init) {