Skip to content

Commit eaf3adb

Browse files
Aurabindo Pillaialexdeucher
Aurabindo Pillai
authored andcommitted
drm/amd/display: fix a UBSAN warning in DML2.1
When programming phantom pipe, since cursor_width is explicity set to 0, this causes calculation logic to trigger overflow for an unsigned int triggering the kernel's UBSAN check as below: [ 40.962845] UBSAN: shift-out-of-bounds in /tmp/amd.EfpumTkO/amd/amdgpu/../display/dc/dml2/dml21/src/dml2_core/dml2_core_dcn4_calcs.c:3312:34 [ 40.962849] shift exponent 4294967170 is too large for 32-bit type 'unsigned int' [ 40.962852] CPU: 1 PID: 1670 Comm: gnome-shell Tainted: G W OE 6.5.0-41-generic #41~22.04.2-Ubuntu [ 40.962854] Hardware name: Gigabyte Technology Co., Ltd. X670E AORUS PRO X/X670E AORUS PRO X, BIOS F21 01/10/2024 [ 40.962856] Call Trace: [ 40.962857] <TASK> [ 40.962860] dump_stack_lvl+0x48/0x70 [ 40.962870] dump_stack+0x10/0x20 [ 40.962872] __ubsan_handle_shift_out_of_bounds+0x1ac/0x360 [ 40.962878] calculate_cursor_req_attributes.cold+0x1b/0x28 [amdgpu] [ 40.963099] dml_core_mode_support+0x6b91/0x16bc0 [amdgpu] [ 40.963327] ? srso_alias_return_thunk+0x5/0x7f [ 40.963331] ? CalculateWatermarksMALLUseAndDRAMSpeedChangeSupport+0x18b8/0x2790 [amdgpu] [ 40.963534] ? srso_alias_return_thunk+0x5/0x7f [ 40.963536] ? dml_core_mode_support+0xb3db/0x16bc0 [amdgpu] [ 40.963730] dml2_core_calcs_mode_support_ex+0x2c/0x90 [amdgpu] [ 40.963906] ? srso_alias_return_thunk+0x5/0x7f [ 40.963909] ? dml2_core_calcs_mode_support_ex+0x2c/0x90 [amdgpu] [ 40.964078] core_dcn4_mode_support+0x72/0xbf0 [amdgpu] [ 40.964247] dml2_top_optimization_perform_optimization_phase+0x1d3/0x2a0 [amdgpu] [ 40.964420] dml2_build_mode_programming+0x23d/0x750 [amdgpu] [ 40.964587] dml21_validate+0x274/0x770 [amdgpu] [ 40.964761] ? srso_alias_return_thunk+0x5/0x7f [ 40.964763] ? resource_append_dpp_pipes_for_plane_composition+0x27c/0x3b0 [amdgpu] [ 40.964942] dml2_validate+0x504/0x750 [amdgpu] [ 40.965117] ? dml21_copy+0x95/0xb0 [amdgpu] [ 40.965291] ? srso_alias_return_thunk+0x5/0x7f [ 40.965295] dcn401_validate_bandwidth+0x4e/0x70 [amdgpu] [ 40.965491] update_planes_and_stream_state+0x38d/0x5c0 [amdgpu] [ 40.965672] update_planes_and_stream_v3+0x52/0x1e0 [amdgpu] [ 40.965845] ? srso_alias_return_thunk+0x5/0x7f [ 40.965849] dc_update_planes_and_stream+0x71/0xb0 [amdgpu] Fix this by adding a guard for checking cursor width before triggering the size calculation. Reviewed-by: Rodrigo Siqueira <[email protected]> Signed-off-by: Aurabindo Pillai <[email protected]> Signed-off-by: Wayne Lin <[email protected]> Tested-by: Daniel Wheeler <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 792be2e commit eaf3adb

File tree

1 file changed

+49
-44
lines changed

1 file changed

+49
-44
lines changed

drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_core/dml2_core_dcn4_calcs.c

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7247,10 +7247,9 @@ static bool dml_core_mode_support(struct dml2_core_calcs_mode_support_ex *in_out
72477247
/* Cursor Support Check */
72487248
mode_lib->ms.support.CursorSupport = true;
72497249
for (k = 0; k < mode_lib->ms.num_active_planes; k++) {
7250-
if (display_cfg->plane_descriptors[k].cursor.cursor_width > 0.0) {
7251-
if (display_cfg->plane_descriptors[k].cursor.cursor_bpp == 64 && mode_lib->ip.cursor_64bpp_support == false) {
7250+
if (display_cfg->plane_descriptors[k].cursor.num_cursors > 0) {
7251+
if (display_cfg->plane_descriptors[k].cursor.cursor_bpp == 64 && mode_lib->ip.cursor_64bpp_support == false)
72527252
mode_lib->ms.support.CursorSupport = false;
7253-
}
72547253
}
72557254
}
72567255

@@ -8111,27 +8110,31 @@ static bool dml_core_mode_support(struct dml2_core_calcs_mode_support_ex *in_out
81118110
for (k = 0; k < mode_lib->ms.num_active_planes; ++k) {
81128111
double line_time_us = (double)display_cfg->stream_descriptors[display_cfg->plane_descriptors[k].stream_index].timing.h_total / ((double)display_cfg->stream_descriptors[display_cfg->plane_descriptors[k].stream_index].timing.pixel_clock_khz / 1000);
81138112
bool cursor_not_enough_urgent_latency_hiding = 0;
8114-
calculate_cursor_req_attributes(
8115-
display_cfg->plane_descriptors[k].cursor.cursor_width,
8116-
display_cfg->plane_descriptors[k].cursor.cursor_bpp,
81178113

8118-
// output
8119-
&s->cursor_lines_per_chunk[k],
8120-
&s->cursor_bytes_per_line[k],
8121-
&s->cursor_bytes_per_chunk[k],
8122-
&s->cursor_bytes[k]);
8123-
8124-
calculate_cursor_urgent_burst_factor(
8125-
mode_lib->ip.cursor_buffer_size,
8126-
display_cfg->plane_descriptors[k].cursor.cursor_width,
8127-
s->cursor_bytes_per_chunk[k],
8128-
s->cursor_lines_per_chunk[k],
8129-
line_time_us,
8130-
mode_lib->ms.UrgLatency,
8114+
if (display_cfg->plane_descriptors[k].cursor.num_cursors > 0) {
8115+
calculate_cursor_req_attributes(
8116+
display_cfg->plane_descriptors[k].cursor.cursor_width,
8117+
display_cfg->plane_descriptors[k].cursor.cursor_bpp,
8118+
8119+
// output
8120+
&s->cursor_lines_per_chunk[k],
8121+
&s->cursor_bytes_per_line[k],
8122+
&s->cursor_bytes_per_chunk[k],
8123+
&s->cursor_bytes[k]);
8124+
8125+
calculate_cursor_urgent_burst_factor(
8126+
mode_lib->ip.cursor_buffer_size,
8127+
display_cfg->plane_descriptors[k].cursor.cursor_width,
8128+
s->cursor_bytes_per_chunk[k],
8129+
s->cursor_lines_per_chunk[k],
8130+
line_time_us,
8131+
mode_lib->ms.UrgLatency,
8132+
8133+
// output
8134+
&mode_lib->ms.UrgentBurstFactorCursor[k],
8135+
&cursor_not_enough_urgent_latency_hiding);
8136+
}
81318137

8132-
// output
8133-
&mode_lib->ms.UrgentBurstFactorCursor[k],
8134-
&cursor_not_enough_urgent_latency_hiding);
81358138
mode_lib->ms.UrgentBurstFactorCursorPre[k] = mode_lib->ms.UrgentBurstFactorCursor[k];
81368139

81378140
#ifdef __DML_VBA_DEBUG__
@@ -10608,31 +10611,33 @@ static bool dml_core_mode_programming(struct dml2_core_calcs_mode_programming_ex
1060810611

1060910612
for (k = 0; k < s->num_active_planes; ++k) {
1061010613
bool cursor_not_enough_urgent_latency_hiding = 0;
10611-
double line_time_us;
10614+
double line_time_us = 0.0;
1061210615

10613-
calculate_cursor_req_attributes(
10614-
display_cfg->plane_descriptors[k].cursor.cursor_width,
10615-
display_cfg->plane_descriptors[k].cursor.cursor_bpp,
10616+
line_time_us = display_cfg->stream_descriptors[display_cfg->plane_descriptors[k].stream_index].timing.h_total /
10617+
((double)display_cfg->stream_descriptors[display_cfg->plane_descriptors[k].stream_index].timing.pixel_clock_khz / 1000);
10618+
if (display_cfg->plane_descriptors[k].cursor.num_cursors > 0) {
10619+
calculate_cursor_req_attributes(
10620+
display_cfg->plane_descriptors[k].cursor.cursor_width,
10621+
display_cfg->plane_descriptors[k].cursor.cursor_bpp,
1061610622

10617-
// output
10618-
&s->cursor_lines_per_chunk[k],
10619-
&s->cursor_bytes_per_line[k],
10620-
&s->cursor_bytes_per_chunk[k],
10621-
&s->cursor_bytes[k]);
10622-
10623-
line_time_us = display_cfg->stream_descriptors[display_cfg->plane_descriptors[k].stream_index].timing.h_total / ((double)display_cfg->stream_descriptors[display_cfg->plane_descriptors[k].stream_index].timing.pixel_clock_khz / 1000);
10624-
10625-
calculate_cursor_urgent_burst_factor(
10626-
mode_lib->ip.cursor_buffer_size,
10627-
display_cfg->plane_descriptors[k].cursor.cursor_width,
10628-
s->cursor_bytes_per_chunk[k],
10629-
s->cursor_lines_per_chunk[k],
10630-
line_time_us,
10631-
mode_lib->mp.UrgentLatency,
10623+
// output
10624+
&s->cursor_lines_per_chunk[k],
10625+
&s->cursor_bytes_per_line[k],
10626+
&s->cursor_bytes_per_chunk[k],
10627+
&s->cursor_bytes[k]);
10628+
10629+
calculate_cursor_urgent_burst_factor(
10630+
mode_lib->ip.cursor_buffer_size,
10631+
display_cfg->plane_descriptors[k].cursor.cursor_width,
10632+
s->cursor_bytes_per_chunk[k],
10633+
s->cursor_lines_per_chunk[k],
10634+
line_time_us,
10635+
mode_lib->mp.UrgentLatency,
1063210636

10633-
// output
10634-
&mode_lib->mp.UrgentBurstFactorCursor[k],
10635-
&cursor_not_enough_urgent_latency_hiding);
10637+
// output
10638+
&mode_lib->mp.UrgentBurstFactorCursor[k],
10639+
&cursor_not_enough_urgent_latency_hiding);
10640+
}
1063610641
mode_lib->mp.UrgentBurstFactorCursorPre[k] = mode_lib->mp.UrgentBurstFactorCursor[k];
1063710642

1063810643
CalculateUrgentBurstFactor(

0 commit comments

Comments
 (0)