Skip to contentSkip to conversation

RISC-V: Only provide the single-letter extensions in HWCAP

PATCH Applied Palmer Dabbelt 3 participants 3 messages Feb 2, 2023 – Feb 22, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RISC-V: Only provide the single-letter extensions in HWCAP

The recent refactoring led to us leaking some HWCAP bits to userspace that didn't make much sense. With any luck we'll have a better scheme soon, but for now just mask off those bits to avoid polluting userspace.

---
 arch/riscv/include/asm/elf.h   | 10 ++++++----
 arch/riscv/include/asm/hwcap.h |  8 --------
 2 files changed, 6 insertions(+), 12 deletions(-)
arch/riscv/include/asm/elf.h +6 -4
index e7acffdf21d2..30e7d2455960 100644
@@ -14,6 +14,7 @@
 #include <asm/auxvec.h>
 #include <asm/byteorder.h>
 #include <asm/cacheinfo.h>
+#include <asm/hwcap.h>
 
 /*
  * These are used to set parameters in the core dumps.
@@ -59,12 +60,13 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
 #define STACK_RND_MASK		(0x3ffff >> (PAGE_SHIFT - 12))
 #endif
 #endif
+
 /*
- * This yields a mask that user programs can use to figure out what
- * instruction set this CPU supports.  This could be done in user space,
- * but it's not easy, and we've already done it here.
+ * Provides information on the availiable set of ISA extensions to userspace,
+ * via a bitmap that coorespends to each single-letter ISA extension.  This is
+ * essentially defunct, but will remain for compatibility with userspace.
  */
-#define ELF_HWCAP	(elf_hwcap)
+#define ELF_HWCAP	(elf_hwcap & ((1UL << RISCV_ISA_EXT_BASE) - 1))
 extern unsigned long elf_hwcap;
 
 /*
arch/riscv/include/asm/hwcap.h +0 -8
index ee9c80fe0062..831bebacb7fb 100644
@@ -52,18 +52,10 @@
 
 #include <linux/jump_label.h>
 
-/*
- * This yields a mask that user programs can use to figure out what
- * instruction set this cpu supports.
- */
-#define ELF_HWCAP		(elf_hwcap)
-
 enum {
 	CAP_HWCAP = 1,
 };
 
-extern unsigned long elf_hwcap;
-
 struct riscv_isa_ext_data {
 	/* Name of the extension displayed to userspace via /proc/cpuinfo */
 	char uprop[RISCV_ISA_EXT_NAME_LEN_MAX];
Signature · 7 lines
2.39.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Acked-by on v1 1/1
#1 lore raw
Quoted 27 lines · Palmer Dabbelt

The recent refactoring led to us leaking some HWCAP bits to userspace that didn't make much sense. With any luck we'll have a better scheme soon, but for now just mask off those bits to avoid polluting userspace.

---
 arch/riscv/include/asm/elf.h   | 10 ++++++----
 arch/riscv/include/asm/hwcap.h |  8 --------
 2 files changed, 6 insertions(+), 12 deletions(-)
arch/riscv/include/asm/elf.h +2 -0
index e7acffdf21d2..30e7d2455960 100644
@@ -14,6 +14,7 @@
 #include <asm/auxvec.h>
 #include <asm/byteorder.h>
 #include <asm/cacheinfo.h>
+#include <asm/hwcap.h>
 
 /*
  * These are used to set parameters in the core dumps.
@@ -59,12 +60,13 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
 #define STACK_RND_MASK		(0x3ffff >> (PAGE_SHIFT - 12))
 #endif
 #endif
+

arch/riscv/include/asm/elf.h extern bool compat_elf_check_arch(Elf32_Ehdr *hdr); · line 69

Quoted 10 lines
arch/riscv/include/asm/elf.h +4 -4
 /*
- * This yields a mask that user programs can use to figure out what
- * instruction set this CPU supports.  This could be done in user space,
- * but it's not easy, and we've already done it here.
+ * Provides information on the availiable set of ISA extensions to userspace,
+ * via a bitmap that coorespends to each single-letter ISA extension.  This is
+ * essentially defunct, but will remain for compatibility with userspace.
  */
-#define ELF_HWCAP	(elf_hwcap)
+#define ELF_HWCAP	(elf_hwcap & ((1UL << RISCV_ISA_EXT_BASE) - 1))

Should that not be a GENMASK, or is there a reason not to use that here? Away from a setup where I can poke at it though, so, since you say this has only been exported in for-next, preventing us running out of hwcap sounds like a great idea.

Thanks,
Conor.

Quoted 35 lines
arch/riscv/include/asm/elf.h +0 -0
 extern unsigned long elf_hwcap;
 
 /*
arch/riscv/include/asm/hwcap.h +0 -8
index ee9c80fe0062..831bebacb7fb 100644
@@ -52,18 +52,10 @@
 
 #include <linux/jump_label.h>
 
-/*
- * This yields a mask that user programs can use to figure out what
- * instruction set this cpu supports.
- */
-#define ELF_HWCAP		(elf_hwcap)
-
 enum {
 	CAP_HWCAP = 1,
 };
 
-extern unsigned long elf_hwcap;
-
 struct riscv_isa_ext_data {
 	/* Name of the extension displayed to userspace via /proc/cpuinfo */
 	char uprop[RISCV_ISA_EXT_NAME_LEN_MAX];
Signature · 7 lines
2.39.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#2 lore raw
In reply to Palmer Dabbelt
This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Quoted 9 lines · On Thu, 2 Feb 2023 15:38:32 -0800 you wrote:

The recent refactoring led to us leaking some HWCAP bits to userspace that didn't make much sense. With any luck we'll have a better scheme soon, but for now just mask off those bits to avoid polluting userspace.

---
 arch/riscv/include/asm/elf.h   | 10 ++++++----
 arch/riscv/include/asm/hwcap.h |  8 --------
 2 files changed, 6 insertions(+), 12 deletions(-)

Here is the summary with links:
- RISC-V: Only provide the single-letter extensions in HWCAP

    https://git.kernel.org/riscv/c/2350bd192fa2

You are awesome, thank you!

Signature · 9 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv