Skip to content

Commit e835d51

Browse files
tobiasjakobialexdeucher
authored andcommitted
drm/amd/display: Avoid race between dcn35_set_drr() and dc_state_destruct()
dc_state_destruct() nulls the resource context of the DC state. The pipe context passed to dcn35_set_drr() is a member of this resource context. If dc_state_destruct() is called parallel to the IRQ processing (which calls dcn35_set_drr() at some point), we can end up using already nulled function callback fields of struct stream_resource. The logic in dcn35_set_drr() already tries to avoid this, by checking tg against NULL. But if the nulling happens exactly after the NULL check and before the next access, then we get a race. Avoid this by copying tg first to a local variable, and then use this variable for all the operations. This should work, as long as nobody frees the resource pool where the timing generators live. Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3142 Fixes: 06ad7e1 ("drm/amd/display: Destroy DC context while keeping DML and DML2") Signed-off-by: Tobias Jakobi <[email protected]> Reviewed-by: Harry Wentland <[email protected]> Signed-off-by: Mario Limonciello <[email protected]> Signed-off-by: Alex Deucher <[email protected]> (cherry picked from commit 0607a50) Cc: [email protected]
1 parent a7aeb03 commit e835d51

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

drivers/gpu/drm/amd/display/dc/hwss/dcn35/dcn35_hwseq.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,13 @@ void dcn35_set_drr(struct pipe_ctx **pipe_ctx,
14621462
params.vertical_total_mid_frame_num = adjust.v_total_mid_frame_num;
14631463

14641464
for (i = 0; i < num_pipes; i++) {
1465-
if ((pipe_ctx[i]->stream_res.tg != NULL) && pipe_ctx[i]->stream_res.tg->funcs) {
1465+
/* dc_state_destruct() might null the stream resources, so fetch tg
1466+
* here first to avoid a race condition. The lifetime of the pointee
1467+
* itself (the timing_generator object) is not a problem here.
1468+
*/
1469+
struct timing_generator *tg = pipe_ctx[i]->stream_res.tg;
1470+
1471+
if ((tg != NULL) && tg->funcs) {
14661472
struct dc_crtc_timing *timing = &pipe_ctx[i]->stream->timing;
14671473
struct dc *dc = pipe_ctx[i]->stream->ctx->dc;
14681474

@@ -1475,14 +1481,12 @@ void dcn35_set_drr(struct pipe_ctx **pipe_ctx,
14751481
num_frames = 2 * (frame_rate % 60);
14761482
}
14771483
}
1478-
if (pipe_ctx[i]->stream_res.tg->funcs->set_drr)
1479-
pipe_ctx[i]->stream_res.tg->funcs->set_drr(
1480-
pipe_ctx[i]->stream_res.tg, &params);
1484+
if (tg->funcs->set_drr)
1485+
tg->funcs->set_drr(tg, &params);
14811486
if (adjust.v_total_max != 0 && adjust.v_total_min != 0)
1482-
if (pipe_ctx[i]->stream_res.tg->funcs->set_static_screen_control)
1483-
pipe_ctx[i]->stream_res.tg->funcs->set_static_screen_control(
1484-
pipe_ctx[i]->stream_res.tg,
1485-
event_triggers, num_frames);
1487+
if (tg->funcs->set_static_screen_control)
1488+
tg->funcs->set_static_screen_control(
1489+
tg, event_triggers, num_frames);
14861490
}
14871491
}
14881492
}

0 commit comments

Comments
 (0)