• David Hildenbrand's avatar
    selftests/mm: factor out detection of hugetlb page sizes into vm_util · 81b1e3f9
    David Hildenbrand authored
    Patch series "selftests/mm: new test for FOLL_LONGTERM on file mappings".
    
    Let's add some selftests to make sure that:
    * R/O long-term pinning always works of file mappings
    * R/W long-term pinning always works in MAP_PRIVATE file mappings
    * R/W long-term pinning only works in MAP_SHARED mappings with special
      filesystems (shmem, hugetlb) and fails with other filesystems (ext4, btrfs,
      xfs).
    
    The tests make use of the gup_test kernel module to trigger ordinary GUP
    and GUP-fast, and liburing (similar to our COW selftests).  Test with
    memfd, memfd hugetlb, tmpfile() and mkstemp().  The latter usually gives
    us a "real" filesystem (ext4, btrfs, xfs) where long-term pinning is
    expected to fail.
    
    Note that these selftests don't contain any actual reproducers for data
    corruptions in case R/W long-term pinning on problematic filesystems
    "would" work.
    
    Maybe we can later come up with a racy !FOLL_LONGTERM reproducer that can
    reuse an existing interface to trigger short-term pinning (I'll look into
    that next).
    
    On current mm/mm-unstable:
    	# ./gup_longterm
    	# [INFO] detected hugetlb page size: 2048 KiB
    	# [INFO] detected hugetlb page size: 1048576 KiB
    	TAP version 13
    	1..50
    	# [RUN] R/W longterm GUP pin in MAP_SHARED file mapping ... with memfd
    	ok 1 Should have worked
    	# [RUN] R/W longterm GUP pin in MAP_SHARED file mapping ... with tmpfile
    	ok 2 Should have worked
    	# [RUN] R/W longterm GUP pin in MAP_SHARED file mapping ... with local tmpfile
    	ok 3 Should have failed
    	# [RUN] R/W longterm GUP pin in MAP_SHARED file mapping ... with memfd hugetlb (2048 kB)
    	ok 4 Should have worked
    	# [RUN] R/W longterm GUP pin in MAP_SHARED file mapping ... with memfd hugetlb (1048576 kB)
    	ok 5 Should have worked
    	# [RUN] R/W longterm GUP-fast pin in MAP_SHARED file mapping ... with memfd
    	ok 6 Should have worked
    	# [RUN] R/W longterm GUP-fast pin in MAP_SHARED file mapping ... with tmpfile
    	ok 7 Should have worked
    	# [RUN] R/W longterm GUP-fast pin in MAP_SHARED file mapping ... with local tmpfile
    	ok 8 Should have failed
    	# [RUN] R/W longterm GUP-fast pin in MAP_SHARED file mapping ... with memfd hugetlb (2048 kB)
    	ok 9 Should have worked
    	# [RUN] R/W longterm GUP-fast pin in MAP_SHARED file mapping ... with memfd hugetlb (1048576 kB)
    	ok 10 Should have worked
    	# [RUN] R/O longterm GUP pin in MAP_SHARED file mapping ... with memfd
    	ok 11 Should have worked
    	# [RUN] R/O longterm GUP pin in MAP_SHARED file mapping ... with tmpfile
    	ok 12 Should have worked
    	# [RUN] R/O longterm GUP pin in MAP_SHARED file mapping ... with local tmpfile
    	ok 13 Should have worked
    	# [RUN] R/O longterm GUP pin in MAP_SHARED file mapping ... with memfd hugetlb (2048 kB)
    	ok 14 Should have worked
    	# [RUN] R/O longterm GUP pin in MAP_SHARED file mapping ... with memfd hugetlb (1048576 kB)
    	ok 15 Should have worked
    	# [RUN] R/O longterm GUP-fast pin in MAP_SHARED file mapping ... with memfd
    	ok 16 Should have worked
    	# [RUN] R/O longterm GUP-fast pin in MAP_SHARED file mapping ... with tmpfile
    	ok 17 Should have worked
    	# [RUN] R/O longterm GUP-fast pin in MAP_SHARED file mapping ... with local tmpfile
    	ok 18 Should have worked
    	# [RUN] R/O longterm GUP-fast pin in MAP_SHARED file mapping ... with memfd hugetlb (2048 kB)
    	ok 19 Should have worked
    	# [RUN] R/O longterm GUP-fast pin in MAP_SHARED file mapping ... with memfd hugetlb (1048576 kB)
    	ok 20 Should have worked
    	# [RUN] R/W longterm GUP pin in MAP_PRIVATE file mapping ... with memfd
    	ok 21 Should have worked
    	# [RUN] R/W longterm GUP pin in MAP_PRIVATE file mapping ... with tmpfile
    	ok 22 Should have worked
    	# [RUN] R/W longterm GUP pin in MAP_PRIVATE file mapping ... with local tmpfile
    	ok 23 Should have worked
    	# [RUN] R/W longterm GUP pin in MAP_PRIVATE file mapping ... with memfd hugetlb (2048 kB)
    	ok 24 Should have worked
    	# [RUN] R/W longterm GUP pin in MAP_PRIVATE file mapping ... with memfd hugetlb (1048576 kB)
    	ok 25 Should have worked
    	# [RUN] R/W longterm GUP-fast pin in MAP_PRIVATE file mapping ... with memfd
    	ok 26 Should have worked
    	# [RUN] R/W longterm GUP-fast pin in MAP_PRIVATE file mapping ... with tmpfile
    	ok 27 Should have worked
    	# [RUN] R/W longterm GUP-fast pin in MAP_PRIVATE file mapping ... with local tmpfile
    	ok 28 Should have worked
    	# [RUN] R/W longterm GUP-fast pin in MAP_PRIVATE file mapping ... with memfd hugetlb (2048 kB)
    	ok 29 Should have worked
    	# [RUN] R/W longterm GUP-fast pin in MAP_PRIVATE file mapping ... with memfd hugetlb (1048576 kB)
    	ok 30 Should have worked
    	# [RUN] R/O longterm GUP pin in MAP_PRIVATE file mapping ... with memfd
    	ok 31 Should have worked
    	# [RUN] R/O longterm GUP pin in MAP_PRIVATE file mapping ... with tmpfile
    	ok 32 Should have worked
    	# [RUN] R/O longterm GUP pin in MAP_PRIVATE file mapping ... with local tmpfile
    	ok 33 Should have worked
    	# [RUN] R/O longterm GUP pin in MAP_PRIVATE file mapping ... with memfd hugetlb (2048 kB)
    	ok 34 Should have worked
    	# [RUN] R/O longterm GUP pin in MAP_PRIVATE file mapping ... with memfd hugetlb (1048576 kB)
    	ok 35 Should have worked
    	# [RUN] R/O longterm GUP-fast pin in MAP_PRIVATE file mapping ... with memfd
    	ok 36 Should have worked
    	# [RUN] R/O longterm GUP-fast pin in MAP_PRIVATE file mapping ... with tmpfile
    	ok 37 Should have worked
    	# [RUN] R/O longterm GUP-fast pin in MAP_PRIVATE file mapping ... with local tmpfile
    	ok 38 Should have worked
    	# [RUN] R/O longterm GUP-fast pin in MAP_PRIVATE file mapping ... with memfd hugetlb (2048 kB)
    	ok 39 Should have worked
    	# [RUN] R/O longterm GUP-fast pin in MAP_PRIVATE file mapping ... with memfd hugetlb (1048576 kB)
    	ok 40 Should have worked
    	# [RUN] io_uring fixed buffer with MAP_SHARED file mapping ... with memfd
    	ok 41 Should have worked
    	# [RUN] io_uring fixed buffer with MAP_SHARED file mapping ... with tmpfile
    	ok 42 Should have worked
    	# [RUN] io_uring fixed buffer with MAP_SHARED file mapping ... with local tmpfile
    	ok 43 Should have failed
    	# [RUN] io_uring fixed buffer with MAP_SHARED file mapping ... with memfd hugetlb (2048 kB)
    	ok 44 Should have worked
    	# [RUN] io_uring fixed buffer with MAP_SHARED file mapping ... with memfd hugetlb (1048576 kB)
    	ok 45 Should have worked
    	# [RUN] io_uring fixed buffer with MAP_PRIVATE file mapping ... with memfd
    	ok 46 Should have worked
    	# [RUN] io_uring fixed buffer with MAP_PRIVATE file mapping ... with tmpfile
    	ok 47 Should have worked
    	# [RUN] io_uring fixed buffer with MAP_PRIVATE file mapping ... with local tmpfile
    	ok 48 Should have worked
    	# [RUN] io_uring fixed buffer with MAP_PRIVATE file mapping ... with memfd hugetlb (2048 kB)
    	ok 49 Should have worked
    	# [RUN] io_uring fixed buffer with MAP_PRIVATE file mapping ... with memfd hugetlb (1048576 kB)
    	ok 50 Should have worked
    	# Totals: pass:50 fail:0 xfail:0 xpass:0 skip:0 error:0
    
    
    This patch (of 3):
    
    Let's factor detection out into vm_util, to be reused by a new test.
    
    Link: https://lkml.kernel.org/r/20230519102723.185721-1-david@redhat.com
    Link: https://lkml.kernel.org/r/20230519102723.185721-2-david@redhat.comSigned-off-by: default avatarDavid Hildenbrand <david@redhat.com>
    Reviewed-by: default avatarLorenzo Stoakes <lstoakes@gmail.com>
    Cc: Jan Kara <jack@suse.cz>
    Cc: Jason Gunthorpe <jgg@nvidia.com>
    Cc: Jens Axboe <axboe@kernel.dk>
    Cc: John Hubbard <jhubbard@nvidia.com>
    Cc: Peter Xu <peterx@redhat.com>
    Cc: Shuah Khan <shuah@kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    81b1e3f9
cow.c 41.3 KB