documented (hopefully adequately) in the respective changelogs. Notable series include: - Lucas Stach has provided some page-mapping cleanup/consolidation/maintainability work in the series "mm/treewide: Remove pXd_huge() API". - In the series "Allow migrate on protnone reference with MPOL_PREFERRED_MANY policy", Donet Tom has optimized mempolicy's MPOL_PREFERRED_MANY mode, yielding almost doubled performance in one test. - In their series "Memory allocation profiling" Kent Overstreet and Suren Baghdasaryan have contributed a means of determining (via /proc/allocinfo) whereabouts in the kernel memory is being allocated: number of calls and amount of memory. - Matthew Wilcox has provided the series "Various significant MM patches" which does a number of rather unrelated things, but in largely similar code sites. - In his series "mm: page_alloc: freelist migratetype hygiene" Johannes Weiner has fixed the page allocator's handling of migratetype requests, with resulting improvements in compaction efficiency. - In the series "make the hugetlb migration strategy consistent" Baolin Wang has fixed a hugetlb migration issue, which should improve hugetlb allocation reliability. - Liu Shixin has hit an I/O meltdown caused by readahead in a memory-tight memcg. Addressed in the series "Fix I/O high when memory almost met memcg limit". - In the series "mm/filemap: optimize folio adding and splitting" Kairui Song has optimized pagecache insertion, yielding ~10% performance improvement in one test. - Baoquan He has cleaned up and consolidated the early zone initialization code in the series "mm/mm_init.c: refactor free_area_init_core()". - Baoquan has also redone some MM initializatio code in the series "mm/init: minor clean up and improvement". - MM helper cleanups from Christoph Hellwig in his series "remove follow_pfn". - More cleanups from Matthew Wilcox in the series "Various page->flags cleanups". - Vlastimil Babka has contributed maintainability improvements in the series "memcg_kmem hooks refactoring". - More folio conversions and cleanups in Matthew Wilcox's series "Convert huge_zero_page to huge_zero_folio" "khugepaged folio conversions" "Remove page_idle and page_young wrappers" "Use folio APIs in procfs" "Clean up __folio_put()" "Some cleanups for memory-failure" "Remove page_mapping()" "More folio compat code removal" - David Hildenbrand chipped in with "fs/proc/task_mmu: convert hugetlb functions to work on folis". - Code consolidation and cleanup work related to GUP's handling of hugetlbs in Peter Xu's series "mm/gup: Unify hugetlb, part 2". - Rick Edgecombe has developed some fixes to stack guard gaps in the series "Cover a guard gap corner case". - Jinjiang Tu has fixed KSM's behaviour after a fork+exec in the series "mm/ksm: fix ksm exec support for prctl". - Baolin Wang has implemented NUMA balancing for multi-size THPs. This is a simple first-cut implementation for now. The series is "support multi-size THP numa balancing". - Cleanups to vma handling helper functions from Matthew Wilcox in the series "Unify vma_address and vma_pgoff_address". - Some selftests maintenance work from Dev Jain in the series "selftests/mm: mremap_test: Optimizations and style fixes". - Improvements to the swapping of multi-size THPs from Ryan Roberts in the series "Swap-out mTHP without splitting". - Kefeng Wang has significantly optimized the handling of arm64's permission page faults in the series "arch/mm/fault: accelerate pagefault when badaccess" "mm: remove arch's private VM_FAULT_BADMAP/BADACCESS" - GUP cleanups from David Hildenbrand in "mm/gup: consistently call it GUP-fast". - hugetlb fault code cleanups from Vishal Moola in "Hugetlb fault path to use struct vm_fault". - selftests build fixes from John Hubbard in the series "Fix selftests/mm build without requiring "make headers"". - Memory tiering fixes/improvements from Ho-Ren (Jack) Chuang in the series "Improved Memory Tier Creation for CPUless NUMA Nodes". Fixes the initialization code so that migration between different memory types works as intended. - David Hildenbrand has improved follow_pte() and fixed an errant driver in the series "mm: follow_pte() improvements and acrn follow_pte() fixes". - David also did some cleanup work on large folio mapcounts in his series "mm: mapcount for large folios + page_mapcount() cleanups". - Folio conversions in KSM in Alex Shi's series "transfer page to folio in KSM". - Barry Song has added some sysfs stats for monitoring multi-size THP's in the series "mm: add per-order mTHP alloc and swpout counters". - Some zswap cleanups from Yosry Ahmed in the series "zswap same-filled and limit checking cleanups". - Matthew Wilcox has been looking at buffer_head code and found the documentation to be lacking. The series is "Improve buffer head documentation". - Multi-size THPs get more work, this time from Lance Yang. His series "mm/madvise: enhance lazyfreeing with mTHP in madvise_free" optimizes the freeing of these things. - Kemeng Shi has added more userspace-visible writeback instrumentation in the series "Improve visibility of writeback". - Kemeng Shi then sent some maintenance work on top in the series "Fix and cleanups to page-writeback". - Matthew Wilcox reduces mmap_lock traffic in the anon vma code in the series "Improve anon_vma scalability for anon VMAs". Intel's test bot reported an improbable 3x improvement in one test. - SeongJae Park adds some DAMON feature work in the series "mm/damon: add a DAMOS filter type for page granularity access recheck" "selftests/damon: add DAMOS quota goal test" - Also some maintenance work in the series "mm/damon/paddr: simplify page level access re-check for pageout" "mm/damon: misc fixes and improvements" - David Hildenbrand has disabled some known-to-fail selftests ni the series "selftests: mm: cow: flag vmsplice() hugetlb tests as XFAIL". - memcg metadata storage optimizations from Shakeel Butt in "memcg: reduce memory consumption by memcg stats". - DAX fixes and maintenance work from Vishal Verma in the series "dax/bus.c: Fixups for dax-bus locking". -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQTTMBEPP41GrTpTJgfdBJ7gKXxAjgUCZkgQYwAKCRDdBJ7gKXxA jrdKAP9WVJdpEcXxpoub/vVE0UWGtffr8foifi9bCwrQrGh5mgEAx7Yf0+d/oBZB nvA4E0DcPrUAFy144FNM0NTCb7u9vAw= =V3R/ -----END PGP SIGNATURE----- Merge tag 'mm-stable-2024-05-17-19-19' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Pull mm updates from Andrew Morton: "The usual shower of singleton fixes and minor series all over MM, documented (hopefully adequately) in the respective changelogs. Notable series include: - Lucas Stach has provided some page-mapping cleanup/consolidation/ maintainability work in the series "mm/treewide: Remove pXd_huge() API". - In the series "Allow migrate on protnone reference with MPOL_PREFERRED_MANY policy", Donet Tom has optimized mempolicy's MPOL_PREFERRED_MANY mode, yielding almost doubled performance in one test. - In their series "Memory allocation profiling" Kent Overstreet and Suren Baghdasaryan have contributed a means of determining (via /proc/allocinfo) whereabouts in the kernel memory is being allocated: number of calls and amount of memory. - Matthew Wilcox has provided the series "Various significant MM patches" which does a number of rather unrelated things, but in largely similar code sites. - In his series "mm: page_alloc: freelist migratetype hygiene" Johannes Weiner has fixed the page allocator's handling of migratetype requests, with resulting improvements in compaction efficiency. - In the series "make the hugetlb migration strategy consistent" Baolin Wang has fixed a hugetlb migration issue, which should improve hugetlb allocation reliability. - Liu Shixin has hit an I/O meltdown caused by readahead in a memory-tight memcg. Addressed in the series "Fix I/O high when memory almost met memcg limit". - In the series "mm/filemap: optimize folio adding and splitting" Kairui Song has optimized pagecache insertion, yielding ~10% performance improvement in one test. - Baoquan He has cleaned up and consolidated the early zone initialization code in the series "mm/mm_init.c: refactor free_area_init_core()". - Baoquan has also redone some MM initializatio code in the series "mm/init: minor clean up and improvement". - MM helper cleanups from Christoph Hellwig in his series "remove follow_pfn". - More cleanups from Matthew Wilcox in the series "Various page->flags cleanups". - Vlastimil Babka has contributed maintainability improvements in the series "memcg_kmem hooks refactoring". - More folio conversions and cleanups in Matthew Wilcox's series: "Convert huge_zero_page to huge_zero_folio" "khugepaged folio conversions" "Remove page_idle and page_young wrappers" "Use folio APIs in procfs" "Clean up __folio_put()" "Some cleanups for memory-failure" "Remove page_mapping()" "More folio compat code removal" - David Hildenbrand chipped in with "fs/proc/task_mmu: convert hugetlb functions to work on folis". - Code consolidation and cleanup work related to GUP's handling of hugetlbs in Peter Xu's series "mm/gup: Unify hugetlb, part 2". - Rick Edgecombe has developed some fixes to stack guard gaps in the series "Cover a guard gap corner case". - Jinjiang Tu has fixed KSM's behaviour after a fork+exec in the series "mm/ksm: fix ksm exec support for prctl". - Baolin Wang has implemented NUMA balancing for multi-size THPs. This is a simple first-cut implementation for now. The series is "support multi-size THP numa balancing". - Cleanups to vma handling helper functions from Matthew Wilcox in the series "Unify vma_address and vma_pgoff_address". - Some selftests maintenance work from Dev Jain in the series "selftests/mm: mremap_test: Optimizations and style fixes". - Improvements to the swapping of multi-size THPs from Ryan Roberts in the series "Swap-out mTHP without splitting". - Kefeng Wang has significantly optimized the handling of arm64's permission page faults in the series "arch/mm/fault: accelerate pagefault when badaccess" "mm: remove arch's private VM_FAULT_BADMAP/BADACCESS" - GUP cleanups from David Hildenbrand in "mm/gup: consistently call it GUP-fast". - hugetlb fault code cleanups from Vishal Moola in "Hugetlb fault path to use struct vm_fault". - selftests build fixes from John Hubbard in the series "Fix selftests/mm build without requiring "make headers"". - Memory tiering fixes/improvements from Ho-Ren (Jack) Chuang in the series "Improved Memory Tier Creation for CPUless NUMA Nodes". Fixes the initialization code so that migration between different memory types works as intended. - David Hildenbrand has improved follow_pte() and fixed an errant driver in the series "mm: follow_pte() improvements and acrn follow_pte() fixes". - David also did some cleanup work on large folio mapcounts in his series "mm: mapcount for large folios + page_mapcount() cleanups". - Folio conversions in KSM in Alex Shi's series "transfer page to folio in KSM". - Barry Song has added some sysfs stats for monitoring multi-size THP's in the series "mm: add per-order mTHP alloc and swpout counters". - Some zswap cleanups from Yosry Ahmed in the series "zswap same-filled and limit checking cleanups". - Matthew Wilcox has been looking at buffer_head code and found the documentation to be lacking. The series is "Improve buffer head documentation". - Multi-size THPs get more work, this time from Lance Yang. His series "mm/madvise: enhance lazyfreeing with mTHP in madvise_free" optimizes the freeing of these things. - Kemeng Shi has added more userspace-visible writeback instrumentation in the series "Improve visibility of writeback". - Kemeng Shi then sent some maintenance work on top in the series "Fix and cleanups to page-writeback". - Matthew Wilcox reduces mmap_lock traffic in the anon vma code in the series "Improve anon_vma scalability for anon VMAs". Intel's test bot reported an improbable 3x improvement in one test. - SeongJae Park adds some DAMON feature work in the series "mm/damon: add a DAMOS filter type for page granularity access recheck" "selftests/damon: add DAMOS quota goal test" - Also some maintenance work in the series "mm/damon/paddr: simplify page level access re-check for pageout" "mm/damon: misc fixes and improvements" - David Hildenbrand has disabled some known-to-fail selftests ni the series "selftests: mm: cow: flag vmsplice() hugetlb tests as XFAIL". - memcg metadata storage optimizations from Shakeel Butt in "memcg: reduce memory consumption by memcg stats". - DAX fixes and maintenance work from Vishal Verma in the series "dax/bus.c: Fixups for dax-bus locking"" * tag 'mm-stable-2024-05-17-19-19' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (426 commits) memcg, oom: cleanup unused memcg_oom_gfp_mask and memcg_oom_order selftests/mm: hugetlb_madv_vs_map: avoid test skipping by querying hugepage size at runtime mm/hugetlb: add missing VM_FAULT_SET_HINDEX in hugetlb_wp mm/hugetlb: add missing VM_FAULT_SET_HINDEX in hugetlb_fault selftests: cgroup: add tests to verify the zswap writeback path mm: memcg: make alloc_mem_cgroup_per_node_info() return bool mm/damon/core: fix return value from damos_wmark_metric_value mm: do not update memcg stats for NR_{FILE/SHMEM}_PMDMAPPED selftests: cgroup: remove redundant enabling of memory controller Docs/mm/damon/maintainer-profile: allow posting patches based on damon/next tree Docs/mm/damon/maintainer-profile: change the maintainer's timezone from PST to PT Docs/mm/damon/design: use a list for supported filters Docs/admin-guide/mm/damon/usage: fix wrong schemes effective quota update command Docs/admin-guide/mm/damon/usage: fix wrong example of DAMOS filter matching sysfs file selftests/damon: classify tests for functionalities and regressions selftests/damon/_damon_sysfs: use 'is' instead of '==' for 'None' selftests/damon/_damon_sysfs: find sysfs mount point from /proc/mounts selftests/damon/_damon_sysfs: check errors from nr_schemes file reads mm/damon/core: initialize ->esz_bp from damos_quota_init_priv() selftests/damon: add a test for DAMOS quota goal ...
468 lines
10 KiB
C
468 lines
10 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* GUP long-term page pinning tests.
|
|
*
|
|
* Copyright 2023, Red Hat, Inc.
|
|
*
|
|
* Author(s): David Hildenbrand <david@redhat.com>
|
|
*/
|
|
#define _GNU_SOURCE
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <assert.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/ioctl.h>
|
|
#include <sys/vfs.h>
|
|
#include <linux/magic.h>
|
|
#include <linux/memfd.h>
|
|
|
|
#include "local_config.h"
|
|
#ifdef LOCAL_CONFIG_HAVE_LIBURING
|
|
#include <liburing.h>
|
|
#endif /* LOCAL_CONFIG_HAVE_LIBURING */
|
|
|
|
#include "../../../../mm/gup_test.h"
|
|
#include "../kselftest.h"
|
|
#include "vm_util.h"
|
|
|
|
static size_t pagesize;
|
|
static int nr_hugetlbsizes;
|
|
static size_t hugetlbsizes[10];
|
|
static int gup_fd;
|
|
|
|
static __fsword_t get_fs_type(int fd)
|
|
{
|
|
struct statfs fs;
|
|
int ret;
|
|
|
|
do {
|
|
ret = fstatfs(fd, &fs);
|
|
} while (ret && errno == EINTR);
|
|
|
|
return ret ? 0 : fs.f_type;
|
|
}
|
|
|
|
static bool fs_is_unknown(__fsword_t fs_type)
|
|
{
|
|
/*
|
|
* We only support some filesystems in our tests when dealing with
|
|
* R/W long-term pinning. For these filesystems, we can be fairly sure
|
|
* whether they support it or not.
|
|
*/
|
|
switch (fs_type) {
|
|
case TMPFS_MAGIC:
|
|
case HUGETLBFS_MAGIC:
|
|
case BTRFS_SUPER_MAGIC:
|
|
case EXT4_SUPER_MAGIC:
|
|
case XFS_SUPER_MAGIC:
|
|
return false;
|
|
default:
|
|
return true;
|
|
}
|
|
}
|
|
|
|
static bool fs_supports_writable_longterm_pinning(__fsword_t fs_type)
|
|
{
|
|
assert(!fs_is_unknown(fs_type));
|
|
switch (fs_type) {
|
|
case TMPFS_MAGIC:
|
|
case HUGETLBFS_MAGIC:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
enum test_type {
|
|
TEST_TYPE_RO,
|
|
TEST_TYPE_RO_FAST,
|
|
TEST_TYPE_RW,
|
|
TEST_TYPE_RW_FAST,
|
|
#ifdef LOCAL_CONFIG_HAVE_LIBURING
|
|
TEST_TYPE_IOURING,
|
|
#endif /* LOCAL_CONFIG_HAVE_LIBURING */
|
|
};
|
|
|
|
static void do_test(int fd, size_t size, enum test_type type, bool shared)
|
|
{
|
|
__fsword_t fs_type = get_fs_type(fd);
|
|
bool should_work;
|
|
char *mem;
|
|
int ret;
|
|
|
|
if (ftruncate(fd, size)) {
|
|
ksft_test_result_fail("ftruncate() failed\n");
|
|
return;
|
|
}
|
|
|
|
if (fallocate(fd, 0, 0, size)) {
|
|
if (size == pagesize)
|
|
ksft_test_result_fail("fallocate() failed\n");
|
|
else
|
|
ksft_test_result_skip("need more free huge pages\n");
|
|
return;
|
|
}
|
|
|
|
mem = mmap(NULL, size, PROT_READ | PROT_WRITE,
|
|
shared ? MAP_SHARED : MAP_PRIVATE, fd, 0);
|
|
if (mem == MAP_FAILED) {
|
|
if (size == pagesize || shared)
|
|
ksft_test_result_fail("mmap() failed\n");
|
|
else
|
|
ksft_test_result_skip("need more free huge pages\n");
|
|
return;
|
|
}
|
|
|
|
/* Fault in the page such that GUP-fast can pin it directly. */
|
|
memset(mem, 0, size);
|
|
|
|
switch (type) {
|
|
case TEST_TYPE_RO:
|
|
case TEST_TYPE_RO_FAST:
|
|
/*
|
|
* Cover more cases regarding unsharing decisions when
|
|
* long-term R/O pinning by mapping the page R/O.
|
|
*/
|
|
ret = mprotect(mem, size, PROT_READ);
|
|
if (ret) {
|
|
ksft_test_result_fail("mprotect() failed\n");
|
|
goto munmap;
|
|
}
|
|
/* FALLTHROUGH */
|
|
case TEST_TYPE_RW:
|
|
case TEST_TYPE_RW_FAST: {
|
|
struct pin_longterm_test args;
|
|
const bool fast = type == TEST_TYPE_RO_FAST ||
|
|
type == TEST_TYPE_RW_FAST;
|
|
const bool rw = type == TEST_TYPE_RW ||
|
|
type == TEST_TYPE_RW_FAST;
|
|
|
|
if (gup_fd < 0) {
|
|
ksft_test_result_skip("gup_test not available\n");
|
|
break;
|
|
}
|
|
|
|
if (rw && shared && fs_is_unknown(fs_type)) {
|
|
ksft_test_result_skip("Unknown filesystem\n");
|
|
return;
|
|
}
|
|
/*
|
|
* R/O pinning or pinning in a private mapping is always
|
|
* expected to work. Otherwise, we expect long-term R/W pinning
|
|
* to only succeed for special fielesystems.
|
|
*/
|
|
should_work = !shared || !rw ||
|
|
fs_supports_writable_longterm_pinning(fs_type);
|
|
|
|
args.addr = (__u64)(uintptr_t)mem;
|
|
args.size = size;
|
|
args.flags = fast ? PIN_LONGTERM_TEST_FLAG_USE_FAST : 0;
|
|
args.flags |= rw ? PIN_LONGTERM_TEST_FLAG_USE_WRITE : 0;
|
|
ret = ioctl(gup_fd, PIN_LONGTERM_TEST_START, &args);
|
|
if (ret && errno == EINVAL) {
|
|
ksft_test_result_skip("PIN_LONGTERM_TEST_START failed\n");
|
|
break;
|
|
} else if (ret && errno == EFAULT) {
|
|
ksft_test_result(!should_work, "Should have failed\n");
|
|
break;
|
|
} else if (ret) {
|
|
ksft_test_result_fail("PIN_LONGTERM_TEST_START failed\n");
|
|
break;
|
|
}
|
|
|
|
if (ioctl(gup_fd, PIN_LONGTERM_TEST_STOP))
|
|
ksft_print_msg("[INFO] PIN_LONGTERM_TEST_STOP failed\n");
|
|
|
|
/*
|
|
* TODO: if the kernel ever supports long-term R/W pinning on
|
|
* some previously unsupported filesystems, we might want to
|
|
* perform some additional tests for possible data corruptions.
|
|
*/
|
|
ksft_test_result(should_work, "Should have worked\n");
|
|
break;
|
|
}
|
|
#ifdef LOCAL_CONFIG_HAVE_LIBURING
|
|
case TEST_TYPE_IOURING: {
|
|
struct io_uring ring;
|
|
struct iovec iov;
|
|
|
|
/* io_uring always pins pages writable. */
|
|
if (shared && fs_is_unknown(fs_type)) {
|
|
ksft_test_result_skip("Unknown filesystem\n");
|
|
return;
|
|
}
|
|
should_work = !shared ||
|
|
fs_supports_writable_longterm_pinning(fs_type);
|
|
|
|
/* Skip on errors, as we might just lack kernel support. */
|
|
ret = io_uring_queue_init(1, &ring, 0);
|
|
if (ret < 0) {
|
|
ksft_test_result_skip("io_uring_queue_init() failed\n");
|
|
break;
|
|
}
|
|
/*
|
|
* Register the range as a fixed buffer. This will FOLL_WRITE |
|
|
* FOLL_PIN | FOLL_LONGTERM the range.
|
|
*/
|
|
iov.iov_base = mem;
|
|
iov.iov_len = size;
|
|
ret = io_uring_register_buffers(&ring, &iov, 1);
|
|
/* Only new kernels return EFAULT. */
|
|
if (ret && (errno == ENOSPC || errno == EOPNOTSUPP ||
|
|
errno == EFAULT)) {
|
|
ksft_test_result(!should_work, "Should have failed\n");
|
|
} else if (ret) {
|
|
/*
|
|
* We might just lack support or have insufficient
|
|
* MEMLOCK limits.
|
|
*/
|
|
ksft_test_result_skip("io_uring_register_buffers() failed\n");
|
|
} else {
|
|
ksft_test_result(should_work, "Should have worked\n");
|
|
io_uring_unregister_buffers(&ring);
|
|
}
|
|
|
|
io_uring_queue_exit(&ring);
|
|
break;
|
|
}
|
|
#endif /* LOCAL_CONFIG_HAVE_LIBURING */
|
|
default:
|
|
assert(false);
|
|
}
|
|
|
|
munmap:
|
|
munmap(mem, size);
|
|
}
|
|
|
|
typedef void (*test_fn)(int fd, size_t size);
|
|
|
|
static void run_with_memfd(test_fn fn, const char *desc)
|
|
{
|
|
int fd;
|
|
|
|
ksft_print_msg("[RUN] %s ... with memfd\n", desc);
|
|
|
|
fd = memfd_create("test", 0);
|
|
if (fd < 0) {
|
|
ksft_test_result_fail("memfd_create() failed\n");
|
|
return;
|
|
}
|
|
|
|
fn(fd, pagesize);
|
|
close(fd);
|
|
}
|
|
|
|
static void run_with_tmpfile(test_fn fn, const char *desc)
|
|
{
|
|
FILE *file;
|
|
int fd;
|
|
|
|
ksft_print_msg("[RUN] %s ... with tmpfile\n", desc);
|
|
|
|
file = tmpfile();
|
|
if (!file) {
|
|
ksft_test_result_fail("tmpfile() failed\n");
|
|
return;
|
|
}
|
|
|
|
fd = fileno(file);
|
|
if (fd < 0) {
|
|
ksft_test_result_fail("fileno() failed\n");
|
|
goto close;
|
|
}
|
|
|
|
fn(fd, pagesize);
|
|
close:
|
|
fclose(file);
|
|
}
|
|
|
|
static void run_with_local_tmpfile(test_fn fn, const char *desc)
|
|
{
|
|
char filename[] = __FILE__"_tmpfile_XXXXXX";
|
|
int fd;
|
|
|
|
ksft_print_msg("[RUN] %s ... with local tmpfile\n", desc);
|
|
|
|
fd = mkstemp(filename);
|
|
if (fd < 0) {
|
|
ksft_test_result_fail("mkstemp() failed\n");
|
|
return;
|
|
}
|
|
|
|
if (unlink(filename)) {
|
|
ksft_test_result_fail("unlink() failed\n");
|
|
goto close;
|
|
}
|
|
|
|
fn(fd, pagesize);
|
|
close:
|
|
close(fd);
|
|
}
|
|
|
|
static void run_with_memfd_hugetlb(test_fn fn, const char *desc,
|
|
size_t hugetlbsize)
|
|
{
|
|
int flags = MFD_HUGETLB;
|
|
int fd;
|
|
|
|
ksft_print_msg("[RUN] %s ... with memfd hugetlb (%zu kB)\n", desc,
|
|
hugetlbsize / 1024);
|
|
|
|
flags |= __builtin_ctzll(hugetlbsize) << MFD_HUGE_SHIFT;
|
|
|
|
fd = memfd_create("test", flags);
|
|
if (fd < 0) {
|
|
ksft_test_result_skip("memfd_create() failed\n");
|
|
return;
|
|
}
|
|
|
|
fn(fd, hugetlbsize);
|
|
close(fd);
|
|
}
|
|
|
|
struct test_case {
|
|
const char *desc;
|
|
test_fn fn;
|
|
};
|
|
|
|
static void test_shared_rw_pin(int fd, size_t size)
|
|
{
|
|
do_test(fd, size, TEST_TYPE_RW, true);
|
|
}
|
|
|
|
static void test_shared_rw_fast_pin(int fd, size_t size)
|
|
{
|
|
do_test(fd, size, TEST_TYPE_RW_FAST, true);
|
|
}
|
|
|
|
static void test_shared_ro_pin(int fd, size_t size)
|
|
{
|
|
do_test(fd, size, TEST_TYPE_RO, true);
|
|
}
|
|
|
|
static void test_shared_ro_fast_pin(int fd, size_t size)
|
|
{
|
|
do_test(fd, size, TEST_TYPE_RO_FAST, true);
|
|
}
|
|
|
|
static void test_private_rw_pin(int fd, size_t size)
|
|
{
|
|
do_test(fd, size, TEST_TYPE_RW, false);
|
|
}
|
|
|
|
static void test_private_rw_fast_pin(int fd, size_t size)
|
|
{
|
|
do_test(fd, size, TEST_TYPE_RW_FAST, false);
|
|
}
|
|
|
|
static void test_private_ro_pin(int fd, size_t size)
|
|
{
|
|
do_test(fd, size, TEST_TYPE_RO, false);
|
|
}
|
|
|
|
static void test_private_ro_fast_pin(int fd, size_t size)
|
|
{
|
|
do_test(fd, size, TEST_TYPE_RO_FAST, false);
|
|
}
|
|
|
|
#ifdef LOCAL_CONFIG_HAVE_LIBURING
|
|
static void test_shared_iouring(int fd, size_t size)
|
|
{
|
|
do_test(fd, size, TEST_TYPE_IOURING, true);
|
|
}
|
|
|
|
static void test_private_iouring(int fd, size_t size)
|
|
{
|
|
do_test(fd, size, TEST_TYPE_IOURING, false);
|
|
}
|
|
#endif /* LOCAL_CONFIG_HAVE_LIBURING */
|
|
|
|
static const struct test_case test_cases[] = {
|
|
{
|
|
"R/W longterm GUP pin in MAP_SHARED file mapping",
|
|
test_shared_rw_pin,
|
|
},
|
|
{
|
|
"R/W longterm GUP-fast pin in MAP_SHARED file mapping",
|
|
test_shared_rw_fast_pin,
|
|
},
|
|
{
|
|
"R/O longterm GUP pin in MAP_SHARED file mapping",
|
|
test_shared_ro_pin,
|
|
},
|
|
{
|
|
"R/O longterm GUP-fast pin in MAP_SHARED file mapping",
|
|
test_shared_ro_fast_pin,
|
|
},
|
|
{
|
|
"R/W longterm GUP pin in MAP_PRIVATE file mapping",
|
|
test_private_rw_pin,
|
|
},
|
|
{
|
|
"R/W longterm GUP-fast pin in MAP_PRIVATE file mapping",
|
|
test_private_rw_fast_pin,
|
|
},
|
|
{
|
|
"R/O longterm GUP pin in MAP_PRIVATE file mapping",
|
|
test_private_ro_pin,
|
|
},
|
|
{
|
|
"R/O longterm GUP-fast pin in MAP_PRIVATE file mapping",
|
|
test_private_ro_fast_pin,
|
|
},
|
|
#ifdef LOCAL_CONFIG_HAVE_LIBURING
|
|
{
|
|
"io_uring fixed buffer with MAP_SHARED file mapping",
|
|
test_shared_iouring,
|
|
},
|
|
{
|
|
"io_uring fixed buffer with MAP_PRIVATE file mapping",
|
|
test_private_iouring,
|
|
},
|
|
#endif /* LOCAL_CONFIG_HAVE_LIBURING */
|
|
};
|
|
|
|
static void run_test_case(struct test_case const *test_case)
|
|
{
|
|
int i;
|
|
|
|
run_with_memfd(test_case->fn, test_case->desc);
|
|
run_with_tmpfile(test_case->fn, test_case->desc);
|
|
run_with_local_tmpfile(test_case->fn, test_case->desc);
|
|
for (i = 0; i < nr_hugetlbsizes; i++)
|
|
run_with_memfd_hugetlb(test_case->fn, test_case->desc,
|
|
hugetlbsizes[i]);
|
|
}
|
|
|
|
static int tests_per_test_case(void)
|
|
{
|
|
return 3 + nr_hugetlbsizes;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int i, err;
|
|
|
|
pagesize = getpagesize();
|
|
nr_hugetlbsizes = detect_hugetlb_page_sizes(hugetlbsizes,
|
|
ARRAY_SIZE(hugetlbsizes));
|
|
|
|
ksft_print_header();
|
|
ksft_set_plan(ARRAY_SIZE(test_cases) * tests_per_test_case());
|
|
|
|
gup_fd = open("/sys/kernel/debug/gup_test", O_RDWR);
|
|
|
|
for (i = 0; i < ARRAY_SIZE(test_cases); i++)
|
|
run_test_case(&test_cases[i]);
|
|
|
|
err = ksft_get_fail_cnt();
|
|
if (err)
|
|
ksft_exit_fail_msg("%d out of %d tests failed\n",
|
|
err, ksft_test_num());
|
|
ksft_exit_pass();
|
|
}
|