From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,kalyazin@amazon.com,akpm@linux-foundation.org
Subject: + kvm-selftests-test-userfaultfd-missing-for-guest_memfd.patch added to mm-unstable branch
Date: Mon, 30 Mar 2026 12:44:19 -0700 [thread overview]
Message-ID: <20260330194419.CE46DC4CEF7@smtp.kernel.org> (raw)
The patch titled
Subject: KVM: selftests: test userfaultfd missing for guest_memfd
has been added to the -mm mm-unstable branch. Its filename is
kvm-selftests-test-userfaultfd-missing-for-guest_memfd.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/kvm-selftests-test-userfaultfd-missing-for-guest_memfd.patch
This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Nikita Kalyazin <kalyazin@amazon.com>
Subject: KVM: selftests: test userfaultfd missing for guest_memfd
Date: Mon, 30 Mar 2026 13:11:16 +0300
The test demonstrates that a missing userfaultfd event in guest_memfd can
be resolved via a UFFDIO_COPY ioctl.
Link: https://lkml.kernel.org/r/20260330101116.1117699-16-rppt@kernel.org
Signed-off-by: Nikita Kalyazin <kalyazin@amazon.com>
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Andrei Vagin <avagin@google.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: David Hildenbrand (Arm) <david@kernel.org>
Cc: Harry Yoo <harry.yoo@oracle.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: James Houghton <jthoughton@google.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
tools/testing/selftests/kvm/guest_memfd_test.c | 80 ++++++++++++++-
1 file changed, 79 insertions(+), 1 deletion(-)
--- a/tools/testing/selftests/kvm/guest_memfd_test.c~kvm-selftests-test-userfaultfd-missing-for-guest_memfd
+++ a/tools/testing/selftests/kvm/guest_memfd_test.c
@@ -439,6 +439,82 @@ static void test_uffd_minor(int fd, size
close(uffd);
}
+static void test_uffd_missing(int fd, size_t total_size)
+{
+ struct uffdio_register uffd_reg;
+ struct uffdio_copy uffd_copy;
+ struct uffd_msg msg;
+ struct fault_args args;
+ pthread_t fault_thread;
+ void *mem, *buf = NULL;
+ int uffd, ret;
+ off_t offset = page_size;
+ void *fault_addr;
+ const char test_val = 0xab;
+
+ ret = posix_memalign(&buf, page_size, total_size);
+ TEST_ASSERT_EQ(ret, 0);
+ memset(buf, test_val, total_size);
+
+ uffd = syscall(__NR_userfaultfd, O_CLOEXEC);
+ TEST_ASSERT(uffd != -1, "userfaultfd creation should succeed");
+
+ struct uffdio_api uffdio_api = {
+ .api = UFFD_API,
+ .features = 0,
+ };
+ ret = ioctl(uffd, UFFDIO_API, &uffdio_api);
+ TEST_ASSERT(ret != -1, "ioctl(UFFDIO_API) should succeed");
+
+ mem = mmap(NULL, total_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ TEST_ASSERT(mem != MAP_FAILED, "mmap should succeed");
+
+ uffd_reg.range.start = (unsigned long)mem;
+ uffd_reg.range.len = total_size;
+ uffd_reg.mode = UFFDIO_REGISTER_MODE_MISSING;
+ ret = ioctl(uffd, UFFDIO_REGISTER, &uffd_reg);
+ TEST_ASSERT(ret != -1, "ioctl(UFFDIO_REGISTER) should succeed");
+
+ fault_addr = mem + offset;
+ args.addr = fault_addr;
+
+ ret = pthread_create(&fault_thread, NULL, fault_thread_fn, &args);
+ TEST_ASSERT(ret == 0, "pthread_create should succeed");
+
+ ret = read(uffd, &msg, sizeof(msg));
+ TEST_ASSERT(ret != -1, "read from userfaultfd should succeed");
+ TEST_ASSERT(msg.event == UFFD_EVENT_PAGEFAULT, "event type should be pagefault");
+ TEST_ASSERT((void *)(msg.arg.pagefault.address & ~(page_size - 1)) == fault_addr,
+ "pagefault should occur at expected address");
+ TEST_ASSERT(!(msg.arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WP),
+ "pagefault should not be write-protect");
+
+ uffd_copy.dst = (unsigned long)fault_addr;
+ uffd_copy.src = (unsigned long)(buf + offset);
+ uffd_copy.len = page_size;
+ uffd_copy.mode = 0;
+ ret = ioctl(uffd, UFFDIO_COPY, &uffd_copy);
+ TEST_ASSERT(ret != -1, "ioctl(UFFDIO_COPY) should succeed");
+
+ /* Wait for the faulting thread to complete - this provides the memory barrier */
+ ret = pthread_join(fault_thread, NULL);
+ TEST_ASSERT(ret == 0, "pthread_join should succeed");
+
+ /*
+ * Now it's safe to check args.value - the thread has completed
+ * and memory is synchronized
+ */
+ TEST_ASSERT(args.value == test_val,
+ "memory should contain the value that was copied");
+ TEST_ASSERT(*(char *)(mem + offset) == test_val,
+ "no further fault is expected");
+
+ ret = munmap(mem, total_size);
+ TEST_ASSERT(!ret, "munmap should succeed");
+ free(buf);
+ close(uffd);
+}
+
static void test_guest_memfd_flags(struct kvm_vm *vm)
{
uint64_t valid_flags = vm_check_cap(vm, KVM_CAP_GUEST_MEMFD_FLAGS);
@@ -494,8 +570,10 @@ static void __test_guest_memfd(struct kv
gmem_test(fallocate, vm, flags);
gmem_test(invalid_punch_hole, vm, flags);
- if (flags & GUEST_MEMFD_FLAG_INIT_SHARED)
+ if (flags & GUEST_MEMFD_FLAG_INIT_SHARED) {
gmem_test(uffd_minor, vm, flags);
+ gmem_test(uffd_missing, vm, flags);
+ }
}
static void test_guest_memfd(unsigned long vm_type)
_
Patches currently in -mm which might be from kalyazin@amazon.com are
kvm-guest_memfd-implement-userfaultfd-operations.patch
kvm-selftests-test-userfaultfd-minor-for-guest_memfd.patch
kvm-selftests-test-userfaultfd-missing-for-guest_memfd.patch
next reply other threads:[~2026-03-30 19:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-30 19:44 Andrew Morton [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-04-02 4:37 + kvm-selftests-test-userfaultfd-missing-for-guest_memfd.patch added to mm-unstable branch Andrew Morton
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=20260330194419.CE46DC4CEF7@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=kalyazin@amazon.com \
--cc=mm-commits@vger.kernel.org \
/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.