From 437cbca5ea50af4d1b37dd05aa33b4e791fd6d0f Mon Sep 17 00:00:00 2001 From: Srinivasan Shanmugam Date: Thu, 23 Apr 2026 19:02:10 +0530 Subject: [PATCH] drm/amd/display: Fix unsigned underflow in SubVP vblank schedulability check v2 subvp_vblank_schedulable() checks whether the SubVP active region can fit the prefetch time, vblank frame time, and the larger of the vblank blanking time and MALL region. Commit 11236ac905e7 ("drm/amd/display: Fix dml2_0 narrowing boundaries") changed the intermediate timing variables from u16 to u32. After that change, the schedulability test: subvp_active_us - prefetch_us - vblank_frame_us - max_vblank_mallregion > 0 is evaluated in unsigned arithmetic. If the required time exceeds the available active time, the subtraction can underflow and wrap, producing a large positive value instead of a negative result. Fix this by comparing the available time against the required time directly, using u64 for the accumulated required duration. v2: - Use uint64_t instead of u64 for consistency with DC style (Dillon) - Make all terms explicitly uint64_t in the accumulated sum & use single-definition form for required_us (Gaghik) Fixes: 11236ac905e7 ("drm/amd/display: Fix dml2_0 narrowing boundaries") Reported-by: Dan Carpenter Cc: Roman Li Cc: Alex Hung Cc: Tom Chung Cc: Dillon Varone Cc: Gaghik Khachatrian Cc: Aurabindo Pillai Cc: Chenyu Chen Signed-off-by: Srinivasan Shanmugam Reviewed-by: Dillon Varone Signed-off-by: Alex Deucher --- drivers/gpu/drm/amd/display/dc/dml2_0/dml2_mall_phantom.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/display/dc/dml2_0/dml2_mall_phantom.c b/drivers/gpu/drm/amd/display/dc/dml2_0/dml2_mall_phantom.c index fe667aea6ec85..4543a60a06839 100644 --- a/drivers/gpu/drm/amd/display/dc/dml2_0/dml2_mall_phantom.c +++ b/drivers/gpu/drm/amd/display/dc/dml2_0/dml2_mall_phantom.c @@ -594,11 +594,14 @@ static bool subvp_vblank_schedulable(struct dml2_context *ctx, struct dc_state * subvp_active_us = (uint32_t)(main_timing->v_addressable * main_timing->h_total / (double)(main_timing->pix_clk_100hz * 100) * 1000000); max_vblank_mallregion = vblank_blank_us > mall_region_us ? vblank_blank_us : mall_region_us; + const uint64_t required_us = (uint64_t)prefetch_us + + (uint64_t)vblank_frame_us + + (uint64_t)max_vblank_mallregion; // Schedulable if VACTIVE region of the SubVP pipe can fit the MALL prefetch, VBLANK frame time, // and the max of (VBLANK blanking time, MALL region) // TODO: Possibly add some margin (i.e. the below conditions should be [...] > X instead of [...] > 0) - if (subvp_active_us - prefetch_us - vblank_frame_us - max_vblank_mallregion > 0) + if ((uint64_t)subvp_active_us > required_us) schedulable = true; } return schedulable; -- 2.47.3