Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752232AbdGaMmN (ORCPT ); Mon, 31 Jul 2017 08:42:13 -0400 Received: from mail-wm0-f44.google.com ([74.125.82.44]:38269 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750923AbdGaMmL (ORCPT ); Mon, 31 Jul 2017 08:42:11 -0400 Date: Mon, 31 Jul 2017 14:42:07 +0200 From: Christoffer Dall To: Jintack Lim Cc: kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com, corbet@lwn.net, pbonzini@redhat.com, rkrcmar@redhat.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, akpm@linux-foundation.org, mchehab@kernel.org, cov@codeaurora.org, daniel.lezcano@linaro.org, david.daney@cavium.com, mark.rutland@arm.com, suzuki.poulose@arm.com, stefan@hello-penguin.com, andy.gross@linaro.org, wcohen@redhat.com, ard.biesheuvel@linaro.org, shankerd@codeaurora.org, vladimir.murzin@arm.com, james.morse@arm.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [RFC PATCH v2 36/38] KVM: arm64: Respect virtual HCR_EL2.TVM and TRVM settings Message-ID: <20170731124207.GV5176@cbox> References: <1500397144-16232-1-git-send-email-jintack.lim@linaro.org> <1500397144-16232-37-git-send-email-jintack.lim@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1500397144-16232-37-git-send-email-jintack.lim@linaro.org> 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: 2477 Lines: 77 On Tue, Jul 18, 2017 at 11:59:02AM -0500, Jintack Lim wrote: > Forward the EL1 virtual memory register traps to the virtual EL2 if they > are not coming from the virtual EL2 and the virtual HCR_EL2.TVM or TRVM > bit is set. I noticed that all these recursive patches don't change how we program the physical HCR_EL2. Is that because we always respect the guest hypervisor's configuration of the virtual HCR_EL2 into the physical one when running the VM? If so, perhaps we should add a single sentence in the commit messages about that. > > This is for recursive nested virtualization. > > Signed-off-by: Jintack Lim > --- > arch/arm64/kvm/sys_regs.c | 24 ++++++++++++++++++++++++ > 1 file changed, 24 insertions(+) > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index 3559cf7..3e4ec5e 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -135,6 +135,27 @@ static inline bool el12_reg(struct sys_reg_params *p) > return (p->Op1 == 5); > } > > +/* This function is to support the recursive nested virtualization */ it's just 'recursive nested virtualization', not 'the recursive nested virtualization', and I also think 'recursive virtualization' is sufficient. > +static bool forward_vm_traps(struct kvm_vcpu *vcpu, struct sys_reg_params *p) > +{ > + u64 hcr_el2 = vcpu_sys_reg(vcpu, HCR_EL2); > + > + /* If a trap comes from the virtual EL2, the host hypervisor handles. */ > + if (vcpu_mode_el2(vcpu)) > + return false; > + > + /* > + * If the virtual HCR_EL2.TVM or TRVM bit is set, we need to foward > + * this trap to the virtual EL2. > + */ > + if ((hcr_el2 & HCR_TVM) && p->is_write) > + return true; > + else if ((hcr_el2 & HCR_TRVM) && !p->is_write) > + return true; > + > + return false; > +} > + > /* > * Generic accessor for VM registers. Only called as long as HCR_TVM > * is set. If the guest enables the MMU, we stop trapping the VM > @@ -152,6 +173,9 @@ static bool access_vm_reg(struct kvm_vcpu *vcpu, > if (el12_reg(p) && forward_nv_traps(vcpu)) > return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_hsr(vcpu)); > > + if (!el12_reg(p) && forward_vm_traps(vcpu, p)) > + return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_hsr(vcpu)); why do you need the !el12_reg(p) check here? > + > /* > * Redirect EL1 register accesses to the corresponding EL2 registers if > * they are meant to access EL2 registers. > -- > 1.9.1 > Thanks, -Christoffer