Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8cbececc authored by Axel Rasmussen's avatar Axel Rasmussen Committed by Michael Bestas
Browse files

FROMGIT: userfaultfd/selftests: exercise minor fault handling shmem support

Enable test_uffdio_minor for test_type == TEST_SHMEM, and modify the test
slightly to pass in / check for the right feature flags.

Link: https://lkml.kernel.org/r/20210503180737.2487560-11-axelrasmussen@google.com


Signed-off-by: default avatarAxel Rasmussen <axelrasmussen@google.com>
Reviewed-by: default avatarPeter Xu <peterx@redhat.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Brian Geffon <bgeffon@google.com>
Cc: "Dr . David Alan Gilbert" <dgilbert@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: Joe Perches <joe@perches.com>
Cc: Kirill A. Shutemov <kirill@shutemov.name>
Cc: Lokesh Gidra <lokeshgidra@google.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
Cc: Mina Almasry <almasrymina@google.com>
Cc: Oliver Upton <oupton@google.com>
Cc: Shaohua Li <shli@fb.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Wang Qing <wangqing@vivo.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
(cherry picked from commit b0287e43fb420ab3c5631b146d99b2a1fc9a14d7
https: //git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
akpm)
Link: https://lore.kernel.org/patchwork/patch/1420977/


Signed-off-by: default avatarLokesh Gidra <lokeshgidra@google.com>
Bug: 187930641
Change-Id: Ic6a6aa2ea92bc6353f60d8f982c2aef78e4ce323
parent 958319fe
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -443,6 +443,7 @@ static int my_bcmp(char *str1, char *str2, size_t n)
static void continue_range(int ufd, __u64 start, __u64 len)
{
	struct uffdio_continue req;
	int ret;

	req.range.start = start;
	req.range.len = len;
@@ -451,6 +452,17 @@ static void continue_range(int ufd, __u64 start, __u64 len)
	if (ioctl(ufd, UFFDIO_CONTINUE, &req))
		err("UFFDIO_CONTINUE failed for address 0x%" PRIx64,
		    (uint64_t)start);

	/*
	 * Error handling within the kernel for continue is subtly different
	 * from copy or zeropage, so it may be a source of bugs. Trigger an
	 * error (-EEXIST) on purpose, to verify doing so doesn't cause a BUG.
	 */
	req.mapped = 0;
	ret = ioctl(ufd, UFFDIO_CONTINUE, &req);
	if (ret >= 0 || req.mapped != -EEXIST)
		err("failed to exercise UFFDIO_CONTINUE error handling, ret=%d, mapped=%" PRId64,
		    ret, (int64_t) req.mapped);
}

static void *locking_thread(void *arg)
@@ -1095,7 +1107,7 @@ static int userfaultfd_minor_test(void)
	void *expected_page;
	char c;
	struct uffd_stats stats = { 0 };
	uint64_t features = UFFD_FEATURE_MINOR_HUGETLBFS;
	uint64_t req_features, features_out;

	if (!test_uffdio_minor)
		return 0;
@@ -1103,9 +1115,17 @@ static int userfaultfd_minor_test(void)
	printf("testing minor faults: ");
	fflush(stdout);

	uffd_test_ctx_init_ext(&features);
	/* If kernel reports the feature isn't supported, skip the test. */
	if (!(features & UFFD_FEATURE_MINOR_HUGETLBFS)) {
	if (test_type == TEST_HUGETLB)
		req_features = UFFD_FEATURE_MINOR_HUGETLBFS;
	else if (test_type == TEST_SHMEM)
		req_features = UFFD_FEATURE_MINOR_SHMEM;
	else
		return 1;

	features_out = req_features;
	uffd_test_ctx_init_ext(&features_out);
	/* If kernel reports required features aren't supported, skip test. */
	if ((features_out & req_features) != req_features) {
		printf("skipping test due to lack of feature support\n");
		fflush(stdout);
		return 0;
@@ -1328,6 +1348,7 @@ static void set_test_type(const char *type)
		map_shared = true;
		test_type = TEST_SHMEM;
		uffd_test_ops = &shmem_uffd_test_ops;
		test_uffdio_minor = true;
	} else {
		err("Unknown test type: %s", type);
	}