vma_internal.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * vma_internal.h
  4. *
  5. * Header providing userland wrappers and shims for the functionality provided
  6. * by mm/vma_internal.h.
  7. *
  8. * We make the header guard the same as mm/vma_internal.h, so if this shim
  9. * header is included, it precludes the inclusion of the kernel one.
  10. */
  11. #ifndef __MM_VMA_INTERNAL_H
  12. #define __MM_VMA_INTERNAL_H
  13. #define __private
  14. #define __bitwise
  15. #define __randomize_layout
  16. #define CONFIG_MMU
  17. #define CONFIG_PER_VMA_LOCK
  18. #include <stdlib.h>
  19. #include <linux/list.h>
  20. #include <linux/maple_tree.h>
  21. #include <linux/mm.h>
  22. #include <linux/rbtree.h>
  23. #include <linux/rwsem.h>
  24. #define VM_WARN_ON(_expr) (WARN_ON(_expr))
  25. #define VM_WARN_ON_ONCE(_expr) (WARN_ON_ONCE(_expr))
  26. #define VM_BUG_ON(_expr) (BUG_ON(_expr))
  27. #define VM_BUG_ON_VMA(_expr, _vma) (BUG_ON(_expr))
  28. #define VM_NONE 0x00000000
  29. #define VM_READ 0x00000001
  30. #define VM_WRITE 0x00000002
  31. #define VM_EXEC 0x00000004
  32. #define VM_SHARED 0x00000008
  33. #define VM_MAYREAD 0x00000010
  34. #define VM_MAYWRITE 0x00000020
  35. #define VM_GROWSDOWN 0x00000100
  36. #define VM_PFNMAP 0x00000400
  37. #define VM_LOCKED 0x00002000
  38. #define VM_IO 0x00004000
  39. #define VM_DONTEXPAND 0x00040000
  40. #define VM_ACCOUNT 0x00100000
  41. #define VM_MIXEDMAP 0x10000000
  42. #define VM_STACK VM_GROWSDOWN
  43. #define VM_SHADOW_STACK VM_NONE
  44. #define VM_SOFTDIRTY 0
  45. #define VM_ACCESS_FLAGS (VM_READ | VM_WRITE | VM_EXEC)
  46. #define VM_SPECIAL (VM_IO | VM_DONTEXPAND | VM_PFNMAP | VM_MIXEDMAP)
  47. #define FIRST_USER_ADDRESS 0UL
  48. #define USER_PGTABLES_CEILING 0UL
  49. #define vma_policy(vma) NULL
  50. #define down_write_nest_lock(sem, nest_lock)
  51. #define pgprot_val(x) ((x).pgprot)
  52. #define __pgprot(x) ((pgprot_t) { (x) } )
  53. #define for_each_vma(__vmi, __vma) \
  54. while (((__vma) = vma_next(&(__vmi))) != NULL)
  55. /* The MM code likes to work with exclusive end addresses */
  56. #define for_each_vma_range(__vmi, __vma, __end) \
  57. while (((__vma) = vma_find(&(__vmi), (__end))) != NULL)
  58. #define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK)
  59. #define PHYS_PFN(x) ((unsigned long)((x) >> PAGE_SHIFT))
  60. #define test_and_set_bit(nr, addr) __test_and_set_bit(nr, addr)
  61. #define test_and_clear_bit(nr, addr) __test_and_clear_bit(nr, addr)
  62. #define TASK_SIZE ((1ul << 47)-PAGE_SIZE)
  63. #define AS_MM_ALL_LOCKS 2
  64. /* We hardcode this for now. */
  65. #define sysctl_max_map_count 0x1000000UL
  66. #define pgoff_t unsigned long
  67. typedef unsigned long pgprotval_t;
  68. typedef struct pgprot { pgprotval_t pgprot; } pgprot_t;
  69. typedef unsigned long vm_flags_t;
  70. typedef __bitwise unsigned int vm_fault_t;
  71. /*
  72. * The shared stubs do not implement this, it amounts to an fprintf(STDERR,...)
  73. * either way :)
  74. */
  75. #define pr_warn_once pr_err
  76. typedef struct refcount_struct {
  77. atomic_t refs;
  78. } refcount_t;
  79. struct kref {
  80. refcount_t refcount;
  81. };
  82. /*
  83. * Define the task command name length as enum, then it can be visible to
  84. * BPF programs.
  85. */
  86. enum {
  87. TASK_COMM_LEN = 16,
  88. };
  89. struct task_struct {
  90. char comm[TASK_COMM_LEN];
  91. pid_t pid;
  92. struct mm_struct *mm;
  93. };
  94. struct task_struct *get_current(void);
  95. #define current get_current()
  96. struct anon_vma {
  97. struct anon_vma *root;
  98. struct rb_root_cached rb_root;
  99. /* Test fields. */
  100. bool was_cloned;
  101. bool was_unlinked;
  102. };
  103. struct anon_vma_chain {
  104. struct anon_vma *anon_vma;
  105. struct list_head same_vma;
  106. };
  107. struct anon_vma_name {
  108. struct kref kref;
  109. /* The name needs to be at the end because it is dynamically sized. */
  110. char name[];
  111. };
  112. struct vma_iterator {
  113. struct ma_state mas;
  114. };
  115. #define VMA_ITERATOR(name, __mm, __addr) \
  116. struct vma_iterator name = { \
  117. .mas = { \
  118. .tree = &(__mm)->mm_mt, \
  119. .index = __addr, \
  120. .node = NULL, \
  121. .status = ma_start, \
  122. }, \
  123. }
  124. struct address_space {
  125. struct rb_root_cached i_mmap;
  126. unsigned long flags;
  127. atomic_t i_mmap_writable;
  128. };
  129. struct vm_userfaultfd_ctx {};
  130. struct mempolicy {};
  131. struct mmu_gather {};
  132. struct mutex {};
  133. #define DEFINE_MUTEX(mutexname) \
  134. struct mutex mutexname = {}
  135. struct mm_struct {
  136. struct maple_tree mm_mt;
  137. int map_count; /* number of VMAs */
  138. unsigned long total_vm; /* Total pages mapped */
  139. unsigned long locked_vm; /* Pages that have PG_mlocked set */
  140. unsigned long data_vm; /* VM_WRITE & ~VM_SHARED & ~VM_STACK */
  141. unsigned long exec_vm; /* VM_EXEC & ~VM_WRITE & ~VM_STACK */
  142. unsigned long stack_vm; /* VM_STACK */
  143. };
  144. struct vma_lock {
  145. struct rw_semaphore lock;
  146. };
  147. struct file {
  148. struct address_space *f_mapping;
  149. };
  150. struct vm_area_struct {
  151. /* The first cache line has the info for VMA tree walking. */
  152. union {
  153. struct {
  154. /* VMA covers [vm_start; vm_end) addresses within mm */
  155. unsigned long vm_start;
  156. unsigned long vm_end;
  157. };
  158. #ifdef CONFIG_PER_VMA_LOCK
  159. struct rcu_head vm_rcu; /* Used for deferred freeing. */
  160. #endif
  161. };
  162. struct mm_struct *vm_mm; /* The address space we belong to. */
  163. pgprot_t vm_page_prot; /* Access permissions of this VMA. */
  164. /*
  165. * Flags, see mm.h.
  166. * To modify use vm_flags_{init|reset|set|clear|mod} functions.
  167. */
  168. union {
  169. const vm_flags_t vm_flags;
  170. vm_flags_t __private __vm_flags;
  171. };
  172. #ifdef CONFIG_PER_VMA_LOCK
  173. /* Flag to indicate areas detached from the mm->mm_mt tree */
  174. bool detached;
  175. /*
  176. * Can only be written (using WRITE_ONCE()) while holding both:
  177. * - mmap_lock (in write mode)
  178. * - vm_lock->lock (in write mode)
  179. * Can be read reliably while holding one of:
  180. * - mmap_lock (in read or write mode)
  181. * - vm_lock->lock (in read or write mode)
  182. * Can be read unreliably (using READ_ONCE()) for pessimistic bailout
  183. * while holding nothing (except RCU to keep the VMA struct allocated).
  184. *
  185. * This sequence counter is explicitly allowed to overflow; sequence
  186. * counter reuse can only lead to occasional unnecessary use of the
  187. * slowpath.
  188. */
  189. int vm_lock_seq;
  190. struct vma_lock *vm_lock;
  191. #endif
  192. /*
  193. * For areas with an address space and backing store,
  194. * linkage into the address_space->i_mmap interval tree.
  195. *
  196. */
  197. struct {
  198. struct rb_node rb;
  199. unsigned long rb_subtree_last;
  200. } shared;
  201. /*
  202. * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
  203. * list, after a COW of one of the file pages. A MAP_SHARED vma
  204. * can only be in the i_mmap tree. An anonymous MAP_PRIVATE, stack
  205. * or brk vma (with NULL file) can only be in an anon_vma list.
  206. */
  207. struct list_head anon_vma_chain; /* Serialized by mmap_lock &
  208. * page_table_lock */
  209. struct anon_vma *anon_vma; /* Serialized by page_table_lock */
  210. /* Function pointers to deal with this struct. */
  211. const struct vm_operations_struct *vm_ops;
  212. /* Information about our backing store: */
  213. unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
  214. units */
  215. struct file * vm_file; /* File we map to (can be NULL). */
  216. void * vm_private_data; /* was vm_pte (shared mem) */
  217. #ifdef CONFIG_ANON_VMA_NAME
  218. /*
  219. * For private and shared anonymous mappings, a pointer to a null
  220. * terminated string containing the name given to the vma, or NULL if
  221. * unnamed. Serialized by mmap_lock. Use anon_vma_name to access.
  222. */
  223. struct anon_vma_name *anon_name;
  224. #endif
  225. #ifdef CONFIG_SWAP
  226. atomic_long_t swap_readahead_info;
  227. #endif
  228. #ifndef CONFIG_MMU
  229. struct vm_region *vm_region; /* NOMMU mapping region */
  230. #endif
  231. #ifdef CONFIG_NUMA
  232. struct mempolicy *vm_policy; /* NUMA policy for the VMA */
  233. #endif
  234. #ifdef CONFIG_NUMA_BALANCING
  235. struct vma_numab_state *numab_state; /* NUMA Balancing state */
  236. #endif
  237. struct vm_userfaultfd_ctx vm_userfaultfd_ctx;
  238. } __randomize_layout;
  239. struct vm_fault {};
  240. struct vm_operations_struct {
  241. void (*open)(struct vm_area_struct * area);
  242. /**
  243. * @close: Called when the VMA is being removed from the MM.
  244. * Context: User context. May sleep. Caller holds mmap_lock.
  245. */
  246. void (*close)(struct vm_area_struct * area);
  247. /* Called any time before splitting to check if it's allowed */
  248. int (*may_split)(struct vm_area_struct *area, unsigned long addr);
  249. int (*mremap)(struct vm_area_struct *area);
  250. /*
  251. * Called by mprotect() to make driver-specific permission
  252. * checks before mprotect() is finalised. The VMA must not
  253. * be modified. Returns 0 if mprotect() can proceed.
  254. */
  255. int (*mprotect)(struct vm_area_struct *vma, unsigned long start,
  256. unsigned long end, unsigned long newflags);
  257. vm_fault_t (*fault)(struct vm_fault *vmf);
  258. vm_fault_t (*huge_fault)(struct vm_fault *vmf, unsigned int order);
  259. vm_fault_t (*map_pages)(struct vm_fault *vmf,
  260. pgoff_t start_pgoff, pgoff_t end_pgoff);
  261. unsigned long (*pagesize)(struct vm_area_struct * area);
  262. /* notification that a previously read-only page is about to become
  263. * writable, if an error is returned it will cause a SIGBUS */
  264. vm_fault_t (*page_mkwrite)(struct vm_fault *vmf);
  265. /* same as page_mkwrite when using VM_PFNMAP|VM_MIXEDMAP */
  266. vm_fault_t (*pfn_mkwrite)(struct vm_fault *vmf);
  267. /* called by access_process_vm when get_user_pages() fails, typically
  268. * for use by special VMAs. See also generic_access_phys() for a generic
  269. * implementation useful for any iomem mapping.
  270. */
  271. int (*access)(struct vm_area_struct *vma, unsigned long addr,
  272. void *buf, int len, int write);
  273. /* Called by the /proc/PID/maps code to ask the vma whether it
  274. * has a special name. Returning non-NULL will also cause this
  275. * vma to be dumped unconditionally. */
  276. const char *(*name)(struct vm_area_struct *vma);
  277. #ifdef CONFIG_NUMA
  278. /*
  279. * set_policy() op must add a reference to any non-NULL @new mempolicy
  280. * to hold the policy upon return. Caller should pass NULL @new to
  281. * remove a policy and fall back to surrounding context--i.e. do not
  282. * install a MPOL_DEFAULT policy, nor the task or system default
  283. * mempolicy.
  284. */
  285. int (*set_policy)(struct vm_area_struct *vma, struct mempolicy *new);
  286. /*
  287. * get_policy() op must add reference [mpol_get()] to any policy at
  288. * (vma,addr) marked as MPOL_SHARED. The shared policy infrastructure
  289. * in mm/mempolicy.c will do this automatically.
  290. * get_policy() must NOT add a ref if the policy at (vma,addr) is not
  291. * marked as MPOL_SHARED. vma policies are protected by the mmap_lock.
  292. * If no [shared/vma] mempolicy exists at the addr, get_policy() op
  293. * must return NULL--i.e., do not "fallback" to task or system default
  294. * policy.
  295. */
  296. struct mempolicy *(*get_policy)(struct vm_area_struct *vma,
  297. unsigned long addr, pgoff_t *ilx);
  298. #endif
  299. /*
  300. * Called by vm_normal_page() for special PTEs to find the
  301. * page for @addr. This is useful if the default behavior
  302. * (using pte_page()) would not find the correct page.
  303. */
  304. struct page *(*find_special_page)(struct vm_area_struct *vma,
  305. unsigned long addr);
  306. };
  307. static inline void vma_iter_invalidate(struct vma_iterator *vmi)
  308. {
  309. mas_pause(&vmi->mas);
  310. }
  311. static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
  312. {
  313. return __pgprot(pgprot_val(oldprot) | pgprot_val(newprot));
  314. }
  315. static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
  316. {
  317. return __pgprot(vm_flags);
  318. }
  319. static inline bool is_shared_maywrite(vm_flags_t vm_flags)
  320. {
  321. return (vm_flags & (VM_SHARED | VM_MAYWRITE)) ==
  322. (VM_SHARED | VM_MAYWRITE);
  323. }
  324. static inline bool vma_is_shared_maywrite(struct vm_area_struct *vma)
  325. {
  326. return is_shared_maywrite(vma->vm_flags);
  327. }
  328. static inline struct vm_area_struct *vma_next(struct vma_iterator *vmi)
  329. {
  330. /*
  331. * Uses mas_find() to get the first VMA when the iterator starts.
  332. * Calling mas_next() could skip the first entry.
  333. */
  334. return mas_find(&vmi->mas, ULONG_MAX);
  335. }
  336. static inline bool vma_lock_alloc(struct vm_area_struct *vma)
  337. {
  338. vma->vm_lock = calloc(1, sizeof(struct vma_lock));
  339. if (!vma->vm_lock)
  340. return false;
  341. init_rwsem(&vma->vm_lock->lock);
  342. vma->vm_lock_seq = -1;
  343. return true;
  344. }
  345. static inline void vma_assert_write_locked(struct vm_area_struct *);
  346. static inline void vma_mark_detached(struct vm_area_struct *vma, bool detached)
  347. {
  348. /* When detaching vma should be write-locked */
  349. if (detached)
  350. vma_assert_write_locked(vma);
  351. vma->detached = detached;
  352. }
  353. extern const struct vm_operations_struct vma_dummy_vm_ops;
  354. static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm)
  355. {
  356. memset(vma, 0, sizeof(*vma));
  357. vma->vm_mm = mm;
  358. vma->vm_ops = &vma_dummy_vm_ops;
  359. INIT_LIST_HEAD(&vma->anon_vma_chain);
  360. vma_mark_detached(vma, false);
  361. }
  362. static inline struct vm_area_struct *vm_area_alloc(struct mm_struct *mm)
  363. {
  364. struct vm_area_struct *vma = calloc(1, sizeof(struct vm_area_struct));
  365. if (!vma)
  366. return NULL;
  367. vma_init(vma, mm);
  368. if (!vma_lock_alloc(vma)) {
  369. free(vma);
  370. return NULL;
  371. }
  372. return vma;
  373. }
  374. static inline struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig)
  375. {
  376. struct vm_area_struct *new = calloc(1, sizeof(struct vm_area_struct));
  377. if (!new)
  378. return NULL;
  379. memcpy(new, orig, sizeof(*new));
  380. if (!vma_lock_alloc(new)) {
  381. free(new);
  382. return NULL;
  383. }
  384. INIT_LIST_HEAD(&new->anon_vma_chain);
  385. return new;
  386. }
  387. /*
  388. * These are defined in vma.h, but sadly vm_stat_account() is referenced by
  389. * kernel/fork.c, so we have to these broadly available there, and temporarily
  390. * define them here to resolve the dependency cycle.
  391. */
  392. #define is_exec_mapping(flags) \
  393. ((flags & (VM_EXEC | VM_WRITE | VM_STACK)) == VM_EXEC)
  394. #define is_stack_mapping(flags) \
  395. (((flags & VM_STACK) == VM_STACK) || (flags & VM_SHADOW_STACK))
  396. #define is_data_mapping(flags) \
  397. ((flags & (VM_WRITE | VM_SHARED | VM_STACK)) == VM_WRITE)
  398. static inline void vm_stat_account(struct mm_struct *mm, vm_flags_t flags,
  399. long npages)
  400. {
  401. WRITE_ONCE(mm->total_vm, READ_ONCE(mm->total_vm)+npages);
  402. if (is_exec_mapping(flags))
  403. mm->exec_vm += npages;
  404. else if (is_stack_mapping(flags))
  405. mm->stack_vm += npages;
  406. else if (is_data_mapping(flags))
  407. mm->data_vm += npages;
  408. }
  409. #undef is_exec_mapping
  410. #undef is_stack_mapping
  411. #undef is_data_mapping
  412. /* Currently stubbed but we may later wish to un-stub. */
  413. static inline void vm_acct_memory(long pages);
  414. static inline void vm_unacct_memory(long pages)
  415. {
  416. vm_acct_memory(-pages);
  417. }
  418. static inline void mapping_allow_writable(struct address_space *mapping)
  419. {
  420. atomic_inc(&mapping->i_mmap_writable);
  421. }
  422. static inline void vma_set_range(struct vm_area_struct *vma,
  423. unsigned long start, unsigned long end,
  424. pgoff_t pgoff)
  425. {
  426. vma->vm_start = start;
  427. vma->vm_end = end;
  428. vma->vm_pgoff = pgoff;
  429. }
  430. static inline
  431. struct vm_area_struct *vma_find(struct vma_iterator *vmi, unsigned long max)
  432. {
  433. return mas_find(&vmi->mas, max - 1);
  434. }
  435. static inline int vma_iter_clear_gfp(struct vma_iterator *vmi,
  436. unsigned long start, unsigned long end, gfp_t gfp)
  437. {
  438. __mas_set_range(&vmi->mas, start, end - 1);
  439. mas_store_gfp(&vmi->mas, NULL, gfp);
  440. if (unlikely(mas_is_err(&vmi->mas)))
  441. return -ENOMEM;
  442. return 0;
  443. }
  444. static inline void mmap_assert_locked(struct mm_struct *);
  445. static inline struct vm_area_struct *find_vma_intersection(struct mm_struct *mm,
  446. unsigned long start_addr,
  447. unsigned long end_addr)
  448. {
  449. unsigned long index = start_addr;
  450. mmap_assert_locked(mm);
  451. return mt_find(&mm->mm_mt, &index, end_addr - 1);
  452. }
  453. static inline
  454. struct vm_area_struct *vma_lookup(struct mm_struct *mm, unsigned long addr)
  455. {
  456. return mtree_load(&mm->mm_mt, addr);
  457. }
  458. static inline struct vm_area_struct *vma_prev(struct vma_iterator *vmi)
  459. {
  460. return mas_prev(&vmi->mas, 0);
  461. }
  462. static inline void vma_iter_set(struct vma_iterator *vmi, unsigned long addr)
  463. {
  464. mas_set(&vmi->mas, addr);
  465. }
  466. static inline bool vma_is_anonymous(struct vm_area_struct *vma)
  467. {
  468. return !vma->vm_ops;
  469. }
  470. /* Defined in vma.h, so temporarily define here to avoid circular dependency. */
  471. #define vma_iter_load(vmi) \
  472. mas_walk(&(vmi)->mas)
  473. static inline struct vm_area_struct *
  474. find_vma_prev(struct mm_struct *mm, unsigned long addr,
  475. struct vm_area_struct **pprev)
  476. {
  477. struct vm_area_struct *vma;
  478. VMA_ITERATOR(vmi, mm, addr);
  479. vma = vma_iter_load(&vmi);
  480. *pprev = vma_prev(&vmi);
  481. if (!vma)
  482. vma = vma_next(&vmi);
  483. return vma;
  484. }
  485. #undef vma_iter_load
  486. static inline void vma_iter_init(struct vma_iterator *vmi,
  487. struct mm_struct *mm, unsigned long addr)
  488. {
  489. mas_init(&vmi->mas, &mm->mm_mt, addr);
  490. }
  491. /* Stubbed functions. */
  492. static inline struct anon_vma_name *anon_vma_name(struct vm_area_struct *vma)
  493. {
  494. return NULL;
  495. }
  496. static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma,
  497. struct vm_userfaultfd_ctx vm_ctx)
  498. {
  499. return true;
  500. }
  501. static inline bool anon_vma_name_eq(struct anon_vma_name *anon_name1,
  502. struct anon_vma_name *anon_name2)
  503. {
  504. return true;
  505. }
  506. static inline void might_sleep(void)
  507. {
  508. }
  509. static inline unsigned long vma_pages(struct vm_area_struct *vma)
  510. {
  511. return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
  512. }
  513. static inline void fput(struct file *)
  514. {
  515. }
  516. static inline void mpol_put(struct mempolicy *)
  517. {
  518. }
  519. static inline void vma_lock_free(struct vm_area_struct *vma)
  520. {
  521. free(vma->vm_lock);
  522. }
  523. static inline void __vm_area_free(struct vm_area_struct *vma)
  524. {
  525. vma_lock_free(vma);
  526. free(vma);
  527. }
  528. static inline void vm_area_free(struct vm_area_struct *vma)
  529. {
  530. __vm_area_free(vma);
  531. }
  532. static inline void lru_add_drain(void)
  533. {
  534. }
  535. static inline void tlb_gather_mmu(struct mmu_gather *, struct mm_struct *)
  536. {
  537. }
  538. static inline void update_hiwater_rss(struct mm_struct *)
  539. {
  540. }
  541. static inline void update_hiwater_vm(struct mm_struct *)
  542. {
  543. }
  544. static inline void unmap_vmas(struct mmu_gather *tlb, struct ma_state *mas,
  545. struct vm_area_struct *vma, unsigned long start_addr,
  546. unsigned long end_addr, unsigned long tree_end,
  547. bool mm_wr_locked)
  548. {
  549. (void)tlb;
  550. (void)mas;
  551. (void)vma;
  552. (void)start_addr;
  553. (void)end_addr;
  554. (void)tree_end;
  555. (void)mm_wr_locked;
  556. }
  557. static inline void free_pgtables(struct mmu_gather *tlb, struct ma_state *mas,
  558. struct vm_area_struct *vma, unsigned long floor,
  559. unsigned long ceiling, bool mm_wr_locked)
  560. {
  561. (void)tlb;
  562. (void)mas;
  563. (void)vma;
  564. (void)floor;
  565. (void)ceiling;
  566. (void)mm_wr_locked;
  567. }
  568. static inline void mapping_unmap_writable(struct address_space *)
  569. {
  570. }
  571. static inline void flush_dcache_mmap_lock(struct address_space *)
  572. {
  573. }
  574. static inline void tlb_finish_mmu(struct mmu_gather *)
  575. {
  576. }
  577. static inline void get_file(struct file *)
  578. {
  579. }
  580. static inline int vma_dup_policy(struct vm_area_struct *, struct vm_area_struct *)
  581. {
  582. return 0;
  583. }
  584. static inline int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
  585. {
  586. /* For testing purposes. We indicate that an anon_vma has been cloned. */
  587. if (src->anon_vma != NULL) {
  588. dst->anon_vma = src->anon_vma;
  589. dst->anon_vma->was_cloned = true;
  590. }
  591. return 0;
  592. }
  593. static inline void vma_start_write(struct vm_area_struct *vma)
  594. {
  595. /* Used to indicate to tests that a write operation has begun. */
  596. vma->vm_lock_seq++;
  597. }
  598. static inline void vma_adjust_trans_huge(struct vm_area_struct *vma,
  599. unsigned long start,
  600. unsigned long end,
  601. long adjust_next)
  602. {
  603. (void)vma;
  604. (void)start;
  605. (void)end;
  606. (void)adjust_next;
  607. }
  608. static inline void hugetlb_split(struct vm_area_struct *, unsigned long) {}
  609. static inline void vma_iter_free(struct vma_iterator *vmi)
  610. {
  611. mas_destroy(&vmi->mas);
  612. }
  613. static inline
  614. struct vm_area_struct *vma_iter_next_range(struct vma_iterator *vmi)
  615. {
  616. return mas_next_range(&vmi->mas, ULONG_MAX);
  617. }
  618. static inline void vm_acct_memory(long pages)
  619. {
  620. }
  621. static inline void vma_interval_tree_insert(struct vm_area_struct *,
  622. struct rb_root_cached *)
  623. {
  624. }
  625. static inline void vma_interval_tree_remove(struct vm_area_struct *,
  626. struct rb_root_cached *)
  627. {
  628. }
  629. static inline void flush_dcache_mmap_unlock(struct address_space *)
  630. {
  631. }
  632. static inline void anon_vma_interval_tree_insert(struct anon_vma_chain*,
  633. struct rb_root_cached *)
  634. {
  635. }
  636. static inline void anon_vma_interval_tree_remove(struct anon_vma_chain*,
  637. struct rb_root_cached *)
  638. {
  639. }
  640. static inline void uprobe_mmap(struct vm_area_struct *)
  641. {
  642. }
  643. static inline void uprobe_munmap(struct vm_area_struct *vma,
  644. unsigned long start, unsigned long end)
  645. {
  646. (void)vma;
  647. (void)start;
  648. (void)end;
  649. }
  650. static inline void i_mmap_lock_write(struct address_space *)
  651. {
  652. }
  653. static inline void anon_vma_lock_write(struct anon_vma *)
  654. {
  655. }
  656. static inline void vma_assert_write_locked(struct vm_area_struct *)
  657. {
  658. }
  659. static inline void unlink_anon_vmas(struct vm_area_struct *vma)
  660. {
  661. /* For testing purposes, indicate that the anon_vma was unlinked. */
  662. vma->anon_vma->was_unlinked = true;
  663. }
  664. static inline void anon_vma_unlock_write(struct anon_vma *)
  665. {
  666. }
  667. static inline void i_mmap_unlock_write(struct address_space *)
  668. {
  669. }
  670. static inline void anon_vma_merge(struct vm_area_struct *,
  671. struct vm_area_struct *)
  672. {
  673. }
  674. static inline int userfaultfd_unmap_prep(struct vm_area_struct *vma,
  675. unsigned long start,
  676. unsigned long end,
  677. struct list_head *unmaps)
  678. {
  679. (void)vma;
  680. (void)start;
  681. (void)end;
  682. (void)unmaps;
  683. return 0;
  684. }
  685. static inline void mmap_write_downgrade(struct mm_struct *)
  686. {
  687. }
  688. static inline void mmap_read_unlock(struct mm_struct *)
  689. {
  690. }
  691. static inline void mmap_write_unlock(struct mm_struct *)
  692. {
  693. }
  694. static inline bool can_modify_mm(struct mm_struct *mm,
  695. unsigned long start,
  696. unsigned long end)
  697. {
  698. (void)mm;
  699. (void)start;
  700. (void)end;
  701. return true;
  702. }
  703. static inline void arch_unmap(struct mm_struct *mm,
  704. unsigned long start,
  705. unsigned long end)
  706. {
  707. (void)mm;
  708. (void)start;
  709. (void)end;
  710. }
  711. static inline void mmap_assert_locked(struct mm_struct *)
  712. {
  713. }
  714. static inline bool mpol_equal(struct mempolicy *, struct mempolicy *)
  715. {
  716. return true;
  717. }
  718. static inline void khugepaged_enter_vma(struct vm_area_struct *vma,
  719. unsigned long vm_flags)
  720. {
  721. (void)vma;
  722. (void)vm_flags;
  723. }
  724. static inline bool mapping_can_writeback(struct address_space *)
  725. {
  726. return true;
  727. }
  728. static inline bool is_vm_hugetlb_page(struct vm_area_struct *)
  729. {
  730. return false;
  731. }
  732. static inline bool vma_soft_dirty_enabled(struct vm_area_struct *)
  733. {
  734. return false;
  735. }
  736. static inline bool userfaultfd_wp(struct vm_area_struct *)
  737. {
  738. return false;
  739. }
  740. static inline void mmap_assert_write_locked(struct mm_struct *)
  741. {
  742. }
  743. static inline void mutex_lock(struct mutex *)
  744. {
  745. }
  746. static inline void mutex_unlock(struct mutex *)
  747. {
  748. }
  749. static inline bool mutex_is_locked(struct mutex *)
  750. {
  751. return true;
  752. }
  753. static inline bool signal_pending(void *)
  754. {
  755. return false;
  756. }
  757. #endif /* __MM_VMA_INTERNAL_H */