{"id":2215652,"url":"http://patchwork.ozlabs.org/api/patches/2215652/?format=json","web_url":"http://patchwork.ozlabs.org/project/ltp/patch/20260325011605.5957-1-wegao@suse.com/","project":{"id":59,"url":"http://patchwork.ozlabs.org/api/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":"<20260325011605.5957-1-wegao@suse.com>","list_archive_url":null,"date":"2026-03-25T01:15:53","name":"[v5] mremap07.c: New case check mremap with MREMAP_DONTUNMAP","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":false,"hash":"2d1166f1dd1c5e76d7a457a1d8bf29582ccbbfa0","submitter":{"id":85577,"url":"http://patchwork.ozlabs.org/api/people/85577/?format=json","name":"Wei Gao","email":"wegao@suse.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/ltp/patch/20260325011605.5957-1-wegao@suse.com/mbox/","series":[{"id":497368,"url":"http://patchwork.ozlabs.org/api/series/497368/?format=json","web_url":"http://patchwork.ozlabs.org/project/ltp/list/?series=497368","date":"2026-03-25T01:15:53","name":"[v5] mremap07.c: New case check mremap with MREMAP_DONTUNMAP","version":5,"mbox":"http://patchwork.ozlabs.org/series/497368/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2215652/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2215652/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=YgB30ZcM;\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=Yev80XKz;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it\n (client-ip=213.254.12.146; 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 [213.254.12.146])\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 4fgTWT1408z1xy3\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 25 Mar 2026 12:16:18 +1100 (AEDT)","from picard.linux.it (localhost [IPv6:::1])\n\tby picard.linux.it (Postfix) with ESMTP id 6C0913E5EFC\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 25 Mar 2026 02:16:14 +0100 (CET)","from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6])\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 5F1303CC477\n for <ltp@lists.linux.it>; Wed, 25 Mar 2026 02:16:10 +0100 (CET)","from mail-wm1-x335.google.com (mail-wm1-x335.google.com\n [IPv6:2a00:1450:4864:20::335])\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-6.smtp.seeweb.it (Postfix) with ESMTPS id 6CB5A1400B88\n for <ltp@lists.linux.it>; Wed, 25 Mar 2026 02:16:09 +0100 (CET)","by mail-wm1-x335.google.com with SMTP id\n 5b1f17b1804b1-487035181a7so25696275e9.2\n for <ltp@lists.linux.it>; Tue, 24 Mar 2026 18:16:09 -0700 (PDT)","from localhost ([2a07:de40:b240:0:2ad6:ed42:2ad6:ed42])\n by smtp.gmail.com with UTF8SMTPSA id\n 5b1f17b1804b1-4871174f2cesm89314195e9.10.2026.03.24.18.16.07\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Tue, 24 Mar 2026 18:16:07 -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=1774401374; 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=2E5u+84vhhuVpdZ98Wfy9WcUtrVVTyY6AtPUUFQUKxo=;\n b=YgB30ZcMwft6inBJ4FKD6gvMLUH+1qhpALCYi9nr22o00WHY0ifXc2koCaHmXTnGDNxnj\n 4W7U3BYl/FhAN1IxCf71NPgdfOy2OF5V2h/ZolZ63eJ4IIN9SE0YKDLhXeSd/NetjRA5eTY\n KL5llo3Hlk+t9B/ko7dxaltJCCX08Ww=","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=suse.com; s=google; t=1774401368; x=1775006168; 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=snGyBniSzxVyZaBvhoDjJilvPiB7l1hVEw961Vc7OwU=;\n b=Yev80XKz+GmPjhRq+Yzi7OC0XxIvlkBwPw9+lKxyXMi19v1ptA4QvbyuQ7rQxJ1MDR\n hl4zZ3h4ZwGyYHrCGOWW10/Q1X9YwcLeku0ItRoWPKW+KNq+lhPGhPAgfv3SgLgjK0aX\n BBtGraqkJrPDIFsTx0hqVFUweQrqmAV2G9Bmm+KJn1pqb6yrCIjKPSAoVNMXCLLC2xfI\n EamhrtNCq0SjC17NKilNJprCaTBw4maYkApys5dC7pUqSoB5NZYfTXou/bEBxOcPJoCI\n gDAwTluDI7D5kw29CG1VVF/xv7HSiz3ErWqe9C2xJJc9lvPwqzr1AQZqfTFsIs4uVm3n\n 2X2g=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1774401368; x=1775006168;\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=snGyBniSzxVyZaBvhoDjJilvPiB7l1hVEw961Vc7OwU=;\n b=figusclrEV0Z4Sa3Ty7wEGcUktbQMfdpYCPSuHg4NSY+eHz/kCjgJRhFh8RNBkHKWb\n aVCjAedc+L837u6kqjh8784LcjWUI5hxCAHIsV0zuSKBRsBxcL8gS8t3CUMHeRYSw+Tk\n rk1wWc9vy9PgQ5WJBNmlWKRcNhK/VJMyRlWnNwnPlf2Xf/9lPMLA6CUlSSVxyRJGqR+p\n QAaM5gcLI2HQCxwBcyyhAcLCq8ZvgwVAyP3Fc0Jn0Ce98zOTBP9y8wN/+q+qpnX3g+Vp\n UvMSISce39Lepgl4cemNQAGd6eJeok37skxh2zUSq+65tGi4auCp1of0ORlVcRUUGGXg\n imMQ==","X-Gm-Message-State":"AOJu0YyXPy88/Z/wh97Q+pnll3uFix5uT1wwvcwf+uZyki/FIHfFiuuM\n Ujgr/rTSDqlz3772oayWbMh+i4oiV/OO4faeZENi4nBdbtBS7plT6xL+xQJ9larwIN0ENeLmd4q\n 1dPM=","X-Gm-Gg":"ATEYQzwjsaN5TXWsgYP0nQZa5Za484Q3cCNPmH5w2ZNnppZKEN1BTd/nbXxCAmbSmpr\n WKXabBkonkMDCh/mbkYCAtK2UDfjv9Vv5bheFcHiH0f1OWJuqfsMZRsCk80rLnDeZrv7rM8RwTF\n iQ9Ez3zFvuhCBI6F+4L+ejASgEf6B2NesYIxVk3Nm8sg6oyK6v1fKJ4A45bCOeSxULhYoRvlTfu\n n4NckOjqu63JVr+KhHuZnCnDqXmLhxCG6sGnd4K3dY6mPbVn5cj8rDqL9CCHQzq9u9DOxhu7mPs\n jM5mg9eVaGwjyuWquk6Zc6xaCIw4dmt4+aERTKhTo+FOnlUYLQ1eKLq577rdy7REoQRUyR+LHdu\n MUayX/k7IAS1T65ZT+CQn/l8xDGJuOamalUpcESsvhM4I81/1NZrH14bVoDJVCOiaChS7Rp8A25\n GzIqAIqsD5jto=","X-Received":"by 2002:a05:600c:1f12:b0:487:575:5e1 with SMTP id\n 5b1f17b1804b1-487160511e0mr22248645e9.24.1774401368296;\n Tue, 24 Mar 2026 18:16:08 -0700 (PDT)","To":"ltp@lists.linux.it","Date":"Wed, 25 Mar 2026 01:15:53 +0000","Message-ID":"<20260325011605.5957-1-wegao@suse.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20260225090525.19581-1-wegao@suse.com>","References":"<20260225090525.19581-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-6.smtp.seeweb.it","X-Virus-Scanned":"clamav-milter 1.0.9 at in-6.smtp.seeweb.it","X-Virus-Status":"Clean","Subject":"[LTP] [PATCH v5] mremap07.c: New case check 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 case test mremap() with MREMAP_DONTUNMAP and use userfaultfd\nverifies fault which triggered by accessing old memory region.\n\nFixes: #1168\nSigned-off-by: Wei Gao <wegao@suse.com>\n---\nv4->v5:\n1)Added NULL as the 5th argument to mremap(), otherwise mremap will return\nEINVAL, latest kernel will check new address is aligned or not.\n2)Initialized uffd to -1\n3)Updated fault_handler_thread to return void *\n4)Enhanced the cleanup() function to verify that pointers are not\nMAP_FAILED\n5)Switched from TTERRNO to TERRNO in the mremap check\n6)Removed .needs_root = 1\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 | 160 ++++++++++++++++++++\n 5 files changed, 164 insertions(+)\n create mode 100644 testcases/kernel/syscalls/mremap/mremap07.c","diff":"diff --git a/configure.ac b/configure.ac\nindex 7fa614dcb..c836ef7f3 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 2f629e4e4..9d7c6c32e 100644\n--- a/runtest/syscalls\n+++ b/runtest/syscalls\n@@ -925,6 +925,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..51c24b6fc\n--- /dev/null\n+++ b/testcases/kernel/syscalls/mremap/mremap07.c\n@@ -0,0 +1,160 @@\n+// SPDX-License-Identifier: GPL-2.0-or-later\n+/*\n+ * Copyright (c) 2025 Wei Gao <wegao@suse.com>\n+ */\n+\n+/*\\\n+ * LTP test case for mremap() with MREMAP_DONTUNMAP and userfaultfd.\n+ *\n+ * This test verifies a fault is triggered on the old memory region\n+ * and is then correctly 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+\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+\tif (strcmp(fault_addr, test_string) != 0)\n+\t\ttst_res(TFAIL, \"Verification failed: Content of the old \"\n+\t\t\t\"address is '%s', expected '%s'\", fault_addr, test_string);\n+\telse\n+\t\ttst_res(TPASS, \"Verification passed: Content of the old \"\n+\t\t\t\"address is correct after fault handling\");\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":["v5"]}