All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Eric Biederman <ebiederm@xmission.com>,
	Kees Cook <keescook@chromium.org>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>,
	Szabolcs Nagy <szabolcs.nagy@arm.com>,
	linux-arm-kernel@lists.infradead.org,
	Mark Brown <broonie@kernel.org>
Subject: [PATCH v2 3/4] arm64/cpufeature: Support AT_HWCAP3
Date: Mon, 20 Jun 2022 13:54:50 +0100	[thread overview]
Message-ID: <20220620125451.653507-4-broonie@kernel.org> (raw)
In-Reply-To: <20220620125451.653507-1-broonie@kernel.org>

We have filled the low 32 bits of both AT_HWCAP and AT_HWCAP2 so in order
to support further architecture features we must either start allocating
from the upper 32 bits or add a new AT_HWCAP3. Feedback from the glibc
developers was that AT_HWCAP3 would be cleaner so go with that.

This patch merely adds the glue required for AT_HWCAP3, meaning that we
start providing AT_HWCAP3 for ELF executables but no bits will be set in
it.

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

diff --git a/Documentation/arm64/elf_hwcaps.rst b/Documentation/arm64/elf_hwcaps.rst
index 3d116fb536c5..5f4d89c4afe2 100644
--- a/Documentation/arm64/elf_hwcaps.rst
+++ b/Documentation/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 auxilliary 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 84756c660b5e..901cf318a556 100644
--- a/arch/arm64/include/asm/cpufeature.h
+++ b/arch/arm64/include/asm/cpufeature.h
@@ -13,7 +13,7 @@
 
 /* Note that bits 62 and 63 of each AT_HWCAP are reserved */
 #define CPU_FEATURES_PER_HWCAP	32
-#define MAX_CPU_FEATURES	64
+#define MAX_CPU_FEATURES	96
 #define cpu_feature(x)		KERNEL_HWCAP_ ## x
 
 #ifndef __ASSEMBLY__
@@ -436,6 +436,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 e0054c7b3a98..1ef208ab6895 100644
--- a/arch/arm64/include/asm/hwcap.h
+++ b/arch/arm64/include/asm/hwcap.h
@@ -44,10 +44,11 @@
 #define KHWCAP_OFFSET(n)		((n - 1) * CPU_FEATURES_PER_HWCAP)
 
 /*
- * For userspace we represent hwcaps as a collection of HWCAP{,2}_x bitfields
- * as described in uapi/asm/hwcap.h. For the kernel we represent hwcaps as
- * natural numbers (in a single range of size MAX_CPU_FEATURES) defined here
- * with prefix KERNEL_HWCAP_ mapped to their HWCAP{,2}_x counterpart.
+ * For userspace we represent hwcaps as a collection of HWCAP{,[23]}_x
+ * bitfields as described in uapi/asm/hwcap.h. For the kernel we
+ * represent hwcaps as natural numbers (in a single range of size
+ * MAX_CPU_FEATURES) defined here with prefix KERNEL_HWCAP_ mapped to
+ * their HWCAP{,2}_x counterpart.
  *
  * Hwcaps should be set and tested within the kernel via the
  * cpu_{set,have}_named_feature(feature) where feature is the unique suffix
@@ -121,12 +122,15 @@
 #define KERNEL_HWCAP_SME_FA64		__khwcap2_feature(SME_FA64)
 #define KERNEL_HWCAP_WFXT		__khwcap2_feature(WFXT)
 
+#define __khwcap3_feature(x)		(const_ilog2(HWCAP3_ ## x) + KHWCAP_OFFSET(3))
+
 /*
  * 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)
diff --git a/arch/arm64/include/uapi/asm/hwcap.h b/arch/arm64/include/uapi/asm/hwcap.h
index 4bb2cc8ac446..7b818f8fc01b 100644
--- a/arch/arm64/include/uapi/asm/hwcap.h
+++ b/arch/arm64/include/uapi/asm/hwcap.h
@@ -89,4 +89,8 @@
 #define HWCAP2_SME_FA64		(1 << 30)
 #define HWCAP2_WFXT		(1UL << 31)
 
+/*
+ * 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 1a8f60a6661e..7605b213d9db 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -3132,6 +3132,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_system_capabilities(void)
 {
 	/*
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2022-06-20 13:22 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20 12:54 [PATCH v2 0/4] arm64: Add AT_HWCAP3 Mark Brown
2022-06-20 12:54 ` [PATCH v2 1/4] arm64/cpufeature: Store elf_hwcaps as an array rather than unsigned long Mark Brown
2022-06-28 14:21   ` Will Deacon
2022-06-28 15:06     ` Mark Brown
2022-06-29 10:01       ` Szabolcs Nagy
2022-06-29 11:44         ` Mark Brown
2022-06-29 12:06           ` Szabolcs Nagy
2022-06-29 13:55         ` Catalin Marinas
2022-06-29 15:07           ` Mark Brown
2022-06-20 12:54 ` [PATCH v2 2/4] elf: Allow architectures to provide AT_HWCAP3 Mark Brown
2022-06-20 12:54 ` Mark Brown [this message]
2022-06-20 12:54 ` [PATCH v2 4/4] arm64/hwcap: Support FEAT_EBF16 Mark Brown
2022-07-05 17:53 ` [PATCH v2 0/4] arm64: Add AT_HWCAP3 Mark Brown
2022-07-06  9:02   ` Szabolcs Nagy
2022-07-06 10:08   ` Marc Zyngier
2022-07-06 13:48     ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220620125451.653507-4-broonie@kernel.org \
    --to=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=ebiederm@xmission.com \
    --cc=keescook@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=suzuki.poulose@arm.com \
    --cc=szabolcs.nagy@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.