Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp6099746rdb; Mon, 18 Sep 2023 04:24:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPaUYxEU6VRGkioPxmUMwqX8f8r3zrlCik+77p4u6A10T6bOJ/uGMKKLkNDoiDmAOQthRV X-Received: by 2002:a17:90a:db8a:b0:268:798:a28b with SMTP id h10-20020a17090adb8a00b002680798a28bmr16082759pjv.23.1695036282489; Mon, 18 Sep 2023 04:24:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695036282; cv=none; d=google.com; s=arc-20160816; b=ObyDQNFJzdChPA6ISkEd/R6pYRSOvBhkcWHJYkWFaSpJ4jwkAPNrblXZmZ3XVEKcOJ wzOiUXDSGsX3GuoaUdBoSnym9Rv+S3DMkX1fF95viiCy9FtO94Hg6iweXB796A7HZsBD 4tQB6nwozIT79ug5U2syGX4HSfvTgnFO2OCH4R2fzdZLNF+FEvVHzRGM37TLytJbtMlg PZr8wihw9MFMvB1ZSlttbF5EuFOo2ADZPouRBEhnXVSJEyWwfBKpqbquUph0mupzxU2K R/7n4U4DUe7zbyzlgzwoI6x3vju3RlNR/HU9Yj9B0RfsleZLBrNum2QiswczhqdaA9oZ Ss7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=/n7bsxEX1vUL4CSeZJzzRCNVH6DXBDPLtNDxphI2q20=; fh=zbuQeNK+uPQUUNirnUS+zz7qZk7O4LG51qtS1QTWFkk=; b=m+x4qfGD3wUvDuaYjiaHj8QoWtvnSuU96n31fZ2ry4NC7PBOlnR39ATu/qy+W618GV QNy4cFW0s8XQbwgAs0xKEPRqNTZ6Vid+xAQ+lPhw0L38Zq2bvetp0mKTOhq4DSaMR89s ti5uQjyTRh80M9hS+dVdqx04PorYwTRHkK5Vxpx4QdpGXgoIGbzGpOfhrxPHH5VolUAt Rke3iIG9AqO+svPFjTLkOdpZdamIQbt6zky4YXX9m87Dw29x5W0iplIoDF3QhFh5HA/s 7l6RN9UL+6REfD4cV0dulGECwm6AdBkRITxXDW8E1iCrNaJGwpMEzBsVVKYyelNicDXS WwdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MDXPch+U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id i3-20020a17090a64c300b0027198088485si9946855pjm.45.2023.09.18.04.24.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 04:24:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MDXPch+U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 4FF2B80BDE31; Mon, 18 Sep 2023 04:11:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232521AbjIRLLM (ORCPT + 99 others); Mon, 18 Sep 2023 07:11:12 -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 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 18 Sep 2023 04:11:53 -0700 (PDT) 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.