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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF744C46CA1 for ; Mon, 18 Sep 2023 11:11:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237473AbjIRLLO (ORCPT ); Mon, 18 Sep 2023 07:11:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241446AbjIRLLF (ORCPT ); Mon, 18 Sep 2023 07:11:05 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB8CC10E for ; Mon, 18 Sep 2023 04:10:28 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6643EC433C7; Mon, 18 Sep 2023 11:10:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695035428; bh=nI22GzPf38yVW5irsdFYpIrR/SVQVuIbqZOLX6We6Z8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=MDXPch+U1V86R6jsI5MRXRdNS08DHTT9f+J4ixiTLCLnBBTZp+oap1Djxu7EnWSCb jxws0XxDF1tIQ59+FW6IexuQcVRxt+8NVHlEsleyJgl+ow3qA2oPf5p0AcqJn8xOCO qcEXq5O9eO+8qeScu5gZS7Xi5G3tqRFLg7//4wej+BBe6mzSGsiFV/K11OZVUQ/cYf clab0hasqHHg4NAJqAMqF5g5WqSN4Ce+QH1v2f/uEdNhihIf3wvY/WPVuUbT35zm0S pWNyvvPBWuYTF09QggZarbXQxia5a0ZC4gMmuKgZZgAG2lUrT4FOu2Empi1yLX/2E1 nY9M8aQA6ZZkQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qiC93-00Dw69-On; Mon, 18 Sep 2023 12:10:25 +0100 Date: Mon, 18 Sep 2023 12:10:25 +0100 Message-ID: <865y47enz2.wl-maz@kernel.org> From: Marc Zyngier To: Kristina Martsenko Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Vladimir Murzin , Colton Lewis , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] KVM: arm64: Configure HCRX_EL2 dynamically In-Reply-To: <20230915124840.474888-2-kristina.martsenko@arm.com> References: <20230915124840.474888-1-kristina.martsenko@arm.com> <20230915124840.474888-2-kristina.martsenko@arm.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kristina.martsenko@arm.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, vladimir.murzin@arm.com, coltonlewis@google.com, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Kristina, On Fri, 15 Sep 2023 13:48:38 +0100, Kristina Martsenko wrote: > > At the moment the HCRX_EL2 system register is always initialized to > HCRX_GUEST_FLAGS when running a guest. Instead, choose the configuration > at vcpu reset time and save it in the vcpu struct, similarly to how > HCR_EL2 is set up. This will be needed in a subsequent change to > configure the register based on CPU features detected at runtime. > > Signed-off-by: Kristina Martsenko > --- > arch/arm64/include/asm/kvm_emulate.h | 5 +++++ > arch/arm64/include/asm/kvm_host.h | 1 + > arch/arm64/kvm/arm.c | 1 + > arch/arm64/kvm/hyp/include/hyp/switch.h | 2 +- > arch/arm64/kvm/hyp/nvhe/hyp-main.c | 1 + > arch/arm64/kvm/hyp/nvhe/pkvm.c | 1 + > 6 files changed, 10 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h > index 3d6725ff0bf6..64ea27e6deb1 100644 > --- a/arch/arm64/include/asm/kvm_emulate.h > +++ b/arch/arm64/include/asm/kvm_emulate.h > @@ -134,6 +134,11 @@ static inline void vcpu_ptrauth_disable(struct kvm_vcpu *vcpu) > vcpu->arch.hcr_el2 &= ~(HCR_API | HCR_APK); > } > > +static inline void vcpu_reset_hcrx(struct kvm_vcpu *vcpu) > +{ > + vcpu->arch.hcrx_el2 = HCRX_GUEST_FLAGS; > +} > + > static inline unsigned long vcpu_get_vsesr(struct kvm_vcpu *vcpu) > { > return vcpu->arch.vsesr_el2; > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > index af06ccb7ee34..2764748756a7 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -487,6 +487,7 @@ struct kvm_vcpu_arch { > > /* Values of trap registers for the guest. */ > u64 hcr_el2; > + u64 hcrx_el2; Do we really need this extra field? Yes, this is only an extra 64bit, but they tend to accumulate... Looking at patch #3, the change is related to this: vcpu->arch.hcrx_el2 = HCRX_GUEST_FLAGS; + + if (cpus_have_final_cap(ARM64_HAS_MOPS)) { + vcpu->arch.hcrx_el2 |= HCRX_EL2_MSCEn; + vcpu->arch.hcrx_el2 |= HCRX_EL2_MCE2; + } meaning that this is a constant value for a given boot of the host. At this stage, I'd rather you define HCRX_GUEST_FLAGS as: #define HCRX_GUEST_FLAGS \ (HCRX_EL2_SMPME | HCRX_EL2_TCR2En | \ cpus_have_final_cap(ARM64_HAS_MOPS) ? \ (HCRX_EL2_MSCEn | HCRX_EL2_MCE2) : 0) and drop the new field altogether, until we have something that requires dynamic flipping of an HCRX_EL2 field. Thanks, M. -- Without deviation from the norm, progress is not possible.