Skip to content

Commit 1b6775e

Browse files
Aurabindo Pillaigregkh
Aurabindo Pillai
authored andcommitted
drm/amd/display: fix a UBSAN warning in DML2.1
[ Upstream commit eaf3adb ] 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 torvalds#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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 97103dc commit 1b6775e

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

+49-44
Original file line numberDiff line numberDiff line change
@@ -7231,10 +7231,9 @@ static bool dml_core_mode_support(struct dml2_core_calcs_mode_support_ex *in_out
72317231
/* Cursor Support Check */
72327232
mode_lib->ms.support.CursorSupport = true;
72337233
for (k = 0; k < mode_lib->ms.num_active_planes; k++) {
7234-
if (display_cfg->plane_descriptors[k].cursor.cursor_width > 0.0) {
7235-
if (display_cfg->plane_descriptors[k].cursor.cursor_bpp == 64 && mode_lib->ip.cursor_64bpp_support == false) {
7234+
if (display_cfg->plane_descriptors[k].cursor.num_cursors > 0) {
7235+
if (display_cfg->plane_descriptors[k].cursor.cursor_bpp == 64 && mode_lib->ip.cursor_64bpp_support == false)
72367236
mode_lib->ms.support.CursorSupport = false;
7237-
}
72387237
}
72397238
}
72407239

@@ -8091,27 +8090,31 @@ static bool dml_core_mode_support(struct dml2_core_calcs_mode_support_ex *in_out
80918090
for (k = 0; k < mode_lib->ms.num_active_planes; ++k) {
80928091
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);
80938092
bool cursor_not_enough_urgent_latency_hiding = 0;
8094-
calculate_cursor_req_attributes(
8095-
display_cfg->plane_descriptors[k].cursor.cursor_width,
8096-
display_cfg->plane_descriptors[k].cursor.cursor_bpp,
80978093

8098-
// output
8099-
&s->cursor_lines_per_chunk[k],
8100-
&s->cursor_bytes_per_line[k],
8101-
&s->cursor_bytes_per_chunk[k],
8102-
&s->cursor_bytes[k]);
8103-
8104-
calculate_cursor_urgent_burst_factor(
8105-
mode_lib->ip.cursor_buffer_size,
8106-
display_cfg->plane_descriptors[k].cursor.cursor_width,
8107-
s->cursor_bytes_per_chunk[k],
8108-
s->cursor_lines_per_chunk[k],
8109-
line_time_us,
8110-
mode_lib->ms.UrgLatency,
8094+
if (display_cfg->plane_descriptors[k].cursor.num_cursors > 0) {
8095+
calculate_cursor_req_attributes(
8096+
display_cfg->plane_descriptors[k].cursor.cursor_width,
8097+
display_cfg->plane_descriptors[k].cursor.cursor_bpp,
8098+
8099+
// output
8100+
&s->cursor_lines_per_chunk[k],
8101+
&s->cursor_bytes_per_line[k],
8102+
&s->cursor_bytes_per_chunk[k],
8103+
&s->cursor_bytes[k]);
8104+
8105+
calculate_cursor_urgent_burst_factor(
8106+
mode_lib->ip.cursor_buffer_size,
8107+
display_cfg->plane_descriptors[k].cursor.cursor_width,
8108+
s->cursor_bytes_per_chunk[k],
8109+
s->cursor_lines_per_chunk[k],
8110+
line_time_us,
8111+
mode_lib->ms.UrgLatency,
8112+
8113+
// output
8114+
&mode_lib->ms.UrgentBurstFactorCursor[k],
8115+
&cursor_not_enough_urgent_latency_hiding);
8116+
}
81118117

8112-
// output
8113-
&mode_lib->ms.UrgentBurstFactorCursor[k],
8114-
&cursor_not_enough_urgent_latency_hiding);
81158118
mode_lib->ms.UrgentBurstFactorCursorPre[k] = mode_lib->ms.UrgentBurstFactorCursor[k];
81168119

81178120
#ifdef __DML_VBA_DEBUG__
@@ -10592,31 +10595,33 @@ static bool dml_core_mode_programming(struct dml2_core_calcs_mode_programming_ex
1059210595

1059310596
for (k = 0; k < s->num_active_planes; ++k) {
1059410597
bool cursor_not_enough_urgent_latency_hiding = 0;
10595-
double line_time_us;
10598+
double line_time_us = 0.0;
1059610599

10597-
calculate_cursor_req_attributes(
10598-
display_cfg->plane_descriptors[k].cursor.cursor_width,
10599-
display_cfg->plane_descriptors[k].cursor.cursor_bpp,
10600+
line_time_us = display_cfg->stream_descriptors[display_cfg->plane_descriptors[k].stream_index].timing.h_total /
10601+
((double)display_cfg->stream_descriptors[display_cfg->plane_descriptors[k].stream_index].timing.pixel_clock_khz / 1000);
10602+
if (display_cfg->plane_descriptors[k].cursor.num_cursors > 0) {
10603+
calculate_cursor_req_attributes(
10604+
display_cfg->plane_descriptors[k].cursor.cursor_width,
10605+
display_cfg->plane_descriptors[k].cursor.cursor_bpp,
1060010606

10601-
// output
10602-
&s->cursor_lines_per_chunk[k],
10603-
&s->cursor_bytes_per_line[k],
10604-
&s->cursor_bytes_per_chunk[k],
10605-
&s->cursor_bytes[k]);
10606-
10607-
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);
10608-
10609-
calculate_cursor_urgent_burst_factor(
10610-
mode_lib->ip.cursor_buffer_size,
10611-
display_cfg->plane_descriptors[k].cursor.cursor_width,
10612-
s->cursor_bytes_per_chunk[k],
10613-
s->cursor_lines_per_chunk[k],
10614-
line_time_us,
10615-
mode_lib->mp.UrgentLatency,
10607+
// output
10608+
&s->cursor_lines_per_chunk[k],
10609+
&s->cursor_bytes_per_line[k],
10610+
&s->cursor_bytes_per_chunk[k],
10611+
&s->cursor_bytes[k]);
10612+
10613+
calculate_cursor_urgent_burst_factor(
10614+
mode_lib->ip.cursor_buffer_size,
10615+
display_cfg->plane_descriptors[k].cursor.cursor_width,
10616+
s->cursor_bytes_per_chunk[k],
10617+
s->cursor_lines_per_chunk[k],
10618+
line_time_us,
10619+
mode_lib->mp.UrgentLatency,
1061610620

10617-
// output
10618-
&mode_lib->mp.UrgentBurstFactorCursor[k],
10619-
&cursor_not_enough_urgent_latency_hiding);
10621+
// output
10622+
&mode_lib->mp.UrgentBurstFactorCursor[k],
10623+
&cursor_not_enough_urgent_latency_hiding);
10624+
}
1062010625
mode_lib->mp.UrgentBurstFactorCursorPre[k] = mode_lib->mp.UrgentBurstFactorCursor[k];
1062110626

1062210627
CalculateUrgentBurstFactor(

0 commit comments

Comments
 (0)