The DRM core depends on mm->mmap_sem being the outer lock in order to
setup/teardown and utilize fault handlers. If we taint the mm->mmap_sem
as soon as we open the device for a process, we can define this proper
ordering for lockdep and so it will report any violations early.

Signed-off-by: Chris Wilson <ch...@chris-wilson.co.uk>
---
 drivers/gpu/drm/drm_fops.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
index aeef58ed359b..a95d588c24c8 100644
--- a/drivers/gpu/drm/drm_fops.c
+++ b/drivers/gpu/drm/drm_fops.c
@@ -246,6 +246,19 @@ static int drm_open_helper(struct file *filp, struct 
drm_minor *minor)
 
        DRM_DEBUG("pid = %d, minor = %d\n", task_pid_nr(current), minor->index);
 
+       if (IS_ENABLED(CONFIG_LOCKDEP)) {
+               /* We depend upon the strict order of mmap_sem outside of
+                * struct_mutex in order for the fault handlers and their
+                * setup/teardown. Taint mmap_sem as early as possible in
+                * order to define the proper order and flag ABBA errors
+                * should the order ever be inverted.
+                */
+               down_write(&current->mm->mmap_sem);
+               mutex_lock(&dev->struct_mutex);
+               mutex_unlock(&dev->struct_mutex);
+               up_write(&current->mm->mmap_sem);
+       }
+
        priv = kzalloc(sizeof(*priv), GFP_KERNEL);
        if (!priv)
                return -ENOMEM;
-- 
2.7.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to