Message ID | 20240206-arm64-sve-vl-max-comment-v1-1-dddf16414412@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-55317-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1674239dyb; Tue, 6 Feb 2024 08:56:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFOR3wJJ44GLfZsDEWnTjTY2sKsl1Ffy18wq/KRhOI0rc4SglpZ1cbq9qx2eP3luTnxqH7w X-Received: by 2002:a17:903:41cb:b0:1d9:5ef2:abdd with SMTP id u11-20020a17090341cb00b001d95ef2abddmr3130352ple.0.1707238599452; Tue, 06 Feb 2024 08:56:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707238599; cv=pass; d=google.com; s=arc-20160816; b=kz4VKGt11EQ1tPqp/DL35QhHy/UMwZSh6ItCJRbVfM66LLXGfBrIovf77j6JwvzAcB 1SjF/K2r4nqsCFuYyFhiC5ZbZ+FC8aiII+2p9qnkdFBdC/nWI1keg88LVnQIWfKhWlEx jz4kB4AuHaAQHKYwuj84dWlj97qlycgw1nzhVlpDUbmncRs1FC3q6xFq/Kw4VHd+wz6Q eV6DAq48WotyOdGl1dV6uO37m7lOJrQeI2ehr+6mgFzvMoEq7Di0NhFE4UjUU5WqHw2I rIHB4BRb5rFgHV6eJdaaC77ZJEwu1xBK7ik2ar/xD8+WVAb4ShukazQ9qj4tHRVfHOqW 8Xng== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature; bh=oapksXAKGEtngDCtZfJ8woPoFQ9yeyN8nMF+K/9PDaQ=; fh=5OD0jwMRFR4efnIdM5kpeIVmjdEP+e7HhGLo0o7D1mw=; b=yDYwfEENXC7z9VORtoaEzEsFqjxQe+gAo4dsONHcJ5QPwuRupldhrh7U5OyjxwVAtT BzVsHFwsI+ItSxIFatcMl9OXCpHDO3J9uw7rVCXqoq8wHW4EkLu7w4pPkajwuVCL4j53 keMwhduPSUXgPgdFNmya868FpmgpJXvaLBW/4FftdDgkrsYE8my7RiuoZ4oKBMjgBJft aVuMtrTAUfuLrnWHdwQJelxwsa/r8KjIYrNZ6U7Ei5o8nZgVhZka6HM0lTHIRVHoM7Co R+ihvKYvqlMn7qDOiRRgtLhhBQisGv+YMkWvEKxEdgrjKSfp2tl7xOGplMHmSfv6Nux4 UJLA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OkWsDSNo; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-55317-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55317-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCX09uT5wlZX1pj0FL71hLvi4zU2bGDcyOIosmmn7K2CIFEmWrnsTy3ROZjKR6nkX2KZbF+MGovRHGYWWiML5Cuv/Nh7Ew== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id w9-20020a170902e88900b001d8e7ebba53si2014655plg.360.2024.02.06.08.56.39 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 08:56:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55317-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OkWsDSNo; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-55317-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55317-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 29176B29A62 for <ouuuleilei@gmail.com>; Tue, 6 Feb 2024 16:28:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F36361350C2; Tue, 6 Feb 2024 16:27:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OkWsDSNo" 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 4DC72134CCA for <linux-kernel@vger.kernel.org>; Tue, 6 Feb 2024 16:27:50 +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=1707236871; cv=none; b=GiaCOMR1kOUua9QHMDT/xFQ5Wq6uYh++WWI0SQWG2F1AlM3aWN9x1QNKjyx/w8X9/dltiECikGSH9iNYg9gFvjurfjJ6FoK6bs0eeYb30Bf5JKj7nxqh3ftHMeamO4MKvm8HNkk0PixRtZuURdP4wqVE/pFTyzN0j2uMB2SUtLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707236871; c=relaxed/simple; bh=fRog9coSpdrDKRPeW6Hy2Z/gSCmjUBq/+m0a/5NTav8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=WHenfj5dAC3zHA8CzPn+3XLz3zzCFEeJIfPXzQ5It9iGQ9a+tCiaugs8uwAcjxwrRhA8jrrutBaCgmix1fp6wUx7ACi+rFtRw9cK1E7jr4K4qlu+5gs2sgpgO6EoKU540IOxmMYvBgHRbkWD9UYIlciodsvqc1ketilb7jUTZ0k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OkWsDSNo; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05E20C433C7; Tue, 6 Feb 2024 16:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707236870; bh=fRog9coSpdrDKRPeW6Hy2Z/gSCmjUBq/+m0a/5NTav8=; h=From:Date:Subject:To:Cc:From; b=OkWsDSNoWY8FCQEgO0G6MAYEFLmLRO8xubuBvugziOoPoxa+xMwSX76yMmr12AuKB kDq4nVyMnVWtGMHzpaRfHUrGzzhT6psrIG9XSClj56+WQsNhVvaUU99P6DQah5GWlU gGsYkPZI/lqtNyp0AqDZY1V1GMisS08d7ECGlwwWbGC/XZvnoqJQ1ttmomFFpyc8za zD9VlzAQTImWKTEd4q7MWl9KhTA3gKPCF/rpLbsgBYjtCExQuaDtFRpqGgIzVNa2g0 fWO26Gk7/IXE4M9tSHl6nzEcewLCE6uesbB7YSyOxAB7YEaBRYumJK9xP+neZ//Ol9 9csjNBKuwt5ug== From: Mark Brown <broonie@kernel.org> Date: Tue, 06 Feb 2024 16:27:01 +0000 Subject: [PATCH] arm64/sve: Document that __SVE_VQ_MAX is much larger than needed Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240206-arm64-sve-vl-max-comment-v1-1-dddf16414412@kernel.org> X-B4-Tracking: v=1; b=H4sIANRdwmUC/x3MQQqAIBBA0avErBswMxddJVqIjTWQGhoSSHdPW r7F/xUyJaYMc1chUeHMMTQMfQf2MGEn5K0ZpJBKSKHRJK8V5kJYTvTmQRu9p3CjVuTM6MSo5QQ tvxI5fv71sr7vBw/DDWdqAAAA To: Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org> Cc: Dave Martin <Dave.Martin@arm.com>, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mark Brown <broonie@kernel.org> X-Mailer: b4 0.13-dev-0438c X-Developer-Signature: v=1; a=openpgp-sha256; l=1327; i=broonie@kernel.org; h=from:subject:message-id; bh=fRog9coSpdrDKRPeW6Hy2Z/gSCmjUBq/+m0a/5NTav8=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlwl4DLTjeWojBDQwiaeCesLKB01RBMye6iqVO9 W/87/JHKN+JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZcJeAwAKCRAk1otyXVSH 0F8KB/0dwrDLgl+VpeCMPKSQvsPK0/ZbXt8jR6xLiS04IOvrXQptZgBHtWmY/f5KIQSTdnRkHoj ksAn9CfWWvpUy91iB65q4RxXcGgSE+htmYdXM9ZxdV2RaAzTCVCyjtl6/npVzY4f91tUTx1oqXT h7QwjfMJCTjPfTHtHspOrjSA9WcBOKOqhCTsLxMlYg78TxnaJkSkiloydk3Epp7xUUcDK6JsKjX bfjBKLFnebOVearwBWJ5Dr3c4qGL8DuyQvVtQ5Ur5wu1TT7jL6IFNwu6IfVoQsalQ238+JpdS1H VG2dtOHIhTs2/EjyTMp99SfQqxjOzAw4CpymanzQw5TPUzev X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790169421771585840 X-GMAIL-MSGID: 1790169421771585840 |
Series |
arm64/sve: Document that __SVE_VQ_MAX is much larger than needed
|
|
Commit Message
Mark Brown
Feb. 6, 2024, 4:27 p.m. UTC
__SVE_VQ_MAX is defined without comment as 512 but the actual
architectural maximum is 16, a substantial difference which might not
be obvious to readers especially given the several different units used
for specifying vector sizes in various contexts and the fact that it's
often used via macros. In an effort to minimise surprises for users who
might assume the value is the architectural maximum and use it to do
things like size allocations add a comment noting the difference.
Signed-off-by: Mark Brown <broonie@kernel.org>
---
arch/arm64/include/uapi/asm/sve_context.h | 4 ++++
1 file changed, 4 insertions(+)
---
base-commit: 54be6c6c5ae8e0d93a6c4641cb7528eb0b6ba478
change-id: 20240206-arm64-sve-vl-max-comment-64efa3f03625
Best regards,
Comments
On Tue, Feb 06, 2024 at 04:27:01PM +0000, Mark Brown wrote: > __SVE_VQ_MAX is defined without comment as 512 but the actual > architectural maximum is 16, a substantial difference which might not > be obvious to readers especially given the several different units used > for specifying vector sizes in various contexts and the fact that it's > often used via macros. In an effort to minimise surprises for users who > might assume the value is the architectural maximum and use it to do > things like size allocations add a comment noting the difference. Well, the value 512 was semi-deliberately chosen to be surprising. But the point about units is valid: to the casual reader, "512" does look suspiciously like a bit count when it really really isn't... > > Signed-off-by: Mark Brown <broonie@kernel.org> > --- > arch/arm64/include/uapi/asm/sve_context.h | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/arch/arm64/include/uapi/asm/sve_context.h b/arch/arm64/include/uapi/asm/sve_context.h > index 754ab751b523..59f283f373a6 100644 > --- a/arch/arm64/include/uapi/asm/sve_context.h > +++ b/arch/arm64/include/uapi/asm/sve_context.h > @@ -13,6 +13,10 @@ > > #define __SVE_VQ_BYTES 16 /* number of bytes per quadword */ > > +/* > + * Note that for future proofing __SVE_VQ_MAX is defined much larger > + * than the actual architecture maximum of 16. > + */ I think that putting shadow #defines in comments in UAPI headers is a really bad idea... is this a normative statement about the user API, or what? My concern is that if we muddy the waters here different bits of software will do different things and we will get a mess with no advantages. Portability issues may ensue if userspace software feels it can substitute some other value for this constant, since we can't control what userspace uses it for. > #define __SVE_VQ_MIN 1 Would it be sufficient to say something like: /* * Yes, this is 512 QUADWORDS. * Never allocate memory or size structures based on the value of this * constant. */ > #define __SVE_VQ_MAX 512 Though comments might be better placed alongsize SVE_VQ_MAX at al., in ptrace.h and sigcontext.h rather than here. The leading __ should at least be a hint that __SVE_VQ_MAX shouldn't be used directly by anyone... Cheers ---Dave
On Wed, Feb 07, 2024 at 12:01:43PM +0000, Dave Martin wrote: > On Tue, Feb 06, 2024 at 04:27:01PM +0000, Mark Brown wrote: > > +/* > > + * Note that for future proofing __SVE_VQ_MAX is defined much larger > > + * than the actual architecture maximum of 16. > > + */ > I think that putting shadow #defines in comments in UAPI headers is a > really bad idea... is this a normative statement about the user API, > or what? Well, the only reason I'm mentioning the constant here is that __SVE_VQ_MIN is defined too and has a perfectly good value, things look a bit neater with a shared comment block. I'm not sure there's a hugely meaingful difference between having a comment adjacent to a named constant in a header and one a couple of lines away that mentions the constant by name. > My concern is that if we muddy the waters here different bits of > software will do different things and we will get a mess with no > advantages. > Portability issues may ensue if userspace software feels it can > substitute some other value for this constant, since we can't control > what userspace uses it for. I don't think we want people using this at all, ideally we'd remove it but it's in the uapi. > Would it be sufficient to say something like: > /* > * Yes, this is 512 QUADWORDS. > * Never allocate memory or size structures based on the value of this > * constant. > */ > > #define __SVE_VQ_MAX 512 I think the fact that this vector length is more than an order of magnitude more than is architecturally supported at present needs to be conveyed, it's perfectly reasonable for people to not want to do dynamic allocation/sizing of buffers in some applications and the above sounds more like stylistic guidance about using dynamic sizing to improve memory usage. > Though comments might be better placed alongsize SVE_VQ_MAX at al., in > ptrace.h and sigcontext.h rather than here. The leading __ should at > least be a hint that __SVE_VQ_MAX shouldn't be used directly by > anyone... Yeah, the multiple layers of indirection aren't helpful here. We probably need to comment it in both places TBH.
On Wed, Feb 07, 2024 at 12:48:58PM +0000, Mark Brown wrote: > On Wed, Feb 07, 2024 at 12:01:43PM +0000, Dave Martin wrote: > > On Tue, Feb 06, 2024 at 04:27:01PM +0000, Mark Brown wrote: > > > > +/* > > > + * Note that for future proofing __SVE_VQ_MAX is defined much larger > > > + * than the actual architecture maximum of 16. > > > + */ > > > I think that putting shadow #defines in comments in UAPI headers is a > > really bad idea... is this a normative statement about the user API, > > or what? > > Well, the only reason I'm mentioning the constant here is that > __SVE_VQ_MIN is defined too and has a perfectly good value, things look > a bit neater with a shared comment block. I'm not sure there's a hugely > meaingful difference between having a comment adjacent to a named > constant in a header and one a couple of lines away that mentions the > constant by name. It wasn't so much the exact location that concerned me, rather putting it in a UAPI header at all. Maybe so long as the comment doesn't quote a literal value for the arch max VQ that would be better. If there is a value there, we may be kind of legitimising its use even if it's in a comment... > > > My concern is that if we muddy the waters here different bits of > > software will do different things and we will get a mess with no > > advantages. > > > Portability issues may ensue if userspace software feels it can > > substitute some other value for this constant, since we can't control > > what userspace uses it for. > > I don't think we want people using this at all, ideally we'd remove it > but it's in the uapi. I think the main legitimate uses are for implementing sve_vl_valid() and for type selection purposes (analogous to the C <limits.h> constants -- though all the "obvious" types are fine so this is a but redundant). But yeah, it's there now. > > Would it be sufficient to say something like: > > > /* > > * Yes, this is 512 QUADWORDS. > > * Never allocate memory or size structures based on the value of this > > * constant. > > */ > > > #define __SVE_VQ_MAX 512 > > I think the fact that this vector length is more than an order of > magnitude more than is architecturally supported at present needs to be > conveyed, it's perfectly reasonable for people to not want to do dynamic > allocation/sizing of buffers in some applications and the above sounds > more like stylistic guidance about using dynamic sizing to improve > memory usage. I guess that's true; people need to know that they'll be allocating a silly amount of memory if they use the existing _MAX constants directly. Laziness is a perfectly good reason for doing this for development hacks that aren't going to be published, less so for code that ends up in libraries or otherwise gets into the wild... I preferred to encourage people to size dynamically, but we don't have a way to enforce it. Ideally there would be a direct way to read out the system-wide max VL to provide userspace with a sensible default allocation size, but that doesn't really exist today (though ptrace and PR_SVE_{SET,GEL}_VL provide ways to find out, but it's a bit grungy). How about something along the lines of: /* * Yes, this is 512 QUADWORDS. * To help ensure forward portability, this is much larger than the * current maximum value defined by the SVE architecture. * While arrays or static allocations can be sized based on this value, * watch out! It will waste a surprisingly large amount of memory. * Dynamic sizing based on the actual runtime vector length is likely to * be preferable for most purposes. */ > > > Though comments might be better placed alongsize SVE_VQ_MAX at al., in > > ptrace.h and sigcontext.h rather than here. The leading __ should at > > least be a hint that __SVE_VQ_MAX shouldn't be used directly by > > anyone... > > Yeah, the multiple layers of indirection aren't helpful here. We > probably need to comment it in both places TBH. Agreed, part of that came from a desire to avoid duplicating information. I think the indirection via sve_context.h was introduced to work around a bad interaction with user C library headers, but I'm a bit hazy on that now without digging through the history. Cheers ---Dave
On Wed, Feb 07, 2024 at 01:39:13PM +0000, Dave Martin wrote: > How about something along the lines of: > /* > * Yes, this is 512 QUADWORDS. > * To help ensure forward portability, this is much larger than the > * current maximum value defined by the SVE architecture. > * While arrays or static allocations can be sized based on this value, > * watch out! It will waste a surprisingly large amount of memory. > * Dynamic sizing based on the actual runtime vector length is likely to > * be preferable for most purposes. > */ That works for me. The cost of initialising can also add up in emulation.
diff --git a/arch/arm64/include/uapi/asm/sve_context.h b/arch/arm64/include/uapi/asm/sve_context.h index 754ab751b523..59f283f373a6 100644 --- a/arch/arm64/include/uapi/asm/sve_context.h +++ b/arch/arm64/include/uapi/asm/sve_context.h @@ -13,6 +13,10 @@ #define __SVE_VQ_BYTES 16 /* number of bytes per quadword */ +/* + * Note that for future proofing __SVE_VQ_MAX is defined much larger + * than the actual architecture maximum of 16. + */ #define __SVE_VQ_MIN 1 #define __SVE_VQ_MAX 512