From: Heiko Stuebner <heiko.stuebner@...>
Date: Wed, 12 Apr 2023 17:17:30 +0200
Commit-Message
Already defined aux-vectors regarding the machine type are AT_PLATFORM
and AT_BASE_PLATFORM. PPC already uses AT_BASE_PLATFORM to identify the
real platform the system is running on, so do a similar thing on RISC-V
and export the ISA string of the running machine via this aux-vector
element.
This way userspace can possibly adapt to extensions that allow it to
run certain loads more performantly.
Signed-off-by: Heiko Stuebner <heiko.stuebner@...>
Patch-Comment
arch/riscv/include/asm/elf.h | 10 ++++++++++
arch/riscv/kernel/cpu.c | 12 ++++++++++++
2 files changed, 22 insertions(+)
Statistics
- 22 lines added
- 0 lines removed
Changes
@@ -78,6 +78,16 @@ extern unsigned long elf_hwcap;
#define COMPAT_ELF_PLATFORM (NULL)
+/*
+ * ELF_PLATFORM indicates the ISA supported by the platform, but has
+ * special meaning to ld.so .
+ * Expose the ISA string including all usable extensions via
+ * ELF_BASE_PLATFORM instead and allow userspace to adapt to them
+ * if needed.
+ */
+#define ELF_BASE_PLATFORM (riscv_base_platform)
+extern const char *riscv_base_platform;
+
#ifdef CONFIG_MMU
#define ARCH_DLINFO \
do { \
@@ -118,8 +118,12 @@ static int riscv_cpuinfo_starting(unsigned int cpu)
return 0;
}
+const char *riscv_base_platform = NULL;
+static char *riscv_create_isa_string(void);
+
static int __init riscv_cpuinfo_init(void)
{
+ char *isa_str;
int ret;
ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "riscv/cpuinfo:starting",
@@ -129,6 +133,14 @@ static int __init riscv_cpuinfo_init(void)
return ret;
}
+ /*
+ * Create the isa-string with the common set of extensions over
+ * all harts, to expose as AT_BASE_PLATFORM in the aux vector.
+ */
+ isa_str = riscv_create_isa_string();
+ if (!IS_ERR(isa_str))
+ riscv_base_platform = isa_str;
+
return 0;
}
arch_initcall(riscv_cpuinfo_init);