Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1072912rdb; Tue, 30 Jan 2024 07:12:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEIAlFyn8wuZGJYcuku+7SHj48AKO95Mr1J8oSSb+t9+mSd7eK4gzLM+zLsZmtIVqmJN9w2 X-Received: by 2002:a05:6a20:4890:b0:19b:211a:e62d with SMTP id fo16-20020a056a20489000b0019b211ae62dmr7217141pzb.25.1706627567945; Tue, 30 Jan 2024 07:12:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706627567; cv=pass; d=google.com; s=arc-20160816; b=oh58c76TsFUhKHbqmfUgBZl3VouMdU/z+ele11KjhsXl27BHzG3YbdtVYq4yVhtNur GYf9WWk7d07gznKOOPRu7J8FG4Sgn7ouweYZNHslVIkw8M34jb9UF+JXW/Zz7IUVXpu7 y9isvqozi2DiV74+7lcKSuP58XYLQtOYOVx54RdS2ijQLtaYYFY/ncNe3eh491zOyTk/ LrQEdX9JbgcfHwzwg7Bd5NnpJo2VkDySkn3lidqg7XjHu7hCrzh4VpmGyP+1lzT+u0bQ R+fCJammddS7s56uXta9ULmv6hGpkEuV0BxdlnPpnw0RGDbBpgAOfwnxSjNmWHEA9sKk Q2dg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=8+8bIQPzxyK0sSMPHPwCXIN+ts0S/uTMos3WEW7bSwI=; fh=L3x+FmRlkcec9FftIxaz4PsxU6q3ka7vKXDcNlobBSI=; b=G/pFi/jmFIBLZlFtvRpPXKYAEV8i+PJt5P1IHoRw8IbIbhNaRLZjMp5TNPuVJKzIbV lCtccVnkMevVslC3FUFu4vJ2dKU3GBDzU99iByanGuJZvMab8M9lakjcE5rvly9vLxqz xd2xhI7XPJwcVNCdMsx+IXtUMhrY0Srdjb34PnmLKyYnBphlql852VRaZsPUhm13lxCr xHKFfTm51OBxgnLxlpE2OcoK3x5hM55pA/w/t9WDv+MEGbWGpE55GK7dkj3vggNOqej+ sPXThKVqQ6ExW5xLa+rBVLoCbECTBTLavKBKCvZSo3o4EIkQaQELM3hkIAAYkElncajh it+g== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-44766-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44766-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 207-20020a6300d8000000b005c6606d5b9esi1419595pga.572.2024.01.30.07.12.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 07:12:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44766-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-44766-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44766-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A16ACB221F3 for ; Tue, 30 Jan 2024 14:45:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D0C97C0B1; Tue, 30 Jan 2024 14:45:01 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 72406F4EE; Tue, 30 Jan 2024 14:44:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706625901; cv=none; b=m1wYAB/4HKq8wCwu3DUfNmMcEFfTRtrsvTqIMKAygK3SxsMzhSoAbys87YseW10rTrVktwX3ZgCgAbtSaPLG9SIjqK86KddvCp6FkQuylMYV41d3vqWpx+YFBVat8Zox7J3MHMJebryQIOSiNCcTHNrXOi4OtQYvEKNHYAtxStY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706625901; c=relaxed/simple; bh=0VbkX8braxi3BLs1wzLKUruKz9+ZnyZtunF5Xh0bD5g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Fs36wyUifsX2yzmJ67Hf6ULw0EUj/hH5bK48+qe7sJXadQGihVTztIK3H8KhJQuqZQPY36JylUdQR9PPUXE284Er1sQmdZ36qYe/yhaH1HLk6ocpcCM95muhsALaem87qyco4hXpcC/kPlN78VsV2X+FINkJ7ojH4scSSATeGHk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E629FDA7; Tue, 30 Jan 2024 06:45:39 -0800 (PST) Received: from e133380.arm.com (e133380.arm.com [10.1.197.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 884443F762; Tue, 30 Jan 2024 06:44:54 -0800 (PST) Date: Tue, 30 Jan 2024 14:44:51 +0000 From: Dave Martin To: Mark Brown Cc: Will Deacon , Catalin Marinas , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] arm64/signal: Don't assume that TIF_SVE means we saved SVE state Message-ID: References: <20240119-arm64-sve-signal-regs-v1-1-b9fd61b0289a@kernel.org> <20240130115107.GB13551@willie-the-truck> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Jan 30, 2024 at 02:09:34PM +0000, Mark Brown wrote: > On Tue, Jan 30, 2024 at 11:51:07AM +0000, Will Deacon wrote: > > On Fri, Jan 19, 2024 at 12:29:13PM +0000, Mark Brown wrote: > > > > - if (test_thread_flag(TIF_SVE)) > > > + if (current->thread.fp_type == FP_STATE_SVE) > > > sve_to_fpsimd(current); > > > } > > > I don't think this hunk applies on -rc2 ^^. > > Hrm, git seemed to figure out a rebase with no intervention - I've > thrown it at my CI and will resend assuming no changes from the rest of > the discussion. > > > > - if (add_all || test_thread_flag(TIF_SVE) || > > > + if (add_all || current->thread.fp_type == FP_STATE_SVE || > > > thread_sm_enabled(¤t->thread)) { > > > int vl = max(sve_max_vl(), sme_max_vl()); > > > I think this code is preemptible, so I'm struggling to understand what > > happens if the fp_type changes under our feet as a result of a context > > switch. > > We are relying here on having forced a flush of the floating point > register state prior to this code running, simple preemption won't > change the state from what was already saved. The same consideration > also applies to the check for streaming mode here. > > That said if this is preempted ptrace *could* come in and rewrite the > data or at worst change the vector length (which could leave us with > sve_state deallocated or a different size, possibly while we're in the > middle of accessing it). This could also happen with the existing check > for TIF_SVE so I don't think there's anything new here - AFAICT this has > always been an issue with the vector code, unless I'm missing some > bigger thing which excludes ptrace. I think any change that's needed > there won't overlap with this one, I'm looking. I'm pretty sure that terrible things will happen treewide if ptrace can ever access or manipulate the internal state of a _running_ task. I think the logic is that any ptrace call that can access or manipulate the state of a task is gated on the task being ptrace-stopped. Once we have committed to deliveing a signal, we have obviously run past the opportunity to stop (and hence be ptraced) on that signal. Cases where a multiple signals are delivered before acutally reaching userspace might want some thought. I haven't tracked down the smokeproof gun in the code yet, though. From memory, I think that the above forced flush was there to protect against the context switch code rather than ptrace, and guarantees that any change that ctxsw _might_ spontaneously make to the task state has already been done and dusted before we do the actual signal delivery. This may be a red herring so far as ptrace hazards are concerned. Cheers ---Dave