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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38A1AC0015E for ; Fri, 23 Jun 2023 17:28:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232387AbjFWR2T (ORCPT ); Fri, 23 Jun 2023 13:28:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230506AbjFWR2S (ORCPT ); Fri, 23 Jun 2023 13:28:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40DC01997; Fri, 23 Jun 2023 10:28:17 -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 B923A61AD8; Fri, 23 Jun 2023 17:28:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF171C433C0; Fri, 23 Jun 2023 17:28:14 +0000 (UTC) Date: Fri, 23 Jun 2023 18:28:12 +0100 From: Catalin Marinas To: Mark Brown Cc: Will Deacon , Shuah Khan , Szabolcs Nagy , linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2 1/2] arm64/signal: Restore TPIDR2 register rather than memory state Message-ID: References: <20230621-arm64-fix-tpidr2-signal-restore-v2-0-c8e8fcc10302@kernel.org> <20230621-arm64-fix-tpidr2-signal-restore-v2-1-c8e8fcc10302@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org On Thu, Jun 22, 2023 at 06:11:20PM +0100, Mark Brown wrote: > On Thu, Jun 22, 2023 at 05:42:54PM +0100, Catalin Marinas wrote: > > On Thu, Jun 22, 2023 at 02:39:45PM +0100, Mark Brown wrote: > > > > - current->thread.tpidr2_el0 = tpidr2_el0; > > > + write_sysreg_s(tpidr2_el0, SYS_TPIDR2_EL0); > > > I guess the other way around may also be true - the libc sets tpidr2_el0 > > to something else and doesn't want the kernel to restore its original > > value from sigcontext. > > > For tpidr_el0 we don't bother with sigcontext, not sure what the use for > > tpidr2_el0 in signals is. If we assume the context saved is only > > informative (like esr), we can simply ignore restoring it from the > > signal stack. > > TPIDR2 is intended to go along with the thread stack, it's intended to > be used to allow lazy save of the (rather large) ZA register state when > a called function needs it rather than forcing it to be caller saved. > TPIDR2 is used to point to memory allocated for managing this process, > something that provides a new value should be making a deliberate > decision to do so and editing the stack frame. OK, so if the signal handler invokes a function that touches the ZA state, it may use TPIDR2 for lazy saving in any callee. In this case we need to restore the original TPIDR2 of the interrupted context on sigreturn. So I convinced myself this is the only option that makes sense ;). I'll queue the patches. -- Catalin