All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v3 0/2] Add process_mrelease testing suite
@ 2026-09-07  8:55 Andrea Cervesato
  2026-09-07  8:55 ` [LTP] [PATCH v3 1/2] Add process_mrelease01 test Andrea Cervesato
  2026-09-07  8:55 ` [LTP] [PATCH v3 2/2] Add process_mrelease02 test Andrea Cervesato
  0 siblings, 2 replies; 4+ messages in thread
From: Andrea Cervesato @ 2026-09-07  8:55 UTC (permalink / raw)
  To: Linux Test Project

This testing suite is meant to add coverage for process_mrelease()
syscall, introduced in the kernel 5.15.

The testing suite is providing following tests:
- process_mrelease01
- process_mrelease02

Since there's no man pages, please consider the following
documentation instead:

https://lwn.net/Articles/864184/
https://lwn.net/Articles/865341/

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Changes in v3:
process_mrelease01:
- drop /proc/<pid>/maps check and unused shared memory setup
- retry on ESRCH with exponentially increasing memory allocations
- pass immediately when process_mrelease() returns success
- remove unneeded needs_root flag
- fix author name typo and description formatting

process_mrelease02:
- wait for child process after checkpoint wake to avoid zombies
- remove unneeded needs_root flag
- update doc comment formatting

Changes in v2:
- process_mrelease01: change the algorithm to ensure we released the
  memory after process_mrelease() is called
- process_mrelease02: verify ESRCH error
- Link to v1: https://lore.kernel.org/r/20240522-process_mrelease-v1-0-41fe2fa44194@suse.com

To: Linux Test Project <ltp@lists.linux.it>

---
Andrea Cervesato (2):
      Add process_mrelease01 test
      Add process_mrelease02 test

 runtest/syscalls                                   |  3 +
 .../kernel/syscalls/process_mrelease/.gitignore    |  2 +
 .../kernel/syscalls/process_mrelease/Makefile      |  7 ++
 .../syscalls/process_mrelease/process_mrelease01.c | 94 ++++++++++++++++++++++
 .../syscalls/process_mrelease/process_mrelease02.c | 90 +++++++++++++++++++++
 5 files changed, 196 insertions(+)
---
base-commit: 463b33ad464b6840d0a1df5d41939e50d55d542c
change-id: 20240522-process_mrelease-3f2632b432e6

Best regards,
--  
Andrea Cervesato <andrea.cervesato@suse.com>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [LTP] [PATCH v3 1/2] Add process_mrelease01 test
  2026-09-07  8:55 [LTP] [PATCH v3 0/2] Add process_mrelease testing suite Andrea Cervesato
@ 2026-09-07  8:55 ` Andrea Cervesato
  2026-09-07 12:06   ` [LTP] " linuxtestproject.agent
  2026-09-07  8:55 ` [LTP] [PATCH v3 2/2] Add process_mrelease02 test Andrea Cervesato
  1 sibling, 1 reply; 4+ messages in thread
From: Andrea Cervesato @ 2026-09-07  8:55 UTC (permalink / raw)
  To: Linux Test Project

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [LTP] [PATCH v3 2/2] Add process_mrelease02 test
  2026-09-07  8:55 [LTP] [PATCH v3 0/2] Add process_mrelease testing suite Andrea Cervesato
  2026-09-07  8:55 ` [LTP] [PATCH v3 1/2] Add process_mrelease01 test Andrea Cervesato
@ 2026-09-07  8:55 ` Andrea Cervesato
  1 sibling, 0 replies; 4+ messages in thread
From: Andrea Cervesato @ 2026-09-07  8:55 UTC (permalink / raw)
  To: Linux Test Project

From: Andrea Cervesato <andrea.cervesato@suse.com>

Verify that process_mrelease() returns expected error codes on
invalid file descriptors, non-zero flags, alive processes without
pending exit, and terminated processes.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                                   |  1 +
 .../kernel/syscalls/process_mrelease/.gitignore    |  1 +
 .../syscalls/process_mrelease/process_mrelease02.c | 90 ++++++++++++++++++++++
 3 files changed, 92 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index cfe76efca..b456afe20 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1152,6 +1152,7 @@ preadv203_64 preadv203_64
 profil01 profil01
 
 process_mrelease01 process_mrelease01
+process_mrelease02 process_mrelease02
 
 process_vm_readv01 process_vm01 -r
 process_vm_readv02 process_vm_readv02
diff --git a/testcases/kernel/syscalls/process_mrelease/.gitignore b/testcases/kernel/syscalls/process_mrelease/.gitignore
index 673983858..f1e7a8fea 100644
--- a/testcases/kernel/syscalls/process_mrelease/.gitignore
+++ b/testcases/kernel/syscalls/process_mrelease/.gitignore
@@ -1 +1,2 @@
 /process_mrelease01
+/process_mrelease02
diff --git a/testcases/kernel/syscalls/process_mrelease/process_mrelease02.c b/testcases/kernel/syscalls/process_mrelease/process_mrelease02.c
new file mode 100644
index 000000000..d48aba623
--- /dev/null
+++ b/testcases/kernel/syscalls/process_mrelease/process_mrelease02.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Test verifies error codes for :manpage:`process_mrelease(2)`:
+ *
+ * - EBADF when invalid file descriptor is passed
+ * - EINVAL when flags parameter is not zero
+ * - EINVAL when target process is still alive and not dying
+ * - ESRCH when target process has terminated
+ *
+ * [Algorithm]
+ *
+ * - Call process_mrelease() with bad fd (-1) to expect EBADF
+ * - Spawn child, call process_mrelease() with invalid flags (-1) to expect EINVAL
+ * - Call process_mrelease() on running child without pending exit to expect EINVAL
+ * - Wait for child exit, call process_mrelease() on dead child to expect ESRCH
+ */
+
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+
+static int badfd = -1;
+static int pidfd;
+
+enum {
+	NO_CHILD,
+	EXIT_CHILD,
+	WAIT_CHILD,
+};
+
+static struct tcase {
+	int child_type;
+	int *fd;
+	int flags;
+	int exp_errno;
+	char *msg;
+} tcases[] = {
+	{NO_CHILD, &badfd, 0, EBADF, "bad file descriptor"},
+	{WAIT_CHILD, &pidfd, -1, EINVAL, "flags is not 0"},
+	{WAIT_CHILD, &pidfd, 0, EINVAL, "task memory cannot be released"},
+	{EXIT_CHILD, &pidfd, 0, ESRCH, "child is not running"},
+};
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	int status;
+	pid_t pid = -1;
+
+	if (tc->child_type != NO_CHILD) {
+		pid = SAFE_FORK();
+		if (!pid) {
+			if (tc->child_type == WAIT_CHILD)
+				TST_CHECKPOINT_WAIT(0);
+
+			exit(0);
+		}
+
+		tst_res(TINFO, "Spawned waiting child with pid=%d", pid);
+
+		pidfd = SAFE_PIDFD_OPEN(pid, 0);
+
+		if (tc->child_type == EXIT_CHILD)
+			SAFE_WAITPID(pid, &status, 0);
+	}
+
+	TST_EXP_FAIL(tst_syscall(__NR_process_mrelease, *tc->fd, tc->flags),
+		tc->exp_errno,
+		"%s", tc->msg);
+
+	if (tc->child_type != NO_CHILD) {
+		if (tc->child_type == WAIT_CHILD) {
+			TST_CHECKPOINT_WAKE(0);
+			SAFE_WAITPID(pid, &status, 0);
+		}
+
+		SAFE_CLOSE(pidfd);
+	}
+}
+
+static struct tst_test test = {
+	.test = run,
+	.tcnt = ARRAY_SIZE(tcases),
+	.forks_child = 1,
+	.min_kver = "5.15",
+	.needs_checkpoints = 1,
+};

-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] Add process_mrelease01 test
  2026-09-07  8:55 ` [LTP] [PATCH v3 1/2] Add process_mrelease01 test Andrea Cervesato
@ 2026-09-07 12:06   ` linuxtestproject.agent
  0 siblings, 0 replies; 4+ messages in thread
From: linuxtestproject.agent @ 2026-09-07 12:06 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi Andrea,

On Mon, Sep 7, 2026, Andrea Cervesato wrote:
> Add process_mrelease01 test

Verdict - Reviewed

---
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

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-07 12:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-07  8:55 [LTP] [PATCH v3 0/2] Add process_mrelease testing suite Andrea Cervesato
2026-09-07  8:55 ` [LTP] [PATCH v3 1/2] Add process_mrelease01 test Andrea Cervesato
2026-09-07 12:06   ` [LTP] " linuxtestproject.agent
2026-09-07  8:55 ` [LTP] [PATCH v3 2/2] Add process_mrelease02 test Andrea Cervesato

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.