From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christoffer Dall Subject: Re: [PATCH] KVM: arm/arm64: No need to zero CNTVOFF in kvm_timer_vcpu_put() for VHE Date: Thu, 22 Feb 2018 09:42:31 +0100 Message-ID: <20180222084231.GA29376@cbox> References: <1519054687-14405-1-git-send-email-shankerd@codeaurora.org> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Return-path: Content-Disposition: inline In-Reply-To: <1519054687-14405-1-git-send-email-shankerd@codeaurora.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=m.gmane.org@lists.infradead.org To: Shanker Donthineni Cc: Marc Zyngier , Vikram Sethi , linux-kernel , linux-arm-kernel , kvmarm List-Id: kvmarm@lists.cs.columbia.edu SGkgU2hhbmtlciwKCk9uIE1vbiwgRmViIDE5LCAyMDE4IGF0IDA5OjM4OjA3QU0gLTA2MDAsIFNo YW5rZXIgRG9udGhpbmVuaSB3cm90ZToKPiBJbiBBQXJjaDY0L0FBcmNoMzIsIHRoZSB2aXJ0dWFs IGNvdW50ZXIgdXNlcyBhIGZpeGVkIHZpcnR1YWwgb2Zmc2V0Cj4gb2YgemVybyBpbiB0aGUgZm9s bG93aW5nIHNpdHVhdGlvbnMgYXMgcGVyIEFSTXY4IHNwZWNpZmljYXRpb25zOgo+IAo+IDEpIEhD Ul9FTDIuRTJIIGlzIDEsIGFuZCBDTlRWQ1RfRUwwL0NOVFZDVCBhcmUgcmVhZCBmcm9tIEVMMi4K PiAyKSBIQ1JfRUwyLntFMkgsIFRHRX0gaXMgezEsIDF9LCBhbmQgZWl0aGVyOgo+ICAgIOKAlCBD TlRWQ1RfRUwwIGlzIHJlYWQgZnJvbSBOb24tc2VjdXJlIEVMMCBvciBFTDIuCj4gICAg4oCUIENO VFZDVCBpcyByZWFkIGZyb20gTm9uLXNlY3VyZSBFTDAuCj4gCj4gU28s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plcm8sIHNvIG5vIG5lZWQgdG8gemVybyBD TlRWT0ZGX0VMMiByZWdpc3Rlci4KPiAgCSAqLwo+IC0Jc2V0X2NudHZvZmYoMCk7Cj4gKwlpZiAo IWhhc192aGUoKSkKPiArCQlzZXRfY250dm9mZigwKTsKPiAgfQo+ICAKPiAgLyoKCkknbSBva2F5 IHdpdGggdGhpcyBjaGFuZ2UuICBJIGRvbid0IHRoaW5rIHRoZXJlJ3MgYSBodWdlIGdhaW4gaGVy ZQp0aG91Z2guCgpNYXJjLCBhbnkgdGhvdWdodHMgb3IgY29uY2VybnM/CgpUaGFua3MsCi1DaHJp c3RvZmZlcgoKX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18K bGludXgtYXJtLWtlcm5lbCBtYWlsaW5nIGxpc3QKbGludXgtYXJtLWtlcm5lbEBsaXN0cy5pbmZy YWRlYWQub3JnCmh0dHA6Ly9saXN0cy5pbmZyYWRlYWQub3JnL21haWxtYW4vbGlzdGluZm8vbGlu dXgtYXJtLWtlcm5lbAo= From mboxrd@z Thu Jan 1 00:00:00 1970 From: christoffer.dall@linaro.org (Christoffer Dall) Date: Thu, 22 Feb 2018 09:42:31 +0100 Subject: [PATCH] KVM: arm/arm64: No need to zero CNTVOFF in kvm_timer_vcpu_put() for VHE In-Reply-To: <1519054687-14405-1-git-send-email-shankerd@codeaurora.org> References: <1519054687-14405-1-git-send-email-shankerd@codeaurora.org> Message-ID: <20180222084231.GA29376@cbox> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org Hi Shanker, On Mon, Feb 19, 2018 at 09:38:07AM -0600, Shanker Donthineni wrote: > In AArch64/AArch32, the virtual counter uses a fixed virtual offset > of zero in the following situations as per ARMv8 specifications: > > 1) HCR_EL2.E2H is 1, and CNTVCT_EL0/CNTVCT are read from EL2. > 2) HCR_EL2.{E2H, TGE} is {1, 1}, and either: > ? CNTVCT_EL0 is read from Non-secure EL0 or EL2. > ? CNTVCT is read from Non-secure EL0. > > So, no need to zero CNTVOFF_EL2/CNTVOFF for VHE case. > > Signed-off-by: Shanker Donthineni > --- > virt/kvm/arm/arch_timer.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c > index 70268c0..86eca324 100644 > --- a/virt/kvm/arm/arch_timer.c > +++ b/virt/kvm/arm/arch_timer.c > @@ -541,9 +541,11 @@ void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu) > * The kernel may decide to run userspace after calling vcpu_put, so > * we reset cntvoff to 0 to ensure a consistent read between user > * accesses to the virtual counter and kernel access to the physical > - * counter. > + * counter of non-VHE case. For VHE, the virtual counter uses a fixed > + * virtual offset of zero, so no need to zero CNTVOFF_EL2 register. > */ > - set_cntvoff(0); > + if (!has_vhe()) > + set_cntvoff(0); > } > > /* I'm okay with this change. I don't think there's a huge gain here though. Marc, any thoughts or concerns? Thanks, -Christoffer From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752859AbeBVImg (ORCPT ); Thu, 22 Feb 2018 03:42:36 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:35387 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752765AbeBVIme (ORCPT ); Thu, 22 Feb 2018 03:42:34 -0500 X-Google-Smtp-Source: AH8x225no/ZWm9cTOL4rKZ3dZHHjx7n4AFESvWibPBYzn04JObgvmjoOOuyNFkP7m9raKm++nmABXQ== Date: Thu, 22 Feb 2018 09:42:31 +0100 From: Christoffer Dall To: Shanker Donthineni Cc: Marc Zyngier , linux-kernel , linux-arm-kernel , kvmarm , Vikram Sethi Subject: Re: [PATCH] KVM: arm/arm64: No need to zero CNTVOFF in kvm_timer_vcpu_put() for VHE Message-ID: <20180222084231.GA29376@cbox> References: <1519054687-14405-1-git-send-email-shankerd@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1519054687-14405-1-git-send-email-shankerd@codeaurora.org> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Shanker, On Mon, Feb 19, 2018 at 09:38:07AM -0600, Shanker Donthineni wrote: > In AArch64/AArch32, the virtual counter uses a fixed virtual offset > of zero in the following situations as per ARMv8 specifications: > > 1) HCR_EL2.E2H is 1, and CNTVCT_EL0/CNTVCT are read from EL2. > 2) HCR_EL2.{E2H, TGE} is {1, 1}, and either: > — CNTVCT_EL0 is read from Non-secure EL0 or EL2. > — CNTVCT is read from Non-secure EL0. > > So, no need to zero CNTVOFF_EL2/CNTVOFF for VHE case. > > Signed-off-by: Shanker Donthineni > --- > virt/kvm/arm/arch_timer.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c > index 70268c0..86eca324 100644 > --- a/virt/kvm/arm/arch_timer.c > +++ b/virt/kvm/arm/arch_timer.c > @@ -541,9 +541,11 @@ void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu) > * The kernel may decide to run userspace after calling vcpu_put, so > * we reset cntvoff to 0 to ensure a consistent read between user > * accesses to the virtual counter and kernel access to the physical > - * counter. > + * counter of non-VHE case. For VHE, the virtual counter uses a fixed > + * virtual offset of zero, so no need to zero CNTVOFF_EL2 register. > */ > - set_cntvoff(0); > + if (!has_vhe()) > + set_cntvoff(0); > } > > /* I'm okay with this change. I don't think there's a huge gain here though. Marc, any thoughts or concerns? Thanks, -Christoffer