Use the mmu_notifier_range_blockable() helper function instead of directly dereferencing the range->blockable field. This is done to make it easier to change the mmu_notifier range field. This patch is the outcome of the following coccinelle patch: %<------------------------------------------------------------------- @@ identifier I1, FN; @@ FN(..., struct mmu_notifier_range *I1, ...) { <... -I1->blockable +mmu_notifier_range_blockable(I1) ...> } ------------------------------------------------------------------->% spatch --in-place --sp-file blockable.spatch --dir .
Unified · Split
| @@ -256,14 +256,14 @@ static int amdgpu_mn_invalidate_range_start_gfx(struct mmu_notifier *mn, · 255 unmodified lines | ||
| 256 | 256 | /* TODO we should be able to split locking for interval tree and |
| 257 | 257 | * amdgpu_mn_invalidate_node |
| 258 | 258 | */ |
| 259 | − if (amdgpu_mn_read_lock(amn, range->blockable)) | |
| 259 | + if (amdgpu_mn_read_lock(amn, mmu_notifier_range_blockable(range))) | |
| 260 | 260 | return -EAGAIN; |
| 261 | 261 | |
| 262 | 262 | it = interval_tree_iter_first(&amn->objects, range->start, end); |
| 263 | 263 | while (it) { |
| 264 | 264 | struct amdgpu_mn_node *node; |
| 265 | 265 | |
| 266 | − if (!range->blockable) { | |
| 266 | + if (!mmu_notifier_range_blockable(range)) { | |
| 267 | 267 | amdgpu_mn_read_unlock(amn); |
| 268 | 268 | return -EAGAIN; |
| 269 | 269 | } |
| @@ -299,7 +299,7 @@ static int amdgpu_mn_invalidate_range_start_hsa(struct mmu_notifier *mn, · 29 unmodified lines | ||
| 299 | 299 | /* notification is exclusive, but interval is inclusive */ |
| 300 | 300 | end = range->end - 1; |
| 301 | 301 | |
| 302 | − if (amdgpu_mn_read_lock(amn, range->blockable)) | |
| 302 | + if (amdgpu_mn_read_lock(amn, mmu_notifier_range_blockable(range))) | |
| 303 | 303 | return -EAGAIN; |
| 304 | 304 | |
| 305 | 305 | it = interval_tree_iter_first(&amn->objects, range->start, end); |
| @@ -307,7 +307,7 @@ static int amdgpu_mn_invalidate_range_start_hsa(struct mmu_notifier *mn, · 1 unmodified line | ||
| 307 | 307 | struct amdgpu_mn_node *node; |
| 308 | 308 | struct amdgpu_bo *bo; |
| 309 | 309 | |
| 310 | − if (!range->blockable) { | |
| 310 | + if (!mmu_notifier_range_blockable(range)) { | |
| 311 | 311 | amdgpu_mn_read_unlock(amn); |
| 312 | 312 | return -EAGAIN; |
| 313 | 313 | } |
| @@ -122,7 +122,7 @@ userptr_mn_invalidate_range_start(struct mmu_notifier *_mn, · 121 unmodified lines | ||
| 122 | 122 | while (it) { |
| 123 | 123 | struct drm_i915_gem_object *obj; |
| 124 | 124 | |
| 125 | − if (!range->blockable) { | |
| 125 | + if (!mmu_notifier_range_blockable(range)) { | |
| 126 | 126 | ret = -EAGAIN; |
| 127 | 127 | break; |
| 128 | 128 | } |
| @@ -133,7 +133,7 @@ static int radeon_mn_invalidate_range_start(struct mmu_notifier *mn, · 132 unmodified lines | ||
| 133 | 133 | /* TODO we should be able to split locking for interval tree and |
| 134 | 134 | * the tear down. |
| 135 | 135 | */ |
| 136 | − if (range->blockable) | |
| 136 | + if (mmu_notifier_range_blockable(range)) | |
| 137 | 137 | mutex_lock(&rmn->lock); |
| 138 | 138 | else if (!mutex_trylock(&rmn->lock)) |
| 139 | 139 | return -EAGAIN; |
| @@ -144,7 +144,7 @@ static int radeon_mn_invalidate_range_start(struct mmu_notifier *mn, · 4 unmodified lines | ||
| 144 | 144 | struct radeon_bo *bo; |
| 145 | 145 | long r; |
| 146 | 146 | |
| 147 | − if (!range->blockable) { | |
| 147 | + if (!mmu_notifier_range_blockable(range)) { | |
| 148 | 148 | ret = -EAGAIN; |
| 149 | 149 | goto out_unlock; |
| 150 | 150 | } |
| @@ -152,7 +152,7 @@ static int ib_umem_notifier_invalidate_range_start(struct mmu_notifier *mn, · 151 unmodified lines | ||
| 152 | 152 | struct ib_ucontext_per_mm *per_mm = |
| 153 | 153 | container_of(mn, struct ib_ucontext_per_mm, mn); |
| 154 | 154 | |
| 155 | − if (range->blockable) | |
| 155 | + if (mmu_notifier_range_blockable(range)) | |
| 156 | 156 | down_read(&per_mm->umem_rwsem); |
| 157 | 157 | else if (!down_read_trylock(&per_mm->umem_rwsem)) |
| 158 | 158 | return -EAGAIN; |
| @@ -170,7 +170,8 @@ static int ib_umem_notifier_invalidate_range_start(struct mmu_notifier *mn, · 11 unmodified lines | ||
| 170 | 170 | return rbt_ib_umem_for_each_in_range(&per_mm->umem_tree, range->start, |
| 171 | 171 | range->end, |
| 172 | 172 | invalidate_range_start_trampoline, |
| 173 | − range->blockable, NULL); | |
| 173 | + mmu_notifier_range_blockable(range), | |
| 174 | + NULL); | |
| 174 | 175 | } |
| 175 | 176 | |
| 176 | 177 | static int invalidate_range_end_trampoline(struct ib_umem_odp *item, u64 start, |
| @@ -526,20 +526,20 @@ static int mn_invl_range_start(struct mmu_notifier *mn, · 525 unmodified lines | ||
| 526 | 526 | struct gntdev_grant_map *map; |
| 527 | 527 | int ret = 0; |
| 528 | 528 | |
| 529 | − if (range->blockable) | |
| 529 | + if (mmu_notifier_range_blockable(range)) | |
| 530 | 530 | mutex_lock(&priv->lock); |
| 531 | 531 | else if (!mutex_trylock(&priv->lock)) |
| 532 | 532 | return -EAGAIN; |
| 533 | 533 | |
| 534 | 534 | list_for_each_entry(map, &priv->maps, next) { |
| 535 | 535 | ret = unmap_if_in_range(map, range->start, range->end, |
| 536 | − range->blockable); | |
| 536 | + mmu_notifier_range_blockable(range)); | |
| 537 | 537 | if (ret) |
| 538 | 538 | goto out_unlock; |
| 539 | 539 | } |
| 540 | 540 | list_for_each_entry(map, &priv->freeable_maps, next) { |
| 541 | 541 | ret = unmap_if_in_range(map, range->start, range->end, |
| 542 | − range->blockable); | |
| 542 | + mmu_notifier_range_blockable(range)); | |
| 543 | 543 | if (ret) |
| 544 | 544 | goto out_unlock; |
| 545 | 545 | } |
| @@ -205,9 +205,9 @@ static int hmm_invalidate_range_start(struct mmu_notifier *mn, · 204 unmodified lines | ||
| 205 | 205 | update.start = nrange->start; |
| 206 | 206 | update.end = nrange->end; |
| 207 | 207 | update.event = HMM_UPDATE_INVALIDATE; |
| 208 | − update.blockable = nrange->blockable; | |
| 208 | + update.blockable = mmu_notifier_range_blockable(nrange); | |
| 209 | 209 | |
| 210 | − if (nrange->blockable) | |
| 210 | + if (mmu_notifier_range_blockable(nrange)) | |
| 211 | 211 | mutex_lock(&hmm->lock); |
| 212 | 212 | else if (!mutex_trylock(&hmm->lock)) { |
| 213 | 213 | ret = -EAGAIN; |
| @@ -222,7 +222,7 @@ static int hmm_invalidate_range_start(struct mmu_notifier *mn, · 8 unmodified lines | ||
| 222 | 222 | } |
| 223 | 223 | mutex_unlock(&hmm->lock); |
| 224 | 224 | |
| 225 | − if (nrange->blockable) | |
| 225 | + if (mmu_notifier_range_blockable(nrange)) | |
| 226 | 226 | down_read(&hmm->mirrors_sem); |
| 227 | 227 | else if (!down_read_trylock(&hmm->mirrors_sem)) { |
| 228 | 228 | ret = -EAGAIN; |
| @@ -180,7 +180,7 @@ int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) · 179 unmodified lines | ||
| 180 | 180 | if (_ret) { |
| 181 | 181 | pr_info("%pS callback failed with %d in %sblockable context.\n", |
| 182 | 182 | mn->ops->invalidate_range_start, _ret, |
| 183 | − !range->blockable ? "non-" : ""); | |
| 183 | + !mmu_notifier_range_blockable(range) ? "non-" : ""); | |
| 184 | 184 | ret = _ret; |
| 185 | 185 | } |
| 186 | 186 | } |
| @@ -391,7 +391,8 @@ static int kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn, · 390 unmodified lines | ||
| 391 | 391 | spin_unlock(&kvm->mmu_lock); |
| 392 | 392 | |
| 393 | 393 | ret = kvm_arch_mmu_notifier_invalidate_range(kvm, range->start, |
| 394 | − range->end, range->blockable); | |
| 394 | + range->end, | |
| 395 | + mmu_notifier_range_blockable(range)); | |
| 395 | 396 | |
| 396 | 397 | srcu_read_unlock(&kvm->srcu, idx); |
| 397 | 398 | |