Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1385150lqb; Thu, 30 May 2024 08:41:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW5ntq9rqn1IPAv6l7w3QExDFITNkD6omGveBqzkTTAQrZ9RNs0+4Du6tLtGsU83iOfRz1A9Wv08hDhGO6Z7LnTWVnvhWyi+sLiDb209A== X-Google-Smtp-Source: AGHT+IGkxPJQHJUXy5TiozKVo9GWXZtQ8dhVN2DunccV4Slk4wvfm+jEtKn/aYq7qRYL3gN3BLNE X-Received: by 2002:a17:906:7cd0:b0:a62:187b:e7f5 with SMTP id a640c23a62f3a-a65e924fdc8mr159064266b.57.1717083661985; Thu, 30 May 2024 08:41:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717083661; cv=pass; d=google.com; s=arc-20160816; b=xFZdXGdAKsr/JZXwyN8OiYh63KvnwCgC1i2c6uYShuVkSn0aKUkk6GUkQ4oVEegNuX Rz3o/ixd1Zg0koAXgqVCB/EH8yBsh2oITXFT2IQOptWtPaMacKsM+osU8H4fS645p7KO NwOsmO1XY6T0ERIgiGQTGftkUD5gRq1uC6ai4lKjBncWU3GO3ZAnVE/mIf7DTrtFTWiX hE2NvqKKbgTaneUtJun+ppqcWu/QIbK89bSK6mVZwKoBKVcnmKdOePDSX2Igva/QRZwd BRb7lCusXRH1nZ3+T1RsaA1Y2sm2QR8paCnKGCM2wJv8Nv8CTk3KluTt0wz241A6aASh L5vQ== 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:dkim-signature; bh=stlUgRLDzsu69egH4WOaU95TqzBWDkeZbFawBnyU0kg=; fh=RqYE/C9cMD64/S8lvU/ufvJ3OeJjG14UBHtIesxKZt4=; b=rwNMsflIYl4ti/YbXBYtrH65h52uJLYUQo2675SYj53rHjVtx4VBuoRURqi52hgJbq sVtEnbnX3hHIcVAiBoM6pbFZZsHS06jqgz0+HpeCY2gOtBZjy6tq06bh3nYgqyz1tnwJ AIRXFgB+lpArR8W1+roMGhxyyYNauxhZNqxqkB4yYdOdSoVSUO1CoGSNH1El4UudwjjM /G1UItU8HGRN/iL7pBpPoUeH7h9RHVQmlRt3PBH3nijTsbkk3TuvdQR+IGNgrlYPw2nK ceaashG8srJ2BUqNPdlbV2IG3fSBdSXI/otbdG83bwNscaK8OIKs7ba+cwMybJ0VxOcW uF2g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Lw/JMKK6"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-195610-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195610-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a626c800e81si739960666b.102.2024.05.30.08.41.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 08:41:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195610-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Lw/JMKK6"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-195610-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195610-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8ADBD1F22B5C for ; Thu, 30 May 2024 15:41:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BE98183077; Thu, 30 May 2024 15:40:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Lw/JMKK6" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 932D5182D01 for ; Thu, 30 May 2024 15:40:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717083652; cv=none; b=Sw9+maHlCYWuSoLRijR55WGJhO185SOzQf/mfXph69hchlx1JA3tiyR1ejsbQn2Af3sSfgjy7HfaruKtU8E18MbINP1fArtTqvKoAT9+ICpawBGXlhYYxGRCz4t+UYy/Oa4DNWCk3n9y/PncgQ+W/oe1R+JaDdQDHrJ7uSRQES4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717083652; c=relaxed/simple; bh=bi2dy1JH5i6qd8dR05t2RFgbb5YxpsCSkK8He6pwaPg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sNle834Hse0Hizp0ZIaMMOTBeggBdCjUrOA6MX3+MCI20ilL3bQ2yZfK1i5E0Ut2HKfPo/qOi/GMvmk8EyHT3egkhBCiBbdMMUgETfSvBSZEtRWLViznYyoCwvKbQo1kSdprXMe61SgFFkdKQuQbwiijWzdcZkgzsaoJ30Ik2Jo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Lw/JMKK6; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B857EC32781; Thu, 30 May 2024 15:40:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717083652; bh=bi2dy1JH5i6qd8dR05t2RFgbb5YxpsCSkK8He6pwaPg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Lw/JMKK64FM/ys7PssXjAU7fjFJY0Eh/vuSfeYRoEHikqTEsgDseOqOcSldF9QQts PvAbVjIVMnpC1tPKkiXjRzle0+WEOJNA5ODnss+aOkvCv/500U5qdOSX/TMqNGggAu DuQaSWMYWjKNe4T8VYQya4HVS3an7rXL09IT5wDDCLH/iE+FY1NY118ki8KRkSAO53 vew3d2fbElqmykbVk0O9LJ1RJtbPdEc3xv5bYmJKJgYpdaciT9MD9wmV2k1GSiR3L5 QqVBQAMojyqRjvETvcVkTb5miYArd5Iykdj2RqlQFP3Z3pPuY14RbU6MDntYiV2ln3 193lz3GwZh/qg== Date: Thu, 30 May 2024 16:40:47 +0100 From: Mark Brown To: Dave Martin Cc: Catalin Marinas , Will Deacon , Benjamin Herrenschmidt , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v6] arm64/fpsimd: Suppress SVE access traps when loading FPSIMD state Message-ID: References: <20240529-arm64-sve-trap-mitigation-v6-1-c2037be6aced@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Mw6N+ieN4n79Ouzd" Content-Disposition: inline In-Reply-To: X-Cookie: To err is human, to moo bovine. --Mw6N+ieN4n79Ouzd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, May 30, 2024 at 03:03:42PM +0100, Dave Martin wrote: > On Wed, May 29, 2024 at 08:46:23PM +0100, Mark Brown wrote: > > When we are in a syscall we take the opportunity to discard the SVE state, > > saving only the FPSIMD subset of the register state. When we reload the > > state from memory we reenable SVE access traps, stopping tracking SVE until > > the task takes another SVE access trap. This means that for a task which is > > actively using SVE many blocking system calls will have the additional > > overhead of a SVE access trap. > Playing devil's advocate here: doesn't a blocking syscall already imply > a high overhead (at least in terms of latency for the thread concerned)? > i.e., does letting TIF_SVE linger across some blocking syscalls make a > meaningful difference in some known use case? I don't have any solid examples since I didn't do physical benchmarking yet (the only thing I have access to is Graviton, I need to figure out deploying kernels there for test). I am always slightly nervous about only benchmarking on big cores, though for something like this they might well get more benefit anyway. > Could your instrumentation be extended to build a histogram of the delay > between successive SVE traps per task? You could do that instrumentation, what I had was extremely crude though. > There's a difference here between a task that takes a lot of traps in a > burst (perhaps due to startup or a specific library call), versus a task > that uses SVE sporadically for all time. The pattern I was seeing was mostly either a very small number of SVE uses during startup and then none for the rest of the runtime or otherwise SVE used on comfortably over 50% of the restores so I didn't look super hard. I'd expect you will see some things more in the middle where a non-SVE application uses a SVE enabled library (eg, a JIT that doesn't generate SVE code doing calls out occasionally to a C library built with SVE) though. > I wonder whether the sweet spot for the timeout may be quite a lot > shorter than a second. Still, once we have something we can tune, we > can always tune it later as you suggest. My instinct is that a second is probably on the high end, yeah. Given that it's just pulling numbers out of thin air I went high to minimise the impact on tasks that are actively using SVE for a long time, guessing that short running tasks are likely to not get scheduled so often anyway and they only pay the cost when preempted. > > + if (time_after(jiffies, current->thread.sve_timeout)) { > > + clear_thread_flag(TIF_SVE); > > + sve_user_disable(); > > + } else { > > + sve_flush_live(true, sve_vq_minus_one); > Didn't we already flush Zn[max:128] as a side-effect of loading the > V-regs in fpsimd_load_state() above? Looking at the pseudoode for V[] that does appear to be true for the Z registers since we are now setting the vector length, but we do still need to worry about the P and FFR registers so there still needs to be some flush. Unless we're both missing something there there's room for an optimisation here, it won't make a difference for 128 bit VLs since we skip the Z register flush there anyway but it would help with larger VLs. > Also, unless I'm missing something, prior to this patch we could just > fall through this code with TIF_SVE still set, suggesting that either > this flush is not needed for some reason, or it is shadowed by another > flush done somewhere else, or a flush is currenly needed but missing. > Am I just getting myself confused here? With the current code we will disable SVE so the contents of the state only accessible with SVE become immaterial, we deal with it when we take an access trap. With this patch we will leave SVE enabled so we do need to ensure that the visible SVE state is flushed. As you point out we no longer need to flush the Z registers even for larger VLs since SVE is always enabled for EL1 and this patch means that we always set the vector length if the task has TIF_SVE. Setting the VL means that the constrained unpredictable choice between zeroing the maximum or currently visible upper bits in the Z registers will always zero all the bits that EL0 could access. We do however continue to need to flush the predicate registers. --Mw6N+ieN4n79Ouzd Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAmZYnf4ACgkQJNaLcl1U h9BH/Af/ZjVlG2wP2REXw/799jMZW00bhKv5xxae5aTMp/wYxs1TXyDDo9aF6CbJ O/d7A7883Dv8aJc1PaXfWACnLssnA9thQo1IAywiybo9iPv9v+5okVhuucHXvW4W b5uEyqbM+nAKxIoSkTZbA1yecZsXc3XFHQ061hjDv3QA2qgVzkjnYQW7tkmzclzL Eb+QyVXqt4JFtS6vA7XcME0ptyxQs/PXtwmzDnupnxrheLNmHsrF5Iq942ekDJOD S1767PQ2gL1lrWqJwTG8j2pra6tvTzZlpZEFCoVcH6/PumpMcLkE3NotqBEf9fHU UadtldqO+eyMcbZv6H8XBHGIjp0m/w== =QFcO -----END PGP SIGNATURE----- --Mw6N+ieN4n79Ouzd--