Skip to contentSkip to conversation

Make userfaultfd0{1, 3, 4} LTP tests valgrind compatible

PATCH In review Martin Cermak via ltp 4 participants 11 messages Apr 21 – Apr 28

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make userfaultfd0{1, 3, 4} LTP tests valgrind compatible

Historically a page fault is handled in the linux kernel. The userfaultfd mechanism [1] was introduced in Linux 4.3 (2015) to allow custom handling page faults in userspace. It allows for custom page fault handling strategies such as lazy loading, live migration of qemu VMs, etc. With userfaultfd, kernel communicates with userspace via a file descriptor (userfaultfd). Userfaultfd LTP tests cover this.

These tests set up a main thread and a page fault handler thread. Once a page fault happens in the main thread, kernel stops it, and let's the handler take care of the page fault.

This is a problem for Valgrind, because it serializes the threads execution (using one "big mutex", VG_(acquire_BigLock)). Once kernel stops the main thread, under valgrind, the handler thread doesn't have a chance to handle the page fault. Valgrind stalls till the timeout (adjustable via LTP_TIMEOUT_MUL ;)

However, some of the testcases can be easily changed to use forked processes instead of threads. That's what this patch does. When client program forks, Valgrind forks too, and that allows for the needed parallelism to handle the page fault.

This redesign can't be easily done with some of the tests, such as e.g. userfaultfd02 where both the main thread and the handler thread need to share the address space. That could be done via clone() and is proven to work. But unfortunately there is another Valgrind limitation in clone flags it supports, so this also isn't a practical way to go.

That said, this update tweaks userfaultfd01, userfaultfd03, and userfaultfd04 in a way that they become "compatible" with Valgrind. It's a test coverage improvement.

[1] https://www.kernel.org/doc/html/latest/admin-guide/mm/userfaultfd.html

---
 .../kernel/syscalls/userfaultfd/userfaultfd01.c   | 13 +++++++++----
 .../kernel/syscalls/userfaultfd/userfaultfd03.c   | 15 ++++++++++-----
 .../kernel/syscalls/userfaultfd/userfaultfd04.c   | 13 +++++++++----
 3 files changed, 28 insertions(+), 13 deletions(-)
testcases/kernel/syscalls/userfaultfd/userfaultfd01.c +9 -4
index 7368d3863..c927cda95 100644
@@ -57,7 +57,7 @@ static void reset_pages(void)
 	SAFE_MUNMAP(copy_page, page_size);
 }
 
-static void *handle_thread(void)
+static void *pagefault_handler(void)
 {
 	static struct uffd_msg msg;
 	struct uffdio_copy uffdio_copy = {};
@@ -91,7 +91,7 @@ static void *handle_thread(void)
 
 static void run(unsigned int i)
 {
-	pthread_t thr;
+	pid_t pid;
 	struct uffdio_api uffdio_api = {};
 	struct uffdio_register uffdio_register;
 	struct tcase *tc = &tcases[i];
@@ -112,7 +112,11 @@ static void run(unsigned int i)
 
 	SAFE_IOCTL(uffd, UFFDIO_REGISTER, &uffdio_register);
 
-	SAFE_PTHREAD_CREATE(&thr, NULL, (void *) handle_thread, NULL);
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		pagefault_handler();
+		_exit(0);
+	}
 
 	char c = page[0xf];
 
@@ -121,7 +125,7 @@ static void run(unsigned int i)
 	else
 		tst_res(TFAIL, "Pagefault not handled!");
 
-	SAFE_PTHREAD_JOIN(thr, NULL);
+	SAFE_WAITPID(pid, NULL, 0);
 	reset_pages();
 }
 
@@ -129,4 +133,5 @@ static struct tst_test test = {
 	.setup = setup,
 	.test = run,
 	.tcnt = ARRAY_SIZE(tcases),
+	.forks_child = 1,
 };
testcases/kernel/syscalls/userfaultfd/userfaultfd03.c +10 -5
index b65f39eca..f5d3be1ae 100644
@@ -61,7 +61,7 @@ static void reset_pages(void)
 	SAFE_MUNMAP(copy_page, page_size);
 }
 
-static void *handle_thread(void)
+static void *pagefault_handler(void)
 {
 	static struct uffd_msg msg;
 	struct uffdio_copy uffdio_copy = {};
@@ -95,7 +95,7 @@ static void *handle_thread(void)
 
 static void run(void)
 {
-	pthread_t thr;
+	pid_t pid;
 	struct uffdio_api uffdio_api = {};
 	struct uffdio_register uffdio_register;
 
@@ -112,7 +112,11 @@ static void run(void)
 
 	SAFE_IOCTL(uffd, UFFDIO_REGISTER, &uffdio_register);
 
-	SAFE_PTHREAD_CREATE(&thr, NULL, (void *) handle_thread, NULL);
+	pid = SAFE_FORK();
+		if (pid == 0) {
+		pagefault_handler();
+		_exit(0);
+	}
 
 	char c = page[0xf];
 
@@ -121,7 +125,7 @@ static void run(void)
 	else
 		tst_res(TFAIL, "Pagefault not handled via /dev/userfaultfd");
 
-	SAFE_PTHREAD_JOIN(thr, NULL);
+	SAFE_WAITPID(pid, NULL, 0);
 	reset_pages();
 }
 
@@ -132,5 +136,6 @@ static struct tst_test test = {
 	.needs_kconfigs = (const char *[]) {
 		"CONFIG_USERFAULTFD=y",
 		NULL
-	}
+	},
+	.forks_child = 1,
 };
testcases/kernel/syscalls/userfaultfd/userfaultfd04.c +9 -4
index 4eb811e45..13883a711 100644
@@ -33,7 +33,7 @@ static void reset_pages(void)
 	SAFE_MUNMAP(page, page_size);
 }
 
-static void *handle_thread(void)
+static void *pagefault_handler(void)
 {
 	static struct uffd_msg msg;
 	struct uffdio_zeropage uffdio_zeropage = {};
@@ -64,7 +64,7 @@ static void *handle_thread(void)
 
 static void run(void)
 {
-	pthread_t thr;
+	pid_t pid;
 	struct uffdio_api uffdio_api = {};
 	struct uffdio_register uffdio_register;
 
@@ -81,7 +81,11 @@ static void run(void)
 
 	SAFE_IOCTL(uffd, UFFDIO_REGISTER, &uffdio_register);
 
-	SAFE_PTHREAD_CREATE(&thr, NULL, (void *) handle_thread, NULL);
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		pagefault_handler();
+		_exit(0);
+	}
 
 	for (int i = 0; i < page_size; i++) {
 		if (page[i] != 0) {
@@ -92,10 +96,11 @@ static void run(void)
 
 	tst_res(TPASS, "Pagefault handled with UFFDIO_ZEROPAGE");
 
-	SAFE_PTHREAD_JOIN(thr, NULL);
+	SAFE_WAITPID(pid, NULL, 0);
 	reset_pages();
 }
 
 static struct tst_test test = {
 	.test_all = run,
+	.forks_child = 1,
 };
Signature · 5 lines
2.53.0


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

Hi Martin,

Quoted 1 line · Martin Cermak

Make userfaultfd0{1, 3, 4} LTP tests valgrind compatible

The commit message is missing a Signed-off-by: tag.

Review

Quoted 2 lines
(quoted diff) +1 -1
-static void *handle_thread(void)
+static void *pagefault_handler(void)

Since this is no longer a thread entry point, change the return type to void and drop the return NULL.

Quoted 4 lines

/*\
* Force a pagefault event and handle it using :manpage:userfaultfd(2)
* from a different thread.
*/

The handler now runs in a forked child, not a thread. Update the doc comment in all three files.

[...]

testcases/kernel/syscalls/userfaultfd/userfaultfd01.c static void run(unsigned int i) · line 117

Quoted 3 lines
testcases/kernel/syscalls/userfaultfd/userfaultfd01.c +3 -0
+	pid = SAFE_FORK();
+		if (pid == 0) {
+		pagefault_handler();

userfaultfd03.c: extra leading tab on the if line.

[...]

Review

Quoted 2 lines
(quoted diff) +1 -0
+	SAFE_WAITPID(pid, NULL, 0);
 	reset_pages();

In the original code the thread closed uffd for the whole process (threads share the fd table). With fork, the child closes only its own copy; the parent's uffd is never closed. Add SAFE_CLOSE(uffd) before reset_pages() in all three tests.

Also, tst_safe_pthread.h is no longer used in userfaultfd03.c and userfaultfd04.c after this change; remove the include.

---
Note:

Our agent completed the review of the patch.

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
#2 lore raw
In reply to Martin Cermak via ltp

Hi Martin,

[ Cc Ricardo ]

Quoted 17 lines

Historically a page fault is handled in the linux kernel. The userfaultfd mechanism [1] was introduced in Linux 4.3 (2015) to allow custom handling page faults in userspace. It allows for custom page fault handling strategies such as lazy loading, live migration of qemu VMs, etc. With userfaultfd, kernel communicates with userspace via a file descriptor (userfaultfd). Userfaultfd LTP tests cover this.

These tests set up a main thread and a page fault handler thread. Once a page fault happens in the main thread, kernel stops it, and let's the handler take care of the page fault.

This is a problem for Valgrind, because it serializes the threads execution (using one "big mutex", VG_(acquire_BigLock)). Once kernel stops the main thread, under valgrind, the handler thread doesn't have a chance to handle the page fault. Valgrind stalls till the timeout (adjustable via LTP_TIMEOUT_MUL ;)

Quoted 4 lines

However, some of the testcases can be easily changed to use forked processes instead of threads. That's what this patch does. When client program forks, Valgrind forks too, and that allows for the needed parallelism to handle the page fault.

You understand process vs. threads more than me. But shouldn't mmap() use MAP_SHARED instead of MAP_PRIVATE for those which aren't using /dev/userfaultfd?

Quoted 3 lines

This redesign can't be easily done with some of the tests, such as e.g. userfaultfd02 where both the main thread and the handler thread need to share the address space. That could be done via clone() and is proven

What is the difference with userfaultfd02 then?

Quoted 6 lines

to work. But unfortunately there is another Valgrind limitation in clone flags it supports, so this also isn't a practical way to go.

That said, this update tweaks userfaultfd01, userfaultfd03, and userfaultfd04 in a way that they become "compatible" with Valgrind. It's a test coverage improvement.

Also doc should be updated (mentions thread).

Please don't forget to add it next time:

Quoted 157 lines

[1] https://www.kernel.org/doc/html/latest/admin-guide/mm/userfaultfd.html

---
 .../kernel/syscalls/userfaultfd/userfaultfd01.c   | 13 +++++++++----
 .../kernel/syscalls/userfaultfd/userfaultfd03.c   | 15 ++++++++++-----
 .../kernel/syscalls/userfaultfd/userfaultfd04.c   | 13 +++++++++----
 3 files changed, 28 insertions(+), 13 deletions(-)
testcases/kernel/syscalls/userfaultfd/userfaultfd01.c +9 -4
index 7368d3863..c927cda95 100644
@@ -57,7 +57,7 @@ static void reset_pages(void)
 	SAFE_MUNMAP(copy_page, page_size);
 }
 
-static void *handle_thread(void)
+static void *pagefault_handler(void)
 {
 	static struct uffd_msg msg;
 	struct uffdio_copy uffdio_copy = {};
@@ -91,7 +91,7 @@ static void *handle_thread(void)
 
 static void run(unsigned int i)
 {
-	pthread_t thr;
+	pid_t pid;
 	struct uffdio_api uffdio_api = {};
 	struct uffdio_register uffdio_register;
 	struct tcase *tc = &tcases[i];
@@ -112,7 +112,11 @@ static void run(unsigned int i)
 
 	SAFE_IOCTL(uffd, UFFDIO_REGISTER, &uffdio_register);
 
-	SAFE_PTHREAD_CREATE(&thr, NULL, (void *) handle_thread, NULL);
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		pagefault_handler();
+		_exit(0);
+	}
 
 	char c = page[0xf];
 
@@ -121,7 +125,7 @@ static void run(unsigned int i)
 	else
 		tst_res(TFAIL, "Pagefault not handled!");
 
-	SAFE_PTHREAD_JOIN(thr, NULL);
+	SAFE_WAITPID(pid, NULL, 0);
 	reset_pages();
 }
 
@@ -129,4 +133,5 @@ static struct tst_test test = {
 	.setup = setup,
 	.test = run,
 	.tcnt = ARRAY_SIZE(tcases),
+	.forks_child = 1,
 };
testcases/kernel/syscalls/userfaultfd/userfaultfd03.c +10 -5
index b65f39eca..f5d3be1ae 100644
@@ -61,7 +61,7 @@ static void reset_pages(void)
 	SAFE_MUNMAP(copy_page, page_size);
 }
 
-static void *handle_thread(void)
+static void *pagefault_handler(void)
 {
 	static struct uffd_msg msg;
 	struct uffdio_copy uffdio_copy = {};
@@ -95,7 +95,7 @@ static void *handle_thread(void)
 
 static void run(void)
 {
-	pthread_t thr;
+	pid_t pid;
 	struct uffdio_api uffdio_api = {};
 	struct uffdio_register uffdio_register;
 
@@ -112,7 +112,11 @@ static void run(void)
 
 	SAFE_IOCTL(uffd, UFFDIO_REGISTER, &uffdio_register);
 
-	SAFE_PTHREAD_CREATE(&thr, NULL, (void *) handle_thread, NULL);
+	pid = SAFE_FORK();
+		if (pid == 0) {
+		pagefault_handler();
+		_exit(0);
+	}
 
 	char c = page[0xf];
 
@@ -121,7 +125,7 @@ static void run(void)
 	else
 		tst_res(TFAIL, "Pagefault not handled via /dev/userfaultfd");
 
-	SAFE_PTHREAD_JOIN(thr, NULL);
+	SAFE_WAITPID(pid, NULL, 0);
 	reset_pages();
 }
 
@@ -132,5 +136,6 @@ static struct tst_test test = {
 	.needs_kconfigs = (const char *[]) {
 		"CONFIG_USERFAULTFD=y",
 		NULL
-	}
+	},
+	.forks_child = 1,
 };
testcases/kernel/syscalls/userfaultfd/userfaultfd04.c +9 -4
index 4eb811e45..13883a711 100644
@@ -33,7 +33,7 @@ static void reset_pages(void)
 	SAFE_MUNMAP(page, page_size);
 }
 
-static void *handle_thread(void)
+static void *pagefault_handler(void)
 {
 	static struct uffd_msg msg;
 	struct uffdio_zeropage uffdio_zeropage = {};
@@ -64,7 +64,7 @@ static void *handle_thread(void)
 
 static void run(void)
 {
-	pthread_t thr;
+	pid_t pid;
 	struct uffdio_api uffdio_api = {};
 	struct uffdio_register uffdio_register;
 
@@ -81,7 +81,11 @@ static void run(void)
 
 	SAFE_IOCTL(uffd, UFFDIO_REGISTER, &uffdio_register);
 
-	SAFE_PTHREAD_CREATE(&thr, NULL, (void *) handle_thread, NULL);
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		pagefault_handler();
+		_exit(0);
+	}
 
 	for (int i = 0; i < page_size; i++) {
 		if (page[i] != 0) {
@@ -92,10 +96,11 @@ static void run(void)
 
 	tst_res(TPASS, "Pagefault handled with UFFDIO_ZEROPAGE");
 
-	SAFE_PTHREAD_JOIN(thr, NULL);
+	SAFE_WAITPID(pid, NULL, 0);
 	reset_pages();
 }
 
 static struct tst_test test = {
 	.test_all = run,
+	.forks_child = 1,
 };
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
Quoted 6 lines · Petr Vorel
Quoted 4 lines

However, some of the testcases can be easily changed to use forked processes instead of threads. That's what this patch does. When client program forks, Valgrind forks too, and that allows for the needed parallelism to handle the page fault.

You understand process vs. threads more than me. But shouldn't mmap() use MAP_SHARED instead of MAP_PRIVATE for those which aren't using /dev/userfaultfd?

The documentation for userfaultfd mentions threads.  I'm afraid we'll lose vital coverage if we move to forked processes.

Perhaps we should cover both?

Also checkout UFFD_FEATURE_EVENT_FORK and the BUGS section for this in userfaultfd(2).
I have like 3 patches for userfaultfd that I'm afraid I'd have to rebase then.\ Best, Ricardo

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw
Quoted 7 lines · Petr Vorel
Quoted 4 lines
Quoted 4 lines

However, some of the testcases can be easily changed to use forked processes instead of threads. That's what this patch does. When client program forks, Valgrind forks too, and that allows for the needed parallelism to handle the page fault.

Quoted 5 lines
Quoted 2 lines

You understand process vs. threads more than me. But shouldn't mmap() use MAP_SHARED instead of MAP_PRIVATE for those which aren't using /dev/userfaultfd?

The documentation for userfaultfd mentions threads.  I'm afraid we'll lose vital coverage if we move to forked processes.

+1, at least some tests would keep threads (not all userfaultfd tests would be converted, but yes, that's why I suggested to use MAP_SHARED, which could be similar to threads (yes, the difference between processes and threads in Linux kernel is not that huge as both are created in clone(), it's mostly about what is shared).

Quoted 1 line

Perhaps we should cover both?

What do you mean by "both"?

Run test with both processes and threads e.g. via .test_variants? Because combine MAP_SHARED | MAP_PRIVATE is not possible (mutually exclusive).

Quoted 2 lines

Also checkout UFFD_FEATURE_EVENT_FORK and the BUGS section for this in userfaultfd(2).

+1

Quoted 2 lines

I have like 3 patches for userfaultfd that I'm afraid I'd have to rebase then.\ Best,

Yeah, that's life of an open source development.

Kind regards,
Petr

Quoted 1 line

Ricardo

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw
Quoted 4 lines · Petr Vorel
Quoted 1 line

Perhaps we should cover both?

What do you mean by "both"?

Run test with both processes and threads e.g. via .test_variants?

Yes.

Best,
R

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw
In reply to Petr Vorel
Quoted 10 lines · Petr Vorel
Quoted 9 lines · Petr Vorel
Quoted 6 lines
Quoted 4 lines

However, some of the testcases can be easily changed to use forked processes instead of threads. That's what this patch does. When client program forks, Valgrind forks too, and that allows for the needed parallelism to handle the page fault.

You understand process vs. threads more than me. But shouldn't mmap() use MAP_SHARED instead of MAP_PRIVATE for those which aren't using /dev/userfaultfd?

Quoted 8 lines
Quoted 2 lines

The documentation for userfaultfd mentions threads.  I'm afraid we'll lose vital coverage if we move to forked processes.

+1, at least some tests would keep threads (not all userfaultfd tests would be converted, but yes, that's why I suggested to use MAP_SHARED, which could be similar to threads (yes, the difference between processes and threads in Linux kernel is not that huge as both are created in clone(), it's mostly about what is shared).

My goal is to make at least part of these userfaultfd tests compatible with Valgrind. I've experimented with clone() and it seems like Valgrind has limited support for it. That said, adding another set of userfaultfd tests using fork() or clone() instead of threads might help. Some of such new tests will be "incompatible" with valgrind, but it might be a test coverage improvement.

m.

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author Reviewed-by Martin Cermak
#7 lore raw
Quoted 20 lines · Martin Cermak
Quoted 10 lines · Petr Vorel
Quoted 9 lines · Petr Vorel
Quoted 6 lines
Quoted 4 lines

However, some of the testcases can be easily changed to use forked processes instead of threads. That's what this patch does. When client program forks, Valgrind forks too, and that allows for the needed parallelism to handle the page fault.

You understand process vs. threads more than me. But shouldn't mmap() use MAP_SHARED instead of MAP_PRIVATE for those which aren't using /dev/userfaultfd?

Quoted 8 lines
Quoted 2 lines

The documentation for userfaultfd mentions threads.  I'm afraid we'll lose vital coverage if we move to forked processes.

+1, at least some tests would keep threads (not all userfaultfd tests would be converted, but yes, that's why I suggested to use MAP_SHARED, which could be similar to threads (yes, the difference between processes and threads in Linux kernel is not that huge as both are created in clone(), it's mostly about what is shared).

Quoted 7 lines

My goal is to make at least part of these userfaultfd tests compatible with Valgrind. I've experimented with clone() and it seems like Valgrind has limited support for it. That said, adding another set of userfaultfd tests using fork() or clone() instead of threads might help. Some of such new tests will be "incompatible" with valgrind, but it might be a test coverage improvement.

Here is an ai-assisted patch that works for me:

From 693f3015d39b39e2c263aac57c183e3e4cf7df4d Mon Sep 17 00:00:00 2001
From: Martin Cermak <[email protected]>
Date: Thu, 23 Apr 2026 15:51:10 +0200
Subject: [PATCH] Provide Valgrind-compatible userfaultfd tests

The userfaultfd tests use threads. Threads are executed serially in Valgrind, but parallelism is important for userfaultfd tests. When a page fault happens in parent thread, kernel stops it, and waits for the handler thread to handle the page fault. That said, userfaultfd tests 01 - 06 stall in Valgrind.

This update comes with second set of userfaultfd tests 07 - 12. These additional tests use fork() or clone(), thus a separate process instead of threads. Support for clone() is also limited in Valgrind. For that reason only tests 07, 09 and 10 are "Valgrind compatible". But it's a test coverage improvement.

Valgrind can filter LTP tests on the per test binary basis. That's why this update adds separate tests 07 - 12.

Assisted-by Anthropic Claude
---
 include/lapi/sched.h                          |   8 +
 .../kernel/syscalls/userfaultfd/.gitignore    |   6 +
 .../kernel/syscalls/userfaultfd/Makefile      |   3 +
 .../syscalls/userfaultfd/userfaultfd07.c      | 136 +++++++++++++++
 .../syscalls/userfaultfd/userfaultfd08.c      | 113 +++++++++++++
 .../syscalls/userfaultfd/userfaultfd09.c      | 141 ++++++++++++++++
 .../syscalls/userfaultfd/userfaultfd10.c      | 106 ++++++++++++
 .../syscalls/userfaultfd/userfaultfd11.c      | 140 ++++++++++++++++
 .../syscalls/userfaultfd/userfaultfd12.c      | 157 ++++++++++++++++++
 9 files changed, 810 insertions(+)
 create mode 100644 testcases/kernel/syscalls/userfaultfd/userfaultfd07.c
 create mode 100644 testcases/kernel/syscalls/userfaultfd/userfaultfd08.c
 create mode 100644 testcases/kernel/syscalls/userfaultfd/userfaultfd09.c
 create mode 100644 testcases/kernel/syscalls/userfaultfd/userfaultfd10.c
 create mode 100644 testcases/kernel/syscalls/userfaultfd/userfaultfd11.c
 create mode 100644 testcases/kernel/syscalls/userfaultfd/userfaultfd12.c
include/lapi/sched.h +8 -0
index 05b322c1c..b33de6657 100644
@@ -121,6 +121,14 @@ static inline int getcpu(unsigned *cpu, unsigned *node)
 # define CLONE_FS	0x00000200
 #endif
 
+#ifndef CLONE_FILES
+# define CLONE_FILES	0x00000400
+#endif
+
+#ifndef CLONE_SIGHAND
+# define CLONE_SIGHAND	0x00000800
+#endif
+
 #ifndef CLONE_PIDFD
 # define CLONE_PIDFD	0x00001000
 #endif
testcases/kernel/syscalls/userfaultfd/.gitignore +6 -0
index bc32fdf3b..59d28c6f3 100644
@@ -4,3 +4,9 @@
 /userfaultfd04
 /userfaultfd05
 /userfaultfd06
+/userfaultfd07
+/userfaultfd08
+/userfaultfd09
+/userfaultfd10
+/userfaultfd11
+/userfaultfd12
testcases/kernel/syscalls/userfaultfd/Makefile +3 -0
index 3252e47df..e4ed56b4b 100644
@@ -17,3 +17,6 @@ userfaultfd03: CFLAGS += -pthread
 userfaultfd04: CFLAGS += -pthread
 userfaultfd05: CFLAGS += -pthread
 userfaultfd06: CFLAGS += -pthread
+# Tests 07-12: Valgrind-compatible variants using fork/clone
+# Tests 07, 09, 10: fork-based (no pthread needed)
+# Tests 08, 11, 12: clone-based (no pthread needed)
testcases/kernel/syscalls/userfaultfd/userfaultfd07.c new file +136 -0

136 lines not on this page · raw message

testcases/kernel/syscalls/userfaultfd/userfaultfd08.c new file +113 -0

113 lines not on this page · raw message

testcases/kernel/syscalls/userfaultfd/userfaultfd09.c new file +141 -0

141 lines not on this page · raw message

testcases/kernel/syscalls/userfaultfd/userfaultfd10.c new file +106 -0

106 lines not on this page · raw message

testcases/kernel/syscalls/userfaultfd/userfaultfd11.c new file +140 -0

140 lines not on this page · raw message

testcases/kernel/syscalls/userfaultfd/userfaultfd12.c new file +157 -0

157 lines not on this page · raw message

Signature · 5 lines
2.53.0


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

Hi Martin,

please re-send the new patch version so we can review it properly :-)

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author Reviewed-by Martin Cermak
#9 lore raw
Quoted 3 lines · Andrea Cervesato via Valgrind-developers

Hi Martin,

please re-send the new patch version so we can review it properly :-)

Hi Andrea,

the patch is below. It adds 6 new tests. New tests are easy to text-diff against their originals. The only difference is that new tests use fork() or clone() instead of threads to handle the page fault. Please review:

From 693f3015d39b39e2c263aac57c183e3e4cf7df4d Mon Sep 17 00:00:00 2001
From: Martin Cermak <[email protected]>
Date: Thu, 23 Apr 2026 15:51:10 +0200
Subject: [PATCH] Provide Valgrind-compatible userfaultfd tests

The userfaultfd tests use threads. Threads are executed serially in Valgrind, but parallelism is important for userfaultfd tests. When a page fault happens in parent thread, kernel stops it, and waits for the handler thread to handle the page fault. That said, userfaultfd tests 01 - 06 stall in Valgrind.

This update comes with second set of userfaultfd tests 07 - 12. These additional tests use fork() or clone(), thus a separate process instead of threads. Support for clone() is also limited in Valgrind. For that reason only tests 07, 09 and 10 are "Valgrind compatible". But it's a test coverage improvement.

Valgrind can filter LTP tests on the per test binary basis. That's why this update adds separate tests 07 - 12.

Assisted-by Anthropic Claude
include/lapi/sched.h +8 -0
index 05b322c1c..b33de6657 100644
@@ -121,6 +121,14 @@ static inline int getcpu(unsigned *cpu, unsigned *node)
 # define CLONE_FS	0x00000200
 #endif
 
+#ifndef CLONE_FILES
+# define CLONE_FILES	0x00000400
+#endif
+
+#ifndef CLONE_SIGHAND
+# define CLONE_SIGHAND	0x00000800
+#endif
+
 #ifndef CLONE_PIDFD
 # define CLONE_PIDFD	0x00001000
 #endif
testcases/kernel/syscalls/userfaultfd/.gitignore +6 -0
index bc32fdf3b..59d28c6f3 100644
@@ -4,3 +4,9 @@
 /userfaultfd04
 /userfaultfd05
 /userfaultfd06
+/userfaultfd07
+/userfaultfd08
+/userfaultfd09
+/userfaultfd10
+/userfaultfd11
+/userfaultfd12
testcases/kernel/syscalls/userfaultfd/Makefile +3 -0
index 3252e47df..e4ed56b4b 100644
@@ -17,3 +17,6 @@ userfaultfd03: CFLAGS += -pthread
 userfaultfd04: CFLAGS += -pthread
 userfaultfd05: CFLAGS += -pthread
 userfaultfd06: CFLAGS += -pthread
+# Tests 07-12: Valgrind-compatible variants using fork/clone
+# Tests 07, 09, 10: fork-based (no pthread needed)
+# Tests 08, 11, 12: clone-based (no pthread needed)
testcases/kernel/syscalls/userfaultfd/userfaultfd07.c new file +136 -0

136 lines not on this page · raw message

testcases/kernel/syscalls/userfaultfd/userfaultfd08.c new file +113 -0

113 lines not on this page · raw message

testcases/kernel/syscalls/userfaultfd/userfaultfd09.c new file +141 -0

141 lines not on this page · raw message

testcases/kernel/syscalls/userfaultfd/userfaultfd10.c new file +106 -0

106 lines not on this page · raw message

testcases/kernel/syscalls/userfaultfd/userfaultfd11.c new file +140 -0

140 lines not on this page · raw message

testcases/kernel/syscalls/userfaultfd/userfaultfd12.c new file +157 -0

157 lines not on this page · raw message

Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw
Quoted 6 lines

Hi Andrea,

the patch is below. It adds 6 new tests. New tests are easy to text-diff against their originals. The only difference is that new tests use fork() or clone() instead of threads to handle the page fault. Please review:

I seen it, but when we receive patches as comments to the original patches (without versioning), we get out of the loop of CI + automatic review, which is our bare minimum request in order to accept patches from LTP ML.

Kind Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp