Hugetlb:Migrating the libhugetlbfs tests
cover Hugetlb:Migrating the libhugetlbfs tests
Hi,
This patch series is in continuation to part [1], part [2] and part [3]. This series include 13 more tests taken from libhugetlbfs.
Background:
Libhugetlbfs is not being maintained actively, and some distro is dropping support for it. There are some tests that are good for testing hugetlb functionality in kernel. These patches include tests from libhugetlbfs.
ref:
1. https://lore.kernel.org/all/[email protected]/
2. https://lore.kernel.org/all/[email protected]/
3. https://lore.kernel.org/all/[email protected]/
Tarun Sahu (13):
Hugetlb: Migrating libhugetlbfs mlock
Hugetlb: Migrating libhugetlbfs mmap-cow
Hugetlb: Migrating libhugetlbfs mmap-gettest
Hugetlb: Migrating libhugetlbfs mprotect
Hugetlb: Migrating libhugetlbfs mremap-fixed-huge-near-normal
Hugetlb: Migrating libhugetlbfs mremap-fixed-normal-near-huge
Hugetlb: Migrating libhugetlbfs noresv-reserve-resv-page
Hugetlb: Migrating libhugetlbfs noresv-regarded-as-resv
Hugetlb: Migrating libhugetlbfs private
Hugetlb: Migrating libhugetlbfs readahead_reserve
Hugetlb: Migrating libhugetlbfs shared
Hugetlb: Migrating libhugetlbfs shm-fork
Hugetlb: Migrating libhugetlbfs mremap-expand-slice-collision
runtest/hugetlb | 13 + testcases/kernel/mem/.gitignore | 13 + .../kernel/mem/hugetlb/hugefork/hugefork02.c | 104 ++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap20.c | 88 +++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap21.c | 131 ++++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap22.c | 104 ++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap23.c | 244 ++++++++++++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap24.c | 212 +++++++++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap25.c | 146 +++++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap26.c | 131 ++++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap27.c | 136 ++++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap28.c | 74 ++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap29.c | 115 +++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap30.c | 85 ++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap31.c | 84 ++++++ 15 files changed, 1680 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugefork/hugefork02.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap24.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap25.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap27.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap28.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap30.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap31.c
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 1/13 Hugetlb: Migrating libhugetlbfs mlock
Migrating the libhugetlbfs/testcases/mlock.c test
Test Description: The test checks that mlocking hugetlb areas works with all combinations of MAP_PRIVATE and MAP_SHARED with and without MAP_LOCKED specified.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap20.c | 88 +++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c
runtest/hugetlb +1 -0
@@ -21,6 +21,7 @@ hugemmap16 hugemmap16 hugemmap17 hugemmap17 hugemmap18 hugemmap18 hugemmap19 hugemmap19 +hugemmap20 hugemmap20 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -20,6 +20,7 @@ /hugetlb/hugemmap/hugemmap17 /hugetlb/hugemmap/hugemmap18 /hugetlb/hugemmap/hugemmap19 +/hugetlb/hugemmap/hugemmap20 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c new file +88 -0
88 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 01/13] Hugetlb: Migrating libhugetlbfs mlock
Quoted 112 lines · Tarun Sahu
Migrating the
libhugetlbfs/testcases/mlock.ctestTest Description: The test checks that mlocking hugetlb areas works with all combinations of
MAP_PRIVATEandMAP_SHAREDwith and withoutMAP_LOCKEDspecified.Signed-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap20.c | 88 +++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.cruntest/hugetlb +1
-0@@ -21,6 +21,7 @@ hugemmap16 hugemmap16 hugemmap17 hugemmap17 hugemmap18 hugemmap18 hugemmap19 hugemmap19 +hugemmap20 hugemmap20 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -20,6 +20,7 @@ /hugetlb/hugemmap/hugemmap17 /hugetlb/hugemmap/hugemmap18 /hugetlb/hugemmap/hugemmap19 +/hugetlb/hugemmap/hugemmap20 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c new file +37
-0@@ -0,0 +1,88 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation. +* Author: David Gibson & Adam Litke +*/ + +/*\ +* [Description] +* +* The test checks that mlocking hugetlb areas works with all combinations +* of MAP_PRIVATE and MAP_SHARED with and without MAP_LOCKED specified. +*/ + +#include <stdio.h> +#include <sys/mount.h> +#include <limits.h> +#include <sys/param.h> +#include <sys/types.h> +#include <sys/resource.h> + +#include "hugetlb.h" + +#define MNTPOINT "hugetlbfs/" +static int fd =-1 ; +static unsigned long hpage_size; + +static void test_simple_mlock (int flags,char *flags_str) +{ +void *p; +int ret; + + fd =tst_creat_unlinked (MNTPOINT ,0 ); + p =SAFE_MMAP (0 , hpage_size,PROT_READ |PROT_WRITE , flags, fd,0 ); + + ret =mlock (p, hpage_size); +if (ret) { + tst_res(TFAIL|TERRNO, "mlock() failed (flags %s)",
flags_str);testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c new file +6
-0+ goto cleanup; + } + + ret =munlock (p, hpage_size); +if (ret) + tst_res(TFAIL|TERRNO, "munlock() failed (flags %s)",
flags_str);testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c new file +14
-0+else +tst_res (TPASS ,"mlock/munlock with %s hugetlb mmap" , + flags_str); +cleanup: +SAFE_MUNMAP (p, hpage_size); +SAFE_CLOSE (fd); +} + +static void run_test (void ) +{ +struct rlimit limit_info; + +if (getrlimit (RLIMIT_MEMLOCK , &limit_info)) + tst_res(TWARN|TERRNO, "Unable to read locked memoryrlimit");
testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c new file +2
-0+if (limit_info.rlim_cur < hpage_size) + tst_brk(TCONF, "Locked memory ulimit set below huge page
Quoted 2 lines
size");
These lines are better for moving into setup() phase. And, I'd propose printing the value of 'limit_info.rlim_cur' and 'hpage_size' when TCONF.
The default value of max-locked-memory is smaller than hpage_size on both RHEL8 and 9, which means this test will TCONF and skip running. I'm hesitating should we temporally cancel the limitations and make this test can really perform then restore that value to the original, is this change make sense? WDYT?
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c new file +4
-0+ +test_simple_mlock (MAP_PRIVATE ,"MAP_PRIVATE" ); +test_simple_mlock (MAP_SHARED ,"MAP_SHARED" ); + test_simple_mlock(MAP_PRIVATE|MAP_LOCKED,"MAP_PRIVATE|MAP_LOCKED");
+test_simple_mlock(MAP_SHARED|MAP_LOCKED, "MAP_SHARED|MAP_LOCKED");
If we define an additional function like flags_to_str(int flags) for converting
the flag into a string, which will be more simple for reading.
static char *flags_to_str(int flags)
{
...
}static void test_simple_mlock(int flags)
{
char *flags_str = flags_to_str(flags);
...
}Quoted 28 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c new file +24
-1+ +} + +static void setup (void ) +{ + hpage_size =SAFE_READ_MEMINFO (MEMINFO_HPAGE_SIZE )*1024 ; +} + +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .needs_root =1 , + .mntpoint =MNTPOINT , + .needs_hugetlbfs =1 , + .needs_tmpdir =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {1 ,TST_NEEDS }, +}; --2.31.1
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 01/13] Hugetlb: Migrating libhugetlbfs mlock
Hi Li,
Thanks for reviewing the patch.
Please find my comments inline.
--skip
Quoted 17 lines · Li Wang
Quoted 13 lines · Tarun Sahu
testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c new file +6
-0+static void run_test (void ) +{ +struct rlimit limit_info; + +if (getrlimit (RLIMIT_MEMLOCK , &limit_info)) + tst_res(TWARN|TERRNO, "Unable to read locked memoryrlimit");
(quoted diff) +2
-0+ if (limit_info.rlim_cur < hpage_size) + tst_brk(TCONF, "Locked memory ulimit set below huge pageQuoted 2 lines
size");
Quoted 9 lines
These lines are better for moving into
setup()phase. And, I'd propose printing the value of 'limit_info.rlim_cur' and 'hpage_size' when TCONF.The default value of max-locked-memory is smaller than
hpage_sizeon both RHEL8 and 9, which means this test will TCONF and skip running. I'm hesitating should we temporally cancel the limitations and make this test can really perform then restore that value to the original, is this change make sense? WDYT?
Yeah, Incase if limit is smaller than expected, we can change it temporarily to run the test. Will update in next revision. Also will change, getrlimit/setrlimit function to SAFE_*.
Quoted 19 lines
Quoted 9 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c new file +4
-0+ +test_simple_mlock (MAP_PRIVATE ,"MAP_PRIVATE" ); +test_simple_mlock (MAP_SHARED ,"MAP_SHARED" ); + test_simple_mlock(MAP_PRIVATE|MAP_LOCKED,"MAP_PRIVATE|MAP_LOCKED");
+test_simple_mlock(MAP_SHARED|MAP_LOCKED, "MAP_SHARED|MAP_LOCKED");If we define an additional function like
flags_to_str(int flags)for converting
the flag into a string, which will be more simple for reading.static char *flags_to_str(int flags)
{ ... }
Quoted 6 lines
static void
test_simple_mlock(int flags){ char *flags_str = flags_to_str(flags); ... }
It was not used so often and only some specific flags are used. I think if there will be more general use case being some more mmap flags used in application, then it would be good to change this to function.
Another way is to define a macro like
#define FLAGS_STR(flag) #flag
and pass it like: test_simple_mlock(flag, FLAGS_STR(flag));
But I thought, it is like passing the string itself.
what do you think?
Quoted 37 lines
Quoted 30 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c new file +24
-1+ +} + +static void setup (void ) +{ + hpage_size =SAFE_READ_MEMINFO (MEMINFO_HPAGE_SIZE )*1024 ; +} + +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .needs_root =1 , + .mntpoint =MNTPOINT , + .needs_hugetlbfs =1 , + .needs_tmpdir =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {1 ,TST_NEEDS }, +}; --2.31.1
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 01/13] Hugetlb: Migrating libhugetlbfs mlock
Quoted 71 lines · Tarun Sahu
Hi Li,
Thanks for reviewing the patch.
Please find my comments inline.--skip
Quoted 7 lines · Li Wang
Quoted 3 lines · Tarun Sahu
(quoted diff) +2
-0+static void run_test(void) +{Quoted 7 lines
Review
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c new file +4
-0+struct rlimit limit_info; + +if (getrlimit (RLIMIT_MEMLOCK , &limit_info)) + tst_res(TWARN|TERRNO, "Unable to read locked memoryrlimit");
(quoted diff) +2
-0+ if (limit_info.rlim_cur < hpage_size) + tst_brk(TCONF, "Locked memory ulimit set below hugepage
Quoted 12 lines
Quoted 2 lines
size");
These lines are better for moving into
setup()phase. And, I'd propose printing the value of 'limit_info.rlim_cur' and 'hpage_size' when TCONF.The default value of max-locked-memory is smaller than
hpage_sizeon both RHEL8 and 9, which means this test will TCONF and skip running. I'm hesitating should we temporally cancel the limitations and make this test can really perform then restore that value to the original, is this change make sense? WDYT?Yeah, Incase if limit is smaller than expected, we can change it temporarily
to run the test. Will update in next revision. Also will change, getrlimit/setrlimit function to SAFE_*.Quoted 8 lines
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c new file +4
-0+ +test_simple_mlock (MAP_PRIVATE ,"MAP_PRIVATE" ); +test_simple_mlock (MAP_SHARED ,"MAP_SHARED" ); + test_simple_mlock(MAP_PRIVATE|MAP_LOCKED,"MAP_PRIVATE|MAP_LOCKED");
+ test_simple_mlock(MAP_SHARED|MAP_LOCKED,"MAP_SHARED|MAP_LOCKED");
Quoted 11 lines
Quoted 1 line
If we define an additional function like
flags_to_str(int flags)for converting
the flag into a string, which will be more simple for reading.static char *flags_to_str(int flags)
{ ... }Quoted 6 lines
static void
test_simple_mlock(int flags){ char *flags_str = flags_to_str(flags); ... }It was not used so often and only some specific flags are used. I think if there will be more general use case being some more mmap flags used in application, then it would be good to change this to function.
Another way is to define a macro like
Quoted 8 lines
#define
FLAGS_STR(flag)#flagand pass it like:
test_simple_mlock(flag, FLAGS_STR(flag));But I thought, it is like passing the string itself.
what do you think?
Yes sure, and I think of we have TST_TO_STR() in LTP as well.
$ git grep TST_TO_STR tst_common.h:#define TST_TO_STR_(s) #s tst_common.h:#define TST_TO_STR(s) TST_TO_STR_(s)
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/13 Hugetlb: Migrating libhugetlbfs mmap-cow
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/mmap-cow.c test
Test Description: Tests copy-on-write semantics of large pages where a number of threads map the same file with the MAP_PRIVATE flag. The threads then write into their copy of the mapping and recheck the contents to ensure they were not corrupted by the other threads.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap21.c | 131 ++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c
runtest/hugetlb +1 -0
@@ -22,6 +22,7 @@ hugemmap17 hugemmap17 hugemmap18 hugemmap18 hugemmap19 hugemmap19 hugemmap20 hugemmap20 +hugemmap21 hugemmap21 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -21,6 +21,7 @@ /hugetlb/hugemmap/hugemmap18 /hugetlb/hugemmap/hugemmap19 /hugetlb/hugemmap/hugemmap20 +/hugetlb/hugemmap/hugemmap21 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c new file +131 -0
131 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 02/13] Hugetlb: Migrating libhugetlbfs mmap-cow
Quoted 110 lines · Tarun Sahu
Migrating the
libhugetlbfs/testcases/mmap-cow.ctestTest Description: Tests copy-on-write semantics of large pages where a number of threads map the same file with the
MAP_PRIVATEflag. The threads then write into their copy of the mapping and recheck the contents to ensure they were not corrupted by the other threads.Signed-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap21.c | 131 ++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.cruntest/hugetlb +1
-0@@ -22,6 +22,7 @@ hugemmap17 hugemmap17 hugemmap18 hugemmap18 hugemmap19 hugemmap19 hugemmap20 hugemmap20 +hugemmap21 hugemmap21 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -21,6 +21,7 @@ /hugetlb/hugemmap/hugemmap18 /hugetlb/hugemmap/hugemmap19 /hugetlb/hugemmap/hugemmap20 +/hugetlb/hugemmap/hugemmap21 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c new file +46
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2005-2006 IBM Corporation. +* Author: David Gibson & Adam Litke +*/ + +/*\ +* [Description] +* +* Tests copy-on-write semantics of large pages where a number of threads +* map the same file with the MAP_PRIVATE flag. The threads then write +* into their copy of the mapping and recheck the contents to ensure they +* were not corrupted by the other threads. +*/ + +#include <stdio.h> +#include <sys/mount.h> +#include <limits.h> +#include <sys/param.h> +#include <sys/types.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> +#include <sys/shm.h> +#include <sys/wait.h> + +#include "hugetlb.h" + +#define BUF_SZ 256 +#define THREADS 5 +#define NR_HUGEPAGES 6 +#define MNTPOINT "hugetlbfs/" + +static int fd =-1 ; +static long hpage_size; + +static void do_work (int thread,size_t size,int fd) +{ +char *addr; +size_t i; +char pattern = thread+65 ; + + addr = SAFE_MMAP(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE,fd, 0);
testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c new file +14
-0+ +tst_res (TINFO ,"Thread %d (pid %d): Mapped at address %p" , + thread,getpid (), addr); + +for (i =0 ; i < size; i++) +memcpy ((char *)addr+i, &pattern,1 ); + +if (msync (addr, size,MS_SYNC )) +tst_brk (TBROK |TERRNO ,"Thread %d (pid %d): msync() failed" , + thread,getpid ()); + +for (i =0 ; i < size; i++) +if (addr[i] != pattern) { + tst_res(TFAIL, "thread %d (pid: %d): Corruption at%p; "
testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c new file +6
-0+"Got %c, Expected %c" , thread,getpid (), + &addr[i], addr[i], pattern); + goto cleanup; + } +tst_res (TINFO ,"Thread %d (pid %d): Pattern verified" , + thread,getpid ());
Maybe combining the address output with the content of patterns is better?
i.e.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c +0 -0
@@ -45,9 +45,6 @@ static void do_work(int thread, size_t size, int fd) addr = SAFE_MMAP(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd,
0);
- tst_res(TINFO, "Thread %d (pid %d): Mapped at address %p",
- thread, getpid(), addr);
-
for (i = 0; i < size; i++)
memcpy((char *)addr+i, &pattern, 1);@@ -62,8 +59,8 @@ static void do_work(int thread, size_t size, int fd)
&addr[i], addr[i], pattern);
goto cleanup;
}- tst_res(TINFO, "Thread %d (pid %d): Pattern verified",
- thread, getpid());
+ tst_res(TINFO, "Thread %d (pid %d): Pattern %c verified at address
%p",
+ thread, getpid(), pattern, addr);
cleanup:
SAFE_MUNMAP(addr, size);
Quoted 37 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c new file +23
-0+ +cleanup: +SAFE_MUNMAP (addr, size); +exit (0 ); +} + +static void run_test (void ) +{ +char *addr; +size_t size, itr; +int i, pid; +pid_t *wait_list; + + wait_list =SAFE_MALLOC (THREADS *sizeof (pid_t)); + size = (NR_HUGEPAGES / (THREADS +1 )) * hpage_size; + + +/* First, mmap the file with MAP_SHARED and fill with data +* If this is not done, then the fault handler will not be +* called in the kernel since private mappings will be +* created for the children at prefault time. +*/ + addr = SAFE_MMAP(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd,0);
testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c new file +12
-0+ +for (itr =0 ; itr < size; itr +=8 ) +memcpy (addr+itr,"deadbeef" ,8 ); + +for (i =0 ; i <THREADS ; i++) { + pid =SAFE_FORK (); + +if (pid ==0 ) +do_work (i, size, fd); + + wait_list[i] = pid; + }
testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c new file +10
-0+tst_reap_children (); + +SAFE_MUNMAP (addr, size); +free (wait_list); +tst_res (TPASS ,"mmap COW working as expected." ); +} + +static void setup (void ) +{ + hpage_size =SAFE_READ_MEMINFO (MEMINFO_HPAGE_SIZE )*1024 ;
We do have a dedicated function named tst_get_hugepage_size(); could be used for getting huge page size.
The rest part looks good to me.
Quoted 24 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c new file +20
-1+ fd =tst_creat_unlinked (MNTPOINT ,0 ); +} + +static void cleanup (void ) +{ +if (fd >=1 ) +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .needs_root =1 , + .mntpoint =MNTPOINT , + .needs_hugetlbfs =1 , + .needs_tmpdir =1 , + .forks_child =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {NR_HUGEPAGES ,TST_NEEDS }, +}; --2.31.1
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 02/13] Hugetlb: Migrating libhugetlbfs mmap-cow
Hi Li,
Thanks for reviewing the patch.
Please find my comments inline.
--skip
Quoted 59 lines
Quoted 24 lines
(quoted diff) +7
-0+static void do_work(int thread, size_t size, int fd) +{ + char *addr; + size_t i; + char pattern = thread+65; + + addr = SAFE_MMAP(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE,fd, 0);
(quoted diff) +14
-0+ + tst_res(TINFO, "Thread %d (pid %d): Mapped at address %p", + thread, getpid(), addr); + + for (i = 0; i < size; i++) + memcpy((char *)addr+i, &pattern, 1); + + if (msync(addr, size, MS_SYNC)) + tst_brk(TBROK|TERRNO, "Thread %d (pid %d): msync() failed", + thread, getpid()); + + for (i = 0; i < size; i++) + if (addr[i] != pattern) { + tst_res(TFAIL, "thread %d (pid: %d): Corruption at%p; "
Review
Quoted 6 lines
(quoted diff) +6
-0+ "Got %c, Expected %c", thread, getpid(), + &addr[i], addr[i], pattern); + goto cleanup; + } + tst_res(TINFO, "Thread %d (pid %d): Pattern verified", + thread, getpid());Maybe combining the address output with the content of patterns is better?
i.e.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c +2
-5@@ -45,9 +45,6 @@ static void do_work(int thread, size_t size, int fd) addr =SAFE_MMAP (NULL , size,PROT_READ |PROT_WRITE ,MAP_PRIVATE , fd,0 ); -tst_res (TINFO ,"Thread %d (pid %d): Mapped at address %p" , - thread,getpid (), addr); -for (i =0 ; i < size; i++)memcpy ((char *)addr+i, &pattern,1 );@@ -62,8 +59,8 @@ static void do_work(int thread, size_t size, int fd) &addr[i], addr[i], pattern); goto cleanup; } -tst_res (TINFO ,"Thread %d (pid %d): Pattern verified" , - thread,getpid ()); + tst_res(TINFO, "Thread %d (pid %d): Pattern %c verified at address %p", + thread,getpid (), pattern, addr); cleanup:
Quoted 2 lines
SAFE_MUNMAP(addr, size);
In case of failure, this verified comment will not get printed. In case of success, I dont think it matters to show the content of pattern.
Quoted 44 lines
Quoted 44 lines
(quoted diff) +23
-0+ +cleanup: + SAFE_MUNMAP(addr, size); + exit(0); +} + +static void run_test(void) +{ + char *addr; + size_t size, itr; + int i, pid; + pid_t *wait_list; + + wait_list = SAFE_MALLOC(THREADS * sizeof(pid_t)); + size = (NR_HUGEPAGES / (THREADS+1)) * hpage_size; + + + /* First, mmap the file with MAP_SHARED and fill with data + * If this is not done, then the fault handler will not be + * called in the kernel since private mappings will be + * created for the children at prefault time. + */ + addr = SAFE_MMAP(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd,0);
(quoted diff) +18
-0+ + for (itr = 0; itr < size; itr += 8) + memcpy(addr+itr, "deadbeef", 8); + + for (i = 0; i < THREADS; i++) { + pid = SAFE_FORK(); + + if (pid == 0) + do_work(i, size, fd); + + wait_list[i] = pid; + } + tst_reap_children(); + + SAFE_MUNMAP(addr, size); + free(wait_list); + tst_res(TPASS, "mmap COW working as expected."); +}
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +4
-0+ +static void setup(void) +{ + hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;We do have a dedicated function named
tst_get_hugepage_size(); could be used for getting huge page size.
Oh right! I could have used it in all other previous tests too. Thanks for pointing this, Will take care of it in next revision.
Quoted 38 lines
The rest part looks good to me.
Reviewed-by Li Wang <[email protected]>Quoted 24 lines
(quoted diff) +20
-1+ fd = tst_creat_unlinked(MNTPOINT, 0); +} + +static void cleanup(void) +{ + if (fd >= 1) + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .needs_root = 1, + .mntpoint = MNTPOINT, + .needs_hugetlbfs = 1, + .needs_tmpdir = 1, + .forks_child = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {NR_HUGEPAGES, TST_NEEDS}, +}; --2.31.1
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 3/13 Hugetlb: Migrating libhugetlbfs mmap-gettest
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/mmap-gettest.c test
Test Description: This baseline test validates that a mapping of a certain size can be created, correctly. Once created, all the pages are filled with a pattern and rechecked to test for corruption. The mapping is then released. This process is repeated for a specified number of iterations.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap22.c | 104 ++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c
runtest/hugetlb +1 -0
@@ -23,6 +23,7 @@ hugemmap18 hugemmap18 hugemmap19 hugemmap19 hugemmap20 hugemmap20 hugemmap21 hugemmap21 +hugemmap22 hugemmap22 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -22,6 +22,7 @@ /hugetlb/hugemmap/hugemmap19 /hugetlb/hugemmap/hugemmap20 /hugetlb/hugemmap/hugemmap21 +/hugetlb/hugemmap/hugemmap22 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c new file +104 -0
104 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 03/13] Hugetlb: Migrating libhugetlbfs mmap-gettest
Quoted 10 lines · Tarun Sahu
Migrating the
libhugetlbfs/testcases/mmap-gettest.ctestTest Description: This baseline test validates that a mapping of a certain size can be created, correctly. Once created, all the pages are filled with a pattern and rechecked to test for corruption. The mapping is then released. This process is repeated for a specified number of iterations.
Signed-off-by Tarun Sahu <[email protected]>
Quoted 54 lines
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap22.c | 104 ++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.cruntest/hugetlb +1
-0@@ -23,6 +23,7 @@ hugemmap18 hugemmap18 hugemmap19 hugemmap19 hugemmap20 hugemmap20 hugemmap21 hugemmap21 +hugemmap22 hugemmap22 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -22,6 +22,7 @@ /hugetlb/hugemmap/hugemmap19 /hugetlb/hugemmap/hugemmap20 /hugetlb/hugemmap/hugemmap21 +/hugetlb/hugemmap/hugemmap22 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c new file +14
-0@@ -0,0 +1,104 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2005-2006 IBM Corporation. +* Author: David Gibson & Adam Litke +*/ + +/*\ +* [Description] +* +* This baseline test validates that a mapping of a certain size can be +* created, correctly. Once created, all the pages are filled with a +* pattern and rechecked to test for corruption. The mapping is then +* released. This process is repeated for a specified number of +* iterations.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c line 24
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c new file +10
-0+*/ + +#include <stdio.h> +#include <sys/mount.h> +#include <unistd.h> +#include <unistd.h> + +#include "hugetlb.h" + +#define ITERATIONS 10
I don't think we need too many iterations, it will cost too much time and easily timed out on a slower machine, so at most cycling up two times should be enough.
Quoted 56 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c new file +14
-0+#define NR_HUGEPAGES 2 +#define MNTPOINT "hugetlbfs/" + +static unsigned long hpage_size; +static int fd =-1 ; + +static void test_per_iteration (size_t size,int iter) +{ +char *m; +size_t i, j; +char pattern ='A' ; + + fd =tst_creat_unlinked (MNTPOINT ,0 ); + m = SAFE_MMAP(NULL, size, (PROT_READ|PROT_WRITE), MAP_SHARED, fd,0);
testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c new file +5
-0+ +for (i =0 ; i <NR_HUGEPAGES ; i++) { +for (j =0 ; j < hpage_size; j++) { +if (*(m+(i*hpage_size)+j) !=0 ) { + tst_res(TFAIL, "Iter %d: Verifying themmap area failed. "
testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c new file +16
-0+"Got %c, expected 0" , iter, + *(m+(i*hpage_size)+j)); + goto cleanup; + } + } + } +for (i =0 ; i <NR_HUGEPAGES ; i++) { + pattern =65 +(i%26 ); +memset (m+(i*hpage_size), pattern, hpage_size); + } + +for (i =0 ; i <NR_HUGEPAGES ; i++) { + pattern =65 +(i%26 ); +for (j =0 ; j < hpage_size; j++) { +if (*(m+(i*hpage_size)+j) != pattern) { + tst_res(TFAIL, "Verifying the mmap areafailed. "
testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c new file +17
-0+"got: %c, expected: %c" , + *(m+(i*hpage_size)+j), pattern); + goto cleanup; + } + } + } + +cleanup: +SAFE_MUNMAP (m, size); +SAFE_CLOSE (fd); +} + +static void run_test (void ) +{ +size_t size; +int i; +
testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c line 86
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c new file +10
-0+ size =NR_HUGEPAGES * hpage_size; +for (i =0 ; i <ITERATIONS ; i++) +test_per_iteration (size, i); + +tst_res (TPASS ,"Successfully verified the mmap area." ); +} + +static void setup (void ) +{ + hpage_size =SAFE_READ_MEMINFO (MEMINFO_HPAGE_SIZE )*1024 ;
hpage_size = tst_get_hugepage_size();
+}
Quoted 21 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c new file +17
-1+ +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .needs_root =1 , + .mntpoint =MNTPOINT , + .needs_hugetlbfs =1 , + .needs_tmpdir =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {NR_HUGEPAGES ,TST_NEEDS }, +}; --2.31.1
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 03/13] Hugetlb: Migrating libhugetlbfs mmap-gettest
Hi Li,
Thanks for reviewing it.
Will take care of suggestions in next revision.
Thanks
Tarun
Quoted 184 lines · Li Wang
Quoted 10 lines · Tarun Sahu
Migrating the
libhugetlbfs/testcases/mmap-gettest.ctestTest Description: This baseline test validates that a mapping of a certain size can be created, correctly. Once created, all the pages are filled with a pattern and rechecked to test for corruption. The mapping is then released. This process is repeated for a specified number of iterations.
Signed-off-by Tarun Sahu <[email protected]>Reviewed-by Li Wang <[email protected]>Quoted 54 lines
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap22.c | 104 ++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.cruntest/hugetlb +1
-0@@ -23,6 +23,7 @@ hugemmap18 hugemmap18 hugemmap19 hugemmap19 hugemmap20 hugemmap20 hugemmap21 hugemmap21 +hugemmap22 hugemmap22 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -22,6 +22,7 @@ /hugetlb/hugemmap/hugemmap19 /hugetlb/hugemmap/hugemmap20 /hugetlb/hugemmap/hugemmap21 +/hugetlb/hugemmap/hugemmap22 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c new file +14
-0@@ -0,0 +1,104 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2005-2006 IBM Corporation. +* Author: David Gibson & Adam Litke +*/ + +/*\ +* [Description] +* +* This baseline test validates that a mapping of a certain size can be +* created, correctly. Once created, all the pages are filled with a +* pattern and rechecked to test for corruption. The mapping is then +* released. This process is repeated for a specified number of +* iterations. testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c line 24
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c new file +10
-0+*/ + +#include <stdio.h> +#include <sys/mount.h> +#include <unistd.h> +#include <unistd.h> + +#include "hugetlb.h" + +#define ITERATIONS 10I don't think we need too many iterations, it will cost too much time and easily timed out on a slower machine, so at most cycling up two times should be enough.
Quoted 56 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c new file +14
-0+#define NR_HUGEPAGES 2 +#define MNTPOINT "hugetlbfs/" + +static unsigned long hpage_size; +static int fd =-1 ; + +static void test_per_iteration (size_t size,int iter) +{ +char *m; +size_t i, j; +char pattern ='A' ; + + fd =tst_creat_unlinked (MNTPOINT ,0 ); + m = SAFE_MMAP(NULL, size, (PROT_READ|PROT_WRITE), MAP_SHARED, fd,0);
testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c new file +5
-0+ +for (i =0 ; i <NR_HUGEPAGES ; i++) { +for (j =0 ; j < hpage_size; j++) { +if (*(m+(i*hpage_size)+j) !=0 ) { + tst_res(TFAIL, "Iter %d: Verifying themmap area failed. "
testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c new file +16
-0+"Got %c, expected 0" , iter, + *(m+(i*hpage_size)+j)); + goto cleanup; + } + } + } +for (i =0 ; i <NR_HUGEPAGES ; i++) { + pattern =65 +(i%26 ); +memset (m+(i*hpage_size), pattern, hpage_size); + } + +for (i =0 ; i <NR_HUGEPAGES ; i++) { + pattern =65 +(i%26 ); +for (j =0 ; j < hpage_size; j++) { +if (*(m+(i*hpage_size)+j) != pattern) { + tst_res(TFAIL, "Verifying the mmap areafailed. "
testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c new file +17
-0+"got: %c, expected: %c" , + *(m+(i*hpage_size)+j), pattern); + goto cleanup; + } + } + } + +cleanup: +SAFE_MUNMAP (m, size); +SAFE_CLOSE (fd); +} + +static void run_test (void ) +{ +size_t size; +int i; +testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c line 86
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c new file +10
-0+ size =NR_HUGEPAGES * hpage_size; +for (i =0 ; i <ITERATIONS ; i++) +test_per_iteration (size, i); + +tst_res (TPASS ,"Successfully verified the mmap area." ); +} + +static void setup (void ) +{ + hpage_size =SAFE_READ_MEMINFO (MEMINFO_HPAGE_SIZE )*1024 ;
hpage_size=tst_get_hugepage_size();+}
Quoted 21 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c new file +17
-1+ +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .needs_root =1 , + .mntpoint =MNTPOINT , + .needs_hugetlbfs =1 , + .needs_tmpdir =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {NR_HUGEPAGES ,TST_NEEDS }, +}; --2.31.1
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 4/13 Hugetlb: Migrating libhugetlbfs mprotect
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/mprotect.c test
Test Description: This test uses mprotect to change protection of hugepage mapping and perform read/write operation. It checks if the operation results in expected behaviour as per the protection.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap23.c | 244 ++++++++++++++++++ 3 files changed, 246 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c
runtest/hugetlb +1 -0
@@ -24,6 +24,7 @@ hugemmap19 hugemmap19 hugemmap20 hugemmap20 hugemmap21 hugemmap21 hugemmap22 hugemmap22 +hugemmap23 hugemmap23 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -23,6 +23,7 @@ /hugetlb/hugemmap/hugemmap20 /hugetlb/hugemmap/hugemmap21 /hugetlb/hugemmap/hugemmap22 +/hugetlb/hugemmap/hugemmap23 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +244 -0
244 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 04/13] Hugetlb: Migrating libhugetlbfs mprotect
Hi Tarun,
This test itself is no problem but looks a bit messy in code organization. At least we need to do some refactored work to improve the readability and reduce the (long-term) maintenance workload.
Tarun Sahu <[email protected]> wrote:
Migrating the libhugetlbfs/testcases/mprotect.c test
Quoted 70 lines
Test Description: This test uses mprotect to change protection of hugepage mapping and perform read/write operation. It checks if the operation results in expected behaviour as per the protection.
Signed-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap23.c | 244 ++++++++++++++++++ 3 files changed, 246 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.cruntest/hugetlb +1
-0@@ -24,6 +24,7 @@ hugemmap19 hugemmap19 hugemmap20 hugemmap20 hugemmap21 hugemmap21 hugemmap22 hugemmap22 +hugemmap23 hugemmap23 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -23,6 +23,7 @@ /hugetlb/hugemmap/hugemmap20 /hugetlb/hugemmap/hugemmap21 /hugetlb/hugemmap/hugemmap22 +/hugetlb/hugemmap/hugemmap23 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +24
-0@@ -0,0 +1,244 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2005-2006 IBM Corporation. +* Author: David Gibson & Adam Litke +*/ + +/*\ +* [Description] +* +* This test uses mprotect to change protection of hugepage mapping and +* perform read/write operation. It checks if the operation results in +* expected behaviour as per the protection. +*/ + +#include <stdio.h> +#include <sys/mount.h> +#include <unistd.h> +#include <sys/mman.h> +#include <setjmp.h> +#include <signal.h> + +#include "hugetlb.h" + +#ifndef barrier
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c line 34
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +10
-0+# ifdef mb +/* Redefining the mb() */ +# define barrier () mb() +# else +# define barrier () __asm__ __volatile__ ("" : : : "memory") +# endif +#endif + +#define MNTPOINT "hugetlbfs/" +#define RANDOM_CONSTANT 0x1234ABCD
Avoid mixing tab and spaces in the macro definition.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c line 36
Quoted 3 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +2
-0+ +static int fd =-1 ;
^ one space is enough.
Quoted 170 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +9
-0+static sigjmp_buf sig_escape; +static void *sig_expected =MAP_FAILED ; +static long hpage_size; + +static void sig_handler (int signum,siginfo_t *si,void *uc) +{ + (void )uc; +if (signum ==SIGSEGV ) { + tst_res(TINFO, "SIGSEGV at %p (sig_expected=%p)",
si->si_addr,testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +61
-0+ sig_expected); +if (si->si_addr == sig_expected) +siglongjmp (sig_escape,1 ); +tst_res (TFAIL ,"SIGSEGV somewhere unexpected" ); + }else +tst_res (TFAIL ,"Unexpected signal %s" ,strsignal (signum)); +} + +static int test_read (void *p) +{ +volatile unsigned long *pl = p; +unsigned long x; + +if (sigsetjmp (sig_escape,1 )) { +/* We got a SEGV */ + sig_expected =MAP_FAILED ; +return -1 ; + } + + sig_expected = p; +barrier (); + x = *pl; +tst_res (TINFO ,"Read back %lu" , x); +barrier (); + sig_expected =MAP_FAILED ; +return 0 ; +} + +static int test_write (void *p,unsigned long val) +{ +volatile unsigned long *pl = p; +unsigned long x; + +if (sigsetjmp (sig_escape,1 )) { +/* We got a SEGV */ + sig_expected =MAP_FAILED ; +return -1 ; + } + + sig_expected = p; +barrier (); + *pl = val; + x = *pl; +barrier (); + sig_expected =MAP_FAILED ; + +return (x != val); +} + +static int test_prot (void *p,int prot,char *prot_str) +{ +int r, w; + + r =test_read (p); +tst_res (TINFO ,"On Read: %d" , r); + w =test_write (p,RANDOM_CONSTANT ); +tst_res (TINFO ,"On Write: %d" , w); + +if (prot &PROT_READ ) { +if (r !=0 ) { + tst_res(TFAIL, "read failed on mmap(prot %s)",
prot_str);testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +6
-0+return -1 ; + } + + }else { +if (r !=-1 ) { + tst_res(TFAIL, "read succeeded on mmap(prot %s)",
prot_str);testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +8
-0+return -1 ; + } + } + +if (prot &PROT_WRITE ) { +switch (w) { +case -1 : + tst_res(TFAIL, "write failed on mmap(prot %s)",
prot_str);testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +5
-0+return -1 ; +case 0 : +break ; +case 1 : + tst_res(TFAIL, "write mismatch on mmap(prot %s)",
prot_str);testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +11
-0+return -1 ; +default : +tst_res (TWARN ,"Bug in test" ); +return -1 ; + } + }else { +switch (w) { +case -1 : +break ; +case 0 : + tst_res(TFAIL, "write succeeded on mmap(prot %s)",
prot_str);testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +3
-0+return -1 ; +case 1 : + tst_res(TFAIL, "write mismatch on mmap(prot %s)",
prot_str);testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +27
-0+return -1 ; +default : +tst_res (TWARN ,"Bug in test" ); +break ; + } + } +return 0 ; +} + +static int test_mprotect (int fd,char *testname, +unsigned long len1,int prot1,char *prot1_str, +unsigned long len2,int prot2,char *prot2_str) +{ +void *p; +int ret; + +tst_res (TINFO ,"Testing %s" , testname); +tst_res (TINFO ,"Mapping with prot %s" , prot1_str); + p =SAFE_MMAP (NULL , len1, prot1,MAP_SHARED , fd,0 ); + + ret =test_prot (p, prot1, prot1_str); +if (ret) + goto cleanup; +tst_res (TINFO ,"mprotect()ing to prot %s" , prot2_str); + ret =mprotect (p, len2, prot2); +if (ret !=0 ) { + tst_res(TFAIL|TERRNO, "%s: mprotect(prot %s)", testname,
prot2_str);testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +27
-0+ goto cleanup; + } + + ret =test_prot (p, prot2, prot2_str); +if (ret) + goto cleanup; +if (len2 < len1) + ret =test_prot (p + len2, prot1, prot1_str); + +cleanup: +SAFE_MUNMAP (p, len1); +return ret; +} + +static void run_test (void ) +{ +void *p; + +struct sigaction sa = { + .sa_sigaction = sig_handler, + .sa_flags =SA_SIGINFO , + }; + +SAFE_SIGACTION (SIGSEGV , &sa,NULL ); + + fd =tst_creat_unlinked (MNTPOINT ,0 ); + p = SAFE_MMAP(NULL, 2*hpage_size, PROT_READ|PROT_WRITE,
MAP_SHARED, fd, 0);
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c line 195
Quoted 2 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +2
-0+memset (p,0 , hpage_size); +SAFE_MUNMAP (p, hpage_size);
I guess moving those preparation work into setup() is better.
Quoted 26 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +3
-0+ + if (test_mprotect(fd, "R->RW", hpage_size, PROT_READ, "PROT_READ", + hpage_size, PROT_READ|PROT_WRITE,"PROT_READ|PROT_WRITE"))
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +3
-0+ goto cleanup; + if (test_mprotect(fd, "RW->R", hpage_size, PROT_READ|PROT_WRITE, + "PROT_READ|PROT_WRITE", hpage_size, PROT_READ,"
PROT_READ"))testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +3
-0+ goto cleanup; + + if (test_mprotect(fd, "R->RW 1/2", 2*hpage_size, PROT_READ,"
PROT_READ",
+hpage_size, PROT_READ|PROT_WRITE,
"PROT_READ|PROT_WRITE"))testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +2
-0+ goto cleanup; + if (test_mprotect(fd, "RW->R 1/2", 2*hpage_size,PROT_READ|PROT_WRITE,
+ "PROT_READ|PROT_WRITE",hpage_size,PROT_READ,
"PROT_READ"))testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +3
-0+ goto cleanup; + + if (test_mprotect(fd, "NONE->R", hpage_size, PROT_NONE,"
PROT_NONE",testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +3
-0+ hpage_size, PROT_READ, "PROT_READ")) + goto cleanup; + if (test_mprotect(fd, "NONE->RW", hpage_size, PROT_NONE,
Quoted 5 lines
"
PROT_NONE",
+hpage_size, PROT_READ|PROT_WRITE,
"PROT_READ|PROT_WRITE"))
+ goto cleanup;
Can we reorg those test options just into one structure for reducing the duplicated code? Something maybe like:
static struct mprotect_param {
char *tname;
int pg_num;
int prot1;
char *prot1_str;
int prot2;
char *prot2_str;
} mprotect_params[] = {
{"R->RW", 1,
PROT_READ, "PROT_READ",
PROT_READ|PROT_WRITE, "PROT_READ|PROT_WRITE"},
{"RW->R", 1,
PROT_READ|PROT_WRITE, "PROT_READ|PROT_WRITE",
PROT_READ, "PROT_READ"},
{"R->RW 1/2", 2,
PROT_READ, "PROT_READ",
PROT_READ|PROT_WRITE, "PROT_READ|PROT_WRITE"},
{"RW->R 1/2", 2,
PROT_READ|PROT_WRITE, "PROT_READ|PROT_WRITE",
PROT_READ, "PROT_READ"},
{"NONE->R", 1,
PROT_NONE, "PROT_NONE",
PROT_READ, "PROT_READ"},
{"NONE->RW", 1,
PROT_NONE, "PROT_NONE",
PROT_READ|PROT_WRITE, "PROT_READ|PROT_WRITE"},
};static void run_test(unsigned int i)
{
struct mprotect_param *mpt = &mprotect_params[i];
if (test_mprotect(fd, mpt->tname,
hpage_size * mpt->pg_num, mpt->prot1,
mpt->prot1_str,
hpage_size, mpt->prot2, mpt->prot2_str))
return;
tst_res(TPASS, "Successfully tested mprotect with hugetlb area\n");
}static void setup(void)
{
struct sigaction sa = {
.sa_sigaction = sig_handler,
.sa_flags = SA_SIGINFO,
};
SAFE_SIGACTION(SIGSEGV, &sa, NULL);
hpage_size = tst_get_hugepage_size();
fd = tst_creat_unlinked(MNTPOINT, 0);
p = SAFE_MMAP(NULL, 2*hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,fd, 0);
memset(p, 0, hpage_size);
SAFE_MUNMAP(p, hpage_size);
}static void cleanup(void)
{
SAFE_MUNMAP(p+hpage_size, hpage_size);
if (fd >= 0)
SAFE_CLOSE(fd);
}static struct tst_test test = {
.tcnt = ARRAY_SIZE(mprotect_params),
.needs_root = 1,
.mntpoint = MNTPOINT,
.needs_hugetlbfs = 1,
.needs_tmpdir = 1,
.setup = setup,
.cleanup = cleanup,
.test = run_test,
.hugepages = {2, TST_NEEDS},
};
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c line 221
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +5
-0+ +tst_res (TPASS ,"Successfully tested mprotect with hugetlb area" ); +cleanup: +SAFE_MUNMAP (p+hpage_size, hpage_size); +SAFE_CLOSE (fd);
we can move this into cleanup() function as well.
Quoted 27 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +23
-1+} + +static void setup (void ) +{ + hpage_size =SAFE_READ_MEMINFO (MEMINFO_HPAGE_SIZE )*1024 ; +} + +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .needs_root =1 , + .mntpoint =MNTPOINT , + .needs_hugetlbfs =1 , + .needs_tmpdir =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {2 ,TST_NEEDS }, +}; --2.31.1
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 04/13] Hugetlb: Migrating libhugetlbfs mprotect
Hi Li,
Thanks for reviewing this patch.
I will rework on this.
Quoted 450 lines · Li Wang
Hi Tarun,
This test itself is no problem but looks a bit messy in code organization. At least we need to do some refactored work to improve the readability and reduce the (long-term) maintenance workload.
Tarun Sahu <[email protected]> wrote:
Migrating the
libhugetlbfs/testcases/mprotect.ctestQuoted 70 lines
Test Description: This test uses mprotect to change protection of hugepage mapping and perform read/write operation. It checks if the operation results in expected behaviour as per the protection.
Signed-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap23.c | 244 ++++++++++++++++++ 3 files changed, 246 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.cruntest/hugetlb +1
-0@@ -24,6 +24,7 @@ hugemmap19 hugemmap19 hugemmap20 hugemmap20 hugemmap21 hugemmap21 hugemmap22 hugemmap22 +hugemmap23 hugemmap23 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -23,6 +23,7 @@ /hugetlb/hugemmap/hugemmap20 /hugetlb/hugemmap/hugemmap21 /hugetlb/hugemmap/hugemmap22 +/hugetlb/hugemmap/hugemmap23 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +24
-0@@ -0,0 +1,244 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2005-2006 IBM Corporation. +* Author: David Gibson & Adam Litke +*/ + +/*\ +* [Description] +* +* This test uses mprotect to change protection of hugepage mapping and +* perform read/write operation. It checks if the operation results in +* expected behaviour as per the protection. +*/ + +#include <stdio.h> +#include <sys/mount.h> +#include <unistd.h> +#include <sys/mman.h> +#include <setjmp.h> +#include <signal.h> + +#include "hugetlb.h" + +#ifndef barriertestcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c line 34
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +10
-0+# ifdef mb +/* Redefining the mb() */ +# define barrier () mb() +# else +# define barrier () __asm__ __volatile__ ("" : : : "memory") +# endif +#endif + +#define MNTPOINT "hugetlbfs/" +#define RANDOM_CONSTANT 0x1234ABCDAvoid mixing tab and spaces in the macro definition.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c line 36
Quoted 3 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +2
-0+ +static int fd =-1 ;^ one space is enough.
Quoted 170 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +9
-0+static sigjmp_buf sig_escape; +static void *sig_expected =MAP_FAILED ; +static long hpage_size; + +static void sig_handler (int signum,siginfo_t *si,void *uc) +{ + (void )uc; +if (signum ==SIGSEGV ) { + tst_res(TINFO, "SIGSEGV at %p (sig_expected=%p)",
si->si_addr,testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +61
-0+ sig_expected); +if (si->si_addr == sig_expected) +siglongjmp (sig_escape,1 ); +tst_res (TFAIL ,"SIGSEGV somewhere unexpected" ); + }else +tst_res (TFAIL ,"Unexpected signal %s" ,strsignal (signum)); +} + +static int test_read (void *p) +{ +volatile unsigned long *pl = p; +unsigned long x; + +if (sigsetjmp (sig_escape,1 )) { +/* We got a SEGV */ + sig_expected =MAP_FAILED ; +return -1 ; + } + + sig_expected = p; +barrier (); + x = *pl; +tst_res (TINFO ,"Read back %lu" , x); +barrier (); + sig_expected =MAP_FAILED ; +return 0 ; +} + +static int test_write (void *p,unsigned long val) +{ +volatile unsigned long *pl = p; +unsigned long x; + +if (sigsetjmp (sig_escape,1 )) { +/* We got a SEGV */ + sig_expected =MAP_FAILED ; +return -1 ; + } + + sig_expected = p; +barrier (); + *pl = val; + x = *pl; +barrier (); + sig_expected =MAP_FAILED ; + +return (x != val); +} + +static int test_prot (void *p,int prot,char *prot_str) +{ +int r, w; + + r =test_read (p); +tst_res (TINFO ,"On Read: %d" , r); + w =test_write (p,RANDOM_CONSTANT ); +tst_res (TINFO ,"On Write: %d" , w); + +if (prot &PROT_READ ) { +if (r !=0 ) { + tst_res(TFAIL, "read failed on mmap(prot %s)",
prot_str);testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +6
-0+return -1 ; + } + + }else { +if (r !=-1 ) { + tst_res(TFAIL, "read succeeded on mmap(prot %s)",
prot_str);testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +8
-0+return -1 ; + } + } + +if (prot &PROT_WRITE ) { +switch (w) { +case -1 : + tst_res(TFAIL, "write failed on mmap(prot %s)",
prot_str);testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +5
-0+return -1 ; +case 0 : +break ; +case 1 : + tst_res(TFAIL, "write mismatch on mmap(prot %s)",
prot_str);testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +11
-0+return -1 ; +default : +tst_res (TWARN ,"Bug in test" ); +return -1 ; + } + }else { +switch (w) { +case -1 : +break ; +case 0 : + tst_res(TFAIL, "write succeeded on mmap(prot %s)",
prot_str);testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +3
-0+return -1 ; +case 1 : + tst_res(TFAIL, "write mismatch on mmap(prot %s)",
prot_str);testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +27
-0+return -1 ; +default : +tst_res (TWARN ,"Bug in test" ); +break ; + } + } +return 0 ; +} + +static int test_mprotect (int fd,char *testname, +unsigned long len1,int prot1,char *prot1_str, +unsigned long len2,int prot2,char *prot2_str) +{ +void *p; +int ret; + +tst_res (TINFO ,"Testing %s" , testname); +tst_res (TINFO ,"Mapping with prot %s" , prot1_str); + p =SAFE_MMAP (NULL , len1, prot1,MAP_SHARED , fd,0 ); + + ret =test_prot (p, prot1, prot1_str); +if (ret) + goto cleanup; +tst_res (TINFO ,"mprotect()ing to prot %s" , prot2_str); + ret =mprotect (p, len2, prot2); +if (ret !=0 ) { + tst_res(TFAIL|TERRNO, "%s: mprotect(prot %s)", testname,
prot2_str);testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +27
-0+ goto cleanup; + } + + ret =test_prot (p, prot2, prot2_str); +if (ret) + goto cleanup; +if (len2 < len1) + ret =test_prot (p + len2, prot1, prot1_str); + +cleanup: +SAFE_MUNMAP (p, len1); +return ret; +} + +static void run_test (void ) +{ +void *p; + +struct sigaction sa = { + .sa_sigaction = sig_handler, + .sa_flags =SA_SIGINFO , + }; + +SAFE_SIGACTION (SIGSEGV , &sa,NULL ); + + fd =tst_creat_unlinked (MNTPOINT ,0 ); + p = SAFE_MMAP(NULL, 2*hpage_size, PROT_READ|PROT_WRITE,
MAP_SHARED, fd, 0);testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c line 195
Quoted 2 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +2
-0+memset (p,0 , hpage_size); +SAFE_MUNMAP (p, hpage_size);I guess moving those preparation work into
setup()is better.Quoted 26 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +3
-0+ + if (test_mprotect(fd, "R->RW", hpage_size, PROT_READ, "PROT_READ", + hpage_size, PROT_READ|PROT_WRITE,"PROT_READ|PROT_WRITE"))
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +3
-0+ goto cleanup; + if (test_mprotect(fd, "RW->R", hpage_size, PROT_READ|PROT_WRITE, + "PROT_READ|PROT_WRITE", hpage_size, PROT_READ,"
PROT_READ"))testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +3
-0+ goto cleanup; + + if (test_mprotect(fd, "R->RW 1/2", 2*hpage_size, PROT_READ,"
PROT_READ",
+hpage_size, PROT_READ|PROT_WRITE,
"PROT_READ|PROT_WRITE"))testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +2
-0+ goto cleanup; + if (test_mprotect(fd, "RW->R 1/2", 2*hpage_size,PROT_READ|PROT_WRITE,
+ "PROT_READ|PROT_WRITE",hpage_size,PROT_READ,
"PROT_READ"))testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +3
-0+ goto cleanup; + + if (test_mprotect(fd, "NONE->R", hpage_size, PROT_NONE,"
PROT_NONE",testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +3
-0+ hpage_size, PROT_READ, "PROT_READ")) + goto cleanup; + if (test_mprotect(fd, "NONE->RW", hpage_size, PROT_NONE,Quoted 5 lines
"
PROT_NONE",
+hpage_size, PROT_READ|PROT_WRITE,
"PROT_READ|PROT_WRITE"))
+ goto cleanup;Can we reorg those test options just into one structure for reducing the duplicated code? Something maybe like:
static struct mprotect_param { char *tname; int pg_num; int prot1; char *prot1_str; int prot2; char *prot2_str; } mprotect_params[] = { {"R->RW", 1, PROT_READ, "PROT_READ", PROT_READ|PROT_WRITE, "PROT_READ|PROT_WRITE"}, {"RW->R", 1, PROT_READ|PROT_WRITE, "PROT_READ|PROT_WRITE", PROT_READ, "PROT_READ"}, {"R->RW 1/2", 2, PROT_READ, "PROT_READ", PROT_READ|PROT_WRITE, "PROT_READ|PROT_WRITE"}, {"RW->R 1/2", 2, PROT_READ|PROT_WRITE, "PROT_READ|PROT_WRITE", PROT_READ, "PROT_READ"}, {"NONE->R", 1, PROT_NONE, "PROT_NONE", PROT_READ, "PROT_READ"}, {"NONE->RW", 1, PROT_NONE, "PROT_NONE", PROT_READ|PROT_WRITE, "PROT_READ|PROT_WRITE"}, };static void
run_test(unsigned int i){ struct mprotect_param *mpt = &mprotect_params[i]; if (test_mprotect(fd, mpt->tname, hpage_size * mpt->pg_num, mpt->prot1, mpt->prot1_str, hpage_size, mpt->prot2, mpt->prot2_str)) return; tst_res(TPASS, "Successfully tested mprotect with hugetlb area\n"); }static void setup(void)
{ struct sigaction sa = { .sa_sigaction = sig_handler, .sa_flags = SA_SIGINFO, }; SAFE_SIGACTION(SIGSEGV, &sa, NULL); hpage_size = tst_get_hugepage_size(); fd = tst_creat_unlinked(MNTPOINT, 0); p = SAFE_MMAP(NULL, 2*hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,fd, 0);
memset(p, 0, hpage_size); SAFE_MUNMAP(p, hpage_size); }static void cleanup(void)
{ SAFE_MUNMAP(p+hpage_size, hpage_size); if (fd >= 0) SAFE_CLOSE(fd); }static struct
tst_testtest = {
.tcnt =ARRAY_SIZE(mprotect_params),
.needs_root = 1,
.mntpoint = MNTPOINT,
.needs_hugetlbfs = 1,
.needs_tmpdir = 1,
.setup = setup,
.cleanup = cleanup,
.test =run_test,
.hugepages = {2,TST_NEEDS},
};testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c line 221
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +5
-0+ +tst_res (TPASS ,"Successfully tested mprotect with hugetlb area" ); +cleanup: +SAFE_MUNMAP (p+hpage_size, hpage_size); +SAFE_CLOSE (fd);we can move this into
cleanup()function as well.Quoted 27 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c new file +23
-1+} + +static void setup (void ) +{ + hpage_size =SAFE_READ_MEMINFO (MEMINFO_HPAGE_SIZE )*1024 ; +} + +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .needs_root =1 , + .mntpoint =MNTPOINT , + .needs_hugetlbfs =1 , + .needs_tmpdir =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {2 ,TST_NEEDS }, +}; --2.31.1
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 5/13 Hugetlb: Migrating libhugetlbfs mremap-fixed-huge-near-normal
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/mremap-fixed-huge-near-normal.c test
Test Description: The kernel has bug for mremap() on some architecture. mremap() can cause crashes on architectures with holes in the address space (like ia64) and on powerpc with it's distinct page size "slices".
This test get the normal mapping address and mremap() hugepage mapping near to this normal mapping.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap25.c | 146 ++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap25.c
runtest/hugetlb +1 -0
@@ -25,6 +25,7 @@ hugemmap20 hugemmap20 hugemmap21 hugemmap21 hugemmap22 hugemmap22 hugemmap23 hugemmap23 +hugemmap25 hugemmap25 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -24,6 +24,7 @@ /hugetlb/hugemmap/hugemmap21 /hugetlb/hugemmap/hugemmap22 /hugetlb/hugemmap/hugemmap23 +/hugetlb/hugemmap/hugemmap25 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap25.c new file +146 -0
146 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 6/13 Hugetlb: Migrating libhugetlbfs mremap-fixed-normal-near-huge
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/mremap-fixed-normal-near-huge.c test
Test Description: The kernel has bug for mremap() on some architecture. mremap() can cause crashes on architectures with holes in the address space (like ia64) and on powerpc with it's distinct page size "slices".
This test get the huge mapping address and mremap() normal mapping near to this huge mapping.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap26.c | 131 ++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c
runtest/hugetlb +1 -0
@@ -26,6 +26,7 @@ hugemmap21 hugemmap21 hugemmap22 hugemmap22 hugemmap23 hugemmap23 hugemmap25 hugemmap25 +hugemmap26 hugemmap26 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -25,6 +25,7 @@ /hugetlb/hugemmap/hugemmap22 /hugetlb/hugemmap/hugemmap23 /hugetlb/hugemmap/hugemmap25 +/hugetlb/hugemmap/hugemmap26 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +131 -0
131 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 06/13] Hugetlb: Migrating libhugetlbfs mremap-fixed-normal-near-huge
Quoted 119 lines · Tarun Sahu
Migrating the
libhugetlbfs/testcases/mremap-fixed-normal-near-huge.ctestTest Description: The kernel has bug for
mremap()on some architecture.mremap()can cause crashes on architectures with holes in the address space (like ia64) and on powerpc with it's distinct page size "slices".This test get the huge mapping address and
mremap()normal mapping near to this huge mapping.Signed-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap26.c | 131 ++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.cruntest/hugetlb +1
-0@@ -26,6 +26,7 @@ hugemmap21 hugemmap21 hugemmap22 hugemmap22 hugemmap23 hugemmap23 hugemmap25 hugemmap25 +hugemmap26 hugemmap26 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -25,6 +25,7 @@ /hugetlb/hugemmap/hugemmap22 /hugetlb/hugemmap/hugemmap23 /hugetlb/hugemmap/hugemmap25 +/hugetlb/hugemmap/hugemmap26 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +46
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2009 IBM Corporation. +* Author: David Gibson +*/ + +/*\ +* [Description] +* +* Test Description: The kernel has bug for mremap() on some architecture. +* mremap() can cause crashes on architectures with holes in the address +* space (like ia64) and on powerpc with it's distinct page size "slices". +* +* This test get the huge mapping address and mremap() normal mapping +* near to this huge mapping. +*/ + +#define _GNU_SOURCE +#include <stdio.h> +#include <sys/mount.h> +#include <limits.h> +#include <sys/param.h> +#include <sys/types.h> + +#include "hugetlb.h" + +#define RANDOM_CONSTANT 0x1234ABCD +#define MNTPOINT "hugetlbfs/" + +static int fd =-1 ; +static long hpage_size, page_size; + +static int do_readback (void *p,size_t size,const char *stage) +{ +unsigned int *q = p; +size_t i; + +tst_res (TINFO ,"%s(%p, 0x%lx, \"%s\")" , __func__, p, + (unsigned long )size, stage); + +for (i =0 ; i < (size /sizeof (*q)); i++) + q[i] =RANDOM_CONSTANT ^ i; + +for (i =0 ; i < (size /sizeof (*q)); i++) { +if (q[i] != (RANDOM_CONSTANT ^ i)) { + tst_res(TFAIL, "Stage \"%s\": Mismatch at offset0x%lx: 0x%x "
+ "instead of 0x%lx", stage, i,
q[i],RANDOM_CONSTANT^ i);testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +20
-0+return -1 ; + } + } +return 0 ; +} + +static int do_remap (void *target) +{ +void *a, *b; +int ret; + + a =SAFE_MMAP (NULL , page_size,PROT_READ |PROT_WRITE , +MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ); + + ret =do_readback (a, page_size,"base normal" ); +if (ret) + goto cleanup; + b =mremap (a, page_size, page_size,MREMAP_MAYMOVE |MREMAP_FIXED , + target); +
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c line 77
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +10
-0+if (b !=MAP_FAILED ) { +do_readback (b, page_size,"remapped" ); + a = b; + }else +tst_res (TINFO |TERRNO ,"mremap(MAYMOVE|FIXED) disallowed" ); + +cleanup: +SAFE_MUNMAP (a, page_size); +return ret; +}
Those two functions do_readback() and do_remap() are copy&past from hugemmap2[4|5].c, what about extracting them into a common header file(tst_hugetlb.h or mem.h) for easy reusing?
And I also noticed other tests (hugemmap27) using the same macro mem barrier(), it'd be great to define it in a header file.
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 06/13] Hugetlb: Migrating libhugetlbfs mremap-fixed-normal-near-huge
Hi Li,
Thanks for reviewing the patch.
I will update it in next revision.
--skip
Quoted 45 lines
Quoted 45 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +14
-0+static int do_readback (void *p,size_t size,const char *stage) +{ +unsigned int *q = p; +size_t i; + +tst_res (TINFO ,"%s(%p, 0x%lx, \"%s\")" , __func__, p, + (unsigned long )size, stage); + +for (i =0 ; i < (size /sizeof (*q)); i++) + q[i] =RANDOM_CONSTANT ^ i; + +for (i =0 ; i < (size /sizeof (*q)); i++) { +if (q[i] != (RANDOM_CONSTANT ^ i)) { + tst_res(TFAIL, "Stage \"%s\": Mismatch at offset0x%lx: 0x%x "
+ "instead of 0x%lx", stage, i,
q[i],RANDOM_CONSTANT^ i);testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +28
-0+return -1 ; + } + } +return 0 ; +} + +static int do_remap (void *target) +{ +void *a, *b; +int ret; + + a =SAFE_MMAP (NULL , page_size,PROT_READ |PROT_WRITE , +MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ); + + ret =do_readback (a, page_size,"base normal" ); +if (ret) + goto cleanup; + b =mremap (a, page_size, page_size,MREMAP_MAYMOVE |MREMAP_FIXED , + target); + +if (b !=MAP_FAILED ) { +do_readback (b, page_size,"remapped" ); + a = b; + }else +tst_res (TINFO |TERRNO ,"mremap(MAYMOVE|FIXED) disallowed" ); + +cleanup: +SAFE_MUNMAP (a, page_size);
Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ return ret; +}Those two functions
do_readback()anddo_remap()are copy&past from hugemmap2[4|5].c, what about extracting them into a common headerfile(tst_hugetlb.h or mem.h)for easy reusing?
ok, I think, hugetlb.h/.c will be better place to keep them.
Quoted 3 lines
And I also noticed other tests (hugemmap27) using the same macro mem
barrier(), it'd be great to define it in a header file.
ok.
Quoted 7 lines
Signature · 6 lines
-- Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 06/13] Hugetlb: Migrating libhugetlbfs mremap-fixed-normal-near-huge
Hi,
Quoted 59 lines · Tarun Sahu
Hi Li,
Thanks for reviewing the patch.
I will update it in next revision.--skip
Quoted 45 lines
Quoted 45 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +14
-0+static int do_readback (void *p,size_t size,const char *stage) +{ +unsigned int *q = p; +size_t i; + +tst_res (TINFO ,"%s(%p, 0x%lx, \"%s\")" , __func__, p, + (unsigned long )size, stage); + +for (i =0 ; i < (size /sizeof (*q)); i++) + q[i] =RANDOM_CONSTANT ^ i; + +for (i =0 ; i < (size /sizeof (*q)); i++) { +if (q[i] != (RANDOM_CONSTANT ^ i)) { + tst_res(TFAIL, "Stage \"%s\": Mismatch at offset0x%lx: 0x%x "
+ "instead of 0x%lx", stage, i,
q[i],RANDOM_CONSTANT^ i);testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +28
-0+return -1 ; + } + } +return 0 ; +} + +static int do_remap (void *target) +{ +void *a, *b; +int ret; + + a =SAFE_MMAP (NULL , page_size,PROT_READ |PROT_WRITE , +MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ); + + ret =do_readback (a, page_size,"base normal" ); +if (ret) + goto cleanup; + b =mremap (a, page_size, page_size,MREMAP_MAYMOVE |MREMAP_FIXED , + target); + +if (b !=MAP_FAILED ) { +do_readback (b, page_size,"remapped" ); + a = b; + }else +tst_res (TINFO |TERRNO ,"mremap(MAYMOVE|FIXED) disallowed" ); + +cleanup: +SAFE_MUNMAP (a, page_size);Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ return ret; +}Those two functions
do_readback()anddo_remap()are copy&past from hugemmap2[4|5].c, what about extracting them into a common headerfile(tst_hugetlb.h or mem.h)for easy reusing?
Quoted 2 lines
ok, I think, hugetlb.h/.c will be better place to keep them.
These two functions are very specific to tests (specially the do_remap). Also, they use values that are defined only inside the test. Though do_readback is more general which can be put in hugetlb.h/c.
WDYT?
Quoted 11 lines
Quoted 3 lines
And I also noticed other tests (hugemmap27) using the same macro mem
barrier(), it'd be great to define it in a header file.ok.
Quoted 7 lines
Signature · 6 lines
-- Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 06/13] Hugetlb: Migrating libhugetlbfs mremap-fixed-normal-near-huge
Quoted 67 lines · Tarun Sahu
Hi,
Quoted 5 lines · Tarun Sahu
Hi Li,
Thanks for reviewing the patch.
I will update it in next revision.--skip
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +6
-0+static int do_readback (void *p,size_t size,const char *stage) +{ +unsigned int *q = p; +size_t i; + + tst_res(TINFO, "%s(%p, 0x%lx, \"%s\")", __func__, p,Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +8
-0+ (unsigned long)size, stage); + +for (i =0 ; i < (size /sizeof (*q)); i++) + q[i] =RANDOM_CONSTANT ^ i; + +for (i =0 ; i < (size /sizeof (*q)); i++) { +if (q[i] != (RANDOM_CONSTANT ^ i)) { + tst_res(TFAIL, "Stage \"%s\": Mismatch atoffset
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
0x%lx: 0x%x "
+ "instead of 0x%lx", stage, i,
q[i],RANDOM_CONSTANT^ i);testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +10
-0+return -1 ; + } + } +return 0 ; +} + +static int do_remap (void *target) +{ +void *a, *b; +int ret;Quoted 8 lines
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +8
-0+ + a =SAFE_MMAP (NULL , page_size,PROT_READ |PROT_WRITE , +MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ); + + ret =do_readback (a, page_size,"base normal" ); +if (ret) + goto cleanup; + b = mremap(a, page_size, page_size, MREMAP_MAYMOVE |
MREMAP_FIXED,Quoted 7 lines
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +7
-0+ target); + +if (b !=MAP_FAILED ) { +do_readback (b, page_size,"remapped" ); + a = b; + }else + tst_res(TINFO|TERRNO, "mremap(MAYMOVE|FIXED)disallowed");
Quoted 12 lines
Quoted 12 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c line 77
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +5
-0+ +cleanup: +SAFE_MUNMAP (a, page_size); +return ret; +}Those two functions
do_readback()anddo_remap()are copy&past from hugemmap2[4|5].c, what about extracting them into a common headerfile(tst_hugetlb.h or mem.h)for easy reusing?
Quoted 8 lines
Quoted 2 lines
ok, I think, hugetlb.h/.c will be better place to keep them.
These two functions are very specific to tests (specially the
do_remap). Also, they use values that are defined only inside the test. Thoughdo_readbackis more general which can be put in hugetlb.h/c.WDYT?
Ah yes, I didn't realize the difference.
Or can we pass the specific arguments based on the variable part? e.g.
static int do_remap(int fd, size_t page_size; int prot, void *target);
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 06/13] Hugetlb: Migrating libhugetlbfs mremap-fixed-normal-near-huge
Hi,
Quoted 75 lines · Li Wang
Quoted 73 lines · Tarun Sahu
Hi,
Quoted 5 lines · Tarun Sahu
Hi Li,
Thanks for reviewing the patch.
I will update it in next revision.--skip
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +6
-0+static int do_readback (void *p,size_t size,const char *stage) +{ +unsigned int *q = p; +size_t i; + + tst_res(TINFO, "%s(%p, 0x%lx, \"%s\")", __func__, p,Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +8
-0+ (unsigned long)size, stage); + +for (i =0 ; i < (size /sizeof (*q)); i++) + q[i] =RANDOM_CONSTANT ^ i; + +for (i =0 ; i < (size /sizeof (*q)); i++) { +if (q[i] != (RANDOM_CONSTANT ^ i)) { + tst_res(TFAIL, "Stage \"%s\": Mismatch atoffset
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
0x%lx: 0x%x "
+ "instead of 0x%lx", stage, i,
q[i],RANDOM_CONSTANT^ i);testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +10
-0+return -1 ; + } + } +return 0 ; +} + +static int do_remap (void *target) +{ +void *a, *b; +int ret;Quoted 8 lines
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +8
-0+ + a =SAFE_MMAP (NULL , page_size,PROT_READ |PROT_WRITE , +MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ); + + ret =do_readback (a, page_size,"base normal" ); +if (ret) + goto cleanup; + b = mremap(a, page_size, page_size, MREMAP_MAYMOVE |
MREMAP_FIXED,Quoted 7 lines
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +7
-0+ target); + +if (b !=MAP_FAILED ) { +do_readback (b, page_size,"remapped" ); + a = b; + }else + tst_res(TINFO|TERRNO, "mremap(MAYMOVE|FIXED)disallowed");
Quoted 12 lines
Quoted 12 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c line 77
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +5
-0+ +cleanup: +SAFE_MUNMAP (a, page_size); +return ret; +}Those two functions
do_readback()anddo_remap()are copy&past from hugemmap2[4|5].c, what about extracting them into a common headerfile(tst_hugetlb.h or mem.h)for easy reusing?Quoted 2 lines
ok, I think, hugetlb.h/.c will be better place to keep them.
These two functions are very specific to tests (specially the
do_remap). Also, they use values that are defined only inside the test. Thoughdo_readbackis more general which can be put in hugetlb.h/c.
Quoted 9 lines
Quoted 2 lines
WDYT?
Ah yes, I didn't realize the difference.
Or can we pass the specific arguments based on the variable part? e.g.static int do_remap(int fd, size_t page_size; int prot, void *target);
This can be done this way, but What concerned me is mremap function itself. it is defined in sys/mmap under _GNU_SOURCE. I am not sure whether it will be ok to use _GNU_SOURCE specific function in lib/hugetlb.c/h file.
please confirm if it is ok to define _GNU_SOURCE in hugetlb.c/h.
Quoted 7 lines
Signature · 6 lines
-- Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 06/13] Hugetlb: Migrating libhugetlbfs mremap-fixed-normal-near-huge
Quoted 87 lines · Tarun Sahu
Hi,
Quoted 27 lines · Li Wang
Quoted 25 lines · Tarun Sahu
Hi,
Quoted 5 lines · Tarun Sahu
Hi Li,
Thanks for reviewing the patch.
I will update it in next revision.--skip
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +6
-0+static int do_readback (void *p,size_t size,const char *stage) +{ +unsigned int *q = p; +size_t i; + + tst_res(TINFO, "%s(%p, 0x%lx, \"%s\")", __func__, p,Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +8
-0+ (unsigned long)size, stage); + +for (i =0 ; i < (size /sizeof (*q)); i++) + q[i] =RANDOM_CONSTANT ^ i; + +for (i =0 ; i < (size /sizeof (*q)); i++) { +if (q[i] != (RANDOM_CONSTANT ^ i)) { + tst_res(TFAIL, "Stage \"%s\": Mismatch atoffset
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
0x%lx: 0x%x "
+ "instead of 0x%lx", stage,i,
Quoted 53 lines
Quoted 40 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
q[i],
RANDOM_CONSTANT^ i);testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +10
-0+return -1 ; + } + } +return 0 ; +} + +static int do_remap (void *target) +{ +void *a, *b; +int ret;Quoted 8 lines
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +8
-0+ + a =SAFE_MMAP (NULL , page_size,PROT_READ |PROT_WRITE , +MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ); + + ret =do_readback (a, page_size,"base normal" ); +if (ret) + goto cleanup; + b = mremap(a, page_size, page_size, MREMAP_MAYMOVE |
MREMAP_FIXED,Quoted 7 lines
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +7
-0+ target); + +if (b !=MAP_FAILED ) { +do_readback (b, page_size,"remapped" ); + a = b; + }else + tst_res(TINFO|TERRNO, "mremap(MAYMOVE|FIXED)disallowed");
Quoted 12 lines
Quoted 12 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c line 77
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c new file +5
-0+ +cleanup: +SAFE_MUNMAP (a, page_size); +return ret; +}Those two functions
do_readback()anddo_remap()are copy&past from hugemmap2[4|5].c, what about extracting them into a common headerfile(tst_hugetlb.h or mem.h)for easy reusing?Quoted 8 lines
Quoted 2 lines
ok, I think, hugetlb.h/.c will be better place to keep them.
These two functions are very specific to tests (specially the
do_remap). Also, they use values that are defined only inside the test. Thoughdo_readbackis more general which can be put in hugetlb.h/c.WDYT?
Ah yes, I didn't realize the difference.
Or can we pass the specific arguments based on the variable part? e.g.
Quoted 8 lines
Quoted 1 line
static int do_remap(int fd,
size_tpage_size; int prot, void*target);
Quoted 1 line
This can be done this way, but What concerned me is mremap function itself. it is defined in sys/mmap under
_GNU_SOURCE. I am not sure whether it will be ok to use_GNU_SOURCEspecific function inlib/hugetlb.c/hfile.
Good catch.
Quoted 3 lines
please confirm if it is ok to define
_GNU_SOURCEin hugetlb.c/h.
Well, I guess we should avoid doing that because it will bring more uncertain factors to other tests that include this header file.
You could make an informed trade-off about review comments according to actual conditions.
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 7/13 Hugetlb: Migrating libhugetlbfs noresv-reserve-resv-page
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/noresv-preserve-resv-page.c test
Test Description: Test to preserve a reserved page against no-reserved mapping. If all hugepages are reserved, access to no-reserved shared mapping cause a process die, instead of stealing a hugepage which is reserved for other process.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap27.c | 136 ++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap27.c
runtest/hugetlb +1 -0
@@ -27,6 +27,7 @@ hugemmap22 hugemmap22 hugemmap23 hugemmap23 hugemmap25 hugemmap25 hugemmap26 hugemmap26 +hugemmap27 hugemmap27 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -26,6 +26,7 @@ /hugetlb/hugemmap/hugemmap23 /hugetlb/hugemmap/hugemmap25 /hugetlb/hugemmap/hugemmap26 +/hugetlb/hugemmap/hugemmap27 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap27.c new file +136 -0
136 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 8/13 Hugetlb: Migrating libhugetlbfs noresv-regarded-as-resv
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/noresv-regarded-as-resv.c test
Test Description: Test to correct handling for reserve count. If no reserved mapping is created to reserved file region, it should be considered as reserve mapping. Otherwise, reserve count will be overflowed.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap28.c | 74 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap28.c
runtest/hugetlb +1 -0
@@ -28,6 +28,7 @@ hugemmap23 hugemmap23 hugemmap25 hugemmap25 hugemmap26 hugemmap26 hugemmap27 hugemmap27 +hugemmap28 hugemmap28 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -27,6 +27,7 @@ /hugetlb/hugemmap/hugemmap25 /hugetlb/hugemmap/hugemmap26 /hugetlb/hugemmap/hugemmap27 +/hugetlb/hugemmap/hugemmap28 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap28.c new file +74 -0
74 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 08/13] Hugetlb: Migrating libhugetlbfs noresv-regarded-as-resv
Tarun Sahu <[email protected]> wrote:
Migrating the libhugetlbfs/testcases/noresv-regarded-as-resv.c test
Quoted 8 lines
Test Description: Test to correct handling for reserve count. If no reserved mapping is created to reserved file region, it should be considered as reserve mapping. Otherwise, reserve count will be overflowed.
Signed-off-by Tarun Sahu <[email protected]>
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 9/13 Hugetlb: Migrating libhugetlbfs private
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/private.c test
Test Description: The test do mmap() with shared mapping and write. It matches the data with private mmap() and then change it with other data. It checks shared mapping data if data is not contaiminated by private mapping.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap29.c | 115 ++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c
runtest/hugetlb +1 -0
@@ -29,6 +29,7 @@ hugemmap25 hugemmap25 hugemmap26 hugemmap26 hugemmap27 hugemmap27 hugemmap28 hugemmap28 +hugemmap29 hugemmap29 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -28,6 +28,7 @@ /hugetlb/hugemmap/hugemmap26 /hugetlb/hugemmap/hugemmap27 /hugetlb/hugemmap/hugemmap28 +/hugetlb/hugemmap/hugemmap29 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c new file +115 -0
115 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 09/13] Hugetlb: Migrating libhugetlbfs private
Quoted 67 lines · Tarun Sahu
Migrating the
libhugetlbfs/testcases/private.ctestTest Description: The test do
mmap()with shared mapping and write. It matches the data with privatemmap()and then change it with other data. It checks shared mapping data if data is not contaiminated by private mapping.Signed-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap29.c | 115 ++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.cruntest/hugetlb +1
-0@@ -29,6 +29,7 @@ hugemmap25 hugemmap25 hugemmap26 hugemmap26 hugemmap27 hugemmap27 hugemmap28 hugemmap28 +hugemmap29 hugemmap29 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -28,6 +28,7 @@ /hugetlb/hugemmap/hugemmap26 /hugetlb/hugemmap/hugemmap27 /hugetlb/hugemmap/hugemmap28 +/hugetlb/hugemmap/hugemmap29 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c new file +13
-0@@ -0,0 +1,115 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2005-2006 IBM Corporation. +* Author: David Gibson & Adam Litke +*/ + +/*\ +* [Description] +* +* The test do mmap() with shared mapping and write. It matches the data +* with private mmap() and then change it with other data. It checks +* shared mapping data if data is not contaiminated by private mapping. +* Similiarly checks for private data if it is not contaminated by changing
+ * shared mmap data.
+ */testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c new file +3
-0+ +#define _GNU_SOURCE +#include <stdio.h>
testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c line 28
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c new file +10
-0+#include <sys/mount.h> +#include <limits.h> +#include <sys/param.h> +#include <setjmp.h> +#include <sys/types.h> + +#include "hugetlb.h" + +#define C1 0x1234ABCD +#define C2 0xFEDC9876
Dont mix tabs and spaces ^
Quoted 98 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c new file +26
-0+ +#define MNTPOINT "hugetlbfs/" +static unsigned long hpage_size; +static int fd =-1 ; + +static void run_test (void ) +{ +void *p, *q; +unsigned int *pl, *ql; +unsigned long i; + + fd =tst_creat_unlinked (MNTPOINT ,0 ); + p =SAFE_MMAP (NULL , hpage_size,PROT_READ |PROT_WRITE ,MAP_SHARED , + fd,0 ); + + pl = p; +for (i =0 ; i < (hpage_size /sizeof (*pl)); i++) + pl[i] =C1 ^ i; + + q =SAFE_MMAP (NULL , hpage_size,PROT_READ |PROT_WRITE ,MAP_PRIVATE , + fd,0 ); + + ql = q; +for (i =0 ; i < (hpage_size /sizeof (*ql)); i++) { +if (ql[i] != (C1 ^ i)) { + tst_res(TFAIL, "Mismatch at offset %lu, got: %u,expected: %lu",
testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c new file +11
-0+ i, ql[i], C1 ^ i); + goto cleanup; + } + } + +for (i =0 ; i < (hpage_size /sizeof (*ql)); i++) + ql[i] =C2 ^ i; + +for (i =0 ; i < (hpage_size /sizeof (*ql)); i++) { +if (ql[i] != (C2 ^ i)) { + tst_res(TFAIL, "PRIVATE mismatch at offset %lu,got: %u, expected: %lu",
testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c new file +8
-0+ i, ql[i], C2 ^ i); + goto cleanup; + } + } + +for (i =0 ; i < (hpage_size /sizeof (*pl)); i++) { +if (pl[i] != (C1 ^ i)) { + tst_res(TFAIL, "SHARED map contaminated at offset%lu, "
+ "got: %u, expected: %lu", i,
pl[i], C1 ^ i);testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c new file +9
-0+ goto cleanup; + } + } + +memset (p,0 , hpage_size); + +for (i =0 ; i < (hpage_size /sizeof (*ql)); i++) { +if (ql[i] != (C2 ^ i)) { + tst_res(TFAIL, "PRIVATE map contaminated at offset%lu, "
+ "got: %u, expected: %lu", i,
ql[i], C2 ^ i);testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c new file +4
-0+ goto cleanup; + } + } + tst_res(TPASS, "Successfully tested shared/private mmaping and itsdata");
testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c new file +27
-1+cleanup: +SAFE_MUNMAP (p, hpage_size); +SAFE_MUNMAP (q, hpage_size); +SAFE_CLOSE (fd); +} + +static void setup (void ) +{ + hpage_size =SAFE_READ_MEMINFO (MEMINFO_HPAGE_SIZE )*1024 ; +} + +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .needs_root =1 , + .mntpoint =MNTPOINT , + .needs_hugetlbfs =1 , + .needs_tmpdir =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {2 ,TST_NEEDS }, +}; --2.31.1
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 10/13 Hugetlb: Migrating libhugetlbfs readahead_reserve
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/readahead_reserve.c test
Test Description: readahead() on some kernels can cause the reservation counter to get corrupted. The problem is that the patches are allocated for the reservation but not faulted in at the time of allocation. The counters do not get updated and effectively "leak". This test identifies whether the kernel is vulnerable to the problem or not. It's fixed in kernel by 'commit f2deae9d4e70
("Remove implementation of readpage from the hugetlbfs_aops")'.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap30.c | 85 +++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap30.c
runtest/hugetlb +1 -0
@@ -30,6 +30,7 @@ hugemmap26 hugemmap26 hugemmap27 hugemmap27 hugemmap28 hugemmap28 hugemmap29 hugemmap29 +hugemmap30 hugemmap30 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -29,6 +29,7 @@ /hugetlb/hugemmap/hugemmap27 /hugetlb/hugemmap/hugemmap28 /hugetlb/hugemmap/hugemmap29 +/hugetlb/hugemmap/hugemmap30 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap30.c new file +85 -0
85 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 10/13] Hugetlb: Migrating libhugetlbfs readahead_reserve
Quoted 71 lines · Tarun Sahu
Migrating the
libhugetlbfs/testcases/readahead_reserve.ctestTest Description:
readahead()on some kernels can cause the reservation counter to get corrupted. The problem is that the patches are allocated for the reservation but not faulted in at the time of allocation. The counters do not get updated and effectively "leak". This test identifies whether the kernel is vulnerable to the problem or not. It's fixed in kernel by 'commitf2deae9d4e70
("Remove implementation of readpage from thehugetlbfs_aops")'.Signed-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap30.c | 85 +++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap30.cruntest/hugetlb +1
-0@@ -30,6 +30,7 @@ hugemmap26 hugemmap26 hugemmap27 hugemmap27 hugemmap28 hugemmap28 hugemmap29 hugemmap29 +hugemmap30 hugemmap30 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -29,6 +29,7 @@ /hugetlb/hugemmap/hugemmap27 /hugetlb/hugemmap/hugemmap28 /hugetlb/hugemmap/hugemmap29 +/hugetlb/hugemmap/hugemmap30 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap30.c new file +18
-0@@ -0,0 +1,85 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2005-2006 IBM Corporation. +* Author: Mel Gorman +*/ + +/*\ +* [Description] +* +* readahead() on some kernels can cause the reservation counter to get +* corrupted. The problem is that the pages are allocated for the +* reservation but not faulted in at the time of allocation. The +* counters do not get updated and effectively "leak". This test +* identifies whether the kernel is vulnerable to the problem or not. +* It's fixed in kernel by commit f2deae9d4e70. +*/ + +#define _GNU_SOURCE
testcases/kernel/mem/hugetlb/hugemmap/hugemmap30.c line 27
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap30.c new file +9
-0+#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/mount.h> +#include <limits.h> +#include <sys/param.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h>
I just found these header files are not needed, this test still compiles fine without including them. The possible reason is that we already indirectly include them via hugetlb.h.
This comment also works for other tests.
Quoted 62 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap30.c new file +58
-1+ +#include "hugetlb.h" + +#define MNTPOINT "hugetlbfs/" +static long hpage_size; +static int fd =-1 ; + +static void run_test (void ) +{ +void *p; +unsigned long initial_rsvd, map_rsvd, readahead_rsvd, end_rsvd; + + fd =tst_creat_unlinked (MNTPOINT ,0 ); + initial_rsvd =SAFE_READ_MEMINFO (MEMINFO_HPAGE_RSVD ); + + p =SAFE_MMAP (NULL , hpage_size,PROT_READ |PROT_WRITE ,MAP_SHARED , + fd,0 ); + map_rsvd =SAFE_READ_MEMINFO (MEMINFO_HPAGE_RSVD ); +tst_res (TINFO ,"map_rsvd: %lu" , map_rsvd); + +readahead (fd,0 , hpage_size); + readahead_rsvd =SAFE_READ_MEMINFO (MEMINFO_HPAGE_RSVD ); +tst_res (TINFO ,"readahead_rsvd: %lu" , readahead_rsvd); + +memset (p,1 , hpage_size); + +SAFE_MUNMAP (p, hpage_size); +SAFE_CLOSE (fd); + end_rsvd =SAFE_READ_MEMINFO (MEMINFO_HPAGE_RSVD ); + +TST_EXP_EQ_LU (end_rsvd, initial_rsvd); +} + +static void setup (void ) +{ + hpage_size =SAFE_READ_MEMINFO (MEMINFO_HPAGE_SIZE )*1024 ; +} + +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .tags = (struct tst_tag []) { + {"linux-git" ,"f2deae9d4e70" }, + {} + }, + .needs_root =1 , + .mntpoint =MNTPOINT , + .needs_hugetlbfs =1 , + .needs_tmpdir =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {1 ,TST_NEEDS }, +}; --2.31.1
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 11/13 Hugetlb: Migrating libhugetlbfs shared
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/shared.c test
Test Description: This test is basic shared mapping test. Two shared mappings are created with same offset on a file. It checks if writing to one mapping can be seen to other mapping or not?
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap31.c | 84 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap31.c
runtest/hugetlb +1 -0
@@ -31,6 +31,7 @@ hugemmap27 hugemmap27 hugemmap28 hugemmap28 hugemmap29 hugemmap29 hugemmap30 hugemmap30 +hugemmap31 hugemmap31 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -30,6 +30,7 @@ /hugetlb/hugemmap/hugemmap28 /hugetlb/hugemmap/hugemmap29 /hugetlb/hugemmap/hugemmap30 +/hugetlb/hugemmap/hugemmap31 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap31.c new file +84 -0
84 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 11/13] Hugetlb: Migrating libhugetlbfs shared
Quoted 8 lines · Tarun Sahu
Migrating the
libhugetlbfs/testcases/shared.ctestTest Description: This test is basic shared mapping test. Two shared mappings are created with same offset on a file. It checks if writing to one mapping can be seen to other mapping or not?
Signed-off-by Tarun Sahu <[email protected]>
Quoted 129 lines
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap31.c | 84 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap31.cruntest/hugetlb +1
-0@@ -31,6 +31,7 @@ hugemmap27 hugemmap27 hugemmap28 hugemmap28 hugemmap29 hugemmap29 hugemmap30 hugemmap30 +hugemmap31 hugemmap31 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -30,6 +30,7 @@ /hugetlb/hugemmap/hugemmap28 /hugetlb/hugemmap/hugemmap29 /hugetlb/hugemmap/hugemmap30 +/hugetlb/hugemmap/hugemmap31 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap31.c new file +51
-0@@ -0,0 +1,84 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2005-2006 IBM Corporation. +* Author: David Gibson & Adam Litke +*/ + +/*\ +* [Description] +* +* This test is basic shared mapping test. Two shared mappings are created +* with same offset on a file. It checks if writing to one mapping can be +* seen to other mapping or not? +*/ + +#define _GNU_SOURCE +#include <stdio.h> +#include <sys/mount.h> +#include <limits.h> +#include <sys/param.h> +#include <setjmp.h> +#include <sys/types.h> + +#include "hugetlb.h" + +#define RANDOM_CONSTANT 0x1234ABCD +#define MNTPOINT "hugetlbfs/" + +static long hpage_size; +static int fd =-1 ; + +static void run_test (void ) +{ +void *p, *q; +unsigned long *pl, *ql; +unsigned long i; + + fd =tst_creat_unlinked (MNTPOINT ,0 ); + p =SAFE_MMAP (NULL , hpage_size,PROT_READ |PROT_WRITE ,MAP_SHARED , + fd,0 ); + + q =SAFE_MMAP (NULL , hpage_size,PROT_READ |PROT_WRITE ,MAP_SHARED , + fd,0 ); + + pl = p; +for (i =0 ; i < (hpage_size /sizeof (*pl)); i++) + pl[i] =RANDOM_CONSTANT ^ i; + + ql = q; +for (i =0 ; i < (hpage_size /sizeof (*ql)); i++) { +if (ql[i] != (RANDOM_CONSTANT ^ i)) { + tst_res(TFAIL, "Mismatch at offset %lu, Got: %lu,Expected: %lu",
testcases/kernel/mem/hugetlb/hugemmap/hugemmap31.c new file +6
-0+ i, ql[i], RANDOM_CONSTANT ^ i); + goto cleanup; + } + } + + tst_res(TPASS, "Successfully tested data between two sharedmappings");
testcases/kernel/mem/hugetlb/hugemmap/hugemmap31.c new file +27
-1+cleanup: +SAFE_MUNMAP (p, hpage_size); +SAFE_MUNMAP (q, hpage_size); +SAFE_CLOSE (fd); +} + +static void setup (void ) +{ + hpage_size =SAFE_READ_MEMINFO (MEMINFO_HPAGE_SIZE )*1024 ; +} + +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .needs_root =1 , + .mntpoint =MNTPOINT , + .needs_hugetlbfs =1 , + .needs_tmpdir =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {2 ,TST_NEEDS }, +}; --2.31.1
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 12/13 Hugetlb: Migrating libhugetlbfs shm-fork
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/shm-fork.c test
Test Description: Test shared memory behavior when multiple threads are Test shared memory behavior when multiple threads are attached to a segment. A segment is created and then children are spawned which attach, write, read (verify), and detach from the shared memory segment.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugefork/hugefork02.c | 104 ++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugefork/hugefork02.c
runtest/hugetlb +1 -0
@@ -2,6 +2,7 @@ hugefallocate01 hugefallocate01 hugefallocate02 hugefallocate02 hugefork01 hugefork01 +hugefork02 hugefork02 -P 3 -s 5 hugemmap01 hugemmap01 hugemmap02 hugemmap02
testcases/kernel/mem/.gitignore +1 -0
@@ -2,6 +2,7 @@ /hugetlb/hugefallocate/hugefallocate01 /hugetlb/hugefallocate/hugefallocate02 /hugetlb/hugefork/hugefork01 +/hugetlb/hugefork/hugefork02 /hugetlb/hugemmap/hugemmap01 /hugetlb/hugemmap/hugemmap02 /hugetlb/hugemmap/hugemmap04
testcases/kernel/mem/hugetlb/hugefork/hugefork02.c new file +104 -0
104 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 12/13] Hugetlb: Migrating libhugetlbfs shm-fork
Quoted 77 lines · Tarun Sahu
Migrating the
libhugetlbfs/testcases/shm-fork.ctestTest Description: Test shared memory behavior when multiple threads are Test shared memory behavior when multiple threads are attached to a segment. A segment is created and then children are spawned which attach, write, read (verify), and detach from the shared memory segment.
Signed-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugefork/hugefork02.c | 104 ++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugefork/hugefork02.cruntest/hugetlb +1
-0@@ -2,6 +2,7 @@ hugefallocate01 hugefallocate01 hugefallocate02 hugefallocate02 hugefork01 hugefork01 +hugefork02 hugefork02 -P 3 -s 5 hugemmap01 hugemmap01 hugemmap02 hugemmap02testcases/kernel/mem/.gitignore +1
-0@@ -2,6 +2,7 @@ /hugetlb/hugefallocate/hugefallocate01 /hugetlb/hugefallocate/hugefallocate02 /hugetlb/hugefork/hugefork01 +/hugetlb/hugefork/hugefork02 /hugetlb/hugemmap/hugemmap01 /hugetlb/hugemmap/hugemmap02 /hugetlb/hugemmap/hugemmap04testcases/kernel/mem/hugetlb/hugefork/hugefork02.c new file +12
-0@@ -0,0 +1,104 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation. +* Author: David Gibson & Adam Litke +*/ + +/*\ +* [Description] +* +* Test shared memory behavior when multiple threads are attached to a +* segment. A segment is created and then children are spawned which +* attach, write, read (verify), and detach from the shared memory segment.
+ */testcases/kernel/mem/hugetlb/hugefork/hugefork02.c new file +14
-0+ +#define _GNU_SOURCE +#include <stdio.h> +#include <sys/mount.h> +#include <limits.h> +#include <sys/param.h> +#include <setjmp.h> +#include <sys/types.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/shm.h> + +#include "tst_safe_sysv_ipc.h"
testcases/kernel/mem/hugetlb/hugefork/hugefork02.c line 33
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork02.c new file +6
-0+#include "hugetlb.h" + +static int shmid =-1 ; + +#define NR_HUGEPAGES 5 +#define NUMPROCS 20
Defining a fixed number to fork children might not be wise.
A sanity way is to detect the available NCPUS and create corresponding children (or twice the amount), this will benefit small machines (e.g. KVM guest with only single CPU). For a system with a larger number of CPUs, just choose 20 as the default will be OK.
LTP has tst_ncpus_available() function for getting available NCPUS.
testcases/kernel/mem/hugetlb/hugefork/hugefork02.c line 36
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork02.c new file +3
-0+#define MNTPOINT "hugetlbfs/" +#define MAX_PROCS 200 +#define BUF_SZ 256
I don't see any places using these two macros.
+
Quoted 73 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork02.c new file +16
-0+static long hpage_size; + +static void do_child (int thread,unsigned long size) +{ +volatile char *shmaddr; +int j; +unsigned long k; + +for (j =0 ; j <5 ; j++) { + shmaddr =SAFE_SHMAT (shmid,0 ,SHM_RND ); + +for (k =0 ; k < size; k++) + shmaddr[k] = (char ) (k); +for (k =0 ; k < size; k++) +if (shmaddr[k] != (char )k) { + tst_res(TFAIL, "Thread %d, Offset %lumismatch", thread, k);
testcases/kernel/mem/hugetlb/hugefork/hugefork02.c new file +27
-0+ goto cleanup; + } + +SAFE_SHMDT ((const void *)shmaddr); + } +cleanup: +exit (0 ); +} + +static void run_test (void ) +{ +unsigned long size; +int pid; +int i; + + size = hpage_size *NR_HUGEPAGES ; + shmid =SAFE_SHMGET (2 , size,SHM_HUGETLB |IPC_CREAT |SHM_R |SHM_W ); + +for (i =0 ; i <NUMPROCS ; i++) { + pid =SAFE_FORK (); + +if (pid ==0 ) +do_child (i, size); + } + +tst_reap_children (); + tst_res(TPASS, "Successfully tested shared hugetlb memory withmultiple procs");
testcases/kernel/mem/hugetlb/hugefork/hugefork02.c new file +24
-1+} + +static void setup (void ) +{ + hpage_size =SAFE_READ_MEMINFO (MEMINFO_HPAGE_SIZE )*1024 ; +} + +static void cleanup (void ) +{ +if (shmid >=0 ) +SAFE_SHMCTL (shmid,IPC_RMID ,NULL ); +} + +static struct tst_test test = { + .needs_root =1 , + .mntpoint =MNTPOINT , + .needs_hugetlbfs =1 , + .needs_tmpdir =1 , + .forks_child =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {NR_HUGEPAGES ,TST_NEEDS }, +}; --2.31.1
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 12/13] Hugetlb: Migrating libhugetlbfs shm-fork
In reply to Tarun SahuHi,
Quoted 1 line
Migrating the
libhugetlbfs/testcases/shm-fork.ctest
NOTE: if you're talking about libhugetlbfs [1], the test path is tests/shm-fork.c (not testcases).
Quoted 19 lines
Test Description: Test shared memory behavior when multiple threads are Test shared memory behavior when multiple threads are attached to a segment. A segment is created and then children are spawned which attach, write, read (verify), and detach from the shared memory segment.
Signed-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugefork/hugefork02.c | 104 ++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugefork/hugefork02.cruntest/hugetlb +0
-0
runtest/hugetlb hugefallocate01 hugefallocate01 · line 5
Quoted 4 lines
runtest/hugetlb +1
-0@@ -2,6 +2,7 @@ hugefallocate01 hugefallocate01 hugefallocate02 hugefallocate02 hugefork01 hugefork01 +hugefork02 hugefork02 -P 3 -s 5
You're not define tst_option [2] (you don't even have any code which would hold these options), therefore passing any of these 2 options will quit the test:
hugefork02: invalid option -- 'P'
Please fix it in next version.
Kind regards,
Petr
[1] https://github.com/libhugetlbfs/libhugetlbfs
[2] https://github.com/linux-test-project/ltp/wiki/C-Test-API#15-test-specific-command-line-options
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 12/13] Hugetlb: Migrating libhugetlbfs shm-fork
Petr Vorel <[email protected]> writes:
Hi Petr,
Thanks for reviewing it.
Quoted 5 lines
Hi,
Quoted 1 line
Migrating the
libhugetlbfs/testcases/shm-fork.ctestNOTE: if you're talking about libhugetlbfs [1], the test path is
tests/shm-fork.c(not testcases).
Ohh Right. Thanks for pointing this out.
I checked, I did the same in all the past testcases, will take care of it.
Quoted 24 lines
Quoted 23 lines
Test Description: Test shared memory behavior when multiple threads are Test shared memory behavior when multiple threads are attached to a segment. A segment is created and then children are spawned which attach, write, read (verify), and detach from the shared memory segment.
Signed-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugefork/hugefork02.c | 104 ++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugefork/hugefork02.cruntest/hugetlb +0
-0@@ -2,6 +2,7 @@ hugefallocate01 hugefallocate01 hugefallocate02 hugefallocate02
Quoted 9 lines
runtest/hugetlb hugefallocate01 hugefallocate01 · line 5
Quoted 2 lines
runtest/hugetlb +1
-0hugefork01 hugefork01 +hugefork02 hugefork02 -P 3 -s 5You're not define
tst_option[2] (you don't even have any code which would hold these options), therefore passing any of these 2 options will quit the test:
hugefork02: invalid option -- 'P'Please fix it in next version.
Fixed it in next revision.
please check here: https://lore.kernel.org/all/[email protected]/
Quoted 8 lines
Kind regards,
Petr[1] https://github.com/libhugetlbfs/libhugetlbfs
[2] https://github.com/linux-test-project/ltp/wiki/C-Test-API#15-test-specific-command-line-optionsSignature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 13/13 Hugetlb: Migrating libhugetlbfs mremap-expand-slice-collision
In reply to Tarun SahuKernel has bug in mremap for some architecture. mremap() can cause crashes on architectures with holes in the address space (like ia64) and on powerpc with it's distict page size slices.
This test perform mremap() with normal and hugepages around powerpc slice boundary.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap24.c | 212 ++++++++++++++++++ 3 files changed, 214 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap24.c
runtest/hugetlb +1 -0
@@ -26,6 +26,7 @@ hugemmap20 hugemmap20 hugemmap21 hugemmap21 hugemmap22 hugemmap22 hugemmap23 hugemmap23 +hugemmap23 hugemmap24 hugemmap25 hugemmap25 hugemmap26 hugemmap26 hugemmap27 hugemmap27
testcases/kernel/mem/.gitignore +1 -0
@@ -25,6 +25,7 @@ /hugetlb/hugemmap/hugemmap21 /hugetlb/hugemmap/hugemmap22 /hugetlb/hugemmap/hugemmap23 +/hugetlb/hugemmap/hugemmap24 /hugetlb/hugemmap/hugemmap25 /hugetlb/hugemmap/hugemmap26 /hugetlb/hugemmap/hugemmap27
testcases/kernel/mem/hugetlb/hugemmap/hugemmap24.c new file +212 -0
212 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp