Hi,
This is a short series that makes a few simplifications we can now afford: getting rid of morello_capcpy(), as it is unnecessary now that the kernel is a "proper" hybrid binary with a tag-preserving memcpy(); and making use of <linux/cheri.h> to simplify includes.
The Morello helpers could be further simplified by reimplementing many of them in C instead of assembly, issue #61 [1] was created to that end.
Review branch:
https://git.morello-project.org/kbrodsky-arm/linux/-/commits/morello/cheri_c...
Cheers, Kevin
[1] https://git.morello-project.org/morello/kernel/linux/-/issues/61
Kevin Brodsky (3): arm64: morello: Replace morello_capcpy() with standard copy arm64: Replace cheriintrin.h with linux/cheri.h lib: Replace cheriintrin.h with linux/cheri.h
arch/arm64/include/asm/morello.h | 6 ------ arch/arm64/kernel/process.c | 9 +-------- arch/arm64/kernel/signal.c | 5 +---- arch/arm64/lib/morello.S | 18 ------------------ lib/test_printf.c | 4 +--- lib/vsprintf.c | 5 +---- 6 files changed, 4 insertions(+), 43 deletions(-)
morello_capcpy() was introduced by "arm64: morello: Context-switch capability GPRs and CSP" in order to copy the capability registers (preserving their tags). Nowadays, the kernel is compiled as a hybrid binary, allowing capabilities to be directly manipulated. This implies in in particular that memcpy() preserves capability tags if possible. As a result, we no longer need a dedicated function like morello_capcpy() - we can simply let the compiler copy capabilities itself, or call memcpy().
This commit partially reverts "arm64: morello: Context-switch capability GPRs and CSP".
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com ---
Note: I checked in the generated code for copy_thread() that the branch to morello_capcpy is replaced by one to memcpy, with absolutely no other difference.
arch/arm64/include/asm/morello.h | 6 ------ arch/arm64/kernel/process.c | 9 +-------- arch/arm64/lib/morello.S | 18 ------------------ 3 files changed, 1 insertion(+), 32 deletions(-)
diff --git a/arch/arm64/include/asm/morello.h b/arch/arm64/include/asm/morello.h index 9f35d710cbfe..68ec2d4767a2 100644 --- a/arch/arm64/include/asm/morello.h +++ b/arch/arm64/include/asm/morello.h @@ -62,12 +62,6 @@ void morello_thread_set_csp(struct pt_regs *regs, user_uintptr_t sp); * Any invalid usage will result in an error at link time. */
-/* - * Copies src to dst preserving capability tags. - * All of dst, src and len must be 16-byte aligned. - */ -void *morello_capcpy(void *dst, const void *src, size_t len); - void morello_thread_start(struct pt_regs *regs, unsigned long pc); void morello_thread_init_user(void); void morello_thread_save_user_state(struct task_struct *tsk); diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index cab68cebf1fa..cff890a14d41 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -396,14 +396,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) ptrauth_thread_init_kernel(p);
if (likely(!args->fn)) { - if (!system_supports_morello()) { - *childregs = *current_pt_regs(); - } else { - BUILD_BUG_ON(__alignof__(struct pt_regs) < - __alignof__(__uint128_t)); - morello_capcpy(childregs, current_pt_regs(), - sizeof(*current_pt_regs())); - } + *childregs = *current_pt_regs(); childregs->regs[0] = 0;
/* diff --git a/arch/arm64/lib/morello.S b/arch/arm64/lib/morello.S index 5bc1540c829f..04ef653380d2 100644 --- a/arch/arm64/lib/morello.S +++ b/arch/arm64/lib/morello.S @@ -46,24 +46,6 @@ SYM_FUNC_START(morello_build_any_user_cap) ret SYM_FUNC_END(morello_build_any_user_cap)
-SYM_FUNC_START(morello_capcpy) - mov x3, x0 - and x4, x2, #0x10 // Bytes to reach 32-byte alignment (0 or 16) - subs x5, x2, x4 // 32-byte aligned length - b.eq 2f -1: - ldp c6, c7, [x1], #32 // 32-byte loop - stp c6, c7, [x3], #32 - subs x5, x5, #32 - b.ne 1b -2: - cbz x4, 3f // 16-byte leftover (if any) - ldr c6, [x1], #16 - str c6, [x3], #16 -3: - ret -SYM_FUNC_END(morello_capcpy) - SYM_FUNC_START(__morello_thread_init_user) mov x9, #THREAD_MORELLO_USER_STATE add x0, x0, x9 // x0 = tsk->thread.morello_user_state
Now that we have our own header for CHERI APIs, let's include it instead of the compiler-provided cheriintrin.h. This also allows removing the #ifdef'ing, as linux/cheri.h already takes care of including cheriintrin.h if available.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com --- arch/arm64/kernel/signal.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index c21ef7bebcae..9e1e9c54a3e4 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -19,6 +19,7 @@ #include <linux/resume_user_mode.h> #include <linux/ratelimit.h> #include <linux/syscalls.h> +#include <linux/cheri.h>
#include <asm/daifflags.h> #include <asm/debug-monitors.h> @@ -38,10 +39,6 @@ #include <asm/traps.h> #include <asm/vdso.h>
-#ifdef CONFIG_CHERI_PURECAP_UABI -#include <cheriintrin.h> -#endif - #ifndef SIGNAL_COMPAT64 /* * Do a signal return; undo the signal stack. These are aligned to 128-bit.
Now that we have our own header for CHERI APIs, let's include it instead of the compiler-provided cheriintrin.h. This also allows removing the #ifdef'ing, as linux/cheri.h already takes care of including cheriintrin.h if available.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com --- lib/test_printf.c | 4 +--- lib/vsprintf.c | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-)
diff --git a/lib/test_printf.c b/lib/test_printf.c index b9bf303907e2..28e2b7f52dfc 100644 --- a/lib/test_printf.c +++ b/lib/test_printf.c @@ -24,9 +24,7 @@
#include <linux/property.h>
-#ifdef __CHERI__ -#include <cheriintrin.h> -#endif +#include <linux/cheri.h>
#include "../tools/testing/selftests/kselftest_module.h"
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index db0ec7372c4f..0e38291993ec 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -42,6 +42,7 @@ #include <linux/compiler.h> #include <linux/property.h> #include <linux/notifier.h> +#include <linux/cheri.h> #ifdef CONFIG_BLOCK #include <linux/blkdev.h> #endif @@ -52,10 +53,6 @@ #include <asm/byteorder.h> /* cpu_to_le16 */ #include <asm/unaligned.h>
-#ifdef __CHERI__ -#include <cheriintrin.h> -#endif - #include <linux/string_helpers.h> #include "kstrtox.h"
On 01-09-2023 12:30, Kevin Brodsky wrote:
Hi,
This is a short series that makes a few simplifications we can now afford: getting rid of morello_capcpy(), as it is unnecessary now that the kernel is a "proper" hybrid binary with a tag-preserving memcpy(); and making use of <linux/cheri.h> to simplify includes.
The Morello helpers could be further simplified by reimplementing many of them in C instead of assembly, issue #61 [1] was created to that end.
Review branch:
https://git.morello-project.org/kbrodsky-arm/linux/-/commits/morello/cheri_c...
Cheers, Kevin
Looks great!
Tudor
[1] https://git.morello-project.org/morello/kernel/linux/-/issues/61
Kevin Brodsky (3): arm64: morello: Replace morello_capcpy() with standard copy arm64: Replace cheriintrin.h with linux/cheri.h lib: Replace cheriintrin.h with linux/cheri.h
arch/arm64/include/asm/morello.h | 6 ------ arch/arm64/kernel/process.c | 9 +-------- arch/arm64/kernel/signal.c | 5 +---- arch/arm64/lib/morello.S | 18 ------------------ lib/test_printf.c | 4 +--- lib/vsprintf.c | 5 +---- 6 files changed, 4 insertions(+), 43 deletions(-)
On 01/09/2023 12:30, Kevin Brodsky wrote:
Hi,
This is a short series that makes a few simplifications we can now afford: getting rid of morello_capcpy(), as it is unnecessary now that the kernel is a "proper" hybrid binary with a tag-preserving memcpy(); and making use of <linux/cheri.h> to simplify includes.
The Morello helpers could be further simplified by reimplementing many of them in C instead of assembly, issue #61 [1] was created to that end.
Review branch:
https://git.morello-project.org/kbrodsky-arm/linux/-/commits/morello/cheri_c...
Cheers, Kevin
[1] https://git.morello-project.org/morello/kernel/linux/-/issues/61
Kevin Brodsky (3): arm64: morello: Replace morello_capcpy() with standard copy arm64: Replace cheriintrin.h with linux/cheri.h lib: Replace cheriintrin.h with linux/cheri.h
+1
Thanks, Zach
arch/arm64/include/asm/morello.h | 6 ------ arch/arm64/kernel/process.c | 9 +-------- arch/arm64/kernel/signal.c | 5 +---- arch/arm64/lib/morello.S | 18 ------------------ lib/test_printf.c | 4 +--- lib/vsprintf.c | 5 +---- 6 files changed, 4 insertions(+), 43 deletions(-)
On 01/09/2023 13:30, Kevin Brodsky wrote:
Kevin Brodsky (3): arm64: morello: Replace morello_capcpy() with standard copy arm64: Replace cheriintrin.h with linux/cheri.h lib: Replace cheriintrin.h with linux/cheri.h
Thanks Zach and Tudor for the reviews! Now in next.
Kevin
linux-morello@op-lists.linaro.org