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 95DF0C433F5 for ; Mon, 24 Jan 2022 16:13:13 +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:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=gGGDKakMNPYeuOuN/ZiDNM5OxcV9l9xU2DuZIs7zBeM=; b=ykHnZPfBF5o9+j BbXFMKb16Lp5JeYvLa8Kbsuy3gW5T4gB6uAxRRTrwHwfFlcev9T8OsxXwv7r1CaiUC3AzBtshw/Gt jnyqkPgAtDaC+K+l4tf4iCVTlT3QJ35bIPURds9t+N7f18fBoIsolHdRFS8zYRuvp3iiZ1tZtP+XB m4STQ6eZ+aQLCdguT9FwlER7oyEfMZdp1/fQ69uwptWQomZhDHIk9qFKD8+inMpef+0ZSw5wuNspq rrbNXQ7ej7108aVi/vl5JXtNFcYma+/vXKCQ9Wip+fb0QHT64ZOUyv0/R5pgVn1MTGbt70dCwSh1L h6NqWz39REWgBRfig4lg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nC1wN-003wu1-JX; Mon, 24 Jan 2022 16:11:36 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nC1wD-003wrU-Vf for linux-arm-kernel@lists.infradead.org; Mon, 24 Jan 2022 16:11:27 +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 ams.source.kernel.org (Postfix) with ESMTPS id 86855B8110B; Mon, 24 Jan 2022 16:11:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B2B5C340E5; Mon, 24 Jan 2022 16:11:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643040683; bh=leAHSaNjutpj94tS9QMOgpo3UhO7fWwJSckdfu0Dg3c=; h=From:To:Cc:Subject:Date:From; b=OIkYx6lX1SBXc8dRQJveD1M29LmEAmY1FqK9LaNPONm1SgXlizCXKE9zht6zE3ycu V8UZ0GCc6xfH7q5iSuOMi0TeOsYq0f69LtuIuQdC33qwkqfhCGN+q0DvyTb9unVTwK qOIOCjfhfUm6KSAA9NDQaADISCbe0GMT6/jCKDIqX2CUes4zr8RjQPfsvlSq/bqwBb adu4LyoLmwTL478klk0yOMeh07DE7bHWIGTMYmj3K1k4TkOCXEyTSy1GoSMwcyrWo5 xG84pfEEzRGZhB3jjM2yP2SJNzkJ5ySj9HUWh893DQxcCrXOZ2w+FMYpgydYxO7QNR H32foQt/QQECw== From: Mark Brown To: Catalin Marinas , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, Marc Zyngier , Mark Brown Subject: [PATCH] arm64/fpsimd: Clarify the purpose of using last in fpsimd_save() Date: Mon, 24 Jan 2022 16:11:15 +0000 Message-Id: <20220124161115.115200-1-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1756; h=from:subject; bh=leAHSaNjutpj94tS9QMOgpo3UhO7fWwJSckdfu0Dg3c=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBh7s8IG2bu11sOABADNAo1PVTZDxZ0yvLe0enOWQFg LSGAeWSJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYe7PCAAKCRAk1otyXVSH0JrxCA CA/rFxbOTi2Ao3dc8nn1xIAxYjusc5qUAURBGf2ZqFJ3NGdu0OThJPK9ecu1b45Y7PNvLTZctW5v3n 7bZJ7KccktOTd2KzoKWEP2fWI1pyORSeTwdlGmADvrYDi8bwamS1H0yi9Kd/uDTqqKNHq97hZji9YU ScC35js+ZTRiPNVqQOqGSVU4mlCDTyG6UmZlI52M2IVRlgyIIoMfrjwKDBgdTiV8XkcfpmX/bci/2z 0xYJ9kfUVsSbk5+OYooVsn5wHgUk+jj/MRPuhLfSuTs6wNKTSkk4ebaMhlh2ry7Y8uqwyPjzUmg3IK rWBhQwwKNH1gemjJmr0vBhw4oT1h+a X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220124_081126_195318_E6643114 X-CRM114-Status: GOOD ( 17.35 ) 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 When saving the floating point context in fpsimd_save() we always reference the state using last-> rather than using current->. Looking at the FP code in isolation the reason for this is not entirely obvious, it's done because when KVM is running it will bind the guest context and rely on the host writing out the guest state on context switch away from the guest. There's a slight trick here in that KVM still uses TIF_FOREIGN_FPSTATE and TIF_SVE to communicate what needs to be saved, it maintains those flags and restores them when it is done running the guest so that the normal restore paths function when we return back to userspace. Add a comment to explain this to help future readers work out what's going on a bit faster. Signed-off-by: Mark Brown --- arch/arm64/kernel/fpsimd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index 5280e098cfb5..47af76e53221 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -348,7 +348,13 @@ static void task_fpsimd_load(void) /* * Ensure FPSIMD/SVE storage in memory for the loaded context is up to - * date with respect to the CPU registers. + * date with respect to the CPU registers. Note carefully that the + * current context is the context last bound to the CPU stored in + * last, if KVM is involved this may be the guest VM context rather + * than the host thread for the VM pointed to by current. This means + * that we must always reference the state storage via last rather + * than via current, other than the TIF_ flags which KVM will + * carefully maintain for us. */ static void fpsimd_save(void) { -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel