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 CDDB9C04FFE for ; Fri, 17 May 2024 17:10:01 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wMbCQQQE6hbQpKx5lvWuf2I0WgNZK4K4RnRMOPw1Z2I=; b=ts8zRE8ahOHWy0 i/InKLC0K8uRPOPAZDIKBSl4dh8W4FX98F44P7ExAkn8iU42sVBmwhrXO4Af07JLWWhVZQC1o6Az3 A1bsE2wKNaMifNYCpuHy6wIYohoOgl+tn2CzXH0UP4/N20aFVcrBbfuaW+jlwrgOxzj2Eoq8Rjd1N QPTL4I2lAtLFNf+76pwA2W1IZkbvPaZ0mZf415UNYfT+t9mbIkxdZGuK25hXYcXSGbdIKqMLbsI55 g4bw0e9FgbFJ7EAntiACCKYYn7nLYUdRG/h9zC6E0Ok+TjCkVLxIvTonwXqbuwuxot+fmEt5W0S0b GD01HzeZulYLsKabbSHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s815Z-00000008TiU-2N8n; Fri, 17 May 2024 17:09:49 +0000 Received: from out-170.mta1.migadu.com ([2001:41d0:203:375::aa]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s815V-00000008ThZ-0KDg for linux-arm-kernel@lists.infradead.org; Fri, 17 May 2024 17:09:47 +0000 X-Envelope-To: tabba@google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1715965778; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=EOd0DGjVTF8TMATOC1ei3+rrNIetbYtP/rVgFxN3if0=; b=h37jX6WTUAuYO8xHNmDGL9K/rMHAX47h3nCjx7LXmZjshMKOOIJ1ZAdxDG46VNEKTQBn5m iN4bwBL64q77dKFeQlkxfQUwoUNoSVwskxDrtvFMTFgSV4ZbdxEiYLwHhUqacf8ToEWeK2 eqxhXW1zFajZGwYekhegx4CpLQYa0ys= X-Envelope-To: kvmarm@lists.linux.dev X-Envelope-To: linux-arm-kernel@lists.infradead.org X-Envelope-To: maz@kernel.org X-Envelope-To: will@kernel.org X-Envelope-To: qperret@google.com X-Envelope-To: seanjc@google.com X-Envelope-To: alexandru.elisei@arm.com X-Envelope-To: catalin.marinas@arm.com X-Envelope-To: philmd@linaro.org X-Envelope-To: james.morse@arm.com X-Envelope-To: suzuki.poulose@arm.com X-Envelope-To: mark.rutland@arm.com X-Envelope-To: broonie@kernel.org X-Envelope-To: joey.gouly@arm.com X-Envelope-To: rananta@google.com X-Envelope-To: yuzenghui@huawei.com Date: Fri, 17 May 2024 17:09:31 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Fuad Tabba Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, maz@kernel.org, will@kernel.org, qperret@google.com, seanjc@google.com, alexandru.elisei@arm.com, catalin.marinas@arm.com, philmd@linaro.org, james.morse@arm.com, suzuki.poulose@arm.com, mark.rutland@arm.com, broonie@kernel.org, joey.gouly@arm.com, rananta@google.com, yuzenghui@huawei.com Subject: Re: [PATCH v1 6/7] KVM: arm64: Eagerly restore host fpsimd/sve state in pKVM Message-ID: References: <20240517131814.719933-1-tabba@google.com> <20240517131814.719933-7-tabba@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240517131814.719933-7-tabba@google.com> X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240517_100946_052426_8F643D63 X-CRM114-Status: GOOD ( 10.73 ) 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 Fuad, On Fri, May 17, 2024 at 02:18:13PM +0100, Fuad Tabba wrote: > static void kvm_hyp_save_fpsimd_host(struct kvm_vcpu *vcpu) > { > - __fpsimd_save_state(*host_data_ptr(fpsimd_state)); > + /* > + * Non-protected kvm relies on the host restoring its sve state. > + * Protected kvm restores the host's sve state as not to reveal that > + * fpsimd was used by a guest nor leak upper sve bits. > + */ > + if (unlikely(is_protected_kvm_enabled() && system_supports_sve())) { > + __hyp_sve_save_host(); > + > + /* Re-enable SVE traps for guests that do not support it. */ > + if (!vcpu_has_sve(vcpu)) > + sysreg_clear_set(cptr_el2, 0, CPTR_EL2_TZ); This doesn't account for hVHE. I wonder we'd be better off abstracting CPTR_EL2 behind a helper wherever it gets used in nVHE and translate into the VHE-format behind the scenes: static inline void __cptr_clear_set_hvhe(u64 cptr_clr, u64 cptr_set) { u64 clr = 0, set = 0; if (cptr_clr & CPTR_EL2_TFP) set |= CPACR_ELx_FPEN; if (cptr_clr & CPTR_EL2_TZ) set |= CPACR_ELx_ZEN; if (cptr_clr & CPTR_EL2_TSM) set |= CPACR_ELx_SMEN; if (cptr_set & CPTR_EL2_TFP) clr |= CPACR_ELx_FPEN; if (cptr_set & CPTR_EL2_TZ) clr |= CPACR_ELx_ZEN; if (cptr_set & CPTR_EL2_TSM) clr |= CPACR_ELx_SMEN; sysreg_clear_set(cpacr_el1, clr, set); } static inline void cptr_clear_set(u64 clr, u64 set) { if (has_hvhe()) __cptr_clear_set_hvhe(clr, set); else sysreg_clear_set(cptr_el2, clr, set); } -- Thanks, Oliver _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel