Skip to contentSkip to conversation

hugemmap24: increase the baseline of slice_boundary according to hpage size

PATCH In review Li Wang 3 participants 4 messages Apr 27, 2023

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH 1/1 hugemmap24: increase the baseline of slice_boundary according to hpage size

This is to avoid error happens on system (aarch64: 512MB) with large huge page:

  # ./hugemmap24
  tst_hugepage.c:83: TINFO: 7 hugepage(s) reserved
  tst_test.c:1560: TINFO: Timeout per run is 0h 00m 30s
  hugemmap24.c:57: TINFO: can't use slice_boundary: 0x10000000: EINVAL (22)
  hugemmap24.c:57: TINFO: can't use slice_boundary: 0x20000000: ENOMEM (12)
  hugemmap24.c:57: TINFO: can't use slice_boundary: 0x30000000: EINVAL (22)
  tst_test.c:1618: TBROK: Test killed by SIGSEGV!
  # strace -f ./hugemmap24:
  ...
  [pid 86580] mmap(0xfffffffff0000000, 2147483648, PROT_READ, MAP_SHARED|MAP_FIXED, 3, 0) = -1 EINVAL
  [pid 86580] write(2, "hugemmap24.c:57: \33[1;34mTINFO: \33"..., 85hugemmap24.c:57: TINFO: can't use slice_boundary: 0x30000000: EINVAL (22)) = 85
  [pid 86580] mmap(NULL, 2147483648, PROT_READ, MAP_SHARED|MAP_FIXED, 3, 0) = 0
  [pid 86580] --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_ACCERR, si_addr=0x404338} ---
  [pid 86580] +++ killed by SIGSEGV (core dumped) +++
  # cat /proc/meminfo
  Hugepagesize: 524288 kB

Note:
This is basically an improved patch based on Jan's work, the only difference is that to bypass the heap and avoid some potential mmap collisions.

Patch get passed on RHEL-7/8/9 across many arches. (x86_64, ppc64le, ppc64, aarch64, s390x)

Discuss: https://lists.linux.it/pipermail/ltp/2023-March/033117.html

Cc Jan Stancek <[email protected]>
Cc Tarun Sahu <[email protected]>
Cc Fanhui Meng <[email protected]>
---
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap24.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
testcases/kernel/mem/hugetlb/hugemmap/hugemmap24.c +8 -1
index a465aadec..158a03010 100644
@@ -23,7 +23,7 @@
 
 static int  fd = -1;
 static unsigned long slice_boundary;
-static long hpage_size, page_size;
+static unsigned long hpage_size, page_size;
 
 static int init_slice_boundary(int fd)
 {
@@ -44,6 +44,13 @@ static int init_slice_boundary(int fd)
 	heap = malloc(1);
 	free(heap);
 
+	 /* Avoid underflow on systems with large huge pages.
+	  * The additionally plus heap address is to reduce the possibility
+	  * of MAP_FIXED stomp over existing mappings.
+	  */
+	while (slice_boundary + slice_size < (unsigned long)heap + 2*hpage_size)
+		slice_boundary += slice_size;
+
 	/* Find 2 neighbour slices with couple huge pages free
 	 * around slice boundary.
 	 * 16 is the maximum number of slices (low/high)
Signature · 5 lines
2.40.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Acked-by on v1 1/1
#1 lore raw
Quoted 22 lines · Li Wang

This is to avoid error happens on system (aarch64: 512MB) with large huge page:

  # ./hugemmap24
  tst_hugepage.c:83: TINFO: 7 hugepage(s) reserved
  tst_test.c:1560: TINFO: Timeout per run is 0h 00m 30s
  hugemmap24.c:57: TINFO: can't use slice_boundary: 0x10000000: EINVAL (22)
  hugemmap24.c:57: TINFO: can't use slice_boundary: 0x20000000: ENOMEM (12)
  hugemmap24.c:57: TINFO: can't use slice_boundary: 0x30000000: EINVAL (22)
  tst_test.c:1618: TBROK: Test killed by SIGSEGV!
  # strace -f ./hugemmap24:
  ...
  [pid 86580] mmap(0xfffffffff0000000, 2147483648, PROT_READ, MAP_SHARED|MAP_FIXED, 3, 0) = -1 EINVAL
  [pid 86580] write(2, "hugemmap24.c:57: \33[1;34mTINFO: \33"..., 85hugemmap24.c:57: TINFO: can't use slice_boundary: 0x30000000: EINVAL (22)) = 85
  [pid 86580] mmap(NULL, 2147483648, PROT_READ, MAP_SHARED|MAP_FIXED, 3, 0) = 0
  [pid 86580] --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_ACCERR, si_addr=0x404338} ---
  [pid 86580] +++ killed by SIGSEGV (core dumped) +++
  # cat /proc/meminfo
  Hugepagesize: 524288 kB
Quoted 7 lines

Note:
This is basically an improved patch based on Jan's work, the only difference is that to bypass the heap and avoid some potential mmap collisions.

Patch get passed on RHEL-7/8/9 across many arches. (x86_64, ppc64le, ppc64, aarch64, s390x)

It's an improvement, but the issue of usage of MAP_FIXED remains. No harm taking the patch, but we should likely still rewrite this test.

Quoted 42 lines

Discuss: https://lists.linux.it/pipermail/ltp/2023-March/033117.html

Cc Jan Stancek <[email protected]>
Cc Tarun Sahu <[email protected]>
Cc Fanhui Meng <[email protected]>
---
 testcases/kernel/mem/hugetlb/hugemmap/hugemmap24.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
testcases/kernel/mem/hugetlb/hugemmap/hugemmap24.c +8 -2
index a465aadec..158a03010 100644
@@ -23,7 +23,7 @@
 
 static int  fd = -1;
 static unsigned long slice_boundary;
-static long hpage_size, page_size;
+static unsigned long hpage_size, page_size;
 
 static int init_slice_boundary(int fd)
 {
@@ -44,6 +44,13 @@ static int init_slice_boundary(int fd)
        heap = malloc(1);
        free(heap);
 
+        /* Avoid underflow on systems with large huge pages.
+         * The additionally plus heap address is to reduce the possibility
+         * of MAP_FIXED stomp over existing mappings.
+         */
+       while (slice_boundary + slice_size < (unsigned long)heap + 2*hpage_size)
+               slice_boundary += slice_size;
+
        /* Find 2 neighbour slices with couple huge pages free
         * around slice boundary.
         * 16 is the maximum number of slices (low/high)
--

2.40.0

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Acked-by
#2 lore raw

Hi!

Quoted 4 lines

It's an improvement, but the issue of usage of MAP_FIXED remains. No harm taking the patch, but we should likely still rewrite this test.

I suppose that this is a band-aid that can go in before the release, but as Jan said the test needs to be redesigned.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#3 lore raw

Hi,

Quoted 9 lines · Cyril Hrubis

Hi!

Quoted 4 lines

It's an improvement, but the issue of usage of MAP_FIXED remains. No harm taking the patch, but we should likely still rewrite this test.

I suppose that this is a band-aid that can go in before the release, but as Jan said the test needs to be redesigned.

Sure, I agree with you both. I will be thinking redesign the structure of this test then.

Patch applied. thanks!

Quoted 8 lines

--
Cyril Hrubis
[email protected]

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp