-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
riscv: Introduce virtual kernel mapping KASLR
KASLR implementation relies on a relocatable kernel so that we can move the kernel mapping. The seed needed to virtually move the kernel is taken from the device tree, so we rely on the bootloader to provide a correct seed. Zkr could be used unconditionnally instead if implemented, but that's for another patch. Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> Tested-by: Conor Dooley <conor.dooley@microchip.com> Tested-by: Song Shuai <songshuaishuai@tinylab.org> Reviewed-by: Sami Tolvanen <samitolvanen@google.com> Tested-by: Sami Tolvanen <samitolvanen@google.com> Link: https://lore.kernel.org/r/20230722123850.634544-2-alexghiti@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
- Loading branch information
Alexandre Ghiti
authored and
Palmer Dabbelt
committed
Sep 6, 2023
1 parent
06c2afb
commit 84fe419
Showing
6 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
#include <linux/types.h> | ||
#include <linux/init.h> | ||
#include <linux/libfdt.h> | ||
|
||
/* | ||
* 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 get_kaslr_seed(uintptr_t dtb_pa); | ||
|
||
u64 get_kaslr_seed(uintptr_t dtb_pa) | ||
{ | ||
int node, len; | ||
fdt64_t *prop; | ||
u64 ret; | ||
|
||
node = fdt_path_offset((void *)dtb_pa, "/chosen"); | ||
if (node < 0) | ||
return 0; | ||
|
||
prop = fdt_getprop_w((void *)dtb_pa, node, "kaslr-seed", &len); | ||
if (!prop || len != sizeof(u64)) | ||
return 0; | ||
|
||
ret = fdt64_to_cpu(*prop); | ||
*prop = 0; | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters