mem/hugetlb: shift an empty region to use in hugemmap02.c
PATCH v3 1/1 mem/hugetlb: shift an empty region to use in hugemmap02.c
v2 --> v3
1. delete the line[MAPS_BUF_SZ] array
2. use the tst_resm(TWARN, ...) to replace printf()
3. achieve range_is_mapped() function just by fscanf()
the testcase 'hugemmap02' always failed on s390x as:
----------
hugemmap02 0 TINFO : set nr_hugepages to 128 hugemmap02 1 TPASS : huge mmap succeeded (64-bit)
./hugemmap02: relocation error: ./hugemmap02: symbol , version GLIBC_2.2 not defined in file libc.so.6 with link time reference
----------
it is caused by mapping in zero where libc.so.6 was loaded and resulting in the dynamic loader finding no information about versions for the library.
running the program, we could obviously see the region area:
---------------
program address:
80000000-80001000 r--s 00000000 00:05 2644 /dev/zero 80001000-80012000 r-xp 00001000 fd:00 35121302 /mnt/tests/kernel/distribution/ltp/generic/ltp-full-20150903/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02 80012000-80013000 r--p 00011000 fd:00 35121302 /mnt/tests/kernel/distribution/ltp/generic/ltp-full-20150903/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02 80013000-80014000 rw-p 00012000 fd:00 35121302 /mnt/tests/kernel/distribution/ltp/generic/ltp-full-20150903/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02 80014000-80017000 rw-p 00000000 00:00 0 90000000-90200000 rw-s 00000000 00:29 75950 /tmp/hugme85Xf/mmapfile41071 9c14f000-9c170000 rw-p 00000000 00:00 0 [heap] 3ffad342000-3ffbd342000 r--s 00000000 00:05 2644 /dev/zero 3ffbd342000-3ffcd342000 r--s 00000000 00:05 2644 /dev/zero 3ffcd342000-3ffdd342000 r--s 00000000 00:05 2644 /dev/zero 3ffdd342000-3ffed342000 r--s 00000000 00:05 2644 /dev/zero 3ffed342000-3fffd342000 r--s 00000000 00:05 2644 /dev/zero 3fffd342000-3fffd344000 rw-p 00000000 00:00 0 3fffd344000-3fffd4db000 r-xp 00000000 fd:00 5438 /usr/lib64/libc-2.17.so 3fffd4db000-3fffd4df000 r--p 00196000 fd:00 5438 /usr/lib64/libc-2.17.so 3fffd4df000-3fffd4e1000 rw-p 0019a000 fd:00 5438 /usr/lib64/libc-2.17.so 3fffd4e1000-3fffd4e6000 rw-p 00000000 00:00 0 3fffd4e6000-3fffd4fe000 r-xp 00000000 fd:00 5464 /usr/lib64/libpthread-2.17.so 3fffd4fe000-3fffd4ff000 r--p 00017000 fd:00 5464 /usr/lib64/libpthread-2.17.so 3fffd4ff000-3fffd500000 rw-p 00018000 fd:00 5464 /usr/lib64/libpthread-2.17.so 3fffd500000-3fffd504000 rw-p 00000000 00:00 0 3fffd50c000-3fffd510000 rw-p 00000000 00:00 0 3fffd510000-3fffd512000 r-xp 00000000 00:00 0 [vdso] 3fffd512000-3fffd534000 r-xp 00000000 fd:00 5431 /usr/lib64/ld-2.17.so 3fffd534000-3fffd535000 r--p 00022000 fd:00 5431 /usr/lib64/ld-2.17.so 3fffd535000-3fffd536000 rw-p 00023000 fd:00 5431 /usr/lib64/ld-2.17.so
3fffd536000-3fffd537000 rw-p 00000000 00:00 0
3ffffaaf000-3ffffad0000 rw-p 00000000 00:00 0 [stack]
-------------
--- testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c | 25 +++++++++++++--- testcases/kernel/mem/include/mem.h | 2 ++ testcases/kernel/mem/lib/mem.c | 35 ++++++++++++++++++++++ 3 files changed, 58 insertions(+), 4 deletions(-)
testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c +21 -4
@@ -56,8 +56,8 @@#include "safe_macros.h" #include "mem.h" -#define LOW_ADDR (void *)(0x80000000) -#define LOW_ADDR2 (void *)(0x90000000) +#define LOW_ADDR 0x80000000 +#define LOW_ADDR2 0x90000000static char TEMPFILE [MAXPATHLEN ];
@@ -65,6 +65,8 @@ char *TCID = "hugemmap02";int TST_TOTAL =1 ;static unsigned long *addr;static unsigned long *addr2; +static unsigned long low_addr =LOW_ADDR ; +static unsigned long low_addr2 =LOW_ADDR2 ;static unsigned long *addrlist[5 ];static int i;static int fildes;
@@ -75,6 +77,7 @@ static long hugepages = 128;static long orig_hugepages;static void help (void ); +int range_is_mapped (unsigned long low,unsigned long high);int main (int ac,char **av) {
@@ -127,15 +130,29 @@ int main(int ac, char **av) addrlist[i] = addr; } +while (range_is_mapped (low_addr, low_addr +0x1000 ) ==1 ) { + low_addr = low_addr +0x10000000 ; + +if (low_addr <LOW_ADDR ) +tst_brkm (TBROK |TERRNO , cleanup, +"no empty region to use" ); + }/* mmap using normal pages and a low memory address */ - addr =mmap (LOW_ADDR , page_sz,PROT_READ , + addr =mmap ((void *)low_addr, page_sz,PROT_READ ,MAP_SHARED |MAP_FIXED , nfildes,0 );if (addr ==MAP_FAILED )tst_brkm (TBROK |TERRNO , cleanup,"mmap failed on nfildes" ); +while (range_is_mapped (low_addr2, low_addr2 +0x1000 ) ==1 ) { + low_addr2 = low_addr2 +0x10000000 ; + +if (low_addr2 <LOW_ADDR2 ) +tst_brkm (TBROK |TERRNO , cleanup, +"no empty region to use" ); + }/* Attempt to mmap a huge page into a low memory address */ - addr2 =mmap (LOW_ADDR2 , map_sz,PROT_READ |PROT_WRITE , + addr2 =mmap ((void *)low_addr2, map_sz,PROT_READ |PROT_WRITE ,MAP_SHARED , fildes,0 );#if __WORDSIZE ==64 /* 64-bit process */ if (addr2 ==MAP_FAILED ) {
testcases/kernel/mem/include/mem.h +2 -0
@@ -100,4 +100,6 @@ void setup(void);void update_shm_size (size_t *shm_size); +/* MMAP */ +int range_is_mapped (unsigned long low,unsigned long high);#endif
testcases/kernel/mem/lib/mem.c +35 -0
@@ -1113,3 +1113,38 @@ void update_shm_size(size_t * shm_size) *shm_size = shmmax; } } + +int range_is_mapped (unsigned long low,unsigned long high) +{ +FILE *f; + + f =fopen ("/proc/self/maps" ,"r" ); +if (!f) { +tst_resm (TWARN |TERRNO ,"Failed to open /proc/self/maps." ); +return -1 ; + } + +while (!feof (f)) { +unsigned long start, end; +int ret; + + ret =fscanf (f,"%lx-%lx %*[^\n]\n" , &start, &end); +if (ret !=2 ) { +tst_resm (TWARN |TERRNO ,"Couldn't parse /proc/self/maps line." ); +fclose (f); +return -1 ; + } + +if ((start >= low) && (start < high)) { +fclose (f); +return 1 ; + } +if ((end >= low) && (end < high)) { +fclose (f); +return 1 ; + } + } + +fclose (f); +return 0 ; +}
Signature · 1 line
1.8.3.1
PATCH v3 1/1 mem/hugetlb: shift an empty region to use in hugemmap02.c
Hi!
testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c int main(int ac, char **av) · line 133
Quoted 7 lines
int
main(int ac, char **av)
{testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c +1
-0@@ -127,15 +130,29 @@ int main(int ac, char **av) addrlist[i] = addr; } +while (range_is_mapped (low_addr, low_addr +0x1000 ) ==1 ) {
^ + map_sz?
testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c int main(int ac, char **av) · line 139
Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c +6
-0+ low_addr = low_addr +0x10000000 ; + +if (low_addr <LOW_ADDR ) +tst_brkm (TBROK |TERRNO , cleanup, +"no empty region to use" ); + }
Well, if we do not call tst_brkm() in the range_is_mapped() function we should check here that the return value wasn't -1 and exit the test accordingly...
Signature · 2 lines
Cyril Hrubis [email protected]
A message that is not in the archive (sent off-list or not yet received): CAEemH2dRZ11NJSrpNPvR-xA_C_ULsqdObWVFSGBZi-22fRGOcw@mail.gmail.com
PATCH v3 1/1 mem/hugetlb: shift an empty region to use in hugemmap02.c
---------- Forwarded message ----------
From: Li Wang <[email protected]>
Date: Wed, Oct 14, 2015 at 2:50 PM
Subject: Re: [PATCH v3] mem/hugetlb: shift an empty region to use in hugemmap02.c
To: Cyril Hrubis <[email protected]>
Hi,
Quoted 11 lines · Cyril Hrubis
Hi!
testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c int main(int ac, char **av) · line 133
Quoted 7 lines
int
main(int ac, char **av)
{testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c +1
-0@@ -127,15 +130,29 @@ int main(int ac, char **av) addrlist[i] = addr; } +while (range_is_mapped (low_addr, low_addr +0x1000 ) ==1 ) {^ + map_sz?
oops! I just focus on s390x before, it should be map_sz.
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c int main(int ac, char **av) · line 139
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c +6
-0+ low_addr = low_addr +0x10000000 ; + +if (low_addr <LOW_ADDR ) +tst_brkm (TBROK |TERRNO , cleanup, +"no empty region to use" ); + }
Quoted 4 lines
Well, if we do not call
tst_brkm()in therange_is_mapped()function we should check here that the return value wasn't -1 and exit the test accordingly...
hmm, check the return value here is not good, that would make confused in range_is_mapped() used. I'd like to handle the situation by the function itself.
-----
int range_is_mapped(unsigned long low, unsigned long high)
{
FILE *fp;
fp = fopen("/proc/self/maps", "r");
if (fp == NULL)
tst_brkm(TBROK | TERRNO, tst_exit, "Failed to open/proc/self/maps.");
while (!feof(fp)) {
unsigned long start, end;
int ret;
ret = fscanf(fp, "%lx-%lx %*[^\n]\n", &start, &end);
if (ret != 2) {
fclose(fp);
tst_brkm(TBROK | TERRNO, tst_exit, "Couldn't parse
/proc/self/maps line.");
}
if ((start >= low) && (start < high)) {
fclose(fp);
return 1;
}
if ((end >= low) && (end < high)) {
fclose(fp);
return 1;
}
}
fclose(fp);
return 0;
}any problem?
Signature · 13 lines
Regards, Li Wang Email: [email protected] -- Regards, Li Wang Email: [email protected] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20151014/81ed9953/attachment-0001.html>
PATCH v3 1/1 mem/hugetlb: shift an empty region to use in hugemmap02.c
Hi!
Quoted 3 lines
hmm, check the return value here is not good, that would make confused in
range_is_mapped()used. I'd like to handle the situation by the function itself.
Then we are back at passing the cleanup callback to the function so that we can pass it to the tst_brkm(). Otherwise the nr_hugepages that has been changed in the test setup() wouldn't be restored.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/1 mem/hugetlb: shift an empty region to use in hugemmap02.c
Hi,
Quoted 10 lines · Cyril Hrubis
Hi!
Quoted 3 lines
hmm, check the return value here is not good, that would make confused in
range_is_mapped()used. I'd like to handle the situation by the function itself.Then we are back at passing the cleanup callback to the function so that we can pass it to the
tst_brkm(). Otherwise thenr_hugepagesthat has been changed in the testsetup()wouldn't be restored.
Sure, I got your point, the function should be like:
int range_is_mapped(void (*cleanup_fn) (void), unsigned long low, unsigned long high)
{
...
}
Signature · 6 lines
Regards, Li Wang Email: [email protected] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20151015/484ac792/attachment.html>