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> 8b72327fcSMichel Lespinasse #include <linux/mmap_lock.h> 921a92735SSagi Grimberg #include <linux/srcu.h> 1099cb252fSJason Gunthorpe #include <linux/interval_tree.h> 11cddb8a5cSAndrea Arcangeli 12984cfe4eSJason Gunthorpe struct mmu_notifier_subscriptions; 13cddb8a5cSAndrea Arcangeli struct mmu_notifier; 1456f434f4SJason Gunthorpe struct mmu_notifier_range; 1599cb252fSJason Gunthorpe struct mmu_interval_notifier; 16cddb8a5cSAndrea Arcangeli 17d87f055bSJérôme Glisse /** 18d87f055bSJérôme Glisse * enum mmu_notifier_event - reason for the mmu notifier callback 19d87f055bSJérôme Glisse * @MMU_NOTIFY_UNMAP: either munmap() that unmap the range or a mremap() that 20d87f055bSJérôme Glisse * move the range 21d87f055bSJérôme Glisse * 22d87f055bSJérôme Glisse * @MMU_NOTIFY_CLEAR: clear page table entry (many reasons for this like 23d87f055bSJérôme Glisse * madvise() or replacing a page by another one, ...). 24d87f055bSJérôme Glisse * 25d87f055bSJérôme Glisse * @MMU_NOTIFY_PROTECTION_VMA: update is due to protection change for the range 26d87f055bSJérôme Glisse * ie using the vma access permission (vm_page_prot) to update the whole range 27d87f055bSJérôme Glisse * is enough no need to inspect changes to the CPU page table (mprotect() 28d87f055bSJérôme Glisse * syscall) 29d87f055bSJérôme Glisse * 30d87f055bSJérôme Glisse * @MMU_NOTIFY_PROTECTION_PAGE: update is due to change in read/write flag for 31d87f055bSJérôme Glisse * pages in the range so to mirror those changes the user must inspect the CPU 32d87f055bSJérôme Glisse * page table (from the end callback). 33d87f055bSJérôme Glisse * 34d87f055bSJérôme Glisse * @MMU_NOTIFY_SOFT_DIRTY: soft dirty accounting (still same page and same 35d87f055bSJérôme Glisse * access flags). User should soft dirty the page in the end callback to make 36d87f055bSJérôme Glisse * sure that anyone relying on soft dirtyness catch pages that might be written 37d87f055bSJérôme Glisse * through non CPU mappings. 3899cb252fSJason Gunthorpe * 3999cb252fSJason Gunthorpe * @MMU_NOTIFY_RELEASE: used during mmu_interval_notifier invalidate to signal 4099cb252fSJason Gunthorpe * that the mm refcount is zero and the range is no longer accessible. 41998427b3SRalph Campbell * 42998427b3SRalph Campbell * @MMU_NOTIFY_MIGRATE: used during migrate_vma_collect() invalidate to signal 43998427b3SRalph Campbell * a device driver to possibly ignore the invalidation if the 44998427b3SRalph Campbell * migrate_pgmap_owner field matches the driver's device private pgmap owner. 45d87f055bSJérôme Glisse */ 46d87f055bSJérôme Glisse enum mmu_notifier_event { 47d87f055bSJérôme Glisse MMU_NOTIFY_UNMAP = 0, 48d87f055bSJérôme Glisse MMU_NOTIFY_CLEAR, 49d87f055bSJérôme Glisse MMU_NOTIFY_PROTECTION_VMA, 50d87f055bSJérôme Glisse MMU_NOTIFY_PROTECTION_PAGE, 51d87f055bSJérôme Glisse MMU_NOTIFY_SOFT_DIRTY, 5299cb252fSJason Gunthorpe MMU_NOTIFY_RELEASE, 53998427b3SRalph Campbell MMU_NOTIFY_MIGRATE, 54d87f055bSJérôme Glisse }; 55d87f055bSJérôme Glisse 5627560ee9SJérôme Glisse #define MMU_NOTIFIER_RANGE_BLOCKABLE (1 << 0) 5727560ee9SJérôme Glisse 58cddb8a5cSAndrea Arcangeli struct mmu_notifier_ops { 59cddb8a5cSAndrea Arcangeli /* 60cddb8a5cSAndrea Arcangeli * Called either by mmu_notifier_unregister or when the mm is 61cddb8a5cSAndrea Arcangeli * being destroyed by exit_mmap, always before all pages are 62cddb8a5cSAndrea Arcangeli * freed. This can run concurrently with other mmu notifier 63cddb8a5cSAndrea Arcangeli * methods (the ones invoked outside the mm context) and it 64cddb8a5cSAndrea Arcangeli * should tear down all secondary mmu mappings and freeze the 65cddb8a5cSAndrea Arcangeli * secondary mmu. If this method isn't implemented you've to 66cddb8a5cSAndrea Arcangeli * be sure that nothing could possibly write to the pages 67cddb8a5cSAndrea Arcangeli * through the secondary mmu by the time the last thread with 68cddb8a5cSAndrea Arcangeli * tsk->mm == mm exits. 69cddb8a5cSAndrea Arcangeli * 70cddb8a5cSAndrea Arcangeli * As side note: the pages freed after ->release returns could 71cddb8a5cSAndrea Arcangeli * be immediately reallocated by the gart at an alias physical 72cddb8a5cSAndrea Arcangeli * address with a different cache model, so if ->release isn't 73cddb8a5cSAndrea Arcangeli * implemented because all _software_ driven memory accesses 74cddb8a5cSAndrea Arcangeli * through the secondary mmu are terminated by the time the 75cddb8a5cSAndrea Arcangeli * last thread of this mm quits, you've also to be sure that 76cddb8a5cSAndrea Arcangeli * speculative _hardware_ operations can't allocate dirty 77cddb8a5cSAndrea Arcangeli * cachelines in the cpu that could not be snooped and made 78cddb8a5cSAndrea Arcangeli * coherent with the other read and write operations happening 79cddb8a5cSAndrea Arcangeli * through the gart alias address, so leading to memory 80cddb8a5cSAndrea Arcangeli * corruption. 81cddb8a5cSAndrea Arcangeli */ 821991722aSJason Gunthorpe void (*release)(struct mmu_notifier *subscription, 83cddb8a5cSAndrea Arcangeli struct mm_struct *mm); 84cddb8a5cSAndrea Arcangeli 85cddb8a5cSAndrea Arcangeli /* 86cddb8a5cSAndrea Arcangeli * clear_flush_young is called after the VM is 87cddb8a5cSAndrea Arcangeli * test-and-clearing the young/accessed bitflag in the 88cddb8a5cSAndrea Arcangeli * pte. This way the VM will provide proper aging to the 89cddb8a5cSAndrea Arcangeli * accesses to the page through the secondary MMUs and not 90cddb8a5cSAndrea Arcangeli * only to the ones through the Linux pte. 9157128468SAndres Lagar-Cavilla * Start-end is necessary in case the secondary MMU is mapping the page 9257128468SAndres Lagar-Cavilla * at a smaller granularity than the primary MMU. 93cddb8a5cSAndrea Arcangeli */ 941991722aSJason Gunthorpe int (*clear_flush_young)(struct mmu_notifier *subscription, 95cddb8a5cSAndrea Arcangeli struct mm_struct *mm, 9657128468SAndres Lagar-Cavilla unsigned long start, 9757128468SAndres Lagar-Cavilla unsigned long end); 98cddb8a5cSAndrea Arcangeli 99cddb8a5cSAndrea Arcangeli /* 1001d7715c6SVladimir Davydov * clear_young is a lightweight version of clear_flush_young. Like the 1011d7715c6SVladimir Davydov * latter, it is supposed to test-and-clear the young/accessed bitflag 1021d7715c6SVladimir Davydov * in the secondary pte, but it may omit flushing the secondary tlb. 1031d7715c6SVladimir Davydov */ 1041991722aSJason Gunthorpe int (*clear_young)(struct mmu_notifier *subscription, 1051d7715c6SVladimir Davydov struct mm_struct *mm, 1061d7715c6SVladimir Davydov unsigned long start, 1071d7715c6SVladimir Davydov unsigned long end); 1081d7715c6SVladimir Davydov 1091d7715c6SVladimir Davydov /* 1108ee53820SAndrea Arcangeli * test_young is called to check the young/accessed bitflag in 1118ee53820SAndrea Arcangeli * the secondary pte. This is used to know if the page is 1128ee53820SAndrea Arcangeli * frequently used without actually clearing the flag or tearing 1138ee53820SAndrea Arcangeli * down the secondary mapping on the page. 1148ee53820SAndrea Arcangeli */ 1151991722aSJason Gunthorpe int (*test_young)(struct mmu_notifier *subscription, 1168ee53820SAndrea Arcangeli struct mm_struct *mm, 1178ee53820SAndrea Arcangeli unsigned long address); 1188ee53820SAndrea Arcangeli 1198ee53820SAndrea Arcangeli /* 120828502d3SIzik Eidus * change_pte is called in cases that pte mapping to page is changed: 121828502d3SIzik Eidus * for example, when ksm remaps pte to point to a new shared page. 122828502d3SIzik Eidus */ 1231991722aSJason Gunthorpe void (*change_pte)(struct mmu_notifier *subscription, 124828502d3SIzik Eidus struct mm_struct *mm, 125828502d3SIzik Eidus unsigned long address, 126828502d3SIzik Eidus pte_t pte); 127828502d3SIzik Eidus 128828502d3SIzik Eidus /* 129cddb8a5cSAndrea Arcangeli * invalidate_range_start() and invalidate_range_end() must be 130c1e8d7c6SMichel Lespinasse * paired and are called only when the mmap_lock and/or the 1310f0a327fSJoerg Roedel * locks protecting the reverse maps are held. If the subsystem 1320f0a327fSJoerg Roedel * can't guarantee that no additional references are taken to 1330f0a327fSJoerg Roedel * the pages in the range, it has to implement the 1340f0a327fSJoerg Roedel * invalidate_range() notifier to remove any references taken 1350f0a327fSJoerg Roedel * after invalidate_range_start(). 136cddb8a5cSAndrea Arcangeli * 137cddb8a5cSAndrea Arcangeli * Invalidation of multiple concurrent ranges may be 138cddb8a5cSAndrea Arcangeli * optionally permitted by the driver. Either way the 139cddb8a5cSAndrea Arcangeli * establishment of sptes is forbidden in the range passed to 140cddb8a5cSAndrea Arcangeli * invalidate_range_begin/end for the whole duration of the 141cddb8a5cSAndrea Arcangeli * invalidate_range_begin/end critical section. 142cddb8a5cSAndrea Arcangeli * 143cddb8a5cSAndrea Arcangeli * invalidate_range_start() is called when all pages in the 144cddb8a5cSAndrea Arcangeli * range are still mapped and have at least a refcount of one. 145cddb8a5cSAndrea Arcangeli * 146cddb8a5cSAndrea Arcangeli * invalidate_range_end() is called when all pages in the 147cddb8a5cSAndrea Arcangeli * range have been unmapped and the pages have been freed by 148cddb8a5cSAndrea Arcangeli * the VM. 149cddb8a5cSAndrea Arcangeli * 150cddb8a5cSAndrea Arcangeli * The VM will remove the page table entries and potentially 151cddb8a5cSAndrea Arcangeli * the page between invalidate_range_start() and 152cddb8a5cSAndrea Arcangeli * invalidate_range_end(). If the page must not be freed 153cddb8a5cSAndrea Arcangeli * because of pending I/O or other circumstances then the 154cddb8a5cSAndrea Arcangeli * invalidate_range_start() callback (or the initial mapping 155cddb8a5cSAndrea Arcangeli * by the driver) must make sure that the refcount is kept 156cddb8a5cSAndrea Arcangeli * elevated. 157cddb8a5cSAndrea Arcangeli * 158cddb8a5cSAndrea Arcangeli * If the driver increases the refcount when the pages are 159cddb8a5cSAndrea Arcangeli * initially mapped into an address space then either 160cddb8a5cSAndrea Arcangeli * invalidate_range_start() or invalidate_range_end() may 161cddb8a5cSAndrea Arcangeli * decrease the refcount. If the refcount is decreased on 162cddb8a5cSAndrea Arcangeli * invalidate_range_start() then the VM can free pages as page 163cddb8a5cSAndrea Arcangeli * table entries are removed. If the refcount is only 164cddb8a5cSAndrea Arcangeli * droppped on invalidate_range_end() then the driver itself 165cddb8a5cSAndrea Arcangeli * will drop the last refcount but it must take care to flush 166cddb8a5cSAndrea Arcangeli * any secondary tlb before doing the final free on the 167cddb8a5cSAndrea Arcangeli * page. Pages will no longer be referenced by the linux 168cddb8a5cSAndrea Arcangeli * address space but may still be referenced by sptes until 169cddb8a5cSAndrea Arcangeli * the last refcount is dropped. 1705ff7091fSDavid Rientjes * 17193065ac7SMichal Hocko * If blockable argument is set to false then the callback cannot 172*c2655835SSean Christopherson * sleep and has to return with -EAGAIN if sleeping would be required. 173*c2655835SSean Christopherson * 0 should be returned otherwise. Please note that notifiers that can 174*c2655835SSean Christopherson * fail invalidate_range_start are not allowed to implement 175*c2655835SSean Christopherson * invalidate_range_end, as there is no mechanism for informing the 176*c2655835SSean Christopherson * notifier that its start failed. 177cddb8a5cSAndrea Arcangeli */ 1781991722aSJason Gunthorpe int (*invalidate_range_start)(struct mmu_notifier *subscription, 1795d6527a7SJérôme Glisse const struct mmu_notifier_range *range); 1801991722aSJason Gunthorpe void (*invalidate_range_end)(struct mmu_notifier *subscription, 1815d6527a7SJérôme Glisse const struct mmu_notifier_range *range); 1820f0a327fSJoerg Roedel 1830f0a327fSJoerg Roedel /* 1840f0a327fSJoerg Roedel * invalidate_range() is either called between 1850f0a327fSJoerg Roedel * invalidate_range_start() and invalidate_range_end() when the 1860f0a327fSJoerg Roedel * VM has to free pages that where unmapped, but before the 1870f0a327fSJoerg Roedel * pages are actually freed, or outside of _start()/_end() when 1880f0a327fSJoerg Roedel * a (remote) TLB is necessary. 1890f0a327fSJoerg Roedel * 1900f0a327fSJoerg Roedel * If invalidate_range() is used to manage a non-CPU TLB with 1910f0a327fSJoerg Roedel * shared page-tables, it not necessary to implement the 1920f0a327fSJoerg Roedel * invalidate_range_start()/end() notifiers, as 1930f0a327fSJoerg Roedel * invalidate_range() alread catches the points in time when an 1940f10851eSJérôme Glisse * external TLB range needs to be flushed. For more in depth 195ad56b738SMike Rapoport * discussion on this see Documentation/vm/mmu_notifier.rst 1960f0a327fSJoerg Roedel * 1970f0a327fSJoerg Roedel * Note that this function might be called with just a sub-range 1980f0a327fSJoerg Roedel * of what was passed to invalidate_range_start()/end(), if 1990f0a327fSJoerg Roedel * called between those functions. 2000f0a327fSJoerg Roedel */ 2011991722aSJason Gunthorpe void (*invalidate_range)(struct mmu_notifier *subscription, 2021991722aSJason Gunthorpe struct mm_struct *mm, 2031991722aSJason Gunthorpe unsigned long start, 2041991722aSJason Gunthorpe unsigned long end); 2052c7933f5SJason Gunthorpe 2062c7933f5SJason Gunthorpe /* 2072c7933f5SJason Gunthorpe * These callbacks are used with the get/put interface to manage the 2082c7933f5SJason Gunthorpe * lifetime of the mmu_notifier memory. alloc_notifier() returns a new 2092c7933f5SJason Gunthorpe * notifier for use with the mm. 2102c7933f5SJason Gunthorpe * 2112c7933f5SJason Gunthorpe * free_notifier() is only called after the mmu_notifier has been 2122c7933f5SJason Gunthorpe * fully put, calls to any ops callback are prevented and no ops 2132c7933f5SJason Gunthorpe * callbacks are currently running. It is called from a SRCU callback 2142c7933f5SJason Gunthorpe * and cannot sleep. 2152c7933f5SJason Gunthorpe */ 2162c7933f5SJason Gunthorpe struct mmu_notifier *(*alloc_notifier)(struct mm_struct *mm); 2171991722aSJason Gunthorpe void (*free_notifier)(struct mmu_notifier *subscription); 218cddb8a5cSAndrea Arcangeli }; 219cddb8a5cSAndrea Arcangeli 220cddb8a5cSAndrea Arcangeli /* 221c1e8d7c6SMichel Lespinasse * The notifier chains are protected by mmap_lock and/or the reverse map 222cddb8a5cSAndrea Arcangeli * semaphores. Notifier chains are only changed when all reverse maps and 223c1e8d7c6SMichel Lespinasse * the mmap_lock locks are taken. 224cddb8a5cSAndrea Arcangeli * 225cddb8a5cSAndrea Arcangeli * Therefore notifier chains can only be traversed when either 226cddb8a5cSAndrea Arcangeli * 227c1e8d7c6SMichel Lespinasse * 1. mmap_lock is held. 228c8c06efaSDavidlohr Bueso * 2. One of the reverse map locks is held (i_mmap_rwsem or anon_vma->rwsem). 229cddb8a5cSAndrea Arcangeli * 3. No other concurrent thread can access the list (release) 230cddb8a5cSAndrea Arcangeli */ 231cddb8a5cSAndrea Arcangeli struct mmu_notifier { 232cddb8a5cSAndrea Arcangeli struct hlist_node hlist; 233cddb8a5cSAndrea Arcangeli const struct mmu_notifier_ops *ops; 2342c7933f5SJason Gunthorpe struct mm_struct *mm; 2352c7933f5SJason Gunthorpe struct rcu_head rcu; 2362c7933f5SJason Gunthorpe unsigned int users; 237cddb8a5cSAndrea Arcangeli }; 238cddb8a5cSAndrea Arcangeli 23999cb252fSJason Gunthorpe /** 24099cb252fSJason Gunthorpe * struct mmu_interval_notifier_ops 24199cb252fSJason Gunthorpe * @invalidate: Upon return the caller must stop using any SPTEs within this 24299cb252fSJason Gunthorpe * range. This function can sleep. Return false only if sleeping 24399cb252fSJason Gunthorpe * was required but mmu_notifier_range_blockable(range) is false. 24499cb252fSJason Gunthorpe */ 24599cb252fSJason Gunthorpe struct mmu_interval_notifier_ops { 2465292e24aSJason Gunthorpe bool (*invalidate)(struct mmu_interval_notifier *interval_sub, 24799cb252fSJason Gunthorpe const struct mmu_notifier_range *range, 24899cb252fSJason Gunthorpe unsigned long cur_seq); 24999cb252fSJason Gunthorpe }; 25099cb252fSJason Gunthorpe 25199cb252fSJason Gunthorpe struct mmu_interval_notifier { 25299cb252fSJason Gunthorpe struct interval_tree_node interval_tree; 25399cb252fSJason Gunthorpe const struct mmu_interval_notifier_ops *ops; 25499cb252fSJason Gunthorpe struct mm_struct *mm; 25599cb252fSJason Gunthorpe struct hlist_node deferred_item; 25699cb252fSJason Gunthorpe unsigned long invalidate_seq; 25799cb252fSJason Gunthorpe }; 25899cb252fSJason Gunthorpe 25956f434f4SJason Gunthorpe #ifdef CONFIG_MMU_NOTIFIER 26056f434f4SJason Gunthorpe 26156f434f4SJason Gunthorpe #ifdef CONFIG_LOCKDEP 26256f434f4SJason Gunthorpe extern struct lockdep_map __mmu_notifier_invalidate_range_start_map; 26356f434f4SJason Gunthorpe #endif 26456f434f4SJason Gunthorpe 26556f434f4SJason Gunthorpe struct mmu_notifier_range { 26656f434f4SJason Gunthorpe struct vm_area_struct *vma; 26756f434f4SJason Gunthorpe struct mm_struct *mm; 26856f434f4SJason Gunthorpe unsigned long start; 26956f434f4SJason Gunthorpe unsigned long end; 27056f434f4SJason Gunthorpe unsigned flags; 27156f434f4SJason Gunthorpe enum mmu_notifier_event event; 272998427b3SRalph Campbell void *migrate_pgmap_owner; 27356f434f4SJason Gunthorpe }; 27456f434f4SJason Gunthorpe 275cddb8a5cSAndrea Arcangeli static inline int mm_has_notifiers(struct mm_struct *mm) 276cddb8a5cSAndrea Arcangeli { 277984cfe4eSJason Gunthorpe return unlikely(mm->notifier_subscriptions); 278cddb8a5cSAndrea Arcangeli } 279cddb8a5cSAndrea Arcangeli 2802c7933f5SJason Gunthorpe struct mmu_notifier *mmu_notifier_get_locked(const struct mmu_notifier_ops *ops, 2812c7933f5SJason Gunthorpe struct mm_struct *mm); 2822c7933f5SJason Gunthorpe static inline struct mmu_notifier * 2832c7933f5SJason Gunthorpe mmu_notifier_get(const struct mmu_notifier_ops *ops, struct mm_struct *mm) 2842c7933f5SJason Gunthorpe { 2852c7933f5SJason Gunthorpe struct mmu_notifier *ret; 2862c7933f5SJason Gunthorpe 287b72327fcSMichel Lespinasse mmap_write_lock(mm); 2882c7933f5SJason Gunthorpe ret = mmu_notifier_get_locked(ops, mm); 289b72327fcSMichel Lespinasse mmap_write_unlock(mm); 2902c7933f5SJason Gunthorpe return ret; 2912c7933f5SJason Gunthorpe } 2921991722aSJason Gunthorpe void mmu_notifier_put(struct mmu_notifier *subscription); 2932c7933f5SJason Gunthorpe void mmu_notifier_synchronize(void); 2942c7933f5SJason Gunthorpe 2951991722aSJason Gunthorpe extern int mmu_notifier_register(struct mmu_notifier *subscription, 296cddb8a5cSAndrea Arcangeli struct mm_struct *mm); 2971991722aSJason Gunthorpe extern int __mmu_notifier_register(struct mmu_notifier *subscription, 298cddb8a5cSAndrea Arcangeli struct mm_struct *mm); 2991991722aSJason Gunthorpe extern void mmu_notifier_unregister(struct mmu_notifier *subscription, 300cddb8a5cSAndrea Arcangeli struct mm_struct *mm); 30199cb252fSJason Gunthorpe 3025292e24aSJason Gunthorpe unsigned long 3035292e24aSJason Gunthorpe mmu_interval_read_begin(struct mmu_interval_notifier *interval_sub); 3045292e24aSJason Gunthorpe int mmu_interval_notifier_insert(struct mmu_interval_notifier *interval_sub, 30599cb252fSJason Gunthorpe struct mm_struct *mm, unsigned long start, 30699cb252fSJason Gunthorpe unsigned long length, 30799cb252fSJason Gunthorpe const struct mmu_interval_notifier_ops *ops); 30899cb252fSJason Gunthorpe int mmu_interval_notifier_insert_locked( 3095292e24aSJason Gunthorpe struct mmu_interval_notifier *interval_sub, struct mm_struct *mm, 31099cb252fSJason Gunthorpe unsigned long start, unsigned long length, 31199cb252fSJason Gunthorpe const struct mmu_interval_notifier_ops *ops); 3125292e24aSJason Gunthorpe void mmu_interval_notifier_remove(struct mmu_interval_notifier *interval_sub); 31399cb252fSJason Gunthorpe 31499cb252fSJason Gunthorpe /** 31599cb252fSJason Gunthorpe * mmu_interval_set_seq - Save the invalidation sequence 3165292e24aSJason Gunthorpe * @interval_sub - The subscription passed to invalidate 31799cb252fSJason Gunthorpe * @cur_seq - The cur_seq passed to the invalidate() callback 31899cb252fSJason Gunthorpe * 31999cb252fSJason Gunthorpe * This must be called unconditionally from the invalidate callback of a 32099cb252fSJason Gunthorpe * struct mmu_interval_notifier_ops under the same lock that is used to call 32199cb252fSJason Gunthorpe * mmu_interval_read_retry(). It updates the sequence number for later use by 32299cb252fSJason Gunthorpe * mmu_interval_read_retry(). The provided cur_seq will always be odd. 32399cb252fSJason Gunthorpe * 32499cb252fSJason Gunthorpe * If the caller does not call mmu_interval_read_begin() or 32599cb252fSJason Gunthorpe * mmu_interval_read_retry() then this call is not required. 32699cb252fSJason Gunthorpe */ 3275292e24aSJason Gunthorpe static inline void 3285292e24aSJason Gunthorpe mmu_interval_set_seq(struct mmu_interval_notifier *interval_sub, 32999cb252fSJason Gunthorpe unsigned long cur_seq) 33099cb252fSJason Gunthorpe { 3315292e24aSJason Gunthorpe WRITE_ONCE(interval_sub->invalidate_seq, cur_seq); 33299cb252fSJason Gunthorpe } 33399cb252fSJason Gunthorpe 33499cb252fSJason Gunthorpe /** 33599cb252fSJason Gunthorpe * mmu_interval_read_retry - End a read side critical section against a VA range 3365292e24aSJason Gunthorpe * interval_sub: The subscription 33799cb252fSJason Gunthorpe * seq: The return of the paired mmu_interval_read_begin() 33899cb252fSJason Gunthorpe * 33999cb252fSJason Gunthorpe * This MUST be called under a user provided lock that is also held 34099cb252fSJason Gunthorpe * unconditionally by op->invalidate() when it calls mmu_interval_set_seq(). 34199cb252fSJason Gunthorpe * 34299cb252fSJason Gunthorpe * Each call should be paired with a single mmu_interval_read_begin() and 34399cb252fSJason Gunthorpe * should be used to conclude the read side. 34499cb252fSJason Gunthorpe * 34599cb252fSJason Gunthorpe * Returns true if an invalidation collided with this critical section, and 34699cb252fSJason Gunthorpe * the caller should retry. 34799cb252fSJason Gunthorpe */ 3485292e24aSJason Gunthorpe static inline bool 3495292e24aSJason Gunthorpe mmu_interval_read_retry(struct mmu_interval_notifier *interval_sub, 35099cb252fSJason Gunthorpe unsigned long seq) 35199cb252fSJason Gunthorpe { 3525292e24aSJason Gunthorpe return interval_sub->invalidate_seq != seq; 35399cb252fSJason Gunthorpe } 35499cb252fSJason Gunthorpe 35599cb252fSJason Gunthorpe /** 35699cb252fSJason Gunthorpe * mmu_interval_check_retry - Test if a collision has occurred 3575292e24aSJason Gunthorpe * interval_sub: The subscription 35899cb252fSJason Gunthorpe * seq: The return of the matching mmu_interval_read_begin() 35999cb252fSJason Gunthorpe * 36099cb252fSJason Gunthorpe * This can be used in the critical section between mmu_interval_read_begin() 36199cb252fSJason Gunthorpe * and mmu_interval_read_retry(). A return of true indicates an invalidation 36299cb252fSJason Gunthorpe * has collided with this critical region and a future 36399cb252fSJason Gunthorpe * mmu_interval_read_retry() will return true. 36499cb252fSJason Gunthorpe * 36599cb252fSJason Gunthorpe * False is not reliable and only suggests a collision may not have 36699cb252fSJason Gunthorpe * occured. It can be called many times and does not have to hold the user 36799cb252fSJason Gunthorpe * provided lock. 36899cb252fSJason Gunthorpe * 36999cb252fSJason Gunthorpe * This call can be used as part of loops and other expensive operations to 37099cb252fSJason Gunthorpe * expedite a retry. 37199cb252fSJason Gunthorpe */ 3725292e24aSJason Gunthorpe static inline bool 3735292e24aSJason Gunthorpe mmu_interval_check_retry(struct mmu_interval_notifier *interval_sub, 37499cb252fSJason Gunthorpe unsigned long seq) 37599cb252fSJason Gunthorpe { 37699cb252fSJason Gunthorpe /* Pairs with the WRITE_ONCE in mmu_interval_set_seq() */ 3775292e24aSJason Gunthorpe return READ_ONCE(interval_sub->invalidate_seq) != seq; 37899cb252fSJason Gunthorpe } 37999cb252fSJason Gunthorpe 380984cfe4eSJason Gunthorpe extern void __mmu_notifier_subscriptions_destroy(struct mm_struct *mm); 381cddb8a5cSAndrea Arcangeli extern void __mmu_notifier_release(struct mm_struct *mm); 382cddb8a5cSAndrea Arcangeli extern int __mmu_notifier_clear_flush_young(struct mm_struct *mm, 38357128468SAndres Lagar-Cavilla unsigned long start, 38457128468SAndres Lagar-Cavilla unsigned long end); 3851d7715c6SVladimir Davydov extern int __mmu_notifier_clear_young(struct mm_struct *mm, 3861d7715c6SVladimir Davydov unsigned long start, 3871d7715c6SVladimir Davydov unsigned long end); 3888ee53820SAndrea Arcangeli extern int __mmu_notifier_test_young(struct mm_struct *mm, 3898ee53820SAndrea Arcangeli unsigned long address); 390828502d3SIzik Eidus extern void __mmu_notifier_change_pte(struct mm_struct *mm, 391828502d3SIzik Eidus unsigned long address, pte_t pte); 392ac46d4f3SJérôme Glisse extern int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *r); 393ac46d4f3SJérôme Glisse extern void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *r, 3944645b9feSJérôme Glisse bool only_end); 3950f0a327fSJoerg Roedel extern void __mmu_notifier_invalidate_range(struct mm_struct *mm, 3960f0a327fSJoerg Roedel unsigned long start, unsigned long end); 397c6d23413SJérôme Glisse extern bool 398c6d23413SJérôme Glisse mmu_notifier_range_update_to_read_only(const struct mmu_notifier_range *range); 399cddb8a5cSAndrea Arcangeli 4004a83bfe9SJérôme Glisse static inline bool 4014a83bfe9SJérôme Glisse mmu_notifier_range_blockable(const struct mmu_notifier_range *range) 4024a83bfe9SJérôme Glisse { 40327560ee9SJérôme Glisse return (range->flags & MMU_NOTIFIER_RANGE_BLOCKABLE); 4044a83bfe9SJérôme Glisse } 4054a83bfe9SJérôme Glisse 406cddb8a5cSAndrea Arcangeli static inline void mmu_notifier_release(struct mm_struct *mm) 407cddb8a5cSAndrea Arcangeli { 408cddb8a5cSAndrea Arcangeli if (mm_has_notifiers(mm)) 409cddb8a5cSAndrea Arcangeli __mmu_notifier_release(mm); 410cddb8a5cSAndrea Arcangeli } 411cddb8a5cSAndrea Arcangeli 412cddb8a5cSAndrea Arcangeli static inline int mmu_notifier_clear_flush_young(struct mm_struct *mm, 41357128468SAndres Lagar-Cavilla unsigned long start, 41457128468SAndres Lagar-Cavilla unsigned long end) 415cddb8a5cSAndrea Arcangeli { 416cddb8a5cSAndrea Arcangeli if (mm_has_notifiers(mm)) 41757128468SAndres Lagar-Cavilla return __mmu_notifier_clear_flush_young(mm, start, end); 418cddb8a5cSAndrea Arcangeli return 0; 419cddb8a5cSAndrea Arcangeli } 420cddb8a5cSAndrea Arcangeli 4211d7715c6SVladimir Davydov static inline int mmu_notifier_clear_young(struct mm_struct *mm, 4221d7715c6SVladimir Davydov unsigned long start, 4231d7715c6SVladimir Davydov unsigned long end) 4241d7715c6SVladimir Davydov { 4251d7715c6SVladimir Davydov if (mm_has_notifiers(mm)) 4261d7715c6SVladimir Davydov return __mmu_notifier_clear_young(mm, start, end); 4271d7715c6SVladimir Davydov return 0; 4281d7715c6SVladimir Davydov } 4291d7715c6SVladimir Davydov 4308ee53820SAndrea Arcangeli static inline int mmu_notifier_test_young(struct mm_struct *mm, 4318ee53820SAndrea Arcangeli unsigned long address) 4328ee53820SAndrea Arcangeli { 4338ee53820SAndrea Arcangeli if (mm_has_notifiers(mm)) 4348ee53820SAndrea Arcangeli return __mmu_notifier_test_young(mm, address); 4358ee53820SAndrea Arcangeli return 0; 4368ee53820SAndrea Arcangeli } 4378ee53820SAndrea Arcangeli 438828502d3SIzik Eidus static inline void mmu_notifier_change_pte(struct mm_struct *mm, 439828502d3SIzik Eidus unsigned long address, pte_t pte) 440828502d3SIzik Eidus { 441828502d3SIzik Eidus if (mm_has_notifiers(mm)) 442828502d3SIzik Eidus __mmu_notifier_change_pte(mm, address, pte); 443828502d3SIzik Eidus } 444828502d3SIzik Eidus 445ac46d4f3SJérôme Glisse static inline void 446ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) 447cddb8a5cSAndrea Arcangeli { 448810e24e0SDaniel Vetter might_sleep(); 449810e24e0SDaniel 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; 453ac46d4f3SJérôme Glisse __mmu_notifier_invalidate_range_start(range); 454ac46d4f3SJérôme Glisse } 45523b68395SDaniel Vetter lock_map_release(&__mmu_notifier_invalidate_range_start_map); 45693065ac7SMichal Hocko } 45793065ac7SMichal Hocko 458ac46d4f3SJérôme Glisse static inline int 459ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_start_nonblock(struct mmu_notifier_range *range) 46093065ac7SMichal Hocko { 46123b68395SDaniel Vetter int ret = 0; 46223b68395SDaniel Vetter 46323b68395SDaniel Vetter lock_map_acquire(&__mmu_notifier_invalidate_range_start_map); 464ac46d4f3SJérôme Glisse if (mm_has_notifiers(range->mm)) { 46527560ee9SJérôme Glisse range->flags &= ~MMU_NOTIFIER_RANGE_BLOCKABLE; 46623b68395SDaniel Vetter ret = __mmu_notifier_invalidate_range_start(range); 467ac46d4f3SJérôme Glisse } 46823b68395SDaniel Vetter lock_map_release(&__mmu_notifier_invalidate_range_start_map); 46923b68395SDaniel Vetter return ret; 470cddb8a5cSAndrea Arcangeli } 471cddb8a5cSAndrea Arcangeli 472ac46d4f3SJérôme Glisse static inline void 473ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range) 474cddb8a5cSAndrea Arcangeli { 475810e24e0SDaniel Vetter if (mmu_notifier_range_blockable(range)) 476810e24e0SDaniel Vetter might_sleep(); 477810e24e0SDaniel Vetter 478ac46d4f3SJérôme Glisse if (mm_has_notifiers(range->mm)) 479ac46d4f3SJérôme Glisse __mmu_notifier_invalidate_range_end(range, false); 4804645b9feSJérôme Glisse } 4814645b9feSJérôme Glisse 482ac46d4f3SJérôme Glisse static inline void 483ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_only_end(struct mmu_notifier_range *range) 4844645b9feSJérôme Glisse { 485ac46d4f3SJérôme Glisse if (mm_has_notifiers(range->mm)) 486ac46d4f3SJérôme Glisse __mmu_notifier_invalidate_range_end(range, true); 487cddb8a5cSAndrea Arcangeli } 488cddb8a5cSAndrea Arcangeli 4891897bdc4SJoerg Roedel static inline void mmu_notifier_invalidate_range(struct mm_struct *mm, 4901897bdc4SJoerg Roedel unsigned long start, unsigned long end) 4911897bdc4SJoerg Roedel { 4920f0a327fSJoerg Roedel if (mm_has_notifiers(mm)) 4930f0a327fSJoerg Roedel __mmu_notifier_invalidate_range(mm, start, end); 4941897bdc4SJoerg Roedel } 4951897bdc4SJoerg Roedel 496984cfe4eSJason Gunthorpe static inline void mmu_notifier_subscriptions_init(struct mm_struct *mm) 497cddb8a5cSAndrea Arcangeli { 498984cfe4eSJason Gunthorpe mm->notifier_subscriptions = NULL; 499cddb8a5cSAndrea Arcangeli } 500cddb8a5cSAndrea Arcangeli 501984cfe4eSJason Gunthorpe static inline void mmu_notifier_subscriptions_destroy(struct mm_struct *mm) 502cddb8a5cSAndrea Arcangeli { 503cddb8a5cSAndrea Arcangeli if (mm_has_notifiers(mm)) 504984cfe4eSJason Gunthorpe __mmu_notifier_subscriptions_destroy(mm); 505cddb8a5cSAndrea Arcangeli } 506cddb8a5cSAndrea Arcangeli 507ac46d4f3SJérôme Glisse 508ac46d4f3SJérôme Glisse static inline void mmu_notifier_range_init(struct mmu_notifier_range *range, 5096f4f13e8SJérôme Glisse enum mmu_notifier_event event, 5106f4f13e8SJérôme Glisse unsigned flags, 5116f4f13e8SJérôme Glisse struct vm_area_struct *vma, 512ac46d4f3SJérôme Glisse struct mm_struct *mm, 513ac46d4f3SJérôme Glisse unsigned long start, 514ac46d4f3SJérôme Glisse unsigned long end) 515ac46d4f3SJérôme Glisse { 516bf198b2bSJérôme Glisse range->vma = vma; 517bf198b2bSJérôme Glisse range->event = event; 518ac46d4f3SJérôme Glisse range->mm = mm; 519ac46d4f3SJérôme Glisse range->start = start; 520ac46d4f3SJérôme Glisse range->end = end; 521bf198b2bSJérôme Glisse range->flags = flags; 522ac46d4f3SJérôme Glisse } 523ac46d4f3SJérôme Glisse 524c1a06df6SRalph Campbell static inline void mmu_notifier_range_init_migrate( 525c1a06df6SRalph Campbell struct mmu_notifier_range *range, unsigned int flags, 526c1a06df6SRalph Campbell struct vm_area_struct *vma, struct mm_struct *mm, 527c1a06df6SRalph Campbell unsigned long start, unsigned long end, void *pgmap) 528c1a06df6SRalph Campbell { 529c1a06df6SRalph Campbell mmu_notifier_range_init(range, MMU_NOTIFY_MIGRATE, flags, vma, mm, 530c1a06df6SRalph Campbell start, end); 531c1a06df6SRalph Campbell range->migrate_pgmap_owner = pgmap; 532c1a06df6SRalph Campbell } 533c1a06df6SRalph Campbell 534cddb8a5cSAndrea Arcangeli #define ptep_clear_flush_young_notify(__vma, __address, __ptep) \ 535cddb8a5cSAndrea Arcangeli ({ \ 536cddb8a5cSAndrea Arcangeli int __young; \ 537cddb8a5cSAndrea Arcangeli struct vm_area_struct *___vma = __vma; \ 538cddb8a5cSAndrea Arcangeli unsigned long ___address = __address; \ 539cddb8a5cSAndrea Arcangeli __young = ptep_clear_flush_young(___vma, ___address, __ptep); \ 540cddb8a5cSAndrea Arcangeli __young |= mmu_notifier_clear_flush_young(___vma->vm_mm, \ 54157128468SAndres Lagar-Cavilla ___address, \ 54257128468SAndres Lagar-Cavilla ___address + \ 54357128468SAndres Lagar-Cavilla PAGE_SIZE); \ 544cddb8a5cSAndrea Arcangeli __young; \ 545cddb8a5cSAndrea Arcangeli }) 546cddb8a5cSAndrea Arcangeli 54791a4ee26SAndrea Arcangeli #define pmdp_clear_flush_young_notify(__vma, __address, __pmdp) \ 54891a4ee26SAndrea Arcangeli ({ \ 54991a4ee26SAndrea Arcangeli int __young; \ 55091a4ee26SAndrea Arcangeli struct vm_area_struct *___vma = __vma; \ 55191a4ee26SAndrea Arcangeli unsigned long ___address = __address; \ 55291a4ee26SAndrea Arcangeli __young = pmdp_clear_flush_young(___vma, ___address, __pmdp); \ 55391a4ee26SAndrea Arcangeli __young |= mmu_notifier_clear_flush_young(___vma->vm_mm, \ 55457128468SAndres Lagar-Cavilla ___address, \ 55557128468SAndres Lagar-Cavilla ___address + \ 55657128468SAndres Lagar-Cavilla PMD_SIZE); \ 55791a4ee26SAndrea Arcangeli __young; \ 55891a4ee26SAndrea Arcangeli }) 55991a4ee26SAndrea Arcangeli 5601d7715c6SVladimir Davydov #define ptep_clear_young_notify(__vma, __address, __ptep) \ 5611d7715c6SVladimir Davydov ({ \ 5621d7715c6SVladimir Davydov int __young; \ 5631d7715c6SVladimir Davydov struct vm_area_struct *___vma = __vma; \ 5641d7715c6SVladimir Davydov unsigned long ___address = __address; \ 5651d7715c6SVladimir Davydov __young = ptep_test_and_clear_young(___vma, ___address, __ptep);\ 5661d7715c6SVladimir Davydov __young |= mmu_notifier_clear_young(___vma->vm_mm, ___address, \ 5671d7715c6SVladimir Davydov ___address + PAGE_SIZE); \ 5681d7715c6SVladimir Davydov __young; \ 5691d7715c6SVladimir Davydov }) 5701d7715c6SVladimir Davydov 5711d7715c6SVladimir Davydov #define pmdp_clear_young_notify(__vma, __address, __pmdp) \ 5721d7715c6SVladimir Davydov ({ \ 5731d7715c6SVladimir Davydov int __young; \ 5741d7715c6SVladimir Davydov struct vm_area_struct *___vma = __vma; \ 5751d7715c6SVladimir Davydov unsigned long ___address = __address; \ 5761d7715c6SVladimir Davydov __young = pmdp_test_and_clear_young(___vma, ___address, __pmdp);\ 5771d7715c6SVladimir Davydov __young |= mmu_notifier_clear_young(___vma->vm_mm, ___address, \ 5781d7715c6SVladimir Davydov ___address + PMD_SIZE); \ 5791d7715c6SVladimir Davydov __young; \ 5801d7715c6SVladimir Davydov }) 5811d7715c6SVladimir Davydov 58234ee645eSJoerg Roedel #define ptep_clear_flush_notify(__vma, __address, __ptep) \ 58334ee645eSJoerg Roedel ({ \ 58434ee645eSJoerg Roedel unsigned long ___addr = __address & PAGE_MASK; \ 58534ee645eSJoerg Roedel struct mm_struct *___mm = (__vma)->vm_mm; \ 58634ee645eSJoerg Roedel pte_t ___pte; \ 58734ee645eSJoerg Roedel \ 58834ee645eSJoerg Roedel ___pte = ptep_clear_flush(__vma, __address, __ptep); \ 58934ee645eSJoerg Roedel mmu_notifier_invalidate_range(___mm, ___addr, \ 59034ee645eSJoerg Roedel ___addr + PAGE_SIZE); \ 59134ee645eSJoerg Roedel \ 59234ee645eSJoerg Roedel ___pte; \ 59334ee645eSJoerg Roedel }) 59434ee645eSJoerg Roedel 5958809aa2dSAneesh Kumar K.V #define pmdp_huge_clear_flush_notify(__vma, __haddr, __pmd) \ 59634ee645eSJoerg Roedel ({ \ 59734ee645eSJoerg Roedel unsigned long ___haddr = __haddr & HPAGE_PMD_MASK; \ 59834ee645eSJoerg Roedel struct mm_struct *___mm = (__vma)->vm_mm; \ 59934ee645eSJoerg Roedel pmd_t ___pmd; \ 60034ee645eSJoerg Roedel \ 6018809aa2dSAneesh Kumar K.V ___pmd = pmdp_huge_clear_flush(__vma, __haddr, __pmd); \ 60234ee645eSJoerg Roedel mmu_notifier_invalidate_range(___mm, ___haddr, \ 60334ee645eSJoerg Roedel ___haddr + HPAGE_PMD_SIZE); \ 60434ee645eSJoerg Roedel \ 60534ee645eSJoerg Roedel ___pmd; \ 60634ee645eSJoerg Roedel }) 60734ee645eSJoerg Roedel 608a00cc7d9SMatthew Wilcox #define pudp_huge_clear_flush_notify(__vma, __haddr, __pud) \ 609a00cc7d9SMatthew Wilcox ({ \ 610a00cc7d9SMatthew Wilcox unsigned long ___haddr = __haddr & HPAGE_PUD_MASK; \ 611a00cc7d9SMatthew Wilcox struct mm_struct *___mm = (__vma)->vm_mm; \ 612a00cc7d9SMatthew Wilcox pud_t ___pud; \ 613a00cc7d9SMatthew Wilcox \ 614a00cc7d9SMatthew Wilcox ___pud = pudp_huge_clear_flush(__vma, __haddr, __pud); \ 615a00cc7d9SMatthew Wilcox mmu_notifier_invalidate_range(___mm, ___haddr, \ 616a00cc7d9SMatthew Wilcox ___haddr + HPAGE_PUD_SIZE); \ 617a00cc7d9SMatthew Wilcox \ 618a00cc7d9SMatthew Wilcox ___pud; \ 619a00cc7d9SMatthew Wilcox }) 620a00cc7d9SMatthew Wilcox 62148af0d7cSXiao Guangrong /* 62248af0d7cSXiao Guangrong * set_pte_at_notify() sets the pte _after_ running the notifier. 62348af0d7cSXiao Guangrong * This is safe to start by updating the secondary MMUs, because the primary MMU 62448af0d7cSXiao Guangrong * pte invalidate must have already happened with a ptep_clear_flush() before 62548af0d7cSXiao Guangrong * set_pte_at_notify() has been invoked. Updating the secondary MMUs first is 62648af0d7cSXiao Guangrong * required when we change both the protection of the mapping from read-only to 62748af0d7cSXiao Guangrong * read-write and the pfn (like during copy on write page faults). Otherwise the 62848af0d7cSXiao Guangrong * old page would remain mapped readonly in the secondary MMUs after the new 62948af0d7cSXiao Guangrong * page is already writable by some CPU through the primary MMU. 63048af0d7cSXiao Guangrong */ 631828502d3SIzik Eidus #define set_pte_at_notify(__mm, __address, __ptep, __pte) \ 632828502d3SIzik Eidus ({ \ 633828502d3SIzik Eidus struct mm_struct *___mm = __mm; \ 634828502d3SIzik Eidus unsigned long ___address = __address; \ 635828502d3SIzik Eidus pte_t ___pte = __pte; \ 636828502d3SIzik Eidus \ 637828502d3SIzik Eidus mmu_notifier_change_pte(___mm, ___address, ___pte); \ 63848af0d7cSXiao Guangrong set_pte_at(___mm, ___address, __ptep, ___pte); \ 639828502d3SIzik Eidus }) 640828502d3SIzik Eidus 641cddb8a5cSAndrea Arcangeli #else /* CONFIG_MMU_NOTIFIER */ 642cddb8a5cSAndrea Arcangeli 643ac46d4f3SJérôme Glisse struct mmu_notifier_range { 644ac46d4f3SJérôme Glisse unsigned long start; 645ac46d4f3SJérôme Glisse unsigned long end; 646ac46d4f3SJérôme Glisse }; 647ac46d4f3SJérôme Glisse 648ac46d4f3SJérôme Glisse static inline void _mmu_notifier_range_init(struct mmu_notifier_range *range, 649ac46d4f3SJérôme Glisse unsigned long start, 650ac46d4f3SJérôme Glisse unsigned long end) 651ac46d4f3SJérôme Glisse { 652ac46d4f3SJérôme Glisse range->start = start; 653ac46d4f3SJérôme Glisse range->end = end; 654ac46d4f3SJérôme Glisse } 655ac46d4f3SJérôme Glisse 6566f4f13e8SJérôme Glisse #define mmu_notifier_range_init(range,event,flags,vma,mm,start,end) \ 657ac46d4f3SJérôme Glisse _mmu_notifier_range_init(range, start, end) 658c1a06df6SRalph Campbell #define mmu_notifier_range_init_migrate(range, flags, vma, mm, start, end, \ 659c1a06df6SRalph Campbell pgmap) \ 660c1a06df6SRalph Campbell _mmu_notifier_range_init(range, start, end) 661ac46d4f3SJérôme Glisse 6624a83bfe9SJérôme Glisse static inline bool 6634a83bfe9SJérôme Glisse mmu_notifier_range_blockable(const struct mmu_notifier_range *range) 6644a83bfe9SJérôme Glisse { 6654a83bfe9SJérôme Glisse return true; 6664a83bfe9SJérôme Glisse } 667ac46d4f3SJérôme Glisse 6684d4bbd85SMichal Hocko static inline int mm_has_notifiers(struct mm_struct *mm) 6694d4bbd85SMichal Hocko { 6704d4bbd85SMichal Hocko return 0; 6714d4bbd85SMichal Hocko } 6724d4bbd85SMichal Hocko 673cddb8a5cSAndrea Arcangeli static inline void mmu_notifier_release(struct mm_struct *mm) 674cddb8a5cSAndrea Arcangeli { 675cddb8a5cSAndrea Arcangeli } 676cddb8a5cSAndrea Arcangeli 677cddb8a5cSAndrea Arcangeli static inline int mmu_notifier_clear_flush_young(struct mm_struct *mm, 67857128468SAndres Lagar-Cavilla unsigned long start, 67957128468SAndres Lagar-Cavilla unsigned long end) 680cddb8a5cSAndrea Arcangeli { 681cddb8a5cSAndrea Arcangeli return 0; 682cddb8a5cSAndrea Arcangeli } 683cddb8a5cSAndrea Arcangeli 6848ee53820SAndrea Arcangeli static inline int mmu_notifier_test_young(struct mm_struct *mm, 6858ee53820SAndrea Arcangeli unsigned long address) 6868ee53820SAndrea Arcangeli { 6878ee53820SAndrea Arcangeli return 0; 6888ee53820SAndrea Arcangeli } 6898ee53820SAndrea Arcangeli 690828502d3SIzik Eidus static inline void mmu_notifier_change_pte(struct mm_struct *mm, 691828502d3SIzik Eidus unsigned long address, pte_t pte) 692828502d3SIzik Eidus { 693828502d3SIzik Eidus } 694828502d3SIzik Eidus 695ac46d4f3SJérôme Glisse static inline void 696ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) 697cddb8a5cSAndrea Arcangeli { 698cddb8a5cSAndrea Arcangeli } 699cddb8a5cSAndrea Arcangeli 700ac46d4f3SJérôme Glisse static inline int 701ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_start_nonblock(struct mmu_notifier_range *range) 70293065ac7SMichal Hocko { 70393065ac7SMichal Hocko return 0; 70493065ac7SMichal Hocko } 70593065ac7SMichal Hocko 706ac46d4f3SJérôme Glisse static inline 707ac46d4f3SJérôme Glisse void mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range) 708cddb8a5cSAndrea Arcangeli { 709cddb8a5cSAndrea Arcangeli } 710cddb8a5cSAndrea Arcangeli 711ac46d4f3SJérôme Glisse static inline void 712ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_only_end(struct mmu_notifier_range *range) 7134645b9feSJérôme Glisse { 7144645b9feSJérôme Glisse } 7154645b9feSJérôme Glisse 7161897bdc4SJoerg Roedel static inline void mmu_notifier_invalidate_range(struct mm_struct *mm, 7171897bdc4SJoerg Roedel unsigned long start, unsigned long end) 7181897bdc4SJoerg Roedel { 7191897bdc4SJoerg Roedel } 7201897bdc4SJoerg Roedel 721984cfe4eSJason Gunthorpe static inline void mmu_notifier_subscriptions_init(struct mm_struct *mm) 722cddb8a5cSAndrea Arcangeli { 723cddb8a5cSAndrea Arcangeli } 724cddb8a5cSAndrea Arcangeli 725984cfe4eSJason Gunthorpe static inline void mmu_notifier_subscriptions_destroy(struct mm_struct *mm) 726cddb8a5cSAndrea Arcangeli { 727cddb8a5cSAndrea Arcangeli } 728cddb8a5cSAndrea Arcangeli 729c6d23413SJérôme Glisse #define mmu_notifier_range_update_to_read_only(r) false 730c6d23413SJérôme Glisse 731cddb8a5cSAndrea Arcangeli #define ptep_clear_flush_young_notify ptep_clear_flush_young 73291a4ee26SAndrea Arcangeli #define pmdp_clear_flush_young_notify pmdp_clear_flush_young 73333c3fc71SVladimir Davydov #define ptep_clear_young_notify ptep_test_and_clear_young 73433c3fc71SVladimir Davydov #define pmdp_clear_young_notify pmdp_test_and_clear_young 73534ee645eSJoerg Roedel #define ptep_clear_flush_notify ptep_clear_flush 7368809aa2dSAneesh Kumar K.V #define pmdp_huge_clear_flush_notify pmdp_huge_clear_flush 737a00cc7d9SMatthew Wilcox #define pudp_huge_clear_flush_notify pudp_huge_clear_flush 738828502d3SIzik Eidus #define set_pte_at_notify set_pte_at 739cddb8a5cSAndrea Arcangeli 7402c7933f5SJason Gunthorpe static inline void mmu_notifier_synchronize(void) 7412c7933f5SJason Gunthorpe { 7422c7933f5SJason Gunthorpe } 7432c7933f5SJason Gunthorpe 744cddb8a5cSAndrea Arcangeli #endif /* CONFIG_MMU_NOTIFIER */ 745cddb8a5cSAndrea Arcangeli 746cddb8a5cSAndrea Arcangeli #endif /* _LINUX_MMU_NOTIFIER_H */ 747