[PATCH RFC 1/8] riscv/kaslr: add interface to get kaslr offset

From: Zong Li
Date: Tue Mar 24 2020 - 03:31:08 EST


Add interface to get the random offset.

Signed-off-by: Zong Li <zong.li@xxxxxxxxxx>
---
arch/riscv/include/asm/page.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h
index 92848e172a40..e2c2020f0a8d 100644
--- a/arch/riscv/include/asm/page.h
+++ b/arch/riscv/include/asm/page.h
@@ -101,6 +101,11 @@ extern unsigned long kernel_virt_addr;
extern unsigned long max_low_pfn;
extern unsigned long min_low_pfn;

+static inline unsigned long get_kaslr_offset(void)
+{
+ return kernel_virt_addr - PAGE_OFFSET;
+}
+
#define __pa_to_va_nodebug(x) ((void *)((unsigned long) (x) + va_pa_offset))
#define __va_to_pa_nodebug(x) ((unsigned long)(x) - va_pa_offset)

--
2.25.1