Hugetlb: Migrating libhugetlbfs tests
cover Hugetlb: Migrating libhugetlbfs tests
Hi,
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.
As per previous dicussion in RFC[1], Here, this patch series consists of hugetlb tests taken from libhugetlbfs modified to work in ltp environment. This series do not include all the tests, I will post another series for the remaining tests soon.
ref:
1: https://lore.kernel.org/all/[email protected]/
Tarun Sahu (29):
Hugetlb: Migrating libhugetlbfs brk_near_huge
Hugetlb: Migrating libhugetlbfs chunk-overcommit
Hugetlb: Migrating libhugetlbfs corrupt-by-cow-opt
Hugetlb: Migrating libhugetlbfs counters
Hugetlb: Migrating libhugetlbfs directio
Hugetlb: Migrating libhugetlbfs fadvise_reserve
Hugetlb: Migrating libhugetlbfs fallocate_align
Hugetlb: Migrating libhugetlbfs fallocate_basic
Hugetlb: Migrating libhugetlbfs fork-cow
Hugetlb: Migrating libhugetlbfs huge_at_4GB_normal_below
Hugetlb: Migrating libhugetlbfs huge_below_4GB_normal_above
Hugetlb: Migrating libhugetlbfs icache-hygiene
Hugetlb: Migrating libhugetlbfs madvise_reserve
Hugetlb: Migrating libhugetlbfs map_high_truncate_2
Hugetlb: Migrating libhugetlbfs misalign
Hugetlb: Migrating libhugetlbfs misaligned_offset
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 readback
Hugetlb: Migrating libhugetlbfs shared
Hugetlb: Migrating libhugetlbfs shm-fork
runtest/hugetlb | 31 ++ testcases/kernel/mem/.gitignore | 29 ++ .../kernel/mem/hugetlb/hugefallocate/Makefile | 10 + .../hugetlb/hugefallocate/hugefallocate01.c | 187 +++++++ .../hugetlb/hugefallocate/hugefallocate02.c | 116 +++++ .../kernel/mem/hugetlb/hugefork/Makefile | 10 + .../kernel/mem/hugetlb/hugefork/hugefork01.c | 220 ++++++++ .../kernel/mem/hugetlb/hugefork/hugefork02.c | 196 ++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap07.c | 163 ++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap08.c | 173 +++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap09.c | 102 ++++ .../kernel/mem/hugetlb/hugemmap/hugemmap10.c | 475 ++++++++++++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap11.c | 111 ++++ .../kernel/mem/hugetlb/hugemmap/hugemmap12.c | 114 +++++ .../kernel/mem/hugetlb/hugemmap/hugemmap13.c | 160 ++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap14.c | 204 ++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap15.c | 250 +++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap16.c | 112 +++++ .../kernel/mem/hugetlb/hugemmap/hugemmap17.c | 126 +++++ .../kernel/mem/hugetlb/hugemmap/hugemmap18.c | 173 +++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap19.c | 166 ++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap20.c | 108 ++++ .../kernel/mem/hugetlb/hugemmap/hugemmap21.c | 222 ++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap22.c | 170 +++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap23.c | 283 +++++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap25.c | 168 +++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap26.c | 148 ++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap27.c | 166 ++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap28.c | 107 ++++ .../kernel/mem/hugetlb/hugemmap/hugemmap29.c | 129 +++++ .../kernel/mem/hugetlb/hugemmap/hugemmap30.c | 120 +++++ .../kernel/mem/hugetlb/hugemmap/hugemmap31.c | 98 ++++ .../kernel/mem/hugetlb/hugemmap/hugemmap32.c | 104 ++++ testcases/kernel/mem/hugetlb/lib/hugetlb.c | 75 +++ testcases/kernel/mem/hugetlb/lib/hugetlb.h | 5 + 35 files changed, 5031 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/Makefile create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate01.c create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c create mode 100644 testcases/kernel/mem/hugetlb/hugefork/Makefile create mode 100644 testcases/kernel/mem/hugetlb/hugefork/hugefork01.c create mode 100644 testcases/kernel/mem/hugetlb/hugefork/hugefork02.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap16.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap17.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap18.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap19.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/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 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.c
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 1/29 Hugetlb: Migrating libhugetlbfs brk_near_huge
Migrating the libhugetlbfs/testcases/brk_near_huge.c test
Test Description:
Certain kernels have a bug where brk() does not perform the same checks that a MAP_FIXED mmap() will, allowing brk() to create a normal page VMA in a hugepage only address region. This can lead to oopses or other badness.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap07.c | 163 ++++++++++++++++++ testcases/kernel/mem/hugetlb/lib/hugetlb.c | 75 ++++++++ testcases/kernel/mem/hugetlb/lib/hugetlb.h | 5 + 5 files changed, 245 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c
runtest/hugetlb +1 -0
@@ -3,6 +3,7 @@ hugemmap02 hugemmap02 hugemmap04 hugemmap04 hugemmap05 hugemmap05 hugemmap06 hugemmap06 +hugemmap07 hugemmap07 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -4,6 +4,7 @@ /hugetlb/hugemmap/hugemmap04 /hugetlb/hugemmap/hugemmap05 /hugetlb/hugemmap/hugemmap06 +/hugetlb/hugemmap/hugemmap07 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +163 -0
163 lines not on this page · raw message
testcases/kernel/mem/hugetlb/lib/hugetlb.c +75 -0
93 lines not on this page · raw message
testcases/kernel/mem/hugetlb/lib/hugetlb.h +5 -0
@@ -20,6 +20,9 @@#include "old_tmpdir.h" #include "mem.h" +#define ALIGN (x, a) (((x) + (a) - 1) & ~((a) - 1)) +#define PALIGN (p, a) ((void *)ALIGN((unsigned long)(p), (a))) +#define SHM_RD 0400#define SHM_WR 0200#define SHM_RW (SHM_RD|SHM_WR)
@@ -39,5 +42,7 @@ extern key_t shmkey; /* an IPC key generated by ftok() */int getipckey (void );int getuserid (char *user);void rm_shm (int shm_id); +int test_addr_huge (void *p); +int read_maps (unsigned long addr,char *buf);#endif /* hugetlb.h */
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge
Hi!
Quoted 45 lines
Test Description:
Certain kernels have a bug wherebrk()does not perform the same checks that aMAP_FIXEDmmap()will, allowingbrk()to create a normal page VMA in a hugepage only address region. This can lead to oopses or other badness.Signed-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap07.c | 163 ++++++++++++++++++ testcases/kernel/mem/hugetlb/lib/hugetlb.c | 75 ++++++++ testcases/kernel/mem/hugetlb/lib/hugetlb.h | 5 + 5 files changed, 245 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.cruntest/hugetlb +1
-0@@ -3,6 +3,7 @@ hugemmap02 hugemmap02 hugemmap04 hugemmap04 hugemmap05 hugemmap05 hugemmap06 hugemmap06 +hugemmap07 hugemmap07 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -4,6 +4,7 @@ /hugetlb/hugemmap/hugemmap04 /hugetlb/hugemmap/hugemmap05 /hugetlb/hugemmap/hugemmap06 +/hugetlb/hugemmap/hugemmap07 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +0
-0
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c line 10
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +10
-0@@ -0,0 +1,163 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation. +* +* Test Name: brk near hugepage +* +* Test Description: Certain kernels have a bug where brk() does not perform +* the same checks that a MAP_FIXED mmap() will, allowing brk() to create a +* normal page VMA in a hugepage only address region. This can lead to oopses +* or other badness.
This description has to be in a separate ascii-doc formatted comment that starts with /*\
Quoted 79 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +78
-0+* HISTORY +* Written by David Gibson & Adam Litke +* +*/ + +#define _GNU_SOURCE +#include <stdio.h> +#include <sys/mount.h> +#include <limits.h> +#include <sys/param.h> +#include <sys/types.h> + +#include "hugetlb.h" +#include "tst_safe_stdio.h" + +static char *verbose; +static int fd =-1 ; +static char hfile[MAXPATHLEN ]; +static long hpage_size; + +static int arch_has_slice_support (void ) +{ +#ifdef __powerpc64__ +char mmu_type[16 ]; +FILE *fp; + + fp =SAFE_POPEN ("cat /proc/cpuinfo | grep MMU | awk '{ print $3}'" ,"r" ); +if (fscanf (fp,"%s" , mmu_type) <0 ) +tst_brk (TBROK ,"Failed to determine MMU type" ); + +pclose (fp); +return strcmp (mmu_type,"Hash" ) ==0 ; +#elif defined(__powerpc__) && !defined(PPC_NO_SEGMENTS ) +return 1 ; +#else +return 0 ; +#endif +} + +#ifdef __powerpc64__ +static void *next_chunk (void *addr) +{ +if (!arch_has_slice_support ()) +return PALIGN (addr,SAFE_READ_MEMINFO ("Hugepagesize:" )*1024 ); + +if ((unsigned long )addr <0x100000000UL ) +/* 256M segments below 4G */ +return PALIGN (addr,0x10000000UL ); +/* 1TB segments above */ +return PALIGN (addr,0x10000000000UL ); +} +#elif defined(__powerpc__) && !defined(PPC_NO_SEGMENTS ) +static void *next_chunk (void *addr) +{ +return PALIGN (addr,0x10000000UL ); +} +#elif defined(__ia64__) +static void *next_chunk (void *addr) +{ +return PALIGN (addr,0x8000000000000000UL ); +} +#else +static void *next_chunk (void *addr) +{ +return PALIGN (addr,SAFE_READ_MEMINFO ("Hugepagesize:" )*1024 ); +} +#endif + +static void run_test (void ) +{ +void *brk0, *hugemap_addr, *newbrk; +char *p; +int err; + + fd =SAFE_OPEN (hfile,O_RDWR |O_CREAT ,0600 ); +SAFE_UNLINK (hfile); + brk0 =sbrk (0 ); +if (verbose)
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c line 100
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +10
-0+tst_res (TINFO ,"Initial break at %p" , brk0); + + hugemap_addr =next_chunk (brk0) + hpage_size; + + p =SAFE_MMAP (hugemap_addr, hpage_size,PROT_READ |PROT_WRITE , +MAP_PRIVATE |MAP_FIXED , fd,0 ); +if (p != hugemap_addr) { +tst_res (TFAIL ,"mmap() at unexpected address %p instead of %p\n" , p, + hugemap_addr); + goto fail;
Can we just do return here instead. The failure has been reported there is no point in calling tst_brk(TBROK, ...) as well.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c line 107
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +7
-0+ } + + err =test_addr_huge ((void *)p); +if (err !=1 ) { +tst_res (TFAIL ,"Mapped address is not hugepage" ); + goto fail; + }
I do not get why we even need this check. We map a file located on hugetlbfs and then we stat it and check that it indeed is on hutetlbfs. What did we expect to fail here? I would say that the mmap() with right path is enough to make sure that the file is created on hugetlbfs.
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +6
-0+ newbrk =next_chunk (brk0) +getpagesize (); + err =brk ((void *)newbrk); +if (err ==-1 ) { +/* Failing the brk() is an acceptable kernel response */ +tst_res (TPASS ,"Failing the brk is an acceptable response" ); + }else {
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c line 124
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +10
-0+/* Suceeding the brk() is acceptable iff the new memory is +* properly accesible and we don't have a kernel blow up when +* we touch it. +*/ +memset (brk0,0 , newbrk-brk0); +tst_res (TPASS ,"Succeding brk is acceptable, as memset confirms that " +"new memory is properly accessible without kernel blow up" ); + } +SAFE_MUNMAP (p, hpage_size); +SAFE_CLOSE (fd);
Shouldn't we brk() back to the original brk0? Does the test work with -i 2?
Quoted 13 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +13
-0+return ; +fail: +tst_brk (TBROK ,"Once failed, No point in continuing the test" ); +} + +static void setup (void ) +{ +if (tst_hugepages <1 ) +tst_brk (TCONF ,"Not enough hugepages for testing." ); + +if (!Hopt) + Hopt =tst_get_tmpdir (); +SAFE_MOUNT ("none" , Hopt,"hugetlbfs" ,0 ,NULL );
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c line 147
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +10
-0+ +snprintf (hfile,sizeof (hfile),"%s/ltp_hugetlbfile%d" , Hopt,getpid ()); + hpage_size =SAFE_READ_MEMINFO ("Hugepagesize:" )*1024 ; +} + +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +umount2 (Hopt,MNT_DETACH );
We whould umount here only if we actually have mounted something.
Quoted 143 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +16
-0+} + +static struct tst_test test = { + .needs_root =1 , + .needs_tmpdir =1 , + .options = (struct tst_option []) { + {"v" , &verbose,"Turns on verbose mode" }, + {"H:" , &Hopt,"Location of hugetlbfs, i.e. -H /var/hugetlbfs" }, + {"s:" , &nr_opt,"Set the number of the been allocated hugepages" }, + {} + }, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {1 ,TST_REQUEST }, +};testcases/kernel/mem/hugetlb/lib/hugetlb.c +75
-0@@ -29,15 +29,19 @@* getipckey() * getuserid() * rm_shm() +* read_maps() +* test_addr_huge() */ #define TST_NO_DEFAULT_MAIN +#define _GNU_SOURCE#include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> #include <sys/time.h> #include <pwd.h> #include "hugetlb.h" +#include "tst_safe_stdio.h" key_t shmkey;@@ -111,3 +115,74 @@ void rm_shm(int shm_id)tst_res (TINFO ,"id = %d" , shm_id); } } + +#define MAPS_BUF_SZ 4096 +#define HUGETLBFS_MAGIC 0x958458f6 + +int read_maps (unsigned long addr,char *buf) +{ +FILE *f; +char line[MAPS_BUF_SZ ]; +char *tmp; + + f =SAFE_FOPEN ("/proc/self/maps" ,"r" ); + +while (1 ) { +unsigned long start, end, off, ino; +int ret; + + tmp =fgets (line,MAPS_BUF_SZ , f); +if (!tmp) +break ; + + buf[0 ] ='\0' ; + ret =sscanf (line,"%lx-%lx %*s %lx %*s %ld %255s" , + &start, &end, &off, &ino, + buf); +if ((ret <4 ) || (ret >5 )) { +tst_res (TWARN ,"Couldn't parse /proc/self/maps line: %s\n" , + line); +SAFE_FCLOSE (f); +return -1 ; + } + +if ((start <= addr) && (addr < end)) { +SAFE_FCLOSE (f); +return 1 ; + } + } + +SAFE_FCLOSE (f); +return 0 ; +} + +int test_addr_huge (void *p) +{ +char name[256 ]; +char *dirend; +int ret; +struct statfs64 sb; + + ret =read_maps ((unsigned long )p, name); +if (ret <0 ) +return ret; +if (ret ==0 ) { +tst_res (TWARN ,"Couldn't find address %p in /proc/self/maps\n" , p); +return -1 ; + } + +/* looks like a filename? */ +if (name[0 ] !='/' ) +return 0 ; + +/* Truncate the filename portion */ + dirend =strrchr (name,'/' ); +if (dirend && dirend > name) + *dirend ='\0' ; + + ret =statfs64 (name, &sb); +if (ret) +return -1 ; + +return (sb.f_type ==HUGETLBFS_MAGIC ); +}testcases/kernel/mem/hugetlb/lib/hugetlb.h +5
-0@@ -20,6 +20,9 @@#include "old_tmpdir.h" #include "mem.h" +#define ALIGN (x, a) (((x) + (a) - 1) & ~((a) - 1)) +#define PALIGN (p, a) ((void *)ALIGN((unsigned long)(p), (a))) +#define SHM_RD 0400#define SHM_WR 0200#define SHM_RW (SHM_RD|SHM_WR)@@ -39,5 +42,7 @@ extern key_t shmkey; /* an IPC key generated by ftok() */int getipckey (void );int getuserid (char *user);void rm_shm (int shm_id); +int test_addr_huge (void *p); +int read_maps (unsigned long addr,char *buf);#endif /* hugetlb.h */ Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge
Hi,
Thanks Cyril for reviewing it.
Please check my comments below.
On
Mon, 2022-10-17 at 11:30 +0200, Cyril Hrubis wrote:
-- skip
Quoted 11 lines
+ *
Quoted 9 lines
+ * Test Name: brk near hugepage
+ *
+ * Test Description: Certain kernels have a bug wherebrk()does not perform
+ * the same checks that aMAP_FIXEDmmap()will, allowingbrk()to create a
+ * normal page VMA in a hugepage only address region. This can lead to oopses
+ * or other badness.
Quoted 2 lines
This description has to be in a separate ascii-doc formatted comment that starts with /*\
Ok. I will update this in all of the patches in this series.
-- skip
Quoted 11 lines
Review
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +4
-0+ p =SAFE_MMAP (hugemap_addr, hpage_size,PROT_READ |PROT_WRITE , +MAP_PRIVATE |MAP_FIXED , fd,0 ); +if (p != hugemap_addr) { + tst_res(TFAIL, "mmap() at unexpected address %p insteadof %p\n", p,
(quoted diff) +2
-0+ hugemap_addr); + goto fail;Can we just do return here instead. The failure has been reported there
is no point in callingtst_brk(TBROK, ...)as well.
When we run one iteration only, tst_brk does not make sense, I agree. But if we are running more than one iteration (i >= 2), test should not continue to next iteration if the current iteration fails. Only way I could find is to use tst_brk(TBROK,... , as tst_brk(TFAIl... is deprecated.
Quoted 16 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c line 107
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +7
-0+ } + + err =test_addr_huge ((void *)p); +if (err !=1 ) { +tst_res (TFAIL ,"Mapped address is not hugepage" ); + goto fail; + }I do not get why we even need this check. We map a file located on hugetlbfs and then we stat it and check that it indeed is on hutetlbfs.
What did we expect to fail here? I would say that themmap()with right
path is enough to make sure that the file is created on hugetlbfs.
I agree, this check is redundant, I will remove it.
Quoted 17 lines
Quoted 17 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +4
-0+ newbrk =next_chunk (brk0) +getpagesize (); + err =brk ((void *)newbrk); +if (err ==-1 ) { +/* Failing the brk() is an acceptable kernel response */
(quoted diff) +1
-0+ tst_res(TPASS, "Failing the brk is an acceptableresponse");
(quoted diff) +2
-0+ } else { + /* Suceeding the brk() is acceptable iff the new memoryis
(quoted diff) +1
-0+ * properly accesible and we don't have a kernel blowup when
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +4
-0+* we touch it. +*/ +memset (brk0,0 , newbrk-brk0); + tst_res(TPASS, "Succeding brk is acceptable, as memsetconfirms that "
Quoted 9 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c line 124
Quoted 5 lines
(quoted diff) +1
-0+ "new memory is properly accessiblewithout kernel blow up");
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +3
-0+ } +SAFE_MUNMAP (p, hpage_size); +SAFE_CLOSE (fd);Shouldn't we
brk()back to the original brk0? Does the test work with -i 2?
Yes, will update it back to brk0.
Yes -i 2.. working, may be becuase, we
are just moving it by 1 page.
--skip
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c line 147
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +6
-0+ +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +umount2 (Hopt,MNT_DETACH );We whould umount here only if we actually have mounted something.
umount only, will require explicit unmap when test fails or break. For
that, all the local variable for address mapping will have to be static defined so that they can be accessed in cleanup() function.
I tried to avoid it by using umount2 which eventually umount when process unmaps all the mappings after it finishes.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge
Quoted 13 lines
-- skip
Quoted 11 lines
Review
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +4
-0+ p =SAFE_MMAP (hugemap_addr, hpage_size,PROT_READ |PROT_WRITE , +MAP_PRIVATE |MAP_FIXED , fd,0 ); +if (p != hugemap_addr) { + tst_res(TFAIL, "mmap() at unexpected address %p insteadof %p\n", p,
(quoted diff) +2
-0+ hugemap_addr); + goto fail;Can we just do return here instead. The failure has been reported there
is no point in callingtst_brk(TBROK, ...)as well.
Quoted 5 lines
When we run one iteration only,
tst_brkdoes not make sense, I agree. But if we are running more than one iteration (i >= 2), test should not continue to next iteration if the current iteration fails. Only way I could find is to use tst_brk(TBROK,... , as tst_brk(TFAIl... is deprecated.
I do not see why we should abort on first failure as long as it's not unrecoverable error. The TBROK status is only for cases where something went really wrong and we cannot continue.
Quoted 7 lines
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c line 147
Quoted 5 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +5
-0+static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +umount2 (Hopt,MNT_DETACH );We whould umount here only if we actually have mounted something.
Quoted 7 lines
umount only, will require explicit unmap when test fails or break. For
that, all the local variable for address mapping will have to be static defined so that they can be accessed incleanup()function.I tried to avoid it by using umount2 which eventually umount when process unmaps all the mappings after it finishes.
That's not what I meant, as long as you pass Hopt on a commandline the test shoud not attempt to umount it at all.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge
Hi Cyril,
Quoted 23 lines · Cyril Hrubis
Quoted 14 lines
-- skip
Quoted 5 lines
Quoted 5 lines
(quoted diff) +1
-0+ p = SAFE_MMAP(hugemap_addr, hpage_size,PROT_READ|PROT_WRITE,
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +3
-0+ MAP_PRIVATE|MAP_FIXED, fd, 0); +if (p != hugemap_addr) { + tst_res(TFAIL, "mmap() at unexpected address %pQuoted 8 lines
Review
Quoted 4 lines
instead
of %p\n", p,(quoted diff) +2
-0+ hugemap_addr); + goto fail;Can we just do return here instead. The failure has been reported there
is no point in callingtst_brk(TBROK, ...)as well.Quoted 8 lines
When we run one iteration only,
tst_brkdoes not make sense, I agree.
But if we are running more than one iteration (i >= 2), test should not continue to next iteration if the current iteration fails.
Only way I could find is to use tst_brk(TBROK,... , as tst_brk(TFAIl...
is deprecated.
Quoted 4 lines
I do not see why we should abort on first failure as long as it's not unrecoverable error. The TBROK status is only for cases where something
went really wrong and we cannot continue.
Understood. I have removed it & updated your suggestions here
https://lore.kernel.org/all/[email protected]/
Here, I posted same patches in small batch (only 3 at first) based on suggestion given by Richard.
Quoted 13 lines
Quoted 13 lines
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c line 147
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +5
-0+static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +umount2 (Hopt,MNT_DETACH );We whould umount here only if we actually have mounted something.
umount only, will require explicit unmap when test fails or break. For
that, all the local variable for address mapping will have to be static defined so that they can be accessed incleanup()function.
Quoted 5 lines
Quoted 2 lines
I tried to avoid it by using umount2 which eventually umount when process unmaps all the mappings after it finishes.
That's not what I meant, as long as you pass Hopt on a commandline the test shoud not attempt to umount it at all.
Hopt is supposed to be the location which test will use to mount/umount the hugetlbfs fs. If Hopt is not provided, it will create a temp location. It is only to avoid creating any temporary locations outside user concerned test environment.
if(!Hopt)
Hopt = tst_get_tmpdir();
SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);It is not expecting any already mounted hugetlbfs. Please, check
https://lore.kernel.org/all/20221019184846.89318-1-
[email protected]/
for updated patch.
Thanks,
Tarun
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge
Hi!
Quoted 10 lines
Hopt is supposed to be the location which test will use to mount/umount the hugetlbfs fs. If Hopt is not provided, it will create a temp location. It is only to avoid creating any temporary locations outside user concerned test environment.
if(!Hopt) Hopt = tst_get_tmpdir(); SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);It is not expecting any already mounted hugetlbfs.
Ah right, this has been changed long ago in:
7420ed0 hugemmap04: auto mount the temporary dir for testing c4dd870 hugemmap03: auto mount the temporary dir for testing 9b4865f hugemmap02: auto mount the temporary dir for testing d8728dc hugemmap01: auto mount the temporary dir for testing
Before that the path had to point to already mounted hugetlbfs. At this point this option is useless. So I would not add it to new tests at all and just use the tmpdir unconditionally.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge
In reply to Tarun Sahutestcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c line 133
Quoted 6 lines · Tarun Sahu
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +5
-0+ +static void setup (void ) +{ +if (tst_hugepages <1 ) +tst_brk (TCONF ,"Not enough hugepages for testing." );
If we needs at least 1 huge page for testing, the TST_NEEDS will be more useful than TST_REQUEST, and do not need to double check the hpage numbers anymore.
TST_REQUEST:
It will try the best to reserve available huge pages and return the number of available hugepages in tst_hugepages, which may be 0 if hugepages are not supported at all.
TST_NEEDS:
This is an enforced requirement, LTP should strictly do hpages applying
and
guarantee the 'HugePages_Free' no less than pages which makes that test
can
use these specified numbers correctly. Otherwise, test exits with TCONF if the attempt to reserve hugepages fails or reserves less than requested.
See:
https://github.com/linux-test-project/ltp/blob/master/doc/c-test-api.txt#L2009
Quoted 27 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +6
-0+ +if (!Hopt) + Hopt =tst_get_tmpdir (); +SAFE_MOUNT ("none" , Hopt,"hugetlbfs" ,0 ,NULL ); + + snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt,
getpid());testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +16
-0+ hpage_size =SAFE_READ_MEMINFO ("Hugepagesize:" )*1024 ; +} + +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +umount2 (Hopt,MNT_DETACH ); +} + +static struct tst_test test = { + .needs_root =1 , + .needs_tmpdir =1 , + .options = (struct tst_option []) { + {"v" , &verbose,"Turns on verbose mode" }, + {"H:", &Hopt, "Location of hugetlbfs, i.e. -H
/var/hugetlbfs"},
+ {"s:",&nr_opt, "Set the number of the been allocated
hugepages"},
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c line 162
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +6
-0+ {} + }, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {1, TST_REQUEST},
^ TST_NEEDS
Quoted 2 lines
+};
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge
Hi Li,
Thanks for reviewing the patch.
I will update it to TST_NEEDS
wherever required in other tests
too. Thanks for pointing it.
Quoted 79 lines · Li Wang
This Message Is From an External Sender
This message came from outside your organization.Quoted 6 lines · Tarun Sahu
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +5
-0+ +static void setup (void ) +{ +if (tst_hugepages <1 ) + tst_brk(TCONF, "Not enough hugepages fortesting.");
If we needs at least 1 huge page for testing, the
TST_NEEDSwill be more useful thanTST_REQUEST, and do not need to double check the hpage numbers anymore.
TST_REQUEST:
It will try the best to reserve available huge pages and return the
number
of available hugepages intst_hugepages, which may be 0 if
hugepages are
not supported at all.
TST_NEEDS:
This is an enforced requirement, LTP should strictly do hpages
applying and
guarantee the 'HugePages_Free' no less than pages which makes that
test can
use these specified numbers correctly. Otherwise, test exits with
TCONF if
the attempt to reserve hugepages fails or reserves less than
requested.See:
https://github.com/linux-test-project/ltp/blob/master/doc/c-test-api.txt#L2009Quoted 26 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +6
-0+ +if (!Hopt) + Hopt =tst_get_tmpdir (); +SAFE_MOUNT ("none" , Hopt,"hugetlbfs" ,0 ,NULL ); + + snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d",Hopt,
getpid());testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +16
-0+ hpage_size =SAFE_READ_MEMINFO ("Hugepagesize:" )*1024 ; +} + +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +umount2 (Hopt,MNT_DETACH ); +} + +static struct tst_test test = { + .needs_root =1 , + .needs_tmpdir =1 , + .options = (struct tst_option []) { + {"v" , &verbose,"Turns on verbose mode" }, + {"H:", &Hopt, "Location of hugetlbfs, i.e. -H
/var/hugetlbfs"},
+ {"s:",&nr_opt, "Set the number of the been
allocated hugepages"},testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c line 162
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +6
-0+ {} + }, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {1, TST_REQUEST},^
TST_NEEDSQuoted 1 line
+};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/29 Hugetlb: Migrating libhugetlbfs chunk-overcommit
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/chunk-overcommit.c test
Test Description: Some kernel versions after hugepage demand allocation was added used a dubious heuristic to check if there was enough hugepage space available for a given mapping. The number of not-already-instantiated pages in the mapping was compared against the total hugepage free pool. It was very easy to confuse this heuristic into overcommitting by allocating hugepage memory in chunks, each less than the total available pool size but together more than available. This would generally lead to OOM SIGKILLs of one process or another when it tried to instantiate pages beyond the available pool.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap08.c | 173 ++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c
runtest/hugetlb +1 -0
@@ -4,6 +4,7 @@ hugemmap04 hugemmap04 hugemmap05 hugemmap05 hugemmap06 hugemmap06 hugemmap07 hugemmap07 +hugemmap08 hugemmap08 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -5,6 +5,7 @@ /hugetlb/hugemmap/hugemmap05 /hugetlb/hugemmap/hugemmap06 /hugetlb/hugemmap/hugemmap07 +/hugetlb/hugemmap/hugemmap08 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +173 -0
173 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/29] Hugetlb: Migrating libhugetlbfs chunk-overcommit
Hi!
Quoted 53 lines
Test Description: Some kernel versions after hugepage demand allocation was added used a dubious heuristic to check if there was enough hugepage space available for a given mapping. The number of not-already-instantiated pages in the mapping was compared against the total hugepage free pool. It was very easy to confuse this heuristic into overcommitting by allocating hugepage memory in chunks, each less than the total available pool size but together more than available. This would generally lead to OOM SIGKILLs of one process or another when it tried to instantiate pages beyond the available pool.
Signed-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap08.c | 173 ++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.cruntest/hugetlb +1
-0@@ -4,6 +4,7 @@ hugemmap04 hugemmap04 hugemmap05 hugemmap05 hugemmap06 hugemmap06 hugemmap07 hugemmap07 +hugemmap08 hugemmap08 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -5,6 +5,7 @@ /hugetlb/hugemmap/hugemmap05 /hugetlb/hugemmap/hugemmap06 /hugetlb/hugemmap/hugemmap07 +/hugetlb/hugemmap/hugemmap08 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +5
-0@@ -0,0 +1,173 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation. +* +* Test Name: Chunk Overcommit
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c line 15
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +10
-0+* +* Test Description: Some kernel versions after hugepage demand allocation was +* added used a dubious heuristic to check if there was enough hugepage space +* available for a given mapping. The number of not-already-instantiated pages +* in the mapping was compared against the total hugepage free pool. It was +* very easy to confuse this heuristic into overcommitting by allocating +* hugepage memory in chunks, each less than the total available pool size but +* together more than available. This would generally lead to OOM SIGKILLs of +* one process or another when it tried to instantiate pages beyond the +* available pool.
Here as well.
Quoted 39 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +39
-0+* HISTORY +* Written by David Gibson & Adam Litke +* +*/ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <sys/mount.h> +#include <limits.h> +#include <sys/param.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <signal.h> + +#include "hugetlb.h" + +#define PROC_OVERCOMMIT "/proc/sys/vm/nr_overcommit_hugepages" +#define WITH_OVERCOMMIT 0 +#define WITHOUT_OVERCOMMIT 1 + +static char *verbose; +static char hfile[MAXPATHLEN ]; +static int fd =-1 ; +static long hpage_size; + +static void test_chunk_overcommit (void ) +{ +unsigned long totpages, chunk1, chunk2; +void *p, *q; +pid_t child; +int status; + + totpages =SAFE_READ_MEMINFO ("HugePages_Free:" ); + + fd =SAFE_OPEN (hfile,O_RDWR |O_CREAT ,0600 ); +SAFE_UNLINK (hfile); + + chunk1 = (totpages /2 ) +1 ;
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c line 65
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +10
-0+ chunk2 = totpages - chunk1 +1 ; + +if (verbose) +tst_res (TINFO ,"overcommit: %ld hugepages available: " +"chunk1=%ld chunk2=%ld" , totpages, chunk1, chunk2); + + p =SAFE_MMAP (NULL , chunk1*hpage_size,PROT_READ |PROT_WRITE ,MAP_SHARED , + fd,0 ); + +/* Can't use SAFE_MMAP here, as test needs to process the output of mmap */
No comments like this plase.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c line 71
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +6
-0+ q =mmap (NULL , chunk2*hpage_size,PROT_READ |PROT_WRITE ,MAP_SHARED , + fd, chunk1*hpage_size); +if (q ==MAP_FAILED ) { +if (errno !=ENOMEM ) { +tst_res (TFAIL |TERRNO ,"mmap() chunk2" ); + goto fail;
Again just return here. In case of cleanup below it should be:
goto cleanup1;
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c line 74
Quoted 3 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +3
-0+ }else { +tst_res (TPASS ,"Successful without overcommit pages" ); + goto pass;
If you want to use kernel-like goto cleanup do it at least properly as:
} else {
tst_res(TPASS, "Successful without overcommit pages");
goto cleanup1;
}
...cleanup2:
SAFE_MUNMAP(q); cleanup1: SAFE_MUNMAP(p); cleanup0: SAFE_CLOSE(fd); }
Quoted 12 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +12
-0+ } + } + +if (verbose) +tst_res (TINFO ,"Looks like we've overcommitted, testing..." ); +/* Looks like we're overcommited, but we need to confirm that +* this is bad. We touch it all in a child process because an +* overcommit will generally lead to a SIGKILL which we can't +* handle, of course. +*/ + child =SAFE_FORK (); +
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c line 96
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +10
-0+if (child ==0 ) { +memset (p,0 , chunk1*hpage_size); +memset (q,0 , chunk2*hpage_size); +exit (0 ); + } + +SAFE_WAITPID (child, &status,0 ); + +if (WIFSIGNALED (status)) { + tst_res(TFAIL, "Killed by signal \"%s\" due to overcommit",
^ Single quotes ('') here plase
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c line 97
Quoted 1 line
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +1
-0+ strsignal(WTERMSIG(status)));
^
Please use tst_strsig()
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c line 97
Quoted 1 line
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +1
-0+ goto fail;
Here as well.
Quoted 9 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +9
-0+ } + +tst_res (TPASS ,"Successful with overcommit pages" ); + +pass: +SAFE_MUNMAP (p, chunk1*hpage_size); +if (q && q !=MAP_FAILED ) +SAFE_MUNMAP (q, chunk2*hpage_size); +SAFE_CLOSE (fd);
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c line 117
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +10
-0+return ; +fail: +tst_brk (TBROK ,"Once failed, No point in continuing the test" ); +} + +static void run_test (unsigned int test_type) +{ +long saved_oc_hugepages; + +SAFE_FILE_LINES_SCANF (PROC_OVERCOMMIT ,"%ld" , &saved_oc_hugepages);
This is wrong function, the LINES_SCANF function is supposed to be used for files that have more than one line. For this case SAFE_FILE_SCANF() should be used instead.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c line 122
Quoted 5 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +5
-0+switch (test_type) { +case WITH_OVERCOMMIT : +if (saved_oc_hugepages >0 ) +SAFE_FILE_PRINTF (PROC_OVERCOMMIT ,"%d" ,0 ); +break ;
This case says WITH_OVERCOMMIT but we disable the overcommit by writing 0?
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c line 126
Quoted 4 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +4
-0+case WITHOUT_OVERCOMMIT : +if (saved_oc_hugepages <0 ) +tst_brk (TCONF ,"Kernel appears to lack dynamic hugetlb pool " +"support" );
I do not think that saved_oc_hugepages can even be < 0, kernel handles the number as long unsigned.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c line 132
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +6
-0+else if (saved_oc_hugepages ==0 ) +SAFE_FILE_PRINTF (PROC_OVERCOMMIT ,"%d" ,2 ); +break ; +default : +tst_brk (TCONF ,"Not a proper test type" ); +break ;
This never happens, there is no need to handle this case.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c line 133
Quoted 2 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +2
-0+ } +test_chunk_overcommit ();
And the PROC_OVERCOMMIT should be properly restored after the test. Ideally by setting up .save_restore field in tst_test structure.
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +10
-0+} + +static void setup (void ) +{ +if (tst_hugepages <3 ) +tst_brk (TCONF ,"Not enough hugepages for testing." ); + +if (!Hopt) + Hopt =tst_get_tmpdir (); +SAFE_MOUNT ("none" , Hopt,"hugetlbfs" ,0 ,NULL );
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c line 154
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +10
-0+ +snprintf (hfile,sizeof (hfile),"%s/ltp_huetlbfile%d" , Hopt,getpid ()); + hpage_size =SAFE_READ_MEMINFO ("Hugepagesize:" )*1024 ; +} + +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +umount2 (Hopt,MNT_DETACH );
Here as well.
Quoted 25 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +19
-0+} + +static struct tst_test test = { + .needs_root =1 , + .needs_tmpdir =1 , + .forks_child =1 , + .options = (struct tst_option []) { + {"v" , &verbose,"Turns on verbose mode" }, + {"H:" , &Hopt,"Location of hugetlbfs, i.e. -H /var/hugetlbfs" }, + {"s:" , &nr_opt,"Set the number of the been allocated hugepages" }, + {} + }, + .tcnt =2 , + .setup = setup, + .cleanup = cleanup, + .test = run_test, + .hugepages = {5 ,TST_REQUEST }, +}; +Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 3/29 Hugetlb: Migrating libhugetlbfs corrupt-by-cow-opt
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/corrupt-by-cow-opt.c test
Test Description: Test sanity of cow optimization on page cache. If a page in page cache has only 1 ref count, it is mapped for a private mapping directly and is overwritten freely, so next time we access the page, we can see corrupt data.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap09.c | 102 ++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c
runtest/hugetlb +1 -0
@@ -5,6 +5,7 @@ hugemmap05 hugemmap05 hugemmap06 hugemmap06 hugemmap07 hugemmap07 hugemmap08 hugemmap08 +hugemmap09 hugemmap09 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -6,6 +6,7 @@ /hugetlb/hugemmap/hugemmap06 /hugetlb/hugemmap/hugemmap07 /hugetlb/hugemmap/hugemmap08 +/hugetlb/hugemmap/hugemmap09 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c new file +102 -0
102 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/29] Hugetlb: Migrating libhugetlbfs corrupt-by-cow-opt
Hi!
Quoted 45 lines
Migrating the
libhugetlbfs/testcases/corrupt-by-cow-opt.ctestTest Description: Test sanity of cow optimization on page cache. If a page in page cache has only 1 ref count, it is mapped for a private mapping directly and is overwritten freely, so next time we access the page, we can see corrupt data.
Signed-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap09.c | 102 ++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.cruntest/hugetlb +1
-0@@ -5,6 +5,7 @@ hugemmap05 hugemmap05 hugemmap06 hugemmap06 hugemmap07 hugemmap07 hugemmap08 hugemmap08 +hugemmap09 hugemmap09 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -6,6 +6,7 @@ /hugetlb/hugemmap/hugemmap06 /hugetlb/hugemmap/hugemmap07 /hugetlb/hugemmap/hugemmap08 +/hugetlb/hugemmap/hugemmap09 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c new file +0
-0
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c line 10
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c new file +10
-0@@ -0,0 +1,102 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2013 Joonsoo Kim, LG Electronics. +* +* Test Name: Corrupt by COW optimization +* +* Test Description: Test sanity of cow optimization on page cache. If a page +* in page cache has only 1 ref count, it is mapped for a private mapping +* directly and is overwritten freely, so next time we access the page, we +* can see corrupt data.
Here as well.
Quoted 16 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c new file +16
-0+* HISTORY +* Written by Joonsoo Kim +* +*/ + +#define _GNU_SOURCE +#include <stdio.h> +#include <sys/mount.h> +#include <limits.h> +#include <sys/param.h> +#include <sys/types.h> + +#include "hugetlb.h" + +static char *verbose; +static int fd =-1 ;
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c line 37
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c new file +10
-0+static char hfile[MAXPATHLEN ]; +static long hpage_size; + +static void run_test (void ) +{ +char *p; +char c; + + fd =SAFE_OPEN (hfile,O_RDWR |O_CREAT ,0600 ); +SAFE_UNLINK (hfile);
This SAFE_OPEN() and SAFE_UNLINK() should be in setup()
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c new file +7
-0+ p =SAFE_MMAP (NULL , hpage_size,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 ); + *p ='s' ; +if (verbose) +tst_res (TINFO ,"Write %c to %p via shared mapping" , *p, p); +SAFE_MUNMAP (p, hpage_size); + + p =SAFE_MMAP (NULL , hpage_size,PROT_READ |PROT_WRITE ,MAP_PRIVATE , fd,0 );
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c line 55
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c new file +10
-0+ *p ='p' ; +if (verbose) +tst_res (TINFO ,"Write %c to %p via private mapping" , *p, p); +SAFE_MUNMAP (p, hpage_size); + + p =SAFE_MMAP (NULL , hpage_size,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 ); + c = *p; +if (verbose) +tst_res (TINFO ,"Read %c from %p via shared mapping" , *p, p); +SAFE_MUNMAP (p, hpage_size);
Also I'm not keen on the verbose flag, I would just print these messages by default. It does not make sense to have verbose flag because in practice it's not enabled on production testing and these days we got reports from various automated systems so we better include anything useful by default.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c line 62
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c new file +6
-0+/* Direct write from huge page */ +if (c !='s' ) { +tst_res (TFAIL ,"Data got corrupted." ); + goto fail; + } +tst_res (TPASS ,"Successful" );
Here the cleanest code would just be:
if (c != 's') tst_res(TFAIL, "Data are corrupted"); else tst_res(TPASS, "Data are correct");
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c line 60
Quoted 1 line
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c new file +1
-0+SAFE_CLOSE (fd);
And this SAFE_CLOSE() is already in cleanup() so we just need to move the SAFE_OPEN() into the setup() and remove this one.
Quoted 13 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c new file +13
-0+return ; +fail: +tst_brk (TBROK ,"Once failed, No point in continuing the test" ); +} + +static void setup (void ) +{ +if (tst_hugepages <2 ) +tst_brk (TCONF ,"Not enough hugepages for testing." ); + +if (!Hopt) + Hopt =tst_get_tmpdir (); +SAFE_MOUNT ("none" , Hopt,"hugetlbfs" ,0 ,NULL );
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c line 86
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c new file +10
-0+ +snprintf (hfile,sizeof (hfile),"%s/ltp_hugetlbfile%d" , Hopt,getpid ()); + hpage_size =SAFE_READ_MEMINFO ("Hugepagesize:" )*1024 ; +} + +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +umount2 (Hopt,MNT_DETACH );
Here as well, umount only what was mounted.
Quoted 22 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c new file +16
-0+} + +static struct tst_test test = { + .needs_root =1 , + .needs_tmpdir =1 , + .options = (struct tst_option []) { + {"v" , &verbose,"Turns on verbose mode" }, + {"H:" , &Hopt,"Location of hugetlbfs, i.e. -H /var/hugetlbfs" }, + {"s:" , &nr_opt,"Set the number of the been allocated hugepages" }, + {} + }, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {2 ,TST_REQUEST }, +};Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 4/29 Hugetlb: Migrating libhugetlbfs counters
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/counters.c test
Test Description: This Test perform mmap and unmap and write operation on hugetlb file based mapping. Mapping can be shared or private. and it checks for Hugetlb counter (Total, Free, Reserve, Surplus) in /proc/meminfo and compare them with expected (calculated) value. if all checks are successful, the test passes.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap10.c | 475 ++++++++++++++++++ 3 files changed, 477 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c
runtest/hugetlb +1 -0
@@ -6,6 +6,7 @@ hugemmap06 hugemmap06 hugemmap07 hugemmap07 hugemmap08 hugemmap08 hugemmap09 hugemmap09 +hugemmap10 hugemmap10 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -7,6 +7,7 @@ /hugetlb/hugemmap/hugemmap07 /hugetlb/hugemmap/hugemmap08 /hugetlb/hugemmap/hugemmap09 +/hugetlb/hugemmap/hugemmap10 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +475 -0
475 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/29] Hugetlb: Migrating libhugetlbfs counters
Hi!
Quoted 39 lines
Signed-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap10.c | 475 ++++++++++++++++++ 3 files changed, 477 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.cruntest/hugetlb +1
-0@@ -6,6 +6,7 @@ hugemmap06 hugemmap06 hugemmap07 hugemmap07 hugemmap08 hugemmap08 hugemmap09 hugemmap09 +hugemmap10 hugemmap10 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -7,6 +7,7 @@ /hugetlb/hugemmap/hugemmap07 /hugetlb/hugemmap/hugemmap08 /hugetlb/hugemmap/hugemmap09 +/hugetlb/hugemmap/hugemmap10 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +1
-0@@ -0,0 +1,475 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 11
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +10
-0+/* +* Copyright (C) 2005-2007 David Gibson & Adam Litke, IBM Corporation. +* +* Test Name: Counters +* +* Test Description: This Test perform mmap and unmap and write operation on +* hugetlb file based mapping. Mapping can be shared or private. and it checks +* for Hugetlb counter (Total, Free, Reserve, Surplus) in /proc/meminfo and +* compare them with expected (calculated) value. if all checks are successful, +* the test passes.
Here as well.
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +7
-0+* HISTORY +* Written by David Gibson & Adam Litke +* +*/ + +#define _GNU_SOURCE +#include <unistd.h>
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 29
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +10
-0+#include <stdio.h> +#include <sys/mount.h> +#include <limits.h> +#include <sys/param.h> +#include <sys/types.h> + +#include "hugetlb.h" + + +/* Global test configuration */
Please no useless comments like this one.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 33
Quoted 4 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +4
-0+#define PROC_NR_HUGEPAGES "/proc/sys/vm/nr_hugepages" +#define PROC_OVERCOMMIT "/proc/sys/vm/nr_overcommit_hugepages" +static long saved_nr_hugepages =-1 ; +static long saved_oc_hugepages =-1 ;
The two proc files should be saved and restored by the .save_restore array in the tst_test structure.
Quoted 12 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +12
-0+static long hpage_size; +static int private_resv; +static char *verbose; + +/* State arrays for our mmaps */ +#define NR_SLOTS 2 +#define SL_SETUP 0 +#define SL_TEST 1 +static char hfile[NR_SLOTS ][MAXPATHLEN ]; +static int map_fd[NR_SLOTS ]; +static char *map_addr[NR_SLOTS ]; +static unsigned long map_size[NR_SLOTS ];
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 55
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +10
-0+static unsigned int touched[NR_SLOTS ]; + +/* Keep track of expected counter values */ +static long prev_total; +static long prev_free; +static long prev_resv; +static long prev_surp; + +#define min (a, b) (((a) < (b)) ? (a) : (b)) +#define max (a, b) (((a) > (b)) ? (a) : (b))
We already have MIN() and MAX() defined in LTP, use them, do not reinvent the wheel.
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +6
-0+static void read_meminfo_huge (long *total,long *free,long *resv,long *surp) +{ + *total =SAFE_READ_MEMINFO ("HugePages_Total:" ); + *free =SAFE_READ_MEMINFO ("HugePages_Free:" ); + *resv =SAFE_READ_MEMINFO ("HugePages_Rsvd:" ); + *surp =SAFE_READ_MEMINFO ("HugePages_Surp:" );
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 72
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +10
-0+} + +static int kernel_has_private_reservations (void ) +{ +int fd; +long t, f, r, s; +long nt, nf, nr, ns; +void *map; + +/* Read pool counters */
Here again, useless comment.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 79
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +7
-0+read_meminfo_huge (&t, &f, &r, &s); + + fd =SAFE_OPEN (hfile[0 ],O_RDWR |O_CREAT ,0600 ); +SAFE_UNLINK (hfile[0 ]); + map =SAFE_MMAP (NULL , hpage_size,PROT_READ |PROT_WRITE ,MAP_PRIVATE , fd,0 ); + +/* Recheck the counters */
And here too.
Quoted 15 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +15
-0+read_meminfo_huge (&nt, &nf, &nr, &ns); + +SAFE_MUNMAP (map, hpage_size); +SAFE_CLOSE (fd); + +/* +* There are only three valid cases: +* 1) If a surplus page was allocated to create a reservation, all +* four pool counters increment +* 2) All counters remain the same except for Hugepages_Rsvd, then +* a reservation was created using an existing pool page. +* 3) All counters remain the same, indicates that no reservation has +* been created +*/ +if ((nt == t +1 ) && (nf == f +1 ) && (ns == s +1 ) && (nr == r +1 )) {
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 104
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +10
-0+return 1 ; + }else if ((nt == t) && (nf == f) && (ns == s)) { +if (nr == r +1 ) +return 1 ; +else if (nr == r) +return 0 ; + }else { +tst_brk (TCONF ,"%s: bad counter state - " +"T:%li F:%li R:%li S:%li -> T:%li F:%li R:%li S:%li\n" , + __func__, t, f, r, s, nt, nf, nr, ns);
There is absolutely no reason to print __func__ all the tst_* reporting function print filename and linenumber already.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 115
Quoted 11 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +11
-0+ } +return -1 ; +} + +static void bad_value (int line,const char *name,long expect,long actual) +{ +tst_res (TFAIL ,"Failure Line %i: Bad %s: expected %li, actual %li" , + line, name, expect, actual); +tst_brk (TBROK ,"Breaking.. as once one of counter is not expected, " +"it will cause other failure anyway" ); +}
Never ever create wrappers around result reporting functions like this. This break the best feature these function have, i.e. they print file and line number where the problem has happenend.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 125
Quoted 9 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +9
-0+static void verify_counters (int line,long et,long ef,long er,long es) +{ +long t, f, r, s; + +/* Read pool counters */ +read_meminfo_huge (&t, &f, &r, &s); + +if (f < r) +tst_res (TWARN ,"HugePages_Free < HugePages_Rsvd" );
Why exactly do we warn here?
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 138
Quoted 12 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +12
-0+/* Check actual values against expected values */ +if (t != et) +bad_value (line,"HugePages_Total" , et, t); + +if (f != ef) +bad_value (line,"HugePages_Free" , ef, f); + +if (r != er) +bad_value (line,"HugePages_Rsvd" , er, r); + +if (s != es) +bad_value (line,"HugePages_Surp" , es, s);
We do have rather nice macros exactly for this TST_EXP_EQ_LI() that would work nicely as long as you name the variables with something more reasonable than a single character.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 150
Quoted 11 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +11
-0+/* Everything's good. Update counters */ + prev_total = t; + prev_free = f; + prev_resv = r; + prev_surp = s; +} + +/* Memory operations: +* Each of these has a predefined effect on the counters +*/ +#define persistent_huge_pages (et - es)
Just NO. Argument-less macros that use local variables like this are nightmare.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 151
Quoted 1 line
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +1
-0+static void _set_nr_hugepages (long count,int line)
Identifiers starting with underscore are reserved in C, don't use them.
Quoted 37 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +37
-0+{ +long min_size; +long et, ef, er, es; + +SAFE_FILE_PRINTF (PROC_NR_HUGEPAGES ,"%lu" , count); + +/* The code below is based on set_max_huge_pages in mm/hugetlb.c */ + es = prev_surp; + et = prev_total; + ef = prev_free; + er = prev_resv; + +/* +* Increase the pool size +* First take pages out of surplus state. Then make up the +* remaining difference by allocating fresh huge pages. +*/ +while (es && count > persistent_huge_pages) + es--; +while (count > persistent_huge_pages) { + et++; + ef++; + } +if (count >= persistent_huge_pages) + goto out; + +/* +* Decrease the pool size +* First return free pages to the buddy allocator (being careful +* to keep enough around to satisfy reservations). Then place +* pages into surplus state as needed so the pool will shrink +* to the desired size as pages become free. +*/ + min_size =MAX (count, er + et - ef); +while (min_size < persistent_huge_pages) { + ef--; + et--;
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 198
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +10
-0+ } +while (count < persistent_huge_pages) + es++; + +out: +verify_counters (line, et, ef, er, es); +} +#define set_nr_hugepages (c) _set_nr_hugepages(c, __LINE__) + +static void _map (int s,int hpages,int flags,int line)
Here ase well.
Quoted 32 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +32
-0+{ +long et, ef, er, es; + + map_fd[s] =SAFE_OPEN (hfile[s],O_RDWR |O_CREAT ,0600 ); +SAFE_UNLINK (hfile[s]); + map_size[s] = hpages * hpage_size; + map_addr[s] =SAFE_MMAP (NULL , map_size[s],PROT_READ |PROT_WRITE , flags, + map_fd[s],0 ); + touched[s] =0 ; + + et = prev_total; + ef = prev_free; + er = prev_resv; + es = prev_surp; + +/* +* When using MAP_SHARED, a reservation will be created to guarantee +* pages to the process. If not enough pages are available to +* satisfy the reservation, surplus pages are added to the pool. +* NOTE: This code assumes that the whole mapping needs to be +* reserved and hence, will not work with partial reservations. +* +* If the kernel supports private reservations, then MAP_PRIVATE +* mappings behave like MAP_SHARED at mmap time. Otherwise, +* no counter updates will occur. +*/ +if ((flags &MAP_SHARED ) || private_resv) { +unsigned long shortfall =0 ; + +if (hpages + prev_resv > prev_free) + shortfall = hpages - prev_free + prev_resv; + et += shortfall;
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 240
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +10
-0+ ef = prev_free + shortfall; + er = prev_resv + hpages; + es = prev_surp + shortfall; + } + +verify_counters (line, et, ef, er, es); +} +#define map (s, h, f) _map(s, h, f, __LINE__) + +static void _unmap (int s,int hpages,int flags,int line)
And here.
Quoted 37 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +37
-0+{ +long et, ef, er, es; +unsigned long i; + +SAFE_MUNMAP (map_addr[s], map_size[s]); +SAFE_CLOSE (map_fd[s]); + map_addr[s] =NULL ; + map_size[s] =0 ; + + et = prev_total; + ef = prev_free; + er = prev_resv; + es = prev_surp; + +/* +* When a VMA is unmapped, the instantiated (touched) pages are +* freed. If the pool is in a surplus state, pages are freed to the +* buddy allocator, otherwise they go back into the hugetlb pool. +* NOTE: This code assumes touched pages have only one user. +*/ +for (i =0 ; i < touched[s]; i++) { +if (es) { + et--; + es--; + }else + ef++; + } + +/* +* mmap may have created some surplus pages to accommodate a +* reservation. If those pages were not touched, then they will +* not have been freed by the code above. Free them here. +*/ +if ((flags &MAP_SHARED ) || private_resv) { +int unused_surplus =MIN (hpages - touched[s], es); + + et -= unused_surplus;
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 287
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +10
-0+ ef -= unused_surplus; + er -= hpages - touched[s]; + es -= unused_surplus; + } + +verify_counters (line, et, ef, er, es); +} +#define unmap (s, h, f) _unmap(s, h, f, __LINE__) + +static void _touch (int s,int hpages,int flags,int line)
And here.
Quoted 102 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +102
-0+{ +long et, ef, er, es; +int nr; +char *c; + +for (c = map_addr[s], nr = hpages; + hpages && c < map_addr[s] + map_size[s]; + c += hpage_size, nr--) + *c = (char ) (nr %2 ); +/* +* Keep track of how many pages were touched since we can't easily +* detect that from user space. +* NOTE: Calling this function more than once for a mmap may yield +* results you don't expect. Be careful :) +*/ + touched[s] =MAX (touched[s], hpages); + +/* +* Shared (and private when supported) mappings and consume resv pages +* that were previously allocated. Also deduct them from the free count. +* +* Unreserved private mappings may need to allocate surplus pages to +* satisfy the fault. The surplus pages become part of the pool +* which could elevate total, free, and surplus counts. resv is +* unchanged but free must be decreased. +*/ +if (flags &MAP_SHARED || private_resv) { + et = prev_total; + ef = prev_free - hpages; + er = prev_resv - hpages; + es = prev_surp; + }else { +if (hpages + prev_resv > prev_free) + et = prev_total + (hpages - prev_free + prev_resv); +else + et = prev_total; + er = prev_resv; + es = prev_surp + et - prev_total; + ef = prev_free - hpages + et - prev_total; + } +verify_counters (line, et, ef, er, es); +} +#define touch (s, h, f) _touch(s, h, f, __LINE__) + +static void test_counters (char *desc,int base_nr) +{ +if (verbose) +tst_res (TINFO ,"%s..." , desc); +set_nr_hugepages (base_nr); + +/* untouched, shared mmap */ +map (SL_TEST ,1 ,MAP_SHARED ); +unmap (SL_TEST ,1 ,MAP_SHARED ); + +/* untouched, private mmap */ +map (SL_TEST ,1 ,MAP_PRIVATE ); +unmap (SL_TEST ,1 ,MAP_PRIVATE ); + +/* touched, shared mmap */ +map (SL_TEST ,1 ,MAP_SHARED ); +touch (SL_TEST ,1 ,MAP_SHARED ); +unmap (SL_TEST ,1 ,MAP_SHARED ); + +/* touched, private mmap */ +map (SL_TEST ,1 ,MAP_PRIVATE ); +touch (SL_TEST ,1 ,MAP_PRIVATE ); +unmap (SL_TEST ,1 ,MAP_PRIVATE ); + +/* Explicit resizing during outstanding surplus */ +/* Consume surplus when growing pool */ +map (SL_TEST ,2 ,MAP_SHARED ); +set_nr_hugepages (max (base_nr,1 )); + +/* Add pages once surplus is consumed */ +set_nr_hugepages (max (base_nr,3 )); + +/* Release free huge pages first */ +set_nr_hugepages (max (base_nr,2 )); + +/* When shrinking beyond committed level, increase surplus */ +set_nr_hugepages (base_nr); + +/* Upon releasing the reservation, reduce surplus counts */ +unmap (SL_TEST ,2 ,MAP_SHARED ); +if (verbose) +tst_res (TINFO ,"OK" ); +} + +static void per_iteration_cleanup (void ) +{ +for (int nr =0 ; nr <NR_SLOTS ; nr++) { +if (map_fd[nr] >=0 ) +SAFE_CLOSE (map_fd[nr]); + } +if (hpage_size <=0 ) +return ; +if (saved_nr_hugepages >=0 ) +SAFE_FILE_PRINTF (PROC_NR_HUGEPAGES ,"%ld" , saved_nr_hugepages); +if (saved_oc_hugepages >=0 ) +SAFE_FILE_PRINTF (PROC_OVERCOMMIT ,"%ld" , saved_oc_hugepages); +} +
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 399
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +10
-0+static void run_test (void ) +{ +int base_nr =0 ; + + saved_nr_hugepages =SAFE_READ_MEMINFO ("HugePages_Total:" ); + +/* Verify Dynamic Pool support */ +SAFE_FILE_LINES_SCANF (PROC_OVERCOMMIT ,"%ld" , &saved_oc_hugepages); +if (saved_oc_hugepages <0 ) +tst_brk (TCONF ,"Kernel appears to lack dynamic hugetlb pool support" );
Again, this cannot happen at all.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 409
Quoted 9 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +9
-0+SAFE_FILE_PRINTF (PROC_OVERCOMMIT ,"%d" ,3 ); + + private_resv =kernel_has_private_reservations (); +/* +* This test case should require a maximum of 3 huge pages. +* Run through the battery of tests multiple times, with an increasing +* base pool size. This alters the circumstances under which surplus +* pages need to be allocated and increases the corner cases tested. +*/
Any verbose description like this should rather be part of the documentaiton comment.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 412
Quoted 3 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +3
-0+for (base_nr =0 ; base_nr <=3 ; base_nr++) { +if (verbose) +tst_res (TINFO ,"Base pool size: %i" , base_nr);
Again not very keen on the verbose flag.
Quoted 69 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +63
-0+/* Run the tests with a clean slate */ +test_counters ("Clean" , base_nr); + +/* Now with a pre-existing untouched, shared mmap */ +map (SL_SETUP ,1 ,MAP_SHARED ); +test_counters ("Untouched, shared" , base_nr); +unmap (SL_SETUP ,1 ,MAP_SHARED ); + +/* Now with a pre-existing untouched, private mmap */ +map (SL_SETUP ,1 ,MAP_PRIVATE ); +test_counters ("Untouched, private" , base_nr); +unmap (SL_SETUP ,1 ,MAP_PRIVATE ); + +/* Now with a pre-existing touched, shared mmap */ +map (SL_SETUP ,1 ,MAP_SHARED ); +touch (SL_SETUP ,1 ,MAP_SHARED ); +test_counters ("Touched, shared" , base_nr); +unmap (SL_SETUP ,1 ,MAP_SHARED ); + +/* Now with a pre-existing touched, private mmap */ +map (SL_SETUP ,1 ,MAP_PRIVATE ); +touch (SL_SETUP ,1 ,MAP_PRIVATE ); +test_counters ("Touched, private" , base_nr); +unmap (SL_SETUP ,1 ,MAP_PRIVATE ); + } +tst_res (TPASS ,"Hugepages Counters works as expected." ); +per_iteration_cleanup (); +} + +static void setup (void ) +{ +if (!Hopt) + Hopt =tst_get_tmpdir (); +SAFE_MOUNT ("none" , Hopt,"hugetlbfs" ,0 ,NULL ); +for (int nr =0 ; nr <NR_SLOTS ; nr++) { +snprintf (hfile[nr],sizeof (hfile[nr]),"%s/ltp_hugetlbfile%d_%d" , + Hopt,getpid (), nr); + } + + hpage_size =SAFE_READ_MEMINFO ("Hugepagesize:" )*1024 ; +} + +static void cleanup (void ) +{ +per_iteration_cleanup (); +umount2 (Hopt,MNT_DETACH ); +} + +static struct tst_test test = { + .needs_root =1 , + .needs_tmpdir =1 , + .options = (struct tst_option []) { + {"v" , &verbose,"Turns on verbose mode" }, + {"H:" , &Hopt,"Location of hugetlbfs, i.e. -H /var/hugetlbfs" }, + {"s:" , &nr_opt,"Set the number of the been allocated hugepages" }, + {} + }, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {0 ,TST_REQUEST }, +}; +Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 04/29] Hugetlb: Migrating libhugetlbfs counters
Hi,
I am now working on this test after recently posted series, Looking at your comments on this, I got the following question.
Quoted 12 lines · Cyril Hrubis
Hi!
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 115
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +7
-0+static void bad_value (int line,const char *name,long expect,long actual) +{ +tst_res (TFAIL ,"Failure Line %i: Bad %s: expected %li, actual %li" , + line, name, expect, actual); +tst_brk (TBROK ,"Breaking.. as once one of counter is not expected, " +"it will cause other failure anyway" ); +}Never ever create wrappers around result reporting functions like this. This break the best feature these function have, i.e. they print file and line number where the problem has happenend.
Sure will update it,
Quoted 13 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 125
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +9
-0+static void verify_counters (int line,long et,long ef,long er,long es) +{ +long t, f, r, s; + +/* Read pool counters */ +read_meminfo_huge (&t, &f, &r, &s); + +if (f < r) +tst_res (TWARN ,"HugePages_Free < HugePages_Rsvd" );Why exactly do we warn here?
Yeah, Will remove this check.
Quoted 8 lines
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +8
-0+/* Check actual values against expected values */ +if (t != et) +bad_value (line,"HugePages_Total" , et, t); + +if (f != ef) +bad_value (line,"HugePages_Free" , ef, f); + +if (r != er)
Quoted 9 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 138
Quoted 4 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +4
-0+bad_value (line,"HugePages_Rsvd" , er, r); + +if (s != es) +bad_value (line,"HugePages_Surp" , es, s);We do have rather nice macros exactly for this
TST_EXP_EQ_LI()that would work nicely as long as you name the variables with something more reasonable than a single character.
Q: TST_EXP_EQ_LI retuns with TPASS if counters matches. Only issue is these counters are getting checked around 4*4*95=(1520) times in the test. so to avoid printing PASS for so many times, I propse to avoid use of it and only print TFAIL in case of failure and exit with help of goto statements (because once counter are not expected, further checks will not matter as they will be checked again corrupted counter values). With this, PASS will be reported only once when all counters will be checked and test will will be finished without any failure.
Quoted 14 lines
Quoted 7 lines
Signature · 6 lines
-- 2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltpSignature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 04/29] Hugetlb: Migrating libhugetlbfs counters
In reply to Tarun Sahutestcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 378
Quoted 5 lines · Tarun Sahu
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +4
-0+ +static void per_iteration_cleanup (void ) +{ +for (int nr =0 ; nr <NR_SLOTS ; nr++) {
Here the for-loop usage is introduced from C99, we have to avoid definition in the loop to dismiss compiling broken on old compilers.
See:
https://github.com/wangli5665/ltp/actions/runs/3261830153/jobs/5357590260
+
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c line 447
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c new file +6
-0+static void setup (void ) +{ +if (!Hopt) + Hopt =tst_get_tmpdir (); +SAFE_MOUNT ("none" , Hopt,"hugetlbfs" ,0 ,NULL ); +for (int nr =0 ; nr <NR_SLOTS ; nr++) {
Here as well ^
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 5/29 Hugetlb: Migrating libhugetlbfs directio
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/direct.c test
Test Description: This Test perform Direct Write/Read from/To hugetlbfs file which is mapped to process address space. The test is checking if it succeeds and data written or read is not corrupted.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap11.c | 111 ++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c
runtest/hugetlb +1 -0
@@ -7,6 +7,7 @@ hugemmap07 hugemmap07 hugemmap08 hugemmap08 hugemmap09 hugemmap09 hugemmap10 hugemmap10 +hugemmap11 hugemmap11 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -8,6 +8,7 @@ /hugetlb/hugemmap/hugemmap08 /hugetlb/hugemmap/hugemmap09 /hugetlb/hugemmap/hugemmap10 +/hugetlb/hugemmap/hugemmap11 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c new file +111 -0
111 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 05/29] Hugetlb: Migrating libhugetlbfs directio
Hi!
Quoted 44 lines
Migrating the
libhugetlbfs/testcases/direct.ctestTest Description: This Test perform Direct Write/Read from/To hugetlbfs file which is mapped to process address space. The test is checking if it succeeds and data written or read is not corrupted.
Signed-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap11.c | 111 ++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.cruntest/hugetlb +1
-0@@ -7,6 +7,7 @@ hugemmap07 hugemmap07 hugemmap08 hugemmap08 hugemmap09 hugemmap09 hugemmap10 hugemmap10 +hugemmap11 hugemmap11 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -8,6 +8,7 @@ /hugetlb/hugemmap/hugemmap08 /hugetlb/hugemmap/hugemmap09 /hugetlb/hugemmap/hugemmap10 +/hugetlb/hugemmap/hugemmap11 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c new file +0
-0
testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c line 9
Quoted 9 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c new file +9
-0@@ -0,0 +1,111 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation. +* +* Test Name: Direct I/O +* +* Test Description: This Test perform Direct Write/Read from/To hugetlbfs file +* which is mapped to process address space. The test is checking if it +* succeeds and data written or read is not corrupted.
Here as well, documentation comment.
Quoted 9 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c new file +9
-0+* HISTORY +* Written by David Gibson & Adam Litke +* +*/ + +#define _GNU_SOURCE +#include <stdio.h> +#include <sys/mount.h> +#include <limits.h>
testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c line 29
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c new file +10
-0+#include <sys/param.h> +#include <sys/types.h> + +#include "hugetlb.h" + +#define P0 "ffffffff" +#define IOSZ 4096 +#define NHFILE "ltp_nfile" + +static char buf[IOSZ] __attribute__((aligned(IOSZ)));
There is no need for this buffer to be global.
Quoted 35 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c new file +35
-0+static int fd =-1 , nfd =-1 ; +static char hfile[MAXPATHLEN ]; +static long hpage_size; + +static void run_test (void ) +{ +void *p; + + fd =SAFE_OPEN (hfile,O_RDWR |O_CREAT ,0600 ); +SAFE_UNLINK (hfile); + + nfd =SAFE_OPEN (NHFILE ,O_CREAT |O_EXCL |O_RDWR |O_DIRECT ,0600 ); +SAFE_UNLINK (NHFILE ); + + p =SAFE_MMAP (NULL , hpage_size,PROT_READ |PROT_WRITE ,MAP_PRIVATE , fd,0 ); +memcpy (p,P0 ,8 ); + +/* Direct write from huge page */ +SAFE_WRITE (1 , nfd, p,IOSZ ); +SAFE_LSEEK (nfd,0 ,SEEK_SET ); + +/* Check for accuracy */ +SAFE_READ (1 , nfd, buf,IOSZ ); +if (memcmp (P0 , buf,8 )) { +tst_res (TFAIL ,"Memory mismatch after Direct-IO write" ); + goto fail; + } +SAFE_LSEEK (nfd,0 ,SEEK_SET ); + +/* Direct read to huge page */ +memset (p,0 ,IOSZ ); +SAFE_READ (1 , nfd, p,IOSZ ); + +/* Check for accuracy */ +if (memcmp (p,P0 ,8 )) {
testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c line 74
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c new file +10
-0+tst_res (TFAIL ,"Memory mismatch after Direct-IO read" ); + goto fail; + } +tst_res (TPASS ,"Successfully tested Hugepage Direct I/O" ); +SAFE_MUNMAP (p, hpage_size); +SAFE_CLOSE (fd); +SAFE_CLOSE (nfd); +return ; +fail: +tst_brk (TBROK ,"Once failed, No point in continuing the test" );
Here as well.
Quoted 12 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c new file +12
-0+} + +static void setup (void ) +{ +if (tst_hugepages <1 ) +tst_brk (TCONF ,"Not enough hugepages for testing." ); + +if (!Hopt) + Hopt =tst_get_tmpdir (); +SAFE_MOUNT ("none" , Hopt,"hugetlbfs" ,0 ,NULL ); + +snprintf (hfile,sizeof (hfile),"%s/ltp_hugetlbfile%d" , Hopt,getpid ());
testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c line 96
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c new file +10
-0+ hpage_size =SAFE_READ_MEMINFO ("Hugepagesize:" )*1024 ; +} + +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +if (nfd >=0 ) +SAFE_CLOSE (nfd); +umount2 (Hopt,MNT_DETACH );
Here as well.
Quoted 21 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c new file +15
-0+} + +static struct tst_test test = { + .needs_root =1 , + .needs_tmpdir =1 , + .options = (struct tst_option []) { + {"H:" , &Hopt,"Location of hugetlbfs, i.e. -H /var/hugetlbfs" }, + {"s:" , &nr_opt,"Set the number of the been allocated hugepages" }, + {} + }, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {1 ,TST_REQUEST }, +};Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 6/29 Hugetlb: Migrating libhugetlbfs fadvise_reserve
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/fadvise_reserve.c test
Test Description: fadvise() 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/hugemmap12.c | 114 ++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c
runtest/hugetlb +1 -0
@@ -8,6 +8,7 @@ hugemmap08 hugemmap08 hugemmap09 hugemmap09 hugemmap10 hugemmap10 hugemmap11 hugemmap11 +hugemmap12 hugemmap12 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -9,6 +9,7 @@ /hugetlb/hugemmap/hugemmap09 /hugetlb/hugemmap/hugemmap10 /hugetlb/hugemmap/hugemmap11 +/hugetlb/hugemmap/hugemmap12 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c new file +114 -0
114 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/29] Hugetlb: Migrating libhugetlbfs fadvise_reserve
Hi!
Quoted 46 lines
Test Description:
fadvise()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/hugemmap12.c | 114 ++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.cruntest/hugetlb +1
-0@@ -8,6 +8,7 @@ hugemmap08 hugemmap08 hugemmap09 hugemmap09 hugemmap10 hugemmap10 hugemmap11 hugemmap11 +hugemmap12 hugemmap12 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -9,6 +9,7 @@ /hugetlb/hugemmap/hugemmap09 /hugetlb/hugemmap/hugemmap10 /hugetlb/hugemmap/hugemmap11 +/hugetlb/hugemmap/hugemmap12 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c new file +1
-0@@ -0,0 +1,114 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c line 11
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c new file +10
-0+/* +* Copyright (C) 2005-2006 IBM Corporation. +* +* Test Name: fadvise_reserve +* +* Test Description: fadvise() 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
Here as well.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c line 12
Quoted 1 line
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c new file +1
-0+* f2deae9d4e70793568ef9e85d227abb7bef5b622.
This hash should be added into .tags in the tst_test structure instead.
Quoted 19 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c new file +19
-0+* HISTORY +* Written by Mel Gorman +*/ + +#define _GNU_SOURCE +#include <stdio.h> +#include <sys/mount.h> +#include <limits.h> +#include <sys/param.h> +#include <sys/types.h> + +#include "hugetlb.h" + +static long hpage_size; +static int fd =-1 ; +static char hfile[MAXPATHLEN ]; +static char *verbose; + +static void run_test (void )
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c line 42
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c new file +10
-0+{ +void *p; +unsigned long initial_rsvd, map_rsvd, fadvise_rsvd, end_rsvd; + + fd =SAFE_OPEN (hfile,O_RDWR |O_CREAT ,0600 ); +SAFE_UNLINK (hfile); + + initial_rsvd =SAFE_READ_MEMINFO ("HugePages_Rsvd:" ); +if (verbose) +tst_res (TINFO ,"Reserve count before map: %lu" , initial_rsvd);
Here as well, not keen on the verbose flag.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c line 44
Quoted 1 line
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c new file +1
-0+/* mmap a region and record reservations */
Here as well, no useless comments.
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c new file +6
-0+ p =SAFE_MMAP (NULL , hpage_size,PROT_READ |PROT_WRITE ,MAP_SHARED , + fd,0 ); + map_rsvd =SAFE_READ_MEMINFO ("HugePages_Rsvd:" ); +if (verbose) +tst_res (TINFO ,"Reserve count after map: %lu" , map_rsvd); +
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c line 60
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c new file +10
-0+/* fadvise the region and record reservations */ +if (posix_fadvise (fd,0 , hpage_size,POSIX_FADV_WILLNEED ) ==-1 ) { +tst_res (TFAIL |TERRNO ,"fadvise()" ); + goto fail; + } + fadvise_rsvd =SAFE_READ_MEMINFO ("HugePages_Rsvd:" ); +if (verbose) +tst_res (TINFO ,"Reserve count after fadvise: %lu" , fadvise_rsvd); + +/* Write the region */
Here as well.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c line 63
Quoted 3 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c new file +3
-0+memset (p,1 , hpage_size); + +/* Free region */
And here as well.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c line 70
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c new file +7
-0+SAFE_MUNMAP (p, hpage_size); +SAFE_CLOSE (fd); + end_rsvd =SAFE_READ_MEMINFO ("HugePages_Rsvd:" ); +if (verbose) +tst_res (TINFO ,"Reserve count after close: %lu" , end_rsvd); + +/* Reserve count should match initial reserve count */
And here.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c line 75
Quoted 5 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c new file +5
-0+if (end_rsvd != initial_rsvd) { +tst_res (TFAIL ,"Reserve leaked: %lu != %lu" , end_rsvd, initial_rsvd); + goto fail; + } +tst_res (TPASS ,"Successful" );
Just TST_EXP_EQ_LU(end_rsvd, initial_rsvd);
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c line 78
Quoted 3 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c new file +3
-0+return ; +fail: +tst_brk (TBROK ,"Once failed, No point in continuing the test" );
Here as well, no tst_brk() like this.
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c new file +10
-0+} + +static void setup (void ) +{ +if (tst_hugepages <1 ) +tst_brk (TCONF ,"Not enough hugepages for testing." ); + +if (!Hopt) + Hopt =tst_get_tmpdir (); +SAFE_MOUNT ("none" , Hopt,"hugetlbfs" ,0 ,NULL );
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c line 98
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c new file +10
-0+ +snprintf (hfile,sizeof (hfile),"%s/ltp_hugetlbfile%d" , Hopt,getpid ()); + hpage_size =SAFE_READ_MEMINFO ("Hugepagesize:" )*1024 ; +} + +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +umount2 (Hopt,MNT_DETACH );
Here as well.
Quoted 22 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c new file +16
-0+} + +static struct tst_test test = { + .needs_root =1 , + .needs_tmpdir =1 , + .options = (struct tst_option []) { + {"v" , &verbose,"Turns on verbose mode" }, + {"H:" , &Hopt,"Location of hugetlbfs, i.e. -H /var/hugetlbfs" }, + {"s:" , &nr_opt,"Set the number of the been allocated hugepages" }, + {} + }, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {1 ,TST_REQUEST }, +};Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 7/29 Hugetlb: Migrating libhugetlbfs fallocate_align
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/fallocate_align.c test
Test Description: It tests alignment of fallocate arguments. fallocate will take non-huge page aligned offsets and addresses. However, operations are only performed on huge pages. This is different that than fallocate behavior in "normal" filesystems.
--- runtest/hugetlb | 2 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugefallocate/Makefile | 10 + .../hugetlb/hugefallocate/hugefallocate01.c | 187 ++++++++++++++++++ 4 files changed, 200 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/Makefile create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate01.c
runtest/hugetlb +2 -0
@@ -1,3 +1,5 @@ +hugefallocate01 hugefallocate01 + hugemmap01 hugemmap01 hugemmap02 hugemmap02 hugemmap04 hugemmap04
testcases/kernel/mem/.gitignore +1 -0
@@ -1,4 +1,5 @@ /cpuset/cpuset01 +/hugetlb/hugefallocate/hugefallocate01 /hugetlb/hugemmap/hugemmap01 /hugetlb/hugemmap/hugemmap02 /hugetlb/hugemmap/hugemmap04
testcases/kernel/mem/hugetlb/hugefallocate/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2009, Cisco Systems Inc. +# Ngie Cooper, July 2009 + +top_srcdir ?= ../../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(abs_srcdir)/../Makefile.inc +include $(top_srcdir)/include/mk/generic_leaf_target.mk +
testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate01.c new file +187 -0
187 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 07/29] Hugetlb: Migrating libhugetlbfs fallocate_align
Hi!
The same comments apply for this test as well.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 8/29 Hugetlb: Migrating libhugetlbfs fallocate_basic
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/fallocate_basic.c test
Test Description: It tests basic fallocate functionality in hugetlbfs. Preallocate huge pages to a file in hugetlbfs, and then remove the pages via hole punch.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../hugetlb/hugefallocate/hugefallocate02.c | 116 ++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c
runtest/hugetlb +1 -0
@@ -1,4 +1,5 @@ hugefallocate01 hugefallocate01 +hugefallocate02 hugefallocate02 hugemmap01 hugemmap01 hugemmap02 hugemmap02
testcases/kernel/mem/.gitignore +1 -0
@@ -1,5 +1,6 @@ /cpuset/cpuset01 /hugetlb/hugefallocate/hugefallocate01 +/hugetlb/hugefallocate/hugefallocate02 /hugetlb/hugemmap/hugemmap01 /hugetlb/hugemmap/hugemmap02 /hugetlb/hugemmap/hugemmap04
testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c new file +116 -0
116 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/29] Hugetlb: Migrating libhugetlbfs fallocate_basic
Hi!
And the same comments apply to this test as well.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 9/29 Hugetlb: Migrating libhugetlbfs fork-cow
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/fork-cow.c test
Test Description: This checks copy-on-write semantics, specifically the semantics of a MAP_PRIVATE mapping across a fork(). Some versions of the powerpc kernel had a bug in huge_ptep_set_wrprotect() which would fail to flush the hash table after setting the write protect bit in the parent's page tables, thus allowing the parent to pollute the child's mapping.
--- runtest/hugetlb | 2 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugefork/Makefile | 10 + .../kernel/mem/hugetlb/hugefork/hugefork01.c | 220 ++++++++++++++++++ 4 files changed, 233 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugefork/Makefile create mode 100644 testcases/kernel/mem/hugetlb/hugefork/hugefork01.c
runtest/hugetlb +2 -0
@@ -1,6 +1,8 @@ hugefallocate01 hugefallocate01 hugefallocate02 hugefallocate02 +hugefork01 hugefork01 + hugemmap01 hugemmap01 hugemmap02 hugemmap02 hugemmap04 hugemmap04
testcases/kernel/mem/.gitignore +1 -0
@@ -1,6 +1,7 @@ /cpuset/cpuset01 /hugetlb/hugefallocate/hugefallocate01 /hugetlb/hugefallocate/hugefallocate02 +/hugetlb/hugefork/hugefork01 /hugetlb/hugemmap/hugemmap01 /hugetlb/hugemmap/hugemmap02 /hugetlb/hugemmap/hugemmap04
testcases/kernel/mem/hugetlb/hugefork/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2009, Cisco Systems Inc. +# Ngie Cooper, July 2009 + +top_srcdir ?= ../../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(abs_srcdir)/../Makefile.inc +include $(top_srcdir)/include/mk/generic_leaf_target.mk +
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +220 -0
220 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/29] Hugetlb: Migrating libhugetlbfs fork-cow
Hi!
Quoted 119 lines
Migrating the
libhugetlbfs/testcases/fork-cow.ctestTest Description: This checks copy-on-write semantics, specifically the semantics of a
MAP_PRIVATEmapping across afork(). Some versions of the powerpc kernel had a bug inhuge_ptep_set_wrprotect()which would fail to flush the hash table after setting the write protect bit in the parent's page tables, thus allowing the parent to pollute the child's mapping.Signed-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 2 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugefork/Makefile | 10 + .../kernel/mem/hugetlb/hugefork/hugefork01.c | 220 ++++++++++++++++++ 4 files changed, 233 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugefork/Makefile create mode 100644 testcases/kernel/mem/hugetlb/hugefork/hugefork01.cruntest/hugetlb +2
-0@@ -1,6 +1,8 @@ hugefallocate01 hugefallocate01 hugefallocate02 hugefallocate02 +hugefork01 hugefork01 + hugemmap01 hugemmap01 hugemmap02 hugemmap02 hugemmap04 hugemmap04testcases/kernel/mem/.gitignore +1
-0@@ -1,6 +1,7 @@ /cpuset/cpuset01 /hugetlb/hugefallocate/hugefallocate01 /hugetlb/hugefallocate/hugefallocate02 +/hugetlb/hugefork/hugefork01 /hugetlb/hugemmap/hugemmap01 /hugetlb/hugemmap/hugemmap02 /hugetlb/hugemmap/hugemmap04testcases/kernel/mem/hugetlb/hugefork/Makefile new file +10
-0@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2009, Cisco Systems Inc. +# Ngie Cooper, July 2009 + +top_srcdir ?= ../../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(abs_srcdir)/../Makefile.inc +include $(top_srcdir)/include/mk/generic_leaf_target.mk +testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +54
-0@@ -0,0 +1,220 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2008 David Gibson, IBM Corporation. +* +* Test Name: fork COW +* +* Test Description: This checks copy-on-write semantics, specifically the +* semantics of a MAP_PRIVATE mapping across a fork(). Some versions of the +* powerpc kernel had a bug in huge_ptep_set_wrprotect() which would fail to +* flush the hash table after setting the write protect bit in the parent's +* page tables, thus allowing the parent to pollute the child's mapping. +* +* HISTORY +* Written by David Gibson +* +*/ + +#define _GNU_SOURCE + + +#include <sys/shm.h> +#include <sys/wait.h> +#include <sys/mman.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/mount.h> +#include <limits.h> +#include <sys/param.h> +#include <sys/types.h> + +#include "hugetlb.h" + +#define RANDOM_CONSTANT 0x1234ABCD +#define OTHER_CONSTANT 0xfeef5678 + +static int fd =-1 ; +static char hfile[MAXPATHLEN ]; +static long hpage_size; +static char *verbose; + +/* +* The parent uses this to check if the child terminated badly. +*/ +static void sigchld_handler (int signum,siginfo_t *si,void *uc) +{ + (void )signum; + (void )uc; +if (WEXITSTATUS (si->si_status) !=0 ) { +tst_res (TFAIL ,"Child failed: %d" ,WEXITSTATUS (si->si_status));
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 64
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +10
-0+ goto fail; + } +if (WIFSIGNALED (si->si_status)) { +tst_res (TFAIL ,"Child recived signal %s" , +strsignal (WTERMSIG (si->si_status))); + goto fail; + } +return ; +fail: +tst_brk (TBROK ,"Once failed, No point in continuing the test" );
You cannot call tst_* functions from a signal handler, these are not async-signal-safe.
The only sensible thing to use the value filled in by the waitpid() call instead.
Quoted 40 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +40
-0+} + +static void run_test (void ) +{ +int status; +void *syncarea; +volatile unsigned int *p; +volatile unsigned int *trigger, *child_readback; +int parent_readback; +pid_t pid; +struct sigaction sa = { + .sa_sigaction = sigchld_handler, + .sa_flags =SA_SIGINFO , + }; + +/* Get a shared normal page for synchronization */ +if (verbose) +tst_res (TINFO ,"Mapping synchronization area.." ); + syncarea =SAFE_MMAP (NULL ,getpagesize (),PROT_READ |PROT_WRITE , +MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ); +if (verbose) +tst_res (TINFO ,"done" ); + + trigger = syncarea; + *trigger =0 ; + + child_readback = trigger +1 ; + *child_readback =0 ; + + fd =SAFE_OPEN (hfile,O_RDWR |O_CREAT ,0600 ); +SAFE_UNLINK (hfile); + +if (verbose) +tst_res (TINFO ,"Mapping hugepage area..." ); + p =SAFE_MMAP (NULL , hpage_size,PROT_READ |PROT_WRITE ,MAP_PRIVATE , fd,0 ); +if (verbose) +tst_res (TINFO ,"mapped at %p" , p); +/* Touch the page for write in parent */ +if (verbose) +tst_res (TINFO ,"Parent writes pre-fork..." );
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 114
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +10
-0+ *p =RANDOM_CONSTANT ; +if (verbose) +tst_res (TINFO ,"%x" ,RANDOM_CONSTANT ); + +SAFE_SIGACTION (SIGCHLD , &sa,NULL ); + + pid =SAFE_FORK (); + +if (pid !=0 ) { +/* Parent */
Useless comment again.
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 120
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +6
-0+if (verbose) +tst_res (TINFO ,"Parent writes post-fork..." ); + *p = ~RANDOM_CONSTANT ; +if (verbose) +tst_res (TINFO ,"~RANDOM_CONSTANT: %x" , ~RANDOM_CONSTANT ); + *trigger =1 ;
We do have checkpoint library exactly for synchronization between parent and child make use of them, see TST_CHECKPOINT_*.
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 126
Quoted 5 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +5
-0+while (*trigger !=2 ) + ; + +if (verbose) +tst_res (TINFO ,"Parent reads.." );
I would be inclined to remove these "Parent does xyz" and "Child does abc" messages from test once we make use of the CHECKPOINTs the synchronization is guaranteed to be right.
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 132
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +6
-0+ parent_readback = *p; +if (verbose) +tst_res (TINFO ,"Parent readback: %x" , parent_readback); + *trigger =3 ; + }else { +/* Child */
Here as well.
Quoted 39 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +39
-0+if (verbose) +tst_res (TINFO ,"Child starts.." ); +while (*trigger !=1 ) + ; + +if (verbose) +tst_res (TINFO ,"Child reads..." ); + *child_readback = *p; +if (verbose) { +tst_res (TINFO ,"child readback: %x" , *child_readback); +tst_res (TINFO ,"Child writes..." ); + } + *p =OTHER_CONSTANT ; +if (verbose) +tst_res (TINFO ,"OTHER_CONSTANT: %x" ,OTHER_CONSTANT ); + + *trigger =2 ; + +while (*trigger !=3 ) + ; +if (verbose) +tst_res (TINFO ,"Child exits..." ); +exit (0 ); + } + +if (verbose) +tst_res (TINFO ,"child_readback = 0x%x, parent_readback = 0x%x\n" , + *child_readback, parent_readback); + +if (*child_readback !=RANDOM_CONSTANT ) { +tst_res (TFAIL ,"Child read back 0x%x instead of 0x%x" , + *child_readback,RANDOM_CONSTANT ); + goto fail; + } +if (parent_readback != ~RANDOM_CONSTANT ) { +tst_res (TFAIL ,"Parent read back 0x%x instead of 0x%x" , + parent_readback,RANDOM_CONSTANT ); + goto fail; + }
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 181
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +10
-0+ +SAFE_WAITPID (pid, &status,0 ); + +tst_res (TPASS ,"Successful" ); +SAFE_MUNMAP ((void *)p, hpage_size); +SAFE_MUNMAP (syncarea,getpagesize ()); +SAFE_CLOSE (fd); +return ; +fail: +tst_brk (TBROK ,"Once failed, No point in continuing the test" );
Here as well.
Quoted 12 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +12
-0+} + +static void setup (void ) +{ +int free_pages =SAFE_READ_MEMINFO ("HugePages_Free:" ); + +if (tst_hugepages <2 || free_pages <2 ) +tst_brk (TCONF ,"Not enough hugepages for testing." ); + +if (!Hopt) + Hopt =tst_get_tmpdir (); +SAFE_MOUNT ("none" , Hopt,"hugetlbfs" ,0 ,NULL );
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 203
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +10
-0+ +snprintf (hfile,sizeof (hfile),"%s/ltp_hugetlbfile%d" , Hopt,getpid ()); + hpage_size =SAFE_READ_MEMINFO ("Hugepagesize:" )*1024 ; +} + +static void cleanup (void ) +{ +if (fd >=0 ) +SAFE_CLOSE (fd); +umount2 (Hopt,MNT_DETACH );
Here as well.
Quoted 23 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +17
-0+} + +static struct tst_test test = { + .needs_root =1 , + .needs_tmpdir =1 , + .options = (struct tst_option []) { + {"v" , &verbose,"Turns on verbose mode" }, + {"H:" , &Hopt,"Location of hugetlbfs, i.e. -H /var/hugetlbfs" }, + {"s:" , &nr_opt,"Set the number of the been allocated hugepages" }, + {} + }, + .forks_child =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {2 ,TST_REQUEST }, +};Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 09/29] Hugetlb: Migrating libhugetlbfs fork-cow
In reply to Tarun SahuQuoted 33 lines · Tarun Sahu
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +33
-0+static void run_test (void ) +{ +int status; +void *syncarea; +volatile unsigned int *p; +volatile unsigned int *trigger, *child_readback; +int parent_readback; +pid_t pid; +struct sigaction sa = { + .sa_sigaction = sigchld_handler, + .sa_flags =SA_SIGINFO , + }; + +/* Get a shared normal page for synchronization */ +if (verbose) +tst_res (TINFO ,"Mapping synchronization area.." ); + syncarea =SAFE_MMAP (NULL ,getpagesize (),PROT_READ |PROT_WRITE , +MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ); +if (verbose) +tst_res (TINFO ,"done" ); + + trigger = syncarea; + *trigger =0 ; + + child_readback = trigger +1 ; + *child_readback =0 ; + + fd =SAFE_OPEN (hfile,O_RDWR |O_CREAT ,0600 ); +SAFE_UNLINK (hfile); + +if (verbose) +tst_res (TINFO ,"Mapping hugepage area..." ); + p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE,
Quoted 2 lines
fd, 0);
After roughly looking at those hpage testcases, almost each one requests the huge memory via mapping a file on hugetlbfs, which can work but quite don't have to.
We can absolutely simplify them via MAP_HUGETLB to get expected size of huge memory for use.
Reference how hugemamp06.c does:
https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/mem/hugetlb/hugemmap/hugemmap06.c#L71
+static void setup(void)
Quoted 15 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +11
-0+{ +int free_pages =SAFE_READ_MEMINFO ("HugePages_Free:" ); + +if (tst_hugepages <2 || free_pages <2 ) +tst_brk (TCONF ,"Not enough hugepages for testing." ); + +if (!Hopt) + Hopt =tst_get_tmpdir (); +SAFE_MOUNT ("none" , Hopt,"hugetlbfs" ,0 ,NULL ); + + snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt,
Quoted 2 lines
getpid());
If we go using MAP_HUGETLB above, those lines can be removed.
Quoted 3 lines
(quoted diff) +2
-0+ hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024; +}
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 10/29 Hugetlb: Migrating libhugetlbfs huge_at_4GB_normal_below
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/huge_at_4GB_normal_below.c test
Test Description: Designed to pick up a bug on ppc64 where touches_hugepage_high_range() falsely reported true for ranges reaching below 4GB
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap13.c | 160 ++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c
runtest/hugetlb +1 -0
@@ -14,6 +14,7 @@ hugemmap09 hugemmap09 hugemmap10 hugemmap10 hugemmap11 hugemmap11 hugemmap12 hugemmap12 +hugemmap13 hugemmap13 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -13,6 +13,7 @@ /hugetlb/hugemmap/hugemmap10 /hugetlb/hugemmap/hugemmap11 /hugetlb/hugemmap/hugemmap12 +/hugetlb/hugemmap/hugemmap13 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c new file +160 -0
160 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/29] Hugetlb: Migrating libhugetlbfs huge_at_4GB_normal_below
Quoted 94 lines
Migrating the
libhugetlbfs/testcases/huge_at_4GB_normal_below.ctestTest Description: Designed to pick up a bug on ppc64 where
touches_hugepage_high_range()falsely reported true for ranges reaching below 4GBSigned-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap13.c | 160 ++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.cruntest/hugetlb +1
-0@@ -14,6 +14,7 @@ hugemmap09 hugemmap09 hugemmap10 hugemmap10 hugemmap11 hugemmap11 hugemmap12 hugemmap12 +hugemmap13 hugemmap13 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -13,6 +13,7 @@ /hugetlb/hugemmap/hugemmap10 /hugetlb/hugemmap/hugemmap11 /hugetlb/hugemmap/hugemmap12 +/hugetlb/hugemmap/hugemmap13 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c new file +49
-0@@ -0,0 +1,160 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation. +* +* Test Name: Huge at 4GB normal below +* +* Test Description: Designed to pick up a bug on ppc64 where +* touches_hugepage_high_range() falsely reported true for ranges reaching +* below 4GB +* +* WARNING: The offsets and addresses used within are specifically +* calculated to trigger the bug as it existed. Don't mess with them +* unless you *really* know what you're doing. +* +* HISTORY +* Written by David Gibson & Adam Litke +* +*/ + +#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 FOURGB (1UL << 32) + +static int fd =-1 ; +static char hfile[MAXPATHLEN ]; +static unsigned long hpage_size; +static char *verbose; + +static void run_test (void ) +{ +int page_size; +int fd; +void *p, *q; +unsigned long lowaddr; +int err; + + page_size =getpagesize (); + + fd =SAFE_OPEN (hfile,O_RDWR |O_CREAT ,0600 ); +SAFE_UNLINK (hfile); + + p = mmap((void *)FOURGB, hpage_size, PROT_READ|PROT_WRITE,
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c line 59
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c new file +10
-0+ MAP_SHARED | MAP_FIXED, fd, 0); +if (p ==MAP_FAILED ) { +/* slice 0 (high) spans from 4G-1T */ +unsigned long below_start =FOURGB ; +unsigned long above_end =1024L *1024 *1024 *1024 ; + +if (range_is_mapped (below_start, above_end) ==1 ) { +if (verbose) { +tst_res (TINFO ,"region 4G-IT is not free" ); +tst_res (TINFO |TERRNO ,"mmap() failed" );
This should be single TINFO message.
Quoted 13 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c new file +13
-0+ } +tst_res (TPASS ,"Successful but inconclusive" ); +SAFE_CLOSE (fd); +return ; + } +tst_res (TFAIL |TERRNO ,"mmap() huge" ); + goto fail; + } +if (p != (void *)FOURGB ) { +tst_res (TFAIL ,"Wrong address with MAP_FIXED huge" ); + goto fail; + } +
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c line 82
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c new file +10
-0+if (verbose) +tst_res (TINFO ,"Mapped hugetlb at %p" , p); + +memset (p,0 , hpage_size); + + err =test_addr_huge (p); +if (err !=1 ) { +tst_res (TFAIL ,"Mapped address is not hugepage" ); + goto fail; + }
Again I fail to see how this is useful. This check looks to me like a circular definition at best. We create file on hugetlbfs, stat() it and check that the magic matches.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c line 95
Quoted 12 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c new file +12
-0+/* Test just below 4GB to check for off-by-one errors */ + lowaddr =FOURGB - page_size; + q =mmap ((void *)lowaddr, page_size,PROT_READ |PROT_WRITE , +MAP_SHARED |MAP_FIXED |MAP_ANONYMOUS ,0 ,0 ); +if (p ==MAP_FAILED ) { +unsigned long below_start =FOURGB - page_size; +unsigned long above_end =FOURGB ; + +if (range_is_mapped (below_start, above_end) ==1 ) { +if (verbose) { +tst_res (TINFO ,"region (4G-page)-4G is not free\n" ); +tst_res (TINFO |TERRNO ,"mmap() failed" );
Here as well, single message.
Quoted 14 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c new file +14
-0+ } +tst_res (TPASS ,"Successful but inconclusive" ); +SAFE_MUNMAP (p, hpage_size); +SAFE_CLOSE (fd); +return ; + } +tst_res (TFAIL |TERRNO ,"mmap() normal" ); + goto fail; + } +if (q != (void *)lowaddr) { +tst_res (TFAIL ,"Wrong address with MAP_FIXED normal" ); + goto fail; + } +
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c line 119
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c new file +10
-0+memset (q,0 , page_size); + +tst_res (TPASS ,"Successful" ); +SAFE_MUNMAP (p, hpage_size); +SAFE_MUNMAP (q, page_size); +SAFE_CLOSE (fd); +return ; +fail: +tst_brk (TBROK ,"Once failed, No point in continuing the test" ); +}
And the usuall comments apply as well.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 11/29 Hugetlb: Migrating libhugetlbfs huge_below_4GB_normal_above
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/huge_below_4GB_normal_above.c test
Test Description: Designed to pick up a bug on ppc64 where touches_hugepage_low_range() could give false positives because of the peculiar (undefined) behaviour of << for large shifts
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap14.c | 204 ++++++++++++++++++ 3 files changed, 206 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c
runtest/hugetlb +1 -0
@@ -15,6 +15,7 @@ hugemmap10 hugemmap10 hugemmap11 hugemmap11 hugemmap12 hugemmap12 hugemmap13 hugemmap13 +hugemmap14 hugemmap14 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -14,6 +14,7 @@ /hugetlb/hugemmap/hugemmap11 /hugetlb/hugemmap/hugemmap12 /hugetlb/hugemmap/hugemmap13 +/hugetlb/hugemmap/hugemmap14 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c new file +204 -0
204 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/29] Hugetlb: Migrating libhugetlbfs huge_below_4GB_normal_above
Hi!
Same comments as for the previous one apply here as well.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 12/29 Hugetlb: Migrating libhugetlbfs icache-hygiene
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/icache-hygiene.c test
Test Description: Older ppc64 kernels don't properly flush dcache to icache before giving a cleared page to userspace. With some exceedingly hairy code, this attempts to test for this bug.
This test will never trigger (obviously) on machines with coherent icache and dcache (including x86 and POWER5). On any given run, even on a buggy kernel there's a chance the bug won't trigger - either because we don't get the same physical page back when we remap, or because the icache happens to get flushed in the interim.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap15.c | 250 ++++++++++++++++++ 3 files changed, 252 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c
runtest/hugetlb +1 -0
@@ -16,6 +16,7 @@ hugemmap11 hugemmap11 hugemmap12 hugemmap12 hugemmap13 hugemmap13 hugemmap14 hugemmap14 +hugemmap15 hugemmap15 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -15,6 +15,7 @@ /hugetlb/hugemmap/hugemmap12 /hugetlb/hugemmap/hugemmap13 /hugetlb/hugemmap/hugemmap14 +/hugetlb/hugemmap/hugemmap15 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c new file +250 -0
250 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/29] Hugetlb: Migrating libhugetlbfs icache-hygiene
Hi!
Quoted 198 lines
Migrating the
libhugetlbfs/testcases/icache-hygiene.ctestTest Description: Older ppc64 kernels don't properly flush dcache to icache before giving a cleared page to userspace. With some exceedingly hairy code, this attempts to test for this bug.
This test will never trigger (obviously) on machines with coherent icache and dcache (including x86 and POWER5). On any given run, even on a buggy kernel there's a chance the bug won't trigger - either because we don't get the same physical page back when we remap, or because the icache happens to get flushed in the interim.
Signed-off-by Tarun Sahu <[email protected]>--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap15.c | 250 ++++++++++++++++++ 3 files changed, 252 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.cruntest/hugetlb +1
-0@@ -16,6 +16,7 @@ hugemmap11 hugemmap11 hugemmap12 hugemmap12 hugemmap13 hugemmap13 hugemmap14 hugemmap14 +hugemmap15 hugemmap15 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -mtestcases/kernel/mem/.gitignore +1
-0@@ -15,6 +15,7 @@ /hugetlb/hugemmap/hugemmap12 /hugetlb/hugemmap/hugemmap13 /hugetlb/hugemmap/hugemmap14 +/hugetlb/hugemmap/hugemmap15 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c new file +148
-0@@ -0,0 +1,250 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation. +* +* Test Name: icache hygiene +* +* Test Description: Older ppc64 kernels don't properly flush dcache to +* icache before giving a cleared page to userspace. With some exceedingly +* hairy code, this attempts to test for this bug. +* +* This test will never trigger (obviously) on machines with coherent +* icache and dcache (including x86 and POWER5). On any given run, +* even on a buggy kernel there's a chance the bug won't trigger - +* either because we don't get the same physical page back when we +* remap, or because the icache happens to get flushed in the interim. +* +* HISTORY +* Written by David Gibson & Adam Litke +* +*/ + +#define _GNU_SOURCE + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <setjmp.h> +#include <unistd.h> +#include <signal.h> +#include <sys/mman.h> +#include <ucontext.h> +#include <sys/mount.h> +#include <limits.h> +#include <sys/param.h> +#include <sys/types.h> + +#include "hugetlb.h" + +static int fd =-1 ; +static char hfile[MAXPATHLEN ]; + +#define COPY_SIZE 128 +#define NUM_REPETITIONS 64/* Seems to be enough to trigger reliably */ + +static char *verbose; +static long hpage_size; + +static void cacheflush (void *p) +{ + (void )p; +#if defined(__powerpc__) + asmvolatile ("dcbst 0,%0; sync; icbi 0,%0; isync" : :"r" (p)); +#elif defined(__arm__) || defined(__aarch64__) +__clear_cache (p, p +COPY_SIZE ); +#endif +} + +static void jumpfunc (int copy,void *p) +{ +/* gcc bug workaround: if there is exactly one &&label +* construct in the function, gcc assumes the computed goto +* goes there, leading to the complete elision of the goto in +* this case +*/ +void *l = &&dummy; + + l = &&jumplabel; + +if (copy) { +memcpy (p, l,COPY_SIZE ); +cacheflush (p); + } + + goto *p; + dummy: +tst_res (TWARN ,"unreachable?" ); + + jumplabel: +return ; +} + +static sigjmp_buf sig_escape; +static void *sig_expected; + +static void sig_handler (int signum,siginfo_t *si,void *uc) +{ +#if defined(__powerpc__) || defined(__powerpc64__) || defined(__ia64__) || \ + defined(__s390__) || defined(__s390x__) || defined(__sparc__) || \ + defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64) + /* On powerpc, ia64, s390 and Aarch64, 0 bytes are an illegal + * instruction, so, if the icache is cleared properly, we SIGILL + * as soon as we jump into the cleared page + */ + if (signum == SIGILL) { + if (verbose) + tst_res(TINFO, "SIGILL at %p (sig_expected=%p)", si->si_addr, + sig_expected); + if (si->si_addr == sig_expected) + siglongjmp(sig_escape, 1); + tst_res(TFAIL, "SIGILL somewhere unexpected"); + goto fail; + } +#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) + /* On x86, zero bytes form a valid instruction: + * add %al,(%eax) (i386) + * or add %al,(%rax) (x86_64) + * + * So, behaviour depends on the contents of [ER]AX, which in + * turn depends on the details of code generation. If [ER]AX + * contains a valid pointer, we will execute the instruction + * repeatedly until we run off that hugepage and get a SIGBUS + * on the second, truncated page. If [ER]AX does not contain + * a valid pointer, we will SEGV on the first instruction in + * the cleared page. We check for both possibilities + * below. + * + * On 32 bit ARM, zero bytes are interpreted as follows: + * andeq r0, r0, r0 (ARM state, 4 bytes) + * movs r0, r0 (Thumb state, 2 bytes) + * + * So, we only expect to run off the end of the huge page and + * generate a SIGBUS. + */ + if (signum == SIGBUS) { + if (verbose) + tst_res(TINFO, "SIGBUS at %p (sig_expected=%p)", si->si_addr, + sig_expected); + if (sig_expected + && (ALIGN((unsigned long)sig_expected, hpage_size) + == (unsigned long)si->si_addr)) { + siglongjmp(sig_escape, 2); + } + tst_res(TFAIL, "SIGBUS somewhere unexpected"); + goto fail; + } +#if defined(__x86_64__) || defined(__i386__) + if (signum == SIGSEGV) { +#ifdef __x86_64__ + void *pc = (void *)((ucontext_t *)uc)->uc_mcontext.gregs[REG_RIP]; +#else + void *pc = (void *)((ucontext_t *)uc)->uc_mcontext.gregs[REG_EIP]; +#endif + if (verbose) + tst_res(TINFO, "SIGSEGV at %p, PC=%p (sig_expected=%p)\n", + si->si_addr, pc, sig_expected); + if (sig_expected == pc) + siglongjmp(sig_escape, 1); + tst_res(TFAIL, "SIGSEGV somewhere unexpected");
testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c line 158
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c new file +10
-0+ goto fail; + } +#endif +#else +#error "Need to setup signal conditions for this arch" +#endif +return ; +fail: +tst_brk (TBROK ,"Once Failed, No Need to continue the next iteration." ); +}
Again no tst_res() or tst_brk() is allowed inside a signal handler, the best we can is to propagate different values for pass/fail in the return value from siglongjmp().
And the usuall comments apply to this test as well.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 13/29 Hugetlb: Migrating libhugetlbfs madvise_reserve
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/madvise_reserve.c test
Test Description: madvise() 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 is 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/hugemmap16.c | 112 ++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap16.c
runtest/hugetlb +1 -0
@@ -17,6 +17,7 @@ hugemmap12 hugemmap12 hugemmap13 hugemmap13 hugemmap14 hugemmap14 hugemmap15 hugemmap15 +hugemmap16 hugemmap16 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -16,6 +16,7 @@ /hugetlb/hugemmap/hugemmap13 /hugetlb/hugemmap/hugemmap14 /hugetlb/hugemmap/hugemmap15 +/hugetlb/hugemmap/hugemmap16 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap16.c new file +112 -0
112 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 14/29 Hugetlb: Migrating libhugetlbfs map_high_truncate_2
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/map_high_truncate_2.c test
Test Description: At one stage, a misconversion of hugetlb_vmtruncate_list to a prio_tree meant that on 32-bit machines, certain combinations of mapping and truncations could truncate incorrect pages, or overwrite pmds from other VMAs, triggering BUG_ON()s or other wierdness.
Test adapted from an example by Kenneth Chen <[email protected]>
WARNING: The offsets and addresses used within are specifically calculated to trigger the bug as it existed. Don't mess with them unless you *really* know what you're doing.
The kernel bug in question was fixed with
'commit 856fc2950555 ("[PATCH] hugetlb: fix prio_tree unit")'.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap17.c | 126 ++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap17.c
runtest/hugetlb +1 -0
@@ -18,6 +18,7 @@ hugemmap13 hugemmap13 hugemmap14 hugemmap14 hugemmap15 hugemmap15 hugemmap16 hugemmap16 +hugemmap17 hugemmap17 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -17,6 +17,7 @@ /hugetlb/hugemmap/hugemmap14 /hugetlb/hugemmap/hugemmap15 /hugetlb/hugemmap/hugemmap16 +/hugetlb/hugemmap/hugemmap17 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap17.c new file +126 -0
126 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 15/29 Hugetlb: Migrating libhugetlbfs misalign
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/misalign.c test
Test Description: Just as normal mmap()s can't have an address, length or offset which is not page aligned, so hugepage mmap()s can't have an address, length or offset with is not hugepage aligned.
However, from time to time when the various mmap() / get_unmapped_area() paths are updated, somebody misses one of the necessary checks for the hugepage paths. This testcase ensures that attempted hugepage mappings with parameters which are not correctly hugepage aligned are rejected.
However starting with 3.10-rc1, length passed in mmap() doesn't need to be aligned because 'commit af73e4d9506d3b797509f3c030e7dcd554f7d9c4 ("hugetlbfs: fix mmap failure in unaligned size request")' added ALIGN() to kernel side, in mmap_pgoff(), when mapping huge page files.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap18.c | 173 ++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap18.c
runtest/hugetlb +1 -0
@@ -19,6 +19,7 @@ hugemmap14 hugemmap14 hugemmap15 hugemmap15 hugemmap16 hugemmap16 hugemmap17 hugemmap17 +hugemmap18 hugemmap18 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -18,6 +18,7 @@ /hugetlb/hugemmap/hugemmap15 /hugetlb/hugemmap/hugemmap16 /hugetlb/hugemmap/hugemmap17 +/hugetlb/hugemmap/hugemmap18 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap18.c new file +173 -0
173 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 16/29 Hugetlb: Migrating libhugetlbfs misaligned_offset
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/misaligned_offset.c test
Test Name: Misaligned offset
Test Description: At one stage, a misconversion of hugetlb_vmtruncate_list to a prio_tree meant that on 32-bit machines, truncates at or above 4GB could truncate lower pages, resulting in BUG_ON()s.
WARNING: The offsets and addresses used within are specifically calculated to trigger the bug as it existed. Don't mess with them unless you *really* know what you're doing.
The kernel bug in question was fixed with
'commit 856fc2950555 ("[PATCH] hugetlb: fix prio_tree unit")'.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap19.c | 166 ++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap19.c
runtest/hugetlb +1 -0
@@ -20,6 +20,7 @@ hugemmap15 hugemmap15 hugemmap16 hugemmap16 hugemmap17 hugemmap17 hugemmap18 hugemmap18 +hugemmap19 hugemmap19 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -19,6 +19,7 @@ /hugetlb/hugemmap/hugemmap16 /hugetlb/hugemmap/hugemmap17 /hugetlb/hugemmap/hugemmap18 +/hugetlb/hugemmap/hugemmap19 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap19.c new file +166 -0
166 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 17/29 Hugetlb: Migrating libhugetlbfs mlock
In reply to Tarun SahuMigrating 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 | 108 ++++++++++++++++++ 3 files changed, 110 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 +108 -0
108 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 18/29 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 | 222 ++++++++++++++++++ 3 files changed, 224 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 -T 2 -s 5 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 +222 -0
222 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 19/29 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 | 170 ++++++++++++++++++ 3 files changed, 172 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 -T 2 -s 5 +hugemmap22 hugemmap22 -T 2 -s 5 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 +170 -0
170 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 20/29 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 | 283 ++++++++++++++++++ 3 files changed, 285 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 -T 2 -s 5 hugemmap22 hugemmap22 -T 2 -s 5 +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 +283 -0
283 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 21/29 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 | 168 ++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap25.c
runtest/hugetlb +1 -0
@@ -25,6 +25,7 @@ hugemmap20 hugemmap20 hugemmap21 hugemmap21 -T 2 -s 5 hugemmap22 hugemmap22 -T 2 -s 5 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 +168 -0
168 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 22/29 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 | 148 ++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c
runtest/hugetlb +1 -0
@@ -26,6 +26,7 @@ hugemmap21 hugemmap21 -T 2 -s 5 hugemmap22 hugemmap22 -T 2 -s 5 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 +148 -0
148 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 23/29 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 | 166 ++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap27.c
runtest/hugetlb +1 -0
@@ -27,6 +27,7 @@ hugemmap22 hugemmap22 -T 2 -s 5 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 +166 -0
166 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 24/29 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 | 107 ++++++++++++++++++ 3 files changed, 109 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 +107 -0
107 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 25/29 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 | 129 ++++++++++++++++++ 3 files changed, 131 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 +129 -0
129 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 26/29 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 | 120 ++++++++++++++++++ 3 files changed, 122 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 +120 -0
120 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 27/29 Hugetlb: Migrating libhugetlbfs readback
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/readback.c test
Test Description: This test is basic test for data validation written on hugepages. It writes random data in chunks, read back and confirm they are same.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap31.c | 98 +++++++++++++++++++ 3 files changed, 100 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 +98 -0
98 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 28/29 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/hugemmap32.c | 104 ++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.c
runtest/hugetlb +1 -0
@@ -32,6 +32,7 @@ hugemmap28 hugemmap28 hugemmap29 hugemmap29 hugemmap30 hugemmap30 hugemmap31 hugemmap31 +hugemmap32 hugemmap32 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -31,6 +31,7 @@ /hugetlb/hugemmap/hugemmap29 /hugetlb/hugemmap/hugemmap30 /hugetlb/hugemmap/hugemmap31 +/hugetlb/hugemmap/hugemmap32 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.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
PATCH 29/29 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 | 196 ++++++++++++++++++ 3 files changed, 198 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 +196 -0
196 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hello,
Quoted 9 lines · Tarun Sahu
Hi,
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.As per previous dicussion in RFC[1], Here, this patch series consists of hugetlb tests taken from libhugetlbfs modified to work in ltp environment. This series do not include all the tests, I will post another series for the remaining tests soon.
Perhaps Cyril already said this, but I suggest just getting one or two of the tests merged first then working through the rest.
This reduces the iteration time and batch size.
At least in terms of what you submit to the mailing list. Perhaps if it gets to the point where most tests pass review first time, you can submit everything remaining.
Also note that submitting this many new tests, once they are merged we will probably get failure reports (including compilation failures). It will make life easier to stagger that.
I'm going to mark this patch-set as changes requested in patchwork.
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Richard,
Understood, I will repost the patch, with first 2/3 in the series.
Thanks,
Quoted 36 lines · Richard Palethorpe
Hello,
Quoted 7 lines · Tarun Sahu
Hi,
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.Quoted 5 lines
As per previous dicussion in RFC[1], Here, this patch series consists
of hugetlb tests taken from libhugetlbfs modified to work in ltp environment. This series do not include all the tests, I will post another series for the remaining tests soon.Perhaps Cyril already said this, but I suggest just getting one or two
of the tests merged first then working through the rest.This reduces the iteration time and batch size.
At least in terms of what you submit to the mailing list. Perhaps if it
gets to the point where most tests pass review first time, you can submit everything remaining.Also note that submitting this many new tests, once they are merged we
will probably get failure reports (including compilation failures). It
will make life easier to stagger that.I'm going to mark this patch-set as changes requested in patchwork.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp