riscv: hwcap: change ELF_HWCAP to a function

Using a function is flexible to represent ELF_HWCAP. So the kernel may
encode hwcap reflecting supported hardware features just at the moment of
the start of each program.

This will be helpful when we introduce prctl/sysctl interface to control
per-process availability of Vector extension in following patches.
Programs started with V disabled should see V masked off in theirs
ELF_HWCAP.

Signed-off-by: Andy Chiu <andy.chiu@sifive.com>
Reviewed-by: Conor Dooley <conor.dooley@microchip.com>
Link: https://lore.kernel.org/r/20230605110724.21391-21-andy.chiu@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
This commit is contained in:
Andy Chiu
2023-06-05 11:07:17 +00:00
committed by Palmer Dabbelt
parent 0f4b825797
commit 50724efcb3
3 changed files with 8 additions and 1 deletions

View File

@@ -66,7 +66,7 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
* via a bitmap that coorespends to each single-letter ISA extension. This is * via a bitmap that coorespends to each single-letter ISA extension. This is
* essentially defunct, but will remain for compatibility with userspace. * essentially defunct, but will remain for compatibility with userspace.
*/ */
#define ELF_HWCAP (elf_hwcap & ((1UL << RISCV_ISA_EXT_BASE) - 1)) #define ELF_HWCAP riscv_get_elf_hwcap()
extern unsigned long elf_hwcap; extern unsigned long elf_hwcap;
/* /*

View File

@@ -61,6 +61,8 @@
#include <linux/jump_label.h> #include <linux/jump_label.h>
unsigned long riscv_get_elf_hwcap(void);
struct riscv_isa_ext_data { struct riscv_isa_ext_data {
/* Name of the extension displayed to userspace via /proc/cpuinfo */ /* Name of the extension displayed to userspace via /proc/cpuinfo */
char uprop[RISCV_ISA_EXT_NAME_LEN_MAX]; char uprop[RISCV_ISA_EXT_NAME_LEN_MAX];

View File

@@ -293,6 +293,11 @@ void __init riscv_fill_hwcap(void)
pr_info("riscv: ELF capabilities %s\n", print_str); pr_info("riscv: ELF capabilities %s\n", print_str);
} }
unsigned long riscv_get_elf_hwcap(void)
{
return (elf_hwcap & ((1UL << RISCV_ISA_EXT_BASE) - 1));
}
#ifdef CONFIG_RISCV_ALTERNATIVE #ifdef CONFIG_RISCV_ALTERNATIVE
/* /*
* Alternative patch sites consider 48 bits when determining when to patch * Alternative patch sites consider 48 bits when determining when to patch