Skip to content

Commit 6c01157

Browse files
cfriedtjhedberg
authored andcommitted
kernel: dynamic: update storage size for pool of dynamic thread stacks
Commit 5c5e17f introduced a subtle regression when userspace was configured on architectures requiring guard pages. Prior to 5c5e17f, the assumption was that guard pages would be included in `CONFIG_DYNAMIC_THREAD_STACK_SIZE`, and that was something that the caller of `k_thread_stack_alloc()` would need to be aware of, although it was not documented at all, unfortunately. It seems that 5c5e17f intended to remove the need for that assumption, but the necessary conditions for doing so had not been met. Update pool storage size to account for guard pages, which ensures that users can access every byte of `CONFIG_DYNAMIC_THREAD_STACK_SIZE` rather than needing to be aware that guard pages would be included in the requested size. The compromise is a more intuitive API at the cost of more storage space for the pool of thread stacks when userspace is enabled. Signed-off-by: Chris Friedt <[email protected]>
1 parent 4c221ac commit 6c01157

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

kernel/dynamic.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,18 @@ struct dyn_cb_data {
2828
};
2929

3030
static K_THREAD_STACK_ARRAY_DEFINE(dynamic_stack, CONFIG_DYNAMIC_THREAD_POOL_SIZE,
31-
CONFIG_DYNAMIC_THREAD_STACK_SIZE);
31+
K_THREAD_STACK_LEN(CONFIG_DYNAMIC_THREAD_STACK_SIZE));
3232
SYS_BITARRAY_DEFINE_STATIC(dynamic_ba, BA_SIZE);
3333

3434
static k_thread_stack_t *z_thread_stack_alloc_pool(size_t size, int flags)
3535
{
3636
int rv;
3737
size_t offset;
3838
k_thread_stack_t *stack;
39-
const size_t max_size = ((flags & K_USER) != 0) ? K_THREAD_STACK_SIZEOF(dynamic_stack[0]) :
40-
K_KERNEL_STACK_SIZEOF(dynamic_stack[0]);
4139

42-
if (size > max_size) {
43-
LOG_DBG("stack size %zu is > pool stack size %zu", size, max_size);
40+
if (size > CONFIG_DYNAMIC_THREAD_STACK_SIZE) {
41+
LOG_DBG("stack size %zu is > pool stack size %zu", size,
42+
(size_t)CONFIG_DYNAMIC_THREAD_STACK_SIZE);
4443
return NULL;
4544
}
4645

tests/posix/common/testcase.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ tests:
7070
- CONFIG_THREAD_STACK_INFO=n
7171
portability.posix.common.userspace:
7272
filter: CONFIG_ARCH_HAS_USERSPACE
73-
# Excluded while #96602 is in review
74-
platform_exclude:
75-
- mps2/an385
7673
tags:
7774
- userspace
7875
extra_configs:

0 commit comments

Comments
 (0)