Commit 366e93c4 authored by Peter Xu's avatar Peter Xu Committed by Andrew Morton

selftests/mm: reuse pagemap_get_entry() in vm_util.h

Meanwhile drop pagemap_read_vaddr().

Link: https://lkml.kernel.org/r/20230412164231.328157-1-peterx@redhat.comSigned-off-by: default avatarPeter Xu <peterx@redhat.com>
Reviewed-by: default avatarAxel Rasmussen <axelrasmussen@google.com>
Reviewed-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
Reviewed-by: default avatarMike Rapoport (IBM) <rppt@kernel.org>
Cc: Dmitry Safonov <0x7f454c46@gmail.com>
Cc: Zach O'Keefe <zokeefe@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 9f74696b
...@@ -1399,19 +1399,6 @@ static int pagemap_open(void) ...@@ -1399,19 +1399,6 @@ static int pagemap_open(void)
return fd; return fd;
} }
static uint64_t pagemap_read_vaddr(int fd, void *vaddr)
{
uint64_t value;
int ret;
ret = pread(fd, &value, sizeof(uint64_t),
((uint64_t)vaddr >> 12) * sizeof(uint64_t));
if (ret != sizeof(uint64_t))
err("pread() on pagemap failed");
return value;
}
/* This macro let __LINE__ works in err() */ /* This macro let __LINE__ works in err() */
#define pagemap_check_wp(value, wp) do { \ #define pagemap_check_wp(value, wp) do { \
if (!!(value & PM_UFFD_WP) != wp) \ if (!!(value & PM_UFFD_WP) != wp) \
...@@ -1427,7 +1414,7 @@ static int pagemap_test_fork(bool present) ...@@ -1427,7 +1414,7 @@ static int pagemap_test_fork(bool present)
if (!child) { if (!child) {
/* Open the pagemap fd of the child itself */ /* Open the pagemap fd of the child itself */
fd = pagemap_open(); fd = pagemap_open();
value = pagemap_read_vaddr(fd, area_dst); value = pagemap_get_entry(fd, area_dst);
/* /*
* After fork() uffd-wp bit should be gone as long as we're * After fork() uffd-wp bit should be gone as long as we're
* without UFFD_FEATURE_EVENT_FORK * without UFFD_FEATURE_EVENT_FORK
...@@ -1446,24 +1433,24 @@ static void userfaultfd_wp_unpopulated_test(int pagemap_fd) ...@@ -1446,24 +1433,24 @@ static void userfaultfd_wp_unpopulated_test(int pagemap_fd)
/* Test applying pte marker to anon unpopulated */ /* Test applying pte marker to anon unpopulated */
wp_range(uffd, (uint64_t)area_dst, page_size, true); wp_range(uffd, (uint64_t)area_dst, page_size, true);
value = pagemap_read_vaddr(pagemap_fd, area_dst); value = pagemap_get_entry(pagemap_fd, area_dst);
pagemap_check_wp(value, true); pagemap_check_wp(value, true);
/* Test unprotect on anon pte marker */ /* Test unprotect on anon pte marker */
wp_range(uffd, (uint64_t)area_dst, page_size, false); wp_range(uffd, (uint64_t)area_dst, page_size, false);
value = pagemap_read_vaddr(pagemap_fd, area_dst); value = pagemap_get_entry(pagemap_fd, area_dst);
pagemap_check_wp(value, false); pagemap_check_wp(value, false);
/* Test zap on anon marker */ /* Test zap on anon marker */
wp_range(uffd, (uint64_t)area_dst, page_size, true); wp_range(uffd, (uint64_t)area_dst, page_size, true);
if (madvise(area_dst, page_size, MADV_DONTNEED)) if (madvise(area_dst, page_size, MADV_DONTNEED))
err("madvise(MADV_DONTNEED) failed"); err("madvise(MADV_DONTNEED) failed");
value = pagemap_read_vaddr(pagemap_fd, area_dst); value = pagemap_get_entry(pagemap_fd, area_dst);
pagemap_check_wp(value, false); pagemap_check_wp(value, false);
/* Test fault in after marker removed */ /* Test fault in after marker removed */
*area_dst = 1; *area_dst = 1;
value = pagemap_read_vaddr(pagemap_fd, area_dst); value = pagemap_get_entry(pagemap_fd, area_dst);
pagemap_check_wp(value, false); pagemap_check_wp(value, false);
/* Drop it to make pte none again */ /* Drop it to make pte none again */
if (madvise(area_dst, page_size, MADV_DONTNEED)) if (madvise(area_dst, page_size, MADV_DONTNEED))
...@@ -1522,7 +1509,7 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize) ...@@ -1522,7 +1509,7 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize)
/* Touch the page */ /* Touch the page */
*area_dst = 1; *area_dst = 1;
wp_range(uffd, (uint64_t)area_dst, test_pgsize, true); wp_range(uffd, (uint64_t)area_dst, test_pgsize, true);
value = pagemap_read_vaddr(pagemap_fd, area_dst); value = pagemap_get_entry(pagemap_fd, area_dst);
pagemap_check_wp(value, true); pagemap_check_wp(value, true);
/* Make sure uffd-wp bit dropped when fork */ /* Make sure uffd-wp bit dropped when fork */
if (pagemap_test_fork(true)) if (pagemap_test_fork(true))
...@@ -1536,7 +1523,7 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize) ...@@ -1536,7 +1523,7 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize)
err("madvise(MADV_PAGEOUT) failed"); err("madvise(MADV_PAGEOUT) failed");
/* Uffd-wp should persist even swapped out */ /* Uffd-wp should persist even swapped out */
value = pagemap_read_vaddr(pagemap_fd, area_dst); value = pagemap_get_entry(pagemap_fd, area_dst);
pagemap_check_wp(value, true); pagemap_check_wp(value, true);
/* Make sure uffd-wp bit dropped when fork */ /* Make sure uffd-wp bit dropped when fork */
if (pagemap_test_fork(false)) if (pagemap_test_fork(false))
...@@ -1544,12 +1531,12 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize) ...@@ -1544,12 +1531,12 @@ static void userfaultfd_pagemap_test(unsigned int test_pgsize)
/* Unprotect; this tests swap pte modifications */ /* Unprotect; this tests swap pte modifications */
wp_range(uffd, (uint64_t)area_dst, page_size, false); wp_range(uffd, (uint64_t)area_dst, page_size, false);
value = pagemap_read_vaddr(pagemap_fd, area_dst); value = pagemap_get_entry(pagemap_fd, area_dst);
pagemap_check_wp(value, false); pagemap_check_wp(value, false);
/* Fault in the page from disk */ /* Fault in the page from disk */
*area_dst = 2; *area_dst = 2;
value = pagemap_read_vaddr(pagemap_fd, area_dst); value = pagemap_get_entry(pagemap_fd, area_dst);
pagemap_check_wp(value, false); pagemap_check_wp(value, false);
close(pagemap_fd); close(pagemap_fd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment