Skip to content

Commit 069b0d5

Browse files
ConchuODpalmer-dabbelt
authored andcommitted
RISC-V: validate riscv,isa at boot, not during ISA string parsing
Since riscv_fill_hwcap() now only iterates over possible cpus, the basic validation of whether riscv,isa contains "rv<width>" can be moved to riscv_early_of_processor_hartid(). Further, "ima" support is required by the kernel, so reject any CPU not fitting the bill. Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Conor Dooley <[email protected]> Reviewed-by: Sunil V L <[email protected]> Link: https://lore.kernel.org/r/20230607-guts-blurry-67e711acf328@spud Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 2ac8743 commit 069b0d5

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

arch/riscv/kernel/cpu.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ int riscv_early_of_processor_hartid(struct device_node *node, unsigned long *har
6565
pr_warn("CPU with hartid=%lu has no \"riscv,isa\" property\n", *hart);
6666
return -ENODEV;
6767
}
68-
if (tolower(isa[0]) != 'r' || tolower(isa[1]) != 'v') {
69-
pr_warn("CPU with hartid=%lu has an invalid ISA of \"%s\"\n", *hart, isa);
68+
69+
if (IS_ENABLED(CONFIG_32BIT) && strncasecmp(isa, "rv32ima", 7))
70+
return -ENODEV;
71+
72+
if (IS_ENABLED(CONFIG_64BIT) && strncasecmp(isa, "rv64ima", 7))
7073
return -ENODEV;
71-
}
7274

7375
return 0;
7476
}

arch/riscv/kernel/cpufeature.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ void __init riscv_fill_hwcap(void)
148148
}
149149
}
150150

151-
if (IS_ENABLED(CONFIG_32BIT) && strncasecmp(isa, "rv32", 4))
152-
continue;
153-
154-
if (IS_ENABLED(CONFIG_64BIT) && strncasecmp(isa, "rv64", 4))
155-
continue;
156-
151+
/*
152+
* For all possible cpus, we have already validated in
153+
* the boot process that they at least contain "rv" and
154+
* whichever of "32"/"64" this kernel supports, and so this
155+
* section can be skipped.
156+
*/
157157
isa += 4;
158158

159159
bitmap_zero(this_isa, RISCV_ISA_EXT_MAX);

0 commit comments

Comments
 (0)