From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9BE1C959 for ; Thu, 23 Mar 2023 19:34:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F4ECC433EF; Thu, 23 Mar 2023 19:34:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679600051; bh=2aTHzINjFGzEzHk60/xoezEEFYuR7NHkldnksAxMggM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=WYBC/aUwc24gxpSYfZw12StIx0fEAOM9HZ96NvSRc3YYRkOfKJQo5GzyKv/PQo203 czqqdReloiDIezbTNMxdr1Hl4B/wkIq66yaXSGuaQrpJ/0eTJIvQyCFrJNnSfcM5Oo R6+aHyuYqySdHdeSVInI/7K1JVktAJVe9U396JUiJTtX3jz2gY9Owxxw58mzMVaMHm riLvv8iALOpAWsGLesgpv8Fcix/YOshr+XPr2p/eHObxRSxkOvMp+/mJ5sCx2CfR6f Fudbdmb4Lnk6qHW7+DmnmsizDcA5UuUx/kEXBTQ1WeOi0YDWuv/5d1ZH5U+kNqg2e+ tJb10tBQ75xlA== 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 1pfQhM-002d4J-Oa; Thu, 23 Mar 2023 19:34:08 +0000 Date: Thu, 23 Mar 2023 19:34:08 +0000 Message-ID: <865yarxnwv.wl-maz@kernel.org> From: Marc Zyngier To: Mark Brown Cc: Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Joey Gouly , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Subject: Re: [PATCH v2 2/2] KVM: arm64: Move FGT value configuration to vCPU state In-Reply-To: <20230301-kvm-arm64-fgt-v2-2-c11c0dcf810a@kernel.org> References: <20230301-kvm-arm64-fgt-v2-0-c11c0dcf810a@kernel.org> <20230301-kvm-arm64-fgt-v2-2-c11c0dcf810a@kernel.org> 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) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: 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: broonie@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, joey.gouly@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Thu, 23 Mar 2023 15:48:36 +0000, Mark Brown wrote: > > Currently the only fine grained traps we use are the SME ones and we decide > if we want to manage fine grained traps for the guest and which to > enable based on the presence of that feature. In order to support SME, > PIE and other features where we need fine grained traps we will need to > select per guest which traps are enabled. Move to storing the traps to > enable in the vCPU data, updating the registers if fine grained traps > are supported and any are enabled. In order to ensure that the fine > grained traps are restored along with other traps there is a bit of > asymmetry with where the registers are restored on guest exit. > > Currently we always set this register to 0 when running the guest so > unconditionally use that value for guests, future patches will configure > this. > > No functional change, though we will do additional saves of the guest > FGT register configurations and will save and restore even if the host > and guest states are identical. > > Signed-off-by: Mark Brown > --- > arch/arm64/include/asm/kvm_emulate.h | 16 ++++++++++++++ > arch/arm64/include/asm/kvm_host.h | 2 ++ > arch/arm64/kvm/arm.c | 1 + > arch/arm64/kvm/hyp/include/hyp/switch.h | 35 ++++++++++++++++-------------- > arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 9 ++++++++ > 5 files changed, 47 insertions(+), 16 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h > index b31b32ecbe2d..9f88bcfdff70 100644 > --- a/arch/arm64/include/asm/kvm_emulate.h > +++ b/arch/arm64/include/asm/kvm_emulate.h > @@ -107,6 +107,22 @@ static inline unsigned long *vcpu_hcr(struct kvm_vcpu *vcpu) > return (unsigned long *)&vcpu->arch.hcr_el2; > } > > +static inline void vcpu_reset_fgt(struct kvm_vcpu *vcpu) > +{ > + if (!cpus_have_const_cap(ARM64_HAS_FGT)) > + return; > + > + /* > + * Enable traps for the guest by default: > + * > + * ACCDATA_EL1, GCSPR_EL0, GCSCRE0_EL1, GCSPR_EL1, GCSCR_EL1, > + * SMPRI_EL1, TPIDR2_EL0, RCWMASK_EL1, PIRE0_EL1, PIR_EL1, > + * POR_EL0, POR_EL1, S2POR_EL1, MAIR2_EL1, and AMAIR_EL1, > + */ > + __vcpu_sys_reg(vcpu, HFGRTR_EL2) = 0; > + __vcpu_sys_reg(vcpu, HFGWTR_EL2) = 0; > +} > + > static inline void vcpu_clear_wfx_traps(struct kvm_vcpu *vcpu) > { > vcpu->arch.hcr_el2 &= ~HCR_TWE; > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > index bcd774d74f34..d81831e36443 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -365,6 +365,8 @@ enum vcpu_sysreg { > TPIDR_EL2, /* EL2 Software Thread ID Register */ > CNTHCTL_EL2, /* Counter-timer Hypervisor Control register */ > SP_EL2, /* EL2 Stack Pointer */ > + HFGRTR_EL2, /* Fine Grained Read Traps */ > + HFGWTR_EL2, /* Fine Grained Write Traps */ No, this is the wrong spot. These registers describe the *guest* state. Not the state that KVM sets for its own use. These registers would be used by a guest hypervisor to manage traps it uses for its own guests. See HCR_EL2, for example, which exists both in this register file for the EL2 guests, and kvm_vcpu_arch for KVM to manage the guest. > > NR_SYS_REGS /* Nothing after this line! */ > }; > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index 3bd732eaf087..baa8d1a089bd 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -1205,6 +1205,7 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu, > } > > vcpu_reset_hcr(vcpu); > + vcpu_reset_fgt(vcpu); > vcpu->arch.cptr_el2 = CPTR_EL2_DEFAULT; > > /* > diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h > index 07d37ff88a3f..bf0183a3a82d 100644 > --- a/arch/arm64/kvm/hyp/include/hyp/switch.h > +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h > @@ -88,33 +88,36 @@ static inline void __activate_traps_common(struct kvm_vcpu *vcpu) > vcpu->arch.mdcr_el2_host = read_sysreg(mdcr_el2); > write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2); > > - if (cpus_have_final_cap(ARM64_SME)) { > - sysreg_clear_set_s(SYS_HFGRTR_EL2, > - HFGxTR_EL2_nSMPRI_EL1_MASK | > - HFGxTR_EL2_nTPIDR2_EL0_MASK, > - 0); > - sysreg_clear_set_s(SYS_HFGWTR_EL2, > - HFGxTR_EL2_nSMPRI_EL1_MASK | > - HFGxTR_EL2_nTPIDR2_EL0_MASK, > - 0); > + if (cpus_have_final_cap(ARM64_HAS_FGT)) { > + write_sysreg_s(__vcpu_sys_reg(vcpu, HFGRTR_EL2), > + SYS_HFGRTR_EL2); > + > + write_sysreg_s(__vcpu_sys_reg(vcpu, HFGWTR_EL2), > + SYS_HFGWTR_EL2); > } > } > > static inline void __deactivate_traps_common(struct kvm_vcpu *vcpu) > { > + struct kvm_cpu_context *host_ctxt; > + > write_sysreg(vcpu->arch.mdcr_el2_host, mdcr_el2); > > write_sysreg(0, hstr_el2); > if (kvm_arm_support_pmu_v3()) > write_sysreg(0, pmuserenr_el0); > > - if (cpus_have_final_cap(ARM64_SME)) { > - sysreg_clear_set_s(SYS_HFGRTR_EL2, 0, > - HFGxTR_EL2_nSMPRI_EL1_MASK | > - HFGxTR_EL2_nTPIDR2_EL0_MASK); > - sysreg_clear_set_s(SYS_HFGWTR_EL2, 0, > - HFGxTR_EL2_nSMPRI_EL1_MASK | > - HFGxTR_EL2_nTPIDR2_EL0_MASK); > + /* > + * Restore the host FGT configuration here since it's managing > + * traps. > + */ > + if (cpus_have_final_cap(ARM64_HAS_FGT)) { > + host_ctxt = &this_cpu_ptr(&kvm_host_data)->host_ctxt; > + > + write_sysreg_s(__vcpu_sys_reg(vcpu, HFGRTR_EL2), > + SYS_HFGRTR_EL2); > + write_sysreg_s(__vcpu_sys_reg(vcpu, HFGWTR_EL2), > + SYS_HFGWTR_EL2); > } > } > > diff --git a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h > index 699ea1f8d409..7e67a3e27749 100644 > --- a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h > +++ b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h > @@ -19,6 +19,15 @@ > static inline void __sysreg_save_common_state(struct kvm_cpu_context *ctxt) > { > ctxt_sys_reg(ctxt, MDSCR_EL1) = read_sysreg(mdscr_el1); > + > + /* > + * These are restored as part of trap disablement rather than > + * in __sysreg_restore_common_state(). > + */ > + if (cpus_have_final_cap(ARM64_HAS_FGT)) { > + ctxt_sys_reg(ctxt, HFGRTR_EL2) = read_sysreg_s(SYS_HFGRTR_EL2); > + ctxt_sys_reg(ctxt, HFGWTR_EL2) = read_sysreg_s(SYS_HFGWTR_EL2); > + } I understand why this gets saved for the host, as we need to restore it. But why does it need to be saved for the guest? Nothing changes it, and certainly not the guest itself. This looks pretty wrong to me. M. -- Without deviation from the norm, progress is not possible. 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 8FB4EC6FD1C for ; Thu, 23 Mar 2023 19:35:17 +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=VXrBJiOuJBjfGVUJDBVTsWlexOXbgkHh49liGA5XlDc=; b=mIajTBhZLidix3 omE/3X84854xkZbdSxEPuAr5kZE/Eh5UjVQSETEuLMefFIvw1gE7fUa8QpxQ19aQs58smRabpiYYn Z1ND6wKoPZTuEUT526VCQCdlG1ujDLrH3/87TQKL2xcsosxqfWV+PK3vCJNbiqbafXJpoV6Z7WVOj WHtts8q4uwknwVQqHhB9wTIDf30Hful33fvcTbtMg99xw344EUHniXdMYr0Yv2KU/rOzd+JgmSRaT 9ypy+Scue1+5FzBkijT19z1e2hZhb4VeCVzgApds+YKUtgvKvLxyzAQEafJvBOAVgkjfq71u5RjC1 MpJ7E0vIpzbemz9q/gkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pfQhe-002q33-0U; Thu, 23 Mar 2023 19:34:26 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pfQhb-002q2J-0Z for linux-arm-kernel@lists.infradead.org; Thu, 23 Mar 2023 19:34:25 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 31734CE2318; Thu, 23 Mar 2023 19:34:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F4ECC433EF; Thu, 23 Mar 2023 19:34:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679600051; bh=2aTHzINjFGzEzHk60/xoezEEFYuR7NHkldnksAxMggM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=WYBC/aUwc24gxpSYfZw12StIx0fEAOM9HZ96NvSRc3YYRkOfKJQo5GzyKv/PQo203 czqqdReloiDIezbTNMxdr1Hl4B/wkIq66yaXSGuaQrpJ/0eTJIvQyCFrJNnSfcM5Oo R6+aHyuYqySdHdeSVInI/7K1JVktAJVe9U396JUiJTtX3jz2gY9Owxxw58mzMVaMHm riLvv8iALOpAWsGLesgpv8Fcix/YOshr+XPr2p/eHObxRSxkOvMp+/mJ5sCx2CfR6f Fudbdmb4Lnk6qHW7+DmnmsizDcA5UuUx/kEXBTQ1WeOi0YDWuv/5d1ZH5U+kNqg2e+ tJb10tBQ75xlA== 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 1pfQhM-002d4J-Oa; Thu, 23 Mar 2023 19:34:08 +0000 Date: Thu, 23 Mar 2023 19:34:08 +0000 Message-ID: <865yarxnwv.wl-maz@kernel.org> From: Marc Zyngier To: Mark Brown Cc: Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Joey Gouly , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Subject: Re: [PATCH v2 2/2] KVM: arm64: Move FGT value configuration to vCPU state In-Reply-To: <20230301-kvm-arm64-fgt-v2-2-c11c0dcf810a@kernel.org> References: <20230301-kvm-arm64-fgt-v2-0-c11c0dcf810a@kernel.org> <20230301-kvm-arm64-fgt-v2-2-c11c0dcf810a@kernel.org> 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: broonie@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, joey.gouly@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev 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-20230323_123423_636239_D83E8C75 X-CRM114-Status: GOOD ( 37.60 ) 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 On Thu, 23 Mar 2023 15:48:36 +0000, Mark Brown wrote: > > Currently the only fine grained traps we use are the SME ones and we decide > if we want to manage fine grained traps for the guest and which to > enable based on the presence of that feature. In order to support SME, > PIE and other features where we need fine grained traps we will need to > select per guest which traps are enabled. Move to storing the traps to > enable in the vCPU data, updating the registers if fine grained traps > are supported and any are enabled. In order to ensure that the fine > grained traps are restored along with other traps there is a bit of > asymmetry with where the registers are restored on guest exit. > > Currently we always set this register to 0 when running the guest so > unconditionally use that value for guests, future patches will configure > this. > > No functional change, though we will do additional saves of the guest > FGT register configurations and will save and restore even if the host > and guest states are identical. > > Signed-off-by: Mark Brown > --- > arch/arm64/include/asm/kvm_emulate.h | 16 ++++++++++++++ > arch/arm64/include/asm/kvm_host.h | 2 ++ > arch/arm64/kvm/arm.c | 1 + > arch/arm64/kvm/hyp/include/hyp/switch.h | 35 ++++++++++++++++-------------- > arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 9 ++++++++ > 5 files changed, 47 insertions(+), 16 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h > index b31b32ecbe2d..9f88bcfdff70 100644 > --- a/arch/arm64/include/asm/kvm_emulate.h > +++ b/arch/arm64/include/asm/kvm_emulate.h > @@ -107,6 +107,22 @@ static inline unsigned long *vcpu_hcr(struct kvm_vcpu *vcpu) > return (unsigned long *)&vcpu->arch.hcr_el2; > } > > +static inline void vcpu_reset_fgt(struct kvm_vcpu *vcpu) > +{ > + if (!cpus_have_const_cap(ARM64_HAS_FGT)) > + return; > + > + /* > + * Enable traps for the guest by default: > + * > + * ACCDATA_EL1, GCSPR_EL0, GCSCRE0_EL1, GCSPR_EL1, GCSCR_EL1, > + * SMPRI_EL1, TPIDR2_EL0, RCWMASK_EL1, PIRE0_EL1, PIR_EL1, > + * POR_EL0, POR_EL1, S2POR_EL1, MAIR2_EL1, and AMAIR_EL1, > + */ > + __vcpu_sys_reg(vcpu, HFGRTR_EL2) = 0; > + __vcpu_sys_reg(vcpu, HFGWTR_EL2) = 0; > +} > + > static inline void vcpu_clear_wfx_traps(struct kvm_vcpu *vcpu) > { > vcpu->arch.hcr_el2 &= ~HCR_TWE; > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > index bcd774d74f34..d81831e36443 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -365,6 +365,8 @@ enum vcpu_sysreg { > TPIDR_EL2, /* EL2 Software Thread ID Register */ > CNTHCTL_EL2, /* Counter-timer Hypervisor Control register */ > SP_EL2, /* EL2 Stack Pointer */ > + HFGRTR_EL2, /* Fine Grained Read Traps */ > + HFGWTR_EL2, /* Fine Grained Write Traps */ No, this is the wrong spot. These registers describe the *guest* state. Not the state that KVM sets for its own use. These registers would be used by a guest hypervisor to manage traps it uses for its own guests. See HCR_EL2, for example, which exists both in this register file for the EL2 guests, and kvm_vcpu_arch for KVM to manage the guest. > > NR_SYS_REGS /* Nothing after this line! */ > }; > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index 3bd732eaf087..baa8d1a089bd 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -1205,6 +1205,7 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu, > } > > vcpu_reset_hcr(vcpu); > + vcpu_reset_fgt(vcpu); > vcpu->arch.cptr_el2 = CPTR_EL2_DEFAULT; > > /* > diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h > index 07d37ff88a3f..bf0183a3a82d 100644 > --- a/arch/arm64/kvm/hyp/include/hyp/switch.h > +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h > @@ -88,33 +88,36 @@ static inline void __activate_traps_common(struct kvm_vcpu *vcpu) > vcpu->arch.mdcr_el2_host = read_sysreg(mdcr_el2); > write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2); > > - if (cpus_have_final_cap(ARM64_SME)) { > - sysreg_clear_set_s(SYS_HFGRTR_EL2, > - HFGxTR_EL2_nSMPRI_EL1_MASK | > - HFGxTR_EL2_nTPIDR2_EL0_MASK, > - 0); > - sysreg_clear_set_s(SYS_HFGWTR_EL2, > - HFGxTR_EL2_nSMPRI_EL1_MASK | > - HFGxTR_EL2_nTPIDR2_EL0_MASK, > - 0); > + if (cpus_have_final_cap(ARM64_HAS_FGT)) { > + write_sysreg_s(__vcpu_sys_reg(vcpu, HFGRTR_EL2), > + SYS_HFGRTR_EL2); > + > + write_sysreg_s(__vcpu_sys_reg(vcpu, HFGWTR_EL2), > + SYS_HFGWTR_EL2); > } > } > > static inline void __deactivate_traps_common(struct kvm_vcpu *vcpu) > { > + struct kvm_cpu_context *host_ctxt; > + > write_sysreg(vcpu->arch.mdcr_el2_host, mdcr_el2); > > write_sysreg(0, hstr_el2); > if (kvm_arm_support_pmu_v3()) > write_sysreg(0, pmuserenr_el0); > > - if (cpus_have_final_cap(ARM64_SME)) { > - sysreg_clear_set_s(SYS_HFGRTR_EL2, 0, > - HFGxTR_EL2_nSMPRI_EL1_MASK | > - HFGxTR_EL2_nTPIDR2_EL0_MASK); > - sysreg_clear_set_s(SYS_HFGWTR_EL2, 0, > - HFGxTR_EL2_nSMPRI_EL1_MASK | > - HFGxTR_EL2_nTPIDR2_EL0_MASK); > + /* > + * Restore the host FGT configuration here since it's managing > + * traps. > + */ > + if (cpus_have_final_cap(ARM64_HAS_FGT)) { > + host_ctxt = &this_cpu_ptr(&kvm_host_data)->host_ctxt; > + > + write_sysreg_s(__vcpu_sys_reg(vcpu, HFGRTR_EL2), > + SYS_HFGRTR_EL2); > + write_sysreg_s(__vcpu_sys_reg(vcpu, HFGWTR_EL2), > + SYS_HFGWTR_EL2); > } > } > > diff --git a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h > index 699ea1f8d409..7e67a3e27749 100644 > --- a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h > +++ b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h > @@ -19,6 +19,15 @@ > static inline void __sysreg_save_common_state(struct kvm_cpu_context *ctxt) > { > ctxt_sys_reg(ctxt, MDSCR_EL1) = read_sysreg(mdscr_el1); > + > + /* > + * These are restored as part of trap disablement rather than > + * in __sysreg_restore_common_state(). > + */ > + if (cpus_have_final_cap(ARM64_HAS_FGT)) { > + ctxt_sys_reg(ctxt, HFGRTR_EL2) = read_sysreg_s(SYS_HFGRTR_EL2); > + ctxt_sys_reg(ctxt, HFGWTR_EL2) = read_sysreg_s(SYS_HFGWTR_EL2); > + } I understand why this gets saved for the host, as we need to restore it. But why does it need to be saved for the guest? Nothing changes it, and certainly not the guest itself. This looks pretty wrong to me. 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