未验证 提交 1771c8c9 编写于 作者: H Heiko Stuebner 提交者: Palmer Dabbelt

riscv: remove usage of function-pointers from cpufeatures and t-head errata

Having a list of alternatives to check with a per-entry function pointer
to a check function is nice style-wise. But in case of early-alternatives
it can clash with the non-relocated kernel and the function pointer in
the list pointing to a completely wrong location.

This isn't an issue with one or two list entries, as in that case the
compiler seems to unroll the loop and even usage of the list structure
and then only does relative jumps into the check functions based on this.

When adding a third entry to either list though, the issue that was
hiding there from the beginning is triggered resulting a jump to a
memory address that isn't part of the kernel at all.

The list of features/erratas only contained an unused name and the
pointer to the check function, so an easy solution for the problem
is to just unroll the loop in code, dismantle the whole list structure
and just call the relevant check functions one by one ourself.

For the T-Head errata this includes moving the stage-check inside
the check functions.

The issue is only relevant for things that might be called for early-
alternatives (T-Head and possible future main extensions), so the
SiFive erratas were not affected from the beginning, as they got
an early return for early-alternatives in the original patchset.
Signed-off-by: NHeiko Stuebner <heiko@sntech.de>
Tested-by: NSamuel Holland <samuel@sholland.org>
Link: https://lore.kernel.org/r/20220526205646.258337-6-heiko@sntech.deSigned-off-by: NPalmer Dabbelt <palmer@rivosinc.com>
上级 b684001a
...@@ -14,40 +14,26 @@ ...@@ -14,40 +14,26 @@
#include <asm/patch.h> #include <asm/patch.h>
#include <asm/vendorid_list.h> #include <asm/vendorid_list.h>
struct errata_info { static bool errata_probe_pbmt(unsigned int stage,
char name[ERRATA_STRING_LENGTH_MAX]; unsigned long arch_id, unsigned long impid)
bool (*check_func)(unsigned long arch_id, unsigned long impid);
unsigned int stage;
};
static bool errata_mt_check_func(unsigned long arch_id, unsigned long impid)
{ {
if (arch_id != 0 || impid != 0) if (arch_id != 0 || impid != 0)
return false; return false;
return true;
}
static const struct errata_info errata_list[ERRATA_THEAD_NUMBER] = { if (stage == RISCV_ALTERNATIVES_EARLY_BOOT ||
{ stage == RISCV_ALTERNATIVES_MODULE)
.name = "memory-types", return true;
.stage = RISCV_ALTERNATIVES_EARLY_BOOT,
.check_func = errata_mt_check_func return false;
}, }
};
static u32 thead_errata_probe(unsigned int stage, unsigned long archid, unsigned long impid) static u32 thead_errata_probe(unsigned int stage,
unsigned long archid, unsigned long impid)
{ {
const struct errata_info *info;
u32 cpu_req_errata = 0; u32 cpu_req_errata = 0;
int idx;
for (idx = 0; idx < ERRATA_THEAD_NUMBER; idx++) {
info = &errata_list[idx];
if ((stage == RISCV_ALTERNATIVES_MODULE || if (errata_probe_pbmt(stage, archid, impid))
info->stage == stage) && info->check_func(archid, impid)) cpu_req_errata |= (1U << ERRATA_THEAD_PBMT);
cpu_req_errata |= (1U << idx);
}
return cpu_req_errata; return cpu_req_errata;
} }
......
...@@ -245,12 +245,7 @@ void __init riscv_fill_hwcap(void) ...@@ -245,12 +245,7 @@ void __init riscv_fill_hwcap(void)
} }
#ifdef CONFIG_RISCV_ALTERNATIVE #ifdef CONFIG_RISCV_ALTERNATIVE
struct cpufeature_info { static bool __init_or_module cpufeature_probe_svpbmt(unsigned int stage)
char name[ERRATA_STRING_LENGTH_MAX];
bool (*check_func)(unsigned int stage);
};
static bool __init_or_module cpufeature_svpbmt_check_func(unsigned int stage)
{ {
#ifdef CONFIG_RISCV_ISA_SVPBMT #ifdef CONFIG_RISCV_ISA_SVPBMT
switch (stage) { switch (stage) {
...@@ -264,26 +259,19 @@ static bool __init_or_module cpufeature_svpbmt_check_func(unsigned int stage) ...@@ -264,26 +259,19 @@ static bool __init_or_module cpufeature_svpbmt_check_func(unsigned int stage)
return false; return false;
} }
static const struct cpufeature_info __initdata_or_module /*
cpufeature_list[CPUFEATURE_NUMBER] = { * Probe presence of individual extensions.
{ *
.name = "svpbmt", * This code may also be executed before kernel relocation, so we cannot use
.check_func = cpufeature_svpbmt_check_func * addresses generated by the address-of operator as they won't be valid in
}, * this context.
}; */
static u32 __init_or_module cpufeature_probe(unsigned int stage) static u32 __init_or_module cpufeature_probe(unsigned int stage)
{ {
const struct cpufeature_info *info;
u32 cpu_req_feature = 0; u32 cpu_req_feature = 0;
int idx;
for (idx = 0; idx < CPUFEATURE_NUMBER; idx++) {
info = &cpufeature_list[idx];
if (info->check_func(stage)) if (cpufeature_probe_svpbmt(stage))
cpu_req_feature |= (1U << idx); cpu_req_feature |= (1U << CPUFEATURE_SVPBMT);
}
return cpu_req_feature; return cpu_req_feature;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册