Commit 9f74696b authored by Peter Xu's avatar Peter Xu Committed by Andrew Morton

selftests/mm: use PM_* macros in vm_utils.h

We've got the macros in uffd-stress.c, move it over and use it in
vm_util.h.

Link: https://lkml.kernel.org/r/20230412164227.328145-1-peterx@redhat.comSigned-off-by: default avatarPeter Xu <peterx@redhat.com>
Reviewed-by: default avatarAxel Rasmussen <axelrasmussen@google.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: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Zach O'Keefe <zokeefe@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent bd4d67e7
...@@ -1389,14 +1389,6 @@ static int userfaultfd_minor_test(void) ...@@ -1389,14 +1389,6 @@ static int userfaultfd_minor_test(void)
return stats.missing_faults != 0 || stats.minor_faults != nr_pages; return stats.missing_faults != 0 || stats.minor_faults != nr_pages;
} }
#define BIT_ULL(nr) (1ULL << (nr))
#define PM_SOFT_DIRTY BIT_ULL(55)
#define PM_MMAP_EXCLUSIVE BIT_ULL(56)
#define PM_UFFD_WP BIT_ULL(57)
#define PM_FILE BIT_ULL(61)
#define PM_SWAP BIT_ULL(62)
#define PM_PRESENT BIT_ULL(63)
static int pagemap_open(void) static int pagemap_open(void)
{ {
int fd = open("/proc/self/pagemap", O_RDONLY); int fd = open("/proc/self/pagemap", O_RDONLY);
......
...@@ -25,25 +25,17 @@ uint64_t pagemap_get_entry(int fd, char *start) ...@@ -25,25 +25,17 @@ uint64_t pagemap_get_entry(int fd, char *start)
bool pagemap_is_softdirty(int fd, char *start) bool pagemap_is_softdirty(int fd, char *start)
{ {
uint64_t entry = pagemap_get_entry(fd, start); return pagemap_get_entry(fd, start) & PM_SOFT_DIRTY;
// Check if dirty bit (55th bit) is set
return entry & 0x0080000000000000ull;
} }
bool pagemap_is_swapped(int fd, char *start) bool pagemap_is_swapped(int fd, char *start)
{ {
uint64_t entry = pagemap_get_entry(fd, start); return pagemap_get_entry(fd, start) & PM_SWAP;
return entry & 0x4000000000000000ull;
} }
bool pagemap_is_populated(int fd, char *start) bool pagemap_is_populated(int fd, char *start)
{ {
uint64_t entry = pagemap_get_entry(fd, start); return pagemap_get_entry(fd, start) & (PM_PRESENT | PM_SWAP);
/* Present or swapped. */
return entry & 0xc000000000000000ull;
} }
unsigned long pagemap_get_pfn(int fd, char *start) unsigned long pagemap_get_pfn(int fd, char *start)
...@@ -51,7 +43,7 @@ unsigned long pagemap_get_pfn(int fd, char *start) ...@@ -51,7 +43,7 @@ unsigned long pagemap_get_pfn(int fd, char *start)
uint64_t entry = pagemap_get_entry(fd, start); uint64_t entry = pagemap_get_entry(fd, start);
/* If present (63th bit), PFN is at bit 0 -- 54. */ /* If present (63th bit), PFN is at bit 0 -- 54. */
if (entry & 0x8000000000000000ull) if (entry & PM_PRESENT)
return entry & 0x007fffffffffffffull; return entry & 0x007fffffffffffffull;
return -1ul; return -1ul;
} }
......
...@@ -6,6 +6,14 @@ ...@@ -6,6 +6,14 @@
#include <string.h> /* ffsl() */ #include <string.h> /* ffsl() */
#include <unistd.h> /* _SC_PAGESIZE */ #include <unistd.h> /* _SC_PAGESIZE */
#define BIT_ULL(nr) (1ULL << (nr))
#define PM_SOFT_DIRTY BIT_ULL(55)
#define PM_MMAP_EXCLUSIVE BIT_ULL(56)
#define PM_UFFD_WP BIT_ULL(57)
#define PM_FILE BIT_ULL(61)
#define PM_SWAP BIT_ULL(62)
#define PM_PRESENT BIT_ULL(63)
extern unsigned int __page_size; extern unsigned int __page_size;
extern unsigned int __page_shift; extern unsigned int __page_shift;
......
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