From: Pavithra <pavrampu@linux.ibm.com>
To: ltp@lists.linux.it
Cc: pavrampu@linux.ibm.com
Subject: [LTP] [PATCH v8] hugemmap/hugemmap41: Migrate ptrace-write-hugepage from libhugetlbfs
Date: Mon, 10 Aug 2026 00:20:27 +0530 [thread overview]
Message-ID: <20260809185027.1867585-1-pavrampu@linux.ibm.com> (raw)
This test verifies that ptrace POKEDATA and PEEKDATA operations work
correctly on hugepage-backed memory regions. Migrating it to LTP as
libhugetlbfs is not actively maintained.
Signed-off-by: Pavithra <pavrampu@linux.ibm.com>
---
v7 -> v8:
Replace SAFE_PTRACE(PTRACE_POKEDATA, ...) with TEST() and an explicit
TFAIL check, consistent with how PTRACE_PEEKDATA is already handled.
Link to v7: https://lore.kernel.org/ltp/20260809171646.1832676-1-pavrampu@linux.ibm.com/
---
runtest/hugetlb | 1 +
testcases/kernel/mem/.gitignore | 1 +
.../kernel/mem/hugetlb/hugemmap/hugemmap41.c | 132 ++++++++++++++++++
3 files changed, 134 insertions(+)
create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c
diff --git a/runtest/hugetlb b/runtest/hugetlb
index 6b35c1f42..621c9718a 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -40,6 +40,7 @@ hugemmap35 hugemmap35
hugemmap36 hugemmap36
hugemmap37 hugemmap37
hugemmap38 hugemmap38
+hugemmap41 hugemmap41
hugemmap05_1 hugemmap05 -m
hugemmap05_2 hugemmap05 -s
hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index e63a6dde7..9e706e1c8 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -40,6 +40,7 @@
/hugetlb/hugemmap/hugemmap36
/hugetlb/hugemmap/hugemmap37
/hugetlb/hugemmap/hugemmap38
+/hugetlb/hugemmap/hugemmap41
/hugetlb/hugeshmat/hugeshmat01
/hugetlb/hugeshmat/hugeshmat02
/hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c
new file mode 100644
index 000000000..d59811d8f
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ * Copyright (c) 2026 Pavithra <pavrampu@linux.ibm.com>
+ */
+
+/*\
+ * Test :manpage:`ptrace(2)` write to hugepage memory.
+ *
+ * A child process maps a hugepage via hugetlbfs, zeroes it, and sends
+ * the mapped address to the parent. The parent attaches with
+ * :manpage:`ptrace(2)`, then uses PTRACE_POKEDATA and PTRACE_PEEKDATA
+ * to write and read back a known value at two different offsets within
+ * the hugepage, verifying that ptrace operates correctly on
+ * hugepage-backed memory regions.
+ *
+ * Requires root to mount hugetlbfs and for :manpage:`ptrace(2)`
+ * PTRACE_ATTACH to work across processes when ptrace_scope is
+ * restrictive.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/ptrace.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "tst_test.h"
+#include "hugetlb.h"
+
+#define CONST 0xdeadbeefL
+#define MNTPOINT "hugetlbfs/"
+
+static long hpage_size;
+static int fd = -1;
+
+static void child(int hugefd, int pipefd[2])
+{
+ void *p;
+
+ SAFE_CLOSE(pipefd[0]);
+
+ p = SAFE_MMAP(NULL, hpage_size, PROT_READ | PROT_WRITE, MAP_SHARED,
+ hugefd, 0);
+
+ memset(p, 0, hpage_size);
+
+ tst_res(TINFO, "Child mapped data at %p", p);
+
+ SAFE_WRITE(SAFE_WRITE_ALL, pipefd[1], &p, sizeof(p));
+ SAFE_CLOSE(pipefd[1]);
+
+ pause();
+ /* Child is killed by parent via SIGKILL, so cleanup is not reached */
+}
+
+static void do_poke(pid_t pid, void *p)
+{
+ tst_res(TINFO, "Poking at %p...", p);
+ TEST(ptrace(PTRACE_POKEDATA, pid, p, (void *)CONST));
+ if (TST_RET == -1)
+ tst_brk(TFAIL | TTERRNO, "ptrace(POKEDATA) failed");
+
+ tst_res(TINFO, "Peeking at %p...", p);
+ TEST(ptrace(PTRACE_PEEKDATA, pid, p, NULL));
+ if (TST_ERR)
+ tst_brk(TFAIL | TTERRNO, "ptrace(PEEKDATA) failed");
+
+ TST_EXP_EQ_LU((unsigned long)TST_RET, CONST);
+}
+
+static void run_test(void)
+{
+ int pipefd[2];
+ pid_t cpid;
+ void *p;
+ int status;
+
+ fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
+
+ SAFE_PIPE(pipefd);
+
+ cpid = SAFE_FORK();
+
+ if (cpid == 0) {
+ child(fd, pipefd);
+ exit(0);
+ }
+
+ SAFE_CLOSE(pipefd[1]);
+ SAFE_READ(1, pipefd[0], &p, sizeof(p));
+ SAFE_CLOSE(pipefd[0]);
+
+ tst_res(TINFO, "Parent received address %p", p);
+
+ SAFE_PTRACE(PTRACE_ATTACH, cpid, NULL, NULL);
+
+ SAFE_WAITPID(cpid, &status, 0);
+ if (!WIFSTOPPED(status))
+ tst_brk(TBROK, "Child %d was not stopped", cpid);
+
+ do_poke(cpid, p);
+ do_poke(cpid, p + getpagesize());
+
+ SAFE_KILL(cpid, SIGKILL);
+ SAFE_WAITPID(cpid, &status, 0);
+
+ SAFE_CLOSE(fd);
+}
+
+static void setup(void)
+{
+ hpage_size = tst_get_hugepage_size();
+}
+
+static void cleanup(void)
+{
+ if (fd != -1)
+ SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .mntpoint = MNTPOINT,
+ .needs_hugetlbfs = 1,
+ .hugepages = {1, TST_NEEDS},
+ .forks_child = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = run_test,
+};
--
2.55.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2026-08-09 18:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-09 18:50 Pavithra [this message]
2026-08-09 19:37 ` [LTP] hugemmap/hugemmap41: Migrate ptrace-write-hugepage from libhugetlbfs linuxtestproject.agent
2026-08-28 11:12 ` [LTP] [PATCH v8] " Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260809185027.1867585-1-pavrampu@linux.ibm.com \
--to=pavrampu@linux.ibm.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.