arm64: vmlinux.ld.S: add assertion for tramp_pg_dir offset
authorJoey Gouly <joey.gouly@arm.com>
Tue, 2 Feb 2021 12:36:58 +0000 (12:36 +0000)
committerWill Deacon <will@kernel.org>
Wed, 3 Feb 2021 20:43:45 +0000 (20:43 +0000)
Add TRAMP_SWAPPER_OFFSET and use that instead of hardcoding
the offset between swapper_pg_dir and tramp_pg_dir.

Then use TRAMP_SWAPPER_OFFSET to assert that the offset is
correct at link time.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Tested-by: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/r/20210202123658.22308-3-joey.gouly@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/include/asm/memory.h
arch/arm64/kernel/entry.S
arch/arm64/kernel/vmlinux.lds.S

index f6bf8a9..6c26749 100644 (file)
  */
 #define RESERVED_SWAPPER_OFFSET        (PAGE_SIZE)
 
+/*
+ *  Open-coded (swapper_pg_dir - tramp_pg_dir) as this cannot be calculated
+ *  until link time.
+ */
+#define TRAMP_SWAPPER_OFFSET   (2 * PAGE_SIZE)
+
 #ifndef __ASSEMBLY__
 
 #include <linux/bitops.h>
index c9bae73..c6aee64 100644 (file)
@@ -805,7 +805,7 @@ SYM_CODE_END(ret_to_user)
        // Move from tramp_pg_dir to swapper_pg_dir
        .macro tramp_map_kernel, tmp
        mrs     \tmp, ttbr1_el1
-       add     \tmp, \tmp, #(2 * PAGE_SIZE)
+       add     \tmp, \tmp, #TRAMP_SWAPPER_OFFSET
        bic     \tmp, \tmp, #USER_ASID_FLAG
        msr     ttbr1_el1, \tmp
 #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003
@@ -825,7 +825,7 @@ alternative_else_nop_endif
        // Move from swapper_pg_dir to tramp_pg_dir
        .macro tramp_unmap_kernel, tmp
        mrs     \tmp, ttbr1_el1
-       sub     \tmp, \tmp, #(2 * PAGE_SIZE)
+       sub     \tmp, \tmp, #TRAMP_SWAPPER_OFFSET
        orr     \tmp, \tmp, #USER_ASID_FLAG
        msr     ttbr1_el1, \tmp
        /*
index a03a530..68f76a9 100644 (file)
@@ -319,3 +319,8 @@ ASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned")
 
 ASSERT(swapper_pg_dir - reserved_pg_dir == RESERVED_SWAPPER_OFFSET,
        "RESERVED_SWAPPER_OFFSET is wrong!")
+
+#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
+ASSERT(swapper_pg_dir - tramp_pg_dir == TRAMP_SWAPPER_OFFSET,
+       "TRAMP_SWAPPER_OFFSET is wrong!")
+#endif