{"id":2224438,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2224438/?format=json","web_url":"http://patchwork.ozlabs.org/project/ltp/patch/20260417122804.23890-1-wegao@suse.com/","project":{"id":59,"url":"http://patchwork.ozlabs.org/api/1.2/projects/59/?format=json","name":"Linux Test Project development","link_name":"ltp","list_id":"ltp.lists.linux.it","list_email":"ltp@lists.linux.it","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260417122804.23890-1-wegao@suse.com>","list_archive_url":null,"date":"2026-04-17T12:27:55","name":"[v8] mremap07.c: New test for mremap() with MREMAP_DONTUNMAP","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"6849d389605e15c9a5f06c5f233bcfa9a998fe5d","submitter":{"id":85577,"url":"http://patchwork.ozlabs.org/api/1.2/people/85577/?format=json","name":"Wei Gao","email":"wegao@suse.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/ltp/patch/20260417122804.23890-1-wegao@suse.com/mbox/","series":[{"id":500320,"url":"http://patchwork.ozlabs.org/api/1.2/series/500320/?format=json","web_url":"http://patchwork.ozlabs.org/project/ltp/list/?series=500320","date":"2026-04-17T12:27:55","name":"[v8] mremap07.c: New test for mremap() with MREMAP_DONTUNMAP","version":8,"mbox":"http://patchwork.ozlabs.org/series/500320/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2224438/comments/","check":"success","checks":"http://patchwork.ozlabs.org/api/patches/2224438/checks/","tags":{},"related":[],"headers":{"Return-Path":"<ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it>","X-Original-To":["incoming@patchwork.ozlabs.org","ltp@lists.linux.it"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","ltp@picard.linux.it"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=lists.linux.it header.i=@lists.linux.it\n header.a=rsa-sha256 header.s=picard header.b=badd1bAN;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256\n header.s=google header.b=VHTcIkEd;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it\n (client-ip=2001:1418:10:5::2; helo=picard.linux.it;\n envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it;\n receiver=patchwork.ozlabs.org)"],"Received":["from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fxvLD2fnXz1yD3\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 17 Apr 2026 22:28:20 +1000 (AEST)","from picard.linux.it (localhost [IPv6:::1])\n\tby picard.linux.it (Postfix) with ESMTP id 3563A3E5945\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 17 Apr 2026 14:28:18 +0200 (CEST)","from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature ECDSA (secp384r1))\n (No client certificate requested)\n by picard.linux.it (Postfix) with ESMTPS id C926C3CD9FD\n for <ltp@lists.linux.it>; Fri, 17 Apr 2026 14:28:13 +0200 (CEST)","from mail-wm1-x333.google.com (mail-wm1-x333.google.com\n [IPv6:2a00:1450:4864:20::333])\n (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 71E6B2003B6\n for <ltp@lists.linux.it>; Fri, 17 Apr 2026 14:28:12 +0200 (CEST)","by mail-wm1-x333.google.com with SMTP id\n 5b1f17b1804b1-4887fd35e60so4091715e9.2\n for <ltp@lists.linux.it>; Fri, 17 Apr 2026 05:28:12 -0700 (PDT)","from localhost ([2a07:de40:b240:0:2ad6:ed42:2ad6:ed42])\n by smtp.gmail.com with UTF8SMTPSA id\n 5b1f17b1804b1-488fc1c01cfsm44634985e9.10.2026.04.17.05.28.10\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Fri, 17 Apr 2026 05:28:10 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it;\n i=@lists.linux.it; q=dns/txt; s=picard; t=1776428898; h=to : date :\n message-id : in-reply-to : references : mime-version : subject :\n list-id : list-unsubscribe : list-archive : list-post : list-help :\n list-subscribe : from : reply-to : content-type :\n content-transfer-encoding : sender : from;\n bh=gJmh7lVuzvO9QReKwum5NGHSsVk+NIfReRVJqchEHgU=;\n b=badd1bANxX0AHaKIkt/WLSYy9lwJwWcNmcHQlMIcIrxbvFMd+GDHKpA6o7wOe8NFKPoNg\n jxX0uXbpI/ON9vXJw+R1XVJW2WdolNLr7gKoz6s5Hhd0T7vcTVKtBhRjwBNW/PP2N0B5WFq\n 9C/NuIErlaVV9Iti6KD0vUZTfR5nrFc=","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=suse.com; s=google; t=1776428891; x=1777033691; darn=lists.linux.it;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=KdXOtCD7I3b1TLJGpWJ5T/haN23bfDiQl4bLQjTi/zc=;\n b=VHTcIkEdOUkGeVZ7ppyJFJHJz8jk0vF6z5cDbdlF2gSy5h8ISZz13Nf0NCEghTBW48\n 7iNy0v5O1RfMJCslGII0TLTCD5kwPkTA1ic4FvzYArTd/pODLLK4Kj1DShg8+KKM1nU6\n vOGtZUsXZc5a2CCVOIFxw7NZn9kCo1OwEgtq4XfMX1jBg8oIEsqWBCOTTdM+CdfaqCiD\n cdcH/O+1pAshWQacArnAZ5SDBxMZXNtHPQ0CqTnvUGyOqsFyJ9bvZ1j2Ycqmk26VRd7K\n hlnISE6BEoU5uvpp4Qb8IW0wiivPxS8t4HDejTfXPIlh5j6h3noy4XFd6i1mjkHCF5mW\n QdxQ=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776428891; x=1777033691;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=KdXOtCD7I3b1TLJGpWJ5T/haN23bfDiQl4bLQjTi/zc=;\n b=fcBo16WYwyatlnHrJRvGtbQNji8ARqYN5lUqRO/qWnGQ8Kf0X7En6cNiu1CT2TMCn/\n xl6mxnnuCFco14XtpxzbGOGOl2M/ZDbzFXFNO8xGJu2d25CSRfSqRb63khCr1VwrOEC8\n 2LsRvbkC+XNoDn1pLRcGSd7JNzRCqinv71Mund1//7fIRYce6eG+MXva5kjFHqD35AfJ\n 0hDejb6KdLBn6cyLIFYclp2qIxgvnrkj2O0TrbABUdiEkEXKnj1Batrk4J3Gsne6twDC\n Vjt45WjhtBpyt44wfwBtSQ5W2EliXYxt+K9TNU2TL5bdAltmUMyq0+rArwDnWzpibIsg\n a58A==","X-Gm-Message-State":"AOJu0YxuMhLNHGGxv/++IddCpSaYb+DrEuY+p/KeCI0ULw2QEnn7GJNp\n aOZoZBfdyPmdcUEi3bqR2ANeigT2Gl1d+WjGu1ywQZetDcyUyM1ZxRaltMUZbLkdg+XJtimtr2c\n Z6RnyiQ==","X-Gm-Gg":"AeBDievN30TxgqFAaGKY2z1yfP88y4Pq4HUq9qx2B/pIgOvMG2MDnJwktqcFUqOGLtb\n 5cmVf7e5aGyLJ/3xBcb9l54WvR22R7kN/Ko9sfG4AwuHPg19PCa7kE+DprLTxwjGK8ffLjXDA9m\n WnViNG3byTYDEyS4Smu57+xyst2wS/pdS/3N2SANMQ0XQnDXn6LEG4+vQVzBSWNNlA2UanCW3ME\n +5B0EuW74/xFw0UBcijPh3k9vOlBtbUfwDc01Wrilog+a5r7f9nZnqU0JwzRgru9wdXEErbiSXc\n g0s3usTgBIO0KgS1xW7Yrpnko6U64dJ0bCY+ZvrXXiD1PWy846W502rMa65gA7j78gvhoDDu2sw\n wG28SnNhBUk6tGSjjteqihVji7bUqfGGZWblpvRQInZK1ZYxajzBSKri7IYBvpolMCsuKFuZyF2\n YB02hxQ7md+qnnGfZTr9nQEA==","X-Received":"by 2002:a05:600c:a31a:b0:488:b241:2c5f with SMTP id\n 5b1f17b1804b1-488fb785b7emr27220845e9.26.1776428891443;\n Fri, 17 Apr 2026 05:28:11 -0700 (PDT)","To":"ltp@lists.linux.it","Date":"Fri, 17 Apr 2026 12:27:55 +0000","Message-ID":"<20260417122804.23890-1-wegao@suse.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20260417065332.23663-1-wegao@suse.com>","References":"<20260417065332.23663-1-wegao@suse.com>","MIME-Version":"1.0","X-Spam-Status":"No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID,\n DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no\n autolearn=disabled version=4.0.1","X-Spam-Checker-Version":"SpamAssassin 4.0.1 (2024-03-25) on in-7.smtp.seeweb.it","X-Virus-Scanned":"clamav-milter 1.0.9 at in-7.smtp.seeweb.it","X-Virus-Status":"Clean","Subject":"[LTP] [PATCH v8] mremap07.c: New test for mremap() with\n MREMAP_DONTUNMAP","X-BeenThere":"ltp@lists.linux.it","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"Linux Test Project <ltp.lists.linux.it>","List-Unsubscribe":"<https://lists.linux.it/options/ltp>,\n <mailto:ltp-request@lists.linux.it?subject=unsubscribe>","List-Archive":"<http://lists.linux.it/pipermail/ltp/>","List-Post":"<mailto:ltp@lists.linux.it>","List-Help":"<mailto:ltp-request@lists.linux.it?subject=help>","List-Subscribe":"<https://lists.linux.it/listinfo/ltp>,\n <mailto:ltp-request@lists.linux.it?subject=subscribe>","From":"Wei Gao via ltp <ltp@lists.linux.it>","Reply-To":"Wei Gao <wegao@suse.com>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it","Sender":"\"ltp\" <ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it>"},"content":"This test verifies the mremap() syscall with the MREMAP_DONTUNMAP flag.\nIt uses userfaultfd to verify that accessing the old memory region\ncorrectly triggers a page fault after the mapping has been moved.\n\nMREMAP_DONTUNMAP behavior with userfaultfd was not covered by existing\nmremap tests. This test provides coverage for the feature requested in\nthe linked issue.\n\nCloses: https://github.com/linux-test-project/ltp/issues/1168\nSigned-off-by: Wei Gao <wegao@suse.com>\n---\nv7 -> v8:\n- Change Fixes: tag to Closes: for GitHub issue reference.\n\n configure.ac                                |   1 +\n runtest/syscalls                            |   1 +\n testcases/kernel/syscalls/mremap/.gitignore |   1 +\n testcases/kernel/syscalls/mremap/Makefile   |   1 +\n testcases/kernel/syscalls/mremap/mremap07.c | 158 ++++++++++++++++++++\n 5 files changed, 162 insertions(+)\n create mode 100644 testcases/kernel/syscalls/mremap/mremap07.c","diff":"diff --git a/configure.ac b/configure.ac\nindex 812f17d8b..211aaa8ad 100644\n--- a/configure.ac\n+++ b/configure.ac\n@@ -46,6 +46,7 @@ AC_CHECK_DECLS([MADV_MERGEABLE],,,[#include <sys/mman.h>])\n AC_CHECK_DECLS([NFTA_CHAIN_ID, NFTA_VERDICT_CHAIN_ID],,,[#include <linux/netfilter/nf_tables.h>])\n AC_CHECK_DECLS([PR_CAPBSET_DROP, PR_CAPBSET_READ],,,[#include <sys/prctl.h>])\n AC_CHECK_DECLS([SEM_STAT_ANY],,,[#include <sys/sem.h>])\n+AC_CHECK_DECLS([MREMAP_DONTUNMAP],,,[#include <linux/mman.h>])\n \n AC_CHECK_HEADERS_ONCE([ \\\n     aio.h \\\ndiff --git a/runtest/syscalls b/runtest/syscalls\nindex d72fceb5e..b9a9ce5fe 100644\n--- a/runtest/syscalls\n+++ b/runtest/syscalls\n@@ -927,6 +927,7 @@ mremap03 mremap03\n mremap04 mremap04\n mremap05 mremap05\n mremap06 mremap06\n+mremap07 mremap07\n \n mseal01 mseal01\n mseal02 mseal02\ndiff --git a/testcases/kernel/syscalls/mremap/.gitignore b/testcases/kernel/syscalls/mremap/.gitignore\nindex ec15a19cd..292899e03 100644\n--- a/testcases/kernel/syscalls/mremap/.gitignore\n+++ b/testcases/kernel/syscalls/mremap/.gitignore\n@@ -4,3 +4,4 @@\n /mremap04\n /mremap05\n /mremap06\n+/mremap07\ndiff --git a/testcases/kernel/syscalls/mremap/Makefile b/testcases/kernel/syscalls/mremap/Makefile\nindex 9f5aca9ec..8811b887e 100644\n--- a/testcases/kernel/syscalls/mremap/Makefile\n+++ b/testcases/kernel/syscalls/mremap/Makefile\n@@ -8,5 +8,6 @@ LTPLIBS = ipc\n include $(top_srcdir)/include/mk/testcases.mk\n \n mremap04: LTPLDLIBS  = -lltpipc\n+mremap07: LDLIBS  += -lpthread\n \n include $(top_srcdir)/include/mk/generic_leaf_target.mk\ndiff --git a/testcases/kernel/syscalls/mremap/mremap07.c b/testcases/kernel/syscalls/mremap/mremap07.c\nnew file mode 100644\nindex 000000000..102136322\n--- /dev/null\n+++ b/testcases/kernel/syscalls/mremap/mremap07.c\n@@ -0,0 +1,158 @@\n+// SPDX-License-Identifier: GPL-2.0-or-later\n+/*\n+ * Copyright (c) 2026 Wei Gao <wegao@suse.com>\n+ */\n+\n+/*\\\n+ * LTP test case for mremap() with MREMAP_DONTUNMAP and userfaultfd.\n+ *\n+ * Test mremap() with MREMAP_DONTUNMAP and verify that accessing the\n+ * old memory region triggers a page fault, which is then correctly\n+ * handled by a userfaultfd handler.\n+ */\n+\n+#define _GNU_SOURCE\n+#include <poll.h>\n+#include <pthread.h>\n+#include <linux/mman.h>\n+\n+#include \"tst_test.h\"\n+#include \"tst_safe_pthread.h\"\n+#include \"lapi/userfaultfd.h\"\n+#include \"config.h\"\n+\n+#if HAVE_DECL_MREMAP_DONTUNMAP\n+\n+static int page_size;\n+static int uffd = -1;\n+static char *fault_addr;\n+static char *new_remap_addr;\n+\n+static const char *test_string = \"Hello, world! This is a test string that fills up a page.\";\n+\n+static void *fault_handler_thread(void *arg LTP_ATTRIBUTE_UNUSED)\n+{\n+\tstruct uffd_msg msg;\n+\tstruct uffdio_copy uffdio_copy;\n+\n+\tTST_CHECKPOINT_WAIT(0);\n+\n+\tstruct pollfd pollfd;\n+\n+\tpollfd.fd = uffd;\n+\tpollfd.events = POLLIN;\n+\n+\tint nready = poll(&pollfd, 1, -1);\n+\n+\tif (nready == -1)\n+\t\ttst_brk(TBROK | TERRNO, \"poll() failed\");\n+\n+\tif (nready == 0)\n+\t\ttst_brk(TBROK, \"poll() timed out unexpectedly\");\n+\n+\tSAFE_READ(1, uffd, &msg, sizeof(msg));\n+\n+\tif (msg.event != UFFD_EVENT_PAGEFAULT)\n+\t\ttst_brk(TBROK, \"Received unexpected UFFD_EVENT: %d\", msg.event);\n+\n+\tif ((char *)msg.arg.pagefault.address != fault_addr)\n+\t\ttst_brk(TBROK, \"Page fault on unexpected address: %p\", (void *)msg.arg.pagefault.address);\n+\n+\ttst_res(TINFO, \"Userfaultfd handler caught a page fault at %p\", (void *)msg.arg.pagefault.address);\n+\n+\tuffdio_copy.src = (unsigned long)new_remap_addr;\n+\tuffdio_copy.dst = (unsigned long)fault_addr;\n+\tuffdio_copy.len = page_size;\n+\tuffdio_copy.mode = 0;\n+\tuffdio_copy.copy = 0;\n+\n+\tSAFE_IOCTL(uffd, UFFDIO_COPY, &uffdio_copy);\n+\ttst_res(TPASS, \"Userfaultfd handler successfully handled the fault\");\n+\n+\treturn NULL;\n+}\n+\n+static void setup(void)\n+{\n+\tpage_size = getpagesize();\n+\tstruct uffdio_api uffdio_api;\n+\tstruct uffdio_register uffdio_register;\n+\n+\tuffd = SAFE_USERFAULTFD(O_CLOEXEC | O_NONBLOCK, true);\n+\n+\tuffdio_api.api = UFFD_API;\n+\tuffdio_api.features = 0;\n+\tSAFE_IOCTL(uffd, UFFDIO_API, &uffdio_api);\n+\n+\tfault_addr = SAFE_MMAP(NULL, page_size,\n+\t\tPROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);\n+\n+\ttst_res(TINFO, \"Original mapping created at %p\", (void *)fault_addr);\n+\n+\tstrcpy(fault_addr, \"ABCD\");\n+\n+\tuffdio_register.range.start = (unsigned long)fault_addr;\n+\tuffdio_register.range.len = page_size;\n+\tuffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING;\n+\tSAFE_IOCTL(uffd, UFFDIO_REGISTER, &uffdio_register);\n+}\n+\n+static void cleanup(void)\n+{\n+\tif (new_remap_addr && new_remap_addr != MAP_FAILED)\n+\t\tSAFE_MUNMAP(new_remap_addr, page_size);\n+\n+\tif (fault_addr && fault_addr != MAP_FAILED)\n+\t\tSAFE_MUNMAP(fault_addr, page_size);\n+\n+\tif (uffd != -1)\n+\t\tSAFE_CLOSE(uffd);\n+}\n+\n+static void run(void)\n+{\n+\tpthread_t handler_thread;\n+\n+\tSAFE_PTHREAD_CREATE(&handler_thread, NULL,\n+\t\tfault_handler_thread, NULL);\n+\n+\tnew_remap_addr = mremap(fault_addr, page_size, page_size,\n+\t\tMREMAP_DONTUNMAP | MREMAP_MAYMOVE, NULL);\n+\n+\tif (new_remap_addr == MAP_FAILED)\n+\t\ttst_brk(TBROK | TERRNO, \"mremap failed\");\n+\n+\ttst_res(TINFO, \"New mapping created at %p\", (void *)new_remap_addr);\n+\n+\tstrcpy(new_remap_addr, test_string);\n+\n+\tTST_CHECKPOINT_WAKE(0);\n+\n+\ttst_res(TINFO, \"Main thread accessing old address %p to trigger fault\",\n+\t\t\t(void *)fault_addr);\n+\n+\t(void)*(volatile char *)fault_addr;\n+\n+\tSAFE_PTHREAD_JOIN(handler_thread, NULL);\n+\n+\tTST_EXP_EQ_STR(fault_addr, test_string);\n+\n+\tSAFE_MUNMAP(new_remap_addr, page_size);\n+\tnew_remap_addr = NULL;\n+}\n+\n+static struct tst_test test = {\n+\t.test_all = run,\n+\t.setup = setup,\n+\t.needs_checkpoints = 1,\n+\t.cleanup = cleanup,\n+\t.needs_kconfigs = (const char *[]) {\n+\t\t\"CONFIG_USERFAULTFD=y\",\n+\t\tNULL,\n+\t},\n+\t.min_kver = \"5.7\",\n+};\n+\n+#else\n+TST_TEST_TCONF(\"Missing MREMAP_DONTUNMAP in <linux/mman.h>\");\n+#endif\n","prefixes":["v8"]}