Skip to contentSkip to conversation

drm/i915: rework the error handling in *_dpll_params

PATCH In review [email protected] 3 participants 4 messages Mar 4, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915: rework the error handling in *_dpll_params

From: Tom Rix <[email protected]>

Clang static analysis reports this issue intel_dpll.c:472:31: warning: The left operand of '-'
is a garbage value [core.UndefinedBinaryOperatorResult]

  this_err = abs(clock.dot - target);
                 ~~~~~~~~~ ^

In a loop clock.dot is set on successful call to i9xx_calc_dpll_params(). If the call fails, the later *is_valid() will use the previous loop's clock.dot.

The *_dpll_params functions return an arithmetic statement with the clock.dot as the variable. Change the error handler to set clock.dot to 0 and jump to the return statement.

Fixes dccbea3b0704 ("drm/i915: calculate the port clock rate along with other PLL params")
---
 drivers/gpu/drm/i915/display/intel_dpll.c | 32 ++++++++++++++---------
 1 file changed, 20 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/display/intel_dpll.c +20 -12
index 0ae37fdbf2a5b..ba7cada704288 100644
@@ -309,11 +309,13 @@ int pnv_calc_dpll_params(int refclk, struct dpll *clock)
 {
 	clock->m = clock->m2 + 2;
 	clock->p = clock->p1 * clock->p2;
-	if (WARN_ON(clock->n == 0 || clock->p == 0))
-		return 0;
+	if (WARN_ON(clock->n == 0 || clock->p == 0)) {
+		clock->dot = 0;
+		goto end;
+	}
 	clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
 	clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
-
+end:
 	return clock->dot;
 }
 
@@ -326,11 +328,13 @@ int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
 {
 	clock->m = i9xx_dpll_compute_m(clock);
 	clock->p = clock->p1 * clock->p2;
-	if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
-		return 0;
+	if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) {
+		clock->dot = 0;
+		goto end;
+	}
 	clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
 	clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
-
+end:
 	return clock->dot;
 }
 
@@ -338,11 +342,13 @@ int vlv_calc_dpll_params(int refclk, struct dpll *clock)
 {
 	clock->m = clock->m1 * clock->m2;
 	clock->p = clock->p1 * clock->p2;
-	if (WARN_ON(clock->n == 0 || clock->p == 0))
-		return 0;
+	if (WARN_ON(clock->n == 0 || clock->p == 0)) {
+		clock->dot = 0;
+		goto end;
+	}
 	clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
 	clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
-
+end:
 	return clock->dot / 5;
 }
 
@@ -350,12 +356,14 @@ int chv_calc_dpll_params(int refclk, struct dpll *clock)
 {
 	clock->m = clock->m1 * clock->m2;
 	clock->p = clock->p1 * clock->p2;
-	if (WARN_ON(clock->n == 0 || clock->p == 0))
-		return 0;
+	if (WARN_ON(clock->n == 0 || clock->p == 0)) {
+		clock->dot = 0;
+		goto end;
+	}
 	clock->vco = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(refclk, clock->m),
 					   clock->n << 22);
 	clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
-
+end:
 	return clock->dot / 5;
 }
 
Signature · 1 line
2.26.3
#1 lore raw
Quoted 11 lines · On Fri, Mar 04, 2022 at 01:03:55PM -0800, [email protected] wrote:

From: Tom Rix <[email protected]>

Clang static analysis reports this issue intel_dpll.c:472:31: warning: The left operand of '-'
is a garbage value [core.UndefinedBinaryOperatorResult]

  this_err = abs(clock.dot - target);
                 ~~~~~~~~~ ^

In a loop clock.dot is set on successful call to i9xx_calc_dpll_params(). If the call fails, the later *is_valid() will use the previous loop's clock.dot.

I don't think this can happen. intel_pll_is_valid() validates all the dividers first and bails out if they are junk.

Quoted 86 lines

The *_dpll_params functions return an arithmetic statement with the clock.dot as the variable. Change the error handler to set clock.dot to 0 and jump to the return statement.

Fixes dccbea3b0704 ("drm/i915: calculate the port clock rate along with other PLL params")
---
 drivers/gpu/drm/i915/display/intel_dpll.c | 32 ++++++++++++++---------
 1 file changed, 20 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/display/intel_dpll.c +20 -12
index 0ae37fdbf2a5b..ba7cada704288 100644
@@ -309,11 +309,13 @@ int pnv_calc_dpll_params(int refclk, struct dpll *clock)
 {
 	clock->m = clock->m2 + 2;
 	clock->p = clock->p1 * clock->p2;
-	if (WARN_ON(clock->n == 0 || clock->p == 0))
-		return 0;
+	if (WARN_ON(clock->n == 0 || clock->p == 0)) {
+		clock->dot = 0;
+		goto end;
+	}
 	clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
 	clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
-
+end:
 	return clock->dot;
 }
 
@@ -326,11 +328,13 @@ int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
 {
 	clock->m = i9xx_dpll_compute_m(clock);
 	clock->p = clock->p1 * clock->p2;
-	if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
-		return 0;
+	if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) {
+		clock->dot = 0;
+		goto end;
+	}
 	clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
 	clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
-
+end:
 	return clock->dot;
 }
 
@@ -338,11 +342,13 @@ int vlv_calc_dpll_params(int refclk, struct dpll *clock)
 {
 	clock->m = clock->m1 * clock->m2;
 	clock->p = clock->p1 * clock->p2;
-	if (WARN_ON(clock->n == 0 || clock->p == 0))
-		return 0;
+	if (WARN_ON(clock->n == 0 || clock->p == 0)) {
+		clock->dot = 0;
+		goto end;
+	}
 	clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
 	clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
-
+end:
 	return clock->dot / 5;
 }
 
@@ -350,12 +356,14 @@ int chv_calc_dpll_params(int refclk, struct dpll *clock)
 {
 	clock->m = clock->m1 * clock->m2;
 	clock->p = clock->p1 * clock->p2;
-	if (WARN_ON(clock->n == 0 || clock->p == 0))
-		return 0;
+	if (WARN_ON(clock->n == 0 || clock->p == 0)) {
+		clock->dot = 0;
+		goto end;
+	}
 	clock->vco = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(refclk, clock->m),
 					   clock->n << 22);
 	clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
-
+end:
 	return clock->dot / 5;
 }
 
Signature · 1 line
2.26.3
Signature · 2 lines
Ville Syrjälä
Intel
#2 lore raw
Quoted 9 lines · Ville Syrjälä
Quoted 8 lines · On Fri, Mar 04, 2022 at 01:03:55PM -0800, [email protected] wrote:

From: Tom Rix <[email protected]>

Clang static analysis reports this issue intel_dpll.c:472:31: warning: The left operand of '-'
is a garbage value [core.UndefinedBinaryOperatorResult]

  this_err = abs(clock.dot - target);
                 ~~~~~~~~~ ^
Quoted 6 lines
Quoted 3 lines

In a loop clock.dot is set on successful call to i9xx_calc_dpll_params(). If the call fails, the later *is_valid() will use the previous loop's clock.dot.

I don't think this can happen. intel_pll_is_valid() validates all the dividers first and bails out if they are junk.

Hmm. That said, there is actually a case to be made for fully initializing the struct, and even removing the WARN. If the BIOS (or whatever was doing stuff before i915 takes over) has misprogrammed the DPLL then we could potentially have garbage dividers on our hands, and during readout we'd just blindly call *_calc_dpll_params() on them.

So I'm thinking something along the lines of
clock->vco = <divisor> ? DIV_ROUND_CLOSEST(...) : 0; clock->dot = <divisor> ? DIV_ROUND_CLOSEST(...) : 0;
might be what we should do here.

To make it a bit less ugly a small helper function might be in order. intel_pll_div() perhaps?

Quoted 91 lines
Quoted 87 lines

The *_dpll_params functions return an arithmetic statement with the clock.dot as the variable. Change the error handler to set clock.dot to 0 and jump to the return statement.

Fixes dccbea3b0704 ("drm/i915: calculate the port clock rate along with other PLL params")
---
 drivers/gpu/drm/i915/display/intel_dpll.c | 32 ++++++++++++++---------
 1 file changed, 20 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/display/intel_dpll.c +20 -12
index 0ae37fdbf2a5b..ba7cada704288 100644
@@ -309,11 +309,13 @@ int pnv_calc_dpll_params(int refclk, struct dpll *clock)
 {
 	clock->m = clock->m2 + 2;
 	clock->p = clock->p1 * clock->p2;
-	if (WARN_ON(clock->n == 0 || clock->p == 0))
-		return 0;
+	if (WARN_ON(clock->n == 0 || clock->p == 0)) {
+		clock->dot = 0;
+		goto end;
+	}
 	clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
 	clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
-
+end:
 	return clock->dot;
 }
 
@@ -326,11 +328,13 @@ int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
 {
 	clock->m = i9xx_dpll_compute_m(clock);
 	clock->p = clock->p1 * clock->p2;
-	if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
-		return 0;
+	if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) {
+		clock->dot = 0;
+		goto end;
+	}
 	clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
 	clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
-
+end:
 	return clock->dot;
 }
 
@@ -338,11 +342,13 @@ int vlv_calc_dpll_params(int refclk, struct dpll *clock)
 {
 	clock->m = clock->m1 * clock->m2;
 	clock->p = clock->p1 * clock->p2;
-	if (WARN_ON(clock->n == 0 || clock->p == 0))
-		return 0;
+	if (WARN_ON(clock->n == 0 || clock->p == 0)) {
+		clock->dot = 0;
+		goto end;
+	}
 	clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
 	clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
-
+end:
 	return clock->dot / 5;
 }
 
@@ -350,12 +356,14 @@ int chv_calc_dpll_params(int refclk, struct dpll *clock)
 {
 	clock->m = clock->m1 * clock->m2;
 	clock->p = clock->p1 * clock->p2;
-	if (WARN_ON(clock->n == 0 || clock->p == 0))
-		return 0;
+	if (WARN_ON(clock->n == 0 || clock->p == 0)) {
+		clock->dot = 0;
+		goto end;
+	}
 	clock->vco = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(refclk, clock->m),
 					   clock->n << 22);
 	clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
-
+end:
 	return clock->dot / 5;
 }
 
Signature · 1 line
2.26.3
Signature · 2 lines
Ville Syrjälä
Intel
Signature · 2 lines
Ville Syrjälä
Intel
#3 lore raw

[Intel-gfx] ✗ Fi.CI.BAT: failure for drm/i915: rework the error handling in *_dpll_params

In reply to [email protected]
== Series Details ==

== Series Details ==

Series: drm/i915: rework the error handling in *_dpll_params
URL : https://patchwork.freedesktop.org/series/101062/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_11330 -> Patchwork_22491
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with Patchwork_22491 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes introduced in Patchwork_22491, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/index.html

Participating hosts (45 -> 43)
------------------------------

Additional (1): fi-glk-dsi
Missing (3): fi-bsw-cyan fi-bdw-samus fi-kbl-8809g

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in Patchwork_22491:

### IGT changes ###

#### Possible regressions ####

* igt@i915_module_load@reload:
- fi-tgl-1115g4: [PASS][1] -> [DMESG-WARN][2] +1 similar issue
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11330/fi-tgl-1115g4/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/fi-tgl-1115g4/igt@[email protected]

#### Warnings ####

* igt@i915_pm_rpm@module-reload:
- fi-tgl-1115g4: [INCOMPLETE][3] ([i915#1385]) -> [INCOMPLETE][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11330/fi-tgl-1115g4/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/fi-tgl-1115g4/igt@[email protected]

Known issues
------------

Here are the changes found in Patchwork_22491 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@amdgpu/amd_cs_nop@sync-fork-gfx0:
- fi-skl-6600u: NOTRUN -> [SKIP][5] ([fdo#109271]) +21 similar issues
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/fi-skl-6600u/igt@amdgpu/[email protected]

* igt@gem_huc_copy@huc-copy:
- fi-skl-6600u: NOTRUN -> [SKIP][6] ([fdo#109271] / [i915#2190])
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/fi-skl-6600u/igt@[email protected]
- fi-glk-dsi: NOTRUN -> [SKIP][7] ([fdo#109271] / [i915#2190])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/fi-glk-dsi/igt@[email protected]

* igt@gem_lmem_swapping@basic:
- fi-glk-dsi: NOTRUN -> [SKIP][8] ([fdo#109271] / [i915#4613]) +3 similar issues
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/fi-glk-dsi/igt@[email protected]

* igt@gem_lmem_swapping@verify-random:
- fi-skl-6600u: NOTRUN -> [SKIP][9] ([fdo#109271] / [i915#4613]) +3 similar issues
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/fi-skl-6600u/igt@[email protected]

* igt@i915_selftest@live@hangcheck:
- fi-snb-2600: [PASS][10] -> [INCOMPLETE][11] ([i915#3921])
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11330/fi-snb-2600/igt@i915_selftest@[email protected]
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/fi-snb-2600/igt@i915_selftest@[email protected]

* igt@kms_chamelium@hdmi-hpd-fast:
- fi-glk-dsi: NOTRUN -> [SKIP][12] ([fdo#109271] / [fdo#111827]) +8 similar issues
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/fi-glk-dsi/igt@[email protected]

* igt@kms_chamelium@vga-edid-read:
- fi-skl-6600u: NOTRUN -> [SKIP][13] ([fdo#109271] / [fdo#111827]) +8 similar issues
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/fi-skl-6600u/igt@[email protected]

* igt@kms_pipe_crc_basic@compare-crc-sanitycheck-pipe-d:
- fi-skl-6600u: NOTRUN -> [SKIP][14] ([fdo#109271] / [i915#533])
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/fi-skl-6600u/igt@[email protected]
- fi-glk-dsi: NOTRUN -> [SKIP][15] ([fdo#109271] / [i915#533])
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/fi-glk-dsi/igt@[email protected]

* igt@kms_psr@primary_page_flip:
- fi-glk-dsi: NOTRUN -> [SKIP][16] ([fdo#109271]) +30 similar issues
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/fi-glk-dsi/igt@kms_psr@primary_page_flip.html

#### Possible fixes ####

* igt@gem_flink_basic@bad-flink:
- fi-skl-6600u: [INCOMPLETE][17] ([i915#4547]) -> [PASS][18]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11330/fi-skl-6600u/igt@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/fi-skl-6600u/igt@[email protected]

* igt@i915_pm_rps@basic-api:
- bat-dg1-5: [FAIL][19] ([i915#4032]) -> [PASS][20]
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11330/bat-dg1-5/igt@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/bat-dg1-5/igt@[email protected]

* igt@i915_selftest@live@active:
- {bat-rpls-2}: [DMESG-WARN][21] ([i915#4391]) -> [PASS][22] +1 similar issue
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11330/bat-rpls-2/igt@i915_selftest@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/bat-rpls-2/igt@i915_selftest@[email protected]

* igt@i915_selftest@live@dmabuf:
- {fi-tgl-dsi}: [FAIL][23] -> [PASS][24]
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11330/fi-tgl-dsi/igt@i915_selftest@[email protected]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/fi-tgl-dsi/igt@i915_selftest@[email protected]

* igt@i915_selftest@live@guc:
- {bat-rpls-2}: [DMESG-WARN][25] -> [PASS][26]
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11330/bat-rpls-2/igt@i915_selftest@[email protected]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/bat-rpls-2/igt@i915_selftest@[email protected]

* igt@kms_flip@basic-flip-vs-wf_vblank@a-edp1:
- {bat-adlp-6}: [DMESG-WARN][27] ([i915#3576]) -> [PASS][28]
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11330/bat-adlp-6/igt@kms_flip@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/bat-adlp-6/igt@kms_flip@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#109315]: https://bugs.freedesktop.org/show_bug.cgi?id=109315
[fdo#111827]: https://bugs.freedesktop.org/show_bug.cgi?id=111827
[i915#1385]: https://gitlab.freedesktop.org/drm/intel/issues/1385
[i915#2190]: https://gitlab.freedesktop.org/drm/intel/issues/2190
[i915#2575]: https://gitlab.freedesktop.org/drm/intel/issues/2575
[i915#3576]: https://gitlab.freedesktop.org/drm/intel/issues/3576
[i915#3921]: https://gitlab.freedesktop.org/drm/intel/issues/3921
[i915#4032]: https://gitlab.freedesktop.org/drm/intel/issues/4032
[i915#4391]: https://gitlab.freedesktop.org/drm/intel/issues/4391
[i915#4547]: https://gitlab.freedesktop.org/drm/intel/issues/4547
[i915#4613]: https://gitlab.freedesktop.org/drm/intel/issues/4613
[i915#533]: https://gitlab.freedesktop.org/drm/intel/issues/533

Build changes
-------------

* Linux: CI_DRM_11330 -> Patchwork_22491

CI-20190529: 20190529
CI_DRM_11330: 68d8cd94c6eaa94aa6bae2e92efbd488523a1a1b @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_6364: 3523fe577bc22e6512a8de7e60175c8f46cf61d2 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_22491: fd2046c6e844f5e24fa10dc2b9c5346e3a1776d0 @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

fd2046c6e844 drm/i915: rework the error handling in *_dpll_params

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_22491/index.html