From: Ricardo Branco <rbranco@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3] userfaultfd: Minor fixes
Date: Fri, 27 Mar 2026 17:01:55 +0100 [thread overview]
Message-ID: <20260327160157.76906-1-rbranco@suse.de> (raw)
- Use POSIX semantics for thread function
- Set cleanup to call reset_pages
Signed-off-by: Ricardo Branco <rbranco@suse.de>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
---
.../kernel/syscalls/userfaultfd/userfaultfd01.c | 13 ++++++++++---
.../kernel/syscalls/userfaultfd/userfaultfd02.c | 13 ++++++++++---
.../kernel/syscalls/userfaultfd/userfaultfd03.c | 15 +++++++++++----
.../kernel/syscalls/userfaultfd/userfaultfd04.c | 8 ++++++--
.../kernel/syscalls/userfaultfd/userfaultfd05.c | 12 ++++++++----
.../kernel/syscalls/userfaultfd/userfaultfd06.c | 4 ++--
6 files changed, 47 insertions(+), 18 deletions(-)
diff --git a/testcases/kernel/syscalls/userfaultfd/userfaultfd01.c b/testcases/kernel/syscalls/userfaultfd/userfaultfd01.c
index 7368d3863..c3a37370e 100644
--- a/testcases/kernel/syscalls/userfaultfd/userfaultfd01.c
+++ b/testcases/kernel/syscalls/userfaultfd/userfaultfd01.c
@@ -53,11 +53,17 @@ static void set_pages(void)
static void reset_pages(void)
{
- SAFE_MUNMAP(page, page_size);
- SAFE_MUNMAP(copy_page, page_size);
+ if (page) {
+ SAFE_MUNMAP(page, page_size);
+ page = NULL;
+ }
+ if (copy_page) {
+ SAFE_MUNMAP(copy_page, page_size);
+ copy_page = NULL;
+ }
}
-static void *handle_thread(void)
+static void *handle_thread(void *arg LTP_ATTRIBUTE_UNUSED)
{
static struct uffd_msg msg;
struct uffdio_copy uffdio_copy = {};
@@ -129,4 +135,5 @@ static struct tst_test test = {
.setup = setup,
.test = run,
.tcnt = ARRAY_SIZE(tcases),
+ .cleanup = reset_pages,
};
diff --git a/testcases/kernel/syscalls/userfaultfd/userfaultfd02.c b/testcases/kernel/syscalls/userfaultfd/userfaultfd02.c
index 2fd5ba5d8..7450c443b 100644
--- a/testcases/kernel/syscalls/userfaultfd/userfaultfd02.c
+++ b/testcases/kernel/syscalls/userfaultfd/userfaultfd02.c
@@ -32,11 +32,17 @@ static void set_pages(void)
static void reset_pages(void)
{
- SAFE_MUNMAP(page, page_size);
- SAFE_MUNMAP(move_page, page_size);
+ if (page) {
+ SAFE_MUNMAP(page, page_size);
+ page = NULL;
+ }
+ if (move_page) {
+ SAFE_MUNMAP(move_page, page_size);
+ move_page = NULL;
+ }
}
-static void *handle_thread(void)
+static void *handle_thread(void *arg LTP_ATTRIBUTE_UNUSED)
{
static struct uffd_msg msg;
struct uffdio_move uffdio_move = {};
@@ -94,4 +100,5 @@ static void run(void)
static struct tst_test test = {
.test_all = run,
.min_kver = "6.8",
+ .cleanup = reset_pages,
};
diff --git a/testcases/kernel/syscalls/userfaultfd/userfaultfd03.c b/testcases/kernel/syscalls/userfaultfd/userfaultfd03.c
index b65f39eca..727e551f6 100644
--- a/testcases/kernel/syscalls/userfaultfd/userfaultfd03.c
+++ b/testcases/kernel/syscalls/userfaultfd/userfaultfd03.c
@@ -57,11 +57,17 @@ static void set_pages(void)
static void reset_pages(void)
{
- SAFE_MUNMAP(page, page_size);
- SAFE_MUNMAP(copy_page, page_size);
+ if (page) {
+ SAFE_MUNMAP(page, page_size);
+ page = NULL;
+ }
+ if (copy_page) {
+ SAFE_MUNMAP(copy_page, page_size);
+ copy_page = NULL;
+ }
}
-static void *handle_thread(void)
+static void *handle_thread(void *arg LTP_ATTRIBUTE_UNUSED)
{
static struct uffd_msg msg;
struct uffdio_copy uffdio_copy = {};
@@ -132,5 +138,6 @@ static struct tst_test test = {
.needs_kconfigs = (const char *[]) {
"CONFIG_USERFAULTFD=y",
NULL
- }
+ },
+ .cleanup = reset_pages,
};
diff --git a/testcases/kernel/syscalls/userfaultfd/userfaultfd04.c b/testcases/kernel/syscalls/userfaultfd/userfaultfd04.c
index 4eb811e45..3273d20cb 100644
--- a/testcases/kernel/syscalls/userfaultfd/userfaultfd04.c
+++ b/testcases/kernel/syscalls/userfaultfd/userfaultfd04.c
@@ -30,10 +30,13 @@ static void set_pages(void)
static void reset_pages(void)
{
- SAFE_MUNMAP(page, page_size);
+ if (page) {
+ SAFE_MUNMAP(page, page_size);
+ page = NULL;
+ }
}
-static void *handle_thread(void)
+static void *handle_thread(void *arg LTP_ATTRIBUTE_UNUSED)
{
static struct uffd_msg msg;
struct uffdio_zeropage uffdio_zeropage = {};
@@ -98,4 +101,5 @@ static void run(void)
static struct tst_test test = {
.test_all = run,
+ .cleanup = reset_pages,
};
diff --git a/testcases/kernel/syscalls/userfaultfd/userfaultfd05.c b/testcases/kernel/syscalls/userfaultfd/userfaultfd05.c
index e25a227cf..eadb2f8c3 100644
--- a/testcases/kernel/syscalls/userfaultfd/userfaultfd05.c
+++ b/testcases/kernel/syscalls/userfaultfd/userfaultfd05.c
@@ -33,10 +33,13 @@ static void set_pages(void)
static void reset_pages(void)
{
- SAFE_MUNMAP(page, page_size);
+ if (page) {
+ SAFE_MUNMAP(page, page_size);
+ page = NULL;
+ }
}
-static void *handle_thread(void)
+static void *handle_thread(void *arg LTP_ATTRIBUTE_UNUSED)
{
static struct uffd_msg msg;
struct uffdio_writeprotect uffdio_writeprotect = {};
@@ -53,7 +56,7 @@ static void *handle_thread(void)
SAFE_READ(1, uffd, &msg, sizeof(msg));
if (msg.event != UFFD_EVENT_PAGEFAULT)
- tst_brk(TFAIL, "Received unexpected UFFD_EVENT %d", msg.event);
+ tst_brk(TFAIL | TERRNO, "Received unexpected UFFD_EVENT %d", msg.event);
if (!(msg.arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WP) ||
!(msg.arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WRITE)) {
@@ -127,5 +130,6 @@ static struct tst_test test = {
.needs_kconfigs = (const char *[]) {
"CONFIG_HAVE_ARCH_USERFAULTFD_WP=y",
NULL
- }
+ },
+ .cleanup = reset_pages,
};
diff --git a/testcases/kernel/syscalls/userfaultfd/userfaultfd06.c b/testcases/kernel/syscalls/userfaultfd/userfaultfd06.c
index 5b1252c35..bc12bc5f2 100644
--- a/testcases/kernel/syscalls/userfaultfd/userfaultfd06.c
+++ b/testcases/kernel/syscalls/userfaultfd/userfaultfd06.c
@@ -58,7 +58,7 @@ static void reset_pages(void)
}
}
-static void *handle_thread(void)
+static void *handle_thread(void *arg LTP_ATTRIBUTE_UNUSED)
{
static struct uffd_msg msg;
struct uffdio_poison uffdio_poison = {};
@@ -74,7 +74,7 @@ static void *handle_thread(void)
SAFE_READ(1, uffd, &msg, sizeof(msg));
if (msg.event != UFFD_EVENT_PAGEFAULT)
- tst_brk(TFAIL, "Received unexpected UFFD_EVENT %d", msg.event);
+ tst_brk(TFAIL | TERRNO, "Received unexpected UFFD_EVENT %d", msg.event);
tst_atomic_store(1, &poison_fault_seen);
--
2.53.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2026-03-27 16:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-27 16:01 Ricardo Branco [this message]
2026-03-30 7:24 ` [LTP] [PATCH v3] userfaultfd: Minor fixes Petr Vorel
2026-03-30 10:15 ` Cyril Hrubis
2026-03-30 10:42 ` Petr Vorel
2026-03-30 7:58 ` Andrea Cervesato via ltp
2026-05-05 12:02 ` 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=20260327160157.76906-1-rbranco@suse.de \
--to=rbranco@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.