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

drm/amd/display: Fix system hang after multiple hotplugs (v3)

[Why]
mutex_lock() was introduced in dm_disable_vblank(), which could
be called in an IRQ context. Waiting in IRQ would cause issues
like kernel lockup, etc.

[How]
Handle code that requires mutex lock on a different thread.

v2: squash in compilation fix without CONFIG_DRM_AMD_DC_DCN (Alex)
v3: squash in warning fix (Wei)

Signed-off-by: Qingqing Zhuo <qingqing.zhuo@amd.com>
Acked-by: Bindu Ramamurthy <bindu.r@amd.com>
Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org

authored by

Qingqing Zhuo and committed by
Alex Deucher
d7faf6f5 1e348913

+92 -13
+65 -13
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
··· 938 938 939 939 } 940 940 #endif 941 + #if defined(CONFIG_DRM_AMD_DC_DCN) 942 + static void event_mall_stutter(struct work_struct *work) 943 + { 941 944 945 + struct vblank_workqueue *vblank_work = container_of(work, struct vblank_workqueue, mall_work); 946 + struct amdgpu_display_manager *dm = vblank_work->dm; 947 + 948 + mutex_lock(&dm->dc_lock); 949 + 950 + if (vblank_work->enable) 951 + dm->active_vblank_irq_count++; 952 + else 953 + dm->active_vblank_irq_count--; 954 + 955 + 956 + dc_allow_idle_optimizations( 957 + dm->dc, dm->active_vblank_irq_count == 0 ? true : false); 958 + 959 + DRM_DEBUG_DRIVER("Allow idle optimizations (MALL): %d\n", dm->active_vblank_irq_count == 0); 960 + 961 + 962 + mutex_unlock(&dm->dc_lock); 963 + } 964 + 965 + static struct vblank_workqueue *vblank_create_workqueue(struct amdgpu_device *adev, struct dc *dc) 966 + { 967 + 968 + int max_caps = dc->caps.max_links; 969 + struct vblank_workqueue *vblank_work; 970 + int i = 0; 971 + 972 + vblank_work = kcalloc(max_caps, sizeof(*vblank_work), GFP_KERNEL); 973 + if (ZERO_OR_NULL_PTR(vblank_work)) { 974 + kfree(vblank_work); 975 + return NULL; 976 + } 977 + 978 + for (i = 0; i < max_caps; i++) 979 + INIT_WORK(&vblank_work[i].mall_work, event_mall_stutter); 980 + 981 + return vblank_work; 982 + } 983 + #endif 942 984 static int amdgpu_dm_init(struct amdgpu_device *adev) 943 985 { 944 986 struct dc_init_data init_data; ··· 1000 958 1001 959 mutex_init(&adev->dm.dc_lock); 1002 960 mutex_init(&adev->dm.audio_lock); 961 + #if defined(CONFIG_DRM_AMD_DC_DCN) 962 + spin_lock_init(&adev->dm.vblank_lock); 963 + #endif 1003 964 1004 965 if(amdgpu_dm_irq_init(adev)) { 1005 966 DRM_ERROR("amdgpu: failed to initialize DM IRQ support.\n"); ··· 1116 1071 adev->dm.freesync_module); 1117 1072 1118 1073 amdgpu_dm_init_color_mod(); 1074 + 1075 + #if defined(CONFIG_DRM_AMD_DC_DCN) 1076 + if (adev->dm.dc->caps.max_links > 0) { 1077 + adev->dm.vblank_workqueue = vblank_create_workqueue(adev, adev->dm.dc); 1078 + 1079 + if (!adev->dm.vblank_workqueue) 1080 + DRM_ERROR("amdgpu: failed to initialize vblank_workqueue.\n"); 1081 + else 1082 + DRM_DEBUG_DRIVER("amdgpu: vblank_workqueue init done %p.\n", adev->dm.vblank_workqueue); 1083 + } 1084 + #endif 1119 1085 1120 1086 #ifdef CONFIG_DRM_AMD_DC_HDCP 1121 1087 if (adev->dm.dc->caps.max_links > 0 && adev->asic_type >= CHIP_RAVEN) { ··· 5432 5376 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc); 5433 5377 struct amdgpu_device *adev = drm_to_adev(crtc->dev); 5434 5378 struct dm_crtc_state *acrtc_state = to_dm_crtc_state(crtc->state); 5379 + #if defined(CONFIG_DRM_AMD_DC_DCN) 5435 5380 struct amdgpu_display_manager *dm = &adev->dm; 5381 + unsigned long flags; 5382 + #endif 5436 5383 int rc = 0; 5437 5384 5438 5385 if (enable) { ··· 5458 5399 if (amdgpu_in_reset(adev)) 5459 5400 return 0; 5460 5401 5461 - mutex_lock(&dm->dc_lock); 5462 - 5463 - if (enable) 5464 - dm->active_vblank_irq_count++; 5465 - else 5466 - dm->active_vblank_irq_count--; 5467 - 5468 5402 #if defined(CONFIG_DRM_AMD_DC_DCN) 5469 - dc_allow_idle_optimizations( 5470 - adev->dm.dc, dm->active_vblank_irq_count == 0 ? true : false); 5471 - 5472 - DRM_DEBUG_DRIVER("Allow idle optimizations (MALL): %d\n", dm->active_vblank_irq_count == 0); 5403 + spin_lock_irqsave(&dm->vblank_lock, flags); 5404 + dm->vblank_workqueue->dm = dm; 5405 + dm->vblank_workqueue->otg_inst = acrtc->otg_inst; 5406 + dm->vblank_workqueue->enable = enable; 5407 + spin_unlock_irqrestore(&dm->vblank_lock, flags); 5408 + schedule_work(&dm->vblank_workqueue->mall_work); 5473 5409 #endif 5474 - 5475 - mutex_unlock(&dm->dc_lock); 5476 5410 5477 5411 return 0; 5478 5412 }
+27
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
··· 93 93 }; 94 94 95 95 /** 96 + * struct vblank_workqueue - Works to be executed in a separate thread during vblank 97 + * @mall_work: work for mall stutter 98 + * @dm: amdgpu display manager device 99 + * @otg_inst: otg instance of which vblank is being set 100 + * @enable: true if enable vblank 101 + */ 102 + struct vblank_workqueue { 103 + struct work_struct mall_work; 104 + struct amdgpu_display_manager *dm; 105 + int otg_inst; 106 + bool enable; 107 + }; 108 + 109 + /** 96 110 * struct amdgpu_dm_backlight_caps - Information about backlight 97 111 * 98 112 * Describe the backlight support for ACPI or eDP AUX. ··· 258 244 struct mutex audio_lock; 259 245 260 246 /** 247 + * @vblank_work_lock: 248 + * 249 + * Guards access to deferred vblank work state. 250 + */ 251 + #if defined(CONFIG_DRM_AMD_DC_DCN) 252 + spinlock_t vblank_lock; 253 + #endif 254 + 255 + /** 261 256 * @audio_component: 262 257 * 263 258 * Used to notify ELD changes to sound driver. ··· 342 319 struct mod_freesync *freesync_module; 343 320 #ifdef CONFIG_DRM_AMD_DC_HDCP 344 321 struct hdcp_workqueue *hdcp_workqueue; 322 + #endif 323 + 324 + #if defined(CONFIG_DRM_AMD_DC_DCN) 325 + struct vblank_workqueue *vblank_workqueue; 345 326 #endif 346 327 347 328 struct drm_atomic_state *cached_state;