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 29FE2C74A5B for ; Fri, 17 Mar 2023 09:03:30 +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=eHW9t4gcQbwkpeOAyjAmzV8rOfynvPEHdbXl0RevOvw=; b=0XYbQODHUeOqhr uBRbLwnau9ao60ZW3uzRyNz2FxTsmSpN6q0IZ+PV6NIVNqyxWUOxwqDKWZEM4D32hmaZr2VzdK1JE faSp71WsI92PO6hIErJJpq/S4H6EvqoJWbdFR2q5Gwsk2qpYoVWqUV4tM7YamFBtS/N/2TVslkuQe dsrn7JIQc/5j+g0OPoI2L544r/UISVUO6Rx02kIlM+EuV+LTsbJruHGA406uCkzcMsRTJkmYKan/F clnJJ61R2Jif/tgtVOr3loKv1RfmqD6Q7cjTn1wEBOKdDXdnVQJCmDDR2LJtiXmGdEPsImCnTtLf+ J3JS489m3KUqrQXkDuNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pd5z0-001dZU-17; Fri, 17 Mar 2023 09:02:42 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pd5yu-001dXW-1Z for linux-arm-kernel@lists.infradead.org; Fri, 17 Mar 2023 09:02:40 +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 dfw.source.kernel.org (Postfix) with ESMTPS id D516162235; Fri, 17 Mar 2023 09:02:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3928FC433EF; Fri, 17 Mar 2023 09:02:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679043755; bh=McNr7ajeFzM4XlvQkqRV4GKHrISt20Jf451v7i73Cj8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=G+9c7xS5mGH+YiiGjRHqB8FY2nqCW9aXtEnfyvKe1p4XNcE+3xbFLwtSEBh1nut2o jUTFKsptmjzVneYcz7pZTQXUUcrncVmKwdorGdKNkleoXamD7fnsoQky5gVWq7gAFk mW0uqbbsJy3nYmjHGJRzyROyVENsNqwzbI9Qxz13AeF1GDPu9oQJROhjQQHCKS43Fn mLOHvdDAOP3DLQbSjPeEZ5kFh7EMm7vWxnGjv1Od577mQatl1Fd1SmIknpBC9div3v C+/ggHGQyn/RgaU2HwLkqhJd+yz/VyEQS6MY+3AuEnGm9IGfks48rAskXVhYdeJ3dA UqnmIBoIKi9GQ== 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 1pd5yq-000t7o-Qr; Fri, 17 Mar 2023 09:02:32 +0000 Date: Fri, 17 Mar 2023 09:02:32 +0000 Message-ID: <867cvfyclz.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 2/2] KVM: arm64: Move FGT value configuration to vCPU state In-Reply-To: <20230301-kvm-arm64-fgt-v1-2-cfdf71ac67dc@kernel.org> References: <20230301-kvm-arm64-fgt-v1-0-cfdf71ac67dc@kernel.org> <20230301-kvm-arm64-fgt-v1-2-cfdf71ac67dc@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-20230317_020236_602474_B4BCB3BE X-CRM114-Status: GOOD ( 30.69 ) 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 Mon, 06 Mar 2023 16:08:52 +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. > > Currently we always set this register to 0 when running the guest and > unused bits in the registers are RES0 so unconditionally use that value > for guests, future patches will configure this. This doesn't quite tell the story. > > The configuration for the host is saved at guest reset under the > assumption that the traps are not dynamically managed for the host at > runtime. This is currently the case, if this changes then we will need > to save each time we enter the guest. > > No functional change. > > Signed-off-by: Mark Brown > --- > arch/arm64/include/asm/kvm_emulate.h | 12 ++++++++++++ > arch/arm64/include/asm/kvm_host.h | 6 ++++++ > arch/arm64/kvm/arm.c | 1 + > arch/arm64/kvm/hyp/include/hyp/switch.h | 31 +++++++++++++++---------------- > 4 files changed, 34 insertions(+), 16 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h > index b31b32ecbe2d..20f2faae12d4 100644 > --- a/arch/arm64/include/asm/kvm_emulate.h > +++ b/arch/arm64/include/asm/kvm_emulate.h > @@ -107,6 +107,18 @@ 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; > + > + vcpu->arch.hfgrtr_el2_host = read_sysreg_s(SYS_HFGRTR_EL2); > + vcpu->arch.hfgwtr_el2_host = read_sysreg_s(SYS_HFGWTR_EL2); > + > + vcpu->arch.hfgrtr_el2 = 0; > + vcpu->arch.hfgwtr_el2 = 0; Although this looks completely innocent, this actually have the effect of trapping the SMPRI_EL1 and TPIDR2_EL0 registers, something that is self documented in the current code, and that completely disappears with this patch. This needs documenting by enumerating the sysregs that get trapped. > +} > + > 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 a1892a8f6032..09b223635764 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -530,6 +530,12 @@ struct kvm_vcpu_arch { > /* Virtual SError ESR to restore when HCR_EL2.VSE is set */ > u64 vsesr_el2; > > + /* Fine grained traps values for the guest and host */ > + u64 hfgrtr_el2; > + u64 hfgwtr_el2; > + u64 hfgrtr_el2_host; > + u64 hfgwtr_el2_host; Why do we have both host and guest? This is the vcpu structure, and the host state doesn't belong here. If you want to save some host state, place the hfgxtr_el2 fields in kvm_cpu_context, and use the per-CPU instance of this structure to save the host state. 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