mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-04 08:17:46 +00:00

Add 2 early command line parameters that allow to downgrade satp mode (using the same naming as x86): - "no5lvl": use a 4-level page table (down from sv57 to sv48) - "no4lvl": use a 3-level page table (down from sv57/sv48 to sv39) Note that going through the device tree to get the kernel command line works with ACPI too since the efi stub creates a device tree anyway with the command line. In KASAN kernels, we can't use the libfdt that early in the boot process since we are not ready to execute instrumented functions. So instead of using the "generic" libfdt, we compile our own versions of those functions that are not instrumented and that are prefixed so that they do not conflict with the generic ones. We also need the non-instrumented versions of the string functions and the prefixed versions of memcpy/memmove. This is largely inspired by commitaacd149b62
("arm64: head: avoid relocating the kernel twice for KASLR") from which I removed compilation flags that were not relevant to RISC-V at the moment (LTO, SCS). Also note that we have to link with -z norelro to avoid ld.lld to throw a warning with the new .got sections, like in commit311bea3cb9
("arm64: link with -z norelro for LLD or aarch64-elf"). Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> Tested-by: Björn Töpel <bjorn@rivosinc.com> Reviewed-by: Björn Töpel <bjorn@rivosinc.com> Link: https://lore.kernel.org/r/20230424092313.178699-2-alexghiti@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
62 lines
1.5 KiB
C
62 lines
1.5 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
#include <linux/types.h>
|
|
#include <linux/init.h>
|
|
#include <linux/libfdt.h>
|
|
#include <linux/string.h>
|
|
#include <asm/pgtable.h>
|
|
#include <asm/setup.h>
|
|
|
|
static char early_cmdline[COMMAND_LINE_SIZE];
|
|
|
|
/*
|
|
* Declare the functions that are exported (but prefixed) here so that LLVM
|
|
* does not complain it lacks the 'static' keyword (which, if added, makes
|
|
* LLVM complain because the function is actually unused in this file).
|
|
*/
|
|
u64 set_satp_mode_from_cmdline(uintptr_t dtb_pa);
|
|
|
|
static char *get_early_cmdline(uintptr_t dtb_pa)
|
|
{
|
|
const char *fdt_cmdline = NULL;
|
|
unsigned int fdt_cmdline_size = 0;
|
|
int chosen_node;
|
|
|
|
if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) {
|
|
chosen_node = fdt_path_offset((void *)dtb_pa, "/chosen");
|
|
if (chosen_node >= 0) {
|
|
fdt_cmdline = fdt_getprop((void *)dtb_pa, chosen_node,
|
|
"bootargs", NULL);
|
|
if (fdt_cmdline) {
|
|
fdt_cmdline_size = strlen(fdt_cmdline);
|
|
strscpy(early_cmdline, fdt_cmdline,
|
|
COMMAND_LINE_SIZE);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
|
|
IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
|
|
fdt_cmdline_size == 0 /* CONFIG_CMDLINE_FALLBACK */) {
|
|
strncat(early_cmdline, CONFIG_CMDLINE,
|
|
COMMAND_LINE_SIZE - fdt_cmdline_size);
|
|
}
|
|
|
|
return early_cmdline;
|
|
}
|
|
|
|
static u64 match_noXlvl(char *cmdline)
|
|
{
|
|
if (strstr(cmdline, "no4lvl"))
|
|
return SATP_MODE_48;
|
|
else if (strstr(cmdline, "no5lvl"))
|
|
return SATP_MODE_57;
|
|
|
|
return 0;
|
|
}
|
|
|
|
u64 set_satp_mode_from_cmdline(uintptr_t dtb_pa)
|
|
{
|
|
char *cmdline = get_early_cmdline(dtb_pa);
|
|
|
|
return match_noXlvl(cmdline);
|
|
}
|