From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AC5E5C433F5 for ; Wed, 9 Feb 2022 11:06:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0cqwCmUTEU+BoKy4ztG1W7TbodlFslemSMrduk4AzuA=; b=y46DP5UUVa8eJd aXXP05OmKdPxbpyjOD4udGctDDRwaUPfGcs7g7mlIT9t57Yoc8nehaUZS/KNBfIVP+OPPZ5dYMtWa X8vlPekGCKS0KU3GXf9a3AnKLyPYy+fCCzT5122YOPoag0s4h/8+4O4x27KAOOeIkEj2mCkcY2GJx Bpc/X/1bsBH/fFrgeWt+YMQma/E+ajavyGZAZ0p6omnr9ThewiynrNvZ3m+j/2LHUmdU2udT5/TH4 Sk4xoDPPVvtZxR2FK1LSOgCFg7uJO8i2ZGKC+37zdJfyedC5E3ADnbHMl1JVJaDM6JSKgqI2eFqYN 6CArsYqt1kyJUsRvcRcw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHkly-00HOly-Ft; Wed, 09 Feb 2022 11:04:30 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHklr-00HOjr-5C for linux-arm-kernel@lists.infradead.org; Wed, 09 Feb 2022 11:04:24 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0F4D9ED1; Wed, 9 Feb 2022 03:04:22 -0800 (PST) Received: from monolith.localdoman (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E1BBB3F73B; Wed, 9 Feb 2022 03:04:18 -0800 (PST) Date: Wed, 9 Feb 2022 11:04:39 +0000 From: Alexandru Elisei To: Marc Zyngier Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Andre Przywara , Christoffer Dall , Jintack Lim , Haibo Xu , Ganapatrao Kulkarni , Chase Conklin , "Russell King (Oracle)" , James Morse , Suzuki K Poulose , karl.heubaum@oracle.com, mihai.carabas@oracle.com, miguel.luis@oracle.com, kernel-team@android.com Subject: Re: [PATCH v6 29/64] KVM: arm64: nv: Forward debug traps to the nested guest Message-ID: References: <20220128121912.509006-1-maz@kernel.org> <20220128121912.509006-30-maz@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220128121912.509006-30-maz@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220209_030423_318821_1B854FE5 X-CRM114-Status: GOOD ( 19.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Marc, On Fri, Jan 28, 2022 at 12:18:37PM +0000, Marc Zyngier wrote: > On handling a debug trap, check whether we need to forward it to the > guest before handling it. > > Signed-off-by: Marc Zyngier > --- > arch/arm64/include/asm/kvm_nested.h | 2 ++ > arch/arm64/kvm/emulate-nested.c | 9 +++++++-- > arch/arm64/kvm/sys_regs.c | 3 +++ > 3 files changed, 12 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_nested.h b/arch/arm64/include/asm/kvm_nested.h > index 82fc8b6c990b..047ca700163b 100644 > --- a/arch/arm64/include/asm/kvm_nested.h > +++ b/arch/arm64/include/asm/kvm_nested.h > @@ -66,6 +66,8 @@ static inline u64 translate_cnthctl_el2_to_cntkctl_el1(u64 cnthctl) > } > > int handle_wfx_nested(struct kvm_vcpu *vcpu, bool is_wfe); > +extern bool __forward_traps(struct kvm_vcpu *vcpu, unsigned int reg, > + u64 control_bit); > extern bool forward_traps(struct kvm_vcpu *vcpu, u64 control_bit); > extern bool forward_nv_traps(struct kvm_vcpu *vcpu); > extern bool forward_nv1_traps(struct kvm_vcpu *vcpu); > diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nested.c > index 0109dfd664dd..1f6cf8fe9fe3 100644 > --- a/arch/arm64/kvm/emulate-nested.c > +++ b/arch/arm64/kvm/emulate-nested.c > @@ -13,14 +13,14 @@ > > #include "trace.h" > > -bool forward_traps(struct kvm_vcpu *vcpu, u64 control_bit) > +bool __forward_traps(struct kvm_vcpu *vcpu, unsigned int reg, u64 control_bit) > { > bool control_bit_set; > > if (!vcpu_has_nv(vcpu)) > return false; > > - control_bit_set = __vcpu_sys_reg(vcpu, HCR_EL2) & control_bit; > + control_bit_set = __vcpu_sys_reg(vcpu, reg) & control_bit; > if (!vcpu_is_el2(vcpu) && control_bit_set) { > kvm_inject_nested_sync(vcpu, kvm_vcpu_get_esr(vcpu)); > return true; > @@ -28,6 +28,11 @@ bool forward_traps(struct kvm_vcpu *vcpu, u64 control_bit) > return false; > } > > +bool forward_traps(struct kvm_vcpu *vcpu, u64 control_bit) > +{ > + return __forward_traps(vcpu, HCR_EL2, control_bit); > +} > + > bool forward_nv_traps(struct kvm_vcpu *vcpu) > { > return forward_traps(vcpu, HCR_NV); > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index 697bf0bca550..3e1f37c507a8 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -566,6 +566,9 @@ static bool trap_debug_regs(struct kvm_vcpu *vcpu, > struct sys_reg_params *p, > const struct sys_reg_desc *r) > { > + if (__forward_traps(vcpu, MDCR_EL2, MDCR_EL2_TDA | MDCR_EL2_TDE)) > + return false; The description of the MDCR_EL2.TDA field says: "This field is treated as being 1 for all purposes other than a direct read when one or more of the following are true: - MDCR_EL2.TDE == 1 - HCR_EL2.TGE == 1" Shouldn't we also check for HCR_EL2.TGE == 1 when deciding to forward the trap? Thanks, Alex > + > access_rw(vcpu, p, r); > if (p->is_write) > vcpu->arch.flags |= KVM_ARM64_DEBUG_DIRTY; > -- > 2.30.2 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel