Skip to contentSkip to conversation

hugetlb: add new testcase hugeshmat05.c

PATCH Superseded Li Wang 2 participants 3 messages Dec 16, 2015 – Dec 21, 2015

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH v2 1/1 hugetlb: add new testcase hugeshmat05.c

shmget()/shmat() fails to allocate huge pages shared memory segment with EINVAL if its size is not in the range [ N*HUGE_PAGE_SIZE - 4095, N*HUGE_PAGE_SIZE ]. This is a problem in the memory segment size round up algorithm. The requested size is rounded up to PAGE_SIZE (4096), but if this roundup does not match HUGE_PAGE_SIZE (2Mb) boundary - the allocation fails.

This bug is present in all RHEL6 versions, but not in RHEL7. It looks like this was fixed in mainstream kernel > v3.3 by the following patches:

091d0d5 shm: fix null pointer deref when userspace specifies invalid hugepage size af73e4d hugetlbfs: fix mmap failure in unaligned size request
42d7395 mm: support more pagesizes for MAP_HUGETLB/SHM_HUGETLB 40716e2 hugetlbfs: fix alignment of huge page requests

---

Notes:
v1 --> v2
a.remove the key value from shmget()
b.improve the brk messages
c.just use one loop in the main function

 runtest/hugetlb                                    |   1 +
 testcases/kernel/mem/.gitignore                    |   1 +
 .../kernel/mem/hugetlb/hugeshmat/hugeshmat05.c     | 136 +++++++++++++++++++++
 3 files changed, 138 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c
runtest/hugetlb +1 -0
index 2e9f215..75e6426 100644
@@ -10,6 +10,7 @@ hugeshmat01 hugeshmat01 -i 5
 hugeshmat02 hugeshmat02 -i 5
 hugeshmat03 hugeshmat03 -i 5
 hugeshmat04 hugeshmat04 -i 5
+hugeshmat05 hugeshmat05 -i 5
 
 hugeshmctl01 hugeshmctl01 -i 5
 hugeshmctl02 hugeshmctl02 -i 5
testcases/kernel/mem/.gitignore +1 -0
index 4702377..46c2432 100644
@@ -7,6 +7,7 @@
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
 /hugetlb/hugeshmat/hugeshmat04
+/hugetlb/hugeshmat/hugeshmat05
 /hugetlb/hugeshmctl/hugeshmctl01
 /hugetlb/hugeshmctl/hugeshmctl02
 /hugetlb/hugeshmctl/hugeshmctl03
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c new file +136 -0

136 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v2 1/1 hugetlb: add new testcase hugeshmat05.c

Hi,

Quoted 35 lines · Li Wang

shmget()/shmat() fails to allocate huge pages shared memory segment with EINVAL if its size is not in the range [ N*HUGE_PAGE_SIZE - 4095, N*HUGE_PAGE_SIZE ]. This is a problem in the memory segment size round up algorithm. The requested size is rounded up to PAGE_SIZE (4096), but if this roundup does not match HUGE_PAGE_SIZE (2Mb) boundary - the allocation fails.

This bug is present in all RHEL6 versions, but not in RHEL7. It looks like this was fixed in mainstream kernel > v3.3 by the following patches:

091d0d5 shm: fix null pointer deref when userspace specifies invalid hugepage size af73e4d hugetlbfs: fix mmap failure in unaligned size request
42d7395 mm: support more pagesizes for MAP_HUGETLB/SHM_HUGETLB 40716e2 hugetlbfs: fix alignment of huge page requests

---

Notes:
v1 --> v2
a.remove the key value from shmget()
b.improve the brk messages
c.just use one loop in the main function

  runtest/hugetlb                                    |   1 +
  testcases/kernel/mem/.gitignore                    |   1 +
  .../kernel/mem/hugetlb/hugeshmat/hugeshmat05.c     | 136 +++++++++++++++++++++
  3 files changed, 138 insertions(+)

create mode 100644 testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c

runtest/hugetlb +0 -0
index 2e9f215..75e6426 100644

runtest/hugetlb hugeshmat01 hugeshmat01 -i 5 · line 13

Quoted 4 lines
runtest/hugetlb +1 -0
@@ -10,6 +10,7 @@ hugeshmat01 hugeshmat01 -i 5
  hugeshmat02 hugeshmat02 -i 5
  hugeshmat03 hugeshmat03 -i 5
  hugeshmat04 hugeshmat04 -i 5
+hugeshmat05 hugeshmat05 -i 5

Did you forget to increase iterations here or it is not needed anymore? In the first patch, if I am not mistaken, was 15 (because of two loops).

Quoted 3 lines
runtest/hugetlb +0 -0
  hugeshmctl01 hugeshmctl01 -i 5
  hugeshmctl02 hugeshmctl02 -i 5

...

Quoted 12 lines
runtest/hugetlb +12 -0
+
+int main(int ac, char **av)
+{
+	int lc;
+
+	tst_parse_opts(ac, av, NULL, NULL);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		tst_count = 0;
+

runtest/hugetlb

Quoted 10 lines
runtest/hugetlb +10 -0
+		/* N*hpage_size - page_size FAIL */
+		shm_test(N * hpage_size - page_size);
+
+		/* N*hpage_size - page_size - 1 SUCCESS*/
+		shm_test(N * hpage_size - page_size - 1);
+
+		/* N*hpage_size  SUCCESS */
+		shm_test(N * hpage_size);
+
+		/* N*hpage_size + 1 FAIL */

Could you please add more informative comments (may be explaining why it is "FAIL"/"SUCCESS")
or remove them completely, they just repeat what is passed to the function.

We could also set sizes in array, defining it before the "for":

const int tst_sizes[] = { N * hpage_size - page_size,

                                             N * hpage_size, ... };
for (lc ...) {
     tst_count = 0;
     for(i = 0; i < ARRAY_SIZE(tst_sizes); ++i)
         shm_test(tst_sizes[i]);
}

Best regards,
Alexey

Quoted 8 lines
runtest/hugetlb +8 -0
+		shm_test(N * hpage_size + 1);
+
+		tst_resm(TPASS, "No regression found.");
+	}
+
+	cleanup();
+	tst_exit();
+}
author
#2 lore raw

PATCH v2 1/1 hugetlb: add new testcase hugeshmat05.c

Hi,

Quoted 36 lines · Alexey Kodanev

Hi,

Quoted 32 lines · Li Wang

shmget()/shmat() fails to allocate huge pages shared memory segment with EINVAL if its size is not in the range [ N*HUGE_PAGE_SIZE - 4095, N*HUGE_PAGE_SIZE ]. This is a problem in the memory segment size round up algorithm. The requested size is rounded up to PAGE_SIZE (4096), but if this roundup does not match HUGE_PAGE_SIZE (2Mb) boundary - the allocation fails.

This bug is present in all RHEL6 versions, but not in RHEL7. It looks like this was fixed in mainstream kernel > v3.3 by the following patches:

091d0d5 shm: fix null pointer deref when userspace specifies invalid hugepage size
af73e4d hugetlbfs: fix mmap failure in unaligned size request 42d7395 mm: support more pagesizes for MAP_HUGETLB/SHM_HUGETLB 40716e2 hugetlbfs: fix alignment of huge page requests

---

Notes:
v1 --> v2
a.remove the key value from shmget()
b.improve the brk messages
c.just use one loop in the main function

  runtest/hugetlb                                    |   1 +
  testcases/kernel/mem/.gitignore                    |   1 +
  .../kernel/mem/hugetlb/hugeshmat/hugeshmat05.c     | 136
+++++++++++++++++++++
  3 files changed, 138 insertions(+)

create mode 100644 testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c

Quoted 14 lines

runtest/hugetlb hugeshmat01 hugeshmat01 -i 5 · line 14

Quoted 10 lines
runtest/hugetlb +1 -0
index 2e9f215..75e6426 100644
@@ -10,6 +10,7 @@ hugeshmat01 hugeshmat01 -i 5
  hugeshmat02 hugeshmat02 -i 5
  hugeshmat03 hugeshmat03 -i 5
  hugeshmat04 hugeshmat04 -i 5
+hugeshmat05 hugeshmat05 -i 5
 

Did you forget to increase iterations here or it is not needed anymore? In the first patch, if I am not mistaken, was 15 (because of two loops).

it is no needed, 5 loops is enough i think. :)

Quoted 34 lines

hugeshmctl01 hugeshmctl01 -i 5

Quoted 2 lines
runtest/hugetlb +0 -0
  hugeshmctl02 hugeshmctl02 -i 5
 

...

Quoted 13 lines
runtest/hugetlb +12 -0
+
+int main(int ac, char **av)
+{
+       int lc;
+
+       tst_parse_opts(ac, av, NULL, NULL);
+
+       setup();
+
+       for (lc = 0; TEST_LOOPING(lc); lc++) {
+               tst_count = 0;
+

runtest/hugetlb

Quoted 10 lines
runtest/hugetlb +10 -0
+               /* N*hpage_size - page_size FAIL */
+               shm_test(N * hpage_size - page_size);
+
+               /* N*hpage_size - page_size - 1 SUCCESS*/
+               shm_test(N * hpage_size - page_size - 1);
+
+               /* N*hpage_size  SUCCESS */
+               shm_test(N * hpage_size);
+
+               /* N*hpage_size + 1 FAIL */

Could you please add more informative comments (may be explaining why it is "FAIL"/"SUCCESS")
or remove them completely, they just repeat what is passed to the function.

Quoted 2 lines

We could also set sizes in array, defining it before the "for":

ok, I tend to accept the second suggestion. because it looks like more neatly than before.

Quoted 11 lines

const int tst_sizes[] = { N * hpage_size - page_size,

                                            N * hpage_size, ... };
for (lc ...) {
    tst_count = 0;
    for(i = 0; i < ARRAY_SIZE(tst_sizes); ++i)
        shm_test(tst_sizes[i]);
}
Quoted 4 lines

Best regards,
Alexey

thanks a lot! If there is no other comments, I'd like to sent patch v3 this evening.

Signature · 6 lines
Regards,
Li Wang
Email: [email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20151221/90d14354/attachment-0001.html>