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

drm/modeset-lock: Take the modeset BKL for legacy drivers

This fell off in the conversion in

commit 9bcaa3fe58ab7559e71df798bcff6e0795158695
Author: Michal Orzel <michalorzel.eng@gmail.com>
Date: Tue Apr 28 19:10:04 2020 +0200

drm: Replace drm_modeset_lock/unlock_all with DRM_MODESET_LOCK_ALL_* helpers

but it's caught by the drm_warn_on_modeset_not_all_locked() that the
legacy modeset code uses. Since this is the bkl and it's unclear
what's all protected, play it safe and grab it again for legacy
drivers.

Unfortunately this means we need to sprinkle a few more #includes
around.

Also we need to add the drm_device as a parameter to the _END macro.

Finally remove the mute_lock() from setcrtc, since that's now done by
the macro.

Cc: Alex Deucher <alexdeucher@gmail.com>
References: https://gitlab.freedesktop.org/drm/amd/-/issues/1224
Fixes: 9bcaa3fe58ab ("drm: Replace drm_modeset_lock/unlock_all with DRM_MODESET_LOCK_ALL_* helpers")
Cc: Michal Orzel <michalorzel.eng@gmail.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: <stable@vger.kernel.org> # v5.8+
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200814093842.3048472-1-daniel.vetter@ffwll.ch

authored by

Daniel Vetter and committed by
Alex Deucher
77ef3857 88fee1c9

+16 -12
+4 -3
drivers/gpu/drm/drm_atomic_helper.c
··· 34 34 #include <drm/drm_bridge.h> 35 35 #include <drm/drm_damage_helper.h> 36 36 #include <drm/drm_device.h> 37 + #include <drm/drm_drv.h> 37 38 #include <drm/drm_plane_helper.h> 38 39 #include <drm/drm_print.h> 39 40 #include <drm/drm_self_refresh_helper.h> ··· 3106 3105 if (ret) 3107 3106 DRM_ERROR("Disabling all crtc's during unload failed with %i\n", ret); 3108 3107 3109 - DRM_MODESET_LOCK_ALL_END(ctx, ret); 3108 + DRM_MODESET_LOCK_ALL_END(dev, ctx, ret); 3110 3109 } 3111 3110 EXPORT_SYMBOL(drm_atomic_helper_shutdown); 3112 3111 ··· 3246 3245 } 3247 3246 3248 3247 unlock: 3249 - DRM_MODESET_LOCK_ALL_END(ctx, err); 3248 + DRM_MODESET_LOCK_ALL_END(dev, ctx, err); 3250 3249 if (err) 3251 3250 return ERR_PTR(err); 3252 3251 ··· 3327 3326 3328 3327 err = drm_atomic_helper_commit_duplicated_state(state, &ctx); 3329 3328 3330 - DRM_MODESET_LOCK_ALL_END(ctx, err); 3329 + DRM_MODESET_LOCK_ALL_END(dev, ctx, err); 3331 3330 drm_atomic_state_put(state); 3332 3331 3333 3332 return err;
+1 -1
drivers/gpu/drm/drm_color_mgmt.c
··· 294 294 crtc->gamma_size, &ctx); 295 295 296 296 out: 297 - DRM_MODESET_LOCK_ALL_END(ctx, ret); 297 + DRM_MODESET_LOCK_ALL_END(dev, ctx, ret); 298 298 return ret; 299 299 300 300 }
+1 -3
drivers/gpu/drm/drm_crtc.c
··· 561 561 if (crtc_req->mode_valid && !drm_lease_held(file_priv, plane->base.id)) 562 562 return -EACCES; 563 563 564 - mutex_lock(&crtc->dev->mode_config.mutex); 565 564 DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 566 565 DRM_MODESET_ACQUIRE_INTERRUPTIBLE, ret); 567 566 ··· 727 728 fb = NULL; 728 729 mode = NULL; 729 730 730 - DRM_MODESET_LOCK_ALL_END(ctx, ret); 731 - mutex_unlock(&crtc->dev->mode_config.mutex); 731 + DRM_MODESET_LOCK_ALL_END(dev, ctx, ret); 732 732 733 733 return ret; 734 734 }
+2 -2
drivers/gpu/drm/drm_mode_object.c
··· 428 428 out_unref: 429 429 drm_mode_object_put(obj); 430 430 out: 431 - DRM_MODESET_LOCK_ALL_END(ctx, ret); 431 + DRM_MODESET_LOCK_ALL_END(dev, ctx, ret); 432 432 return ret; 433 433 } 434 434 ··· 470 470 break; 471 471 } 472 472 drm_property_change_valid_put(prop, ref); 473 - DRM_MODESET_LOCK_ALL_END(ctx, ret); 473 + DRM_MODESET_LOCK_ALL_END(dev, ctx, ret); 474 474 475 475 return ret; 476 476 }
+1 -1
drivers/gpu/drm/drm_plane.c
··· 791 791 crtc_x, crtc_y, crtc_w, crtc_h, 792 792 src_x, src_y, src_w, src_h, &ctx); 793 793 794 - DRM_MODESET_LOCK_ALL_END(ctx, ret); 794 + DRM_MODESET_LOCK_ALL_END(plane->dev, ctx, ret); 795 795 796 796 return ret; 797 797 }
+7 -2
include/drm/drm_modeset_lock.h
··· 164 164 * is 0, so no error checking is necessary 165 165 */ 166 166 #define DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, flags, ret) \ 167 + if (!drm_drv_uses_atomic_modeset(dev)) \ 168 + mutex_lock(&dev->mode_config.mutex); \ 167 169 drm_modeset_acquire_init(&ctx, flags); \ 168 170 modeset_lock_retry: \ 169 171 ret = drm_modeset_lock_all_ctx(dev, &ctx); \ ··· 174 172 175 173 /** 176 174 * DRM_MODESET_LOCK_ALL_END - Helper to release and cleanup modeset locks 175 + * @dev: drm device 177 176 * @ctx: local modeset acquire context, will be dereferenced 178 177 * @ret: local ret/err/etc variable to track error status 179 178 * ··· 191 188 * to that failure. In both of these cases the code between BEGIN/END will not 192 189 * be run, so the failure will reflect the inability to grab the locks. 193 190 */ 194 - #define DRM_MODESET_LOCK_ALL_END(ctx, ret) \ 191 + #define DRM_MODESET_LOCK_ALL_END(dev, ctx, ret) \ 195 192 modeset_lock_fail: \ 196 193 if (ret == -EDEADLK) { \ 197 194 ret = drm_modeset_backoff(&ctx); \ ··· 199 196 goto modeset_lock_retry; \ 200 197 } \ 201 198 drm_modeset_drop_locks(&ctx); \ 202 - drm_modeset_acquire_fini(&ctx); 199 + drm_modeset_acquire_fini(&ctx); \ 200 + if (!drm_drv_uses_atomic_modeset(dev)) \ 201 + mutex_unlock(&dev->mode_config.mutex); 203 202 204 203 #endif /* DRM_MODESET_LOCK_H_ */