Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp375049rdb; Sat, 19 Aug 2023 05:28:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHiqUpjPxssLHJplblZFSfr74/sx+n3RFb0BvRL48vfvhe3eCQbpYvEeRSnHfSraAm0++r0 X-Received: by 2002:a05:6a20:a10c:b0:13e:1d49:7249 with SMTP id q12-20020a056a20a10c00b0013e1d497249mr2136200pzk.2.1692448123201; Sat, 19 Aug 2023 05:28:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692448123; cv=none; d=google.com; s=arc-20160816; b=EorTUZqL4Qireky73QLxnnFUUB9ekd97VxykyW5FpuUXYL9VSOAsozhkpXpTHRalsy qwEPtbysc5dUWDRS+bIYyjy+6/kexf4u2ODNBzu83xBkJzcBFxmEF9UqrQiQ1dL7lvj1 SDvJ4pG6lrPYmNV+DG5FWhTm5ud3CRxR6F3HBJAvWcNNlOWpa0vpQkMUICkNg3+tR59t rPXo8o7hlbJZ9Pet9KRowK1ehiD+8xcjySGIJ+opAmSIYmjgof1tLCcJLM06CNrx0O7B QXr8+ByRWDlT92MSm+RfMxYIB+uQA8IBiZ2jbzA0NWMnvgvG6ajeu03AcNIqA5TSdolP 35mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=VbVT77oQIjCvFuDk62bv/M4ryt70bnE0cI7HzcbZEmM=; fh=CVkEgCQAPesO0OESonqzfvoKM4jyypsfx6AJcL6byIE=; b=OBFWO6CFx+c6gETDL0jc8pIr2V8k6nGI3jQHPX8xqw9//HWIJ+1EAiL3ZxFfAap5Qv ZBHnI5EsE4hkgWFHlHO0WGsZbuSUodXeqD25SiaHN04snDzvmFlypp2IQvEoWLL5Pdyl h9so6qHlbs9Xzen+7RkprJWofKVm6yjTQOLIxSQswYJMz5kAfG8kWL6FHsvzNsYLm/2w MG4zdHzjNHOkTeGyQz9CgQ8+MBor5ASNNF07pvPXHfT4DBcMjl/eBWlbDTqlKxn3/bmj 7IRRAfW66Zq8wNRsXITdRaRTDna7XvN4caz+D0V109P5vXfinWUErg4E/DxiEwCmR0Hy MrPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="A+CcO/ap"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w185-20020a6382c2000000b005652bd28000si3180226pgd.4.2023.08.19.05.28.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 05:28:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="A+CcO/ap"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 82015847DE; Sat, 19 Aug 2023 01:37:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343571AbjHPOWc (ORCPT + 99 others); Wed, 16 Aug 2023 10:22:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343585AbjHPOWZ (ORCPT ); Wed, 16 Aug 2023 10:22:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0080B2705 for ; Wed, 16 Aug 2023 07:22:24 -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 8A94D61FDA for ; Wed, 16 Aug 2023 14:22:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E64D3C433C8; Wed, 16 Aug 2023 14:22:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692195744; bh=zJNWoRzvigLWHBNjpuNAJOa1sNUOYFAS8Jy3IBQ7uac=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=A+CcO/ap0uyWcawKXLPisbB5Gx59/Y/8qiic+jJYjpbK0vb5wOM2SO+vZgDLMoQx1 U/IkJ7QsvM/JnFvgOuekucw3oVlHN4XEvX9kwOLDj9S569hTsjXiLIJGrmRDn/V61C V3MPnqPxmZ2R7Bm/paAsy2TtsX+AThjpGJLXSIZwfC3n4M3kazF5Kq68EpXL6ghmKS EHMGtDy0evB6KmQOxqCOmdrxMKarcTa7fFge2Mx5IBlkQGizCSHprxgStM9E+64qj+ X2T8OmTqWR7jbMxVXCvyMoW/0pqPYj5uVbmMApLs38920hWD6bRbQK2knUbQbImGh6 S2h10K1yFnQ0w== Date: Wed, 16 Aug 2023 15:22:19 +0100 From: Will Deacon To: Mark Brown Cc: Catalin Marinas , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, David Spickett Subject: Re: [PATCH] arm64/ptrace: Ensure that the task sees ZT writes on first use Message-ID: <20230816142219.GA13526@willie-the-truck> References: <20230814-arm64-zt-ptrace-first-use-v1-1-fc8e8022140f@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230814-arm64-zt-ptrace-first-use-v1-1-fc8e8022140f@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 On Mon, Aug 14, 2023 at 10:27:51PM +0100, Mark Brown wrote: > 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); Hmm, this is now weirdly inconsistent with za_set(), which doesn't touch the thread flag unless the regset copy succeeds. Is that intentional? Will