public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] Question on hugemmap34
@ 2024-12-10 11:53 Wei Gao via ltp
  2024-12-10 12:54 ` Jan Stancek
  0 siblings, 1 reply; 11+ messages in thread
From: Wei Gao via ltp @ 2024-12-10 11:53 UTC (permalink / raw)
  To: jstancek, emunson, samir; +Cc: Michal Koutný, ltp

Hi ALL

Is there any special config needed for this test case? Since the test failed with the following output on my test setup(opensuse15.5 with 6.12 kernel):

tst_hugepage.c:84: TINFO: 1 hugepage(s) reserved
tst_tmpdir.c:317: TINFO: Using /tmp/LTP_hugLSJb7r as tmpdir (btrfs filesystem)
tst_test.c:1100: TINFO: Mounting none to /tmp/LTP_hugLSJb7r/hugetlbfs fstyp=hugetlbfs flags=0
tst_test.c:1890: TINFO: LTP version: 20240930
tst_test.c:1894: TINFO: Tested kernel: 6.12.3-lp155.11.g78b0030-vanilla #1 SMP Fri Dec  6 08:56:39 UTC 2024 (78b0030) ppc64le
tst_test.c:1727: TINFO: Timeout per run is 0h 00m 30s
tst_coredump.c:32: TINFO: Avoid dumping corefile for process(pid=6671)
hugemmap34.c:88: TBROK: waitpid(0,0x7fffd8baa220,0) failed: ECHILD (10)
hugemmap34.c:92: TFAIL: Child: exited with 2

The root cause is the mmap call encounter failure with EBUSY.

LTP mmap call 
https://github.com/linux-test-project/ltp/blob/7bb960cc4f736d8860b6b266119e71e761e22b32/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c#L71

hit kernel code
https://elixir.bootlin.com/linux/v6.12/source/arch/powerpc/mm/book3s64/slice.c#L568
  
Let me give an example to explain why this happens base pmap of process in my test system:

Address           Kbytes     RSS     PSS   Dirty    Swap Mode  Mapping
0000000010000000     256     256     128     256       0 r-xp- /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
0000000010040000      64      64      32      64       0 r--p- /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
0000000010050000      64      64      64      64       0 rw-p- /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
0000000010060000      64      64      64      64       0 rw-p-   [ anon ]
0000010010090000     192      64      64      64       0 rw-p-   [ anon ]
00007fff8f3b0000    2368    1408       0       0       0 r-xp- /lib64/libc.so.6
00007fff8f600000      64      64      32      64       0 r--p- /lib64/libc.so.6
00007fff8f610000      64      64      64      64       0 rw-p- /lib64/libc.so.6
00007fff8f620000      64      64      32      64       0 rw-s- /dev/shm/ltp_hugemmap34_15513 (deleted)   
00007fff8f630000     128       0       0       0       0 r--p-   [ anon ]
00007fff8f650000      64       0       0       0       0 r-xp-   [ anon ]
00007fff8f660000     320     128       0       0       0 r-xp- /lib64/ld64.so.2
00007fff8f6b0000      64      64      32      64       0 r--p- /lib64/ld64.so.2
00007fff8f6c0000      64      64      64      64       0 rw-p- /lib64/ld64.so.2
00007fffc6740000     192      64      64      64       0 rw-p-   [ stack ] <<<<
---------------- ------- ------- ------- ------- -------
total kB           20416    2432    1318     896       0

Test power system config:
#getconf PAGE_SIZE
65536
#grep Hugepagesize /proc/meminfo
Hugepagesize:      16384 kB

Kenel split VM space into: 
16 low_slice(64KB page size), each slice size is 256MB
4096 high_slice(64K page size), each slice size is 1TB

00007fffc6740000(stack) is belong 127th high_slice(range is 00007f0000000000 - 00007fffffffffff)

When mmap try to allocate a 16M space(with page size MMU_PAGE_16M) near stack address(00007fffc6740000), 
kernel will first check good_mask but failed, since the all slices is MMU_PAGE_64K 
but mmap request page size is MMU_PAGE_16M.
https://elixir.bootlin.com/linux/v6.12/source/arch/powerpc/mm/book3s64/slice.c#L531

Next kernel start check potential_mask(seach all slice which has no any VM mapped), obviously
the 127th slice is occupied and 126th is the good candidate one but address range not match 
the mmap's request address(0x00007fffc6740000 - 2 * hpage_size), so finally EBUSY returned. 
https://elixir.bootlin.com/linux/v6.12/source/arch/powerpc/mm/book3s64/slice.c#L559

BTW: I have tested a scenario which disables MAP_FIXED_NOREPLACE, the kernel will
allocate successfully within the range of 126th high slice. 

Thanks.
Regards
Wei Gao

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] Question on hugemmap34
  2024-12-10 11:53 [LTP] Question on hugemmap34 Wei Gao via ltp
@ 2024-12-10 12:54 ` Jan Stancek
  2024-12-10 13:25   ` Jan Stancek
  0 siblings, 1 reply; 11+ messages in thread
From: Jan Stancek @ 2024-12-10 12:54 UTC (permalink / raw)
  To: Wei Gao; +Cc: samir, Michal Koutný, emunson, ltp

On Tue, Dec 10, 2024 at 12:53 PM Wei Gao <wegao@suse.com> wrote:
>
> Hi ALL
>
> Is there any special config needed for this test case? Since the test failed with the following output on my test setup(opensuse15.5 with 6.12 kernel):
>
> tst_hugepage.c:84: TINFO: 1 hugepage(s) reserved
> tst_tmpdir.c:317: TINFO: Using /tmp/LTP_hugLSJb7r as tmpdir (btrfs filesystem)
> tst_test.c:1100: TINFO: Mounting none to /tmp/LTP_hugLSJb7r/hugetlbfs fstyp=hugetlbfs flags=0
> tst_test.c:1890: TINFO: LTP version: 20240930
> tst_test.c:1894: TINFO: Tested kernel: 6.12.3-lp155.11.g78b0030-vanilla #1 SMP Fri Dec  6 08:56:39 UTC 2024 (78b0030) ppc64le
> tst_test.c:1727: TINFO: Timeout per run is 0h 00m 30s
> tst_coredump.c:32: TINFO: Avoid dumping corefile for process(pid=6671)
> hugemmap34.c:88: TBROK: waitpid(0,0x7fffd8baa220,0) failed: ECHILD (10)

There's missing exit() in do_child(), but that's not the only issue
with the test.

> hugemmap34.c:92: TFAIL: Child: exited with 2
>
> The root cause is the mmap call encounter failure with EBUSY.
>
> LTP mmap call
> https://github.com/linux-test-project/ltp/blob/7bb960cc4f736d8860b6b266119e71e761e22b32/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c#L71
>
> hit kernel code
> https://elixir.bootlin.com/linux/v6.12/source/arch/powerpc/mm/book3s64/slice.c#L568
>
> Let me give an example to explain why this happens base pmap of process in my test system:
>
> Address           Kbytes     RSS     PSS   Dirty    Swap Mode  Mapping
> 0000000010000000     256     256     128     256       0 r-xp- /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
> 0000000010040000      64      64      32      64       0 r--p- /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
> 0000000010050000      64      64      64      64       0 rw-p- /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
> 0000000010060000      64      64      64      64       0 rw-p-   [ anon ]
> 0000010010090000     192      64      64      64       0 rw-p-   [ anon ]
> 00007fff8f3b0000    2368    1408       0       0       0 r-xp- /lib64/libc.so.6
> 00007fff8f600000      64      64      32      64       0 r--p- /lib64/libc.so.6
> 00007fff8f610000      64      64      64      64       0 rw-p- /lib64/libc.so.6
> 00007fff8f620000      64      64      32      64       0 rw-s- /dev/shm/ltp_hugemmap34_15513 (deleted)
> 00007fff8f630000     128       0       0       0       0 r--p-   [ anon ]
> 00007fff8f650000      64       0       0       0       0 r-xp-   [ anon ]
> 00007fff8f660000     320     128       0       0       0 r-xp- /lib64/ld64.so.2
> 00007fff8f6b0000      64      64      32      64       0 r--p- /lib64/ld64.so.2
> 00007fff8f6c0000      64      64      64      64       0 rw-p- /lib64/ld64.so.2
> 00007fffc6740000     192      64      64      64       0 rw-p-   [ stack ] <<<<
> ---------------- ------- ------- ------- ------- -------
> total kB           20416    2432    1318     896       0
>
> Test power system config:
> #getconf PAGE_SIZE
> 65536
> #grep Hugepagesize /proc/meminfo
> Hugepagesize:      16384 kB
>
> Kenel split VM space into:
> 16 low_slice(64KB page size), each slice size is 256MB
> 4096 high_slice(64K page size), each slice size is 1TB
>
> 00007fffc6740000(stack) is belong 127th high_slice(range is 00007f0000000000 - 00007fffffffffff)
>
> When mmap try to allocate a 16M space(with page size MMU_PAGE_16M) near stack address(00007fffc6740000),
> kernel will first check good_mask but failed, since the all slices is MMU_PAGE_64K
> but mmap request page size is MMU_PAGE_16M.
> https://elixir.bootlin.com/linux/v6.12/source/arch/powerpc/mm/book3s64/slice.c#L531
>
> Next kernel start check potential_mask(seach all slice which has no any VM mapped), obviously
> the 127th slice is occupied and 126th is the good candidate one but address range not match
> the mmap's request address(0x00007fffc6740000 - 2 * hpage_size), so finally EBUSY returned.
> https://elixir.bootlin.com/linux/v6.12/source/arch/powerpc/mm/book3s64/slice.c#L559
>
> BTW: I have tested a scenario which disables MAP_FIXED_NOREPLACE, the kernel will
> allocate successfully within the range of 126th high slice.
>
> Thanks.
> Regards
> Wei Gao
>


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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] Question on hugemmap34
  2024-12-10 12:54 ` Jan Stancek
@ 2024-12-10 13:25   ` Jan Stancek
  2024-12-10 14:22     ` Wei Gao via ltp
  0 siblings, 1 reply; 11+ messages in thread
From: Jan Stancek @ 2024-12-10 13:25 UTC (permalink / raw)
  To: Wei Gao; +Cc: samir, Michal Koutný, emunson, ltp

On Tue, Dec 10, 2024 at 1:54 PM Jan Stancek <jstancek@redhat.com> wrote:
>
> On Tue, Dec 10, 2024 at 12:53 PM Wei Gao <wegao@suse.com> wrote:
> >
> > Hi ALL
> >
> > Is there any special config needed for this test case? Since the test failed with the following output on my test setup(opensuse15.5 with 6.12 kernel):
> >
> > tst_hugepage.c:84: TINFO: 1 hugepage(s) reserved
> > tst_tmpdir.c:317: TINFO: Using /tmp/LTP_hugLSJb7r as tmpdir (btrfs filesystem)
> > tst_test.c:1100: TINFO: Mounting none to /tmp/LTP_hugLSJb7r/hugetlbfs fstyp=hugetlbfs flags=0
> > tst_test.c:1890: TINFO: LTP version: 20240930
> > tst_test.c:1894: TINFO: Tested kernel: 6.12.3-lp155.11.g78b0030-vanilla #1 SMP Fri Dec  6 08:56:39 UTC 2024 (78b0030) ppc64le
> > tst_test.c:1727: TINFO: Timeout per run is 0h 00m 30s
> > tst_coredump.c:32: TINFO: Avoid dumping corefile for process(pid=6671)
> > hugemmap34.c:88: TBROK: waitpid(0,0x7fffd8baa220,0) failed: ECHILD (10)
>
> There's missing exit() in do_child(), but that's not the only issue
> with the test.

Could you give this patch a try?

diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
index a7a88fbb2..818697be8 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
@@ -51,16 +51,23 @@ void do_child(void *stop_address)
                x = alloca(STACK_ALLOCATION_SIZE);
                *x = 1;
        } while ((void *)x >= stop_address);
+       exit(0);
 }

 static void run_test(void)
 {
        int pid, status;
        void *stack_address, *mmap_address, *heap_address, *map;
+       char tmp[128];

        stack_address = alloca(0);
        heap_address = sbrk(0);

+       tst_res(TINFO, "heap is at: %p", heap_address);
+       tst_res(TINFO, "stack is at: %p", stack_address);
+       sprintf(tmp, "cat /proc/%d/maps", getpid());
+       TST_EXP_PASS_SILENT(system(tmp));
+
        /*
         * paranoia: start mapping two hugepages below the start of the stack,
         * in case the alignment would cause us to map over something if we
@@ -70,6 +77,9 @@ static void run_test(void)
        do {
                map = mmap(mmap_address, hpage_size, PROT_READ|PROT_WRITE,
                                MAP_SHARED | MAP_FIXED_NOREPLACE, fd, 0);
+               if (map == mmap_address)
+                       break;
+
                if (map == MAP_FAILED) {
                        if (errno == ENOMEM) {
                                tst_res(TCONF, "There is no enough
memory in the system to do mmap");
@@ -80,7 +90,12 @@ static void run_test(void)
                /*
                 * if we get all the way down to the heap, stop trying
                 */
-       } while (mmap_address <= heap_address);
+       } while (mmap_address > heap_address);
+
+       if (map == MAP_FAILED)
+               tst_brk(TBROK, "failed to map hpage_size area before
hitting heap");
+       tst_res(TINFO, "mapped at %p", mmap);
+
        pid = SAFE_FORK();
        if (pid == 0)
                do_child(mmap_address);


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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [LTP] Question on hugemmap34
  2024-12-10 13:25   ` Jan Stancek
@ 2024-12-10 14:22     ` Wei Gao via ltp
  2024-12-11  3:20       ` Wei Gao via ltp
  0 siblings, 1 reply; 11+ messages in thread
From: Wei Gao via ltp @ 2024-12-10 14:22 UTC (permalink / raw)
  To: Jan Stancek; +Cc: samir, Michal Koutný, emunson, ltp

On Tue, Dec 10, 2024 at 02:25:06PM +0100, Jan Stancek wrote:
> On Tue, Dec 10, 2024 at 1:54 PM Jan Stancek <jstancek@redhat.com> wrote:
> >
> > On Tue, Dec 10, 2024 at 12:53 PM Wei Gao <wegao@suse.com> wrote:
> > >
> > > Hi ALL
> > >
> > > Is there any special config needed for this test case? Since the test failed with the following output on my test setup(opensuse15.5 with 6.12 kernel):
> > >
> > > tst_hugepage.c:84: TINFO: 1 hugepage(s) reserved
> > > tst_tmpdir.c:317: TINFO: Using /tmp/LTP_hugLSJb7r as tmpdir (btrfs filesystem)
> > > tst_test.c:1100: TINFO: Mounting none to /tmp/LTP_hugLSJb7r/hugetlbfs fstyp=hugetlbfs flags=0
> > > tst_test.c:1890: TINFO: LTP version: 20240930
> > > tst_test.c:1894: TINFO: Tested kernel: 6.12.3-lp155.11.g78b0030-vanilla #1 SMP Fri Dec  6 08:56:39 UTC 2024 (78b0030) ppc64le
> > > tst_test.c:1727: TINFO: Timeout per run is 0h 00m 30s
> > > tst_coredump.c:32: TINFO: Avoid dumping corefile for process(pid=6671)
> > > hugemmap34.c:88: TBROK: waitpid(0,0x7fffd8baa220,0) failed: ECHILD (10)
> >
> > There's missing exit() in do_child(), but that's not the only issue
> > with the test.
> 
> Could you give this patch a try?
> 
> diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
> b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
> index a7a88fbb2..818697be8 100644
> --- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
> +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
> @@ -51,16 +51,23 @@ void do_child(void *stop_address)
>                 x = alloca(STACK_ALLOCATION_SIZE);
>                 *x = 1;
>         } while ((void *)x >= stop_address);
> +       exit(0);
>  }
> 
>  static void run_test(void)
>  {
>         int pid, status;
>         void *stack_address, *mmap_address, *heap_address, *map;
> +       char tmp[128];
> 
>         stack_address = alloca(0);
>         heap_address = sbrk(0);
> 
> +       tst_res(TINFO, "heap is at: %p", heap_address);
> +       tst_res(TINFO, "stack is at: %p", stack_address);
> +       sprintf(tmp, "cat /proc/%d/maps", getpid());
> +       TST_EXP_PASS_SILENT(system(tmp));
> +
>         /*
>          * paranoia: start mapping two hugepages below the start of the stack,
>          * in case the alignment would cause us to map over something if we
> @@ -70,6 +77,9 @@ static void run_test(void)
>         do {
>                 map = mmap(mmap_address, hpage_size, PROT_READ|PROT_WRITE,
>                                 MAP_SHARED | MAP_FIXED_NOREPLACE, fd, 0);
> +               if (map == mmap_address)
> +                       break;
> +
>                 if (map == MAP_FAILED) {
>                         if (errno == ENOMEM) {
>                                 tst_res(TCONF, "There is no enough
> memory in the system to do mmap");
> @@ -80,7 +90,12 @@ static void run_test(void)
>                 /*
>                  * if we get all the way down to the heap, stop trying
>                  */
> -       } while (mmap_address <= heap_address);
> +       } while (mmap_address > heap_address);
> +
> +       if (map == MAP_FAILED)
> +               tst_brk(TBROK, "failed to map hpage_size area before
> hitting heap");
> +       tst_res(TINFO, "mapped at %p", mmap);
> +
>         pid = SAFE_FORK();
>         if (pid == 0)
>                 do_child(mmap_address);
> 

Test will timeout if use default timeout so i do quick hack change for setup:
        .forks_child = 1,
+       .max_runtime = 3600,

Test result:

make -C "/root/ltp/lib" -f "/root/ltp/lib/Makefile" all
make[1]: Entering directory '/root/ltp/lib'
GEN ltp-version.h
make[2]: Nothing to be done for 'all'.
make[2]: Nothing to be done for 'all'.
make[1]: Leaving directory '/root/ltp/lib'
hugemmap34.c:150:1: warning: missing initializer for field ‘needs_cmds’ of ‘struct tst_test’ [-Wmissing-field-initializers]
 };
 ^
In file included from /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/../lib/hugetlb.h:19:0,
                 from hugemmap34.c:24:
../../../../../include/tst_test.h:593:21: note: ‘needs_cmds’ declared here
  const char *const *needs_cmds;
                     ^~~~~~~~~~
CC testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
tst_hugepage.c:84: TINFO: 1 hugepage(s) reserved
tst_tmpdir.c:317: TINFO: Using /tmp/LTP_hugkoiPEG as tmpdir (btrfs filesystem)
tst_test.c:1100: TINFO: Mounting none to /tmp/LTP_hugkoiPEG/hugetlbfs fstyp=hugetlbfs flags=0
tst_test.c:1890: TINFO: LTP version: 20240930
tst_test.c:1894: TINFO: Tested kernel: 6.12.3-lp155.11.g78b0030-vanilla #1 SMP Fri Dec  6 08:56:39 UTC 2024 (78b0030) ppc64le
tst_test.c:1727: TINFO: Timeout per run is 1h 00m 30s
hugemmap34.c:66: TINFO: heap is at: 0x1002af30000
hugemmap34.c:67: TINFO: stack is at: 0x7ffff97cab30
10000000-10040000 r-xp 00000000 00:29 11656                              /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
10040000-10050000 r--p 00030000 00:29 11656                              /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
10050000-10060000 rw-p 00040000 00:29 11656                              /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
10060000-10070000 rw-p 00000000 00:00 0
1002af00000-1002af30000 rw-p 00000000 00:00 0                            [heap]
7fff94b20000-7fff94d20000 r-xp 00000000 00:29 11464                      /lib64/libc-2.31.so
7fff94d20000-7fff94d30000 r--p 001f0000 00:29 11464                      /lib64/libc-2.31.so
7fff94d30000-7fff94d40000 rw-p 00200000 00:29 11464                      /lib64/libc-2.31.so
7fff94d40000-7fff94d70000 r-xp 00000000 00:29 11482                      /lib64/libpthread-2.31.so
7fff94d70000-7fff94d80000 r--p 00020000 00:29 11482                      /lib64/libpthread-2.31.so
7fff94d80000-7fff94d90000 rw-p 00030000 00:29 11482                      /lib64/libpthread-2.31.so
7fff94da0000-7fff94db0000 rw-s 00000000 00:17 9                          /dev/shm/ltp_hugemmap34_7730 (deleted)
7fff94db0000-7fff94dd0000 r--p 00000000 00:00 0                          [vvar]
7fff94dd0000-7fff94de0000 r-xp 00000000 00:00 0                          [vdso]
7fff94de0000-7fff94e20000 r-xp 00000000 00:29 11457                      /lib64/ld-2.31.so
7fff94e20000-7fff94e30000 r--p 00030000 00:29 11457                      /lib64/ld-2.31.so
7fff94e30000-7fff94e40000 rw-p 00040000 00:29 11457                      /lib64/ld-2.31.so
7ffff97a0000-7ffff97d0000 rw-p 00000000 00:00 0                          [stack]
hugemmap34.c:97: TINFO: mapped at 0x7fff94c51e80
tst_coredump.c:32: TINFO: Avoid dumping corefile for process(pid=7752)
hugemmap34.c:105: TPASS: Child killed by SIGSEGV as expected

Summary:
passed   1
failed   0
broken   0
skipped  0
warnings 0


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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] Question on hugemmap34
  2024-12-10 14:22     ` Wei Gao via ltp
@ 2024-12-11  3:20       ` Wei Gao via ltp
  2024-12-11  6:46         ` Jan Stancek
  0 siblings, 1 reply; 11+ messages in thread
From: Wei Gao via ltp @ 2024-12-11  3:20 UTC (permalink / raw)
  To: Jan Stancek; +Cc: samir, Michal Koutný, emunson, ltp

Hi Jan

Thanks for your quick support.
Since i use a kernel with my debug enabled so the test case timeout first
time, when i use normal kernel run the test case with your patch, the test
result show pass.
Then i guess you will send new separate patch for fix this later?

Regards
Gao Wei

On Tue, Dec 10, 2024 at 10:22 PM Wei Gao <wegao@suse.com> wrote:

> On Tue, Dec 10, 2024 at 02:25:06PM +0100, Jan Stancek wrote:
> > On Tue, Dec 10, 2024 at 1:54 PM Jan Stancek <jstancek@redhat.com> wrote:
> > >
> > > On Tue, Dec 10, 2024 at 12:53 PM Wei Gao <wegao@suse.com> wrote:
> > > >
> > > > Hi ALL
> > > >
> > > > Is there any special config needed for this test case? Since the
> test failed with the following output on my test setup(opensuse15.5 with
> 6.12 kernel):
> > > >
> > > > tst_hugepage.c:84: TINFO: 1 hugepage(s) reserved
> > > > tst_tmpdir.c:317: TINFO: Using /tmp/LTP_hugLSJb7r as tmpdir (btrfs
> filesystem)
> > > > tst_test.c:1100: TINFO: Mounting none to
> /tmp/LTP_hugLSJb7r/hugetlbfs fstyp=hugetlbfs flags=0
> > > > tst_test.c:1890: TINFO: LTP version: 20240930
> > > > tst_test.c:1894: TINFO: Tested kernel:
> 6.12.3-lp155.11.g78b0030-vanilla #1 SMP Fri Dec  6 08:56:39 UTC 2024
> (78b0030) ppc64le
> > > > tst_test.c:1727: TINFO: Timeout per run is 0h 00m 30s
> > > > tst_coredump.c:32: TINFO: Avoid dumping corefile for
> process(pid=6671)
> > > > hugemmap34.c:88: TBROK: waitpid(0,0x7fffd8baa220,0) failed: ECHILD
> (10)
> > >
> > > There's missing exit() in do_child(), but that's not the only issue
> > > with the test.
> >
> > Could you give this patch a try?
> >
> > diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
> > b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
> > index a7a88fbb2..818697be8 100644
> > --- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
> > +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
> > @@ -51,16 +51,23 @@ void do_child(void *stop_address)
> >                 x = alloca(STACK_ALLOCATION_SIZE);
> >                 *x = 1;
> >         } while ((void *)x >= stop_address);
> > +       exit(0);
> >  }
> >
> >  static void run_test(void)
> >  {
> >         int pid, status;
> >         void *stack_address, *mmap_address, *heap_address, *map;
> > +       char tmp[128];
> >
> >         stack_address = alloca(0);
> >         heap_address = sbrk(0);
> >
> > +       tst_res(TINFO, "heap is at: %p", heap_address);
> > +       tst_res(TINFO, "stack is at: %p", stack_address);
> > +       sprintf(tmp, "cat /proc/%d/maps", getpid());
> > +       TST_EXP_PASS_SILENT(system(tmp));
> > +
> >         /*
> >          * paranoia: start mapping two hugepages below the start of the
> stack,
> >          * in case the alignment would cause us to map over something if
> we
> > @@ -70,6 +77,9 @@ static void run_test(void)
> >         do {
> >                 map = mmap(mmap_address, hpage_size,
> PROT_READ|PROT_WRITE,
> >                                 MAP_SHARED | MAP_FIXED_NOREPLACE, fd, 0);
> > +               if (map == mmap_address)
> > +                       break;
> > +
> >                 if (map == MAP_FAILED) {
> >                         if (errno == ENOMEM) {
> >                                 tst_res(TCONF, "There is no enough
> > memory in the system to do mmap");
> > @@ -80,7 +90,12 @@ static void run_test(void)
> >                 /*
> >                  * if we get all the way down to the heap, stop trying
> >                  */
> > -       } while (mmap_address <= heap_address);
> > +       } while (mmap_address > heap_address);
> > +
> > +       if (map == MAP_FAILED)
> > +               tst_brk(TBROK, "failed to map hpage_size area before
> > hitting heap");
> > +       tst_res(TINFO, "mapped at %p", mmap);
> > +
> >         pid = SAFE_FORK();
> >         if (pid == 0)
> >                 do_child(mmap_address);
> >
>
> Test will timeout if use default timeout so i do quick hack change for
> setup:
>         .forks_child = 1,
> +       .max_runtime = 3600,
>
> Test result:
>
> make -C "/root/ltp/lib" -f "/root/ltp/lib/Makefile" all
> make[1]: Entering directory '/root/ltp/lib'
> GEN ltp-version.h
> make[2]: Nothing to be done for 'all'.
> make[2]: Nothing to be done for 'all'.
> make[1]: Leaving directory '/root/ltp/lib'
> hugemmap34.c:150:1: warning: missing initializer for field ‘needs_cmds’ of
> ‘struct tst_test’ [-Wmissing-field-initializers]
>  };
>  ^
> In file included from
> /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/../lib/hugetlb.h:19:0,
>                  from hugemmap34.c:24:
> ../../../../../include/tst_test.h:593:21: note: ‘needs_cmds’ declared here
>   const char *const *needs_cmds;
>                      ^~~~~~~~~~
> CC testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
> tst_hugepage.c:84: TINFO: 1 hugepage(s) reserved
> tst_tmpdir.c:317: TINFO: Using /tmp/LTP_hugkoiPEG as tmpdir (btrfs
> filesystem)
> tst_test.c:1100: TINFO: Mounting none to /tmp/LTP_hugkoiPEG/hugetlbfs
> fstyp=hugetlbfs flags=0
> tst_test.c:1890: TINFO: LTP version: 20240930
> tst_test.c:1894: TINFO: Tested kernel: 6.12.3-lp155.11.g78b0030-vanilla #1
> SMP Fri Dec  6 08:56:39 UTC 2024 (78b0030) ppc64le
> tst_test.c:1727: TINFO: Timeout per run is 1h 00m 30s
> hugemmap34.c:66: TINFO: heap is at: 0x1002af30000
> hugemmap34.c:67: TINFO: stack is at: 0x7ffff97cab30
> 10000000-10040000 r-xp 00000000 00:29 11656
> /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
> 10040000-10050000 r--p 00030000 00:29 11656
> /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
> 10050000-10060000 rw-p 00040000 00:29 11656
> /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
> 10060000-10070000 rw-p 00000000 00:00 0
> 1002af00000-1002af30000 rw-p 00000000 00:00 0
> [heap]
> 7fff94b20000-7fff94d20000 r-xp 00000000 00:29 11464
> /lib64/libc-2.31.so
> 7fff94d20000-7fff94d30000 r--p 001f0000 00:29 11464
> /lib64/libc-2.31.so
> 7fff94d30000-7fff94d40000 rw-p 00200000 00:29 11464
> /lib64/libc-2.31.so
> 7fff94d40000-7fff94d70000 r-xp 00000000 00:29 11482
> /lib64/libpthread-2.31.so
> 7fff94d70000-7fff94d80000 r--p 00020000 00:29 11482
> /lib64/libpthread-2.31.so
> 7fff94d80000-7fff94d90000 rw-p 00030000 00:29 11482
> /lib64/libpthread-2.31.so
> 7fff94da0000-7fff94db0000 rw-s 00000000 00:17 9
> /dev/shm/ltp_hugemmap34_7730 (deleted)
> 7fff94db0000-7fff94dd0000 r--p 00000000 00:00 0
> [vvar]
> 7fff94dd0000-7fff94de0000 r-xp 00000000 00:00 0
> [vdso]
> 7fff94de0000-7fff94e20000 r-xp 00000000 00:29 11457
> /lib64/ld-2.31.so
> 7fff94e20000-7fff94e30000 r--p 00030000 00:29 11457
> /lib64/ld-2.31.so
> 7fff94e30000-7fff94e40000 rw-p 00040000 00:29 11457
> /lib64/ld-2.31.so
> 7ffff97a0000-7ffff97d0000 rw-p 00000000 00:00 0
> [stack]
> hugemmap34.c:97: TINFO: mapped at 0x7fff94c51e80
> tst_coredump.c:32: TINFO: Avoid dumping corefile for process(pid=7752)
> hugemmap34.c:105: TPASS: Child killed by SIGSEGV as expected
>
> Summary:
> passed   1
> failed   0
> broken   0
> skipped  0
> warnings 0
>
>

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] Question on hugemmap34
  2024-12-11  3:20       ` Wei Gao via ltp
@ 2024-12-11  6:46         ` Jan Stancek
  2024-12-11 10:49           ` Jan Stancek
  2024-12-12  9:29           ` [LTP] [PATCH] hugemmap34: change how test finds suitable huge page and stack for test Jan Stancek
  0 siblings, 2 replies; 11+ messages in thread
From: Jan Stancek @ 2024-12-11  6:46 UTC (permalink / raw)
  To: Wei Gao; +Cc: samir, Michal Koutný, emunson, ltp

On Wed, Dec 11, 2024 at 4:21 AM Wei Gao <wegao@suse.com> wrote:
>
> Hi Jan
>
> Thanks for your quick support.
> Since i use a kernel with my debug enabled so the test case timeout first time, when i use normal kernel run the test case with your patch, the test result show pass.
> Then i guess you will send new separate patch for fix this later?

I'm thinking if we can rewrite it with clone(), so that we can set up
stack and hugepage for the child reliably.

Right now, "the mmap search" is slow, and we end up with address
that's "too far". In your example
the child crashes long before it comes near the area test mapped.

Also the original test is mapping from libhugetlfs and LTP port just
maps a temp file.

>
> Regards
> Gao Wei
>
> On Tue, Dec 10, 2024 at 10:22 PM Wei Gao <wegao@suse.com> wrote:
>>
>> On Tue, Dec 10, 2024 at 02:25:06PM +0100, Jan Stancek wrote:
>> > On Tue, Dec 10, 2024 at 1:54 PM Jan Stancek <jstancek@redhat.com> wrote:
>> > >
>> > > On Tue, Dec 10, 2024 at 12:53 PM Wei Gao <wegao@suse.com> wrote:
>> > > >
>> > > > Hi ALL
>> > > >
>> > > > Is there any special config needed for this test case? Since the test failed with the following output on my test setup(opensuse15.5 with 6.12 kernel):
>> > > >
>> > > > tst_hugepage.c:84: TINFO: 1 hugepage(s) reserved
>> > > > tst_tmpdir.c:317: TINFO: Using /tmp/LTP_hugLSJb7r as tmpdir (btrfs filesystem)
>> > > > tst_test.c:1100: TINFO: Mounting none to /tmp/LTP_hugLSJb7r/hugetlbfs fstyp=hugetlbfs flags=0
>> > > > tst_test.c:1890: TINFO: LTP version: 20240930
>> > > > tst_test.c:1894: TINFO: Tested kernel: 6.12.3-lp155.11.g78b0030-vanilla #1 SMP Fri Dec  6 08:56:39 UTC 2024 (78b0030) ppc64le
>> > > > tst_test.c:1727: TINFO: Timeout per run is 0h 00m 30s
>> > > > tst_coredump.c:32: TINFO: Avoid dumping corefile for process(pid=6671)
>> > > > hugemmap34.c:88: TBROK: waitpid(0,0x7fffd8baa220,0) failed: ECHILD (10)
>> > >
>> > > There's missing exit() in do_child(), but that's not the only issue
>> > > with the test.
>> >
>> > Could you give this patch a try?
>> >
>> > diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
>> > b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
>> > index a7a88fbb2..818697be8 100644
>> > --- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
>> > +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
>> > @@ -51,16 +51,23 @@ void do_child(void *stop_address)
>> >                 x = alloca(STACK_ALLOCATION_SIZE);
>> >                 *x = 1;
>> >         } while ((void *)x >= stop_address);
>> > +       exit(0);
>> >  }
>> >
>> >  static void run_test(void)
>> >  {
>> >         int pid, status;
>> >         void *stack_address, *mmap_address, *heap_address, *map;
>> > +       char tmp[128];
>> >
>> >         stack_address = alloca(0);
>> >         heap_address = sbrk(0);
>> >
>> > +       tst_res(TINFO, "heap is at: %p", heap_address);
>> > +       tst_res(TINFO, "stack is at: %p", stack_address);
>> > +       sprintf(tmp, "cat /proc/%d/maps", getpid());
>> > +       TST_EXP_PASS_SILENT(system(tmp));
>> > +
>> >         /*
>> >          * paranoia: start mapping two hugepages below the start of the stack,
>> >          * in case the alignment would cause us to map over something if we
>> > @@ -70,6 +77,9 @@ static void run_test(void)
>> >         do {
>> >                 map = mmap(mmap_address, hpage_size, PROT_READ|PROT_WRITE,
>> >                                 MAP_SHARED | MAP_FIXED_NOREPLACE, fd, 0);
>> > +               if (map == mmap_address)
>> > +                       break;
>> > +
>> >                 if (map == MAP_FAILED) {
>> >                         if (errno == ENOMEM) {
>> >                                 tst_res(TCONF, "There is no enough
>> > memory in the system to do mmap");
>> > @@ -80,7 +90,12 @@ static void run_test(void)
>> >                 /*
>> >                  * if we get all the way down to the heap, stop trying
>> >                  */
>> > -       } while (mmap_address <= heap_address);
>> > +       } while (mmap_address > heap_address);
>> > +
>> > +       if (map == MAP_FAILED)
>> > +               tst_brk(TBROK, "failed to map hpage_size area before
>> > hitting heap");
>> > +       tst_res(TINFO, "mapped at %p", mmap);
>> > +
>> >         pid = SAFE_FORK();
>> >         if (pid == 0)
>> >                 do_child(mmap_address);
>> >
>>
>> Test will timeout if use default timeout so i do quick hack change for setup:
>>         .forks_child = 1,
>> +       .max_runtime = 3600,
>>
>> Test result:
>>
>> make -C "/root/ltp/lib" -f "/root/ltp/lib/Makefile" all
>> make[1]: Entering directory '/root/ltp/lib'
>> GEN ltp-version.h
>> make[2]: Nothing to be done for 'all'.
>> make[2]: Nothing to be done for 'all'.
>> make[1]: Leaving directory '/root/ltp/lib'
>> hugemmap34.c:150:1: warning: missing initializer for field ‘needs_cmds’ of ‘struct tst_test’ [-Wmissing-field-initializers]
>>  };
>>  ^
>> In file included from /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/../lib/hugetlb.h:19:0,
>>                  from hugemmap34.c:24:
>> ../../../../../include/tst_test.h:593:21: note: ‘needs_cmds’ declared here
>>   const char *const *needs_cmds;
>>                      ^~~~~~~~~~
>> CC testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
>> tst_hugepage.c:84: TINFO: 1 hugepage(s) reserved
>> tst_tmpdir.c:317: TINFO: Using /tmp/LTP_hugkoiPEG as tmpdir (btrfs filesystem)
>> tst_test.c:1100: TINFO: Mounting none to /tmp/LTP_hugkoiPEG/hugetlbfs fstyp=hugetlbfs flags=0
>> tst_test.c:1890: TINFO: LTP version: 20240930
>> tst_test.c:1894: TINFO: Tested kernel: 6.12.3-lp155.11.g78b0030-vanilla #1 SMP Fri Dec  6 08:56:39 UTC 2024 (78b0030) ppc64le
>> tst_test.c:1727: TINFO: Timeout per run is 1h 00m 30s
>> hugemmap34.c:66: TINFO: heap is at: 0x1002af30000
>> hugemmap34.c:67: TINFO: stack is at: 0x7ffff97cab30
>> 10000000-10040000 r-xp 00000000 00:29 11656                              /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
>> 10040000-10050000 r--p 00030000 00:29 11656                              /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
>> 10050000-10060000 rw-p 00040000 00:29 11656                              /root/ltp/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34
>> 10060000-10070000 rw-p 00000000 00:00 0
>> 1002af00000-1002af30000 rw-p 00000000 00:00 0                            [heap]
>> 7fff94b20000-7fff94d20000 r-xp 00000000 00:29 11464                      /lib64/libc-2.31.so
>> 7fff94d20000-7fff94d30000 r--p 001f0000 00:29 11464                      /lib64/libc-2.31.so
>> 7fff94d30000-7fff94d40000 rw-p 00200000 00:29 11464                      /lib64/libc-2.31.so
>> 7fff94d40000-7fff94d70000 r-xp 00000000 00:29 11482                      /lib64/libpthread-2.31.so
>> 7fff94d70000-7fff94d80000 r--p 00020000 00:29 11482                      /lib64/libpthread-2.31.so
>> 7fff94d80000-7fff94d90000 rw-p 00030000 00:29 11482                      /lib64/libpthread-2.31.so
>> 7fff94da0000-7fff94db0000 rw-s 00000000 00:17 9                          /dev/shm/ltp_hugemmap34_7730 (deleted)
>> 7fff94db0000-7fff94dd0000 r--p 00000000 00:00 0                          [vvar]
>> 7fff94dd0000-7fff94de0000 r-xp 00000000 00:00 0                          [vdso]
>> 7fff94de0000-7fff94e20000 r-xp 00000000 00:29 11457                      /lib64/ld-2.31.so
>> 7fff94e20000-7fff94e30000 r--p 00030000 00:29 11457                      /lib64/ld-2.31.so
>> 7fff94e30000-7fff94e40000 rw-p 00040000 00:29 11457                      /lib64/ld-2.31.so
>> 7ffff97a0000-7ffff97d0000 rw-p 00000000 00:00 0                          [stack]
>> hugemmap34.c:97: TINFO: mapped at 0x7fff94c51e80
>> tst_coredump.c:32: TINFO: Avoid dumping corefile for process(pid=7752)
>> hugemmap34.c:105: TPASS: Child killed by SIGSEGV as expected
>>
>> Summary:
>> passed   1
>> failed   0
>> broken   0
>> skipped  0
>> warnings 0
>>


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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] Question on hugemmap34
  2024-12-11  6:46         ` Jan Stancek
@ 2024-12-11 10:49           ` Jan Stancek
  2024-12-12  9:29           ` [LTP] [PATCH] hugemmap34: change how test finds suitable huge page and stack for test Jan Stancek
  1 sibling, 0 replies; 11+ messages in thread
From: Jan Stancek @ 2024-12-11 10:49 UTC (permalink / raw)
  To: Wei Gao; +Cc: samir, Michal Koutný, emunson, ltp

On Wed, Dec 11, 2024 at 7:46 AM Jan Stancek <jstancek@redhat.com> wrote:
>
> On Wed, Dec 11, 2024 at 4:21 AM Wei Gao <wegao@suse.com> wrote:
> >
> > Hi Jan
> >
> > Thanks for your quick support.
> > Since i use a kernel with my debug enabled so the test case timeout first time, when i use normal kernel run the test case with your patch, the test result show pass.
> > Then i guess you will send new separate patch for fix this later?
>
> I'm thinking if we can rewrite it with clone(), so that we can set up
> stack and hugepage for the child reliably.
>
> Right now, "the mmap search" is slow, and we end up with address
> that's "too far". In your example
> the child crashes long before it comes near the area test mapped.
>
> Also the original test is mapping from libhugetlfs and LTP port just
> maps a temp file.

My bad about this last part - there's actually needs_hugetlbfs = 1 in the test
that I missed. Anyway, I'll give the clone() approach a try.


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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [LTP] [PATCH] hugemmap34: change how test finds suitable huge page and stack for test
  2024-12-11  6:46         ` Jan Stancek
  2024-12-11 10:49           ` Jan Stancek
@ 2024-12-12  9:29           ` Jan Stancek
  2024-12-12 13:04             ` Cyril Hrubis
  1 sibling, 1 reply; 11+ messages in thread
From: Jan Stancek @ 2024-12-12  9:29 UTC (permalink / raw)
  To: ltp, wegao; +Cc: samir, mkoutny, emunson

The test is trying to find a place for huge page with mmap(MAP_FIXED_NOREPLACE)
starting at top of stack and going downwards until it succeeds. The problem
is that before it finds one, it goes over other existing mappings. So, child
process does crash when trying to extend stack, but not because it hits
mapped huge page, it hits one of the existing mappings. This search is slow,
specially on -debug kernels.

This patch changes the test, by giving child process a separate stack that is
always immediately above a huge page. Setup temporarily allocates huge pages and
uses those addresses to map potential child stacks. When it allocates huge page
and finds that mapping after it is one of child stacks, it uses that pair
for the test.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 .../kernel/mem/hugetlb/hugemmap/hugemmap34.c  | 151 ++++++++++++++----
 1 file changed, 118 insertions(+), 33 deletions(-)

diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
index a7a88fbb2d9e..91b070a8462e 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
@@ -20,25 +20,32 @@
  * huge page-only segment -- resulting in bugs.
  */
 
+#define _GNU_SOURCE
 #include "lapi/mmap.h"
 #include "hugetlb.h"
 #include <errno.h>
+#include <inttypes.h>
+#include <sched.h>
 
 #ifdef __LP64__
 #define STACK_ALLOCATION_SIZE	(256*1024*1024)
 #else
 #define STACK_ALLOCATION_SIZE	(16*1024*1024)
 #endif
-#define PALIGN(p, a) ((void *)LTP_ALIGN((unsigned long)(p), (a)))
 #define MNTPOINT "hugetlbfs/"
-static int  fd = -1;
-static unsigned long long hpage_size;
-static int page_size;
+#define PATH_HUGEPAGE "/sys/kernel/mm/hugepages"
+
+#define STACKS_MAX 64
 
+static int  fd = -1;
+static uintptr_t hpage_size, stacks[STACKS_MAX];
+static int stacks_num;
+static void *hpage_addr, *stack_addr;
+static void **shared_area;
 
-void do_child(void *stop_address)
+int do_child(void *stop_address)
 {
-	volatile int *x;
+	volatile char *x;
 
 	/* corefile from this process is not interesting and limiting
 	 * its size can save a lot of time. '1' is a special value,
@@ -46,57 +53,77 @@ void do_child(void *stop_address)
 	 * sets limit to RLIM_INFINITY.
 	 */
 	tst_no_corefile(1);
+	tst_res(TINFO, "Child process starting with top of stack at %p", &x);
 
 	do {
 		x = alloca(STACK_ALLOCATION_SIZE);
+		*shared_area = (void *)x;
 		*x = 1;
 	} while ((void *)x >= stop_address);
+	exit(0);
 }
 
 static void run_test(void)
 {
 	int pid, status;
-	void *stack_address, *mmap_address, *heap_address, *map;
 
-	stack_address = alloca(0);
-	heap_address = sbrk(0);
-
-	/*
-	 * paranoia: start mapping two hugepages below the start of the stack,
-	 * in case the alignment would cause us to map over something if we
-	 * only used a gap of one hugepage.
-	 */
-	mmap_address = PALIGN(stack_address - 2 * hpage_size, hpage_size);
-	do {
-		map = mmap(mmap_address, hpage_size, PROT_READ|PROT_WRITE,
-				MAP_SHARED | MAP_FIXED_NOREPLACE, fd, 0);
-		if (map == MAP_FAILED) {
-			if (errno == ENOMEM) {
-				tst_res(TCONF, "There is no enough memory in the system to do mmap");
-				return;
-			}
-		}
-		mmap_address -= hpage_size;
-		/*
-		 * if we get all the way down to the heap, stop trying
-		 */
-	} while (mmap_address <= heap_address);
-	pid = SAFE_FORK();
+	pid = ltp_clone(CLONE_VM | CLONE_VFORK | SIGCHLD, do_child,
+		hpage_addr, hpage_size, stack_addr);
 	if (pid == 0)
-		do_child(mmap_address);
+		do_child(hpage_addr);
 
 	SAFE_WAITPID(pid, &status, 0);
+	tst_res(TINFO, "Child process extended stack up to %p, failed at %p",
+		*shared_area, *shared_area - STACK_ALLOCATION_SIZE);
 	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV)
 		tst_res(TPASS, "Child killed by %s as expected", tst_strsig(SIGSEGV));
 	else
 		tst_res(TFAIL, "Child: %s", tst_strstatus(status));
 }
 
+/* Return start address of next mapping or 0 */
+static uintptr_t  get_next_mapping_start(uintptr_t addr)
+{
+	FILE *fp = fopen("/proc/self/maps", "r");
+
+	if (fp == NULL)
+		tst_brk(TBROK | TERRNO, "Failed to open /proc/self/maps.");
+
+	while (!feof(fp)) {
+		uintptr_t start, end;
+		int ret;
+
+		ret = fscanf(fp, "%"PRIxPTR"-%"PRIxPTR" %*[^\n]\n", &start, &end);
+		if (ret != 2) {
+			fclose(fp);
+			tst_brk(TBROK | TERRNO, "Couldn't parse /proc/self/maps line.");
+		}
+
+		if (start > addr) {
+			fclose(fp);
+			return start;
+		}
+	}
+	fclose(fp);
+	return 0;
+}
+
+static int is_addr_in_stacks(uintptr_t addr)
+{
+	int i;
+
+	for (i = 0; i < stacks_num; i++) {
+		if (addr == stacks[i])
+			return 1;
+	}
+	return 0;
+}
+
 void setup(void)
 {
 	struct rlimit r;
+	int i;
 
-	page_size = getpagesize();
 	hpage_size = tst_get_hugepage_size();
 	/*
 	 * Setting the stack size to unlimited.
@@ -107,7 +134,65 @@ void setup(void)
 	SAFE_GETRLIMIT(RLIMIT_STACK, &r);
 	if (r.rlim_cur != RLIM_INFINITY)
 		tst_brk(TCONF, "Stack rlimit must be 'unlimited'");
+
+	if (access(PATH_HUGEPAGE, F_OK))
+		tst_brk(TCONF, "hugetlbfs is not supported");
+
 	fd = tst_creat_unlinked(MNTPOINT, 0);
+
+	/* shared memory to pass a (void *) from child process */
+	shared_area = SAFE_MMAP(0, getpagesize(), PROT_READ|PROT_WRITE,
+		MAP_SHARED|MAP_ANONYMOUS, -1, 0);
+
+	/*
+	 * We search for potential stack addresses by looking at
+	 * places where kernel would map next huge page and occupying that
+	 * address as potential stack. When huge page lands in such place
+	 * that next mapping is one of our stack mappings, we use those
+	 * two for the test. We try to map huge pages in child process so that
+	 * slices in parent are not affected.
+	 */
+	tst_res(TINFO, "searching for huge page and child stack placement");
+	for (i = 0; i < STACKS_MAX; i++) {
+		uintptr_t next_start;
+		int pid, status;
+
+		pid = SAFE_FORK();
+		if (pid == 0) {
+			*shared_area = SAFE_MMAP(0, hpage_size, PROT_READ|PROT_WRITE,
+				MAP_PRIVATE, fd, 0);
+			SAFE_MUNMAP(*shared_area, hpage_size);
+			exit(0);
+		}
+		SAFE_WAITPID(pid, &status, 0);
+		if (status != 0)
+			tst_brk(TFAIL, "Child: %s", tst_strstatus(status));
+
+		next_start = get_next_mapping_start((uintptr_t)*shared_area);
+		if (is_addr_in_stacks(next_start)) {
+			stack_addr = (void *)next_start;
+			hpage_addr = *shared_area;
+			break;
+		}
+
+		tst_res(TINFO, "potential stack at address %p", *shared_area);
+		stacks[stacks_num++] = (uintptr_t) SAFE_MMAP(*shared_area, hpage_size,
+			PROT_READ|PROT_WRITE,
+			MAP_ANONYMOUS|MAP_PRIVATE|MAP_GROWSDOWN, -1, 0);
+	}
+
+	if (!stack_addr)
+		tst_brk(TCONF, "failed to find good place for huge page and stack");
+
+	hpage_addr = mmap(hpage_addr, hpage_size, PROT_READ|PROT_WRITE,
+		MAP_SHARED|MAP_FIXED, fd, 0);
+	if (hpage_addr == MAP_FAILED) {
+		if (errno == ENOMEM)
+			tst_brk(TCONF, "Not enough memory.");
+		tst_brk(TBROK|TERRNO, "mmap failed");
+	}
+	tst_res(TINFO, "huge page is at address %p", hpage_addr);
+	tst_res(TINFO, "using stack is at address %p", stack_addr);
 }
 
 void cleanup(void)
-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH] hugemmap34: change how test finds suitable huge page and stack for test
  2024-12-12  9:29           ` [LTP] [PATCH] hugemmap34: change how test finds suitable huge page and stack for test Jan Stancek
@ 2024-12-12 13:04             ` Cyril Hrubis
  2024-12-13  4:09               ` Wei Gao via ltp
  2024-12-13  7:27               ` Jan Stancek
  0 siblings, 2 replies; 11+ messages in thread
From: Cyril Hrubis @ 2024-12-12 13:04 UTC (permalink / raw)
  To: Jan Stancek; +Cc: samir, mkoutny, emunson, ltp

Hi!
> Signed-off-by: Jan Stancek <jstancek@redhat.com>
> ---
>  .../kernel/mem/hugetlb/hugemmap/hugemmap34.c  | 151 ++++++++++++++----
>  1 file changed, 118 insertions(+), 33 deletions(-)
> 
> diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
> index a7a88fbb2d9e..91b070a8462e 100644
> --- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
> +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
> @@ -20,25 +20,32 @@
>   * huge page-only segment -- resulting in bugs.
>   */
>  
> +#define _GNU_SOURCE
>  #include "lapi/mmap.h"
>  #include "hugetlb.h"
>  #include <errno.h>
> +#include <inttypes.h>
> +#include <sched.h>
>  
>  #ifdef __LP64__
>  #define STACK_ALLOCATION_SIZE	(256*1024*1024)
>  #else
>  #define STACK_ALLOCATION_SIZE	(16*1024*1024)
>  #endif
> -#define PALIGN(p, a) ((void *)LTP_ALIGN((unsigned long)(p), (a)))
>  #define MNTPOINT "hugetlbfs/"
> -static int  fd = -1;
> -static unsigned long long hpage_size;
> -static int page_size;
> +#define PATH_HUGEPAGE "/sys/kernel/mm/hugepages"
> +
> +#define STACKS_MAX 64
>  
> +static int  fd = -1;
> +static uintptr_t hpage_size, stacks[STACKS_MAX];
> +static int stacks_num;
> +static void *hpage_addr, *stack_addr;
> +static void **shared_area;
>  
> -void do_child(void *stop_address)
> +int do_child(void *stop_address)
>  {
> -	volatile int *x;
> +	volatile char *x;
>  
>  	/* corefile from this process is not interesting and limiting
>  	 * its size can save a lot of time. '1' is a special value,
> @@ -46,57 +53,77 @@ void do_child(void *stop_address)
>  	 * sets limit to RLIM_INFINITY.
>  	 */
>  	tst_no_corefile(1);
> +	tst_res(TINFO, "Child process starting with top of stack at %p", &x);
>  
>  	do {
>  		x = alloca(STACK_ALLOCATION_SIZE);
> +		*shared_area = (void *)x;
>  		*x = 1;
>  	} while ((void *)x >= stop_address);
> +	exit(0);
>  }
>  
>  static void run_test(void)
>  {
>  	int pid, status;
> -	void *stack_address, *mmap_address, *heap_address, *map;
>  
> -	stack_address = alloca(0);
> -	heap_address = sbrk(0);
> -
> -	/*
> -	 * paranoia: start mapping two hugepages below the start of the stack,
> -	 * in case the alignment would cause us to map over something if we
> -	 * only used a gap of one hugepage.
> -	 */
> -	mmap_address = PALIGN(stack_address - 2 * hpage_size, hpage_size);
> -	do {
> -		map = mmap(mmap_address, hpage_size, PROT_READ|PROT_WRITE,
> -				MAP_SHARED | MAP_FIXED_NOREPLACE, fd, 0);
> -		if (map == MAP_FAILED) {
> -			if (errno == ENOMEM) {
> -				tst_res(TCONF, "There is no enough memory in the system to do mmap");
> -				return;
> -			}
> -		}
> -		mmap_address -= hpage_size;
> -		/*
> -		 * if we get all the way down to the heap, stop trying
> -		 */
> -	} while (mmap_address <= heap_address);
> -	pid = SAFE_FORK();
> +	pid = ltp_clone(CLONE_VM | CLONE_VFORK | SIGCHLD, do_child,
> +		hpage_addr, hpage_size, stack_addr);
>  	if (pid == 0)
> -		do_child(mmap_address);
> +		do_child(hpage_addr);
>  
>  	SAFE_WAITPID(pid, &status, 0);
> +	tst_res(TINFO, "Child process extended stack up to %p, failed at %p",
> +		*shared_area, *shared_area - STACK_ALLOCATION_SIZE);
>  	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV)
>  		tst_res(TPASS, "Child killed by %s as expected", tst_strsig(SIGSEGV));
>  	else
>  		tst_res(TFAIL, "Child: %s", tst_strstatus(status));
>  }
>  
> +/* Return start address of next mapping or 0 */
> +static uintptr_t  get_next_mapping_start(uintptr_t addr)
> +{
> +	FILE *fp = fopen("/proc/self/maps", "r");
> +
> +	if (fp == NULL)
> +		tst_brk(TBROK | TERRNO, "Failed to open /proc/self/maps.");
> +
> +	while (!feof(fp)) {
> +		uintptr_t start, end;
> +		int ret;
> +
> +		ret = fscanf(fp, "%"PRIxPTR"-%"PRIxPTR" %*[^\n]\n", &start, &end);
> +		if (ret != 2) {
> +			fclose(fp);
> +			tst_brk(TBROK | TERRNO, "Couldn't parse /proc/self/maps line.");
> +		}
> +
> +		if (start > addr) {
> +			fclose(fp);
> +			return start;
> +		}
> +	}
> +	fclose(fp);
> +	return 0;
> +}

Maybe we could read this once and cache it because besides of the
additions of the potential stack mappings it would not change, but I
guess that it's not worth of the effort.

> +static int is_addr_in_stacks(uintptr_t addr)
> +{
> +	int i;
> +
> +	for (i = 0; i < stacks_num; i++) {
> +		if (addr == stacks[i])
> +			return 1;
> +	}
> +	return 0;
> +}
> +
>  void setup(void)
>  {
>  	struct rlimit r;
> +	int i;
>  
> -	page_size = getpagesize();
>  	hpage_size = tst_get_hugepage_size();
>  	/*
>  	 * Setting the stack size to unlimited.
> @@ -107,7 +134,65 @@ void setup(void)
>  	SAFE_GETRLIMIT(RLIMIT_STACK, &r);
>  	if (r.rlim_cur != RLIM_INFINITY)
>  		tst_brk(TCONF, "Stack rlimit must be 'unlimited'");
> +
> +	if (access(PATH_HUGEPAGE, F_OK))
> +		tst_brk(TCONF, "hugetlbfs is not supported");

Hmm, we have .needs_hugetlbfs in the tst_test structure that isn't
enough? Maybe the test library needs to be fixed then?

>  	fd = tst_creat_unlinked(MNTPOINT, 0);
> +
> +	/* shared memory to pass a (void *) from child process */
> +	shared_area = SAFE_MMAP(0, getpagesize(), PROT_READ|PROT_WRITE,
> +		MAP_SHARED|MAP_ANONYMOUS, -1, 0);
> +
> +	/*
> +	 * We search for potential stack addresses by looking at
> +	 * places where kernel would map next huge page and occupying that
> +	 * address as potential stack. When huge page lands in such place
> +	 * that next mapping is one of our stack mappings, we use those
> +	 * two for the test. We try to map huge pages in child process so that
> +	 * slices in parent are not affected.
> +	 */
> +	tst_res(TINFO, "searching for huge page and child stack placement");
> +	for (i = 0; i < STACKS_MAX; i++) {
> +		uintptr_t next_start;
> +		int pid, status;
> +
> +		pid = SAFE_FORK();
> +		if (pid == 0) {
> +			*shared_area = SAFE_MMAP(0, hpage_size, PROT_READ|PROT_WRITE,
> +				MAP_PRIVATE, fd, 0);
> +			SAFE_MUNMAP(*shared_area, hpage_size);
> +			exit(0);
> +		}
> +		SAFE_WAITPID(pid, &status, 0);
> +		if (status != 0)
> +			tst_brk(TFAIL, "Child: %s", tst_strstatus(status));
> +
> +		next_start = get_next_mapping_start((uintptr_t)*shared_area);
> +		if (is_addr_in_stacks(next_start)) {
> +			stack_addr = (void *)next_start;
> +			hpage_addr = *shared_area;
> +			break;
> +		}
> +
> +		tst_res(TINFO, "potential stack at address %p", *shared_area);
> +		stacks[stacks_num++] = (uintptr_t) SAFE_MMAP(*shared_area, hpage_size,
> +			PROT_READ|PROT_WRITE,
> +			MAP_ANONYMOUS|MAP_PRIVATE|MAP_GROWSDOWN, -1, 0);
> +	}
> +
> +	if (!stack_addr)
> +		tst_brk(TCONF, "failed to find good place for huge page and stack");
> +
> +	hpage_addr = mmap(hpage_addr, hpage_size, PROT_READ|PROT_WRITE,
> +		MAP_SHARED|MAP_FIXED, fd, 0);
> +	if (hpage_addr == MAP_FAILED) {
> +		if (errno == ENOMEM)
> +			tst_brk(TCONF, "Not enough memory.");
> +		tst_brk(TBROK|TERRNO, "mmap failed");
> +	}
> +	tst_res(TINFO, "huge page is at address %p", hpage_addr);
> +	tst_res(TINFO, "using stack is at address %p", stack_addr);

Maybe just one:

tst_res(TINFO, "stack addr = %p huge page addr = %p", ...);


Overall this looks much better than the original:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH] hugemmap34: change how test finds suitable huge page and stack for test
  2024-12-12 13:04             ` Cyril Hrubis
@ 2024-12-13  4:09               ` Wei Gao via ltp
  2024-12-13  7:27               ` Jan Stancek
  1 sibling, 0 replies; 11+ messages in thread
From: Wei Gao via ltp @ 2024-12-13  4:09 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: samir, mkoutny, ltp, emunson

Hi, Jan

Thanks for your new patch, test on my setup and result is pass.

Reviewed-by: Wei Gao <wegao@suse.com>

Regards
Gao Wei

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH] hugemmap34: change how test finds suitable huge page and stack for test
  2024-12-12 13:04             ` Cyril Hrubis
  2024-12-13  4:09               ` Wei Gao via ltp
@ 2024-12-13  7:27               ` Jan Stancek
  1 sibling, 0 replies; 11+ messages in thread
From: Jan Stancek @ 2024-12-13  7:27 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: samir, mkoutny, emunson, ltp

On Thu, Dec 12, 2024 at 2:04 PM Cyril Hrubis <chrubis@suse.cz> wrote:
>
> Hi!
> > Signed-off-by: Jan Stancek <jstancek@redhat.com>
> > ---
> >  .../kernel/mem/hugetlb/hugemmap/hugemmap34.c  | 151 ++++++++++++++----
> >  1 file changed, 118 insertions(+), 33 deletions(-)
> >
> > diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
> > index a7a88fbb2d9e..91b070a8462e 100644
> > --- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
> > +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
> > @@ -20,25 +20,32 @@
> >   * huge page-only segment -- resulting in bugs.
> >   */
> >
> > +#define _GNU_SOURCE
> >  #include "lapi/mmap.h"
> >  #include "hugetlb.h"
> >  #include <errno.h>
> > +#include <inttypes.h>
> > +#include <sched.h>
> >
> >  #ifdef __LP64__
> >  #define STACK_ALLOCATION_SIZE        (256*1024*1024)
> >  #else
> >  #define STACK_ALLOCATION_SIZE        (16*1024*1024)
> >  #endif
> > -#define PALIGN(p, a) ((void *)LTP_ALIGN((unsigned long)(p), (a)))
> >  #define MNTPOINT "hugetlbfs/"
> > -static int  fd = -1;
> > -static unsigned long long hpage_size;
> > -static int page_size;
> > +#define PATH_HUGEPAGE "/sys/kernel/mm/hugepages"
> > +
> > +#define STACKS_MAX 64
> >
> > +static int  fd = -1;
> > +static uintptr_t hpage_size, stacks[STACKS_MAX];
> > +static int stacks_num;
> > +static void *hpage_addr, *stack_addr;
> > +static void **shared_area;
> >
> > -void do_child(void *stop_address)
> > +int do_child(void *stop_address)
> >  {
> > -     volatile int *x;
> > +     volatile char *x;
> >
> >       /* corefile from this process is not interesting and limiting
> >        * its size can save a lot of time. '1' is a special value,
> > @@ -46,57 +53,77 @@ void do_child(void *stop_address)
> >        * sets limit to RLIM_INFINITY.
> >        */
> >       tst_no_corefile(1);
> > +     tst_res(TINFO, "Child process starting with top of stack at %p", &x);
> >
> >       do {
> >               x = alloca(STACK_ALLOCATION_SIZE);
> > +             *shared_area = (void *)x;
> >               *x = 1;
> >       } while ((void *)x >= stop_address);
> > +     exit(0);
> >  }
> >
> >  static void run_test(void)
> >  {
> >       int pid, status;
> > -     void *stack_address, *mmap_address, *heap_address, *map;
> >
> > -     stack_address = alloca(0);
> > -     heap_address = sbrk(0);
> > -
> > -     /*
> > -      * paranoia: start mapping two hugepages below the start of the stack,
> > -      * in case the alignment would cause us to map over something if we
> > -      * only used a gap of one hugepage.
> > -      */
> > -     mmap_address = PALIGN(stack_address - 2 * hpage_size, hpage_size);
> > -     do {
> > -             map = mmap(mmap_address, hpage_size, PROT_READ|PROT_WRITE,
> > -                             MAP_SHARED | MAP_FIXED_NOREPLACE, fd, 0);
> > -             if (map == MAP_FAILED) {
> > -                     if (errno == ENOMEM) {
> > -                             tst_res(TCONF, "There is no enough memory in the system to do mmap");
> > -                             return;
> > -                     }
> > -             }
> > -             mmap_address -= hpage_size;
> > -             /*
> > -              * if we get all the way down to the heap, stop trying
> > -              */
> > -     } while (mmap_address <= heap_address);
> > -     pid = SAFE_FORK();
> > +     pid = ltp_clone(CLONE_VM | CLONE_VFORK | SIGCHLD, do_child,
> > +             hpage_addr, hpage_size, stack_addr);
> >       if (pid == 0)
> > -             do_child(mmap_address);
> > +             do_child(hpage_addr);
> >
> >       SAFE_WAITPID(pid, &status, 0);
> > +     tst_res(TINFO, "Child process extended stack up to %p, failed at %p",
> > +             *shared_area, *shared_area - STACK_ALLOCATION_SIZE);
> >       if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV)
> >               tst_res(TPASS, "Child killed by %s as expected", tst_strsig(SIGSEGV));
> >       else
> >               tst_res(TFAIL, "Child: %s", tst_strstatus(status));
> >  }
> >
> > +/* Return start address of next mapping or 0 */
> > +static uintptr_t  get_next_mapping_start(uintptr_t addr)
> > +{
> > +     FILE *fp = fopen("/proc/self/maps", "r");
> > +
> > +     if (fp == NULL)
> > +             tst_brk(TBROK | TERRNO, "Failed to open /proc/self/maps.");
> > +
> > +     while (!feof(fp)) {
> > +             uintptr_t start, end;
> > +             int ret;
> > +
> > +             ret = fscanf(fp, "%"PRIxPTR"-%"PRIxPTR" %*[^\n]\n", &start, &end);
> > +             if (ret != 2) {
> > +                     fclose(fp);
> > +                     tst_brk(TBROK | TERRNO, "Couldn't parse /proc/self/maps line.");
> > +             }
> > +
> > +             if (start > addr) {
> > +                     fclose(fp);
> > +                     return start;
> > +             }
> > +     }
> > +     fclose(fp);
> > +     return 0;
> > +}
>
> Maybe we could read this once and cache it because besides of the
> additions of the potential stack mappings it would not change, but I
> guess that it's not worth of the effort.
>
> > +static int is_addr_in_stacks(uintptr_t addr)
> > +{
> > +     int i;
> > +
> > +     for (i = 0; i < stacks_num; i++) {
> > +             if (addr == stacks[i])
> > +                     return 1;
> > +     }
> > +     return 0;
> > +}
> > +
> >  void setup(void)
> >  {
> >       struct rlimit r;
> > +     int i;
> >
> > -     page_size = getpagesize();
> >       hpage_size = tst_get_hugepage_size();
> >       /*
> >        * Setting the stack size to unlimited.
> > @@ -107,7 +134,65 @@ void setup(void)
> >       SAFE_GETRLIMIT(RLIMIT_STACK, &r);
> >       if (r.rlim_cur != RLIM_INFINITY)
> >               tst_brk(TCONF, "Stack rlimit must be 'unlimited'");
> > +
> > +     if (access(PATH_HUGEPAGE, F_OK))
> > +             tst_brk(TCONF, "hugetlbfs is not supported");
>
> Hmm, we have .needs_hugetlbfs in the tst_test structure that isn't
> enough? Maybe the test library needs to be fixed then?

I dropped it, it was leftover that shouldn't be needed.

>
> >       fd = tst_creat_unlinked(MNTPOINT, 0);
> > +
> > +     /* shared memory to pass a (void *) from child process */
> > +     shared_area = SAFE_MMAP(0, getpagesize(), PROT_READ|PROT_WRITE,
> > +             MAP_SHARED|MAP_ANONYMOUS, -1, 0);
> > +
> > +     /*
> > +      * We search for potential stack addresses by looking at
> > +      * places where kernel would map next huge page and occupying that
> > +      * address as potential stack. When huge page lands in such place
> > +      * that next mapping is one of our stack mappings, we use those
> > +      * two for the test. We try to map huge pages in child process so that
> > +      * slices in parent are not affected.
> > +      */
> > +     tst_res(TINFO, "searching for huge page and child stack placement");
> > +     for (i = 0; i < STACKS_MAX; i++) {
> > +             uintptr_t next_start;
> > +             int pid, status;
> > +
> > +             pid = SAFE_FORK();
> > +             if (pid == 0) {
> > +                     *shared_area = SAFE_MMAP(0, hpage_size, PROT_READ|PROT_WRITE,
> > +                             MAP_PRIVATE, fd, 0);
> > +                     SAFE_MUNMAP(*shared_area, hpage_size);
> > +                     exit(0);
> > +             }
> > +             SAFE_WAITPID(pid, &status, 0);
> > +             if (status != 0)
> > +                     tst_brk(TFAIL, "Child: %s", tst_strstatus(status));
> > +
> > +             next_start = get_next_mapping_start((uintptr_t)*shared_area);
> > +             if (is_addr_in_stacks(next_start)) {
> > +                     stack_addr = (void *)next_start;
> > +                     hpage_addr = *shared_area;
> > +                     break;
> > +             }
> > +
> > +             tst_res(TINFO, "potential stack at address %p", *shared_area);
> > +             stacks[stacks_num++] = (uintptr_t) SAFE_MMAP(*shared_area, hpage_size,
> > +                     PROT_READ|PROT_WRITE,
> > +                     MAP_ANONYMOUS|MAP_PRIVATE|MAP_GROWSDOWN, -1, 0);
> > +     }
> > +
> > +     if (!stack_addr)
> > +             tst_brk(TCONF, "failed to find good place for huge page and stack");
> > +
> > +     hpage_addr = mmap(hpage_addr, hpage_size, PROT_READ|PROT_WRITE,
> > +             MAP_SHARED|MAP_FIXED, fd, 0);
> > +     if (hpage_addr == MAP_FAILED) {
> > +             if (errno == ENOMEM)
> > +                     tst_brk(TCONF, "Not enough memory.");
> > +             tst_brk(TBROK|TERRNO, "mmap failed");
> > +     }
> > +     tst_res(TINFO, "huge page is at address %p", hpage_addr);
> > +     tst_res(TINFO, "using stack is at address %p", stack_addr);
>
> Maybe just one:
>
> tst_res(TINFO, "stack addr = %p huge page addr = %p", ...);

Applied your suggestion, I also printed upper bound, makes it easier to
see that  child stack address falls into the range.

>
>
> Overall this looks much better than the original:
>
> Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

Thanks, pushed.

>
> --
> Cyril Hrubis
> chrubis@suse.cz
>


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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-12-13  7:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-10 11:53 [LTP] Question on hugemmap34 Wei Gao via ltp
2024-12-10 12:54 ` Jan Stancek
2024-12-10 13:25   ` Jan Stancek
2024-12-10 14:22     ` Wei Gao via ltp
2024-12-11  3:20       ` Wei Gao via ltp
2024-12-11  6:46         ` Jan Stancek
2024-12-11 10:49           ` Jan Stancek
2024-12-12  9:29           ` [LTP] [PATCH] hugemmap34: change how test finds suitable huge page and stack for test Jan Stancek
2024-12-12 13:04             ` Cyril Hrubis
2024-12-13  4:09               ` Wei Gao via ltp
2024-12-13  7:27               ` Jan Stancek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox