Received: by 2002:a05:7412:bb8d:b0:d7:7d3a:4fe2 with SMTP id js13csp2762141rdb; Fri, 18 Aug 2023 09:42:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4xd1FeBgooSi3dwFOCwAM/NII2Nw+eNhEJTas14vczTRjYUcLzUZkzQEzFUS/TEzRYXy2 X-Received: by 2002:a05:6a00:b4d:b0:686:254c:9d4e with SMTP id p13-20020a056a000b4d00b00686254c9d4emr3359287pfo.14.1692376966454; Fri, 18 Aug 2023 09:42:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692376966; cv=none; d=google.com; s=arc-20160816; b=uZM2i/TD3ldVRM+jKOKcAMJZUpAOmGjppEaQ3i4GA7nxhdJ79tx8EkrhI4oLx/ArDF sEOMHOgaPwF4DJ0EtJ/VTdFzHdZJXk33/sfFPMQcnSsMthXWrxz/qq4XVCACn88JBdln WOCgrwjzZppYPQ/UyP+EdmaYyAuopSZDbN651/bNN5va4JLamJkJw5LYfwGionlNd1SJ Dd8Js2yu4w7zXeiWyxJjW5UfOVGNjnfHbThcly8xiLowna8sblsodzH91ExTNa9uVK4e 3/VUpSWfUY5uYtONvNFsFDKUXyIk29qO8GRN/5gyoswRj4qEoWxUgVaJU6q/1TAiqNFU qBKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=FIw2foylGlND9J3nnbdjMgmxYdvp6aZBsTvft2tTv+g=; fh=F/l+Wd5pJOGctlfOCB28jI3AtlqUSXhttgA5zL3jIQY=; b=kNkjSuHYdcfTYmccYWncKwgfx8xiZqEFFSnMPoj7HraR6y0IK3+zeoTVXF0muoOvFi DkPPN40I4j8sesWH6ci1Nz1nKcx35c1srJxXW6L0gG1Iassvjl6xiof4sLR4sH9qJZYJ KUE4aqCaeZoMu+d1dbnEDpaQblnMAuJGfea//hjllFEW2MawLwCunJgf7obGCJRK9Nab lTVEjBOw/1Dcox6XZ66FywN+i/JIML1qnqF4Hbk7DwpaOJYC8ijT5DvKPVrP8iyBPiE7 6M4zBmtZ189mClGHMH57SMr3oYM1RD9FVXDyCehx5IkNKw11ZLfVTSOlO854qvnHddab qkcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AhL+P+uB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cp17-20020a056a00349100b00686f351bdf3si1665398pfb.294.2023.08.18.09.42.32; Fri, 18 Aug 2023 09:42:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AhL+P+uB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232915AbjHNV3N (ORCPT + 99 others); Mon, 14 Aug 2023 17:29:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232979AbjHNV3B (ORCPT ); Mon, 14 Aug 2023 17:29:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FD94B3 for ; Mon, 14 Aug 2023 14:29:01 -0700 (PDT) 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 B342363CE6 for ; Mon, 14 Aug 2023 21:29:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E10E4C433C8; Mon, 14 Aug 2023 21:28:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692048540; bh=STaj8td9cui3Me7gAKPjRhUvpBEqCdVFg2sxrc1L9HI=; h=From:Date:Subject:To:Cc:From; b=AhL+P+uBFabhsqvUHwvcn/C9cJCWPHlWHxKuROpV6jsznxZTZUgn2NEKlMzGCohdG 9yZPiP2X1XNcP3FdFAGc8nDO9nDcrW2NVgus36y4eIJbi42dxegjrwQ3FSpbF+Q1c4 4fxBZTMO4Zk5zEbuDQEYRZLZydvARMzLZh2/HGuBSkLN/YB62Pwub2z4MWAR1brohi tGrAAU8O1jUMl4CcBeLqYxqS65IlCFBDMZaVyjsEqp0LLcNiutLCaFtEnruzX04Rm4 tyJRRW1AmPI53Y2Z272N5mytgwgEh1MJBKRWiHCASEeBFcohM+d6FkbiLOG6hyvyEc J8g1dn0+0A5fQ== From: Mark Brown Date: Mon, 14 Aug 2023 22:27:51 +0100 Subject: [PATCH] arm64/ptrace: Ensure that the task sees ZT writes on first use MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230814-arm64-zt-ptrace-first-use-v1-1-fc8e8022140f@kernel.org> X-B4-Tracking: v=1; b=H4sIAFec2mQC/x3MPQ6DMAxA4asgz7VEUoiAq1QMIXWKB35kB1SBu DsR4ze8d4KSMCl0xQlCOysvc4Z5FRBGP/8I+ZsNtrTvsjEVeplchUfCNYkPhJFFE25KSK5u68E aZ2OA3K9Ckf/P+9Nf1w0EJuapawAAAA== To: Catalin Marinas , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, David Spickett , Mark Brown X-Mailer: b4 0.13-dev-034f2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1593; i=broonie@kernel.org; h=from:subject:message-id; bh=STaj8td9cui3Me7gAKPjRhUvpBEqCdVFg2sxrc1L9HI=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBk2pyZZ/Nb87nFg2VvapXZ9y9h4IYNPxLU62q7z+QW 9R+VjR6JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZNqcmQAKCRAk1otyXVSH0ANEB/ 9ouLTgbmYnpJIisdgjsP5W5b5VNMtRtmAOUF3MRCipJ499ZTrCSVqPr/EdKKaDYJ+r1sVA0/Zndi3V DjarTnhKmGXjin4C4o3uERax+9aWtSuPJ1SMYnH4shcmYNILqZGrCv1HjW6DYRBEqWM96bQwTKIHIe iB2mBn9KfKsdsymbr+lKz4p+5zWqwZX6Z0CAjv7bsmbnsMd+uUQLG54jsha6GxfMFnG7CVW/2qCVtd a84OAgbRvALu5xSGQxgv5PYMsttI3qGBFb7+dGmRgmkrGVvxEiS3JTteAQ1u4AOS2lOkQD3g+ssNrn GVKvDiW73O+BmuDg/dCcOj0+pOF8ES X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the value of ZT is set via ptrace we don't disable traps for SME. This means that when a the task has never used SME before then the value set via ptrace will never be seen by the target task since it will trigger a SME access trap which will flush the register state. Disable SME traps when setting ZT, this means we also need to allocate storage for SVE if it is not already allocated, for the benefit of streaming SVE. Fixes: f90b529bcbe5 ("arm64/sme: Implement ZT0 ptrace support") Signed-off-by: Mark Brown --- arch/arm64/kernel/ptrace.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 5b9b4305248b..254eb37e1f07 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -1170,6 +1170,11 @@ static int zt_set(struct task_struct *target, if (!system_supports_sme2()) return -EINVAL; + /* Ensure SVE storage in case this is first use of SME */ + sve_alloc(target, false); + if (!target->thread.sve_state) + return -ENOMEM; + if (!thread_za_enabled(&target->thread)) { sme_alloc(target); if (!target->thread.sme_state) @@ -1182,6 +1187,8 @@ static int zt_set(struct task_struct *target, if (ret == 0) target->thread.svcr |= SVCR_ZA_MASK; + set_tsk_thread_flag(target, TIF_SME); + fpsimd_flush_task_state(target); return ret; --- base-commit: 2ccdd1b13c591d306f0401d98dedc4bdcd02b421 change-id: 20230814-arm64-zt-ptrace-first-use-e6595b2162fc Best regards, -- Mark Brown