From patchwork Mon Jan 9 06:24:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9503849 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 51C2A6075F for ; Mon, 9 Jan 2017 06:28:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 423892811C for ; Mon, 9 Jan 2017 06:28:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32D8728335; Mon, 9 Jan 2017 06:28:56 +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=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable 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 CC5AD2815E for ; Mon, 9 Jan 2017 06:28:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S940269AbdAIG2S (ORCPT ); Mon, 9 Jan 2017 01:28:18 -0500 Received: from outprodmail01.cc.columbia.edu ([128.59.72.39]:38729 "EHLO outprodmail01.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939923AbdAIG0n (ORCPT ); Mon, 9 Jan 2017 01:26:43 -0500 Received: from hazelnut (hazelnut.cc.columbia.edu [128.59.213.250]) by outprodmail01.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096Q5jT017968 for ; Mon, 9 Jan 2017 01:26:39 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id ABD566D for ; Mon, 9 Jan 2017 01:26:39 -0500 (EST) Received: from sendprodmail02.cc.columbia.edu (sendprodmail02.cc.columbia.edu [128.59.72.14]) by hazelnut (Postfix) with ESMTP id 912806D for ; Mon, 9 Jan 2017 01:26:39 -0500 (EST) Received: from mail-qk0-f197.google.com (mail-qk0-f197.google.com [209.85.220.197]) by sendprodmail02.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096QdCA043217 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:26:39 -0500 Received: by mail-qk0-f197.google.com with SMTP id a195so63267807qkg.3 for ; Sun, 08 Jan 2017 22:26:39 -0800 (PST) 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=ZzAWwT3C4CtVW9JZHnUTdJZyiNOoKvPvHt0fuEqvvM0=; b=r2ZuX00WrmN+xpRMwXp8pxOFpHxoNbFo3H9OC2OCf6VIYo8iaU8iwhx5SU1jgEmHDe ziv59WVQGj8FR5xJ5X1oo4rTGGV9iWjbeSq76Yo/xs7Z9SvRjCyC5fL98JpI3RH6jp18 E3jvYMFYO35cpE65ZA0braAMCEtKzxw6mmgz7wAZQhyZ9QscSbL5kclGSD2OSsqvWvQ+ t1J44S3xknZDglpKcq3f4MI7gS/LGwmv1LvHIxAPbYPMR9Vhxe9l5dtkEg3p8sBppfxc r5I99D3Jg+XU8/Mkay64zH/LTd3QXAt3yShtCRHXh56Eh+ZnQz+CazL5M9Tu3TUND7hl ZIhQ== X-Gm-Message-State: AIkVDXJ6C5JaWDACUGvStGaEkg1HtHpI+xNQgQI/+dLnGJpObjo5a+NtqWtUjJ7n3Si25zHuSRuSKmWHJ3zvfOtYg6D/30cAxsocjlsqvByPDCNECuhWxfD8BqDwj97uC5Yn11Ib+Pi8x/8= X-Received: by 10.200.37.241 with SMTP id f46mr80570072qtf.164.1483943199226; Sun, 08 Jan 2017 22:26:39 -0800 (PST) X-Received: by 10.200.37.241 with SMTP id f46mr80570062qtf.164.1483943199069; Sun, 08 Jan 2017 22:26:39 -0800 (PST) Received: from jintack.cs.columbia.edu ([2001:18d8:ffff:16:21a:4aff:feaa:f900]) by smtp.gmail.com with ESMTPSA id h3sm8623257qtc.6.2017.01.08.22.26.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Jan 2017 22:26:38 -0800 (PST) From: Jintack Lim To: christoffer.dall@linaro.org, marc.zyngier@arm.com, pbonzini@redhat.com, rkrcmar@redhat.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, vladimir.murzin@arm.com, suzuki.poulose@arm.com, mark.rutland@arm.com, james.morse@arm.com, lorenzo.pieralisi@arm.com, kevin.brodsky@arm.com, wcohen@redhat.com, shankerd@codeaurora.org, geoff@infradead.org, andre.przywara@arm.com, eric.auger@redhat.com, anna-maria@linutronix.de, shihwei@cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jintack@cs.columbia.edu Subject: [RFC 54/55] KVM: arm/arm64: Adjust virtual offset considering nesting Date: Mon, 9 Jan 2017 01:24:50 -0500 Message-Id: <1483943091-1364-55-git-send-email-jintack@cs.columbia.edu> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1483943091-1364-1-git-send-email-jintack@cs.columbia.edu> References: <1483943091-1364-1-git-send-email-jintack@cs.columbia.edu> X-No-Spam-Score: Local X-Scanned-By: MIMEDefang 2.78 on 128.59.72.14 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The guest hypervisor sets cntvoff_el2 for its VM (i.e. nested VM). Note that physical/virtual counter value in the guest hypervisor's point of view is already offsetted by the virtual offset set by the host hypervisor. Therefore, the correct offset we need to write to the cntvoff_el2 is the sum of offset the host hypervisor initially has for the VM and virtual offset the guest hypervisor sets for the nested VM. Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_emulate.h | 6 ++++++ arch/arm64/include/asm/kvm_emulate.h | 6 ++++++ virt/kvm/arm/arch_timer.c | 3 ++- virt/kvm/arm/hyp/timer-sr.c | 5 ++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/kvm_emulate.h b/arch/arm/include/asm/kvm_emulate.h index dde5335..c7a690f 100644 --- a/arch/arm/include/asm/kvm_emulate.h +++ b/arch/arm/include/asm/kvm_emulate.h @@ -324,4 +324,10 @@ static inline bool kvm_is_shadow_s2_fault(struct kvm_vcpu *vcpu) return false; } +/* Return the guest hypervisor's cntvoff value */ +static inline u64 kvm_get_vcntvoff(struct kvm_vcpu *vcpu) +{ + return 0; +} + #endif /* __ARM_KVM_EMULATE_H__ */ diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h index 17f4855..0aaa4ca 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -385,4 +385,10 @@ static inline bool kvm_is_shadow_s2_fault(struct kvm_vcpu *vcpu) #endif } +/* Return the guest hypervisor's cntvoff value */ +static inline u64 kvm_get_vcntvoff(struct kvm_vcpu *vcpu) +{ + return vcpu_el2_reg(vcpu, CNTVOFF_EL2); +} + #endif /* __ARM64_KVM_EMULATE_H__ */ diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index 7a161f8..e393939 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -102,7 +103,7 @@ static u64 kvm_timer_cntvoff(struct kvm_vcpu *vcpu, struct arch_timer_context *timer_ctx) { if (timer_ctx == vcpu_vtimer(vcpu)) - return vcpu->kvm->arch.timer.cntvoff; + return vcpu->kvm->arch.timer.cntvoff + kvm_get_vcntvoff(vcpu); return 0; } diff --git a/virt/kvm/arm/hyp/timer-sr.c b/virt/kvm/arm/hyp/timer-sr.c index 4bbd36c..66dab01 100644 --- a/virt/kvm/arm/hyp/timer-sr.c +++ b/virt/kvm/arm/hyp/timer-sr.c @@ -20,6 +20,7 @@ #include #include +#include /* vcpu is already in the HYP VA space */ void __hyp_text __timer_save_state(struct kvm_vcpu *vcpu) @@ -49,6 +50,7 @@ void __hyp_text __timer_restore_state(struct kvm_vcpu *vcpu) struct kvm *kvm = kern_hyp_va(vcpu->kvm); struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); u64 val; + u64 cntvoff; /* * Disallow physical timer access for the guest @@ -60,7 +62,8 @@ void __hyp_text __timer_restore_state(struct kvm_vcpu *vcpu) write_sysreg(val, cnthctl_el2); if (vtimer->enabled) { - write_sysreg(kvm->arch.timer.cntvoff, cntvoff_el2); + cntvoff = kvm->arch.timer.cntvoff + kvm_get_vcntvoff(vcpu); + write_sysreg(cntvoff, cntvoff_el2); write_sysreg_el0(vtimer->cnt_cval, cntv_cval); isb(); write_sysreg_el0(vtimer->cnt_ctl, cntv_ctl);