mirror of
https://github.com/torvalds/linux
synced 2024-11-05 18:23:50 +00:00
selftests/mm: reuse read_pmd_pagesize() in COW selftest
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>
This commit is contained in:
parent
1e9460d132
commit
d6e61afb40
5 changed files with 17 additions and 31 deletions
|
@ -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",
|
||||
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue