Merge tag 'platform-drivers-x86-v6.9-3' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-block.git] / tools / testing / selftests / mm / vm_util.h
CommitLineData
642bc52a
MUA
1/* SPDX-License-Identifier: GPL-2.0 */
2#include <stdint.h>
3#include <stdbool.h>
af605d26
PX
4#include <sys/mman.h>
5#include <err.h>
176517c9 6#include <strings.h> /* ffsl() */
af605d26
PX
7#include <unistd.h> /* _SC_PAGESIZE */
8
9f74696b
PX
9#define BIT_ULL(nr) (1ULL << (nr))
10#define PM_SOFT_DIRTY BIT_ULL(55)
11#define PM_MMAP_EXCLUSIVE BIT_ULL(56)
12#define PM_UFFD_WP BIT_ULL(57)
13#define PM_FILE BIT_ULL(61)
14#define PM_SWAP BIT_ULL(62)
15#define PM_PRESENT BIT_ULL(63)
16
af605d26
PX
17extern unsigned int __page_size;
18extern unsigned int __page_shift;
19
20static inline unsigned int psize(void)
21{
22 if (!__page_size)
23 __page_size = sysconf(_SC_PAGESIZE);
24 return __page_size;
25}
26
27static inline unsigned int pshift(void)
28{
29 if (!__page_shift)
30 __page_shift = (ffsl(psize()) - 1);
31 return __page_shift;
32}
642bc52a
MUA
33
34uint64_t pagemap_get_entry(int fd, char *start);
35bool pagemap_is_softdirty(int fd, char *start);
69c66add 36bool pagemap_is_swapped(int fd, char *start);
a905e82a 37bool pagemap_is_populated(int fd, char *start);
93fb70aa 38unsigned long pagemap_get_pfn(int fd, char *start);
642bc52a 39void clear_softdirty(void);
c07c343c 40bool check_for_pattern(FILE *fp, const char *pattern, char *buf, size_t len);
642bc52a 41uint64_t read_pmd_pagesize(void);
c07c343c 42bool check_huge_anon(void *addr, int nr_hpages, uint64_t hpage_size);
1b03d0d5
ZK
43bool check_huge_file(void *addr, int nr_hpages, uint64_t hpage_size);
44bool check_huge_shmem(void *addr, int nr_hpages, uint64_t hpage_size);
af605d26 45int64_t allocate_transhuge(void *ptr, int pagemap_fd);
bd4d67e7 46unsigned long default_huge_page_size(void);
81b1e3f9 47int detect_hugetlb_page_sizes(size_t sizes[], int max);
af605d26 48
c4277cb6
PX
49int uffd_register(int uffd, void *addr, uint64_t len,
50 bool miss, bool wp, bool minor);
51int uffd_unregister(int uffd, void *addr, uint64_t len);
c3315502
PX
52int uffd_register_with_ioctls(int uffd, void *addr, uint64_t len,
53 bool miss, bool wp, bool minor, uint64_t *ioctls);
c8b90731 54unsigned long get_free_hugepages(void);
c4277cb6 55
af605d26
PX
56/*
57 * On ppc64 this will only work with radix 2M hugepage size
58 */
59#define HPAGE_SHIFT 21
60#define HPAGE_SIZE (1 << HPAGE_SHIFT)
61
62#define PAGEMAP_PRESENT(ent) (((ent) & (1ull << 63)) != 0)
63#define PAGEMAP_PFN(ent) ((ent) & ((1ull << 55) - 1))