From patchwork Wed Jun 28 15:56:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 13296020 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 5B696EB64DC for ; Wed, 28 Jun 2023 15:56:50 +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=WCqu9GVThDm7PTjq3ot4fc0ZuuXc+IWGgJNa1ge20rQ=; b=jLwuGGkvHpCHjI 6xi9N0e0cyf6Xlqudm6bMYOHrvHLSBLXhU8SrT5NdWjqvs5+Tb6M2PUY3aP7xUp0Nu8ZNAOuH5t2I H0flP/ptyhdbrMIp0E6L9dkng74UpdSCJpRX5o2C/+V6EXH5r46kUqeVQ9a/jI4TF/3AuZNwe7TP1 MmKyTTHqN43Nf7TiQNejLyuv0T0bXmtLnm78ks7mBIAtNdHoBI+p68nxlrvLvQS7v/VHA8O12Z21r HX4U3noVjRjoEBucVD3I4M13UXRS6i3Ma3G9YdYUYDQ0Lv/xIXtwv4GmuhkVonEGsiCd/n/xmepog GMJ4+2mT5QYWsDwht3OQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qEXWo-00G2ee-0U; Wed, 28 Jun 2023 15:56:22 +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 1qEXWk-00G2dp-1p for linux-arm-kernel@lists.infradead.org; Wed, 28 Jun 2023 15:56:20 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1C7AE61373; Wed, 28 Jun 2023 15:56:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 218D6C433C0; Wed, 28 Jun 2023 15:56:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687967777; bh=VeakK/ifqcKaZAFJIoMWw2uWZiDzNj369Lzi1GFptNI=; h=From:To:Cc:Subject:Date:From; b=uiyg/Q9GfTM1D4RQeAP6kbm8CQ72aHkoS/r+RQSAzWi+0PghNc5DbWpKZ4028APnf BCXtNgASDfkH7s2OSWzHjFI25zKfTO0owtIaNTKjw8220n0SdyV4Q5QBfqUXItn60z UidDvVHDConBvpOQlKe1Qh0R+Soh6svPzQD8iQ7EAfRUXHfv8q2sMKhOdValNmI6Zt PVSMu/XDj1NUoU8psuJvx7nMcGRQQ9lYZ9MSSBDrNP/I/JcU8Yb5OdprIeenGTEdnm BYLMbrP5S0Qm4MEsM/T9QXqFC+tSkZpp9ZYWUy1xf931VVvEAKmrEv0mkkDDlUKIHZ rPwfV8h8gZffA== From: Will Deacon To: catalin.marinas@arm.com, linux-arm-kernel@lists.infradead.org Cc: Will Deacon , Mark Brown , Mark Rutland , Naresh Kamboju , Linux Kernel Functional Testing Subject: [PATCH] arm64: sme: Use STR P to clear FFR context field in streaming SVE mode Date: Wed, 28 Jun 2023 16:56:05 +0100 Message-Id: <20230628155605.22296-1-will@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230628_085618_674805_2C0927F9 X-CRM114-Status: GOOD ( 13.02 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The FFR is a predicate register which can vary between 16 and 256 bits in size depending upon the configured vector length. When saving the SVE state in streaming SVE mode, the FFR register is inaccessible and so commit 9f5848665788 ("arm64/sve: Make access to FFR optional") simply clears the FFR field of the in-memory context structure. Unfortunately, it achieves this using an unconditional 8-byte store and so if the SME vector length is anything other than 64 bytes in size we will either fail to clear the entire field or, worse, we will corrupt memory immediately following the structure. This has led to intermittent kfence splats in CI [1] and can trigger kmalloc Redzone corruption messages when running the 'fp-stress' kselftest: | ============================================================================= | BUG kmalloc-1k (Not tainted): kmalloc Redzone overwritten | ----------------------------------------------------------------------------- | | 0xffff000809bf1e22-0xffff000809bf1e27 @offset=7714. First byte 0x0 instead of 0xcc | Allocated in do_sme_acc+0x9c/0x220 age=2613 cpu=1 pid=531 | __kmalloc+0x8c/0xcc | do_sme_acc+0x9c/0x220 | ... Replace the 8-byte store with a store of a predicate register which has been zero-initialised with PFALSE, ensuring that the entire field is cleared in memory. [1] https://lore.kernel.org/r/CA+G9fYtU7HsV0R0dp4XEH5xXHSJFw8KyDf5VQrLLfMxWfxQkag@mail.gmail.com Cc: Mark Brown Cc: Mark Rutland Cc: Naresh Kamboju Fixes: 9f5848665788 ("arm64/sve: Make access to FFR optional") Reported-by: Linux Kernel Functional Testing Signed-off-by: Will Deacon Reviewed-by: Mark Brown Tested-by: Anders Roxell --- arch/arm64/include/asm/fpsimdmacros.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/fpsimdmacros.h b/arch/arm64/include/asm/fpsimdmacros.h index cd03819a3b68..cdf6a35e3994 100644 --- a/arch/arm64/include/asm/fpsimdmacros.h +++ b/arch/arm64/include/asm/fpsimdmacros.h @@ -316,12 +316,12 @@ _for n, 0, 15, _sve_str_p \n, \nxbase, \n - 16 cbz \save_ffr, 921f _sve_rdffr 0 - _sve_str_p 0, \nxbase - _sve_ldr_p 0, \nxbase, -16 b 922f 921: - str xzr, [x\nxbase] // Zero out FFR + _sve_pfalse 0 // Zero out FFR 922: + _sve_str_p 0, \nxbase + _sve_ldr_p 0, \nxbase, -16 mrs x\nxtmp, fpsr str w\nxtmp, [\xpfpsr] mrs x\nxtmp, fpcr