mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-06 02:50:49 +09:00
BACKPORT: selftests/mm: call uffd_test_ctx_clear at the end of the test
uffd_test_ctx_clear() is being called from uffd_test_ctx_init() to unmap areas used in the previous test run. This approach is problematic because while unmapping areas uffd_test_ctx_clear() uses page_size and nr_pages which might differ from one test run to another. Fix this by calling uffd_test_ctx_clear() after each test is done. Link: https://lkml.kernel.org/r/20231206103702.3873743-4-surenb@google.com Signed-off-by: Suren Baghdasaryan <surenb@google.com> Reviewed-by: Peter Xu <peterx@redhat.com> Reviewed-by: Axel Rasmussen <axelrasmussen@google.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Brian Geffon <bgeffon@google.com> Cc: Christian Brauner <brauner@kernel.org> Cc: David Hildenbrand <david@redhat.com> Cc: Hugh Dickins <hughd@google.com> Cc: Jann Horn <jannh@google.com> Cc: Kalesh Singh <kaleshsingh@google.com> Cc: Liam R. Howlett <Liam.Howlett@oracle.com> Cc: Lokesh Gidra <lokeshgidra@google.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Mike Rapoport (IBM) <rppt@kernel.org> Cc: Nicolas Geoffray <ngeoffray@google.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Shuah Khan <shuah@kernel.org> Cc: ZhangPeng <zhangpeng362@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 1c8d39fa7b63dcbb77af7b0325fdc519c35fe618) Conflicts: tools/testing/selftests/mm/uffd-common.c tools/testing/selftests/mm/uffd-common.h tools/testing/selftests/mm/uffd-stress.c tools/testing/selftests/mm/uffd-unit-tests.c tools/testing/selftests/vm/userfaultfd.c 1. Userfaultfd selftest was split into separate files and as a consequence the code moved from selftests/vm/userfaultfd.c to selftests/mm/uffd_* files. Bug: 274911254 Change-Id: Ic224c3965a645342dc0f41e743d3c072b7bb852e Signed-off-by: Lokesh Gidra <lokeshgidra@google.com>
This commit is contained in:
committed by
Lokesh Gidra
parent
abd6748ba6
commit
ee72d5a7d9
@@ -517,8 +517,6 @@ static void uffd_test_ctx_init(uint64_t features)
|
|||||||
{
|
{
|
||||||
unsigned long nr, cpu;
|
unsigned long nr, cpu;
|
||||||
|
|
||||||
uffd_test_ctx_clear();
|
|
||||||
|
|
||||||
uffd_test_ops->allocate_area((void **)&area_src, true);
|
uffd_test_ops->allocate_area((void **)&area_src, true);
|
||||||
uffd_test_ops->allocate_area((void **)&area_dst, false);
|
uffd_test_ops->allocate_area((void **)&area_dst, false);
|
||||||
|
|
||||||
@@ -1195,6 +1193,7 @@ static int userfaultfd_zeropage_test(void)
|
|||||||
if (my_bcmp(area_dst, zeropage, page_size))
|
if (my_bcmp(area_dst, zeropage, page_size))
|
||||||
err("zeropage is not zero");
|
err("zeropage is not zero");
|
||||||
|
|
||||||
|
uffd_test_ctx_clear();
|
||||||
printf("done.\n");
|
printf("done.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1207,6 +1206,7 @@ static int userfaultfd_events_test(void)
|
|||||||
pid_t pid;
|
pid_t pid;
|
||||||
char c;
|
char c;
|
||||||
struct uffd_stats stats = { 0 };
|
struct uffd_stats stats = { 0 };
|
||||||
|
int ret;
|
||||||
|
|
||||||
printf("testing events (fork, remap, remove): ");
|
printf("testing events (fork, remap, remove): ");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@@ -1243,12 +1243,16 @@ static int userfaultfd_events_test(void)
|
|||||||
err("faulting process failed");
|
err("faulting process failed");
|
||||||
if (write(pipefd[1], &c, sizeof(c)) != sizeof(c))
|
if (write(pipefd[1], &c, sizeof(c)) != sizeof(c))
|
||||||
err("pipe write");
|
err("pipe write");
|
||||||
|
ret = 1;
|
||||||
if (pthread_join(uffd_mon, NULL))
|
if (pthread_join(uffd_mon, NULL))
|
||||||
return 1;
|
goto out;
|
||||||
|
|
||||||
uffd_stats_report(&stats, 1);
|
uffd_stats_report(&stats, 1);
|
||||||
|
|
||||||
return stats.missing_faults != nr_pages;
|
ret = stats.missing_faults != nr_pages;
|
||||||
|
out:
|
||||||
|
uffd_test_ctx_clear();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int userfaultfd_sig_test(void)
|
static int userfaultfd_sig_test(void)
|
||||||
@@ -1260,6 +1264,7 @@ static int userfaultfd_sig_test(void)
|
|||||||
pid_t pid;
|
pid_t pid;
|
||||||
char c;
|
char c;
|
||||||
struct uffd_stats stats = { 0 };
|
struct uffd_stats stats = { 0 };
|
||||||
|
int ret;
|
||||||
|
|
||||||
printf("testing signal delivery: ");
|
printf("testing signal delivery: ");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@@ -1300,14 +1305,18 @@ static int userfaultfd_sig_test(void)
|
|||||||
err("faulting process failed");
|
err("faulting process failed");
|
||||||
if (write(pipefd[1], &c, sizeof(c)) != sizeof(c))
|
if (write(pipefd[1], &c, sizeof(c)) != sizeof(c))
|
||||||
err("pipe write");
|
err("pipe write");
|
||||||
|
ret = 1;
|
||||||
if (pthread_join(uffd_mon, (void **)&userfaults))
|
if (pthread_join(uffd_mon, (void **)&userfaults))
|
||||||
return 1;
|
goto out;
|
||||||
|
|
||||||
printf("done.\n");
|
printf("done.\n");
|
||||||
if (userfaults)
|
if (userfaults)
|
||||||
err("Signal test failed, userfaults: %ld", userfaults);
|
err("Signal test failed, userfaults: %ld", userfaults);
|
||||||
|
|
||||||
return userfaults != 0;
|
ret = userfaults != 0;
|
||||||
|
out:
|
||||||
|
uffd_test_ctx_clear();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_memory_contents(char *p)
|
void check_memory_contents(char *p)
|
||||||
@@ -1336,6 +1345,7 @@ static int userfaultfd_minor_test(void)
|
|||||||
pthread_t uffd_mon;
|
pthread_t uffd_mon;
|
||||||
char c;
|
char c;
|
||||||
struct uffd_stats stats = { 0 };
|
struct uffd_stats stats = { 0 };
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (!test_uffdio_minor)
|
if (!test_uffdio_minor)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1376,8 +1386,9 @@ static int userfaultfd_minor_test(void)
|
|||||||
|
|
||||||
if (write(pipefd[1], &c, sizeof(c)) != sizeof(c))
|
if (write(pipefd[1], &c, sizeof(c)) != sizeof(c))
|
||||||
err("pipe write");
|
err("pipe write");
|
||||||
|
ret = 1;
|
||||||
if (pthread_join(uffd_mon, NULL))
|
if (pthread_join(uffd_mon, NULL))
|
||||||
return 1;
|
goto out;
|
||||||
|
|
||||||
uffd_stats_report(&stats, 1);
|
uffd_stats_report(&stats, 1);
|
||||||
|
|
||||||
@@ -1398,7 +1409,10 @@ static int userfaultfd_minor_test(void)
|
|||||||
printf(" done.\n");
|
printf(" done.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return stats.missing_faults != 0 || stats.minor_faults != nr_pages;
|
ret = stats.missing_faults != 0 || stats.minor_faults != nr_pages;
|
||||||
|
out:
|
||||||
|
uffd_test_ctx_clear();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BIT_ULL(nr) (1ULL << (nr))
|
#define BIT_ULL(nr) (1ULL << (nr))
|
||||||
@@ -1532,6 +1546,7 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize)
|
|||||||
pagemap_check_wp(value, false);
|
pagemap_check_wp(value, false);
|
||||||
|
|
||||||
close(pagemap_fd);
|
close(pagemap_fd);
|
||||||
|
uffd_test_ctx_clear();
|
||||||
printf("done\n");
|
printf("done\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1621,8 +1636,10 @@ static int userfaultfd_stress(void)
|
|||||||
uffd_stats_reset(uffd_stats, nr_cpus);
|
uffd_stats_reset(uffd_stats, nr_cpus);
|
||||||
|
|
||||||
/* bounce pass */
|
/* bounce pass */
|
||||||
if (stress(uffd_stats))
|
if (stress(uffd_stats)) {
|
||||||
|
uffd_test_ctx_clear();
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Clear all the write protections if there is any */
|
/* Clear all the write protections if there is any */
|
||||||
if (test_uffdio_wp)
|
if (test_uffdio_wp)
|
||||||
@@ -1654,6 +1671,7 @@ static int userfaultfd_stress(void)
|
|||||||
|
|
||||||
uffd_stats_report(uffd_stats, nr_cpus);
|
uffd_stats_report(uffd_stats, nr_cpus);
|
||||||
}
|
}
|
||||||
|
uffd_test_ctx_clear();
|
||||||
|
|
||||||
if (test_type == TEST_ANON) {
|
if (test_type == TEST_ANON) {
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user