From: Andrea Cervesato <andrea.cervesato@suse.de>
To: Linux Test Project <ltp@lists.linux.it>
Subject: [LTP] [PATCH v3 1/2] Add process_mrelease01 test
Date: Mon, 07 Sep 2026 10:55:16 +0200 [thread overview]
Message-ID: <20260907-process_mrelease-v3-1-03bde3e5d77c@suse.com> (raw)
In-Reply-To: <20260907-process_mrelease-v3-0-03bde3e5d77c@suse.com>
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify process_mrelease() releases memory from a dying process.
If the child process terminates before the syscall can reap its
address space, retry with larger memory allocations to extend
teardown duration.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 2 +
.../kernel/syscalls/process_mrelease/.gitignore | 1 +
.../kernel/syscalls/process_mrelease/Makefile | 7 ++
.../syscalls/process_mrelease/process_mrelease01.c | 94 ++++++++++++++++++++++
4 files changed, 104 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 737c63e31..cfe76efca 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1151,6 +1151,8 @@ preadv203_64 preadv203_64
profil01 profil01
+process_mrelease01 process_mrelease01
+
process_vm_readv01 process_vm01 -r
process_vm_readv02 process_vm_readv02
process_vm_readv03 process_vm_readv03
diff --git a/testcases/kernel/syscalls/process_mrelease/.gitignore b/testcases/kernel/syscalls/process_mrelease/.gitignore
new file mode 100644
index 000000000..673983858
--- /dev/null
+++ b/testcases/kernel/syscalls/process_mrelease/.gitignore
@@ -0,0 +1 @@
+/process_mrelease01
diff --git a/testcases/kernel/syscalls/process_mrelease/Makefile b/testcases/kernel/syscalls/process_mrelease/Makefile
new file mode 100644
index 000000000..8cf1b9024
--- /dev/null
+++ b/testcases/kernel/syscalls/process_mrelease/Makefile
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+
+top_srcdir ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/process_mrelease/process_mrelease01.c b/testcases/kernel/syscalls/process_mrelease/process_mrelease01.c
new file mode 100644
index 000000000..37001e846
--- /dev/null
+++ b/testcases/kernel/syscalls/process_mrelease/process_mrelease01.c
@@ -0,0 +1,94 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Test verifies that :manpage:`process_mrelease(2)` syscall releases memory
+ * from a killed process with pending memory allocations.
+ *
+ * [Algorithm]
+ *
+ * - Spawn a child process allocating and dirtying anonymous memory
+ * - Wait until the child is ready via checkpoints
+ * - Obtain child's pidfd and send SIGKILL to the child
+ * - Invoke process_mrelease(pidfd, 0)
+ * - If process_mrelease() fails with ESRCH (child terminated too fast),
+ * double the allocation size and retry
+ * - Check that process_mrelease() succeeds
+ */
+
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+
+#define CHUNK (1 * TST_MB)
+#define MAX_SIZE_MB (1024 * TST_MB)
+
+static void do_child(size_t size)
+{
+ void *mem;
+
+ tst_res(TINFO, "Child: allocate %zu MB", size / TST_MB);
+
+ mem = SAFE_MMAP(NULL,
+ size,
+ PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANON,
+ -1, 0);
+
+ memset(mem, 0, size);
+
+ TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+ SAFE_MUNMAP(mem, size);
+}
+
+static void run(void)
+{
+ size_t mem_size;
+ pid_t pid;
+ int pidfd;
+ int status;
+
+ for (mem_size = CHUNK; mem_size <= MAX_SIZE_MB; mem_size *= 2) {
+ pid = SAFE_FORK();
+ if (!pid) {
+ do_child(mem_size);
+ exit(0);
+ }
+
+ TST_CHECKPOINT_WAIT(0);
+
+ pidfd = SAFE_PIDFD_OPEN(pid, 0);
+
+ SAFE_KILL(pid, SIGKILL);
+
+ TEST(tst_syscall(__NR_process_mrelease, pidfd, 0));
+
+ SAFE_WAITPID(pid, &status, 0);
+ SAFE_CLOSE(pidfd);
+
+ if (TST_RET == 0) {
+ tst_res(TPASS, "process_mrelease() passed with %zu MB",
+ mem_size / TST_MB);
+ return;
+ }
+
+ if (TST_ERR != ESRCH) {
+ tst_res(TFAIL | TTERRNO, "process_mrelease() failed");
+ return;
+ }
+
+ tst_res(TINFO,
+ "Child terminated before process_mrelease(). Increasing memory size and retrying");
+ }
+
+ tst_res(TFAIL, "All process_mrelease() attempts failed with ESRCH");
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .forks_child = 1,
+ .min_kver = "5.15",
+ .needs_checkpoints = 1,
+};
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-09-07 8:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 8:55 [LTP] [PATCH v3 0/2] Add process_mrelease testing suite Andrea Cervesato
2026-09-07 8:55 ` Andrea Cervesato [this message]
2026-09-07 12:06 ` [LTP] Add process_mrelease01 test linuxtestproject.agent
2026-09-07 8:55 ` [LTP] [PATCH v3 2/2] Add process_mrelease02 test Andrea Cervesato
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=20260907-process_mrelease-v3-1-03bde3e5d77c@suse.com \
--to=andrea.cervesato@suse.de \
--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.