mmap18: fix when PTHREAD_STACK_MIN < PAGE_SIZE
PATCH 1/1 mmap18: fix when PTHREAD_STACK_MIN < PAGE_SIZE
PTHREAD_STACK_MIN can be less than the page size, to be more precise 2048 on musl. This value is used in the test as an offset for a new stack address with mmap() + MAP_FIXED flag. Though it might not be aligned to the page size.
This breaks the test with musl:
tst_test.c:1311: TINFO: Timeout per run is 0h 05m 00s mmap18.c:98: TBROK: mmap(0x7fe67e2ee800,2048,3,306,-1,0) failed: EINVAL (22) mmap18.c:169: TFAIL: Child: exited with 2
[...]
The fix is to align mapped_size arg to the page size.
--- testcases/kernel/syscalls/mmap/mmap18.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/mmap/mmap18.c +4 -3
@@ -200,11 +200,12 @@ static void grow_stack_fail(size_t stack_size, size_t mapped_size)static void run_test (void ) { -size_t stack_size =8 *PTHREAD_STACK_MIN ; +size_t pthread_stack =LTP_ALIGN (PTHREAD_STACK_MIN ,getpagesize ()); +size_t stack_size =8 * pthread_stack; -grow_stack_success (stack_size,PTHREAD_STACK_MIN ); +grow_stack_success (stack_size, pthread_stack);grow_stack_success (stack_size, stack_size/2 ); -grow_stack_fail (stack_size,PTHREAD_STACK_MIN ); +grow_stack_fail (stack_size, pthread_stack);grow_stack_fail (stack_size, stack_size/2 ); }
Signature · 1 line
2.25.1
PATCH 1/1 mmap18: fix when PTHREAD_STACK_MIN < PAGE_SIZE
Hi!
Quoted 24 lines
PTHREAD_STACK_MINcan be less than the page size, to be more precise 2048 on musl. This value is used in the test as an offset for a new stack address withmmap()+MAP_FIXEDflag. Though it might not be aligned to the page size.This breaks the test with musl:
tst_test.c:1311: TINFO: Timeout per run is 0h 05m 00s mmap18.c:98: TBROK:
mmap(0x7fe67e2ee800,2048,3,306,-1,0)failed: EINVAL (22) mmap18.c:169: TFAIL: Child: exited with 2
[...]The fix is to align
mapped_sizearg to the page size.Signed-off-by Alexey Kodanev <[email protected]>--- testcases/kernel/syscalls/mmap/mmap18.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)testcases/kernel/syscalls/mmap/mmap18.c +0
-0
testcases/kernel/syscalls/mmap/mmap18.c static void grow_stack_fail(size_t stack_size, size_t mapped_size) · line 204
Quoted 6 lines
testcases/kernel/syscalls/mmap/mmap18.c +2
-1@@ -200,11 +200,12 @@ static void grow_stack_fail(size_t stack_size, size_t mapped_size)static void run_test (void ) { -size_t stack_size =8 *PTHREAD_STACK_MIN ; +size_t pthread_stack =LTP_ALIGN (PTHREAD_STACK_MIN ,getpagesize ()); +size_t stack_size =8 * pthread_stack;
Looking at the code we have to align both stack size and mapped size so this is correct. I guess that we can save a bit by aligning each of them independently since 8 * PTHREAD_STACK_MIN would in most cases be aligned allready.
size_t pthread_stack = LTP_ALIGN(PTHREAD_STACK_MIN, getpagesize()); size_t stack_size = LTP_ALIGN(8 * PTHREAD_STACK_MIN, getpagesize());
Either way this looks good so:
Quoted 14 lines
testcases/kernel/syscalls/mmap/mmap18.c +2
-2-grow_stack_success (stack_size,PTHREAD_STACK_MIN ); +grow_stack_success (stack_size, pthread_stack);grow_stack_success (stack_size, stack_size/2 ); -grow_stack_fail (stack_size,PTHREAD_STACK_MIN ); +grow_stack_fail (stack_size, pthread_stack);grow_stack_fail (stack_size, stack_size/2 ); }Signature · 5 lines
2.25.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 mmap18: fix when PTHREAD_STACK_MIN < PAGE_SIZE
Hi Cyril,
Quoted 37 lines · Cyril Hrubis
Hi!
Quoted 24 lines
PTHREAD_STACK_MINcan be less than the page size, to be more precise 2048 on musl. This value is used in the test as an offset for a new stack address withmmap()+MAP_FIXEDflag. Though it might not be aligned to the page size.This breaks the test with musl:
tst_test.c:1311: TINFO: Timeout per run is 0h 05m 00s mmap18.c:98: TBROK:
mmap(0x7fe67e2ee800,2048,3,306,-1,0)failed: EINVAL (22) mmap18.c:169: TFAIL: Child: exited with 2
[...]The fix is to align
mapped_sizearg to the page size.Signed-off-by Alexey Kodanev <[email protected]>--- testcases/kernel/syscalls/mmap/mmap18.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)testcases/kernel/syscalls/mmap/mmap18.c +0
-0testcases/kernel/syscalls/mmap/mmap18.c static void grow_stack_fail(size_t stack_size, size_t mapped_size) · line 204
Quoted 6 lines
testcases/kernel/syscalls/mmap/mmap18.c +2
-1@@ -200,11 +200,12 @@ static void grow_stack_fail(size_t stack_size, size_t mapped_size)static void run_test (void ) { -size_t stack_size =8 *PTHREAD_STACK_MIN ; +size_t pthread_stack =LTP_ALIGN (PTHREAD_STACK_MIN ,getpagesize ()); +size_t stack_size =8 * pthread_stack;Looking at the code we have to align both stack size and mapped size so this is correct. I guess that we can save a bit by aligning each of them independently since 8 *
PTHREAD_STACK_MINwould in most cases be aligned allready.
Quoted 6 lines
size_t pthread_stack = LTP_ALIGN(PTHREAD_STACK_MIN, getpagesize()); size_t stack_size = LTP_ALIGN(8 * PTHREAD_STACK_MIN, getpagesize());Either way this looks good so:
Reviewed-by Cyril Hrubis <[email protected]>
Thanks for review!
Applied the original patch, it keeps the original proportion between stack_size and mapped_size for both libc, also stack_size divided by two after that for the mapped_size arg (though it doesn't really matter with 8 * 2048):
Quoted 8 lines
Quoted 8 lines
testcases/kernel/syscalls/mmap/mmap18.c +2
-2-grow_stack_success (stack_size,PTHREAD_STACK_MIN ); +grow_stack_success (stack_size, pthread_stack);grow_stack_success (stack_size, stack_size/2 ); -grow_stack_fail (stack_size,PTHREAD_STACK_MIN ); +grow_stack_fail (stack_size, pthread_stack);grow_stack_fail (stack_size, stack_size/2 ); }