Skip to contentSkip to conversation

drm/i915/pmu: avoid -Wmaybe-uninitialized warning

PATCH Superseded Arnd Bergmann 3 participants 7 messages Mar 13, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915/pmu: avoid -Wmaybe-uninitialized warning

The conditional spinlock confuses gcc into thinking the 'flags' value might contain uninitialized data:

drivers/gpu/drm/i915/i915_pmu.c: In function '__i915_pmu_event_read':
arch/x86/include/asm/paravirt_types.h:573:3: error: 'flags' may be used uninitialized in this function [-Werror=maybe-uninitialized]

The code is correct, but it's easy to see how the compiler gets confused here. This avoids the problem by pulling the lock outside of the function into its only caller.

Fixes 1fe699e30113 ("drm/i915/pmu: Fix sleep under atomic in RC6 readout")
---
 drivers/gpu/drm/i915/i915_pmu.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)
drivers/gpu/drm/i915/i915_pmu.c +10 -15
index 4bc7aefa9541..2c8c705d1f18 100644
@@ -415,7 +415,6 @@ static u64 __get_rc6(struct drm_i915_private *i915)
 static u64 get_rc6(struct drm_i915_private *i915, bool locked)
 {
 #if IS_ENABLED(CONFIG_PM)
-	unsigned long flags;
 	u64 val;
 
 	if (intel_runtime_pm_get_if_in_use(i915)) {
@@ -428,18 +427,12 @@ static u64 get_rc6(struct drm_i915_private *i915, bool locked)
 		 * previously.
 		 */
 
-		if (!locked)
-			spin_lock_irqsave(&i915->pmu.lock, flags);
-
 		if (val >= i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur) {
 			i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur = 0;
 			i915->pmu.sample[__I915_SAMPLE_RC6].cur = val;
 		} else {
 			val = i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur;
 		}
-
-		if (!locked)
-			spin_unlock_irqrestore(&i915->pmu.lock, flags);
 	} else {
 		struct pci_dev *pdev = i915->drm.pdev;
 		struct device *kdev = &pdev->dev;
@@ -452,9 +445,6 @@ static u64 get_rc6(struct drm_i915_private *i915, bool locked)
 		 * on top of the last known real value, as the approximated RC6
 		 * counter value.
 		 */
-		if (!locked)
-			spin_lock_irqsave(&i915->pmu.lock, flags);
-
 		spin_lock_irqsave(&kdev->power.lock, flags2);
 
 		if (!i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur)
@@ -470,9 +460,6 @@ static u64 get_rc6(struct drm_i915_private *i915, bool locked)
 		val = jiffies_to_nsecs(val);
 		val += i915->pmu.sample[__I915_SAMPLE_RC6].cur;
 		i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur = val;
-
-		if (!locked)
-			spin_unlock_irqrestore(&i915->pmu.lock, flags);
 	}
 
 	return val;
@@ -519,8 +506,16 @@ static u64 __i915_pmu_event_read(struct perf_event *event, bool locked)
 			val = count_interrupts(i915);
 			break;
 		case I915_PMU_RC6_RESIDENCY:
-			val = get_rc6(i915, locked);
-			break;
+			if (!locked) {
+				unsigned long flags;
+
+				spin_lock_irqsave(&i915->pmu.lock, flags);
+				val = get_rc6(i915, locked);
+				spin_unlock_irqrestore(&i915->pmu.lock, flags);
+				break;
+			} else {
+				val = get_rc6(i915, locked);
+			}
 		}
 	}
 
Signature · 6 lines
2.9.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

✗ Fi.CI.SPARSE: warning for drm/i915/pmu: avoid -Wmaybe-uninitialized warning

== Series Details ==

== Series Details ==

Series: drm/i915/pmu: avoid -Wmaybe-uninitialized warning
URL : https://patchwork.freedesktop.org/series/39857/
State : warning

== Summary ==

$ dim sparse origin/drm-tip
Commit: drm/i915/pmu: avoid -Wmaybe-uninitialized warning
-O:drivers/gpu/drm/i915/i915_pmu.c:442:47: warning: context imbalance in 'get_rc6' - unexpected unlock
+

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#2 lore raw

Re: ✗ Fi.CI.SPARSE: warning for drm/i915/pmu: avoid -Wmaybe-uninitialized warning

Review

Quoted 12 lines · Patchwork

== Series Details ==

Series: drm/i915/pmu: avoid -Wmaybe-uninitialized warning
URL : https://patchwork.freedesktop.org/series/39857/
State : warning

== Summary ==

$ dim sparse origin/drm-tip
Commit: drm/i915/pmu: avoid -Wmaybe-uninitialized warning
(quoted diff) +1 -1
-O:drivers/gpu/drm/i915/i915_pmu.c:442:47: warning: context imbalance in 'get_rc6' - unexpected unlock
+

This means I fixed a warning, not introduced one, right?

Arnd
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw
In reply to Arnd Bergmann

Quoting Arnd Bergmann (2018-03-13 12:08:29)

Quoted 21 lines

The conditional spinlock confuses gcc into thinking the 'flags' value might contain uninitialized data:

drivers/gpu/drm/i915/i915_pmu.c: In function '__i915_pmu_event_read':
arch/x86/include/asm/paravirt_types.h:573:3: error: 'flags' may be used uninitialized in this function [-Werror=maybe-uninitialized]

The code is correct, but it's easy to see how the compiler gets confused here. This avoids the problem by pulling the lock outside of the function into its only caller.

Fixes 1fe699e30113 ("drm/i915/pmu: Fix sleep under atomic in RC6 readout")
---
 drivers/gpu/drm/i915/i915_pmu.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)
drivers/gpu/drm/i915/i915_pmu.c +0 -0
index 4bc7aefa9541..2c8c705d1f18 100644

drivers/gpu/drm/i915/i915_pmu.c static u64 __get_rc6(struct drm_i915_private *i915) · line 415

Quoted 1 line
drivers/gpu/drm/i915/i915_pmu.c +0 -0
@@ -415,7 +415,6 @@ static u64 __get_rc6(struct drm_i915_private *i915)
 static u64 get_rc6(struct drm_i915_private *i915, bool locked)

bool locked is now unused, right?

Quoted 51 lines
drivers/gpu/drm/i915/i915_pmu.c +0 -15
 {
 #if IS_ENABLED(CONFIG_PM)
-       unsigned long flags;
        u64 val;
 
        if (intel_runtime_pm_get_if_in_use(i915)) {
@@ -428,18 +427,12 @@ static u64 get_rc6(struct drm_i915_private *i915, bool locked)
                 * previously.
                 */
 
-               if (!locked)
-                       spin_lock_irqsave(&i915->pmu.lock, flags);
-
                if (val >= i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur) {
                        i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur = 0;
                        i915->pmu.sample[__I915_SAMPLE_RC6].cur = val;
                } else {
                        val = i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur;
                }
-
-               if (!locked)
-                       spin_unlock_irqrestore(&i915->pmu.lock, flags);
        } else {
                struct pci_dev *pdev = i915->drm.pdev;
                struct device *kdev = &pdev->dev;
@@ -452,9 +445,6 @@ static u64 get_rc6(struct drm_i915_private *i915, bool locked)
                 * on top of the last known real value, as the approximated RC6
                 * counter value.
                 */
-               if (!locked)
-                       spin_lock_irqsave(&i915->pmu.lock, flags);
-
                spin_lock_irqsave(&kdev->power.lock, flags2);
 
                if (!i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur)
@@ -470,9 +460,6 @@ static u64 get_rc6(struct drm_i915_private *i915, bool locked)
                val = jiffies_to_nsecs(val);
                val += i915->pmu.sample[__I915_SAMPLE_RC6].cur;
                i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur = val;
-
-               if (!locked)
-                       spin_unlock_irqrestore(&i915->pmu.lock, flags);
        }
 
        return val;
@@ -519,8 +506,16 @@ static u64 __i915_pmu_event_read(struct perf_event *event, bool locked)
                        val = count_interrupts(i915);
                        break;
                case I915_PMU_RC6_RESIDENCY:
-                       val = get_rc6(i915, locked);
-                       break;

drivers/gpu/drm/i915/i915_pmu.c static u64 __i915_pmu_event_read(struct perf_event *event, bool locked) · line 518

Quoted 10 lines
drivers/gpu/drm/i915/i915_pmu.c +10 -0
+                       if (!locked) {
+                               unsigned long flags;
+
+                               spin_lock_irqsave(&i915->pmu.lock, flags);
+                               val = get_rc6(i915, locked);
+                               spin_unlock_irqrestore(&i915->pmu.lock, flags);
+                               break;
+                       } else {
+                               val = get_rc6(i915, locked);
+                       }

break is now on one path only; should be here.
-Chris

#4 lore raw
Quoted 17 lines · Chris Wilson

Quoting Arnd Bergmann (2018-03-13 12:08:29)

Quoted 16 lines

The conditional spinlock confuses gcc into thinking the 'flags' value might contain uninitialized data:

drivers/gpu/drm/i915/i915_pmu.c: In function '__i915_pmu_event_read':
arch/x86/include/asm/paravirt_types.h:573:3: error: 'flags' may be used uninitialized in this function [-Werror=maybe-uninitialized]

The code is correct, but it's easy to see how the compiler gets confused here. This avoids the problem by pulling the lock outside of the function into its only caller.

Fixes 1fe699e30113 ("drm/i915/pmu: Fix sleep under atomic in RC6 readout")
---
 drivers/gpu/drm/i915/i915_pmu.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)
Quoted 8 lines

drivers/gpu/drm/i915/i915_pmu.c static u64 __get_rc6(struct drm_i915_private *i915) · line 415

Quoted 6 lines
drivers/gpu/drm/i915/i915_pmu.c +0 -0
index 4bc7aefa9541..2c8c705d1f18 100644
@@ -415,7 +415,6 @@ static u64 __get_rc6(struct drm_i915_private *i915)
 static u64 get_rc6(struct drm_i915_private *i915, bool locked)

bool locked is now unused, right?

Right, removing it now.

Quoted 13 lines

drivers/gpu/drm/i915/i915_pmu.c static u64 __i915_pmu_event_read(struct perf_event *event, bool locked) · line 518

Quoted 12 lines
drivers/gpu/drm/i915/i915_pmu.c +10 -2
-                       val = get_rc6(i915, locked);
-                       break;
+                       if (!locked) {
+                               unsigned long flags;
+
+                               spin_lock_irqsave(&i915->pmu.lock, flags);
+                               val = get_rc6(i915, locked);
+                               spin_unlock_irqrestore(&i915->pmu.lock, flags);
+                               break;
+                       } else {
+                               val = get_rc6(i915, locked);
+                       }
Quoted 1 line

break is now on one path only; should be here.

Fixed as well. I'll wait a bit for more comments before resending.

Thanks for the review!

Arnd
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#5 lore raw

✓ Fi.CI.BAT: success for drm/i915/pmu: avoid -Wmaybe-uninitialized warning

In reply to Arnd Bergmann
== Series Details ==

== Series Details ==

Series: drm/i915/pmu: avoid -Wmaybe-uninitialized warning
URL : https://patchwork.freedesktop.org/series/39857/
State : success

== Summary ==

Series 39857v1 drm/i915/pmu: avoid -Wmaybe-uninitialized warning
https://patchwork.freedesktop.org/api/1.0/series/39857/revisions/1/mbox/

---- Known issues:

Test kms_chamelium:

        Subgroup dp-edid-read:
                pass       -> FAIL       (fi-kbl-7500u) fdo#102505

fdo#102505 https://bugs.freedesktop.org/show_bug.cgi?id=102505

fi-bdw-5557u     total:288  pass:267  dwarn:0   dfail:0   fail:0   skip:21  time:429s
fi-bdw-gvtdvm    total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:433s
fi-blb-e6850     total:288  pass:223  dwarn:1   dfail:0   fail:0   skip:64  time:383s
fi-bsw-n3050     total:288  pass:242  dwarn:0   dfail:0   fail:0   skip:46  time:530s
fi-bwr-2160      total:288  pass:183  dwarn:0   dfail:0   fail:0   skip:105 time:298s
fi-bxt-dsi       total:288  pass:258  dwarn:0   dfail:0   fail:0   skip:30  time:512s
fi-bxt-j4205     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:512s
fi-byt-j1900     total:288  pass:253  dwarn:0   dfail:0   fail:0   skip:35  time:507s
fi-byt-n2820     total:288  pass:249  dwarn:0   dfail:0   fail:0   skip:39  time:497s
fi-cfl-8700k     total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:410s
fi-cfl-s2        total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:581s
fi-elk-e7500     total:288  pass:229  dwarn:0   dfail:0   fail:0   skip:59  time:427s
fi-gdg-551       total:288  pass:179  dwarn:0   dfail:0   fail:1   skip:108 time:316s
fi-glk-1         total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:529s
fi-hsw-4770      total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:401s
fi-ilk-650       total:288  pass:228  dwarn:0   dfail:0   fail:0   skip:60  time:419s
fi-ivb-3520m     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:475s
fi-ivb-3770      total:288  pass:255  dwarn:0   dfail:0   fail:0   skip:33  time:427s
fi-kbl-7500u     total:288  pass:262  dwarn:1   dfail:0   fail:1   skip:24  time:471s
fi-kbl-7567u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:471s
fi-kbl-r         total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:514s
fi-pnv-d510      total:288  pass:222  dwarn:1   dfail:0   fail:0   skip:65  time:639s
fi-skl-6260u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:451s
fi-skl-6600u     total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:529s
fi-skl-6700hq    total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:539s
fi-skl-6700k2    total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:507s
fi-skl-6770hq    total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:486s
fi-skl-guc       total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:425s
fi-skl-gvtdvm    total:288  pass:265  dwarn:0   dfail:0   fail:0   skip:23  time:442s
fi-snb-2520m     total:288  pass:248  dwarn:0   dfail:0   fail:0   skip:40  time:530s
fi-snb-2600      total:288  pass:248  dwarn:0   dfail:0   fail:0   skip:40  time:404s

Blacklisted hosts:
fi-cnl-drrs total:285 pass:254 dwarn:0 dfail:1 fail:2 skip:27

b27e0c360d42b1dc7da1c4be9094b2acd9dbbe90 drm-tip: 2018y-03m-13d-09h-56m-18s UTC integration manifest c96e70d91cd0 drm/i915/pmu: avoid -Wmaybe-uninitialized warning

== Logs ==

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

#6 lore raw

✓ Fi.CI.IGT: success for drm/i915/pmu: avoid -Wmaybe-uninitialized warning

In reply to Arnd Bergmann
== Series Details ==

== Series Details ==

Series: drm/i915/pmu: avoid -Wmaybe-uninitialized warning
URL : https://patchwork.freedesktop.org/series/39857/
State : success

== Summary ==

---- Known issues:

Test drv_selftest:

        Subgroup live_gtt:
                pass       -> INCOMPLETE (shard-apl) fdo#103927
Test drv_suspend:
        Subgroup forcewake:
                pass       -> SKIP       (shard-hsw) k.org#196691
Test kms_atomic_transition:
        Subgroup 1x-modeset-transitions-nonblocking-fencing:
                pass       -> FAIL       (shard-apl) fdo#103207
Test kms_flip:
        Subgroup 2x-plain-flip-ts-check:
                pass       -> FAIL       (shard-hsw) fdo#100368
Test kms_setmode:
        Subgroup basic:
                pass       -> FAIL       (shard-apl) fdo#99912

fdo#103927 https://bugs.freedesktop.org/show_bug.cgi?id=103927
k.org#196691 https://bugzilla.kernel.org/show_bug.cgi?id=196691
fdo#103207 https://bugs.freedesktop.org/show_bug.cgi?id=103207
fdo#100368 https://bugs.freedesktop.org/show_bug.cgi?id=100368
fdo#99912 https://bugs.freedesktop.org/show_bug.cgi?id=99912

shard-apl        total:3451 pass:1806 dwarn:1   dfail:0   fail:8   skip:1634 time:12539s
shard-hsw        total:3473 pass:1775 dwarn:1   dfail:0   fail:3   skip:1693 time:11781s
shard-snb        total:3473 pass:1364 dwarn:1   dfail:0   fail:3   skip:2105 time:7207s

Blacklisted hosts:
shard-kbl total:3310 pass:1872 dwarn:2 dfail:1 fail:8 skip:1425 time:9411s

== Logs ==

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