Skip to contentSkip to conversation

hugetlb/hugemmap: add hugemmap33 to test hugetlbfs quota accounting

PATCH Superseded Pavithra 2 participants 2 messages Sep 9

v9 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Pavithra

author
#0 lore raw

PATCH v9 1/1 hugetlb/hugemmap: add hugemmap33 to test hugetlbfs quota accounting

Test hugetlbfs quota accounting with filesystem size limits to check for regressions in quota handling for MAP_PRIVATE and MAP_SHARED pages.

---
v8 -> v9:
- Fixed incorrect SAFE_MUNMAP guard to only unmap when mmap unexpectedly succeeds.
- Replaced abbreviated commit hash a1e78772d72b with full 40-character ID a1e78772d72b2616ed20e54896e68e0e7044854e in .tags. Link to v8: https://lore.kernel.org/ltp/[email protected]/

---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap33.c  | 222 ++++++++++++++++++
 3 files changed, 224 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c
runtest/hugetlb +1 -0
index 621c9718a..e3ee42c2f 100644
@@ -35,6 +35,7 @@ hugemmap29 hugemmap29
 hugemmap30 hugemmap30
 hugemmap31 hugemmap31
 hugemmap32 hugemmap32
+hugemmap33 hugemmap33
 hugemmap34 hugemmap34
 hugemmap35 hugemmap35
 hugemmap36 hugemmap36
testcases/kernel/mem/.gitignore +1 -0
index 9e706e1c8..763f134dd 100644
@@ -35,6 +35,7 @@
 /hugetlb/hugemmap/hugemmap30
 /hugetlb/hugemmap/hugemmap31
 /hugetlb/hugemmap/hugemmap32
+/hugetlb/hugemmap/hugemmap33
 /hugetlb/hugemmap/hugemmap34
 /hugetlb/hugemmap/hugemmap35
 /hugetlb/hugemmap/hugemmap36
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +222 -0

222 lines not on this page · raw message

Signature · 5 lines
2.55.0


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

Hi Pavithra,

Quoted 4 lines · Pavithra

hugetlb/hugemmap: add hugemmap33 to test hugetlbfs quota accounting

Test hugetlbfs quota accounting with filesystem size limits to check for regressions in quota handling for MAP_PRIVATE and MAP_SHARED pages.

The empty lines in the commit message body contain trailing whitespace, which triggers checkpatch errors.

Quoted 6 lines

+/*\
+ * Test hugetlbfs quota accounting with filesystem size limits.
+ *
+ * The number of global huge pages available to a mounted hugetlbfs filesystem
+ * can be limited using a quota mechanism by setting the size attribute at
+ * mount time. Older kernels did not properly handle quota accounting for

Quoted 8 lines

+ * MAP_PRIVATE pages and MAP_SHARED reservations.
+ *
+ * Commit a1e78772d72b introduced MAP_PRIVATE reservations at mmap() time,
+ * so quota is checked upfront and mmap() fails with ENOMEM when over quota.
+ * Before this, quota was only checked at fault time resulting in SIGBUS.
+ *
+ * Root is required to mount the quota-limited hugetlbfs instance.
+ */

Use :manpage:mmap(2) when referencing mmap() in the documentation block.

testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 64

Quoted 13 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +13 -0
+static void verify_quota_map_unmap(unsigned long size, int mmap_flags)
+{
+	int fd;
+	char path[PATH_MAX];
+
+	snprintf(path, sizeof(path), "%s/test_file_%d", MNTPOINT, getpid());
+	fd = SAFE_OPEN(path, O_CREAT | O_RDWR, 0600);
+	SAFE_UNLINK(path);
+
+	TST_EXP_PASS_PTR_VOID(mmap(NULL, size, PROT_READ | PROT_WRITE, mmap_flags, fd, 0),
+			       "mmap untouched mapping");
+	SAFE_CLOSE(fd);
+}

verify_quota_map_unmap() never unmaps the mapping. As a result, this tests cleanup on process termination rather than unmapping an untouched mapping. Call SAFE_MUNMAP(TST_RET_PTR, size) if TST_PASS before closing fd.

testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 59

Quoted 3 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +3 -0
+	snprintf(path, sizeof(path), "%s/test_file_%d", MNTPOINT, getpid());
+	fd = SAFE_OPEN(path, O_CREAT | O_RDWR, 0600);
+	SAFE_UNLINK(path);

Use tst_creat_unlinked(MNTPOINT, 0, 0600) instead of manually creating and unlinking files across the test functions.

testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 196

Quoted 5 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +5 -0
+	if (mount("none", MNTPOINT, "hugetlbfs", 0, mount_opts) == -1) {
+		if (errno == ENODEV)
+			tst_brk(TCONF, "hugetlbfs not supported");
+		tst_brk(TBROK | TERRNO, "mount() failed");
+	}

Use SAFE_MOUNT("none", MNTPOINT, "hugetlbfs", 0, mount_opts). Hugepage support is already checked by .hugepages before setup() runs.

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