linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC v2 0/2] arm64: Add infrastructure for use of AT_HWCAP3
@ 2024-10-04 20:26 Mark Brown
  2024-10-04 20:26 ` [PATCH RFC v2 1/2] binfmt_elf: Wire up AT_HWCAP3 at AT_HWCAP4 Mark Brown
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Mark Brown @ 2024-10-04 20:26 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, Jan Kara, Eric Biederman,
	Kees Cook, Catalin Marinas, Will Deacon, Jonathan Corbet
  Cc: linux-fsdevel, linux-mm, linux-kernel, Yury Khrustalev,
	Wilco Dijkstra, linux-arm-kernel, linux-doc, Mark Brown

Since arm64 has now used all of AT_HWCAP2 it needs to either start using
AT_HWCAP3 (which was recently added for PowerPC) or start allocating
bits 32..61 of AT_HWCAP first.  Those are documented in elf_hwcaps.rst
as unused and in uapi/asm/hwcap.h as unallocated for potential use by
libc, glibc does currently use bits 62 and 63.  This series has the code
for enabling AT_HWCAP3 as a reference.

While we've decided to go with using the high bits of AT_HWCAP for now
we will exhaust those at some point so it seems helpful to have this
code available in order to make life easier when we do need to start
using AT_HWCAP3.  This seems like it might come up relatively quickly,
for the past few years the dpISA has used ~15 hwcaps due to the fine
grained feature definitions and the fact that SVE and SME need
independent definitions of everything. When we do start using HWCAP3
we'll potentially have multiple serieses that need to share the addition
so it seems like it might be helpful to have the scaffolding in place
at least the release before it's actuallly required in order to make
things more managable. That's not an issue *now* but could come up
surprisingly quickly.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
Changes in v2:
- Rebase onto v6.12-rc1.
- Fix cut'n'paste 3/4 issues.
- Link to v1: https://lore.kernel.org/r/20240906-arm64-elf-hwcap3-v1-0-8df1a5e63508@kernel.org

---
Mark Brown (2):
      binfmt_elf: Wire up AT_HWCAP3 at AT_HWCAP4
      arm64: Support AT_HWCAP3

 Documentation/arch/arm64/elf_hwcaps.rst |  6 +++---
 arch/arm64/include/asm/cpufeature.h     |  3 ++-
 arch/arm64/include/asm/hwcap.h          |  6 +++++-
 arch/arm64/include/uapi/asm/hwcap.h     |  4 ++++
 arch/arm64/kernel/cpufeature.c          |  6 ++++++
 fs/binfmt_elf.c                         |  6 ++++++
 fs/binfmt_elf_fdpic.c                   |  6 ++++++
 fs/compat_binfmt_elf.c                  | 10 ++++++++++
 8 files changed, 42 insertions(+), 5 deletions(-)
---
base-commit: 9852d85ec9d492ebef56dc5f229416c925758edc
change-id: 20240905-arm64-elf-hwcap3-7709c5593d34

Best regards,
-- 
Mark Brown <broonie@kernel.org>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH RFC v2 1/2] binfmt_elf: Wire up AT_HWCAP3 at AT_HWCAP4
  2024-10-04 20:26 [PATCH RFC v2 0/2] arm64: Add infrastructure for use of AT_HWCAP3 Mark Brown
@ 2024-10-04 20:26 ` Mark Brown
  2024-10-05  0:22   ` Kees Cook
  2024-10-08  7:03   ` Anshuman Khandual
  2024-10-04 20:26 ` [PATCH RFC v2 2/2] arm64: Support AT_HWCAP3 Mark Brown
  2024-10-17 17:58 ` [PATCH RFC v2 0/2] arm64: Add infrastructure for use of AT_HWCAP3 Catalin Marinas
  2 siblings, 2 replies; 8+ messages in thread
From: Mark Brown @ 2024-10-04 20:26 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, Jan Kara, Eric Biederman,
	Kees Cook, Catalin Marinas, Will Deacon, Jonathan Corbet
  Cc: linux-fsdevel, linux-mm, linux-kernel, Yury Khrustalev,
	Wilco Dijkstra, linux-arm-kernel, linux-doc, Mark Brown

AT_HWCAP3 and AT_HWCAP4 were recently defined for use on PowerPC in commit
3281366a8e79 ("uapi/auxvec: Define AT_HWCAP3 and AT_HWCAP4 aux vector,
entries"). Since we want to start using AT_HWCAP3 on arm64 add support for
exposing both these new hwcaps via binfmt_elf.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 fs/binfmt_elf.c        |  6 ++++++
 fs/binfmt_elf_fdpic.c  |  6 ++++++
 fs/compat_binfmt_elf.c | 10 ++++++++++
 3 files changed, 22 insertions(+)

diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 06dc4a57ba78a7939bbde96bf181eefa950ea13a..3039a6b7aba4bd38f26e21b626b579cc03f3a03e 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -257,6 +257,12 @@ create_elf_tables(struct linux_binprm *bprm, const struct elfhdr *exec,
 	NEW_AUX_ENT(AT_RANDOM, (elf_addr_t)(unsigned long)u_rand_bytes);
 #ifdef ELF_HWCAP2
 	NEW_AUX_ENT(AT_HWCAP2, ELF_HWCAP2);
+#endif
+#ifdef ELF_HWCAP3
+	NEW_AUX_ENT(AT_HWCAP3, ELF_HWCAP3);
+#endif
+#ifdef ELF_HWCAP4
+	NEW_AUX_ENT(AT_HWCAP4, ELF_HWCAP4);
 #endif
 	NEW_AUX_ENT(AT_EXECFN, bprm->exec);
 	if (k_platform) {
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index 4fe5bb9f1b1f5e0be6e8d1ef5b20492935b90633..31d253bd3961a8679678c600f4346bba23502598 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -623,6 +623,12 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,
 	NEW_AUX_ENT(AT_HWCAP,	ELF_HWCAP);
 #ifdef ELF_HWCAP2
 	NEW_AUX_ENT(AT_HWCAP2,	ELF_HWCAP2);
+#endif
+#ifdef ELF_HWCAP3
+	NEW_AUX_ENT(AT_HWCAP3,	ELF_HWCAP3);
+#endif
+#ifdef ELF_HWCAP4
+	NEW_AUX_ENT(AT_HWCAP4,	ELF_HWCAP4);
 #endif
 	NEW_AUX_ENT(AT_PAGESZ,	PAGE_SIZE);
 	NEW_AUX_ENT(AT_CLKTCK,	CLOCKS_PER_SEC);
diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
index 8f0af4f626316ed2e92204ff9bf381cd14103ae9..d5ef5469e4e620f6ee97f40ce9cbbfa48e37e33c 100644
--- a/fs/compat_binfmt_elf.c
+++ b/fs/compat_binfmt_elf.c
@@ -80,6 +80,16 @@
 #define	ELF_HWCAP2		COMPAT_ELF_HWCAP2
 #endif
 
+#ifdef	COMPAT_ELF_HWCAP3
+#undef	ELF_HWCAP3
+#define	ELF_HWCAP3		COMPAT_ELF_HWCAP3
+#endif
+
+#ifdef	COMPAT_ELF_HWCAP4
+#undef	ELF_HWCAP4
+#define	ELF_HWCAP4		COMPAT_ELF_HWCAP4
+#endif
+
 #ifdef	COMPAT_ARCH_DLINFO
 #undef	ARCH_DLINFO
 #define	ARCH_DLINFO		COMPAT_ARCH_DLINFO

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH RFC v2 2/2] arm64: Support AT_HWCAP3
  2024-10-04 20:26 [PATCH RFC v2 0/2] arm64: Add infrastructure for use of AT_HWCAP3 Mark Brown
  2024-10-04 20:26 ` [PATCH RFC v2 1/2] binfmt_elf: Wire up AT_HWCAP3 at AT_HWCAP4 Mark Brown
@ 2024-10-04 20:26 ` Mark Brown
  2024-10-08  7:15   ` Anshuman Khandual
  2024-10-17 17:58 ` [PATCH RFC v2 0/2] arm64: Add infrastructure for use of AT_HWCAP3 Catalin Marinas
  2 siblings, 1 reply; 8+ messages in thread
From: Mark Brown @ 2024-10-04 20:26 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, Jan Kara, Eric Biederman,
	Kees Cook, Catalin Marinas, Will Deacon, Jonathan Corbet
  Cc: linux-fsdevel, linux-mm, linux-kernel, Yury Khrustalev,
	Wilco Dijkstra, linux-arm-kernel, linux-doc, Mark Brown

We have filled all 64 bits of AT_HWCAP2 so in order to support discovery of
further features provide the framework to use the already defined AT_HWCAP3
for further CPU features.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 Documentation/arch/arm64/elf_hwcaps.rst | 6 +++---
 arch/arm64/include/asm/cpufeature.h     | 3 ++-
 arch/arm64/include/asm/hwcap.h          | 6 +++++-
 arch/arm64/include/uapi/asm/hwcap.h     | 4 ++++
 arch/arm64/kernel/cpufeature.c          | 6 ++++++
 5 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/Documentation/arch/arm64/elf_hwcaps.rst b/Documentation/arch/arm64/elf_hwcaps.rst
index 694f67fa07d196816b1292e896ebe6a1b599c125..dc1b11d6d1122bba928b054cd1874aad5073e05c 100644
--- a/Documentation/arch/arm64/elf_hwcaps.rst
+++ b/Documentation/arch/arm64/elf_hwcaps.rst
@@ -16,9 +16,9 @@ architected discovery mechanism available to userspace code at EL0. The
 kernel exposes the presence of these features to userspace through a set
 of flags called hwcaps, exposed in the auxiliary vector.
 
-Userspace software can test for features by acquiring the AT_HWCAP or
-AT_HWCAP2 entry of the auxiliary vector, and testing whether the relevant
-flags are set, e.g.::
+Userspace software can test for features by acquiring the AT_HWCAP,
+AT_HWCAP2 or AT_HWCAP3 entry of the auxiliary vector, and testing
+whether the relevant flags are set, e.g.::
 
 	bool floating_point_is_present(void)
 	{
diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
index 3d261cc123c1e22ac7bc9cfcde463624c76b2084..38e7d1a44ea38ab0a06a6f22824ae023b128721b 100644
--- a/arch/arm64/include/asm/cpufeature.h
+++ b/arch/arm64/include/asm/cpufeature.h
@@ -12,7 +12,7 @@
 #include <asm/hwcap.h>
 #include <asm/sysreg.h>
 
-#define MAX_CPU_FEATURES	128
+#define MAX_CPU_FEATURES	192
 #define cpu_feature(x)		KERNEL_HWCAP_ ## x
 
 #define ARM64_SW_FEATURE_OVERRIDE_NOKASLR	0
@@ -438,6 +438,7 @@ void cpu_set_feature(unsigned int num);
 bool cpu_have_feature(unsigned int num);
 unsigned long cpu_get_elf_hwcap(void);
 unsigned long cpu_get_elf_hwcap2(void);
+unsigned long cpu_get_elf_hwcap3(void);
 
 #define cpu_set_named_feature(name) cpu_set_feature(cpu_feature(name))
 #define cpu_have_named_feature(name) cpu_have_feature(cpu_feature(name))
diff --git a/arch/arm64/include/asm/hwcap.h b/arch/arm64/include/asm/hwcap.h
index a775adddecf25633e87d58fb9ac9e6293beac1b3..3b5c50df419ee94193a4d9e3a47516eb0739e89a 100644
--- a/arch/arm64/include/asm/hwcap.h
+++ b/arch/arm64/include/asm/hwcap.h
@@ -159,17 +159,21 @@
 #define KERNEL_HWCAP_SME_SF8DP2		__khwcap2_feature(SME_SF8DP2)
 #define KERNEL_HWCAP_POE		__khwcap2_feature(POE)
 
+#define __khwcap3_feature(x)		(const_ilog2(HWCAP3_ ## x) + 128)
+
 /*
  * This yields a mask that user programs can use to figure out what
  * instruction set this cpu supports.
  */
 #define ELF_HWCAP		cpu_get_elf_hwcap()
 #define ELF_HWCAP2		cpu_get_elf_hwcap2()
+#define ELF_HWCAP3		cpu_get_elf_hwcap3()
 
 #ifdef CONFIG_COMPAT
 #define COMPAT_ELF_HWCAP	(compat_elf_hwcap)
 #define COMPAT_ELF_HWCAP2	(compat_elf_hwcap2)
-extern unsigned int compat_elf_hwcap, compat_elf_hwcap2;
+#define COMPAT_ELF_HWCAP3	(compat_elf_hwcap3)
+extern unsigned int compat_elf_hwcap, compat_elf_hwcap2, compat_elf_hwcap3;
 #endif
 
 enum {
diff --git a/arch/arm64/include/uapi/asm/hwcap.h b/arch/arm64/include/uapi/asm/hwcap.h
index 055381b2c61595361c2d57d38be936c2dfeaa195..3dd4a53a438a14bfb41882b2ab15bdd7ce617475 100644
--- a/arch/arm64/include/uapi/asm/hwcap.h
+++ b/arch/arm64/include/uapi/asm/hwcap.h
@@ -124,4 +124,8 @@
 #define HWCAP2_SME_SF8DP2	(1UL << 62)
 #define HWCAP2_POE		(1UL << 63)
 
+/*
+ * HWCAP3 flags - for AT_HWCAP3
+ */
+
 #endif /* _UAPI__ASM_HWCAP_H */
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 718728a85430fad5151b73fa213a510efac3f834..7221636b790709b153b49126e00246cc3032a7bc 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -103,6 +103,7 @@ static DECLARE_BITMAP(elf_hwcap, MAX_CPU_FEATURES) __read_mostly;
 				 COMPAT_HWCAP_LPAE)
 unsigned int compat_elf_hwcap __read_mostly = COMPAT_ELF_HWCAP_DEFAULT;
 unsigned int compat_elf_hwcap2 __read_mostly;
+unsigned int compat_elf_hwcap3 __read_mostly;
 #endif
 
 DECLARE_BITMAP(system_cpucaps, ARM64_NCAPS);
@@ -3499,6 +3500,11 @@ unsigned long cpu_get_elf_hwcap2(void)
 	return elf_hwcap[1];
 }
 
+unsigned long cpu_get_elf_hwcap3(void)
+{
+	return elf_hwcap[2];
+}
+
 static void __init setup_boot_cpu_capabilities(void)
 {
 	/*

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH RFC v2 1/2] binfmt_elf: Wire up AT_HWCAP3 at AT_HWCAP4
  2024-10-04 20:26 ` [PATCH RFC v2 1/2] binfmt_elf: Wire up AT_HWCAP3 at AT_HWCAP4 Mark Brown
@ 2024-10-05  0:22   ` Kees Cook
  2024-10-08  7:03   ` Anshuman Khandual
  1 sibling, 0 replies; 8+ messages in thread
From: Kees Cook @ 2024-10-05  0:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Alexander Viro, Christian Brauner, Jan Kara, Eric Biederman,
	Catalin Marinas, Will Deacon, Jonathan Corbet, linux-fsdevel,
	linux-mm, linux-kernel, Yury Khrustalev, Wilco Dijkstra,
	linux-arm-kernel, linux-doc

On Fri, Oct 04, 2024 at 09:26:29PM +0100, Mark Brown wrote:
> AT_HWCAP3 and AT_HWCAP4 were recently defined for use on PowerPC in commit
> 3281366a8e79 ("uapi/auxvec: Define AT_HWCAP3 and AT_HWCAP4 aux vector,
> entries"). Since we want to start using AT_HWCAP3 on arm64 add support for

(Side note: I wonder what auxvec 29 and 30 used to be?)

> exposing both these new hwcaps via binfmt_elf.

This seems fine to me, feel free to carry this via the arm64 tree.

Acked-by: Kees Cook <kees@kernel.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH RFC v2 1/2] binfmt_elf: Wire up AT_HWCAP3 at AT_HWCAP4
  2024-10-04 20:26 ` [PATCH RFC v2 1/2] binfmt_elf: Wire up AT_HWCAP3 at AT_HWCAP4 Mark Brown
  2024-10-05  0:22   ` Kees Cook
@ 2024-10-08  7:03   ` Anshuman Khandual
  1 sibling, 0 replies; 8+ messages in thread
From: Anshuman Khandual @ 2024-10-08  7:03 UTC (permalink / raw)
  To: Mark Brown, Alexander Viro, Christian Brauner, Jan Kara,
	Eric Biederman, Kees Cook, Catalin Marinas, Will Deacon,
	Jonathan Corbet
  Cc: linux-fsdevel, linux-mm, linux-kernel, Yury Khrustalev,
	Wilco Dijkstra, linux-arm-kernel, linux-doc



On 10/5/24 01:56, Mark Brown wrote:
> AT_HWCAP3 and AT_HWCAP4 were recently defined for use on PowerPC in commit
> 3281366a8e79 ("uapi/auxvec: Define AT_HWCAP3 and AT_HWCAP4 aux vector,
> entries"). Since we want to start using AT_HWCAP3 on arm64 add support for
> exposing both these new hwcaps via binfmt_elf.
> 
> Signed-off-by: Mark Brown <broonie@kernel.org>
> ---
>  fs/binfmt_elf.c        |  6 ++++++
>  fs/binfmt_elf_fdpic.c  |  6 ++++++
>  fs/compat_binfmt_elf.c | 10 ++++++++++
>  3 files changed, 22 insertions(+)
> 
> diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
> index 06dc4a57ba78a7939bbde96bf181eefa950ea13a..3039a6b7aba4bd38f26e21b626b579cc03f3a03e 100644
> --- a/fs/binfmt_elf.c
> +++ b/fs/binfmt_elf.c
> @@ -257,6 +257,12 @@ create_elf_tables(struct linux_binprm *bprm, const struct elfhdr *exec,
>  	NEW_AUX_ENT(AT_RANDOM, (elf_addr_t)(unsigned long)u_rand_bytes);
>  #ifdef ELF_HWCAP2
>  	NEW_AUX_ENT(AT_HWCAP2, ELF_HWCAP2);
> +#endif
> +#ifdef ELF_HWCAP3
> +	NEW_AUX_ENT(AT_HWCAP3, ELF_HWCAP3);
> +#endif
> +#ifdef ELF_HWCAP4
> +	NEW_AUX_ENT(AT_HWCAP4, ELF_HWCAP4);
>  #endif
>  	NEW_AUX_ENT(AT_EXECFN, bprm->exec);
>  	if (k_platform) {
> diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
> index 4fe5bb9f1b1f5e0be6e8d1ef5b20492935b90633..31d253bd3961a8679678c600f4346bba23502598 100644
> --- a/fs/binfmt_elf_fdpic.c
> +++ b/fs/binfmt_elf_fdpic.c
> @@ -623,6 +623,12 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,
>  	NEW_AUX_ENT(AT_HWCAP,	ELF_HWCAP);
>  #ifdef ELF_HWCAP2
>  	NEW_AUX_ENT(AT_HWCAP2,	ELF_HWCAP2);
> +#endif
> +#ifdef ELF_HWCAP3
> +	NEW_AUX_ENT(AT_HWCAP3,	ELF_HWCAP3);
> +#endif
> +#ifdef ELF_HWCAP4
> +	NEW_AUX_ENT(AT_HWCAP4,	ELF_HWCAP4);
>  #endif
>  	NEW_AUX_ENT(AT_PAGESZ,	PAGE_SIZE);
>  	NEW_AUX_ENT(AT_CLKTCK,	CLOCKS_PER_SEC);
> diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
> index 8f0af4f626316ed2e92204ff9bf381cd14103ae9..d5ef5469e4e620f6ee97f40ce9cbbfa48e37e33c 100644
> --- a/fs/compat_binfmt_elf.c
> +++ b/fs/compat_binfmt_elf.c
> @@ -80,6 +80,16 @@
>  #define	ELF_HWCAP2		COMPAT_ELF_HWCAP2
>  #endif
>  
> +#ifdef	COMPAT_ELF_HWCAP3
> +#undef	ELF_HWCAP3
> +#define	ELF_HWCAP3		COMPAT_ELF_HWCAP3
> +#endif
> +
> +#ifdef	COMPAT_ELF_HWCAP4
> +#undef	ELF_HWCAP4
> +#define	ELF_HWCAP4		COMPAT_ELF_HWCAP4
> +#endif
> +
>  #ifdef	COMPAT_ARCH_DLINFO
>  #undef	ARCH_DLINFO
>  #define	ARCH_DLINFO		COMPAT_ARCH_DLINFO
> 

Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH RFC v2 2/2] arm64: Support AT_HWCAP3
  2024-10-04 20:26 ` [PATCH RFC v2 2/2] arm64: Support AT_HWCAP3 Mark Brown
@ 2024-10-08  7:15   ` Anshuman Khandual
  2024-10-08 10:04     ` Mark Brown
  0 siblings, 1 reply; 8+ messages in thread
From: Anshuman Khandual @ 2024-10-08  7:15 UTC (permalink / raw)
  To: Mark Brown, Alexander Viro, Christian Brauner, Jan Kara,
	Eric Biederman, Kees Cook, Catalin Marinas, Will Deacon,
	Jonathan Corbet
  Cc: linux-fsdevel, linux-mm, linux-kernel, Yury Khrustalev,
	Wilco Dijkstra, linux-arm-kernel, linux-doc



On 10/5/24 01:56, Mark Brown wrote:
> We have filled all 64 bits of AT_HWCAP2 so in order to support discovery of
> further features provide the framework to use the already defined AT_HWCAP3
> for further CPU features.
> 
> Signed-off-by: Mark Brown <broonie@kernel.org>
> ---
>  Documentation/arch/arm64/elf_hwcaps.rst | 6 +++---
>  arch/arm64/include/asm/cpufeature.h     | 3 ++-
>  arch/arm64/include/asm/hwcap.h          | 6 +++++-
>  arch/arm64/include/uapi/asm/hwcap.h     | 4 ++++
>  arch/arm64/kernel/cpufeature.c          | 6 ++++++
>  5 files changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/Documentation/arch/arm64/elf_hwcaps.rst b/Documentation/arch/arm64/elf_hwcaps.rst
> index 694f67fa07d196816b1292e896ebe6a1b599c125..dc1b11d6d1122bba928b054cd1874aad5073e05c 100644
> --- a/Documentation/arch/arm64/elf_hwcaps.rst
> +++ b/Documentation/arch/arm64/elf_hwcaps.rst
> @@ -16,9 +16,9 @@ architected discovery mechanism available to userspace code at EL0. The
>  kernel exposes the presence of these features to userspace through a set
>  of flags called hwcaps, exposed in the auxiliary vector.
>  
> -Userspace software can test for features by acquiring the AT_HWCAP or
> -AT_HWCAP2 entry of the auxiliary vector, and testing whether the relevant
> -flags are set, e.g.::
> +Userspace software can test for features by acquiring the AT_HWCAP,
> +AT_HWCAP2 or AT_HWCAP3 entry of the auxiliary vector, and testing
> +whether the relevant flags are set, e.g.::
>  
>  	bool floating_point_is_present(void)
>  	{
> diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
> index 3d261cc123c1e22ac7bc9cfcde463624c76b2084..38e7d1a44ea38ab0a06a6f22824ae023b128721b 100644
> --- a/arch/arm64/include/asm/cpufeature.h
> +++ b/arch/arm64/include/asm/cpufeature.h
> @@ -12,7 +12,7 @@
>  #include <asm/hwcap.h>
>  #include <asm/sysreg.h>
>  
> -#define MAX_CPU_FEATURES	128
> +#define MAX_CPU_FEATURES	192
>  #define cpu_feature(x)		KERNEL_HWCAP_ ## x
>  
>  #define ARM64_SW_FEATURE_OVERRIDE_NOKASLR	0
> @@ -438,6 +438,7 @@ void cpu_set_feature(unsigned int num);
>  bool cpu_have_feature(unsigned int num);
>  unsigned long cpu_get_elf_hwcap(void);
>  unsigned long cpu_get_elf_hwcap2(void);
> +unsigned long cpu_get_elf_hwcap3(void);
>  
>  #define cpu_set_named_feature(name) cpu_set_feature(cpu_feature(name))
>  #define cpu_have_named_feature(name) cpu_have_feature(cpu_feature(name))
> diff --git a/arch/arm64/include/asm/hwcap.h b/arch/arm64/include/asm/hwcap.h
> index a775adddecf25633e87d58fb9ac9e6293beac1b3..3b5c50df419ee94193a4d9e3a47516eb0739e89a 100644
> --- a/arch/arm64/include/asm/hwcap.h
> +++ b/arch/arm64/include/asm/hwcap.h
> @@ -159,17 +159,21 @@
>  #define KERNEL_HWCAP_SME_SF8DP2		__khwcap2_feature(SME_SF8DP2)
>  #define KERNEL_HWCAP_POE		__khwcap2_feature(POE)
>  
> +#define __khwcap3_feature(x)		(const_ilog2(HWCAP3_ ## x) + 128)
> +
>  /*
>   * This yields a mask that user programs can use to figure out what
>   * instruction set this cpu supports.
>   */
>  #define ELF_HWCAP		cpu_get_elf_hwcap()
>  #define ELF_HWCAP2		cpu_get_elf_hwcap2()
> +#define ELF_HWCAP3		cpu_get_elf_hwcap3()
>  
>  #ifdef CONFIG_COMPAT
>  #define COMPAT_ELF_HWCAP	(compat_elf_hwcap)
>  #define COMPAT_ELF_HWCAP2	(compat_elf_hwcap2)
> -extern unsigned int compat_elf_hwcap, compat_elf_hwcap2;
> +#define COMPAT_ELF_HWCAP3	(compat_elf_hwcap3)
> +extern unsigned int compat_elf_hwcap, compat_elf_hwcap2, compat_elf_hwcap3;
>  #endif
>  
>  enum {
> diff --git a/arch/arm64/include/uapi/asm/hwcap.h b/arch/arm64/include/uapi/asm/hwcap.h
> index 055381b2c61595361c2d57d38be936c2dfeaa195..3dd4a53a438a14bfb41882b2ab15bdd7ce617475 100644
> --- a/arch/arm64/include/uapi/asm/hwcap.h
> +++ b/arch/arm64/include/uapi/asm/hwcap.h
> @@ -124,4 +124,8 @@
>  #define HWCAP2_SME_SF8DP2	(1UL << 62)
>  #define HWCAP2_POE		(1UL << 63)
>  
> +/*
> + * HWCAP3 flags - for AT_HWCAP3
> + */
> +
>  #endif /* _UAPI__ASM_HWCAP_H */
> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
> index 718728a85430fad5151b73fa213a510efac3f834..7221636b790709b153b49126e00246cc3032a7bc 100644
> --- a/arch/arm64/kernel/cpufeature.c
> +++ b/arch/arm64/kernel/cpufeature.c
> @@ -103,6 +103,7 @@ static DECLARE_BITMAP(elf_hwcap, MAX_CPU_FEATURES) __read_mostly;
>  				 COMPAT_HWCAP_LPAE)
>  unsigned int compat_elf_hwcap __read_mostly = COMPAT_ELF_HWCAP_DEFAULT;
>  unsigned int compat_elf_hwcap2 __read_mostly;
> +unsigned int compat_elf_hwcap3 __read_mostly;
>  #endif
>  
>  DECLARE_BITMAP(system_cpucaps, ARM64_NCAPS);
> @@ -3499,6 +3500,11 @@ unsigned long cpu_get_elf_hwcap2(void)
>  	return elf_hwcap[1];
>  }
>  
> +unsigned long cpu_get_elf_hwcap3(void)
> +{
> +	return elf_hwcap[2];
> +}
> +
>  static void __init setup_boot_cpu_capabilities(void)
>  {
>  	/*
> 

LGTM, but just curious do you have a upcoming feature to be added
in AT_HWCAP3 soon ?

Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH RFC v2 2/2] arm64: Support AT_HWCAP3
  2024-10-08  7:15   ` Anshuman Khandual
@ 2024-10-08 10:04     ` Mark Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2024-10-08 10:04 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: Alexander Viro, Christian Brauner, Jan Kara, Eric Biederman,
	Kees Cook, Catalin Marinas, Will Deacon, Jonathan Corbet,
	linux-fsdevel, linux-mm, linux-kernel, Yury Khrustalev,
	Wilco Dijkstra, linux-arm-kernel, linux-doc

[-- Attachment #1: Type: text/plain, Size: 783 bytes --]

On Tue, Oct 08, 2024 at 12:45:42PM +0530, Anshuman Khandual wrote:
> On 10/5/24 01:56, Mark Brown wrote:

> > +unsigned long cpu_get_elf_hwcap3(void)
> > +{
> > +	return elf_hwcap[2];
> > +}
> > +
> >  static void __init setup_boot_cpu_capabilities(void)
> >  {
> >  	/*

> LGTM, but just curious do you have a upcoming feature to be added
> in AT_HWCAP3 soon ?

We've filled AT_HWCAP2 already and are starting on the free bits in
AT_HWCAP, there's only 29 of those remaining and we get things like the
dpISA releases often burning through 15 at a time.  Like the cover says
it's not a pressing issue at this minute but whenever it does become a
pressing issue there's likely to be multiple extensions in flight and
it'll help not to have them all trying to carry the same serieses.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH RFC v2 0/2] arm64: Add infrastructure for use of AT_HWCAP3
  2024-10-04 20:26 [PATCH RFC v2 0/2] arm64: Add infrastructure for use of AT_HWCAP3 Mark Brown
  2024-10-04 20:26 ` [PATCH RFC v2 1/2] binfmt_elf: Wire up AT_HWCAP3 at AT_HWCAP4 Mark Brown
  2024-10-04 20:26 ` [PATCH RFC v2 2/2] arm64: Support AT_HWCAP3 Mark Brown
@ 2024-10-17 17:58 ` Catalin Marinas
  2 siblings, 0 replies; 8+ messages in thread
From: Catalin Marinas @ 2024-10-17 17:58 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, Jan Kara, Eric Biederman,
	Kees Cook, Will Deacon, Jonathan Corbet, Mark Brown
  Cc: linux-fsdevel, linux-mm, linux-kernel, Yury Khrustalev,
	Wilco Dijkstra, linux-arm-kernel, linux-doc

On Fri, 04 Oct 2024 21:26:28 +0100, Mark Brown wrote:
> Since arm64 has now used all of AT_HWCAP2 it needs to either start using
> AT_HWCAP3 (which was recently added for PowerPC) or start allocating
> bits 32..61 of AT_HWCAP first.  Those are documented in elf_hwcaps.rst
> as unused and in uapi/asm/hwcap.h as unallocated for potential use by
> libc, glibc does currently use bits 62 and 63.  This series has the code
> for enabling AT_HWCAP3 as a reference.
> 
> [...]

Applied to arm64 (for-next/hwcap3), thanks! I decided to queue this now
as we seem to burn through about 15 hwcaps at a time with features like
dpISA. It gives libcs out there a bit of time to wire it up.

[1/2] binfmt_elf: Wire up AT_HWCAP3 at AT_HWCAP4
      https://git.kernel.org/arm64/c/4e6e8c2b757f
[2/2] arm64: Support AT_HWCAP3
      https://git.kernel.org/arm64/c/ddadbcdaaed5

-- 
Catalin


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-10-17 17:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-04 20:26 [PATCH RFC v2 0/2] arm64: Add infrastructure for use of AT_HWCAP3 Mark Brown
2024-10-04 20:26 ` [PATCH RFC v2 1/2] binfmt_elf: Wire up AT_HWCAP3 at AT_HWCAP4 Mark Brown
2024-10-05  0:22   ` Kees Cook
2024-10-08  7:03   ` Anshuman Khandual
2024-10-04 20:26 ` [PATCH RFC v2 2/2] arm64: Support AT_HWCAP3 Mark Brown
2024-10-08  7:15   ` Anshuman Khandual
2024-10-08 10:04     ` Mark Brown
2024-10-17 17:58 ` [PATCH RFC v2 0/2] arm64: Add infrastructure for use of AT_HWCAP3 Catalin Marinas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).