Message ID | 20230330160708.3106977-1-peterx@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | selftests/mm: Split / Refactor userfault test | expand |
On 03/30/23 12:07, Peter Xu wrote: > We've got the macros in uffd-stress.c, move it over and use it in > vm_util.h. > > Signed-off-by: Peter Xu <peterx@redhat.com> > --- > tools/testing/selftests/mm/userfaultfd.c | 8 -------- > tools/testing/selftests/mm/vm_util.c | 16 ++++------------ > tools/testing/selftests/mm/vm_util.h | 8 ++++++++ > 3 files changed, 12 insertions(+), 20 deletions(-) Nice, thanks! Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
On 30.03.23 18:07, Peter Xu wrote: > We've got the macros in uffd-stress.c, move it over and use it in > vm_util.h. > > Signed-off-by: Peter Xu <peterx@redhat.com> > --- Reviewed-by: David Hildenbrand <david@redhat.com>
On Thu, Mar 30, 2023 at 12:07:08PM -0400, Peter Xu wrote: > We've got the macros in uffd-stress.c, move it over and use it in > vm_util.h. > > Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Mike Rapoport (IBM) <rppt@kernel.org> > --- > tools/testing/selftests/mm/userfaultfd.c | 8 -------- > tools/testing/selftests/mm/vm_util.c | 16 ++++------------ > tools/testing/selftests/mm/vm_util.h | 8 ++++++++ > 3 files changed, 12 insertions(+), 20 deletions(-) > > diff --git a/tools/testing/selftests/mm/userfaultfd.c b/tools/testing/selftests/mm/userfaultfd.c > index 4cc80a0e8955..7e841f7e2884 100644 > --- a/tools/testing/selftests/mm/userfaultfd.c > +++ b/tools/testing/selftests/mm/userfaultfd.c > @@ -1389,14 +1389,6 @@ static int userfaultfd_minor_test(void) > 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) > { > int fd = open("/proc/self/pagemap", O_RDONLY); > diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c > index 12dc654b5be3..8e9da621764a 100644 > --- a/tools/testing/selftests/mm/vm_util.c > +++ b/tools/testing/selftests/mm/vm_util.c > @@ -25,25 +25,17 @@ uint64_t pagemap_get_entry(int fd, char *start) > > bool pagemap_is_softdirty(int fd, char *start) > { > - uint64_t entry = pagemap_get_entry(fd, start); > - > - // Check if dirty bit (55th bit) is set > - return entry & 0x0080000000000000ull; > + return pagemap_get_entry(fd, start) & PM_SOFT_DIRTY; > } > > bool pagemap_is_swapped(int fd, char *start) > { > - uint64_t entry = pagemap_get_entry(fd, start); > - > - return entry & 0x4000000000000000ull; > + return pagemap_get_entry(fd, start) & PM_SWAP; > } > > bool pagemap_is_populated(int fd, char *start) > { > - uint64_t entry = pagemap_get_entry(fd, start); > - > - /* Present or swapped. */ > - return entry & 0xc000000000000000ull; > + return pagemap_get_entry(fd, start) & (PM_PRESENT | PM_SWAP); > } > > 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); > > /* If present (63th bit), PFN is at bit 0 -- 54. */ > - if (entry & 0x8000000000000000ull) > + if (entry & PM_PRESENT) > return entry & 0x007fffffffffffffull; > return -1ul; > } > diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h > index d7163fff8fb7..d9fadddb5c69 100644 > --- a/tools/testing/selftests/mm/vm_util.h > +++ b/tools/testing/selftests/mm/vm_util.h > @@ -6,6 +6,14 @@ > #include <string.h> /* ffsl() */ > #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_shift; > > -- > 2.39.1 >
diff --git a/tools/testing/selftests/mm/userfaultfd.c b/tools/testing/selftests/mm/userfaultfd.c index 4cc80a0e8955..7e841f7e2884 100644 --- a/tools/testing/selftests/mm/userfaultfd.c +++ b/tools/testing/selftests/mm/userfaultfd.c @@ -1389,14 +1389,6 @@ static int userfaultfd_minor_test(void) 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) { int fd = open("/proc/self/pagemap", O_RDONLY); diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 12dc654b5be3..8e9da621764a 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -25,25 +25,17 @@ uint64_t pagemap_get_entry(int fd, char *start) bool pagemap_is_softdirty(int fd, char *start) { - uint64_t entry = pagemap_get_entry(fd, start); - - // Check if dirty bit (55th bit) is set - return entry & 0x0080000000000000ull; + return pagemap_get_entry(fd, start) & PM_SOFT_DIRTY; } bool pagemap_is_swapped(int fd, char *start) { - uint64_t entry = pagemap_get_entry(fd, start); - - return entry & 0x4000000000000000ull; + return pagemap_get_entry(fd, start) & PM_SWAP; } bool pagemap_is_populated(int fd, char *start) { - uint64_t entry = pagemap_get_entry(fd, start); - - /* Present or swapped. */ - return entry & 0xc000000000000000ull; + return pagemap_get_entry(fd, start) & (PM_PRESENT | PM_SWAP); } 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); /* If present (63th bit), PFN is at bit 0 -- 54. */ - if (entry & 0x8000000000000000ull) + if (entry & PM_PRESENT) return entry & 0x007fffffffffffffull; return -1ul; } diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index d7163fff8fb7..d9fadddb5c69 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -6,6 +6,14 @@ #include <string.h> /* ffsl() */ #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_shift;
We've got the macros in uffd-stress.c, move it over and use it in vm_util.h. Signed-off-by: Peter Xu <peterx@redhat.com> --- tools/testing/selftests/mm/userfaultfd.c | 8 -------- tools/testing/selftests/mm/vm_util.c | 16 ++++------------ tools/testing/selftests/mm/vm_util.h | 8 ++++++++ 3 files changed, 12 insertions(+), 20 deletions(-)