Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751804AbdHALUh (ORCPT ); Tue, 1 Aug 2017 07:20:37 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:35805 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751166AbdHALUe (ORCPT ); Tue, 1 Aug 2017 07:20:34 -0400 Date: Tue, 1 Aug 2017 13:20:29 +0200 From: Christoffer Dall To: Jintack Lim Cc: kvmarm@lists.cs.columbia.edu, Christoffer Dall , Marc Zyngier , Jonathan Corbet , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , linux@armlinux.org.uk, Catalin Marinas , Will Deacon , akpm@linux-foundation.org, mchehab@kernel.org, cov@codeaurora.org, Daniel Lezcano , david.daney@cavium.com, mark.rutland@arm.com, Suzuki K Poulose , stefan@hello-penguin.com, Andy Gross , wcohen@redhat.com, Ard Biesheuvel , shankerd@codeaurora.org, vladimir.murzin@arm.com, james.morse@arm.com, linux-doc@vger.kernel.org, lkml - Kernel Mailing List , KVM General , arm-mail-list Subject: Re: [RFC PATCH v2 38/38] KVM: arm64: Respect the virtual CPTR_EL2.TCPAC setting Message-ID: <20170801112029.GD5176@cbox> References: <1500397144-16232-1-git-send-email-jintack.lim@linaro.org> <1500397144-16232-39-git-send-email-jintack.lim@linaro.org> <20170731125920.GX5176@cbox> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2360 Lines: 64 On Tue, Aug 01, 2017 at 07:03:35AM -0400, Jintack Lim wrote: > Hi Christoffer, > > On Mon, Jul 31, 2017 at 8:59 AM, Christoffer Dall wrote: > > On Tue, Jul 18, 2017 at 11:59:04AM -0500, Jintack Lim wrote: > >> Forward CPACR_EL1 traps to the virtual EL2 if virtual CPTR_EL2 is > >> configured to trap CPACR_EL1 accesses from EL1. > >> > >> This is for recursive nested virtualization. > >> > >> Signed-off-by: Jintack Lim > >> --- > >> arch/arm64/kvm/sys_regs.c | 5 +++++ > >> 1 file changed, 5 insertions(+) > >> > >> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > >> index 6f67666..ba2966d 100644 > >> --- a/arch/arm64/kvm/sys_regs.c > >> +++ b/arch/arm64/kvm/sys_regs.c > >> @@ -1091,6 +1091,11 @@ static bool access_cpacr(struct kvm_vcpu *vcpu, > >> if (el12_reg(p) && forward_nv_traps(vcpu)) > >> return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_hsr(vcpu)); > >> > >> + /* Forward this trap to the virtual EL2 if CPTR_EL2.TCPAC is set*/ > >> + if (!el12_reg(p) && !vcpu_mode_el2(vcpu) && > >> + (vcpu_sys_reg(vcpu, CPTR_EL2) & CPTR_EL2_TCPAC)) > >> + return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_hsr(vcpu)); > >> + > > > > I'm trying to understand what should happen if the VM is in EL1 and > > accesses CPACR_EL12, but the guest hypervisor did not set > > CPTR_EL2.TCPAC, why would we get here, and if there's a good reason why > > I guess what you meant is HCR_EL2.NV bit? > No, HCR_EL2.NV is set, then we obviously get here, due to traps on _EL12 registers. But if that wasn't the case (that's the time you'd be avaluating this if-statement), then you're checking as part of the if-statement if the virtual CPTR_EL2.TCPAC is set. My question is, if the virtual CPTR_EL2.TCPAC is not set, why would the physical one be set, which must be the case if we're running this code, right? > > we god here, is the EL12 access not supposed to undef at EL1 as opposed I obviously meant *got* here. > > to actually work, like it seems your code does when it doesn't take the > > branch? > > IIUC, we need to have this logic > > if (el12_reg() && virtual HCR_EL2.NV == 0) > inject_undef(); > > This is a good point, and should be applied for all traps controlled by NV bit. > Yes, but can this ever happen? Thanks, -Christoffer