Skip to content

Commit 82e9c66

Browse files
evangreenpalmer-dabbelt
authored andcommitted
RISC-V: Track ISA extensions per hart
The kernel maintains a mask of ISA extensions ANDed together across all harts. Let's also keep a bitmap of ISA extensions for each CPU. Although the kernel is currently unlikely to enable a feature that exists only on some CPUs, we want the ability to report asymmetric CPU extensions accurately to usermode. Note that riscv_fill_hwcaps() runs before the per_cpu_offsets are built, which is why I've used a [NR_CPUS] array rather than per_cpu() data. Signed-off-by: Evan Green <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Conor Dooley <[email protected]> Reviewed-by: Palmer Dabbelt <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent c6699ba commit 82e9c66

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

arch/riscv/include/asm/cpufeature.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#ifndef _ASM_CPUFEATURE_H
77
#define _ASM_CPUFEATURE_H
88

9+
#include <linux/bitmap.h>
10+
#include <asm/hwcap.h>
11+
912
/*
1013
* These are probed via a device_initcall(), via either the SBI or directly
1114
* from the corresponding CSRs.
@@ -16,8 +19,15 @@ struct riscv_cpuinfo {
1619
unsigned long mimpid;
1720
};
1821

22+
struct riscv_isainfo {
23+
DECLARE_BITMAP(isa, RISCV_ISA_EXT_MAX);
24+
};
25+
1926
DECLARE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
2027

2128
DECLARE_PER_CPU(long, misaligned_access_speed);
2229

30+
/* Per-cpu ISA extensions. */
31+
extern struct riscv_isainfo hart_isa[NR_CPUS];
32+
2333
#endif

arch/riscv/kernel/cpufeature.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ unsigned long elf_hwcap __read_mostly;
2626
/* Host ISA bitmap */
2727
static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;
2828

29+
/* Per-cpu ISA extensions. */
30+
struct riscv_isainfo hart_isa[NR_CPUS];
31+
2932
/* Performance information */
3033
DEFINE_PER_CPU(long, misaligned_access_speed);
3134

@@ -113,14 +116,18 @@ void __init riscv_fill_hwcap(void)
113116
bitmap_zero(riscv_isa, RISCV_ISA_EXT_MAX);
114117

115118
for_each_of_cpu_node(node) {
119+
struct riscv_isainfo *isainfo;
116120
unsigned long this_hwcap = 0;
117-
DECLARE_BITMAP(this_isa, RISCV_ISA_EXT_MAX);
118121
const char *temp;
122+
unsigned int cpu_id;
119123

120124
rc = riscv_of_processor_hartid(node, &hartid);
121125
if (rc < 0)
122126
continue;
123127

128+
cpu_id = riscv_hartid_to_cpuid(hartid);
129+
isainfo = &hart_isa[cpu_id];
130+
124131
if (of_property_read_string(node, "riscv,isa", &isa)) {
125132
pr_warn("Unable to find \"riscv,isa\" devicetree entry\n");
126133
continue;
@@ -137,7 +144,6 @@ void __init riscv_fill_hwcap(void)
137144
/* The riscv,isa DT property must start with rv64 or rv32 */
138145
if (temp == isa)
139146
continue;
140-
bitmap_zero(this_isa, RISCV_ISA_EXT_MAX);
141147
for (; *isa; ++isa) {
142148
const char *ext = isa++;
143149
const char *ext_end = isa;
@@ -215,7 +221,7 @@ void __init riscv_fill_hwcap(void)
215221
if ((ext_end - ext == sizeof(name) - 1) && \
216222
!memcmp(ext, name, sizeof(name) - 1) && \
217223
riscv_isa_extension_check(bit)) \
218-
set_bit(bit, this_isa); \
224+
set_bit(bit, isainfo->isa); \
219225
} while (false) \
220226

221227
if (unlikely(ext_err))
@@ -225,7 +231,7 @@ void __init riscv_fill_hwcap(void)
225231

226232
if (riscv_isa_extension_check(nr)) {
227233
this_hwcap |= isa2hwcap[nr];
228-
set_bit(nr, this_isa);
234+
set_bit(nr, isainfo->isa);
229235
}
230236
} else {
231237
/* sorted alphabetically */
@@ -257,9 +263,9 @@ void __init riscv_fill_hwcap(void)
257263
elf_hwcap = this_hwcap;
258264

259265
if (bitmap_empty(riscv_isa, RISCV_ISA_EXT_MAX))
260-
bitmap_copy(riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
266+
bitmap_copy(riscv_isa, isainfo->isa, RISCV_ISA_EXT_MAX);
261267
else
262-
bitmap_and(riscv_isa, riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
268+
bitmap_and(riscv_isa, riscv_isa, isainfo->isa, RISCV_ISA_EXT_MAX);
263269
}
264270

265271
/* We don't support systems with F but without D, so mask those out

0 commit comments

Comments
 (0)