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 83260CD37B0 for ; Mon, 18 Sep 2023 11:11:03 +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:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=cmdZRnkWnIjQE8BbvHWA8mmTw3jCfhtrIe80yjrQTZU=; b=vYhY4ANwZoYdOq kCOBHs8+QHP4kzUdbwqVKA8ew04Z41DfDy8D+bFEAMsYy/B15ry+yRGs+WOm4xOBNAUbJGmmfLQjM ubloggvyuX+BQkyoAjPhQJ6Ntyaim1j/WBEpCDoD99/T2+KZH2itBIGAYS/6H44Gkd2LOoA/l+iR1 TFmKtCRCZQsdvQmA0R8+Kb+g+xP6slnx5VP2be8liUFPM6qUFgdntFYwYbUNhjT1W0YUAvAgcw9zJ ix+R5L0qJHaIMspk+w1aus/Pg2mIhCA6x6caBNqVOr4aKJnb+kCikVPm9OnGsaO00JXGC+M8hgr9p 5rVrZ4CtGpNjfeGgn4AA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qiC9E-00FIhN-1P; Mon, 18 Sep 2023 11:10:36 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qiC9B-00FIgy-0p for linux-arm-kernel@lists.infradead.org; Mon, 18 Sep 2023 11:10:34 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D1996B80B43; Mon, 18 Sep 2023 11:10:29 +0000 (UTC) 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") 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230918_041033_615279_85EDDDE9 X-CRM114-Status: GOOD ( 29.59 ) 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 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. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel