Skip to content

Commit 807991e

Browse files
carlocaionenashif
authored andcommitted
AArch64: Do not use CONFIG_GEN_PRIV_STACKS
We are setting CONFIG_GEN_PRIV_STACKS when AArch64 actually uses a statically allocated privileged stack. This error was not captured by the tests because we only verify whether a read/write to a privileged stack is failing, but it can fail for a lot of reasons including when the pointer to the privileged stack is not initialized at all, like in this case. With this patch we deselect CONFIG_GEN_PRIV_STACKS and we fix the mem_protect/userspace test to correctly probe the privileged stack. Signed-off-by: Carlo Caione <[email protected]>
1 parent 1b41da2 commit 807991e

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

arch/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ config ARM
3232
select HAS_DTS
3333
# FIXME: current state of the code for all ARM requires this, but
3434
# is really only necessary for Cortex-M with ARM MPU!
35-
select GEN_PRIV_STACKS
35+
select GEN_PRIV_STACKS if !ARM64
3636
select ARCH_HAS_THREAD_LOCAL_STORAGE if ARM64 || CPU_CORTEX_R || CPU_CORTEX_M
3737
help
3838
ARM architecture

include/arch/arm/aarch64/thread_stack.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@
4747
#define ARCH_KERNEL_STACK_RESERVED 0
4848
#define ARCH_KERNEL_STACK_OBJ_ALIGN ARCH_STACK_PTR_ALIGN
4949

50+
#ifndef _ASMLANGUAGE
51+
52+
struct z_arm64_thread_stack_header {
53+
char privilege_stack[CONFIG_PRIVILEGED_STACK_SIZE];
54+
} __packed __aligned(Z_ARM64_STACK_BASE_ALIGN);
55+
56+
#endif /* _ASMLANGUAGE */
57+
5058
#endif /* ZEPHYR_INCLUDE_ARCH_ARM_AARCH64_THREAD_STACK_H_ */

tests/kernel/mem_protect/userspace/src/main.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,8 @@ static void test_init_and_access_other_memdomain(void)
666666
spawn_user(&default_bool);
667667
}
668668

669-
#if defined(CONFIG_ARM) || (defined(CONFIG_GEN_PRIV_STACKS) && defined(CONFIG_RISCV))
669+
#if (defined(CONFIG_ARM) || (defined(CONFIG_GEN_PRIV_STACKS) && defined(CONFIG_RISCV)) && \
670+
!defined(CONFIG_ARM64))
670671
extern uint8_t *z_priv_stack_find(void *obj);
671672
#endif
672673
extern k_thread_stack_t ztest_thread_stack[];
@@ -942,7 +943,13 @@ void test_main(void)
942943
/* Most of these scenarios use the default domain */
943944
k_mem_domain_add_partition(&k_mem_domain_default, &default_part);
944945

945-
#if defined(CONFIG_ARM)
946+
#if defined(CONFIG_ARM64)
947+
struct z_arm64_thread_stack_header *hdr;
948+
949+
hdr = ((struct z_arm64_thread_stack_header *)ztest_thread_stack);
950+
priv_stack_ptr = (((char *)&hdr->privilege_stack) +
951+
(sizeof(hdr->privilege_stack) - 1));
952+
#elif defined(CONFIG_ARM)
946953
priv_stack_ptr = (char *)z_priv_stack_find(ztest_thread_stack);
947954
#elif defined(CONFIG_X86)
948955
struct z_x86_thread_stack_header *hdr;

0 commit comments

Comments
 (0)