Skip to content

Commit 1d2ac40

Browse files
committed
drm: Protect dev->filelist with its own mutex
amdgpu gained dev->struct_mutex usage, and that's because it's walking the dev->filelist list. Protect that list with it's own lock to take one more step towards getting rid of struct_mutex usage in drivers once and for all. While doing the conversion I noticed that 2 debugfs files in i915 completely lacked appropriate locking. Fix that up too. v2: don't forget to switch to drm_gem_object_unreference_unlocked. Cc: Alex Deucher <[email protected]> Reviewed-by: Alex Deucher <[email protected]> Reviewed-by: Chris Wilson <[email protected]> Signed-off-by: Daniel Vetter <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent f47dbdd commit 1d2ac40

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void amdgpu_gem_force_release(struct amdgpu_device *adev)
9393
struct drm_device *ddev = adev->ddev;
9494
struct drm_file *file;
9595

96-
mutex_lock(&ddev->struct_mutex);
96+
mutex_lock(&ddev->filelist_mutex);
9797

9898
list_for_each_entry(file, &ddev->filelist, lhead) {
9999
struct drm_gem_object *gobj;
@@ -103,13 +103,13 @@ void amdgpu_gem_force_release(struct amdgpu_device *adev)
103103
spin_lock(&file->table_lock);
104104
idr_for_each_entry(&file->object_idr, gobj, handle) {
105105
WARN_ONCE(1, "And also active allocations!\n");
106-
drm_gem_object_unreference(gobj);
106+
drm_gem_object_unreference_unlocked(gobj);
107107
}
108108
idr_destroy(&file->object_idr);
109109
spin_unlock(&file->table_lock);
110110
}
111111

112-
mutex_unlock(&ddev->struct_mutex);
112+
mutex_unlock(&ddev->filelist_mutex);
113113
}
114114

115115
/*
@@ -769,7 +769,7 @@ static int amdgpu_debugfs_gem_info(struct seq_file *m, void *data)
769769
struct drm_file *file;
770770
int r;
771771

772-
r = mutex_lock_interruptible(&dev->struct_mutex);
772+
r = mutex_lock_interruptible(&dev->filelist_mutex);
773773
if (r)
774774
return r;
775775

@@ -793,7 +793,7 @@ static int amdgpu_debugfs_gem_info(struct seq_file *m, void *data)
793793
spin_unlock(&file->table_lock);
794794
}
795795

796-
mutex_unlock(&dev->struct_mutex);
796+
mutex_unlock(&dev->filelist_mutex);
797797
return 0;
798798
}
799799

drivers/gpu/drm/drm_drv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver,
590590
spin_lock_init(&dev->buf_lock);
591591
spin_lock_init(&dev->event_lock);
592592
mutex_init(&dev->struct_mutex);
593+
mutex_init(&dev->filelist_mutex);
593594
mutex_init(&dev->ctxlist_mutex);
594595
mutex_init(&dev->master_mutex);
595596

drivers/gpu/drm/drm_fops.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ static int drm_open_helper(struct file *filp, struct drm_minor *minor)
297297
}
298298
mutex_unlock(&dev->master_mutex);
299299

300-
mutex_lock(&dev->struct_mutex);
300+
mutex_lock(&dev->filelist_mutex);
301301
list_add(&priv->lhead, &dev->filelist);
302-
mutex_unlock(&dev->struct_mutex);
302+
mutex_unlock(&dev->filelist_mutex);
303303

304304
#ifdef __alpha__
305305
/*
@@ -447,8 +447,11 @@ int drm_release(struct inode *inode, struct file *filp)
447447

448448
DRM_DEBUG("open_count = %d\n", dev->open_count);
449449

450-
mutex_lock(&dev->struct_mutex);
450+
mutex_lock(&dev->filelist_mutex);
451451
list_del(&file_priv->lhead);
452+
mutex_unlock(&dev->filelist_mutex);
453+
454+
mutex_lock(&dev->struct_mutex);
452455
if (file_priv->magic)
453456
idr_remove(&file_priv->master->magic_map, file_priv->magic);
454457
mutex_unlock(&dev->struct_mutex);

drivers/gpu/drm/drm_info.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ int drm_clients_info(struct seq_file *m, void *data)
174174
/* dev->filelist is sorted youngest first, but we want to present
175175
* oldest first (i.e. kernel, servers, clients), so walk backwardss.
176176
*/
177-
mutex_lock(&dev->struct_mutex);
177+
mutex_lock(&dev->filelist_mutex);
178178
list_for_each_entry_reverse(priv, &dev->filelist, lhead) {
179179
struct task_struct *task;
180180

@@ -190,7 +190,7 @@ int drm_clients_info(struct seq_file *m, void *data)
190190
priv->magic);
191191
rcu_read_unlock();
192192
}
193-
mutex_unlock(&dev->struct_mutex);
193+
mutex_unlock(&dev->filelist_mutex);
194194
return 0;
195195
}
196196

drivers/gpu/drm/i915/i915_debugfs.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ static int i915_gem_object_info(struct seq_file *m, void* data)
498498

499499
seq_putc(m, '\n');
500500
print_batch_pool_stats(m, dev_priv);
501+
502+
mutex_unlock(&dev->struct_mutex);
503+
504+
mutex_lock(&dev->filelist_mutex);
501505
list_for_each_entry_reverse(file, &dev->filelist, lhead) {
502506
struct file_stats stats;
503507
struct task_struct *task;
@@ -518,8 +522,7 @@ static int i915_gem_object_info(struct seq_file *m, void* data)
518522
print_file_stats(m, task ? task->comm : "<unknown>", stats);
519523
rcu_read_unlock();
520524
}
521-
522-
mutex_unlock(&dev->struct_mutex);
525+
mutex_unlock(&dev->filelist_mutex);
523526

524527
return 0;
525528
}
@@ -2325,6 +2328,7 @@ static int i915_ppgtt_info(struct seq_file *m, void *data)
23252328
else if (INTEL_INFO(dev)->gen >= 6)
23262329
gen6_ppgtt_info(m, dev);
23272330

2331+
mutex_lock(&dev->filelist_mutex);
23282332
list_for_each_entry_reverse(file, &dev->filelist, lhead) {
23292333
struct drm_i915_file_private *file_priv = file->driver_priv;
23302334
struct task_struct *task;
@@ -2339,6 +2343,7 @@ static int i915_ppgtt_info(struct seq_file *m, void *data)
23392343
idr_for_each(&file_priv->context_idr, per_file_ctx,
23402344
(void *)(unsigned long)m);
23412345
}
2346+
mutex_unlock(&dev->filelist_mutex);
23422347

23432348
out_put:
23442349
intel_runtime_pm_put(dev_priv);
@@ -2374,6 +2379,8 @@ static int i915_rps_boost_info(struct seq_file *m, void *data)
23742379
intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
23752380
intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
23762381
intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
2382+
2383+
mutex_lock(&dev->filelist_mutex);
23772384
spin_lock(&dev_priv->rps.client_lock);
23782385
list_for_each_entry_reverse(file, &dev->filelist, lhead) {
23792386
struct drm_i915_file_private *file_priv = file->driver_priv;
@@ -2396,6 +2403,7 @@ static int i915_rps_boost_info(struct seq_file *m, void *data)
23962403
list_empty(&dev_priv->rps.mmioflips.link) ? "" : ", active");
23972404
seq_printf(m, "Kernel boosts: %d\n", dev_priv->rps.boosts);
23982405
spin_unlock(&dev_priv->rps.client_lock);
2406+
mutex_unlock(&dev->filelist_mutex);
23992407

24002408
return 0;
24012409
}

include/drm/drmP.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ struct drm_device {
769769
atomic_t buf_alloc; /**< Buffer allocation in progress */
770770
/*@} */
771771

772+
struct mutex filelist_mutex;
772773
struct list_head filelist;
773774

774775
/** \name Memory management */

0 commit comments

Comments
 (0)