Skip to contentSkip to conversation

drm/i915/dp: fix shifting by a negative number of bits

PATCH In review Gustavo A. R. Silva 3 participants 4 messages Sep 12, 2018

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

PATCH 1/1 drm/i915/dp: fix shifting by a negative number of bits

Function intel_port_to_tc() returns PORT_TC_NONE on error, which is a negative value -1. In case PORT_TC_NONE is returned, there is an undefined behavior when shifting by a negative number of bits in both DP_PHY_MODE_STATUS_NOT_SAFE and P_PHY_MODE_STATUS_COMPLETED macros.

Fix this by adding sanity checks on intel_port_to_tc return value, before using macros DP_PHY_MODE_STATUS_NOT_SAFE and P_PHY_MODE_STATUS_COMPLETED.

Addresses-Coverity-ID: 1473324 ("Bad bit shift operation")
Addresses-Coverity-ID: 1473325 ("Bad bit shift operation")

Fixes 39d1e234e1e1 ("drm/i915/icl: implement the tc/legacy HPD {dis,}connect flows")
---
 drivers/gpu/drm/i915/intel_dp.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/i915/intel_dp.c +9 -0
index 436c22d..e34b7b1 100644
@@ -4811,6 +4811,11 @@ static bool icl_tc_phy_connect(struct drm_i915_private *dev_priv,
 	    dig_port->tc_type != TC_PORT_TYPEC)
 		return true;
 
+	if (tc_port < 0) {
+		DRM_DEBUG_KMS("Bad TC port %d\n", tc_port);
+		return false;
+	}
+
 	val = I915_READ(PORT_TX_DFLEXDPPMS);
 	if (!(val & DP_PHY_MODE_STATUS_COMPLETED(tc_port))) {
 		DRM_DEBUG_KMS("DP PHY for TC port %d not ready\n", tc_port);
@@ -4857,6 +4862,10 @@ static void icl_tc_phy_disconnect(struct drm_i915_private *dev_priv,
 	    dig_port->tc_type != TC_PORT_TYPEC)
 		return;
 
+	if (tc_port < 0) {
+		DRM_DEBUG_KMS("Bad TC port %d\n", tc_port);
+		return;
+	}
 	/*
 	 * This function may be called many times in a row without an HPD event
 	 * in between, so try to avoid the write when we can.
Signature · 1 line
2.7.4
#1 lore raw

✓ Fi.CI.BAT: success for drm/i915/dp: fix shifting by a negative number of bits

== Series Details ==

== Series Details ==

Series: drm/i915/dp: fix shifting by a negative number of bits
URL : https://patchwork.freedesktop.org/series/49565/
State : success

== Summary ==

= CI Bug Log - changes from CI_DRM_4812 -> Patchwork_10156 =

== Summary - SUCCESS ==

No regressions found.

External URL: https://patchwork.freedesktop.org/api/1.0/series/49565/revisions/1/mbox/

== Known issues ==

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

=== IGT changes ===

    ==== Issues hit ====

    igt@drv_selftest@live_guc:
      fi-skl-guc:         NOTRUN -> DMESG-WARN (fdo#107258)

    igt@kms_pipe_crc_basic@read-crc-pipe-b:
      fi-byt-clapper:     PASS -> FAIL (fdo#107362) +1

    igt@kms_psr@primary_page_flip:
      fi-kbl-7560u:       PASS -> FAIL (fdo#107336)

    
    ==== Possible fixes ====

    igt@kms_frontbuffer_tracking@basic:
      fi-byt-clapper:     FAIL (fdo#103167) -> PASS

fdo#103167 https://bugs.freedesktop.org/show_bug.cgi?id=103167
fdo#107258 https://bugs.freedesktop.org/show_bug.cgi?id=107258
fdo#107336 https://bugs.freedesktop.org/show_bug.cgi?id=107336
fdo#107362 https://bugs.freedesktop.org/show_bug.cgi?id=107362

== Participating hosts (49 -> 44) ==

Additional (2): fi-byt-j1900 fi-skl-guc
Missing (7): fi-ilk-m540 fi-bxt-dsi fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-ctg-p8600 fi-icl-u

== Build changes ==

* Linux: CI_DRM_4812 -> Patchwork_10156

CI_DRM_4812: 7bed140e1a21dc0e04f2fd87d2726f47b845e82f @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_4640: 9a8da36e708f9ed15b20689dfe305e41f9a19008 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_10156: bfad517ac799fbbfa711620c387d61e645ed8e67 @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

bfad517ac799 drm/i915/dp: fix shifting by a negative number of bits

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_10156/issues.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#2 lore raw

✓ Fi.CI.IGT: success for drm/i915/dp: fix shifting by a negative number of bits

In reply to Gustavo A. R. Silva
== Series Details ==

== Series Details ==

Series: drm/i915/dp: fix shifting by a negative number of bits
URL : https://patchwork.freedesktop.org/series/49565/
State : success

== Summary ==

= CI Bug Log - changes from CI_DRM_4812_full -> Patchwork_10156_full =

== Summary - SUCCESS ==

No regressions found.

== Known issues ==

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

=== IGT changes ===

    ==== Issues hit ====

    igt@gem_userptr_blits@dmabuf-sync:
      shard-snb:          PASS -> INCOMPLETE (fdo#105411)

    igt@kms_setmode@basic:
      shard-apl:          PASS -> FAIL (fdo#99912)

    igt@perf@rc6-disable:
      shard-kbl:          PASS -> FAIL (fdo#103179)

    
    ==== Possible fixes ====

    igt@kms_cursor_legacy@2x-long-cursor-vs-flip-atomic:
      shard-hsw:          FAIL (fdo#105767) -> PASS

    igt@kms_cursor_legacy@cursor-vs-flip-toggle:
      shard-hsw:          FAIL (fdo#103355) -> PASS

    igt@kms_flip@flip-vs-expired-vblank:
      shard-glk:          FAIL (fdo#105363) -> PASS

    igt@kms_setmode@basic:
      shard-kbl:          FAIL (fdo#99912) -> PASS

fdo#103179 https://bugs.freedesktop.org/show_bug.cgi?id=103179
fdo#103355 https://bugs.freedesktop.org/show_bug.cgi?id=103355
fdo#105363 https://bugs.freedesktop.org/show_bug.cgi?id=105363
fdo#105411 https://bugs.freedesktop.org/show_bug.cgi?id=105411
fdo#105767 https://bugs.freedesktop.org/show_bug.cgi?id=105767
fdo#99912 https://bugs.freedesktop.org/show_bug.cgi?id=99912

== Participating hosts (5 -> 5) ==

No changes in participating hosts

== Build changes ==

* Linux: CI_DRM_4812 -> Patchwork_10156

CI_DRM_4812: 7bed140e1a21dc0e04f2fd87d2726f47b845e82f @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_4640: 9a8da36e708f9ed15b20689dfe305e41f9a19008 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_10156: bfad517ac799fbbfa711620c387d61e645ed8e67 @ git://anongit.freedesktop.org/gfx-ci/linux
piglit_4509: fdc5a4ca11124ab8413c7988896eec4c97336694 @ git://anongit.freedesktop.org/piglit

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_10156/shards.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw
In reply to Gustavo A. R. Silva

Em Qua, 2018-09-12 às 09:31 -0500, Gustavo A. R. Silva escreveu:

Quoted 10 lines

Function intel_port_to_tc() returns PORT_TC_NONE on error, which is a negative value -1. In case PORT_TC_NONE is returned, there is an undefined behavior when shifting by a negative number of bits in both DP_PHY_MODE_STATUS_NOT_SAFE and P_PHY_MODE_STATUS_COMPLETED macros.

Fix this by adding sanity checks on intel_port_to_tc return value, before
using macros DP_PHY_MODE_STATUS_NOT_SAFE and P_PHY_MODE_STATUS_COMPLETED.

This was just discussed yesterday in a patch by Rodrigo:

https://patchwork.freedesktop.org/patch/246903/

I would personally prefer his version because it avoids passing -1 to register macros that Coverity doesn't seem to care about, it's a single check and it prints WARN() instead of DRM_DEBUG_KMS().

Although I do prefer your commit message explanation :).

Perhaps I should reconsider my vote to not merge it. Or we could actually go and test what happens when intel_port_to_tc() is broken, fixing all the issues instead of just the ones reported by Coverity.

Anyway, Rodrigo's patch with an improved commit message could receive my R-B tag now.

Quoted 40 lines

Addresses-Coverity-ID: 1473324 ("Bad bit shift operation")
Addresses-Coverity-ID: 1473325 ("Bad bit shift operation")

Fixes 39d1e234e1e1 ("drm/i915/icl: implement the tc/legacy HPD

{dis,}connect flows")

---
 drivers/gpu/drm/i915/intel_dp.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/i915/intel_dp.c +5 -0
index 436c22d..e34b7b1 100644
@@ -4811,6 +4811,11 @@ static bool icl_tc_phy_connect(struct
 drm_i915_private *dev_priv,
 	    dig_port->tc_type != TC_PORT_TYPEC)
 		return true;
 
+	if (tc_port < 0) {
+		DRM_DEBUG_KMS("Bad TC port %d\n", tc_port);
+		return false;
+	}
+
 	val = I915_READ(PORT_TX_DFLEXDPPMS);
 	if (!(val & DP_PHY_MODE_STATUS_COMPLETED(tc_port))) {

DRM_DEBUG_KMS("DP PHY for TC port %d not ready\n",
tc_port);

drivers/gpu/drm/i915/intel_dp.c +4 -0
@@ -4857,6 +4862,10 @@ static void icl_tc_phy_disconnect(struct
 drm_i915_private *dev_priv,
 	    dig_port->tc_type != TC_PORT_TYPEC)
 		return;
 
+	if (tc_port < 0) {
+		DRM_DEBUG_KMS("Bad TC port %d\n", tc_port);
+		return;
+	}
 	/*
 	 * This function may be called many times in a row without
Quoted 2 lines

an HPD event
* in between, so try to avoid the write when we can.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel