Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/mm: move certain uffd*() routines from vm_util.c to uffd-common.c

There are only three uffd*() routines that are used outside of the uffd
selftests. Leave these in vm_util.c, where they are available to any mm
selftest program:

uffd_register()
uffd_unregister()
uffd_register_with_ioctls().

A few other uffd*() routines, however, are only used by the uffd-focused
tests found in uffd-stress.c and uffd-unit-tests.c. Move those routines
into uffd-common.c.

Link: https://lkml.kernel.org/r/20230606071637.267103-10-jhubbard@nvidia.com
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Acked-by: David Hildenbrand <david@redhat.com>
Tested-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

John Hubbard and committed by
Andrew Morton
56d2afff 3972ea24

+64 -63
+59
tools/testing/selftests/mm/uffd-common.c
··· 616 616 { 617 617 return __copy_page(ufd, offset, false, wp); 618 618 } 619 + 620 + int uffd_open_dev(unsigned int flags) 621 + { 622 + int fd, uffd; 623 + 624 + fd = open("/dev/userfaultfd", O_RDWR | O_CLOEXEC); 625 + if (fd < 0) 626 + return fd; 627 + uffd = ioctl(fd, USERFAULTFD_IOC_NEW, flags); 628 + close(fd); 629 + 630 + return uffd; 631 + } 632 + 633 + int uffd_open_sys(unsigned int flags) 634 + { 635 + #ifdef __NR_userfaultfd 636 + return syscall(__NR_userfaultfd, flags); 637 + #else 638 + return -1; 639 + #endif 640 + } 641 + 642 + int uffd_open(unsigned int flags) 643 + { 644 + int uffd = uffd_open_sys(flags); 645 + 646 + if (uffd < 0) 647 + uffd = uffd_open_dev(flags); 648 + 649 + return uffd; 650 + } 651 + 652 + int uffd_get_features(uint64_t *features) 653 + { 654 + struct uffdio_api uffdio_api = { .api = UFFD_API, .features = 0 }; 655 + /* 656 + * This should by default work in most kernels; the feature list 657 + * will be the same no matter what we pass in here. 658 + */ 659 + int fd = uffd_open(UFFD_USER_MODE_ONLY); 660 + 661 + if (fd < 0) 662 + /* Maybe the kernel is older than user-only mode? */ 663 + fd = uffd_open(0); 664 + 665 + if (fd < 0) 666 + return fd; 667 + 668 + if (ioctl(fd, UFFDIO_API, &uffdio_api)) { 669 + close(fd); 670 + return -errno; 671 + } 672 + 673 + *features = uffdio_api.features; 674 + close(fd); 675 + 676 + return 0; 677 + }
+5
tools/testing/selftests/mm/uffd-common.h
··· 110 110 int copy_page(int ufd, unsigned long offset, bool wp); 111 111 void *uffd_poll_thread(void *arg); 112 112 113 + int uffd_open_dev(unsigned int flags); 114 + int uffd_open_sys(unsigned int flags); 115 + int uffd_open(unsigned int flags); 116 + int uffd_get_features(uint64_t *features); 117 + 113 118 #define TEST_ANON 1 114 119 #define TEST_HUGETLB 2 115 120 #define TEST_SHMEM 3
-59
tools/testing/selftests/mm/vm_util.c
··· 269 269 270 270 return ret; 271 271 } 272 - 273 - int uffd_open_dev(unsigned int flags) 274 - { 275 - int fd, uffd; 276 - 277 - fd = open("/dev/userfaultfd", O_RDWR | O_CLOEXEC); 278 - if (fd < 0) 279 - return fd; 280 - uffd = ioctl(fd, USERFAULTFD_IOC_NEW, flags); 281 - close(fd); 282 - 283 - return uffd; 284 - } 285 - 286 - int uffd_open_sys(unsigned int flags) 287 - { 288 - #ifdef __NR_userfaultfd 289 - return syscall(__NR_userfaultfd, flags); 290 - #else 291 - return -1; 292 - #endif 293 - } 294 - 295 - int uffd_open(unsigned int flags) 296 - { 297 - int uffd = uffd_open_sys(flags); 298 - 299 - if (uffd < 0) 300 - uffd = uffd_open_dev(flags); 301 - 302 - return uffd; 303 - } 304 - 305 - int uffd_get_features(uint64_t *features) 306 - { 307 - struct uffdio_api uffdio_api = { .api = UFFD_API, .features = 0 }; 308 - /* 309 - * This should by default work in most kernels; the feature list 310 - * will be the same no matter what we pass in here. 311 - */ 312 - int fd = uffd_open(UFFD_USER_MODE_ONLY); 313 - 314 - if (fd < 0) 315 - /* Maybe the kernel is older than user-only mode? */ 316 - fd = uffd_open(0); 317 - 318 - if (fd < 0) 319 - return fd; 320 - 321 - if (ioctl(fd, UFFDIO_API, &uffdio_api)) { 322 - close(fd); 323 - return -errno; 324 - } 325 - 326 - *features = uffdio_api.features; 327 - close(fd); 328 - 329 - return 0; 330 - }
-4
tools/testing/selftests/mm/vm_util.h
··· 49 49 int uffd_register(int uffd, void *addr, uint64_t len, 50 50 bool miss, bool wp, bool minor); 51 51 int uffd_unregister(int uffd, void *addr, uint64_t len); 52 - int uffd_open_dev(unsigned int flags); 53 - int uffd_open_sys(unsigned int flags); 54 - int uffd_open(unsigned int flags); 55 - int uffd_get_features(uint64_t *features); 56 52 int uffd_register_with_ioctls(int uffd, void *addr, uint64_t len, 57 53 bool miss, bool wp, bool minor, uint64_t *ioctls); 58 54