Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2016 Intel Corporation. |
| 3 | * |
| 4 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 5 | * redistributing this file, you may do so under either license. |
| 6 | * |
| 7 | * GPL LICENSE SUMMARY |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of version 2 of the GNU General Public License as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * BSD LICENSE |
| 19 | * |
| 20 | * Redistribution and use in source and binary forms, with or without |
| 21 | * modification, are permitted provided that the following conditions |
| 22 | * are met: |
| 23 | * |
| 24 | * - Redistributions of source code must retain the above copyright |
| 25 | * notice, this list of conditions and the following disclaimer. |
| 26 | * - Redistributions in binary form must reproduce the above copyright |
| 27 | * notice, this list of conditions and the following disclaimer in |
| 28 | * the documentation and/or other materials provided with the |
| 29 | * distribution. |
| 30 | * - Neither the name of Intel Corporation nor the names of its |
| 31 | * contributors may be used to endorse or promote products derived |
| 32 | * from this software without specific prior written permission. |
| 33 | * |
| 34 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 35 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 37 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 38 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 39 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 40 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 41 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 42 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 43 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 44 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 45 | * |
| 46 | */ |
| 47 | #include <linux/list.h> |
Mitko Haralanov | 67caea1 | 2016-05-12 10:23:09 -0700 | [diff] [blame] | 48 | #include <linux/rculist.h> |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 49 | #include <linux/mmu_notifier.h> |
Mitko Haralanov | df5a00f8 | 2016-03-08 11:14:53 -0800 | [diff] [blame] | 50 | #include <linux/interval_tree_generic.h> |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 51 | |
| 52 | #include "mmu_rb.h" |
| 53 | #include "trace.h" |
| 54 | |
| 55 | struct mmu_rb_handler { |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 56 | struct mmu_notifier mn; |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 57 | struct rb_root root; |
| 58 | void *ops_arg; |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 59 | spinlock_t lock; /* protect the RB tree */ |
| 60 | struct mmu_rb_ops *ops; |
Ira Weiny | 3faa3d9 | 2016-07-28 15:21:19 -0400 | [diff] [blame] | 61 | struct mm_struct *mm; |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 62 | }; |
| 63 | |
Mitko Haralanov | df5a00f8 | 2016-03-08 11:14:53 -0800 | [diff] [blame] | 64 | static unsigned long mmu_node_start(struct mmu_rb_node *); |
| 65 | static unsigned long mmu_node_last(struct mmu_rb_node *); |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 66 | static inline void mmu_notifier_page(struct mmu_notifier *, struct mm_struct *, |
| 67 | unsigned long); |
| 68 | static inline void mmu_notifier_range_start(struct mmu_notifier *, |
| 69 | struct mm_struct *, |
| 70 | unsigned long, unsigned long); |
| 71 | static void mmu_notifier_mem_invalidate(struct mmu_notifier *, |
Mitko Haralanov | f19bd64 | 2016-04-12 10:45:57 -0700 | [diff] [blame] | 72 | struct mm_struct *, |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 73 | unsigned long, unsigned long); |
| 74 | static struct mmu_rb_node *__mmu_rb_search(struct mmu_rb_handler *, |
| 75 | unsigned long, unsigned long); |
| 76 | |
| 77 | static struct mmu_notifier_ops mn_opts = { |
| 78 | .invalidate_page = mmu_notifier_page, |
| 79 | .invalidate_range_start = mmu_notifier_range_start, |
| 80 | }; |
| 81 | |
Mitko Haralanov | df5a00f8 | 2016-03-08 11:14:53 -0800 | [diff] [blame] | 82 | INTERVAL_TREE_DEFINE(struct mmu_rb_node, node, unsigned long, __last, |
| 83 | mmu_node_start, mmu_node_last, static, __mmu_int_rb); |
| 84 | |
| 85 | static unsigned long mmu_node_start(struct mmu_rb_node *node) |
| 86 | { |
| 87 | return node->addr & PAGE_MASK; |
| 88 | } |
| 89 | |
| 90 | static unsigned long mmu_node_last(struct mmu_rb_node *node) |
| 91 | { |
Mitko Haralanov | de79093 | 2016-04-12 10:46:41 -0700 | [diff] [blame] | 92 | return PAGE_ALIGN(node->addr + node->len) - 1; |
Mitko Haralanov | df5a00f8 | 2016-03-08 11:14:53 -0800 | [diff] [blame] | 93 | } |
| 94 | |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 95 | int hfi1_mmu_rb_register(void *ops_arg, struct mm_struct *mm, |
| 96 | struct mmu_rb_ops *ops, |
| 97 | struct mmu_rb_handler **handler) |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 98 | { |
| 99 | struct mmu_rb_handler *handlr; |
Ira Weiny | 3faa3d9 | 2016-07-28 15:21:19 -0400 | [diff] [blame] | 100 | int ret; |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 101 | |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 102 | handlr = kmalloc(sizeof(*handlr), GFP_KERNEL); |
| 103 | if (!handlr) |
| 104 | return -ENOMEM; |
| 105 | |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 106 | handlr->root = RB_ROOT; |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 107 | handlr->ops = ops; |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 108 | handlr->ops_arg = ops_arg; |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 109 | INIT_HLIST_NODE(&handlr->mn.hlist); |
| 110 | spin_lock_init(&handlr->lock); |
| 111 | handlr->mn.ops = &mn_opts; |
Ira Weiny | 3faa3d9 | 2016-07-28 15:21:19 -0400 | [diff] [blame] | 112 | handlr->mm = mm; |
| 113 | |
| 114 | ret = mmu_notifier_register(&handlr->mn, handlr->mm); |
| 115 | if (ret) { |
| 116 | kfree(handlr); |
| 117 | return ret; |
| 118 | } |
| 119 | |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 120 | *handler = handlr; |
| 121 | return 0; |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 124 | void hfi1_mmu_rb_unregister(struct mmu_rb_handler *handler) |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 125 | { |
Dean Luick | 20a42d0 | 2016-07-28 12:27:36 -0400 | [diff] [blame] | 126 | struct mmu_rb_node *rbnode; |
| 127 | struct rb_node *node; |
Mitko Haralanov | c81e1f6 | 2016-03-08 11:14:25 -0800 | [diff] [blame] | 128 | unsigned long flags; |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 129 | |
Mitko Haralanov | 782f669 | 2016-04-12 10:46:35 -0700 | [diff] [blame] | 130 | /* Unregister first so we don't get any more notifications. */ |
Ira Weiny | 3faa3d9 | 2016-07-28 15:21:19 -0400 | [diff] [blame] | 131 | mmu_notifier_unregister(&handler->mn, handler->mm); |
Mitko Haralanov | 782f669 | 2016-04-12 10:46:35 -0700 | [diff] [blame] | 132 | |
Mitko Haralanov | 782f669 | 2016-04-12 10:46:35 -0700 | [diff] [blame] | 133 | spin_lock_irqsave(&handler->lock, flags); |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 134 | while ((node = rb_first(&handler->root))) { |
Dean Luick | 20a42d0 | 2016-07-28 12:27:36 -0400 | [diff] [blame] | 135 | rbnode = rb_entry(node, struct mmu_rb_node, node); |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 136 | rb_erase(node, &handler->root); |
| 137 | handler->ops->remove(handler->ops_arg, rbnode, |
| 138 | NULL); |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 139 | } |
Mitko Haralanov | 782f669 | 2016-04-12 10:46:35 -0700 | [diff] [blame] | 140 | spin_unlock_irqrestore(&handler->lock, flags); |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 141 | |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 142 | kfree(handler); |
| 143 | } |
| 144 | |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 145 | int hfi1_mmu_rb_insert(struct mmu_rb_handler *handler, |
| 146 | struct mmu_rb_node *mnode) |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 147 | { |
Mitko Haralanov | df5a00f8 | 2016-03-08 11:14:53 -0800 | [diff] [blame] | 148 | struct mmu_rb_node *node; |
Mitko Haralanov | c81e1f6 | 2016-03-08 11:14:25 -0800 | [diff] [blame] | 149 | unsigned long flags; |
Mitko Haralanov | df5a00f8 | 2016-03-08 11:14:53 -0800 | [diff] [blame] | 150 | int ret = 0; |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 151 | |
Mitko Haralanov | c81e1f6 | 2016-03-08 11:14:25 -0800 | [diff] [blame] | 152 | spin_lock_irqsave(&handler->lock, flags); |
Mitko Haralanov | 353b71c | 2016-03-08 11:14:59 -0800 | [diff] [blame] | 153 | hfi1_cdbg(MMU, "Inserting node addr 0x%llx, len %u", mnode->addr, |
| 154 | mnode->len); |
Mitko Haralanov | df5a00f8 | 2016-03-08 11:14:53 -0800 | [diff] [blame] | 155 | node = __mmu_rb_search(handler, mnode->addr, mnode->len); |
| 156 | if (node) { |
| 157 | ret = -EINVAL; |
| 158 | goto unlock; |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 159 | } |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 160 | __mmu_int_rb_insert(mnode, &handler->root); |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 161 | |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 162 | ret = handler->ops->insert(handler->ops_arg, mnode); |
Dean Luick | c094664 | 2016-07-28 12:27:30 -0400 | [diff] [blame] | 163 | if (ret) |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 164 | __mmu_int_rb_remove(mnode, &handler->root); |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 165 | unlock: |
Mitko Haralanov | c81e1f6 | 2016-03-08 11:14:25 -0800 | [diff] [blame] | 166 | spin_unlock_irqrestore(&handler->lock, flags); |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 167 | return ret; |
| 168 | } |
| 169 | |
Mitko Haralanov | de82bdf | 2016-04-12 10:46:03 -0700 | [diff] [blame] | 170 | /* Caller must hold handler lock */ |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 171 | static struct mmu_rb_node *__mmu_rb_search(struct mmu_rb_handler *handler, |
| 172 | unsigned long addr, |
| 173 | unsigned long len) |
| 174 | { |
Mitko Haralanov | 0f310a00 | 2016-03-08 11:15:10 -0800 | [diff] [blame] | 175 | struct mmu_rb_node *node = NULL; |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 176 | |
Mitko Haralanov | 353b71c | 2016-03-08 11:14:59 -0800 | [diff] [blame] | 177 | hfi1_cdbg(MMU, "Searching for addr 0x%llx, len %u", addr, len); |
Mitko Haralanov | 0f310a00 | 2016-03-08 11:15:10 -0800 | [diff] [blame] | 178 | if (!handler->ops->filter) { |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 179 | node = __mmu_int_rb_iter_first(&handler->root, addr, |
Mitko Haralanov | 0f310a00 | 2016-03-08 11:15:10 -0800 | [diff] [blame] | 180 | (addr + len) - 1); |
| 181 | } else { |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 182 | for (node = __mmu_int_rb_iter_first(&handler->root, addr, |
Mitko Haralanov | 0f310a00 | 2016-03-08 11:15:10 -0800 | [diff] [blame] | 183 | (addr + len) - 1); |
| 184 | node; |
| 185 | node = __mmu_int_rb_iter_next(node, addr, |
| 186 | (addr + len) - 1)) { |
| 187 | if (handler->ops->filter(node, addr, len)) |
| 188 | return node; |
| 189 | } |
| 190 | } |
Mitko Haralanov | df5a00f8 | 2016-03-08 11:14:53 -0800 | [diff] [blame] | 191 | return node; |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 192 | } |
| 193 | |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 194 | struct mmu_rb_node *hfi1_mmu_rb_extract(struct mmu_rb_handler *handler, |
Mitko Haralanov | f53af85 | 2016-04-12 10:46:47 -0700 | [diff] [blame] | 195 | unsigned long addr, unsigned long len) |
| 196 | { |
Mitko Haralanov | f53af85 | 2016-04-12 10:46:47 -0700 | [diff] [blame] | 197 | struct mmu_rb_node *node; |
| 198 | unsigned long flags; |
| 199 | |
Mitko Haralanov | f53af85 | 2016-04-12 10:46:47 -0700 | [diff] [blame] | 200 | spin_lock_irqsave(&handler->lock, flags); |
| 201 | node = __mmu_rb_search(handler, addr, len); |
| 202 | if (node) |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 203 | __mmu_int_rb_remove(node, &handler->root); |
Mitko Haralanov | f53af85 | 2016-04-12 10:46:47 -0700 | [diff] [blame] | 204 | spin_unlock_irqrestore(&handler->lock, flags); |
| 205 | |
| 206 | return node; |
| 207 | } |
| 208 | |
Dean Luick | 1034599 | 2016-07-28 15:21:22 -0400 | [diff] [blame^] | 209 | void hfi1_mmu_rb_evict(struct mmu_rb_handler *handler, void *evict_arg) |
| 210 | { |
| 211 | struct mmu_rb_node *rbnode; |
| 212 | struct rb_node *node, *next; |
| 213 | struct list_head del_list; |
| 214 | unsigned long flags; |
| 215 | bool stop = false; |
| 216 | |
| 217 | INIT_LIST_HEAD(&del_list); |
| 218 | |
| 219 | spin_lock_irqsave(&handler->lock, flags); |
| 220 | for (node = rb_first(&handler->root); node; node = next) { |
| 221 | next = rb_next(node); |
| 222 | rbnode = rb_entry(node, struct mmu_rb_node, node); |
| 223 | if (handler->ops->evict(handler->ops_arg, rbnode, evict_arg, |
| 224 | &stop)) { |
| 225 | __mmu_int_rb_remove(rbnode, &handler->root); |
| 226 | list_add(&rbnode->list, &del_list); |
| 227 | } |
| 228 | if (stop) |
| 229 | break; |
| 230 | } |
| 231 | spin_unlock_irqrestore(&handler->lock, flags); |
| 232 | |
| 233 | down_write(&handler->mm->mmap_sem); |
| 234 | while (!list_empty(&del_list)) { |
| 235 | rbnode = list_first_entry(&del_list, struct mmu_rb_node, list); |
| 236 | list_del(&rbnode->list); |
| 237 | handler->ops->remove(handler->ops_arg, rbnode, |
| 238 | handler->mm); |
| 239 | } |
| 240 | up_write(&handler->mm->mmap_sem); |
| 241 | } |
| 242 | |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 243 | void hfi1_mmu_rb_remove(struct mmu_rb_handler *handler, |
| 244 | struct mmu_rb_node *node) |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 245 | { |
Ira Weiny | 3c1091aa | 2016-07-28 12:27:31 -0400 | [diff] [blame] | 246 | unsigned long flags; |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 247 | |
Ira Weiny | 3c1091aa | 2016-07-28 12:27:31 -0400 | [diff] [blame] | 248 | /* Validity of handler and node pointers has been checked by caller. */ |
| 249 | hfi1_cdbg(MMU, "Removing node addr 0x%llx, len %u", node->addr, |
| 250 | node->len); |
| 251 | spin_lock_irqsave(&handler->lock, flags); |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 252 | __mmu_int_rb_remove(node, &handler->root); |
Ira Weiny | 3c1091aa | 2016-07-28 12:27:31 -0400 | [diff] [blame] | 253 | spin_unlock_irqrestore(&handler->lock, flags); |
| 254 | |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 255 | handler->ops->remove(handler->ops_arg, node, NULL); |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | static inline void mmu_notifier_page(struct mmu_notifier *mn, |
| 259 | struct mm_struct *mm, unsigned long addr) |
| 260 | { |
Mitko Haralanov | f19bd64 | 2016-04-12 10:45:57 -0700 | [diff] [blame] | 261 | mmu_notifier_mem_invalidate(mn, mm, addr, addr + PAGE_SIZE); |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | static inline void mmu_notifier_range_start(struct mmu_notifier *mn, |
| 265 | struct mm_struct *mm, |
| 266 | unsigned long start, |
| 267 | unsigned long end) |
| 268 | { |
Mitko Haralanov | f19bd64 | 2016-04-12 10:45:57 -0700 | [diff] [blame] | 269 | mmu_notifier_mem_invalidate(mn, mm, start, end); |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | static void mmu_notifier_mem_invalidate(struct mmu_notifier *mn, |
Mitko Haralanov | f19bd64 | 2016-04-12 10:45:57 -0700 | [diff] [blame] | 273 | struct mm_struct *mm, |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 274 | unsigned long start, unsigned long end) |
| 275 | { |
| 276 | struct mmu_rb_handler *handler = |
| 277 | container_of(mn, struct mmu_rb_handler, mn); |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 278 | struct rb_root *root = &handler->root; |
Mitko Haralanov | f19bd64 | 2016-04-12 10:45:57 -0700 | [diff] [blame] | 279 | struct mmu_rb_node *node, *ptr = NULL; |
Mitko Haralanov | df5a00f8 | 2016-03-08 11:14:53 -0800 | [diff] [blame] | 280 | unsigned long flags; |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 281 | |
Mitko Haralanov | c81e1f6 | 2016-03-08 11:14:25 -0800 | [diff] [blame] | 282 | spin_lock_irqsave(&handler->lock, flags); |
Mitko Haralanov | f19bd64 | 2016-04-12 10:45:57 -0700 | [diff] [blame] | 283 | for (node = __mmu_int_rb_iter_first(root, start, end - 1); |
| 284 | node; node = ptr) { |
| 285 | /* Guard against node removal. */ |
| 286 | ptr = __mmu_int_rb_iter_next(node, start, end - 1); |
Mitko Haralanov | 353b71c | 2016-03-08 11:14:59 -0800 | [diff] [blame] | 287 | hfi1_cdbg(MMU, "Invalidating node addr 0x%llx, len %u", |
| 288 | node->addr, node->len); |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 289 | if (handler->ops->invalidate(handler->ops_arg, node)) { |
Mitko Haralanov | e88c927 | 2016-04-12 10:46:53 -0700 | [diff] [blame] | 290 | __mmu_int_rb_remove(node, root); |
Dean Luick | e0b09ac | 2016-07-28 15:21:20 -0400 | [diff] [blame] | 291 | handler->ops->remove(handler->ops_arg, node, mm); |
Mitko Haralanov | de82bdf | 2016-04-12 10:46:03 -0700 | [diff] [blame] | 292 | } |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 293 | } |
Mitko Haralanov | c81e1f6 | 2016-03-08 11:14:25 -0800 | [diff] [blame] | 294 | spin_unlock_irqrestore(&handler->lock, flags); |
Mitko Haralanov | 06e0ffa | 2016-03-08 11:14:20 -0800 | [diff] [blame] | 295 | } |