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: 9504081 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 11BD86075F for ; Mon, 9 Jan 2017 06:42:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2F06280DE for ; Mon, 9 Jan 2017 06:42:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7BDB2811E; Mon, 9 Jan 2017 06:42:47 +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=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 73C432811C for ; Mon, 9 Jan 2017 06:42:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cQTfI-0005eF-SA; Mon, 09 Jan 2017 06:42:44 +0000 Received: from outprodmail02.cc.columbia.edu ([128.59.72.51]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cQTQ3-0002wg-7W for linux-arm-kernel@lists.infradead.org; Mon, 09 Jan 2017 06:27:05 +0000 Received: from hazelnut (hazelnut.cc.columbia.edu [128.59.213.250]) by outprodmail02.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096Q5fY006218 for ; Mon, 9 Jan 2017 01:26:39 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id BE59982 for ; Mon, 9 Jan 2017 01:26:39 -0500 (EST) Received: from sendprodmail04.cc.columbia.edu (sendprodmail04.cc.columbia.edu [128.59.72.16]) by hazelnut (Postfix) with ESMTP id 9BCD182 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 sendprodmail04.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096QdSR005980 (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 d201so85780883qkg.2 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=awk4EPd6wakIcU1jfJQVaiWeiTQ8h5ZYkPNo7bPD+taD1p3efxR3I3Ec6HrOmjmV3/ J2x/klMjCRiOf+dBZR1+IAtrolmcvXUubFH/8NhqIMXiBErAi4EtSK9HGnLHrxKsRRTL fW3yF2nmmq+PMy6BLScVgs1DM7vfqAQejzhNQSQZsh3NcgfiWofVKcaYVuV7CyGbKN9o dbrgvm0UjNM1w1NAGmhPNiG4W6yk2GyrTOlYkxRVuS82yFjvhHgPOx4MFZufS+Hz0U+J 2889kqC25Ee1eFmfn3Wrc8UOkA8Cx5LDltZC10LFCk7OA0qi+RRbIFART+zefY31O8By nSHA== X-Gm-Message-State: AIkVDXLs0AEhv2fIiNXRFDY7O6SdSF44H5TIgfCLjUK8s4TkPWuD+FZiErsvPB8hPRr5He3uVsDfu7nASXFvu7dyAIPKqYiDfGnG4sc9w0oahDkEO3cmuaClGoQKXAtS3jw/vJop5Vi6I8i1qbVewdsX9LtdVbv/2RxPJw== X-Received: by 10.200.37.241 with SMTP id f46mr80570084qtf.164.1483943199229; 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 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.16 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170108_222700_697667_8CBD2682 X-CRM114-Status: GOOD ( 13.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jintack@cs.columbia.edu MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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);