All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amd/display: fix division by zero in get_estimated_bw()
@ 2026-08-22 14:57 Hari Mishal
  2026-08-22 15:15 ` sashiko-bot
  2026-08-28 20:41 ` Alex Hung
  0 siblings, 2 replies; 3+ messages in thread
From: Hari Mishal @ 2026-08-22 14:57 UTC (permalink / raw)
  To: Harry Wentland
  Cc: Leo Li, Rodrigo Siqueira, Alex Deucher, Christian König,
	David Airlie, Simona Vetter, Dillon Varone, Gaghik Khachatrian,
	Cruise Hung, Chenyu Chen, Peichen Huang, Qingqing Zhuo, Jun Lei,
	Mustapha Ghaddar, amd-gfx, dri-devel, linux-kernel,
	Greg Kroah-Hartman, Hari Mishal

get_estimated_bw() divides by link->dpia_bw_alloc_config.bw_granularity,
which is zeroed by reset_bw_alloc_struct() and only populated once
DP_TUNNELING_BW_ALLOC_CAP_CHANGED has been handled.

link_dp_dpia_handle_bw_alloc_status(), the DPCD interrupt handler,
calls get_estimated_bw() whenever DP_TUNNELING_ESTIMATED_BW_CHANGED
is set, independently of whether DP_TUNNELING_BW_ALLOC_CAP_CHANGED
has ever fired for that link. A connected USB4/DPIA tunneling device
that reports an estimated-bandwidth change before ever reporting a
capability change drives a division by zero in this IRQ path.

link_dpia_send_bw_alloc_request() already guards the same
bw_granularity division; add the identical guard here rather than
introducing a new pattern.

Fixes: 8e5cfe547bf3 ("drm/amd/display: upstream link_dp_dpia_bw.c")
Assisted-by: gkh_clanker_t1000
Signed-off-by: Hari Mishal <harimishal1@gmail.com>
---
 .../gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c  | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c
index dd854d992692..f43fc4b78a8d 100644
--- a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c
+++ b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c
@@ -103,6 +103,11 @@ static int get_estimated_bw(struct dc_link *link)
 {
 	uint8_t bw_estimated_bw = 0;
 
+	if (link->dpia_bw_alloc_config.bw_granularity == 0) {
+		DC_LOG_ERROR("%s: BW granularity is zero!\n", __func__);
+		return 0;
+	}
+
 	core_link_read_dpcd(
 			link,
 			ESTIMATED_BW,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/amd/display: fix division by zero in get_estimated_bw()
  2026-08-22 14:57 [PATCH] drm/amd/display: fix division by zero in get_estimated_bw() Hari Mishal
@ 2026-08-22 15:15 ` sashiko-bot
  2026-08-28 20:41 ` Alex Hung
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-08-22 15:15 UTC (permalink / raw)
  To: Hari Mishal; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Uncapped request_bw is assigned to allocated_bw, causing an oversized value that leads to an integer underflow during bandwidth validation.
--

--- Patch [1]: [PATCH] drm/amd/display: fix division by zero in get_estimated_bw() ---
commit d3870b3b2da2897f934f4033da62b969b6443914
Author: Hari Mishal <harimishal1@gmail.com>

drm/amd/display: fix division by zero in get_estimated_bw()

This commit fixes a division by zero in get_estimated_bw() by returning 0
if bw_granularity is zero. This prevents a crash when a connected DPIA
device reports an estimated bandwidth change before reporting a capability
change.

>     link_dpia_send_bw_alloc_request() already guards the same
>     bw_granularity division; add the identical guard here rather than
>     introducing a new pattern.

[Severity: High]
This is a pre-existing issue, but since the commit message references 
link_dpia_send_bw_alloc_request(), I noticed a potential integer underflow
issue involving allocated_bw.

In link_dpia_send_bw_alloc_request(), the uncapped request_bw variable
is assigned to allocated_bw:

drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c:link_dpia_send_bw_alloc_request() {
    ...
		temp = req_bw * link->dpia_bw_alloc_config.bw_granularity;
		request_reg_val = temp / Kbps_TO_Gbps;
		if (temp % Kbps_TO_Gbps)
			++request_reg_val;
	}

	link->dpia_bw_alloc_config.allocated_bw = request_bw;
    ...
}

Later, in link_dpia_validate_dp_tunnel_bandwidth(), remaining_bw is
calculated using unsigned 32-bit subtraction:

drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c:link_dpia_validate_dp_tunnel_bandwidth() {
    ...
			if (router_sets[j].cm_id == dp_tunnel_settings->cm_id) {
				uint32_t remaining_bw =
					dp_tunnel_settings->estimated_bw - dp_tunnel_settings->allocated_bw;
    ...
}

If a connected DPIA display requests more bandwidth than estimated,
allocated_bw will be strictly greater than estimated_bw.

Could this cause the subtraction to underflow to an extremely large
positive value (~4.29 billion), thereby bypassing the subsequent
capacity checks (required_bw > total_bw) and allowing illegal
configurations that oversubscribe the DP tunnel?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260822145751.42328-1-harimishal1@gmail.com?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/amd/display: fix division by zero in get_estimated_bw()
  2026-08-22 14:57 [PATCH] drm/amd/display: fix division by zero in get_estimated_bw() Hari Mishal
  2026-08-22 15:15 ` sashiko-bot
@ 2026-08-28 20:41 ` Alex Hung
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Hung @ 2026-08-28 20:41 UTC (permalink / raw)
  To: Hari Mishal, Harry Wentland
  Cc: Leo Li, Rodrigo Siqueira, Alex Deucher, Christian König,
	David Airlie, Simona Vetter, Dillon Varone, Gaghik Khachatrian,
	Cruise Hung, Chenyu Chen, Peichen Huang, Qingqing Zhuo, Jun Lei,
	Mustapha Ghaddar, amd-gfx, dri-devel, linux-kernel,
	Greg Kroah-Hartman, Wheeler, Daniel

Weekly promotion tests found no regression.

This patch is
Reviewed-by: Alex Hung <alex.hung@amd.com>

On 8/22/26 08:57, Hari Mishal wrote:
> [Some people who received this message don't often get email from harimishal1@gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> get_estimated_bw() divides by link->dpia_bw_alloc_config.bw_granularity,
> which is zeroed by reset_bw_alloc_struct() and only populated once
> DP_TUNNELING_BW_ALLOC_CAP_CHANGED has been handled.
> 
> link_dp_dpia_handle_bw_alloc_status(), the DPCD interrupt handler,
> calls get_estimated_bw() whenever DP_TUNNELING_ESTIMATED_BW_CHANGED
> is set, independently of whether DP_TUNNELING_BW_ALLOC_CAP_CHANGED
> has ever fired for that link. A connected USB4/DPIA tunneling device
> that reports an estimated-bandwidth change before ever reporting a
> capability change drives a division by zero in this IRQ path.
> 
> link_dpia_send_bw_alloc_request() already guards the same
> bw_granularity division; add the identical guard here rather than
> introducing a new pattern.
> 
> Fixes: 8e5cfe547bf3 ("drm/amd/display: upstream link_dp_dpia_bw.c")
> Assisted-by: gkh_clanker_t1000
> Signed-off-by: Hari Mishal <harimishal1@gmail.com>
> ---
>   .../gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c  | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c
> index dd854d992692..f43fc4b78a8d 100644
> --- a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c
> +++ b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c
> @@ -103,6 +103,11 @@ static int get_estimated_bw(struct dc_link *link)
>   {
>          uint8_t bw_estimated_bw = 0;
> 
> +       if (link->dpia_bw_alloc_config.bw_granularity == 0) {
> +               DC_LOG_ERROR("%s: BW granularity is zero!\n", __func__);
> +               return 0;
> +       }
> +
>          core_link_read_dpcd(
>                          link,
>                          ESTIMATED_BW,
> --
> 2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-28 20:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-22 14:57 [PATCH] drm/amd/display: fix division by zero in get_estimated_bw() Hari Mishal
2026-08-22 15:15 ` sashiko-bot
2026-08-28 20:41 ` Alex Hung

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.