Skip to content

Commit

Permalink
selftests/mm: reuse read_pmd_pagesize() in COW selftest
Browse files Browse the repository at this point in the history
Patch series "mm: (pte|pmd)_mkdirty() should not unconditionally allow for
write access".

This is the follow-up on [1], adding selftests (testing for known issues
we added workarounds for and other issues that haven't been fixed yet),
fixing sparc64, reverting the workarounds, and perform one cleanup.

The patch from [1] was modified slightly (updated/extended patch
description, dropped one unnecessary NOP instruction from the ASM in
__pte_mkhwwrite()).

Retested on x86_64 and sparc64 (sun4u in QEMU).

I scanned most architectures to make sure their (pte|pmd)_mkdirty()
handling is correct.  To be sure, we can run the selftests and find out if
other architectures are still affectes (loongarch was fixed recently as
well).

Based on master for now. I don't expect surprises regarding mm-tress, but
I can rebase if there are any problems.


This patch (of 6):

The COW selftest can deal with THP not being configured.  So move error
handling of read_pmd_pagesize() into the callers such that we can reuse it
in the COW selftest.

Link: https://lkml.kernel.org/r/20230411142512.438404-1-david@redhat.com
Link: https://lkml.kernel.org/r/20221212130213.136267-1-david@redhat.com [1]
Link: https://lkml.kernel.org/r/20230411142512.438404-2-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Hugh Dickins <hughd@google.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Yu Zhao <yuzhao@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
David Hildenbrand authored and Andrew Morton committed Apr 18, 2023
1 parent 1e9460d commit d6e61af
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 31 deletions.
33 changes: 4 additions & 29 deletions tools/testing/selftests/mm/cow.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,6 @@ static size_t hugetlbsizes[10];
static int gup_fd;
static bool has_huge_zeropage;

static void detect_thpsize(void)
{
int fd = open("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size",
O_RDONLY);
size_t size = 0;
char buf[15];
int ret;

if (fd < 0)
return;

ret = pread(fd, buf, sizeof(buf), 0);
if (ret > 0 && ret < sizeof(buf)) {
buf[ret] = 0;

size = strtoul(buf, NULL, 10);
if (size < pagesize)
size = 0;
if (size > 0) {
thpsize = size;
ksft_print_msg("[INFO] detected THP size: %zu KiB\n",
thpsize / 1024);
}
}

close(fd);
}

static void detect_huge_zeropage(void)
{
int fd = open("/sys/kernel/mm/transparent_hugepage/use_zero_page",
Expand Down Expand Up @@ -1741,7 +1713,10 @@ int main(int argc, char **argv)
int err;

pagesize = getpagesize();
detect_thpsize();
thpsize = read_pmd_pagesize();
if (thpsize)
ksft_print_msg("[INFO] detected THP size: %zu KiB\n",
thpsize / 1024);
detect_hugetlbsizes();
detect_huge_zeropage();

Expand Down
4 changes: 4 additions & 0 deletions tools/testing/selftests/mm/khugepaged.c
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,10 @@ int main(int argc, const char **argv)

page_size = getpagesize();
hpage_pmd_size = read_pmd_pagesize();
if (!hpage_pmd_size) {
printf("Reading PMD pagesize failed");
exit(EXIT_FAILURE);
}
hpage_pmd_nr = hpage_pmd_size / page_size;

default_settings.khugepaged.max_ptes_none = hpage_pmd_nr - 1;
Expand Down
3 changes: 3 additions & 0 deletions tools/testing/selftests/mm/soft-dirty.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ static void test_hugepage(int pagemap_fd, int pagesize)
int i, ret;
size_t hpage_len = read_pmd_pagesize();

if (!hpage_len)
ksft_exit_fail_msg("Reading PMD pagesize failed");

map = memalign(hpage_len, hpage_len);
if (!map)
ksft_exit_fail_msg("memalign failed\n");
Expand Down
4 changes: 4 additions & 0 deletions tools/testing/selftests/mm/split_huge_page_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ int main(int argc, char **argv)
pagesize = getpagesize();
pageshift = ffs(pagesize) - 1;
pmd_pagesize = read_pmd_pagesize();
if (!pmd_pagesize) {
printf("Reading PMD pagesize failed\n");
exit(EXIT_FAILURE);
}

split_pmd_thp();
split_pte_mapped_thp();
Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/mm/vm_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ uint64_t read_pmd_pagesize(void)

fd = open(PMD_SIZE_FILE_PATH, O_RDONLY);
if (fd == -1)
ksft_exit_fail_msg("Open hpage_pmd_size failed\n");
return 0;

num_read = read(fd, buf, 19);
if (num_read < 1) {
close(fd);
ksft_exit_fail_msg("Read hpage_pmd_size failed\n");
return 0;
}
buf[num_read] = '\0';
close(fd);
Expand Down

0 comments on commit d6e61af

Please sign in to comment.