* [PATCH] drm/msm/dpu: avoid division by zero in plane bandwidth calc
@ 2026-12-06 4:27 Shirong Zhao
2026-12-06 4:43 ` sashiko-bot
2026-12-06 4:57 ` [PATCH v2] " Shirong Zhao
0 siblings, 2 replies; 3+ messages in thread
From: Shirong Zhao @ 2026-12-06 4:27 UTC (permalink / raw)
To: Rob Clark, Dmitry Baryshkov
Cc: Abhinav Kumar, Jessica Zhang, Sean Paul, Marijn Suijten,
dri-devel, linux-arm-msm, stable, Shirong Zhao
_dpu_plane_calc_bw() divides by the vertical blanking total:
vbp = mode->vtotal - mode->vsync_end;
vpw = mode->vsync_end - mode->vsync_start;
vfp = mode->vsync_start - mode->vdisplay;
if ((vbp+vpw) > hw_latency_lines)
do_div(plane_prefill_bw, (vbp+vpw));
else if ((vbp+vpw+vfp) < hw_latency_lines)
do_div(plane_prefill_bw, (vbp+vpw+vfp));
drm_mode_validate_basic() only checks that vsync_start >= vdisplay,
vsync_end >= vsync_start and vtotal >= vsync_end, so it accepts a mode
where all four are equal. vbp+vpw+vfp is then 0 and, since
0 < min_prefill_lines, the second branch divides by zero (dpu_crtc
mode_valid only rejects modes that are too large). Such a mode can be
supplied through an atomic commit with a crafted mode blob, or through
the legacy SETCRTC ioctl, which also calls drm_mode_validate_driver().
Skip the zero case so it falls back to hw_latency_lines.
Fixes: 0c3d3cc93811 ("drm/msm/dpu: consider vertical front porch in the prefill bw calculation")
Cc: stable@vger.kernel.org
Signed-off-by: Shirong Zhao <shxzhaosr@163.com>
---
drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
index 1a471cd..7a8032e 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
@@ -146,7 +146,7 @@ static u64 _dpu_plane_calc_bw(const struct dpu_mdss_cfg *catalog,
if ((vbp+vpw) > hw_latency_lines)
do_div(plane_prefill_bw, (vbp+vpw));
- else if ((vbp+vpw+vfp) < hw_latency_lines)
+ else if ((vbp+vpw+vfp) && (vbp+vpw+vfp) < hw_latency_lines)
do_div(plane_prefill_bw, (vbp+vpw+vfp));
else
do_div(plane_prefill_bw, hw_latency_lines);
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/msm/dpu: avoid division by zero in plane bandwidth calc
2026-12-06 4:27 [PATCH] drm/msm/dpu: avoid division by zero in plane bandwidth calc Shirong Zhao
@ 2026-12-06 4:43 ` sashiko-bot
2026-12-06 4:57 ` [PATCH v2] " Shirong Zhao
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-06 4:43 UTC (permalink / raw)
To: Shirong Zhao; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/msm/dpu: fallback division by zero in
_dpu_plane_calc_bw() on SC8280XP
--
commit 6a9f48e9576cc98f921a8bdedc159b2c2b15f863
Author: Shirong Zhao <shxzhaosr@163.com>
drm/msm/dpu: avoid division by zero in plane bandwidth calc
This commit adds a non-zero check on (vbp+vpw+vfp) in
_dpu_plane_calc_bw() so that modes with zero vertical blanking fall back
to dividing by hw_latency_lines.
> diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
> index 1a471cdf767b1..7a8032eced27b 100644
> --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
> +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
> @@ -146,7 +146,7 @@ static u64 _dpu_plane_calc_bw(const struct dpu_mdss_cfg *catalog,
>
> if ((vbp+vpw) > hw_latency_lines)
> do_div(plane_prefill_bw, (vbp+vpw));
> - else if ((vbp+vpw+vfp) < hw_latency_lines)
> + else if ((vbp+vpw+vfp) && (vbp+vpw+vfp) < hw_latency_lines)
> do_div(plane_prefill_bw, (vbp+vpw+vfp));
> else
> do_div(plane_prefill_bw, hw_latency_lines);
[Severity: Medium]
Can the else branch still divide by zero on sc8280xp when hw_latency_lines
is 0?
hw_latency_lines comes from catalog->perf->min_prefill_lines, which
sc8280xp_perf_data in
drivers/gpu/drm/msm/disp/dpu1/catalog/dpu_8_0_sc8280xp.h leaves unset (0).
On qcom,sc8280xp-dpu, a mode with zero vertical blanking reaches the else
branch and calls do_div(plane_prefill_bw, 0), causing a divide-by-zero
splat under UBSAN (or a panic with CONFIG_UBSAN_TRAP).
Since plane_prefill_bw is just plane_bw * hw_latency_lines, setting
plane_prefill_bw = plane_bw in the else branch avoids dividing by zero on
all platforms; sc8280xp_perf_data should also set .min_prefill_lines.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261206042720.42-1-shxzhaosr@163.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2] drm/msm/dpu: avoid division by zero in plane bandwidth calc
2026-12-06 4:27 [PATCH] drm/msm/dpu: avoid division by zero in plane bandwidth calc Shirong Zhao
2026-12-06 4:43 ` sashiko-bot
@ 2026-12-06 4:57 ` Shirong Zhao
1 sibling, 0 replies; 3+ messages in thread
From: Shirong Zhao @ 2026-12-06 4:57 UTC (permalink / raw)
To: Rob Clark, Dmitry Baryshkov
Cc: Abhinav Kumar, Jessica Zhang, Sean Paul, Marijn Suijten,
dri-devel, linux-arm-msm, stable, Shirong Zhao
_dpu_plane_calc_bw() derives three vertical blanking intervals:
vbp = mode->vtotal - mode->vsync_end;
vpw = mode->vsync_end - mode->vsync_start;
vfp = mode->vsync_start - mode->vdisplay;
and divides by one of them:
hw_latency_lines = catalog->perf->min_prefill_lines;
plane_prefill_bw = plane_bw * hw_latency_lines;
if ((vbp+vpw) > hw_latency_lines)
do_div(plane_prefill_bw, (vbp+vpw));
else if ((vbp+vpw+vfp) < hw_latency_lines)
do_div(plane_prefill_bw, (vbp+vpw+vfp));
else
do_div(plane_prefill_bw, hw_latency_lines);
Two divisors can be zero.
First, drm_mode_validate_basic() only checks that vsync_start >= vdisplay,
vsync_end >= vsync_start and vtotal >= vsync_end, so it accepts a mode
where all four are equal. vbp+vpw+vfp is then 0 and, as long as
0 < min_prefill_lines, the second branch divides by zero. Such a mode can
be supplied through an atomic commit with a crafted mode blob, or through
the legacy SETCRTC ioctl; dpu_crtc_mode_valid() only rejects modes that
are too large.
Second, sc8280xp_perf_data is the only catalog that leaves
min_prefill_lines unset. On that platform hw_latency_lines is 0, so the
else branch divides by zero whenever vbp+vpw is 0 as well, and normal
modes merely compute a prefill bandwidth of 0.
Skip the zero-blanking case so it falls back to hw_latency_lines, and
return plane_bw directly when min_prefill_lines is unset, since there is
no prefill latency budget to scale against on such catalogs.
Fixes: 0c3d3cc93811 ("drm/msm/dpu: consider vertical front porch in the prefill bw calculation")
Cc: stable@vger.kernel.org
Signed-off-by: Shirong Zhao <shxzhaosr@163.com>
---
v2:
- Also handle min_prefill_lines == 0. sc8280xp leaves it unset, so the
previous version still divided by zero in the else branch there, as
pointed out by Sashiko. Return plane_bw early in that case instead of
scaling the prefill bandwidth against a zero budget.
drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
index 1a471cd..eef8826 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
@@ -142,11 +142,17 @@ static u64 _dpu_plane_calc_bw(const struct dpu_mdss_cfg *catalog,
plane_bw = plane_bit_rate * scale_factor;
+ /* Some catalogs (e.g. sc8280xp) leave min_prefill_lines unset; there is
+ * then no prefill latency budget to scale against.
+ */
+ if (!hw_latency_lines)
+ return plane_bw;
+
plane_prefill_bw = plane_bw * hw_latency_lines;
if ((vbp+vpw) > hw_latency_lines)
do_div(plane_prefill_bw, (vbp+vpw));
- else if ((vbp+vpw+vfp) < hw_latency_lines)
+ else if ((vbp+vpw+vfp) && (vbp+vpw+vfp) < hw_latency_lines)
do_div(plane_prefill_bw, (vbp+vpw+vfp));
else
do_div(plane_prefill_bw, hw_latency_lines);
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-06 4:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06 4:27 [PATCH] drm/msm/dpu: avoid division by zero in plane bandwidth calc Shirong Zhao
2026-12-06 4:43 ` sashiko-bot
2026-12-06 4:57 ` [PATCH v2] " Shirong Zhao
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.