* [PATCH 0/2] Introduce macros for the offsets to reserved_pg_dir and tramp_pg_dir
@ 2021-02-02 12:36 Joey Gouly
2021-02-02 12:36 ` [PATCH 1/2] arm64: vmlinux.ld.S: add assertion for reserved_pg_dir offset Joey Gouly
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Joey Gouly @ 2021-02-02 12:36 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Mark Rutland, Catalin Marinas, nd, Will Deacon, Joey Gouly
Make the offsets to reserved_pg_dir and tramp_pg_dir less fragile by
introducing macros that contain their offsets.
Also use these macros to verify the offsets at link time.
Joey Gouly (2):
arm64: vmlinux.ld.S: add assertion for reserved_pg_dir offset
arm64: vmlinux.ld.S: add assertion for tramp_pg_dir offset
arch/arm64/include/asm/asm-uaccess.h | 4 ++--
arch/arm64/include/asm/memory.h | 12 ++++++++++++
arch/arm64/include/asm/uaccess.h | 2 +-
arch/arm64/kernel/entry.S | 4 ++--
arch/arm64/kernel/vmlinux.lds.S | 8 ++++++++
5 files changed, 25 insertions(+), 5 deletions(-)
--
2.17.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] arm64: vmlinux.ld.S: add assertion for reserved_pg_dir offset
2021-02-02 12:36 [PATCH 0/2] Introduce macros for the offsets to reserved_pg_dir and tramp_pg_dir Joey Gouly
@ 2021-02-02 12:36 ` Joey Gouly
2021-02-02 12:36 ` [PATCH 2/2] arm64: vmlinux.ld.S: add assertion for tramp_pg_dir offset Joey Gouly
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Joey Gouly @ 2021-02-02 12:36 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Mark Rutland, Catalin Marinas, nd, Will Deacon, Joey Gouly
Add RESERVED_SWAPPER_OFFSET and use that instead of hardcoding
the offset between swapper_pg_dir and reserved_pg_dir.
Then use RESERVED_SWAPPER_OFFSET to assert that the offset is
correct at link time.
Signed-off-by: Joey Gouly <joey.gouly@arm.com>
---
arch/arm64/include/asm/asm-uaccess.h | 4 ++--
arch/arm64/include/asm/memory.h | 6 ++++++
arch/arm64/include/asm/uaccess.h | 2 +-
arch/arm64/kernel/vmlinux.lds.S | 3 +++
4 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/include/asm/asm-uaccess.h b/arch/arm64/include/asm/asm-uaccess.h
index 9990059be106..ccedf548dac9 100644
--- a/arch/arm64/include/asm/asm-uaccess.h
+++ b/arch/arm64/include/asm/asm-uaccess.h
@@ -15,10 +15,10 @@
.macro __uaccess_ttbr0_disable, tmp1
mrs \tmp1, ttbr1_el1 // swapper_pg_dir
bic \tmp1, \tmp1, #TTBR_ASID_MASK
- sub \tmp1, \tmp1, #PAGE_SIZE // reserved_pg_dir just before swapper_pg_dir
+ sub \tmp1, \tmp1, #RESERVED_SWAPPER_OFFSET // reserved_pg_dir
msr ttbr0_el1, \tmp1 // set reserved TTBR0_EL1
isb
- add \tmp1, \tmp1, #PAGE_SIZE
+ add \tmp1, \tmp1, #RESERVED_SWAPPER_OFFSET
msr ttbr1_el1, \tmp1 // set reserved ASID
isb
.endm
diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index 99d7e1494aaa..300f728fa288 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -159,6 +159,12 @@
#define IOREMAP_MAX_ORDER (PMD_SHIFT)
#endif
+/*
+ * Open-coded (swapper_pg_dir - reserved_pg_dir) as this cannot be calculated
+ * until link time.
+ */
+#define RESERVED_SWAPPER_OFFSET (PAGE_SIZE)
+
#ifndef __ASSEMBLY__
#include <linux/bitops.h>
diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
index f0fe0cc6abe0..0deb88467111 100644
--- a/arch/arm64/include/asm/uaccess.h
+++ b/arch/arm64/include/asm/uaccess.h
@@ -87,7 +87,7 @@ static inline void __uaccess_ttbr0_disable(void)
ttbr = read_sysreg(ttbr1_el1);
ttbr &= ~TTBR_ASID_MASK;
/* reserved_pg_dir placed before swapper_pg_dir */
- write_sysreg(ttbr - PAGE_SIZE, ttbr0_el1);
+ write_sysreg(ttbr - RESERVED_SWAPPER_OFFSET, ttbr0_el1);
isb();
/* Set reserved ASID */
write_sysreg(ttbr, ttbr1_el1);
diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index 4c0b0c89ad59..a03a5300bce9 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -316,3 +316,6 @@ ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
* If padding is applied before .head.text, virt<->phys conversions will fail.
*/
ASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned")
+
+ASSERT(swapper_pg_dir - reserved_pg_dir == RESERVED_SWAPPER_OFFSET,
+ "RESERVED_SWAPPER_OFFSET is wrong!")
--
2.17.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] arm64: vmlinux.ld.S: add assertion for tramp_pg_dir offset
2021-02-02 12:36 [PATCH 0/2] Introduce macros for the offsets to reserved_pg_dir and tramp_pg_dir Joey Gouly
2021-02-02 12:36 ` [PATCH 1/2] arm64: vmlinux.ld.S: add assertion for reserved_pg_dir offset Joey Gouly
@ 2021-02-02 12:36 ` Joey Gouly
2021-02-03 12:28 ` [PATCH 0/2] Introduce macros for the offsets to reserved_pg_dir and tramp_pg_dir Mark Rutland
2021-02-03 21:31 ` Will Deacon
3 siblings, 0 replies; 5+ messages in thread
From: Joey Gouly @ 2021-02-02 12:36 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Mark Rutland, Catalin Marinas, nd, Will Deacon, Joey Gouly
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>
---
arch/arm64/include/asm/memory.h | 6 ++++++
arch/arm64/kernel/entry.S | 4 ++--
arch/arm64/kernel/vmlinux.lds.S | 5 +++++
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index 300f728fa288..f9aa9fa8806e 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -165,6 +165,12 @@
*/
#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>
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index c9bae73f2621..c6aee646eb6b 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -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
/*
diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index a03a5300bce9..68f76a96c60b 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -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
--
2.17.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] Introduce macros for the offsets to reserved_pg_dir and tramp_pg_dir
2021-02-02 12:36 [PATCH 0/2] Introduce macros for the offsets to reserved_pg_dir and tramp_pg_dir Joey Gouly
2021-02-02 12:36 ` [PATCH 1/2] arm64: vmlinux.ld.S: add assertion for reserved_pg_dir offset Joey Gouly
2021-02-02 12:36 ` [PATCH 2/2] arm64: vmlinux.ld.S: add assertion for tramp_pg_dir offset Joey Gouly
@ 2021-02-03 12:28 ` Mark Rutland
2021-02-03 21:31 ` Will Deacon
3 siblings, 0 replies; 5+ messages in thread
From: Mark Rutland @ 2021-02-03 12:28 UTC (permalink / raw)
To: Joey Gouly; +Cc: Catalin Marinas, nd, Will Deacon, linux-arm-kernel
On Tue, Feb 02, 2021 at 12:36:56PM +0000, Joey Gouly wrote:
> Make the offsets to reserved_pg_dir and tramp_pg_dir less fragile by
> introducing macros that contain their offsets.
>
> Also use these macros to verify the offsets at link time.
I like the idea, the implementation appears to be correct, both patches
build and boot without issue, and if I mess with the offsets I get the
expected warnings. So, for both patches:
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Tested-by: Mark Rutland <mark.rutland@arm.com>
Mark.
>
> Joey Gouly (2):
> arm64: vmlinux.ld.S: add assertion for reserved_pg_dir offset
> arm64: vmlinux.ld.S: add assertion for tramp_pg_dir offset
>
> arch/arm64/include/asm/asm-uaccess.h | 4 ++--
> arch/arm64/include/asm/memory.h | 12 ++++++++++++
> arch/arm64/include/asm/uaccess.h | 2 +-
> arch/arm64/kernel/entry.S | 4 ++--
> arch/arm64/kernel/vmlinux.lds.S | 8 ++++++++
> 5 files changed, 25 insertions(+), 5 deletions(-)
>
> --
> 2.17.1
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] Introduce macros for the offsets to reserved_pg_dir and tramp_pg_dir
2021-02-02 12:36 [PATCH 0/2] Introduce macros for the offsets to reserved_pg_dir and tramp_pg_dir Joey Gouly
` (2 preceding siblings ...)
2021-02-03 12:28 ` [PATCH 0/2] Introduce macros for the offsets to reserved_pg_dir and tramp_pg_dir Mark Rutland
@ 2021-02-03 21:31 ` Will Deacon
3 siblings, 0 replies; 5+ messages in thread
From: Will Deacon @ 2021-02-03 21:31 UTC (permalink / raw)
To: linux-arm-kernel, Joey Gouly
Cc: Mark Rutland, catalin.marinas, nd, kernel-team, Will Deacon
On Tue, 2 Feb 2021 12:36:56 +0000, Joey Gouly wrote:
> Make the offsets to reserved_pg_dir and tramp_pg_dir less fragile by
> introducing macros that contain their offsets.
>
> Also use these macros to verify the offsets at link time.
>
> Joey Gouly (2):
> arm64: vmlinux.ld.S: add assertion for reserved_pg_dir offset
> arm64: vmlinux.ld.S: add assertion for tramp_pg_dir offset
>
> [...]
Applied to arm64 (for-next/misc), thanks!
[1/2] arm64: vmlinux.ld.S: add assertion for reserved_pg_dir offset
https://git.kernel.org/arm64/c/00ef54341936
[2/2] arm64: vmlinux.ld.S: add assertion for tramp_pg_dir offset
https://git.kernel.org/arm64/c/0188a894c390
Cheers,
--
Will
https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-02-03 21:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-02 12:36 [PATCH 0/2] Introduce macros for the offsets to reserved_pg_dir and tramp_pg_dir Joey Gouly
2021-02-02 12:36 ` [PATCH 1/2] arm64: vmlinux.ld.S: add assertion for reserved_pg_dir offset Joey Gouly
2021-02-02 12:36 ` [PATCH 2/2] arm64: vmlinux.ld.S: add assertion for tramp_pg_dir offset Joey Gouly
2021-02-03 12:28 ` [PATCH 0/2] Introduce macros for the offsets to reserved_pg_dir and tramp_pg_dir Mark Rutland
2021-02-03 21:31 ` Will Deacon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).