Migrating the libhugetlbfs/testcases/stack_grow_into_huge.c test
PATCH 1/1 Migrating the libhugetlbfs/testcases/stack_grow_into_huge.c test
Test Description:On PowerPC, the address space is divided into segments. These segments can contain either huge pages or normal pages, but not both.
All segments are initially set up to map normal pages. When a huge page mapping is created within a set of empty segments, they are "enabled" for huge pages at that time. Once enabled for huge pages, they can not be used again for normal pages for the remaining lifetime of the process.
If the segment immediately preceeding the segment containing the stack is converted to huge pages and the stack is made to grow into the this preceeding segment, some kernels may attempt to map normal pages into the huge page-only segment -- resulting in bugs.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap34.c | 145 ++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
runtest/hugetlb +1 -0
@@ -35,6 +35,7 @@ hugemmap29 hugemmap29 hugemmap30 hugemmap30 hugemmap31 hugemmap31 hugemmap32 hugemmap32 +hugemmap34 hugemmap34 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -34,6 +34,7 @@ /hugetlb/hugemmap/hugemmap30 /hugetlb/hugemmap/hugemmap31 /hugetlb/hugemmap/hugemmap32 +/hugetlb/hugemmap/hugemmap34 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c new file +145 -0
145 lines not on this page · raw message
Signature · 5 lines
2.39.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
First of all the whitespaces in the test are messed up, please make sure to run 'make check' and fix all the reported problems.
Quoted 32 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c new file +32
-0+void do_child (void *stop_address) +{ +struct rlimit r; +volatile int *x; + +/* corefile from this process is not interesting and limiting +* its size can save a lot of time. '1' is a special value, +* that will also abort dumping via pipe, which by default +* sets limit to RLIM_INFINITY. */ + r.rlim_cur =1 ; + r.rlim_max =1 ; +SAFE_SETRLIMIT (RLIMIT_CORE , &r); + +do { + x =alloca (STACK_ALLOCATION_SIZE ); + *x =1 ; + }while ((void *)x >= stop_address); +} + +static void run_test (void ) +{ +int pid, status, sig; +char *b; +void *stack_address, *mmap_address, *heap_address; + stack_address =alloca (0 ); + heap_address =sbrk (0 ); +/* +* paranoia: start mapping two hugepages below the start of the stack, +* in case the alignment would cause us to map over something if we +* only used a gap of one hugepage. +*/ + mmap_address =PALIGN (stack_address -2 * hpage_size, hpage_size);
testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c line 80
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c new file +10
-0+do { + b =SAFE_MMAP (mmap_address, hpage_size,PROT_READ |PROT_WRITE , +MAP_FIXED |MAP_SHARED , fd,0 ); + mmap_address -= hpage_size; +/* +* if we get all the way down to the heap, stop trying +*/ +if (mmap_address <= heap_address) +break ; + }while (b ==MAP_FAILED );
This definitelly wouldn't work as expected, SAFE_MMAP() cannot fail, it does exit the test if it fails.
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c new file +10
-0+if (b ==MAP_FAILED ) +tst_res (TFAIL ,"mmap() at unexpected address %p instead of %p\n" , b, + mmap_address); + + pid =SAFE_FORK (); +if (pid ==0 ) { +do_child (mmap_address); +exit (0 ); + } +SAFE_WAITPID (pid, &status,0 );
testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c line 101
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c new file +10
-0+ +if (WIFSIGNALED (status)) { + sig =WTERMSIG (status); + +if (sig ==SIGSEGV ) { +tst_res (TPASS ,"Test Passed" ); +exit (0 ); + }else { +tst_res (TFAIL ,"Got unexpected signal: %s" ,strsignal (sig)); +exit (1 );
No calls to exit(1) in the test, the tst_res() is used to report test results.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c line 104
Quoted 3 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c new file +3
-0+ } + } +tst_res (TFAIL ,"Child not signalled" );
This should use tst_strstatus() to print what has happened to the child. Have a look at syscalls/mmap/mmap18.c how it's done.
Quoted 47 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c new file +41
-0+} + +void setup (void ) +{ +struct rlimit r; + page_size =getpagesize (); + hpage_size =tst_get_hugepage_size (); +/* +* Setting the stack size to unlimited. +*/ + r.rlim_cur =RLIM_INFINITY ; + r.rlim_max =RLIM_INFINITY ; +SAFE_SETRLIMIT (RLIMIT_STACK , &r); + +SAFE_GETRLIMIT (RLIMIT_STACK , &r); +if (r.rlim_cur !=RLIM_INFINITY ) +tst_brk (TCONF ,"Stack rlimit must be 'unlimited'" ); + fd =tst_creat_unlinked (MNTPOINT ,0 ); +} + +void cleanup (void ) +{ +if (fd >0 ) +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .tags = (struct tst_tag []) { + {"linux-git" ,"0d59a01bc461" }, + {} + }, + .needs_root =1 , + .mntpoint =MNTPOINT , + .needs_hugetlbfs =1 , + .needs_tmpdir =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {2 ,TST_NEEDS }, + .forks_child =1 , +};Signature · 5 lines
2.39.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp