]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/udmabuf: add a test to pin first before writing to memfd
authorVivek Kasireddy <vivek.kasireddy@intel.com>
Wed, 18 Jun 2025 05:30:55 +0000 (22:30 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 10 Jul 2025 05:42:15 +0000 (22:42 -0700)
Unlike the existing tests, this new test will create a memfd (backed by
hugetlb) and pin the folios in it (a small subset) before writing/
populating it with data.  This is a valid use-case that invokes the
memfd_alloc_folio() kernel API and is expected to work unless there aren't
enough hugetlb folios to satisfy the allocation needs.

Link: https://lkml.kernel.org/r/20250618053415.1036185-4-vivek.kasireddy@intel.com
Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Steve Sistare <steven.sistare@oracle.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: David Hildenbrand <david@redhat.com>
Cc: Oscar Salvador <osalvador@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/drivers/dma-buf/udmabuf.c

index 6062723a172e6fb351391e168472dd7de3e1f869..77aa2897e79f8e3ca571c0cdfdde18a1bce5bf35 100644 (file)
@@ -138,7 +138,7 @@ int main(int argc, char *argv[])
        void *addr1, *addr2;
 
        ksft_print_header();
-       ksft_set_plan(6);
+       ksft_set_plan(7);
 
        devfd = open("/dev/udmabuf", O_RDWR);
        if (devfd < 0) {
@@ -248,6 +248,24 @@ int main(int argc, char *argv[])
        else
                ksft_test_result_pass("%s: [PASS,test-6]\n", TEST_PREFIX);
 
+       close(buf);
+       close(memfd);
+
+       /* same test as above but we pin first before writing to memfd */
+       page_size = getpagesize() * 512; /* 2 MB */
+       size = MEMFD_SIZE * page_size;
+       memfd = create_memfd_with_seals(size, true);
+       buf = create_udmabuf_list(devfd, memfd, size);
+       addr2 = mmap_fd(buf, NUM_PAGES * NUM_ENTRIES * getpagesize());
+       addr1 = mmap_fd(memfd, size);
+       write_to_memfd(addr1, size, 'a');
+       write_to_memfd(addr1, size, 'b');
+       ret = compare_chunks(addr1, addr2, size);
+       if (ret < 0)
+               ksft_test_result_fail("%s: [FAIL,test-7]\n", TEST_PREFIX);
+       else
+               ksft_test_result_pass("%s: [PASS,test-7]\n", TEST_PREFIX);
+
        close(buf);
        close(memfd);
        close(devfd);