Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/i915: Introduce i915_address_space.mutex

Add a mutex into struct i915_address_space to be used while operating on
the vma and their lists for a particular vm. As this may be called from
the shrinker, we taint the mutex with fs_reclaim so that from the start
lockdep warns us if we are caught holding the mutex across an
allocation. (With such small steps we will eventually rid ourselves of
struct_mutex recursion!)

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20180711073608.20286-2-chris@chris-wilson.co.uk

+25 -1
+1 -1
drivers/gpu/drm/i915/i915_drv.h
··· 3307 3307 unsigned long i915_gem_shrink_all(struct drm_i915_private *i915); 3308 3308 void i915_gem_shrinker_register(struct drm_i915_private *i915); 3309 3309 void i915_gem_shrinker_unregister(struct drm_i915_private *i915); 3310 - 3310 + void i915_gem_shrinker_taints_mutex(struct mutex *mutex); 3311 3311 3312 3312 /* i915_gem_tiling.c */ 3313 3313 static inline bool i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_object *obj)
+10
drivers/gpu/drm/i915/i915_gem_gtt.c
··· 531 531 static void i915_address_space_init(struct i915_address_space *vm, 532 532 struct drm_i915_private *dev_priv) 533 533 { 534 + /* 535 + * The vm->mutex must be reclaim safe (for use in the shrinker). 536 + * Do a dummy acquire now under fs_reclaim so that any allocation 537 + * attempt holding the lock is immediately reported by lockdep. 538 + */ 539 + mutex_init(&vm->mutex); 540 + i915_gem_shrinker_taints_mutex(&vm->mutex); 541 + 534 542 GEM_BUG_ON(!vm->total); 535 543 drm_mm_init(&vm->mm, 0, vm->total); 536 544 vm->mm.head_node.color = I915_COLOR_UNEVICTABLE; ··· 559 551 spin_unlock(&vm->free_pages.lock); 560 552 561 553 drm_mm_takedown(&vm->mm); 554 + 555 + mutex_destroy(&vm->mutex); 562 556 } 563 557 564 558 static int __setup_page_dma(struct i915_address_space *vm,
+2
drivers/gpu/drm/i915/i915_gem_gtt.h
··· 293 293 294 294 bool closed; 295 295 296 + struct mutex mutex; /* protects vma and our lists */ 297 + 296 298 struct i915_page_dma scratch_page; 297 299 struct i915_page_table *scratch_pt; 298 300 struct i915_page_directory *scratch_pd;
+12
drivers/gpu/drm/i915/i915_gem_shrinker.c
··· 23 23 */ 24 24 25 25 #include <linux/oom.h> 26 + #include <linux/sched/mm.h> 26 27 #include <linux/shmem_fs.h> 27 28 #include <linux/slab.h> 28 29 #include <linux/swap.h> ··· 531 530 WARN_ON(unregister_vmap_purge_notifier(&i915->mm.vmap_notifier)); 532 531 WARN_ON(unregister_oom_notifier(&i915->mm.oom_notifier)); 533 532 unregister_shrinker(&i915->mm.shrinker); 533 + } 534 + 535 + void i915_gem_shrinker_taints_mutex(struct mutex *mutex) 536 + { 537 + if (!IS_ENABLED(CONFIG_LOCKDEP)) 538 + return; 539 + 540 + fs_reclaim_acquire(GFP_KERNEL); 541 + mutex_lock(mutex); 542 + mutex_unlock(mutex); 543 + fs_reclaim_release(GFP_KERNEL); 534 544 }