Skip to contentSkip to conversation

syscalls/madvise02.c: Fix ENOMEM errno tests

PATCH New Xiao Yang 2 participants 3 messages Jul 26, 2018 – Jul 27, 2018

lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

PATCH 1/1 syscalls/madvise02.c: Fix ENOMEM errno tests

With commit 212a4b9 on some distros(e.g. RHEL6.9/7.5), running madvise02 got the following error:
------------------------------------------------------
...
madvise02.c:181: CONF: MADV_UNMERGEABLE is not supported madvise02.c:196: FAIL: madvise succeeded unexpectedly madvise02.c:196: FAIL: madvise succeeded unexpectedly madvise02.c:181: CONF: MADV_WILLNEED is not supported
...
-------------------------------------------------------

If MAP_SIZE was equal to a pagesize, shared_anon may get the same address which was a part of file2 and already unmapped, so that the whole address of file2 became valid again. Subsequently, ENOMEM errno tests succeeded, so changing the order of mmaps to make shared_anon get different address.

---
 testcases/kernel/syscalls/madvise/madvise02.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/madvise/madvise02.c +2 -2
index 53e4f51..f683a99 100644
@@ -156,11 +156,11 @@ static void setup(void)
 	SAFE_FSTAT(fd, &st);
 
 	file1 = SAFE_MMAP(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
+	shared_anon = SAFE_MMAP(0, MAP_SIZE, PROT_READ, MAP_SHARED |
+			 MAP_ANONYMOUS, -1, 0);
 	file2 = SAFE_MMAP(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
 	SAFE_MUNMAP(file2 + st.st_size - pagesize, pagesize);
 	file3 = SAFE_MMAP(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
-	shared_anon = SAFE_MMAP(0, MAP_SIZE, PROT_READ, MAP_SHARED |
-			MAP_ANONYMOUS, -1, 0);
 
 	nonalign = file1 + 100;
 
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 syscalls/madvise02.c: Fix ENOMEM errno tests

----- Original Message -----

Quoted 11 lines

With commit 212a4b9 on some distros(e.g. RHEL6.9/7.5), running madvise02 got the following error:
------------------------------------------------------
...
madvise02.c:181: CONF: MADV_UNMERGEABLE is not supported madvise02.c:196: FAIL: madvise succeeded unexpectedly madvise02.c:196: FAIL: madvise succeeded unexpectedly madvise02.c:181: CONF: MADV_WILLNEED is not supported
...
-------------------------------------------------------

Quoted 7 lines

If MAP_SIZE was equal to a pagesize, shared_anon may get the same address which was a part of file2 and already unmapped, so that the whole address of file2 became valid again. Subsequently, ENOMEM errno tests succeeded, so changing the order of mmaps to make shared_anon get different address.

Hi,

I changed patch to move MUNMAP() instead and added comment explaining why.

You can review it here:
https://github.com/linux-test-project/ltp/commit/030e321ce1dfdc3a8daf7ef5a5b7bb7734cf2d9f

Thanks,
Jan

author
#2 lore raw

PATCH 1/1 syscalls/madvise02.c: Fix ENOMEM errno tests

Quoted 18 lines · Jan Stancek

----- Original Message -----

Quoted 17 lines

With commit 212a4b9 on some distros(e.g. RHEL6.9/7.5), running madvise02 got the following error:
------------------------------------------------------
...
madvise02.c:181: CONF: MADV_UNMERGEABLE is not supported madvise02.c:196: FAIL: madvise succeeded unexpectedly madvise02.c:196: FAIL: madvise succeeded unexpectedly madvise02.c:181: CONF: MADV_WILLNEED is not supported
...
-------------------------------------------------------

If MAP_SIZE was equal to a pagesize, shared_anon may get the same address which was a part of file2 and already unmapped, so that the whole address of file2 became valid again. Subsequently, ENOMEM errno tests succeeded, so changing the order of mmaps to make shared_anon get different address.

Quoted 8 lines
Quoted 1 line

Hi,

I changed patch to move MUNMAP() instead and added comment explaining why.

You can review it here:

   https://github.com/linux-test-project/ltp/commit/030e321ce1dfdc3a8daf7ef5a5b7bb7734cf2d9f

Hi Jan,

Thanks for your quick review, and it seems better to me. :-)

Thanks,
Xiao Yang

Quoted 5 lines

Thanks,
Jan