hugetlb/hugeshmat: Add hugeshmat06 migrated from libhugetlbfs shm-perms
PATCH v4 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.
Per-process HugetlbPages: from /proc/<pid>/status is checked before and after each child's attach/detach cycle. A non-zero value after detach indicates a reservation accounting leak. Using a per-process counter instead of the system-wide HugePages_Free: from /proc/meminfo avoids false failures from concurrent hugepage users on the system.
---
Changes in v4:
1. Replace HugePages_Free: (system-wide /proc/meminfo) with
HugetlbPages: (per-process /proc/<pid>/status) for reservation accounting check to avoid false failures when other processes use hugepages concurrently. [Cyril Hrubis]
2. Use tst_hugepages directly instead of re-reading MEMINFO_HPAGE_TOTAL since the LTP framework already stores the reserved count. [Li Wang]
3. Cap iteration count with MIN(tst_hugepages, MAX_CHILDREN) instead of computing it from total hugepages * hpage_size to avoid spawning excessive children on large-memory machines. [Li Wang]
4. Reduce .hugepages request from 32 to HPAGES_IN_SEG (4) since only 4 hugepages are ever needed. [Li Wang]
5. Move all child-local variables into the child process block to fix variable aliasing between the outer fork loop index and the inner hugepage read loop index. [Li Wang]
6. Add data coherence check: each child verifies every hugepage contains the expected 0x55 pattern written by the parent, since children attach with SHM_RDONLY. [Li Wang]
7. Move segment creation and pattern initialisation into setup() to keep run_test() focused on attach/verify/detach/accounting.
8. Add TINFO message per child reporting successful attach. [Li Wang]
9. Fix checkpatch.pl quoted string split across lines warnings.
Link:
https://lore.kernel.org/ltp/[email protected]/ # v3
runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../mem/hugetlb/hugeshmat/hugeshmat06.c | 187 ++++++++++++++++++ 3 files changed, 189 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat06.c
runtest/hugetlb +1 -0
@@ -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
@@ -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 +187 -0
187 lines not on this page · raw message
Signature · 5 lines
2.52.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Samir,
Quoted 6 lines · Samir Mulani
hugetlb/hugeshmat: Add hugeshmat06 migrated from libhugetlbfs shm-perms
hugetlb_after = get_proc_hugetlb_kb(getpid()); if (hugetlb_after != 0) { tst_res(TFAIL, "Child %d: HugetlbPages after detach is %ld kB (expected 0), reservation accounting leak",
Could this use an oracle tied to reservation state instead? In Linux 7.2, HugetlbPages reports mm->hugetlb_usage, which is incremented when a huge page is mapped and decremented when it is unmapped. The original regression leaked hstate->resv_huge_pages, so HugetlbPages can return to zero after shmdt() while that reservation remains leaked.
The original test exposed this by making enough read-only attachments to exhaust the pool. Here, an eventual shmat() failure would also be handled by SAFE_SHMAT() as TBROK rather than reported as a failure of the operation under test. Could the original reservation-leak oracle be retained and the regression reported as TFAIL?
Quoted 3 lines
#define SEGMENT_KEY (0x82ba15ff) shmid = SAFE_SHMGET(SEGMENT_KEY, segment_size, IPC_CREAT | SHM_HUGETLB | 0640);
Could this segment use IPC_PRIVATE? IPC_CREAT without IPC_EXCL returns an accessible pre-existing segment for this key when it is large enough. setup() would then overwrite that segment, and cleanup() would remove another process's IPC object with IPC_RMID.
Quoted 2 lines
/*\
* [Description]
Could the deprecated [Description] header be dropped?
Quoted 2 lines
static struct tst_test test = {
.needs_root = 1,Could the high-level description explain why root is required, namely that the framework modifies the system huge-page pool to reserve pages?
Quoted 1 line
+/hugetlb/hugeshmat/hugeshmat06
Could this entry be placed in testcases/kernel/mem/hugetlb/hugeshmat/.gitignore instead? New test binaries belong in the .gitignore in their own directory.
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
Quoted 14 lines · On 20/08/26 4:03 pm, [email protected] wrote:
Hi Samir,
Quoted 5 lines · Samir Mulani
hugetlb/hugeshmat: Add hugeshmat06 migrated from libhugetlbfs shm-perms
hugetlb_after = get_proc_hugetlb_kb(getpid()); if (hugetlb_after != 0) { tst_res(TFAIL, "Child %d: HugetlbPages after detach is %ld kB (expected 0), reservation accounting leak",Could this use an oracle tied to reservation state instead? In Linux 7.2, HugetlbPages reports
mm->hugetlb_usage, which is incremented when a huge page is mapped and decremented when it is unmapped. The original regression leakedhstate->resv_huge_pages, so HugetlbPages can return to zero aftershmdt()while that reservation remains leaked.
Quoted 5 lines
The original test exposed this by making enough read-only attachments to exhaust the pool. Here, an eventual
shmat()failure would also be handled bySAFE_SHMAT()as TBROK rather than reported as a failure of the operation under test. Could the original reservation-leak oracle be retained and the regression reported as TFAIL?
Agreed. HugetlbPages tracks the hugepage mappings associated with the process and can return to zero after shmdt() while the underlying resv_huge_pages reservation remains leaked.
I have retained the original reservation-exhaustion behavior and handle the relevant shmat() failure explicitly as TFAIL instead of using SAFE_SHMAT(), which would report it as TBROK.
Updated in v5.
Quoted 8 lines
Quoted 4 lines
#define SEGMENT_KEY (0x82ba15ff) shmid = SAFE_SHMGET(SEGMENT_KEY, segment_size, IPC_CREAT | SHM_HUGETLB | 0640);Could this segment use
IPC_PRIVATE?IPC_CREATwithoutIPC_EXCLreturns an accessible pre-existing segment for this key when it is large enough.setup()would then overwrite that segment, andcleanup()would remove another process's IPC object withIPC_RMID.
Agreed. Replaced SEGMENT_KEY with IPC_PRIVATE. The children inherit global_shmid directly, so a fixed key is not required. The unused SEGMENT_KEY definition has also been removed.
Quoted 4 lines
Quoted 3 lines
/*\
* [Description]Could the deprecated [Description] header be dropped?
Agreed. Removed the deprecated [Description] tag while retaining the test description, consistent with the convention used by other tests in this area.
Quoted 4 lines
Quoted 2 lines
static struct tst_test test = { .needs_root = 1,Could the high-level description explain why root is required, namely that the framework modifies the system huge-page pool to reserve pages?
I checked the other tests in the hugeshmat and hugefork directories and none of them document needs_root in the description block. It is a well understood LTP framework convention so I am keeping it as is.
Quoted 4 lines
Quoted 1 line
+/hugetlb/hugeshmat/hugeshmat06
Could this entry be placed in testcases/kernel/mem/hugetlb/hugeshmat/.gitignore instead? New test binaries belong in the .gitignore in their own directory.
There is no per-directory .gitignore under testcases/kernel/mem/hugetlb/hugeshmat/. The existing hugeshmat01 through hugeshmat05 binary entries are maintained in testcases/kernel/mem/.gitignore. I have kept the hugeshmat06 entry there to remain consistent with the existing hugeshmat tests.
Quoted 6 lines
Verdict - Needs revision
---
Note:
Quoted 7 lines
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