1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2cddb8a5cSAndrea Arcangeli #ifndef _LINUX_MMU_NOTIFIER_H 3cddb8a5cSAndrea Arcangeli #define _LINUX_MMU_NOTIFIER_H 4cddb8a5cSAndrea Arcangeli 5cddb8a5cSAndrea Arcangeli #include <linux/list.h> 6cddb8a5cSAndrea Arcangeli #include <linux/spinlock.h> 7cddb8a5cSAndrea Arcangeli #include <linux/mm_types.h> 821a92735SSagi Grimberg #include <linux/srcu.h> 9*99cb252fSJason Gunthorpe #include <linux/interval_tree.h> 10cddb8a5cSAndrea Arcangeli 1156f434f4SJason Gunthorpe struct mmu_notifier_mm; 12cddb8a5cSAndrea Arcangeli struct mmu_notifier; 1356f434f4SJason Gunthorpe struct mmu_notifier_range; 14*99cb252fSJason Gunthorpe struct mmu_interval_notifier; 15cddb8a5cSAndrea Arcangeli 16d87f055bSJérôme Glisse /** 17d87f055bSJérôme Glisse * enum mmu_notifier_event - reason for the mmu notifier callback 18d87f055bSJérôme Glisse * @MMU_NOTIFY_UNMAP: either munmap() that unmap the range or a mremap() that 19d87f055bSJérôme Glisse * move the range 20d87f055bSJérôme Glisse * 21d87f055bSJérôme Glisse * @MMU_NOTIFY_CLEAR: clear page table entry (many reasons for this like 22d87f055bSJérôme Glisse * madvise() or replacing a page by another one, ...). 23d87f055bSJérôme Glisse * 24d87f055bSJérôme Glisse * @MMU_NOTIFY_PROTECTION_VMA: update is due to protection change for the range 25d87f055bSJérôme Glisse * ie using the vma access permission (vm_page_prot) to update the whole range 26d87f055bSJérôme Glisse * is enough no need to inspect changes to the CPU page table (mprotect() 27d87f055bSJérôme Glisse * syscall) 28d87f055bSJérôme Glisse * 29d87f055bSJérôme Glisse * @MMU_NOTIFY_PROTECTION_PAGE: update is due to change in read/write flag for 30d87f055bSJérôme Glisse * pages in the range so to mirror those changes the user must inspect the CPU 31d87f055bSJérôme Glisse * page table (from the end callback). 32d87f055bSJérôme Glisse * 33d87f055bSJérôme Glisse * @MMU_NOTIFY_SOFT_DIRTY: soft dirty accounting (still same page and same 34d87f055bSJérôme Glisse * access flags). User should soft dirty the page in the end callback to make 35d87f055bSJérôme Glisse * sure that anyone relying on soft dirtyness catch pages that might be written 36d87f055bSJérôme Glisse * through non CPU mappings. 37*99cb252fSJason Gunthorpe * 38*99cb252fSJason Gunthorpe * @MMU_NOTIFY_RELEASE: used during mmu_interval_notifier invalidate to signal 39*99cb252fSJason Gunthorpe * that the mm refcount is zero and the range is no longer accessible. 40d87f055bSJérôme Glisse */ 41d87f055bSJérôme Glisse enum mmu_notifier_event { 42d87f055bSJérôme Glisse MMU_NOTIFY_UNMAP = 0, 43d87f055bSJérôme Glisse MMU_NOTIFY_CLEAR, 44d87f055bSJérôme Glisse MMU_NOTIFY_PROTECTION_VMA, 45d87f055bSJérôme Glisse MMU_NOTIFY_PROTECTION_PAGE, 46d87f055bSJérôme Glisse MMU_NOTIFY_SOFT_DIRTY, 47*99cb252fSJason Gunthorpe MMU_NOTIFY_RELEASE, 48d87f055bSJérôme Glisse }; 49d87f055bSJérôme Glisse 5027560ee9SJérôme Glisse #define MMU_NOTIFIER_RANGE_BLOCKABLE (1 << 0) 5127560ee9SJérôme Glisse 52cddb8a5cSAndrea Arcangeli struct mmu_notifier_ops { 53cddb8a5cSAndrea Arcangeli /* 54cddb8a5cSAndrea Arcangeli * Called either by mmu_notifier_unregister or when the mm is 55cddb8a5cSAndrea Arcangeli * being destroyed by exit_mmap, always before all pages are 56cddb8a5cSAndrea Arcangeli * freed. This can run concurrently with other mmu notifier 57cddb8a5cSAndrea Arcangeli * methods (the ones invoked outside the mm context) and it 58cddb8a5cSAndrea Arcangeli * should tear down all secondary mmu mappings and freeze the 59cddb8a5cSAndrea Arcangeli * secondary mmu. If this method isn't implemented you've to 60cddb8a5cSAndrea Arcangeli * be sure that nothing could possibly write to the pages 61cddb8a5cSAndrea Arcangeli * through the secondary mmu by the time the last thread with 62cddb8a5cSAndrea Arcangeli * tsk->mm == mm exits. 63cddb8a5cSAndrea Arcangeli * 64cddb8a5cSAndrea Arcangeli * As side note: the pages freed after ->release returns could 65cddb8a5cSAndrea Arcangeli * be immediately reallocated by the gart at an alias physical 66cddb8a5cSAndrea Arcangeli * address with a different cache model, so if ->release isn't 67cddb8a5cSAndrea Arcangeli * implemented because all _software_ driven memory accesses 68cddb8a5cSAndrea Arcangeli * through the secondary mmu are terminated by the time the 69cddb8a5cSAndrea Arcangeli * last thread of this mm quits, you've also to be sure that 70cddb8a5cSAndrea Arcangeli * speculative _hardware_ operations can't allocate dirty 71cddb8a5cSAndrea Arcangeli * cachelines in the cpu that could not be snooped and made 72cddb8a5cSAndrea Arcangeli * coherent with the other read and write operations happening 73cddb8a5cSAndrea Arcangeli * through the gart alias address, so leading to memory 74cddb8a5cSAndrea Arcangeli * corruption. 75cddb8a5cSAndrea Arcangeli */ 76cddb8a5cSAndrea Arcangeli void (*release)(struct mmu_notifier *mn, 77cddb8a5cSAndrea Arcangeli struct mm_struct *mm); 78cddb8a5cSAndrea Arcangeli 79cddb8a5cSAndrea Arcangeli /* 80cddb8a5cSAndrea Arcangeli * clear_flush_young is called after the VM is 81cddb8a5cSAndrea Arcangeli * test-and-clearing the young/accessed bitflag in the 82cddb8a5cSAndrea Arcangeli * pte. This way the VM will provide proper aging to the 83cddb8a5cSAndrea Arcangeli * accesses to the page through the secondary MMUs and not 84cddb8a5cSAndrea Arcangeli * only to the ones through the Linux pte. 8557128468SAndres Lagar-Cavilla * Start-end is necessary in case the secondary MMU is mapping the page 8657128468SAndres Lagar-Cavilla * at a smaller granularity than the primary MMU. 87cddb8a5cSAndrea Arcangeli */ 88cddb8a5cSAndrea Arcangeli int (*clear_flush_young)(struct mmu_notifier *mn, 89cddb8a5cSAndrea Arcangeli struct mm_struct *mm, 9057128468SAndres Lagar-Cavilla unsigned long start, 9157128468SAndres Lagar-Cavilla unsigned long end); 92cddb8a5cSAndrea Arcangeli 93cddb8a5cSAndrea Arcangeli /* 941d7715c6SVladimir Davydov * clear_young is a lightweight version of clear_flush_young. Like the 951d7715c6SVladimir Davydov * latter, it is supposed to test-and-clear the young/accessed bitflag 961d7715c6SVladimir Davydov * in the secondary pte, but it may omit flushing the secondary tlb. 971d7715c6SVladimir Davydov */ 981d7715c6SVladimir Davydov int (*clear_young)(struct mmu_notifier *mn, 991d7715c6SVladimir Davydov struct mm_struct *mm, 1001d7715c6SVladimir Davydov unsigned long start, 1011d7715c6SVladimir Davydov unsigned long end); 1021d7715c6SVladimir Davydov 1031d7715c6SVladimir Davydov /* 1048ee53820SAndrea Arcangeli * test_young is called to check the young/accessed bitflag in 1058ee53820SAndrea Arcangeli * the secondary pte. This is used to know if the page is 1068ee53820SAndrea Arcangeli * frequently used without actually clearing the flag or tearing 1078ee53820SAndrea Arcangeli * down the secondary mapping on the page. 1088ee53820SAndrea Arcangeli */ 1098ee53820SAndrea Arcangeli int (*test_young)(struct mmu_notifier *mn, 1108ee53820SAndrea Arcangeli struct mm_struct *mm, 1118ee53820SAndrea Arcangeli unsigned long address); 1128ee53820SAndrea Arcangeli 1138ee53820SAndrea Arcangeli /* 114828502d3SIzik Eidus * change_pte is called in cases that pte mapping to page is changed: 115828502d3SIzik Eidus * for example, when ksm remaps pte to point to a new shared page. 116828502d3SIzik Eidus */ 117828502d3SIzik Eidus void (*change_pte)(struct mmu_notifier *mn, 118828502d3SIzik Eidus struct mm_struct *mm, 119828502d3SIzik Eidus unsigned long address, 120828502d3SIzik Eidus pte_t pte); 121828502d3SIzik Eidus 122828502d3SIzik Eidus /* 123cddb8a5cSAndrea Arcangeli * invalidate_range_start() and invalidate_range_end() must be 124cddb8a5cSAndrea Arcangeli * paired and are called only when the mmap_sem and/or the 1250f0a327fSJoerg Roedel * locks protecting the reverse maps are held. If the subsystem 1260f0a327fSJoerg Roedel * can't guarantee that no additional references are taken to 1270f0a327fSJoerg Roedel * the pages in the range, it has to implement the 1280f0a327fSJoerg Roedel * invalidate_range() notifier to remove any references taken 1290f0a327fSJoerg Roedel * after invalidate_range_start(). 130cddb8a5cSAndrea Arcangeli * 131cddb8a5cSAndrea Arcangeli * Invalidation of multiple concurrent ranges may be 132cddb8a5cSAndrea Arcangeli * optionally permitted by the driver. Either way the 133cddb8a5cSAndrea Arcangeli * establishment of sptes is forbidden in the range passed to 134cddb8a5cSAndrea Arcangeli * invalidate_range_begin/end for the whole duration of the 135cddb8a5cSAndrea Arcangeli * invalidate_range_begin/end critical section. 136cddb8a5cSAndrea Arcangeli * 137cddb8a5cSAndrea Arcangeli * invalidate_range_start() is called when all pages in the 138cddb8a5cSAndrea Arcangeli * range are still mapped and have at least a refcount of one. 139cddb8a5cSAndrea Arcangeli * 140cddb8a5cSAndrea Arcangeli * invalidate_range_end() is called when all pages in the 141cddb8a5cSAndrea Arcangeli * range have been unmapped and the pages have been freed by 142cddb8a5cSAndrea Arcangeli * the VM. 143cddb8a5cSAndrea Arcangeli * 144cddb8a5cSAndrea Arcangeli * The VM will remove the page table entries and potentially 145cddb8a5cSAndrea Arcangeli * the page between invalidate_range_start() and 146cddb8a5cSAndrea Arcangeli * invalidate_range_end(). If the page must not be freed 147cddb8a5cSAndrea Arcangeli * because of pending I/O or other circumstances then the 148cddb8a5cSAndrea Arcangeli * invalidate_range_start() callback (or the initial mapping 149cddb8a5cSAndrea Arcangeli * by the driver) must make sure that the refcount is kept 150cddb8a5cSAndrea Arcangeli * elevated. 151cddb8a5cSAndrea Arcangeli * 152cddb8a5cSAndrea Arcangeli * If the driver increases the refcount when the pages are 153cddb8a5cSAndrea Arcangeli * initially mapped into an address space then either 154cddb8a5cSAndrea Arcangeli * invalidate_range_start() or invalidate_range_end() may 155cddb8a5cSAndrea Arcangeli * decrease the refcount. If the refcount is decreased on 156cddb8a5cSAndrea Arcangeli * invalidate_range_start() then the VM can free pages as page 157cddb8a5cSAndrea Arcangeli * table entries are removed. If the refcount is only 158cddb8a5cSAndrea Arcangeli * droppped on invalidate_range_end() then the driver itself 159cddb8a5cSAndrea Arcangeli * will drop the last refcount but it must take care to flush 160cddb8a5cSAndrea Arcangeli * any secondary tlb before doing the final free on the 161cddb8a5cSAndrea Arcangeli * page. Pages will no longer be referenced by the linux 162cddb8a5cSAndrea Arcangeli * address space but may still be referenced by sptes until 163cddb8a5cSAndrea Arcangeli * the last refcount is dropped. 1645ff7091fSDavid Rientjes * 16593065ac7SMichal Hocko * If blockable argument is set to false then the callback cannot 16693065ac7SMichal Hocko * sleep and has to return with -EAGAIN. 0 should be returned 16733490af3SMichal Hocko * otherwise. Please note that if invalidate_range_start approves 16833490af3SMichal Hocko * a non-blocking behavior then the same applies to 16933490af3SMichal Hocko * invalidate_range_end. 17093065ac7SMichal Hocko * 171cddb8a5cSAndrea Arcangeli */ 17293065ac7SMichal Hocko int (*invalidate_range_start)(struct mmu_notifier *mn, 1735d6527a7SJérôme Glisse const struct mmu_notifier_range *range); 174cddb8a5cSAndrea Arcangeli void (*invalidate_range_end)(struct mmu_notifier *mn, 1755d6527a7SJérôme Glisse const struct mmu_notifier_range *range); 1760f0a327fSJoerg Roedel 1770f0a327fSJoerg Roedel /* 1780f0a327fSJoerg Roedel * invalidate_range() is either called between 1790f0a327fSJoerg Roedel * invalidate_range_start() and invalidate_range_end() when the 1800f0a327fSJoerg Roedel * VM has to free pages that where unmapped, but before the 1810f0a327fSJoerg Roedel * pages are actually freed, or outside of _start()/_end() when 1820f0a327fSJoerg Roedel * a (remote) TLB is necessary. 1830f0a327fSJoerg Roedel * 1840f0a327fSJoerg Roedel * If invalidate_range() is used to manage a non-CPU TLB with 1850f0a327fSJoerg Roedel * shared page-tables, it not necessary to implement the 1860f0a327fSJoerg Roedel * invalidate_range_start()/end() notifiers, as 1870f0a327fSJoerg Roedel * invalidate_range() alread catches the points in time when an 1880f10851eSJérôme Glisse * external TLB range needs to be flushed. For more in depth 189ad56b738SMike Rapoport * discussion on this see Documentation/vm/mmu_notifier.rst 1900f0a327fSJoerg Roedel * 1910f0a327fSJoerg Roedel * Note that this function might be called with just a sub-range 1920f0a327fSJoerg Roedel * of what was passed to invalidate_range_start()/end(), if 1930f0a327fSJoerg Roedel * called between those functions. 1940f0a327fSJoerg Roedel */ 1950f0a327fSJoerg Roedel void (*invalidate_range)(struct mmu_notifier *mn, struct mm_struct *mm, 1960f0a327fSJoerg Roedel unsigned long start, unsigned long end); 1972c7933f5SJason Gunthorpe 1982c7933f5SJason Gunthorpe /* 1992c7933f5SJason Gunthorpe * These callbacks are used with the get/put interface to manage the 2002c7933f5SJason Gunthorpe * lifetime of the mmu_notifier memory. alloc_notifier() returns a new 2012c7933f5SJason Gunthorpe * notifier for use with the mm. 2022c7933f5SJason Gunthorpe * 2032c7933f5SJason Gunthorpe * free_notifier() is only called after the mmu_notifier has been 2042c7933f5SJason Gunthorpe * fully put, calls to any ops callback are prevented and no ops 2052c7933f5SJason Gunthorpe * callbacks are currently running. It is called from a SRCU callback 2062c7933f5SJason Gunthorpe * and cannot sleep. 2072c7933f5SJason Gunthorpe */ 2082c7933f5SJason Gunthorpe struct mmu_notifier *(*alloc_notifier)(struct mm_struct *mm); 2092c7933f5SJason Gunthorpe void (*free_notifier)(struct mmu_notifier *mn); 210cddb8a5cSAndrea Arcangeli }; 211cddb8a5cSAndrea Arcangeli 212cddb8a5cSAndrea Arcangeli /* 213cddb8a5cSAndrea Arcangeli * The notifier chains are protected by mmap_sem and/or the reverse map 214cddb8a5cSAndrea Arcangeli * semaphores. Notifier chains are only changed when all reverse maps and 215cddb8a5cSAndrea Arcangeli * the mmap_sem locks are taken. 216cddb8a5cSAndrea Arcangeli * 217cddb8a5cSAndrea Arcangeli * Therefore notifier chains can only be traversed when either 218cddb8a5cSAndrea Arcangeli * 219cddb8a5cSAndrea Arcangeli * 1. mmap_sem is held. 220c8c06efaSDavidlohr Bueso * 2. One of the reverse map locks is held (i_mmap_rwsem or anon_vma->rwsem). 221cddb8a5cSAndrea Arcangeli * 3. No other concurrent thread can access the list (release) 222cddb8a5cSAndrea Arcangeli */ 223cddb8a5cSAndrea Arcangeli struct mmu_notifier { 224cddb8a5cSAndrea Arcangeli struct hlist_node hlist; 225cddb8a5cSAndrea Arcangeli const struct mmu_notifier_ops *ops; 2262c7933f5SJason Gunthorpe struct mm_struct *mm; 2272c7933f5SJason Gunthorpe struct rcu_head rcu; 2282c7933f5SJason Gunthorpe unsigned int users; 229cddb8a5cSAndrea Arcangeli }; 230cddb8a5cSAndrea Arcangeli 231*99cb252fSJason Gunthorpe /** 232*99cb252fSJason Gunthorpe * struct mmu_interval_notifier_ops 233*99cb252fSJason Gunthorpe * @invalidate: Upon return the caller must stop using any SPTEs within this 234*99cb252fSJason Gunthorpe * range. This function can sleep. Return false only if sleeping 235*99cb252fSJason Gunthorpe * was required but mmu_notifier_range_blockable(range) is false. 236*99cb252fSJason Gunthorpe */ 237*99cb252fSJason Gunthorpe struct mmu_interval_notifier_ops { 238*99cb252fSJason Gunthorpe bool (*invalidate)(struct mmu_interval_notifier *mni, 239*99cb252fSJason Gunthorpe const struct mmu_notifier_range *range, 240*99cb252fSJason Gunthorpe unsigned long cur_seq); 241*99cb252fSJason Gunthorpe }; 242*99cb252fSJason Gunthorpe 243*99cb252fSJason Gunthorpe struct mmu_interval_notifier { 244*99cb252fSJason Gunthorpe struct interval_tree_node interval_tree; 245*99cb252fSJason Gunthorpe const struct mmu_interval_notifier_ops *ops; 246*99cb252fSJason Gunthorpe struct mm_struct *mm; 247*99cb252fSJason Gunthorpe struct hlist_node deferred_item; 248*99cb252fSJason Gunthorpe unsigned long invalidate_seq; 249*99cb252fSJason Gunthorpe }; 250*99cb252fSJason Gunthorpe 25156f434f4SJason Gunthorpe #ifdef CONFIG_MMU_NOTIFIER 25256f434f4SJason Gunthorpe 25356f434f4SJason Gunthorpe #ifdef CONFIG_LOCKDEP 25456f434f4SJason Gunthorpe extern struct lockdep_map __mmu_notifier_invalidate_range_start_map; 25556f434f4SJason Gunthorpe #endif 25656f434f4SJason Gunthorpe 25756f434f4SJason Gunthorpe struct mmu_notifier_range { 25856f434f4SJason Gunthorpe struct vm_area_struct *vma; 25956f434f4SJason Gunthorpe struct mm_struct *mm; 26056f434f4SJason Gunthorpe unsigned long start; 26156f434f4SJason Gunthorpe unsigned long end; 26256f434f4SJason Gunthorpe unsigned flags; 26356f434f4SJason Gunthorpe enum mmu_notifier_event event; 26456f434f4SJason Gunthorpe }; 26556f434f4SJason Gunthorpe 266cddb8a5cSAndrea Arcangeli static inline int mm_has_notifiers(struct mm_struct *mm) 267cddb8a5cSAndrea Arcangeli { 268cddb8a5cSAndrea Arcangeli return unlikely(mm->mmu_notifier_mm); 269cddb8a5cSAndrea Arcangeli } 270cddb8a5cSAndrea Arcangeli 2712c7933f5SJason Gunthorpe struct mmu_notifier *mmu_notifier_get_locked(const struct mmu_notifier_ops *ops, 2722c7933f5SJason Gunthorpe struct mm_struct *mm); 2732c7933f5SJason Gunthorpe static inline struct mmu_notifier * 2742c7933f5SJason Gunthorpe mmu_notifier_get(const struct mmu_notifier_ops *ops, struct mm_struct *mm) 2752c7933f5SJason Gunthorpe { 2762c7933f5SJason Gunthorpe struct mmu_notifier *ret; 2772c7933f5SJason Gunthorpe 2782c7933f5SJason Gunthorpe down_write(&mm->mmap_sem); 2792c7933f5SJason Gunthorpe ret = mmu_notifier_get_locked(ops, mm); 2802c7933f5SJason Gunthorpe up_write(&mm->mmap_sem); 2812c7933f5SJason Gunthorpe return ret; 2822c7933f5SJason Gunthorpe } 2832c7933f5SJason Gunthorpe void mmu_notifier_put(struct mmu_notifier *mn); 2842c7933f5SJason Gunthorpe void mmu_notifier_synchronize(void); 2852c7933f5SJason Gunthorpe 286cddb8a5cSAndrea Arcangeli extern int mmu_notifier_register(struct mmu_notifier *mn, 287cddb8a5cSAndrea Arcangeli struct mm_struct *mm); 288cddb8a5cSAndrea Arcangeli extern int __mmu_notifier_register(struct mmu_notifier *mn, 289cddb8a5cSAndrea Arcangeli struct mm_struct *mm); 290cddb8a5cSAndrea Arcangeli extern void mmu_notifier_unregister(struct mmu_notifier *mn, 291cddb8a5cSAndrea Arcangeli struct mm_struct *mm); 292*99cb252fSJason Gunthorpe 293*99cb252fSJason Gunthorpe unsigned long mmu_interval_read_begin(struct mmu_interval_notifier *mni); 294*99cb252fSJason Gunthorpe int mmu_interval_notifier_insert(struct mmu_interval_notifier *mni, 295*99cb252fSJason Gunthorpe struct mm_struct *mm, unsigned long start, 296*99cb252fSJason Gunthorpe unsigned long length, 297*99cb252fSJason Gunthorpe const struct mmu_interval_notifier_ops *ops); 298*99cb252fSJason Gunthorpe int mmu_interval_notifier_insert_locked( 299*99cb252fSJason Gunthorpe struct mmu_interval_notifier *mni, struct mm_struct *mm, 300*99cb252fSJason Gunthorpe unsigned long start, unsigned long length, 301*99cb252fSJason Gunthorpe const struct mmu_interval_notifier_ops *ops); 302*99cb252fSJason Gunthorpe void mmu_interval_notifier_remove(struct mmu_interval_notifier *mni); 303*99cb252fSJason Gunthorpe 304*99cb252fSJason Gunthorpe /** 305*99cb252fSJason Gunthorpe * mmu_interval_set_seq - Save the invalidation sequence 306*99cb252fSJason Gunthorpe * @mni - The mni passed to invalidate 307*99cb252fSJason Gunthorpe * @cur_seq - The cur_seq passed to the invalidate() callback 308*99cb252fSJason Gunthorpe * 309*99cb252fSJason Gunthorpe * This must be called unconditionally from the invalidate callback of a 310*99cb252fSJason Gunthorpe * struct mmu_interval_notifier_ops under the same lock that is used to call 311*99cb252fSJason Gunthorpe * mmu_interval_read_retry(). It updates the sequence number for later use by 312*99cb252fSJason Gunthorpe * mmu_interval_read_retry(). The provided cur_seq will always be odd. 313*99cb252fSJason Gunthorpe * 314*99cb252fSJason Gunthorpe * If the caller does not call mmu_interval_read_begin() or 315*99cb252fSJason Gunthorpe * mmu_interval_read_retry() then this call is not required. 316*99cb252fSJason Gunthorpe */ 317*99cb252fSJason Gunthorpe static inline void mmu_interval_set_seq(struct mmu_interval_notifier *mni, 318*99cb252fSJason Gunthorpe unsigned long cur_seq) 319*99cb252fSJason Gunthorpe { 320*99cb252fSJason Gunthorpe WRITE_ONCE(mni->invalidate_seq, cur_seq); 321*99cb252fSJason Gunthorpe } 322*99cb252fSJason Gunthorpe 323*99cb252fSJason Gunthorpe /** 324*99cb252fSJason Gunthorpe * mmu_interval_read_retry - End a read side critical section against a VA range 325*99cb252fSJason Gunthorpe * mni: The range 326*99cb252fSJason Gunthorpe * seq: The return of the paired mmu_interval_read_begin() 327*99cb252fSJason Gunthorpe * 328*99cb252fSJason Gunthorpe * This MUST be called under a user provided lock that is also held 329*99cb252fSJason Gunthorpe * unconditionally by op->invalidate() when it calls mmu_interval_set_seq(). 330*99cb252fSJason Gunthorpe * 331*99cb252fSJason Gunthorpe * Each call should be paired with a single mmu_interval_read_begin() and 332*99cb252fSJason Gunthorpe * should be used to conclude the read side. 333*99cb252fSJason Gunthorpe * 334*99cb252fSJason Gunthorpe * Returns true if an invalidation collided with this critical section, and 335*99cb252fSJason Gunthorpe * the caller should retry. 336*99cb252fSJason Gunthorpe */ 337*99cb252fSJason Gunthorpe static inline bool mmu_interval_read_retry(struct mmu_interval_notifier *mni, 338*99cb252fSJason Gunthorpe unsigned long seq) 339*99cb252fSJason Gunthorpe { 340*99cb252fSJason Gunthorpe return mni->invalidate_seq != seq; 341*99cb252fSJason Gunthorpe } 342*99cb252fSJason Gunthorpe 343*99cb252fSJason Gunthorpe /** 344*99cb252fSJason Gunthorpe * mmu_interval_check_retry - Test if a collision has occurred 345*99cb252fSJason Gunthorpe * mni: The range 346*99cb252fSJason Gunthorpe * seq: The return of the matching mmu_interval_read_begin() 347*99cb252fSJason Gunthorpe * 348*99cb252fSJason Gunthorpe * This can be used in the critical section between mmu_interval_read_begin() 349*99cb252fSJason Gunthorpe * and mmu_interval_read_retry(). A return of true indicates an invalidation 350*99cb252fSJason Gunthorpe * has collided with this critical region and a future 351*99cb252fSJason Gunthorpe * mmu_interval_read_retry() will return true. 352*99cb252fSJason Gunthorpe * 353*99cb252fSJason Gunthorpe * False is not reliable and only suggests a collision may not have 354*99cb252fSJason Gunthorpe * occured. It can be called many times and does not have to hold the user 355*99cb252fSJason Gunthorpe * provided lock. 356*99cb252fSJason Gunthorpe * 357*99cb252fSJason Gunthorpe * This call can be used as part of loops and other expensive operations to 358*99cb252fSJason Gunthorpe * expedite a retry. 359*99cb252fSJason Gunthorpe */ 360*99cb252fSJason Gunthorpe static inline bool mmu_interval_check_retry(struct mmu_interval_notifier *mni, 361*99cb252fSJason Gunthorpe unsigned long seq) 362*99cb252fSJason Gunthorpe { 363*99cb252fSJason Gunthorpe /* Pairs with the WRITE_ONCE in mmu_interval_set_seq() */ 364*99cb252fSJason Gunthorpe return READ_ONCE(mni->invalidate_seq) != seq; 365*99cb252fSJason Gunthorpe } 366*99cb252fSJason Gunthorpe 367cddb8a5cSAndrea Arcangeli extern void __mmu_notifier_mm_destroy(struct mm_struct *mm); 368cddb8a5cSAndrea Arcangeli extern void __mmu_notifier_release(struct mm_struct *mm); 369cddb8a5cSAndrea Arcangeli extern int __mmu_notifier_clear_flush_young(struct mm_struct *mm, 37057128468SAndres Lagar-Cavilla unsigned long start, 37157128468SAndres Lagar-Cavilla unsigned long end); 3721d7715c6SVladimir Davydov extern int __mmu_notifier_clear_young(struct mm_struct *mm, 3731d7715c6SVladimir Davydov unsigned long start, 3741d7715c6SVladimir Davydov unsigned long end); 3758ee53820SAndrea Arcangeli extern int __mmu_notifier_test_young(struct mm_struct *mm, 3768ee53820SAndrea Arcangeli unsigned long address); 377828502d3SIzik Eidus extern void __mmu_notifier_change_pte(struct mm_struct *mm, 378828502d3SIzik Eidus unsigned long address, pte_t pte); 379ac46d4f3SJérôme Glisse extern int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *r); 380ac46d4f3SJérôme Glisse extern void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *r, 3814645b9feSJérôme Glisse bool only_end); 3820f0a327fSJoerg Roedel extern void __mmu_notifier_invalidate_range(struct mm_struct *mm, 3830f0a327fSJoerg Roedel unsigned long start, unsigned long end); 384c6d23413SJérôme Glisse extern bool 385c6d23413SJérôme Glisse mmu_notifier_range_update_to_read_only(const struct mmu_notifier_range *range); 386cddb8a5cSAndrea Arcangeli 3874a83bfe9SJérôme Glisse static inline bool 3884a83bfe9SJérôme Glisse mmu_notifier_range_blockable(const struct mmu_notifier_range *range) 3894a83bfe9SJérôme Glisse { 39027560ee9SJérôme Glisse return (range->flags & MMU_NOTIFIER_RANGE_BLOCKABLE); 3914a83bfe9SJérôme Glisse } 3924a83bfe9SJérôme Glisse 393cddb8a5cSAndrea Arcangeli static inline void mmu_notifier_release(struct mm_struct *mm) 394cddb8a5cSAndrea Arcangeli { 395cddb8a5cSAndrea Arcangeli if (mm_has_notifiers(mm)) 396cddb8a5cSAndrea Arcangeli __mmu_notifier_release(mm); 397cddb8a5cSAndrea Arcangeli } 398cddb8a5cSAndrea Arcangeli 399cddb8a5cSAndrea Arcangeli static inline int mmu_notifier_clear_flush_young(struct mm_struct *mm, 40057128468SAndres Lagar-Cavilla unsigned long start, 40157128468SAndres Lagar-Cavilla unsigned long end) 402cddb8a5cSAndrea Arcangeli { 403cddb8a5cSAndrea Arcangeli if (mm_has_notifiers(mm)) 40457128468SAndres Lagar-Cavilla return __mmu_notifier_clear_flush_young(mm, start, end); 405cddb8a5cSAndrea Arcangeli return 0; 406cddb8a5cSAndrea Arcangeli } 407cddb8a5cSAndrea Arcangeli 4081d7715c6SVladimir Davydov static inline int mmu_notifier_clear_young(struct mm_struct *mm, 4091d7715c6SVladimir Davydov unsigned long start, 4101d7715c6SVladimir Davydov unsigned long end) 4111d7715c6SVladimir Davydov { 4121d7715c6SVladimir Davydov if (mm_has_notifiers(mm)) 4131d7715c6SVladimir Davydov return __mmu_notifier_clear_young(mm, start, end); 4141d7715c6SVladimir Davydov return 0; 4151d7715c6SVladimir Davydov } 4161d7715c6SVladimir Davydov 4178ee53820SAndrea Arcangeli static inline int mmu_notifier_test_young(struct mm_struct *mm, 4188ee53820SAndrea Arcangeli unsigned long address) 4198ee53820SAndrea Arcangeli { 4208ee53820SAndrea Arcangeli if (mm_has_notifiers(mm)) 4218ee53820SAndrea Arcangeli return __mmu_notifier_test_young(mm, address); 4228ee53820SAndrea Arcangeli return 0; 4238ee53820SAndrea Arcangeli } 4248ee53820SAndrea Arcangeli 425828502d3SIzik Eidus static inline void mmu_notifier_change_pte(struct mm_struct *mm, 426828502d3SIzik Eidus unsigned long address, pte_t pte) 427828502d3SIzik Eidus { 428828502d3SIzik Eidus if (mm_has_notifiers(mm)) 429828502d3SIzik Eidus __mmu_notifier_change_pte(mm, address, pte); 430828502d3SIzik Eidus } 431828502d3SIzik Eidus 432ac46d4f3SJérôme Glisse static inline void 433ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) 434cddb8a5cSAndrea Arcangeli { 435810e24e0SDaniel Vetter might_sleep(); 436810e24e0SDaniel Vetter 43723b68395SDaniel Vetter lock_map_acquire(&__mmu_notifier_invalidate_range_start_map); 438ac46d4f3SJérôme Glisse if (mm_has_notifiers(range->mm)) { 43927560ee9SJérôme Glisse range->flags |= MMU_NOTIFIER_RANGE_BLOCKABLE; 440ac46d4f3SJérôme Glisse __mmu_notifier_invalidate_range_start(range); 441ac46d4f3SJérôme Glisse } 44223b68395SDaniel Vetter lock_map_release(&__mmu_notifier_invalidate_range_start_map); 44393065ac7SMichal Hocko } 44493065ac7SMichal Hocko 445ac46d4f3SJérôme Glisse static inline int 446ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_start_nonblock(struct mmu_notifier_range *range) 44793065ac7SMichal Hocko { 44823b68395SDaniel Vetter int ret = 0; 44923b68395SDaniel Vetter 45023b68395SDaniel Vetter lock_map_acquire(&__mmu_notifier_invalidate_range_start_map); 451ac46d4f3SJérôme Glisse if (mm_has_notifiers(range->mm)) { 45227560ee9SJérôme Glisse range->flags &= ~MMU_NOTIFIER_RANGE_BLOCKABLE; 45323b68395SDaniel Vetter ret = __mmu_notifier_invalidate_range_start(range); 454ac46d4f3SJérôme Glisse } 45523b68395SDaniel Vetter lock_map_release(&__mmu_notifier_invalidate_range_start_map); 45623b68395SDaniel Vetter return ret; 457cddb8a5cSAndrea Arcangeli } 458cddb8a5cSAndrea Arcangeli 459ac46d4f3SJérôme Glisse static inline void 460ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range) 461cddb8a5cSAndrea Arcangeli { 462810e24e0SDaniel Vetter if (mmu_notifier_range_blockable(range)) 463810e24e0SDaniel Vetter might_sleep(); 464810e24e0SDaniel Vetter 465ac46d4f3SJérôme Glisse if (mm_has_notifiers(range->mm)) 466ac46d4f3SJérôme Glisse __mmu_notifier_invalidate_range_end(range, false); 4674645b9feSJérôme Glisse } 4684645b9feSJérôme Glisse 469ac46d4f3SJérôme Glisse static inline void 470ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_only_end(struct mmu_notifier_range *range) 4714645b9feSJérôme Glisse { 472ac46d4f3SJérôme Glisse if (mm_has_notifiers(range->mm)) 473ac46d4f3SJérôme Glisse __mmu_notifier_invalidate_range_end(range, true); 474cddb8a5cSAndrea Arcangeli } 475cddb8a5cSAndrea Arcangeli 4761897bdc4SJoerg Roedel static inline void mmu_notifier_invalidate_range(struct mm_struct *mm, 4771897bdc4SJoerg Roedel unsigned long start, unsigned long end) 4781897bdc4SJoerg Roedel { 4790f0a327fSJoerg Roedel if (mm_has_notifiers(mm)) 4800f0a327fSJoerg Roedel __mmu_notifier_invalidate_range(mm, start, end); 4811897bdc4SJoerg Roedel } 4821897bdc4SJoerg Roedel 483cddb8a5cSAndrea Arcangeli static inline void mmu_notifier_mm_init(struct mm_struct *mm) 484cddb8a5cSAndrea Arcangeli { 485cddb8a5cSAndrea Arcangeli mm->mmu_notifier_mm = NULL; 486cddb8a5cSAndrea Arcangeli } 487cddb8a5cSAndrea Arcangeli 488cddb8a5cSAndrea Arcangeli static inline void mmu_notifier_mm_destroy(struct mm_struct *mm) 489cddb8a5cSAndrea Arcangeli { 490cddb8a5cSAndrea Arcangeli if (mm_has_notifiers(mm)) 491cddb8a5cSAndrea Arcangeli __mmu_notifier_mm_destroy(mm); 492cddb8a5cSAndrea Arcangeli } 493cddb8a5cSAndrea Arcangeli 494ac46d4f3SJérôme Glisse 495ac46d4f3SJérôme Glisse static inline void mmu_notifier_range_init(struct mmu_notifier_range *range, 4966f4f13e8SJérôme Glisse enum mmu_notifier_event event, 4976f4f13e8SJérôme Glisse unsigned flags, 4986f4f13e8SJérôme Glisse struct vm_area_struct *vma, 499ac46d4f3SJérôme Glisse struct mm_struct *mm, 500ac46d4f3SJérôme Glisse unsigned long start, 501ac46d4f3SJérôme Glisse unsigned long end) 502ac46d4f3SJérôme Glisse { 503bf198b2bSJérôme Glisse range->vma = vma; 504bf198b2bSJérôme Glisse range->event = event; 505ac46d4f3SJérôme Glisse range->mm = mm; 506ac46d4f3SJérôme Glisse range->start = start; 507ac46d4f3SJérôme Glisse range->end = end; 508bf198b2bSJérôme Glisse range->flags = flags; 509ac46d4f3SJérôme Glisse } 510ac46d4f3SJérôme Glisse 511cddb8a5cSAndrea Arcangeli #define ptep_clear_flush_young_notify(__vma, __address, __ptep) \ 512cddb8a5cSAndrea Arcangeli ({ \ 513cddb8a5cSAndrea Arcangeli int __young; \ 514cddb8a5cSAndrea Arcangeli struct vm_area_struct *___vma = __vma; \ 515cddb8a5cSAndrea Arcangeli unsigned long ___address = __address; \ 516cddb8a5cSAndrea Arcangeli __young = ptep_clear_flush_young(___vma, ___address, __ptep); \ 517cddb8a5cSAndrea Arcangeli __young |= mmu_notifier_clear_flush_young(___vma->vm_mm, \ 51857128468SAndres Lagar-Cavilla ___address, \ 51957128468SAndres Lagar-Cavilla ___address + \ 52057128468SAndres Lagar-Cavilla PAGE_SIZE); \ 521cddb8a5cSAndrea Arcangeli __young; \ 522cddb8a5cSAndrea Arcangeli }) 523cddb8a5cSAndrea Arcangeli 52491a4ee26SAndrea Arcangeli #define pmdp_clear_flush_young_notify(__vma, __address, __pmdp) \ 52591a4ee26SAndrea Arcangeli ({ \ 52691a4ee26SAndrea Arcangeli int __young; \ 52791a4ee26SAndrea Arcangeli struct vm_area_struct *___vma = __vma; \ 52891a4ee26SAndrea Arcangeli unsigned long ___address = __address; \ 52991a4ee26SAndrea Arcangeli __young = pmdp_clear_flush_young(___vma, ___address, __pmdp); \ 53091a4ee26SAndrea Arcangeli __young |= mmu_notifier_clear_flush_young(___vma->vm_mm, \ 53157128468SAndres Lagar-Cavilla ___address, \ 53257128468SAndres Lagar-Cavilla ___address + \ 53357128468SAndres Lagar-Cavilla PMD_SIZE); \ 53491a4ee26SAndrea Arcangeli __young; \ 53591a4ee26SAndrea Arcangeli }) 53691a4ee26SAndrea Arcangeli 5371d7715c6SVladimir Davydov #define ptep_clear_young_notify(__vma, __address, __ptep) \ 5381d7715c6SVladimir Davydov ({ \ 5391d7715c6SVladimir Davydov int __young; \ 5401d7715c6SVladimir Davydov struct vm_area_struct *___vma = __vma; \ 5411d7715c6SVladimir Davydov unsigned long ___address = __address; \ 5421d7715c6SVladimir Davydov __young = ptep_test_and_clear_young(___vma, ___address, __ptep);\ 5431d7715c6SVladimir Davydov __young |= mmu_notifier_clear_young(___vma->vm_mm, ___address, \ 5441d7715c6SVladimir Davydov ___address + PAGE_SIZE); \ 5451d7715c6SVladimir Davydov __young; \ 5461d7715c6SVladimir Davydov }) 5471d7715c6SVladimir Davydov 5481d7715c6SVladimir Davydov #define pmdp_clear_young_notify(__vma, __address, __pmdp) \ 5491d7715c6SVladimir Davydov ({ \ 5501d7715c6SVladimir Davydov int __young; \ 5511d7715c6SVladimir Davydov struct vm_area_struct *___vma = __vma; \ 5521d7715c6SVladimir Davydov unsigned long ___address = __address; \ 5531d7715c6SVladimir Davydov __young = pmdp_test_and_clear_young(___vma, ___address, __pmdp);\ 5541d7715c6SVladimir Davydov __young |= mmu_notifier_clear_young(___vma->vm_mm, ___address, \ 5551d7715c6SVladimir Davydov ___address + PMD_SIZE); \ 5561d7715c6SVladimir Davydov __young; \ 5571d7715c6SVladimir Davydov }) 5581d7715c6SVladimir Davydov 55934ee645eSJoerg Roedel #define ptep_clear_flush_notify(__vma, __address, __ptep) \ 56034ee645eSJoerg Roedel ({ \ 56134ee645eSJoerg Roedel unsigned long ___addr = __address & PAGE_MASK; \ 56234ee645eSJoerg Roedel struct mm_struct *___mm = (__vma)->vm_mm; \ 56334ee645eSJoerg Roedel pte_t ___pte; \ 56434ee645eSJoerg Roedel \ 56534ee645eSJoerg Roedel ___pte = ptep_clear_flush(__vma, __address, __ptep); \ 56634ee645eSJoerg Roedel mmu_notifier_invalidate_range(___mm, ___addr, \ 56734ee645eSJoerg Roedel ___addr + PAGE_SIZE); \ 56834ee645eSJoerg Roedel \ 56934ee645eSJoerg Roedel ___pte; \ 57034ee645eSJoerg Roedel }) 57134ee645eSJoerg Roedel 5728809aa2dSAneesh Kumar K.V #define pmdp_huge_clear_flush_notify(__vma, __haddr, __pmd) \ 57334ee645eSJoerg Roedel ({ \ 57434ee645eSJoerg Roedel unsigned long ___haddr = __haddr & HPAGE_PMD_MASK; \ 57534ee645eSJoerg Roedel struct mm_struct *___mm = (__vma)->vm_mm; \ 57634ee645eSJoerg Roedel pmd_t ___pmd; \ 57734ee645eSJoerg Roedel \ 5788809aa2dSAneesh Kumar K.V ___pmd = pmdp_huge_clear_flush(__vma, __haddr, __pmd); \ 57934ee645eSJoerg Roedel mmu_notifier_invalidate_range(___mm, ___haddr, \ 58034ee645eSJoerg Roedel ___haddr + HPAGE_PMD_SIZE); \ 58134ee645eSJoerg Roedel \ 58234ee645eSJoerg Roedel ___pmd; \ 58334ee645eSJoerg Roedel }) 58434ee645eSJoerg Roedel 585a00cc7d9SMatthew Wilcox #define pudp_huge_clear_flush_notify(__vma, __haddr, __pud) \ 586a00cc7d9SMatthew Wilcox ({ \ 587a00cc7d9SMatthew Wilcox unsigned long ___haddr = __haddr & HPAGE_PUD_MASK; \ 588a00cc7d9SMatthew Wilcox struct mm_struct *___mm = (__vma)->vm_mm; \ 589a00cc7d9SMatthew Wilcox pud_t ___pud; \ 590a00cc7d9SMatthew Wilcox \ 591a00cc7d9SMatthew Wilcox ___pud = pudp_huge_clear_flush(__vma, __haddr, __pud); \ 592a00cc7d9SMatthew Wilcox mmu_notifier_invalidate_range(___mm, ___haddr, \ 593a00cc7d9SMatthew Wilcox ___haddr + HPAGE_PUD_SIZE); \ 594a00cc7d9SMatthew Wilcox \ 595a00cc7d9SMatthew Wilcox ___pud; \ 596a00cc7d9SMatthew Wilcox }) 597a00cc7d9SMatthew Wilcox 59848af0d7cSXiao Guangrong /* 59948af0d7cSXiao Guangrong * set_pte_at_notify() sets the pte _after_ running the notifier. 60048af0d7cSXiao Guangrong * This is safe to start by updating the secondary MMUs, because the primary MMU 60148af0d7cSXiao Guangrong * pte invalidate must have already happened with a ptep_clear_flush() before 60248af0d7cSXiao Guangrong * set_pte_at_notify() has been invoked. Updating the secondary MMUs first is 60348af0d7cSXiao Guangrong * required when we change both the protection of the mapping from read-only to 60448af0d7cSXiao Guangrong * read-write and the pfn (like during copy on write page faults). Otherwise the 60548af0d7cSXiao Guangrong * old page would remain mapped readonly in the secondary MMUs after the new 60648af0d7cSXiao Guangrong * page is already writable by some CPU through the primary MMU. 60748af0d7cSXiao Guangrong */ 608828502d3SIzik Eidus #define set_pte_at_notify(__mm, __address, __ptep, __pte) \ 609828502d3SIzik Eidus ({ \ 610828502d3SIzik Eidus struct mm_struct *___mm = __mm; \ 611828502d3SIzik Eidus unsigned long ___address = __address; \ 612828502d3SIzik Eidus pte_t ___pte = __pte; \ 613828502d3SIzik Eidus \ 614828502d3SIzik Eidus mmu_notifier_change_pte(___mm, ___address, ___pte); \ 61548af0d7cSXiao Guangrong set_pte_at(___mm, ___address, __ptep, ___pte); \ 616828502d3SIzik Eidus }) 617828502d3SIzik Eidus 618cddb8a5cSAndrea Arcangeli #else /* CONFIG_MMU_NOTIFIER */ 619cddb8a5cSAndrea Arcangeli 620ac46d4f3SJérôme Glisse struct mmu_notifier_range { 621ac46d4f3SJérôme Glisse unsigned long start; 622ac46d4f3SJérôme Glisse unsigned long end; 623ac46d4f3SJérôme Glisse }; 624ac46d4f3SJérôme Glisse 625ac46d4f3SJérôme Glisse static inline void _mmu_notifier_range_init(struct mmu_notifier_range *range, 626ac46d4f3SJérôme Glisse unsigned long start, 627ac46d4f3SJérôme Glisse unsigned long end) 628ac46d4f3SJérôme Glisse { 629ac46d4f3SJérôme Glisse range->start = start; 630ac46d4f3SJérôme Glisse range->end = end; 631ac46d4f3SJérôme Glisse } 632ac46d4f3SJérôme Glisse 6336f4f13e8SJérôme Glisse #define mmu_notifier_range_init(range,event,flags,vma,mm,start,end) \ 634ac46d4f3SJérôme Glisse _mmu_notifier_range_init(range, start, end) 635ac46d4f3SJérôme Glisse 6364a83bfe9SJérôme Glisse static inline bool 6374a83bfe9SJérôme Glisse mmu_notifier_range_blockable(const struct mmu_notifier_range *range) 6384a83bfe9SJérôme Glisse { 6394a83bfe9SJérôme Glisse return true; 6404a83bfe9SJérôme Glisse } 641ac46d4f3SJérôme Glisse 6424d4bbd85SMichal Hocko static inline int mm_has_notifiers(struct mm_struct *mm) 6434d4bbd85SMichal Hocko { 6444d4bbd85SMichal Hocko return 0; 6454d4bbd85SMichal Hocko } 6464d4bbd85SMichal Hocko 647cddb8a5cSAndrea Arcangeli static inline void mmu_notifier_release(struct mm_struct *mm) 648cddb8a5cSAndrea Arcangeli { 649cddb8a5cSAndrea Arcangeli } 650cddb8a5cSAndrea Arcangeli 651cddb8a5cSAndrea Arcangeli static inline int mmu_notifier_clear_flush_young(struct mm_struct *mm, 65257128468SAndres Lagar-Cavilla unsigned long start, 65357128468SAndres Lagar-Cavilla unsigned long end) 654cddb8a5cSAndrea Arcangeli { 655cddb8a5cSAndrea Arcangeli return 0; 656cddb8a5cSAndrea Arcangeli } 657cddb8a5cSAndrea Arcangeli 6588ee53820SAndrea Arcangeli static inline int mmu_notifier_test_young(struct mm_struct *mm, 6598ee53820SAndrea Arcangeli unsigned long address) 6608ee53820SAndrea Arcangeli { 6618ee53820SAndrea Arcangeli return 0; 6628ee53820SAndrea Arcangeli } 6638ee53820SAndrea Arcangeli 664828502d3SIzik Eidus static inline void mmu_notifier_change_pte(struct mm_struct *mm, 665828502d3SIzik Eidus unsigned long address, pte_t pte) 666828502d3SIzik Eidus { 667828502d3SIzik Eidus } 668828502d3SIzik Eidus 669ac46d4f3SJérôme Glisse static inline void 670ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) 671cddb8a5cSAndrea Arcangeli { 672cddb8a5cSAndrea Arcangeli } 673cddb8a5cSAndrea Arcangeli 674ac46d4f3SJérôme Glisse static inline int 675ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_start_nonblock(struct mmu_notifier_range *range) 67693065ac7SMichal Hocko { 67793065ac7SMichal Hocko return 0; 67893065ac7SMichal Hocko } 67993065ac7SMichal Hocko 680ac46d4f3SJérôme Glisse static inline 681ac46d4f3SJérôme Glisse void mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range) 682cddb8a5cSAndrea Arcangeli { 683cddb8a5cSAndrea Arcangeli } 684cddb8a5cSAndrea Arcangeli 685ac46d4f3SJérôme Glisse static inline void 686ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_only_end(struct mmu_notifier_range *range) 6874645b9feSJérôme Glisse { 6884645b9feSJérôme Glisse } 6894645b9feSJérôme Glisse 6901897bdc4SJoerg Roedel static inline void mmu_notifier_invalidate_range(struct mm_struct *mm, 6911897bdc4SJoerg Roedel unsigned long start, unsigned long end) 6921897bdc4SJoerg Roedel { 6931897bdc4SJoerg Roedel } 6941897bdc4SJoerg Roedel 695cddb8a5cSAndrea Arcangeli static inline void mmu_notifier_mm_init(struct mm_struct *mm) 696cddb8a5cSAndrea Arcangeli { 697cddb8a5cSAndrea Arcangeli } 698cddb8a5cSAndrea Arcangeli 699cddb8a5cSAndrea Arcangeli static inline void mmu_notifier_mm_destroy(struct mm_struct *mm) 700cddb8a5cSAndrea Arcangeli { 701cddb8a5cSAndrea Arcangeli } 702cddb8a5cSAndrea Arcangeli 703c6d23413SJérôme Glisse #define mmu_notifier_range_update_to_read_only(r) false 704c6d23413SJérôme Glisse 705cddb8a5cSAndrea Arcangeli #define ptep_clear_flush_young_notify ptep_clear_flush_young 70691a4ee26SAndrea Arcangeli #define pmdp_clear_flush_young_notify pmdp_clear_flush_young 70733c3fc71SVladimir Davydov #define ptep_clear_young_notify ptep_test_and_clear_young 70833c3fc71SVladimir Davydov #define pmdp_clear_young_notify pmdp_test_and_clear_young 70934ee645eSJoerg Roedel #define ptep_clear_flush_notify ptep_clear_flush 7108809aa2dSAneesh Kumar K.V #define pmdp_huge_clear_flush_notify pmdp_huge_clear_flush 711a00cc7d9SMatthew Wilcox #define pudp_huge_clear_flush_notify pudp_huge_clear_flush 712828502d3SIzik Eidus #define set_pte_at_notify set_pte_at 713cddb8a5cSAndrea Arcangeli 7142c7933f5SJason Gunthorpe static inline void mmu_notifier_synchronize(void) 7152c7933f5SJason Gunthorpe { 7162c7933f5SJason Gunthorpe } 7172c7933f5SJason Gunthorpe 718cddb8a5cSAndrea Arcangeli #endif /* CONFIG_MMU_NOTIFIER */ 719cddb8a5cSAndrea Arcangeli 720cddb8a5cSAndrea Arcangeli #endif /* _LINUX_MMU_NOTIFIER_H */ 721