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