Skip to contentSkip to conversation

hugetlb/hugeshmat: Add hugeshmat06 migrated from libhugetlbfs shm-perms

PATCH In review Samir Mulani 2 participants 3 messages Aug 20 – Aug 21

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 hugetlb/hugeshmat: Add hugeshmat06 migrated from libhugetlbfs shm-perms

Test shared memory behavior when multiple processes attach to a hugepage-backed segment with different permissions.

At one point, reservation accounting of free hugepages between the parent and child processes may become inconsistent during memory operations. The parent creates a shared memory segment backed by 4 hugepages (permission 0640), attaches it read-write, initialises each hugepage with a pattern (0x55), then detaches. Child processes are forked in a loop, each reattaching the segment read-only via SHM_RDONLY, verifying the data pattern, detaching, and exiting.

If the reservation accounting leaks, repeated read-only attaches will exhaust the hugepage pool and shmat() will fail. The test uses raw shmat() in each child and reports this failure as TFAIL.

---
Changes in v5:
1. Use raw shmat() instead of SAFE_SHMAT() and report pool exhaustion as TFAIL. HugetlbPages from /proc/<pid>/status only tracks mapped pages and can return zero after shmdt() even when resv_huge_pages is still leaked, so it is not a reliable oracle for this regression. [LTP AI Reviewer]
2. Remove get_proc_hugetlb_kb() helper and the HugetlbPages check as they are no longer needed. [LTP AI Reviewer]
3. Use IPC_PRIVATE instead of a fixed SEGMENT_KEY to avoid accidentally reusing or destroying a pre-existing segment. [LTP AI Reviewer]
4. Drop the deprecated [Description] tag from the /*\ block. [LTP AI Reviewer]

 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../mem/hugetlb/hugeshmat/hugeshmat06.c       | 152 ++++++++++++++++++
 3 files changed, 154 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat06.c
runtest/hugetlb +1 -0
index 6b35c1f42..1eb5c3339 100644
@@ -49,6 +49,7 @@ hugeshmat02 hugeshmat02 -i 5
 hugeshmat03 hugeshmat03 -i 5
 hugeshmat04 hugeshmat04 -i 5
 hugeshmat05 hugeshmat05 -i 5
+hugeshmat06 hugeshmat06 -i 5
 
 hugeshmctl01 hugeshmctl01 -i 5
 hugeshmctl02 hugeshmctl02 -i 5
testcases/kernel/mem/.gitignore +1 -0
index e63a6dde7..704f89d5e 100644
@@ -45,6 +45,7 @@
 /hugetlb/hugeshmat/hugeshmat03
 /hugetlb/hugeshmat/hugeshmat04
 /hugetlb/hugeshmat/hugeshmat05
+/hugetlb/hugeshmat/hugeshmat06
 /hugetlb/hugeshmctl/hugeshmctl01
 /hugetlb/hugeshmctl/hugeshmctl02
 /hugetlb/hugeshmctl/hugeshmctl03
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat06.c new file +152 -0

152 lines not on this page · raw message

Signature · 5 lines
2.52.0


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

Hi Samir,

Quoted 6 lines · Samir Mulani

hugetlb/hugeshmat: Add hugeshmat06 migrated from libhugetlbfs shm-perms

#define HPAGES_IN_SEG 4
#define MAX_CHILDREN 128

	iterations = MIN((long)tst_hugepages, (long)MAX_CHILDREN);

Could the iteration count retain the original test's exhaustion guarantee? Each leaked attach reserves HPAGES_IN_SEG pages, so a pool containing N hugepages requires more than N / HPAGES_IN_SEG attaches to expose the leak. The original test calculated that value plus one.

With this cap, one execution can pass without detecting the bug when the pool contains 512 or more hugepages. Even the "-i 5" runtest entry is insufficient at 2560 or more. Could the count instead be derived from the pool and segment sizes, including the final attach that exceeds the pool?

Quoted 6 lines
			if (shmaddr == (void *)-1) {
				tst_res(TFAIL | TERRNO,
					"Child %d: shmat() failed, hugepage reservation pool may be exhausted",
					getpid());
				exit(EXIT_FAILURE);
			}

Could the child exit successfully after reporting TFAIL? tst_reap_children() converts this nonzero status into an additional TBROK ("Invalid child exit value") and aborts the parent. LTP already propagates the child's tst_res() result, so the regression should remain a TFAIL rather than also becoming a broken-test result.

Quoted 2 lines
static struct tst_test test = {
	.needs_root	 = 1,

This is described as a regression test, but the test has no .tags entry. Could the corresponding linux-git regression fix tag be added?

Quoted 1 line

+/hugetlb/hugeshmat/hugeshmat06

Could this binary instead be ignored by testcases/kernel/mem/hugetlb/hugeshmat/.gitignore as /hugeshmat06? New test binaries should use a leaf-directory .gitignore rather than the shared testcases/kernel/mem/.gitignore.

Quoted 3 lines

/*\
* Tests shared memory behavior when multiple processes attach to a
* hugepage-backed segment with different permissions.

Could the exported description explain why root is required? The test sets .needs_root because the framework adjusts the hugepage pool and mounts hugetlbfs.

Quoted 1 line

* pool. This is detected by using raw shmat() in each child so that a

Could shmat() use the ":manpage:shmat(2)" role here? Syscalls in exported test descriptions should use their man-page role.

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#2 lore raw
Quoted 13 lines · On 21/08/26 12:10 am, [email protected] wrote:

Hi Samir,

Quoted 5 lines · Samir Mulani

hugetlb/hugeshmat: Add hugeshmat06 migrated from libhugetlbfs shm-perms
#define HPAGES_IN_SEG 4
#define MAX_CHILDREN 128

	iterations = MIN((long)tst_hugepages, (long)MAX_CHILDREN);

Could the iteration count retain the original test's exhaustion guarantee? Each leaked attach reserves HPAGES_IN_SEG pages, so a pool containing N hugepages requires more than N / HPAGES_IN_SEG attaches to expose the leak. The original test calculated that value plus one.

Quoted 4 lines

With this cap, one execution can pass without detecting the bug when the pool contains 512 or more hugepages. Even the "-i 5" runtest entry is insufficient at 2560 or more. Could the count instead be derived from the pool and segment sizes, including the final attach that exceeds the pool?

Fixed. Replaced MIN(tst_hugepages, MAX_CHILDREN) with tst_hugepages / HPAGES_IN_SEG + 1 and removed MAX_CHILDREN. Now the count is derived from the pool size and segment size, and includes the final attach that must fail on a buggy kernel.

Quoted 7 lines
Quoted 7 lines
			if (shmaddr == (void *)-1) {
				tst_res(TFAIL | TERRNO,
					"Child %d: shmat() failed, hugepage reservation pool may be exhausted",
					getpid());
				exit(EXIT_FAILURE);
			}
Quoted 5 lines

Could the child exit successfully after reporting TFAIL? tst_reap_children() converts this nonzero status into an additional TBROK ("Invalid child exit value") and aborts the parent. LTP already propagates the child's tst_res() result, so the regression should remain a TFAIL rather than also becoming a broken-test result.

Fixed. Changed both exit(EXIT_FAILURE) to exit(EXIT_SUCCESS) — once in the shmat() failure path and once in the pattern-mismatch path. Also updated the comment above tst_reap_children() which was incorrectly describing the behavior.

Quoted 4 lines
Quoted 2 lines
static struct tst_test test = {
	.needs_root	 = 1,

This is described as a regression test, but the test has no .tags entry. Could the corresponding linux-git regression fix tag be added?

Fixed. The regression was fixed by upstream commit f83a275dbc5c ("mm: account for MAP_SHARED mappings using VM_MAYSHARE and not VM_SHARED in hugetlbfs" by Mel Gorman). Added the .tags entry with the 12-character hash, consistent with the other tests in the same directory.

Quoted 5 lines
Quoted 1 line

+/hugetlb/hugeshmat/hugeshmat06

Could this binary instead be ignored by testcases/kernel/mem/hugetlb/hugeshmat/.gitignore as /hugeshmat06? New test binaries should use a leaf-directory .gitignore rather than the shared testcases/kernel/mem/.gitignore.

This change is not required.

Quoted 10 lines
Quoted 3 lines

/*\
* Tests shared memory behavior when multiple processes attach to a
* hugepage-backed segment with different permissions.

Could the exported description explain why root is required? The test sets .needs_root because the framework adjusts the hugepage pool and mounts hugetlbfs.

Quoted 1 line

* pool. This is detected by using raw shmat() in each child so that a

Could shmat() use the ":manpage:shmat(2)" role here? Syscalls in exported test descriptions should use their man-page role.

Fixed both. Added a sentence in the exported description explaining that root is required because the LTP framework adjusts the hugepage pool and mounts hugetlbfs. Also changed shmat() to :manpage:shmat(2) in the same block.

Quoted 11 lines

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Regards,

Samir

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp