From 3379c04cfa11043e26953c784a7202709b19658e Mon Sep 17 00:00:00 2001 From: Daniel Vetter Date: Sat, 15 Jul 2017 11:53:28 +0200 Subject: [PATCH] drm: Don't complain too much about struct_mutex. Git-commit: 3379c04cfa11043e26953c784a7202709b19658e Patch-mainline: v4.14-rc1 References: FATE#322643 bsc#1055900 For modern drivers the DRM core doesn't use struct_mutex at all, which means it's defacto a driver-private lock. But since we still need it for legacy drivers we can't initialize it in drivers, which means all the different instances share one lockdep key. Despite that they might be placed in totally different places in the locking hierarchy. This results in a lot of bogus lockdep splats when running stuff on systems with multiple gpus. Partially remedy the situation by only doing might_lock checks on drivers that do use struct_mutex still for gem locking. A more complete solution would be to do the mutex_init in the drm core only for legacy drivers, plus add it to each modern driver that still needs it, which would also give each its own lockdep key. Trying to do that dynamically doesn't work, because lockdep requires it's keys to be statically allocated. V2: {} everywhere (Chris) Cc: Hans de Goede Cc: Ben Skeggs Cc: Jiri Slaby Cc: Peter Zijlstra Cc: Ingo Molnar Reviewed-by: Chris Wilson Signed-off-by: Daniel Vetter Link: https://patchwork.freedesktop.org/patch/msgid/20170715095328.25671-1-daniel.vetter@ffwll.ch Acked-by: Takashi Iwai --- drivers/gpu/drm/drm_gem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -826,13 +826,15 @@ drm_gem_object_put_unlocked(struct drm_g return; dev = obj->dev; - might_lock(&dev->struct_mutex); - if (dev->driver->gem_free_object_unlocked) + if (dev->driver->gem_free_object_unlocked) { kref_put(&obj->refcount, drm_gem_object_free); - else if (kref_put_mutex(&obj->refcount, drm_gem_object_free, + } else { + might_lock(&dev->struct_mutex); + if (kref_put_mutex(&obj->refcount, drm_gem_object_free, &dev->struct_mutex)) - mutex_unlock(&dev->struct_mutex); + mutex_unlock(&dev->struct_mutex); + } } EXPORT_SYMBOL(drm_gem_object_put_unlocked);