14 #include <linux/export.h>
19 #include <linux/sched.h>
20 #include <linux/slab.h>
39 struct mmu_notifier *mn;
47 id = srcu_read_lock(&srcu);
48 hlist_for_each_entry_rcu(mn, n, &mm->mmu_notifier_mm->list,
hlist)
57 mn->ops->release(mn, mm);
58 srcu_read_unlock(&srcu,
id);
60 spin_lock(&mm->mmu_notifier_mm->lock);
61 while (
unlikely(!hlist_empty(&mm->mmu_notifier_mm->list))) {
71 hlist_del_init_rcu(&mn->hlist);
73 spin_unlock(&mm->mmu_notifier_mm->lock);
95 struct mmu_notifier *mn;
99 id = srcu_read_lock(&srcu);
100 hlist_for_each_entry_rcu(mn, n, &mm->mmu_notifier_mm->list,
hlist) {
101 if (mn->ops->clear_flush_young)
102 young |= mn->ops->clear_flush_young(mn, mm, address);
104 srcu_read_unlock(&srcu,
id);
112 struct mmu_notifier *mn;
116 id = srcu_read_lock(&srcu);
117 hlist_for_each_entry_rcu(mn, n, &mm->mmu_notifier_mm->list,
hlist) {
118 if (mn->ops->test_young) {
119 young = mn->ops->test_young(mn, mm, address);
124 srcu_read_unlock(&srcu,
id);
132 struct mmu_notifier *mn;
136 id = srcu_read_lock(&srcu);
137 hlist_for_each_entry_rcu(mn, n, &mm->mmu_notifier_mm->list,
hlist) {
138 if (mn->ops->change_pte)
139 mn->ops->change_pte(mn, mm, address, pte);
141 srcu_read_unlock(&srcu,
id);
147 struct mmu_notifier *mn;
151 id = srcu_read_lock(&srcu);
152 hlist_for_each_entry_rcu(mn, n, &mm->mmu_notifier_mm->list,
hlist) {
153 if (mn->ops->invalidate_page)
154 mn->ops->invalidate_page(mn, mm, address);
156 srcu_read_unlock(&srcu,
id);
160 unsigned long start,
unsigned long end)
162 struct mmu_notifier *mn;
166 id = srcu_read_lock(&srcu);
167 hlist_for_each_entry_rcu(mn, n, &mm->mmu_notifier_mm->list,
hlist) {
168 if (mn->ops->invalidate_range_start)
169 mn->ops->invalidate_range_start(mn, mm, start, end);
171 srcu_read_unlock(&srcu,
id);
175 unsigned long start,
unsigned long end)
177 struct mmu_notifier *mn;
181 id = srcu_read_lock(&srcu);
182 hlist_for_each_entry_rcu(mn, n, &mm->mmu_notifier_mm->list,
hlist) {
183 if (mn->ops->invalidate_range_end)
184 mn->ops->invalidate_range_end(mn, mm, start, end);
186 srcu_read_unlock(&srcu,
id);
189 static int do_mmu_notifier_register(
struct mmu_notifier *mn,
193 struct mmu_notifier_mm *mmu_notifier_mm;
202 BUG_ON(!srcu.per_cpu_ref);
215 if (!mm_has_notifiers(mm)) {
219 mm->mmu_notifier_mm = mmu_notifier_mm;
220 mmu_notifier_mm =
NULL;
232 spin_lock(&mm->mmu_notifier_mm->lock);
233 hlist_add_head(&mn->hlist, &mm->mmu_notifier_mm->list);
234 spin_unlock(&mm->mmu_notifier_mm->lock);
240 kfree(mmu_notifier_mm);
261 return do_mmu_notifier_register(mn, mm, 1);
271 return do_mmu_notifier_register(mn, mm, 0);
278 BUG_ON(!hlist_empty(&mm->mmu_notifier_mm->list));
279 kfree(mm->mmu_notifier_mm);
297 if (!hlist_unhashed(&mn->hlist)) {
304 id = srcu_read_lock(&srcu);
310 if (mn->ops->release)
311 mn->ops->release(mn, mm);
312 srcu_read_unlock(&srcu,
id);
314 spin_lock(&mm->mmu_notifier_mm->lock);
315 hlist_del_rcu(&mn->hlist);
316 spin_unlock(&mm->mmu_notifier_mm->lock);
331 static int __init mmu_notifier_init(
void)