Skip to content

Commit ea3b424

Browse files
lillizhuo-amdalexdeucher
authored andcommitted
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 <[email protected]> Acked-by: Bindu Ramamurthy <[email protected]> Tested-by: Daniel Wheeler <[email protected]> Signed-off-by: Alex Deucher <[email protected]> Cc: [email protected]
1 parent b092b19 commit ea3b424

File tree

2 files changed

+92
-13
lines changed

2 files changed

+92
-13
lines changed

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,49 @@ static void mmhub_read_system_context(struct amdgpu_device *adev, struct dc_phy_
937937

938938
}
939939
#endif
940+
#if defined(CONFIG_DRM_AMD_DC_DCN)
941+
static void event_mall_stutter(struct work_struct *work)
942+
{
943+
944+
struct vblank_workqueue *vblank_work = container_of(work, struct vblank_workqueue, mall_work);
945+
struct amdgpu_display_manager *dm = vblank_work->dm;
946+
947+
mutex_lock(&dm->dc_lock);
948+
949+
if (vblank_work->enable)
950+
dm->active_vblank_irq_count++;
951+
else
952+
dm->active_vblank_irq_count--;
953+
954+
955+
dc_allow_idle_optimizations(
956+
dm->dc, dm->active_vblank_irq_count == 0 ? true : false);
957+
958+
DRM_DEBUG_DRIVER("Allow idle optimizations (MALL): %d\n", dm->active_vblank_irq_count == 0);
959+
960+
961+
mutex_unlock(&dm->dc_lock);
962+
}
963+
964+
static struct vblank_workqueue *vblank_create_workqueue(struct amdgpu_device *adev, struct dc *dc)
965+
{
966+
967+
int max_caps = dc->caps.max_links;
968+
struct vblank_workqueue *vblank_work;
969+
int i = 0;
970+
971+
vblank_work = kcalloc(max_caps, sizeof(*vblank_work), GFP_KERNEL);
972+
if (ZERO_OR_NULL_PTR(vblank_work)) {
973+
kfree(vblank_work);
974+
return NULL;
975+
}
940976

977+
for (i = 0; i < max_caps; i++)
978+
INIT_WORK(&vblank_work[i].mall_work, event_mall_stutter);
979+
980+
return vblank_work;
981+
}
982+
#endif
941983
static int amdgpu_dm_init(struct amdgpu_device *adev)
942984
{
943985
struct dc_init_data init_data;
@@ -957,6 +999,9 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)
957999

9581000
mutex_init(&adev->dm.dc_lock);
9591001
mutex_init(&adev->dm.audio_lock);
1002+
#if defined(CONFIG_DRM_AMD_DC_DCN)
1003+
spin_lock_init(&adev->dm.vblank_lock);
1004+
#endif
9601005

9611006
if(amdgpu_dm_irq_init(adev)) {
9621007
DRM_ERROR("amdgpu: failed to initialize DM IRQ support.\n");
@@ -1071,6 +1116,17 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)
10711116

10721117
amdgpu_dm_init_color_mod();
10731118

1119+
#if defined(CONFIG_DRM_AMD_DC_DCN)
1120+
if (adev->dm.dc->caps.max_links > 0) {
1121+
adev->dm.vblank_workqueue = vblank_create_workqueue(adev, adev->dm.dc);
1122+
1123+
if (!adev->dm.vblank_workqueue)
1124+
DRM_ERROR("amdgpu: failed to initialize vblank_workqueue.\n");
1125+
else
1126+
DRM_DEBUG_DRIVER("amdgpu: vblank_workqueue init done %p.\n", adev->dm.vblank_workqueue);
1127+
}
1128+
#endif
1129+
10741130
#ifdef CONFIG_DRM_AMD_DC_HDCP
10751131
if (adev->dm.dc->caps.max_links > 0 && adev->asic_type >= CHIP_RAVEN) {
10761132
adev->dm.hdcp_workqueue = hdcp_create_workqueue(adev, &init_params.cp_psp, adev->dm.dc);
@@ -5375,7 +5431,10 @@ static inline int dm_set_vblank(struct drm_crtc *crtc, bool enable)
53755431
struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
53765432
struct amdgpu_device *adev = drm_to_adev(crtc->dev);
53775433
struct dm_crtc_state *acrtc_state = to_dm_crtc_state(crtc->state);
5434+
#if defined(CONFIG_DRM_AMD_DC_DCN)
53785435
struct amdgpu_display_manager *dm = &adev->dm;
5436+
unsigned long flags;
5437+
#endif
53795438
int rc = 0;
53805439

53815440
if (enable) {
@@ -5398,22 +5457,15 @@ static inline int dm_set_vblank(struct drm_crtc *crtc, bool enable)
53985457
if (amdgpu_in_reset(adev))
53995458
return 0;
54005459

5401-
mutex_lock(&dm->dc_lock);
5402-
5403-
if (enable)
5404-
dm->active_vblank_irq_count++;
5405-
else
5406-
dm->active_vblank_irq_count--;
5407-
54085460
#if defined(CONFIG_DRM_AMD_DC_DCN)
5409-
dc_allow_idle_optimizations(
5410-
adev->dm.dc, dm->active_vblank_irq_count == 0 ? true : false);
5411-
5412-
DRM_DEBUG_DRIVER("Allow idle optimizations (MALL): %d\n", dm->active_vblank_irq_count == 0);
5461+
spin_lock_irqsave(&dm->vblank_lock, flags);
5462+
dm->vblank_workqueue->dm = dm;
5463+
dm->vblank_workqueue->otg_inst = acrtc->otg_inst;
5464+
dm->vblank_workqueue->enable = enable;
5465+
spin_unlock_irqrestore(&dm->vblank_lock, flags);
5466+
schedule_work(&dm->vblank_workqueue->mall_work);
54135467
#endif
54145468

5415-
mutex_unlock(&dm->dc_lock);
5416-
54175469
return 0;
54185470
}
54195471

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,20 @@ struct dm_compressor_info {
9292
uint64_t gpu_addr;
9393
};
9494

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+
95109
/**
96110
* struct amdgpu_dm_backlight_caps - Information about backlight
97111
*
@@ -243,6 +257,15 @@ struct amdgpu_display_manager {
243257
*/
244258
struct mutex audio_lock;
245259

260+
/**
261+
* @vblank_work_lock:
262+
*
263+
* Guards access to deferred vblank work state.
264+
*/
265+
#if defined(CONFIG_DRM_AMD_DC_DCN)
266+
spinlock_t vblank_lock;
267+
#endif
268+
246269
/**
247270
* @audio_component:
248271
*
@@ -321,6 +344,10 @@ struct amdgpu_display_manager {
321344
struct hdcp_workqueue *hdcp_workqueue;
322345
#endif
323346

347+
#if defined(CONFIG_DRM_AMD_DC_DCN)
348+
struct vblank_workqueue *vblank_workqueue;
349+
#endif
350+
324351
struct drm_atomic_state *cached_state;
325352
struct dc_state *cached_dc_state;
326353

0 commit comments

Comments
 (0)