xref: /linux-6.15/include/linux/mmu_notifier.h (revision 1991722a)
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>
999cb252fSJason Gunthorpe #include <linux/interval_tree.h>
10cddb8a5cSAndrea Arcangeli 
11984cfe4eSJason Gunthorpe struct mmu_notifier_subscriptions;
12cddb8a5cSAndrea Arcangeli struct mmu_notifier;
1356f434f4SJason Gunthorpe struct mmu_notifier_range;
1499cb252fSJason 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.
3799cb252fSJason Gunthorpe  *
3899cb252fSJason Gunthorpe  * @MMU_NOTIFY_RELEASE: used during mmu_interval_notifier invalidate to signal
3999cb252fSJason 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,
4799cb252fSJason 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 	 */
76*1991722aSJason Gunthorpe 	void (*release)(struct mmu_notifier *subscription,
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 	 */
88*1991722aSJason Gunthorpe 	int (*clear_flush_young)(struct mmu_notifier *subscription,
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 	 */
98*1991722aSJason Gunthorpe 	int (*clear_young)(struct mmu_notifier *subscription,
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 	 */
109*1991722aSJason Gunthorpe 	int (*test_young)(struct mmu_notifier *subscription,
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 	 */
117*1991722aSJason Gunthorpe 	void (*change_pte)(struct mmu_notifier *subscription,
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 	 */
172*1991722aSJason Gunthorpe 	int (*invalidate_range_start)(struct mmu_notifier *subscription,
1735d6527a7SJérôme Glisse 				      const struct mmu_notifier_range *range);
174*1991722aSJason Gunthorpe 	void (*invalidate_range_end)(struct mmu_notifier *subscription,
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 	 */
195*1991722aSJason Gunthorpe 	void (*invalidate_range)(struct mmu_notifier *subscription,
196*1991722aSJason Gunthorpe 				 struct mm_struct *mm,
197*1991722aSJason Gunthorpe 				 unsigned long start,
198*1991722aSJason Gunthorpe 				 unsigned long end);
1992c7933f5SJason Gunthorpe 
2002c7933f5SJason Gunthorpe 	/*
2012c7933f5SJason Gunthorpe 	 * These callbacks are used with the get/put interface to manage the
2022c7933f5SJason Gunthorpe 	 * lifetime of the mmu_notifier memory. alloc_notifier() returns a new
2032c7933f5SJason Gunthorpe 	 * notifier for use with the mm.
2042c7933f5SJason Gunthorpe 	 *
2052c7933f5SJason Gunthorpe 	 * free_notifier() is only called after the mmu_notifier has been
2062c7933f5SJason Gunthorpe 	 * fully put, calls to any ops callback are prevented and no ops
2072c7933f5SJason Gunthorpe 	 * callbacks are currently running. It is called from a SRCU callback
2082c7933f5SJason Gunthorpe 	 * and cannot sleep.
2092c7933f5SJason Gunthorpe 	 */
2102c7933f5SJason Gunthorpe 	struct mmu_notifier *(*alloc_notifier)(struct mm_struct *mm);
211*1991722aSJason Gunthorpe 	void (*free_notifier)(struct mmu_notifier *subscription);
212cddb8a5cSAndrea Arcangeli };
213cddb8a5cSAndrea Arcangeli 
214cddb8a5cSAndrea Arcangeli /*
215cddb8a5cSAndrea Arcangeli  * The notifier chains are protected by mmap_sem and/or the reverse map
216cddb8a5cSAndrea Arcangeli  * semaphores. Notifier chains are only changed when all reverse maps and
217cddb8a5cSAndrea Arcangeli  * the mmap_sem locks are taken.
218cddb8a5cSAndrea Arcangeli  *
219cddb8a5cSAndrea Arcangeli  * Therefore notifier chains can only be traversed when either
220cddb8a5cSAndrea Arcangeli  *
221cddb8a5cSAndrea Arcangeli  * 1. mmap_sem is held.
222c8c06efaSDavidlohr Bueso  * 2. One of the reverse map locks is held (i_mmap_rwsem or anon_vma->rwsem).
223cddb8a5cSAndrea Arcangeli  * 3. No other concurrent thread can access the list (release)
224cddb8a5cSAndrea Arcangeli  */
225cddb8a5cSAndrea Arcangeli struct mmu_notifier {
226cddb8a5cSAndrea Arcangeli 	struct hlist_node hlist;
227cddb8a5cSAndrea Arcangeli 	const struct mmu_notifier_ops *ops;
2282c7933f5SJason Gunthorpe 	struct mm_struct *mm;
2292c7933f5SJason Gunthorpe 	struct rcu_head rcu;
2302c7933f5SJason Gunthorpe 	unsigned int users;
231cddb8a5cSAndrea Arcangeli };
232cddb8a5cSAndrea Arcangeli 
23399cb252fSJason Gunthorpe /**
23499cb252fSJason Gunthorpe  * struct mmu_interval_notifier_ops
23599cb252fSJason Gunthorpe  * @invalidate: Upon return the caller must stop using any SPTEs within this
23699cb252fSJason Gunthorpe  *              range. This function can sleep. Return false only if sleeping
23799cb252fSJason Gunthorpe  *              was required but mmu_notifier_range_blockable(range) is false.
23899cb252fSJason Gunthorpe  */
23999cb252fSJason Gunthorpe struct mmu_interval_notifier_ops {
24099cb252fSJason Gunthorpe 	bool (*invalidate)(struct mmu_interval_notifier *mni,
24199cb252fSJason Gunthorpe 			   const struct mmu_notifier_range *range,
24299cb252fSJason Gunthorpe 			   unsigned long cur_seq);
24399cb252fSJason Gunthorpe };
24499cb252fSJason Gunthorpe 
24599cb252fSJason Gunthorpe struct mmu_interval_notifier {
24699cb252fSJason Gunthorpe 	struct interval_tree_node interval_tree;
24799cb252fSJason Gunthorpe 	const struct mmu_interval_notifier_ops *ops;
24899cb252fSJason Gunthorpe 	struct mm_struct *mm;
24999cb252fSJason Gunthorpe 	struct hlist_node deferred_item;
25099cb252fSJason Gunthorpe 	unsigned long invalidate_seq;
25199cb252fSJason Gunthorpe };
25299cb252fSJason Gunthorpe 
25356f434f4SJason Gunthorpe #ifdef CONFIG_MMU_NOTIFIER
25456f434f4SJason Gunthorpe 
25556f434f4SJason Gunthorpe #ifdef CONFIG_LOCKDEP
25656f434f4SJason Gunthorpe extern struct lockdep_map __mmu_notifier_invalidate_range_start_map;
25756f434f4SJason Gunthorpe #endif
25856f434f4SJason Gunthorpe 
25956f434f4SJason Gunthorpe struct mmu_notifier_range {
26056f434f4SJason Gunthorpe 	struct vm_area_struct *vma;
26156f434f4SJason Gunthorpe 	struct mm_struct *mm;
26256f434f4SJason Gunthorpe 	unsigned long start;
26356f434f4SJason Gunthorpe 	unsigned long end;
26456f434f4SJason Gunthorpe 	unsigned flags;
26556f434f4SJason Gunthorpe 	enum mmu_notifier_event event;
26656f434f4SJason Gunthorpe };
26756f434f4SJason Gunthorpe 
268cddb8a5cSAndrea Arcangeli static inline int mm_has_notifiers(struct mm_struct *mm)
269cddb8a5cSAndrea Arcangeli {
270984cfe4eSJason Gunthorpe 	return unlikely(mm->notifier_subscriptions);
271cddb8a5cSAndrea Arcangeli }
272cddb8a5cSAndrea Arcangeli 
2732c7933f5SJason Gunthorpe struct mmu_notifier *mmu_notifier_get_locked(const struct mmu_notifier_ops *ops,
2742c7933f5SJason Gunthorpe 					     struct mm_struct *mm);
2752c7933f5SJason Gunthorpe static inline struct mmu_notifier *
2762c7933f5SJason Gunthorpe mmu_notifier_get(const struct mmu_notifier_ops *ops, struct mm_struct *mm)
2772c7933f5SJason Gunthorpe {
2782c7933f5SJason Gunthorpe 	struct mmu_notifier *ret;
2792c7933f5SJason Gunthorpe 
2802c7933f5SJason Gunthorpe 	down_write(&mm->mmap_sem);
2812c7933f5SJason Gunthorpe 	ret = mmu_notifier_get_locked(ops, mm);
2822c7933f5SJason Gunthorpe 	up_write(&mm->mmap_sem);
2832c7933f5SJason Gunthorpe 	return ret;
2842c7933f5SJason Gunthorpe }
285*1991722aSJason Gunthorpe void mmu_notifier_put(struct mmu_notifier *subscription);
2862c7933f5SJason Gunthorpe void mmu_notifier_synchronize(void);
2872c7933f5SJason Gunthorpe 
288*1991722aSJason Gunthorpe extern int mmu_notifier_register(struct mmu_notifier *subscription,
289cddb8a5cSAndrea Arcangeli 				 struct mm_struct *mm);
290*1991722aSJason Gunthorpe extern int __mmu_notifier_register(struct mmu_notifier *subscription,
291cddb8a5cSAndrea Arcangeli 				   struct mm_struct *mm);
292*1991722aSJason Gunthorpe extern void mmu_notifier_unregister(struct mmu_notifier *subscription,
293cddb8a5cSAndrea Arcangeli 				    struct mm_struct *mm);
29499cb252fSJason Gunthorpe 
29599cb252fSJason Gunthorpe unsigned long mmu_interval_read_begin(struct mmu_interval_notifier *mni);
29699cb252fSJason Gunthorpe int mmu_interval_notifier_insert(struct mmu_interval_notifier *mni,
29799cb252fSJason Gunthorpe 				 struct mm_struct *mm, unsigned long start,
29899cb252fSJason Gunthorpe 				 unsigned long length,
29999cb252fSJason Gunthorpe 				 const struct mmu_interval_notifier_ops *ops);
30099cb252fSJason Gunthorpe int mmu_interval_notifier_insert_locked(
30199cb252fSJason Gunthorpe 	struct mmu_interval_notifier *mni, struct mm_struct *mm,
30299cb252fSJason Gunthorpe 	unsigned long start, unsigned long length,
30399cb252fSJason Gunthorpe 	const struct mmu_interval_notifier_ops *ops);
30499cb252fSJason Gunthorpe void mmu_interval_notifier_remove(struct mmu_interval_notifier *mni);
30599cb252fSJason Gunthorpe 
30699cb252fSJason Gunthorpe /**
30799cb252fSJason Gunthorpe  * mmu_interval_set_seq - Save the invalidation sequence
30899cb252fSJason Gunthorpe  * @mni - The mni passed to invalidate
30999cb252fSJason Gunthorpe  * @cur_seq - The cur_seq passed to the invalidate() callback
31099cb252fSJason Gunthorpe  *
31199cb252fSJason Gunthorpe  * This must be called unconditionally from the invalidate callback of a
31299cb252fSJason Gunthorpe  * struct mmu_interval_notifier_ops under the same lock that is used to call
31399cb252fSJason Gunthorpe  * mmu_interval_read_retry(). It updates the sequence number for later use by
31499cb252fSJason Gunthorpe  * mmu_interval_read_retry(). The provided cur_seq will always be odd.
31599cb252fSJason Gunthorpe  *
31699cb252fSJason Gunthorpe  * If the caller does not call mmu_interval_read_begin() or
31799cb252fSJason Gunthorpe  * mmu_interval_read_retry() then this call is not required.
31899cb252fSJason Gunthorpe  */
31999cb252fSJason Gunthorpe static inline void mmu_interval_set_seq(struct mmu_interval_notifier *mni,
32099cb252fSJason Gunthorpe 					unsigned long cur_seq)
32199cb252fSJason Gunthorpe {
32299cb252fSJason Gunthorpe 	WRITE_ONCE(mni->invalidate_seq, cur_seq);
32399cb252fSJason Gunthorpe }
32499cb252fSJason Gunthorpe 
32599cb252fSJason Gunthorpe /**
32699cb252fSJason Gunthorpe  * mmu_interval_read_retry - End a read side critical section against a VA range
32799cb252fSJason Gunthorpe  * mni: The range
32899cb252fSJason Gunthorpe  * seq: The return of the paired mmu_interval_read_begin()
32999cb252fSJason Gunthorpe  *
33099cb252fSJason Gunthorpe  * This MUST be called under a user provided lock that is also held
33199cb252fSJason Gunthorpe  * unconditionally by op->invalidate() when it calls mmu_interval_set_seq().
33299cb252fSJason Gunthorpe  *
33399cb252fSJason Gunthorpe  * Each call should be paired with a single mmu_interval_read_begin() and
33499cb252fSJason Gunthorpe  * should be used to conclude the read side.
33599cb252fSJason Gunthorpe  *
33699cb252fSJason Gunthorpe  * Returns true if an invalidation collided with this critical section, and
33799cb252fSJason Gunthorpe  * the caller should retry.
33899cb252fSJason Gunthorpe  */
33999cb252fSJason Gunthorpe static inline bool mmu_interval_read_retry(struct mmu_interval_notifier *mni,
34099cb252fSJason Gunthorpe 					   unsigned long seq)
34199cb252fSJason Gunthorpe {
34299cb252fSJason Gunthorpe 	return mni->invalidate_seq != seq;
34399cb252fSJason Gunthorpe }
34499cb252fSJason Gunthorpe 
34599cb252fSJason Gunthorpe /**
34699cb252fSJason Gunthorpe  * mmu_interval_check_retry - Test if a collision has occurred
34799cb252fSJason Gunthorpe  * mni: The range
34899cb252fSJason Gunthorpe  * seq: The return of the matching mmu_interval_read_begin()
34999cb252fSJason Gunthorpe  *
35099cb252fSJason Gunthorpe  * This can be used in the critical section between mmu_interval_read_begin()
35199cb252fSJason Gunthorpe  * and mmu_interval_read_retry().  A return of true indicates an invalidation
35299cb252fSJason Gunthorpe  * has collided with this critical region and a future
35399cb252fSJason Gunthorpe  * mmu_interval_read_retry() will return true.
35499cb252fSJason Gunthorpe  *
35599cb252fSJason Gunthorpe  * False is not reliable and only suggests a collision may not have
35699cb252fSJason Gunthorpe  * occured. It can be called many times and does not have to hold the user
35799cb252fSJason Gunthorpe  * provided lock.
35899cb252fSJason Gunthorpe  *
35999cb252fSJason Gunthorpe  * This call can be used as part of loops and other expensive operations to
36099cb252fSJason Gunthorpe  * expedite a retry.
36199cb252fSJason Gunthorpe  */
36299cb252fSJason Gunthorpe static inline bool mmu_interval_check_retry(struct mmu_interval_notifier *mni,
36399cb252fSJason Gunthorpe 					    unsigned long seq)
36499cb252fSJason Gunthorpe {
36599cb252fSJason Gunthorpe 	/* Pairs with the WRITE_ONCE in mmu_interval_set_seq() */
36699cb252fSJason Gunthorpe 	return READ_ONCE(mni->invalidate_seq) != seq;
36799cb252fSJason Gunthorpe }
36899cb252fSJason Gunthorpe 
369984cfe4eSJason Gunthorpe extern void __mmu_notifier_subscriptions_destroy(struct mm_struct *mm);
370cddb8a5cSAndrea Arcangeli extern void __mmu_notifier_release(struct mm_struct *mm);
371cddb8a5cSAndrea Arcangeli extern int __mmu_notifier_clear_flush_young(struct mm_struct *mm,
37257128468SAndres Lagar-Cavilla 					  unsigned long start,
37357128468SAndres Lagar-Cavilla 					  unsigned long end);
3741d7715c6SVladimir Davydov extern int __mmu_notifier_clear_young(struct mm_struct *mm,
3751d7715c6SVladimir Davydov 				      unsigned long start,
3761d7715c6SVladimir Davydov 				      unsigned long end);
3778ee53820SAndrea Arcangeli extern int __mmu_notifier_test_young(struct mm_struct *mm,
3788ee53820SAndrea Arcangeli 				     unsigned long address);
379828502d3SIzik Eidus extern void __mmu_notifier_change_pte(struct mm_struct *mm,
380828502d3SIzik Eidus 				      unsigned long address, pte_t pte);
381ac46d4f3SJérôme Glisse extern int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *r);
382ac46d4f3SJérôme Glisse extern void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *r,
3834645b9feSJérôme Glisse 				  bool only_end);
3840f0a327fSJoerg Roedel extern void __mmu_notifier_invalidate_range(struct mm_struct *mm,
3850f0a327fSJoerg Roedel 				  unsigned long start, unsigned long end);
386c6d23413SJérôme Glisse extern bool
387c6d23413SJérôme Glisse mmu_notifier_range_update_to_read_only(const struct mmu_notifier_range *range);
388cddb8a5cSAndrea Arcangeli 
3894a83bfe9SJérôme Glisse static inline bool
3904a83bfe9SJérôme Glisse mmu_notifier_range_blockable(const struct mmu_notifier_range *range)
3914a83bfe9SJérôme Glisse {
39227560ee9SJérôme Glisse 	return (range->flags & MMU_NOTIFIER_RANGE_BLOCKABLE);
3934a83bfe9SJérôme Glisse }
3944a83bfe9SJérôme Glisse 
395cddb8a5cSAndrea Arcangeli static inline void mmu_notifier_release(struct mm_struct *mm)
396cddb8a5cSAndrea Arcangeli {
397cddb8a5cSAndrea Arcangeli 	if (mm_has_notifiers(mm))
398cddb8a5cSAndrea Arcangeli 		__mmu_notifier_release(mm);
399cddb8a5cSAndrea Arcangeli }
400cddb8a5cSAndrea Arcangeli 
401cddb8a5cSAndrea Arcangeli static inline int mmu_notifier_clear_flush_young(struct mm_struct *mm,
40257128468SAndres Lagar-Cavilla 					  unsigned long start,
40357128468SAndres Lagar-Cavilla 					  unsigned long end)
404cddb8a5cSAndrea Arcangeli {
405cddb8a5cSAndrea Arcangeli 	if (mm_has_notifiers(mm))
40657128468SAndres Lagar-Cavilla 		return __mmu_notifier_clear_flush_young(mm, start, end);
407cddb8a5cSAndrea Arcangeli 	return 0;
408cddb8a5cSAndrea Arcangeli }
409cddb8a5cSAndrea Arcangeli 
4101d7715c6SVladimir Davydov static inline int mmu_notifier_clear_young(struct mm_struct *mm,
4111d7715c6SVladimir Davydov 					   unsigned long start,
4121d7715c6SVladimir Davydov 					   unsigned long end)
4131d7715c6SVladimir Davydov {
4141d7715c6SVladimir Davydov 	if (mm_has_notifiers(mm))
4151d7715c6SVladimir Davydov 		return __mmu_notifier_clear_young(mm, start, end);
4161d7715c6SVladimir Davydov 	return 0;
4171d7715c6SVladimir Davydov }
4181d7715c6SVladimir Davydov 
4198ee53820SAndrea Arcangeli static inline int mmu_notifier_test_young(struct mm_struct *mm,
4208ee53820SAndrea Arcangeli 					  unsigned long address)
4218ee53820SAndrea Arcangeli {
4228ee53820SAndrea Arcangeli 	if (mm_has_notifiers(mm))
4238ee53820SAndrea Arcangeli 		return __mmu_notifier_test_young(mm, address);
4248ee53820SAndrea Arcangeli 	return 0;
4258ee53820SAndrea Arcangeli }
4268ee53820SAndrea Arcangeli 
427828502d3SIzik Eidus static inline void mmu_notifier_change_pte(struct mm_struct *mm,
428828502d3SIzik Eidus 					   unsigned long address, pte_t pte)
429828502d3SIzik Eidus {
430828502d3SIzik Eidus 	if (mm_has_notifiers(mm))
431828502d3SIzik Eidus 		__mmu_notifier_change_pte(mm, address, pte);
432828502d3SIzik Eidus }
433828502d3SIzik Eidus 
434ac46d4f3SJérôme Glisse static inline void
435ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range)
436cddb8a5cSAndrea Arcangeli {
437810e24e0SDaniel Vetter 	might_sleep();
438810e24e0SDaniel Vetter 
43923b68395SDaniel Vetter 	lock_map_acquire(&__mmu_notifier_invalidate_range_start_map);
440ac46d4f3SJérôme Glisse 	if (mm_has_notifiers(range->mm)) {
44127560ee9SJérôme Glisse 		range->flags |= MMU_NOTIFIER_RANGE_BLOCKABLE;
442ac46d4f3SJérôme Glisse 		__mmu_notifier_invalidate_range_start(range);
443ac46d4f3SJérôme Glisse 	}
44423b68395SDaniel Vetter 	lock_map_release(&__mmu_notifier_invalidate_range_start_map);
44593065ac7SMichal Hocko }
44693065ac7SMichal Hocko 
447ac46d4f3SJérôme Glisse static inline int
448ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_start_nonblock(struct mmu_notifier_range *range)
44993065ac7SMichal Hocko {
45023b68395SDaniel Vetter 	int ret = 0;
45123b68395SDaniel Vetter 
45223b68395SDaniel Vetter 	lock_map_acquire(&__mmu_notifier_invalidate_range_start_map);
453ac46d4f3SJérôme Glisse 	if (mm_has_notifiers(range->mm)) {
45427560ee9SJérôme Glisse 		range->flags &= ~MMU_NOTIFIER_RANGE_BLOCKABLE;
45523b68395SDaniel Vetter 		ret = __mmu_notifier_invalidate_range_start(range);
456ac46d4f3SJérôme Glisse 	}
45723b68395SDaniel Vetter 	lock_map_release(&__mmu_notifier_invalidate_range_start_map);
45823b68395SDaniel Vetter 	return ret;
459cddb8a5cSAndrea Arcangeli }
460cddb8a5cSAndrea Arcangeli 
461ac46d4f3SJérôme Glisse static inline void
462ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range)
463cddb8a5cSAndrea Arcangeli {
464810e24e0SDaniel Vetter 	if (mmu_notifier_range_blockable(range))
465810e24e0SDaniel Vetter 		might_sleep();
466810e24e0SDaniel Vetter 
467ac46d4f3SJérôme Glisse 	if (mm_has_notifiers(range->mm))
468ac46d4f3SJérôme Glisse 		__mmu_notifier_invalidate_range_end(range, false);
4694645b9feSJérôme Glisse }
4704645b9feSJérôme Glisse 
471ac46d4f3SJérôme Glisse static inline void
472ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_only_end(struct mmu_notifier_range *range)
4734645b9feSJérôme Glisse {
474ac46d4f3SJérôme Glisse 	if (mm_has_notifiers(range->mm))
475ac46d4f3SJérôme Glisse 		__mmu_notifier_invalidate_range_end(range, true);
476cddb8a5cSAndrea Arcangeli }
477cddb8a5cSAndrea Arcangeli 
4781897bdc4SJoerg Roedel static inline void mmu_notifier_invalidate_range(struct mm_struct *mm,
4791897bdc4SJoerg Roedel 				  unsigned long start, unsigned long end)
4801897bdc4SJoerg Roedel {
4810f0a327fSJoerg Roedel 	if (mm_has_notifiers(mm))
4820f0a327fSJoerg Roedel 		__mmu_notifier_invalidate_range(mm, start, end);
4831897bdc4SJoerg Roedel }
4841897bdc4SJoerg Roedel 
485984cfe4eSJason Gunthorpe static inline void mmu_notifier_subscriptions_init(struct mm_struct *mm)
486cddb8a5cSAndrea Arcangeli {
487984cfe4eSJason Gunthorpe 	mm->notifier_subscriptions = NULL;
488cddb8a5cSAndrea Arcangeli }
489cddb8a5cSAndrea Arcangeli 
490984cfe4eSJason Gunthorpe static inline void mmu_notifier_subscriptions_destroy(struct mm_struct *mm)
491cddb8a5cSAndrea Arcangeli {
492cddb8a5cSAndrea Arcangeli 	if (mm_has_notifiers(mm))
493984cfe4eSJason Gunthorpe 		__mmu_notifier_subscriptions_destroy(mm);
494cddb8a5cSAndrea Arcangeli }
495cddb8a5cSAndrea Arcangeli 
496ac46d4f3SJérôme Glisse 
497ac46d4f3SJérôme Glisse static inline void mmu_notifier_range_init(struct mmu_notifier_range *range,
4986f4f13e8SJérôme Glisse 					   enum mmu_notifier_event event,
4996f4f13e8SJérôme Glisse 					   unsigned flags,
5006f4f13e8SJérôme Glisse 					   struct vm_area_struct *vma,
501ac46d4f3SJérôme Glisse 					   struct mm_struct *mm,
502ac46d4f3SJérôme Glisse 					   unsigned long start,
503ac46d4f3SJérôme Glisse 					   unsigned long end)
504ac46d4f3SJérôme Glisse {
505bf198b2bSJérôme Glisse 	range->vma = vma;
506bf198b2bSJérôme Glisse 	range->event = event;
507ac46d4f3SJérôme Glisse 	range->mm = mm;
508ac46d4f3SJérôme Glisse 	range->start = start;
509ac46d4f3SJérôme Glisse 	range->end = end;
510bf198b2bSJérôme Glisse 	range->flags = flags;
511ac46d4f3SJérôme Glisse }
512ac46d4f3SJérôme Glisse 
513cddb8a5cSAndrea Arcangeli #define ptep_clear_flush_young_notify(__vma, __address, __ptep)		\
514cddb8a5cSAndrea Arcangeli ({									\
515cddb8a5cSAndrea Arcangeli 	int __young;							\
516cddb8a5cSAndrea Arcangeli 	struct vm_area_struct *___vma = __vma;				\
517cddb8a5cSAndrea Arcangeli 	unsigned long ___address = __address;				\
518cddb8a5cSAndrea Arcangeli 	__young = ptep_clear_flush_young(___vma, ___address, __ptep);	\
519cddb8a5cSAndrea Arcangeli 	__young |= mmu_notifier_clear_flush_young(___vma->vm_mm,	\
52057128468SAndres Lagar-Cavilla 						  ___address,		\
52157128468SAndres Lagar-Cavilla 						  ___address +		\
52257128468SAndres Lagar-Cavilla 							PAGE_SIZE);	\
523cddb8a5cSAndrea Arcangeli 	__young;							\
524cddb8a5cSAndrea Arcangeli })
525cddb8a5cSAndrea Arcangeli 
52691a4ee26SAndrea Arcangeli #define pmdp_clear_flush_young_notify(__vma, __address, __pmdp)		\
52791a4ee26SAndrea Arcangeli ({									\
52891a4ee26SAndrea Arcangeli 	int __young;							\
52991a4ee26SAndrea Arcangeli 	struct vm_area_struct *___vma = __vma;				\
53091a4ee26SAndrea Arcangeli 	unsigned long ___address = __address;				\
53191a4ee26SAndrea Arcangeli 	__young = pmdp_clear_flush_young(___vma, ___address, __pmdp);	\
53291a4ee26SAndrea Arcangeli 	__young |= mmu_notifier_clear_flush_young(___vma->vm_mm,	\
53357128468SAndres Lagar-Cavilla 						  ___address,		\
53457128468SAndres Lagar-Cavilla 						  ___address +		\
53557128468SAndres Lagar-Cavilla 							PMD_SIZE);	\
53691a4ee26SAndrea Arcangeli 	__young;							\
53791a4ee26SAndrea Arcangeli })
53891a4ee26SAndrea Arcangeli 
5391d7715c6SVladimir Davydov #define ptep_clear_young_notify(__vma, __address, __ptep)		\
5401d7715c6SVladimir Davydov ({									\
5411d7715c6SVladimir Davydov 	int __young;							\
5421d7715c6SVladimir Davydov 	struct vm_area_struct *___vma = __vma;				\
5431d7715c6SVladimir Davydov 	unsigned long ___address = __address;				\
5441d7715c6SVladimir Davydov 	__young = ptep_test_and_clear_young(___vma, ___address, __ptep);\
5451d7715c6SVladimir Davydov 	__young |= mmu_notifier_clear_young(___vma->vm_mm, ___address,	\
5461d7715c6SVladimir Davydov 					    ___address + PAGE_SIZE);	\
5471d7715c6SVladimir Davydov 	__young;							\
5481d7715c6SVladimir Davydov })
5491d7715c6SVladimir Davydov 
5501d7715c6SVladimir Davydov #define pmdp_clear_young_notify(__vma, __address, __pmdp)		\
5511d7715c6SVladimir Davydov ({									\
5521d7715c6SVladimir Davydov 	int __young;							\
5531d7715c6SVladimir Davydov 	struct vm_area_struct *___vma = __vma;				\
5541d7715c6SVladimir Davydov 	unsigned long ___address = __address;				\
5551d7715c6SVladimir Davydov 	__young = pmdp_test_and_clear_young(___vma, ___address, __pmdp);\
5561d7715c6SVladimir Davydov 	__young |= mmu_notifier_clear_young(___vma->vm_mm, ___address,	\
5571d7715c6SVladimir Davydov 					    ___address + PMD_SIZE);	\
5581d7715c6SVladimir Davydov 	__young;							\
5591d7715c6SVladimir Davydov })
5601d7715c6SVladimir Davydov 
56134ee645eSJoerg Roedel #define	ptep_clear_flush_notify(__vma, __address, __ptep)		\
56234ee645eSJoerg Roedel ({									\
56334ee645eSJoerg Roedel 	unsigned long ___addr = __address & PAGE_MASK;			\
56434ee645eSJoerg Roedel 	struct mm_struct *___mm = (__vma)->vm_mm;			\
56534ee645eSJoerg Roedel 	pte_t ___pte;							\
56634ee645eSJoerg Roedel 									\
56734ee645eSJoerg Roedel 	___pte = ptep_clear_flush(__vma, __address, __ptep);		\
56834ee645eSJoerg Roedel 	mmu_notifier_invalidate_range(___mm, ___addr,			\
56934ee645eSJoerg Roedel 					___addr + PAGE_SIZE);		\
57034ee645eSJoerg Roedel 									\
57134ee645eSJoerg Roedel 	___pte;								\
57234ee645eSJoerg Roedel })
57334ee645eSJoerg Roedel 
5748809aa2dSAneesh Kumar K.V #define pmdp_huge_clear_flush_notify(__vma, __haddr, __pmd)		\
57534ee645eSJoerg Roedel ({									\
57634ee645eSJoerg Roedel 	unsigned long ___haddr = __haddr & HPAGE_PMD_MASK;		\
57734ee645eSJoerg Roedel 	struct mm_struct *___mm = (__vma)->vm_mm;			\
57834ee645eSJoerg Roedel 	pmd_t ___pmd;							\
57934ee645eSJoerg Roedel 									\
5808809aa2dSAneesh Kumar K.V 	___pmd = pmdp_huge_clear_flush(__vma, __haddr, __pmd);		\
58134ee645eSJoerg Roedel 	mmu_notifier_invalidate_range(___mm, ___haddr,			\
58234ee645eSJoerg Roedel 				      ___haddr + HPAGE_PMD_SIZE);	\
58334ee645eSJoerg Roedel 									\
58434ee645eSJoerg Roedel 	___pmd;								\
58534ee645eSJoerg Roedel })
58634ee645eSJoerg Roedel 
587a00cc7d9SMatthew Wilcox #define pudp_huge_clear_flush_notify(__vma, __haddr, __pud)		\
588a00cc7d9SMatthew Wilcox ({									\
589a00cc7d9SMatthew Wilcox 	unsigned long ___haddr = __haddr & HPAGE_PUD_MASK;		\
590a00cc7d9SMatthew Wilcox 	struct mm_struct *___mm = (__vma)->vm_mm;			\
591a00cc7d9SMatthew Wilcox 	pud_t ___pud;							\
592a00cc7d9SMatthew Wilcox 									\
593a00cc7d9SMatthew Wilcox 	___pud = pudp_huge_clear_flush(__vma, __haddr, __pud);		\
594a00cc7d9SMatthew Wilcox 	mmu_notifier_invalidate_range(___mm, ___haddr,			\
595a00cc7d9SMatthew Wilcox 				      ___haddr + HPAGE_PUD_SIZE);	\
596a00cc7d9SMatthew Wilcox 									\
597a00cc7d9SMatthew Wilcox 	___pud;								\
598a00cc7d9SMatthew Wilcox })
599a00cc7d9SMatthew Wilcox 
60048af0d7cSXiao Guangrong /*
60148af0d7cSXiao Guangrong  * set_pte_at_notify() sets the pte _after_ running the notifier.
60248af0d7cSXiao Guangrong  * This is safe to start by updating the secondary MMUs, because the primary MMU
60348af0d7cSXiao Guangrong  * pte invalidate must have already happened with a ptep_clear_flush() before
60448af0d7cSXiao Guangrong  * set_pte_at_notify() has been invoked.  Updating the secondary MMUs first is
60548af0d7cSXiao Guangrong  * required when we change both the protection of the mapping from read-only to
60648af0d7cSXiao Guangrong  * read-write and the pfn (like during copy on write page faults). Otherwise the
60748af0d7cSXiao Guangrong  * old page would remain mapped readonly in the secondary MMUs after the new
60848af0d7cSXiao Guangrong  * page is already writable by some CPU through the primary MMU.
60948af0d7cSXiao Guangrong  */
610828502d3SIzik Eidus #define set_pte_at_notify(__mm, __address, __ptep, __pte)		\
611828502d3SIzik Eidus ({									\
612828502d3SIzik Eidus 	struct mm_struct *___mm = __mm;					\
613828502d3SIzik Eidus 	unsigned long ___address = __address;				\
614828502d3SIzik Eidus 	pte_t ___pte = __pte;						\
615828502d3SIzik Eidus 									\
616828502d3SIzik Eidus 	mmu_notifier_change_pte(___mm, ___address, ___pte);		\
61748af0d7cSXiao Guangrong 	set_pte_at(___mm, ___address, __ptep, ___pte);			\
618828502d3SIzik Eidus })
619828502d3SIzik Eidus 
620cddb8a5cSAndrea Arcangeli #else /* CONFIG_MMU_NOTIFIER */
621cddb8a5cSAndrea Arcangeli 
622ac46d4f3SJérôme Glisse struct mmu_notifier_range {
623ac46d4f3SJérôme Glisse 	unsigned long start;
624ac46d4f3SJérôme Glisse 	unsigned long end;
625ac46d4f3SJérôme Glisse };
626ac46d4f3SJérôme Glisse 
627ac46d4f3SJérôme Glisse static inline void _mmu_notifier_range_init(struct mmu_notifier_range *range,
628ac46d4f3SJérôme Glisse 					    unsigned long start,
629ac46d4f3SJérôme Glisse 					    unsigned long end)
630ac46d4f3SJérôme Glisse {
631ac46d4f3SJérôme Glisse 	range->start = start;
632ac46d4f3SJérôme Glisse 	range->end = end;
633ac46d4f3SJérôme Glisse }
634ac46d4f3SJérôme Glisse 
6356f4f13e8SJérôme Glisse #define mmu_notifier_range_init(range,event,flags,vma,mm,start,end)  \
636ac46d4f3SJérôme Glisse 	_mmu_notifier_range_init(range, start, end)
637ac46d4f3SJérôme Glisse 
6384a83bfe9SJérôme Glisse static inline bool
6394a83bfe9SJérôme Glisse mmu_notifier_range_blockable(const struct mmu_notifier_range *range)
6404a83bfe9SJérôme Glisse {
6414a83bfe9SJérôme Glisse 	return true;
6424a83bfe9SJérôme Glisse }
643ac46d4f3SJérôme Glisse 
6444d4bbd85SMichal Hocko static inline int mm_has_notifiers(struct mm_struct *mm)
6454d4bbd85SMichal Hocko {
6464d4bbd85SMichal Hocko 	return 0;
6474d4bbd85SMichal Hocko }
6484d4bbd85SMichal Hocko 
649cddb8a5cSAndrea Arcangeli static inline void mmu_notifier_release(struct mm_struct *mm)
650cddb8a5cSAndrea Arcangeli {
651cddb8a5cSAndrea Arcangeli }
652cddb8a5cSAndrea Arcangeli 
653cddb8a5cSAndrea Arcangeli static inline int mmu_notifier_clear_flush_young(struct mm_struct *mm,
65457128468SAndres Lagar-Cavilla 					  unsigned long start,
65557128468SAndres Lagar-Cavilla 					  unsigned long end)
656cddb8a5cSAndrea Arcangeli {
657cddb8a5cSAndrea Arcangeli 	return 0;
658cddb8a5cSAndrea Arcangeli }
659cddb8a5cSAndrea Arcangeli 
6608ee53820SAndrea Arcangeli static inline int mmu_notifier_test_young(struct mm_struct *mm,
6618ee53820SAndrea Arcangeli 					  unsigned long address)
6628ee53820SAndrea Arcangeli {
6638ee53820SAndrea Arcangeli 	return 0;
6648ee53820SAndrea Arcangeli }
6658ee53820SAndrea Arcangeli 
666828502d3SIzik Eidus static inline void mmu_notifier_change_pte(struct mm_struct *mm,
667828502d3SIzik Eidus 					   unsigned long address, pte_t pte)
668828502d3SIzik Eidus {
669828502d3SIzik Eidus }
670828502d3SIzik Eidus 
671ac46d4f3SJérôme Glisse static inline void
672ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range)
673cddb8a5cSAndrea Arcangeli {
674cddb8a5cSAndrea Arcangeli }
675cddb8a5cSAndrea Arcangeli 
676ac46d4f3SJérôme Glisse static inline int
677ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_start_nonblock(struct mmu_notifier_range *range)
67893065ac7SMichal Hocko {
67993065ac7SMichal Hocko 	return 0;
68093065ac7SMichal Hocko }
68193065ac7SMichal Hocko 
682ac46d4f3SJérôme Glisse static inline
683ac46d4f3SJérôme Glisse void mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range)
684cddb8a5cSAndrea Arcangeli {
685cddb8a5cSAndrea Arcangeli }
686cddb8a5cSAndrea Arcangeli 
687ac46d4f3SJérôme Glisse static inline void
688ac46d4f3SJérôme Glisse mmu_notifier_invalidate_range_only_end(struct mmu_notifier_range *range)
6894645b9feSJérôme Glisse {
6904645b9feSJérôme Glisse }
6914645b9feSJérôme Glisse 
6921897bdc4SJoerg Roedel static inline void mmu_notifier_invalidate_range(struct mm_struct *mm,
6931897bdc4SJoerg Roedel 				  unsigned long start, unsigned long end)
6941897bdc4SJoerg Roedel {
6951897bdc4SJoerg Roedel }
6961897bdc4SJoerg Roedel 
697984cfe4eSJason Gunthorpe static inline void mmu_notifier_subscriptions_init(struct mm_struct *mm)
698cddb8a5cSAndrea Arcangeli {
699cddb8a5cSAndrea Arcangeli }
700cddb8a5cSAndrea Arcangeli 
701984cfe4eSJason Gunthorpe static inline void mmu_notifier_subscriptions_destroy(struct mm_struct *mm)
702cddb8a5cSAndrea Arcangeli {
703cddb8a5cSAndrea Arcangeli }
704cddb8a5cSAndrea Arcangeli 
705c6d23413SJérôme Glisse #define mmu_notifier_range_update_to_read_only(r) false
706c6d23413SJérôme Glisse 
707cddb8a5cSAndrea Arcangeli #define ptep_clear_flush_young_notify ptep_clear_flush_young
70891a4ee26SAndrea Arcangeli #define pmdp_clear_flush_young_notify pmdp_clear_flush_young
70933c3fc71SVladimir Davydov #define ptep_clear_young_notify ptep_test_and_clear_young
71033c3fc71SVladimir Davydov #define pmdp_clear_young_notify pmdp_test_and_clear_young
71134ee645eSJoerg Roedel #define	ptep_clear_flush_notify ptep_clear_flush
7128809aa2dSAneesh Kumar K.V #define pmdp_huge_clear_flush_notify pmdp_huge_clear_flush
713a00cc7d9SMatthew Wilcox #define pudp_huge_clear_flush_notify pudp_huge_clear_flush
714828502d3SIzik Eidus #define set_pte_at_notify set_pte_at
715cddb8a5cSAndrea Arcangeli 
7162c7933f5SJason Gunthorpe static inline void mmu_notifier_synchronize(void)
7172c7933f5SJason Gunthorpe {
7182c7933f5SJason Gunthorpe }
7192c7933f5SJason Gunthorpe 
720cddb8a5cSAndrea Arcangeli #endif /* CONFIG_MMU_NOTIFIER */
721cddb8a5cSAndrea Arcangeli 
722cddb8a5cSAndrea Arcangeli #endif /* _LINUX_MMU_NOTIFIER_H */
723