Skip to contentSkip to conversation

drm/i915/pmu: Check if pmu is closed before stopping event

PATCH In review Umesh Nerlige Ramappa 3 participants 3 messages Oct 19, 2023 – Oct 24, 2023

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

PATCH 1/1 drm/i915/pmu: Check if pmu is closed before stopping event

When the driver unbinds, pmu is unregistered and i915->uabi_engines is set to RB_ROOT. Due to this, when i915 PMU tries to stop the engine events, it issues a warn_on because engine lookup fails.

All perf hooks are taking care of this using a pmu->closed flag that is set when PMU unregisters. The stop event seems to have been left out.

Check for pmu->closed in pmu_event_stop as well.

Based on discussion here -
https://patchwork.freedesktop.org/patch/492079/?series=105790&rev=2

v2: s/is/if/ in commit title

---
 drivers/gpu/drm/i915/i915_pmu.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/i915/i915_pmu.c +9 -0
index 108b675088ba..f861863eb7c1 100644
@@ -831,9 +831,18 @@ static void i915_pmu_event_start(struct perf_event *event, int flags)
 
 static void i915_pmu_event_stop(struct perf_event *event, int flags)
 {
+	struct drm_i915_private *i915 =
+		container_of(event->pmu, typeof(*i915), pmu.base);
+	struct i915_pmu *pmu = &i915->pmu;
+
+	if (pmu->closed)
+		goto out;
+
 	if (flags & PERF_EF_UPDATE)
 		i915_pmu_event_read(event);
 	i915_pmu_disable(event);
+
+out:
 	event->hw.state = PERF_HES_STOPPED;
 }
 
Signature · 1 line
2.38.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Umesh Nerlige Ramappa

When the driver unbinds, pmu is unregistered and i915->uabi_engines is set to RB_ROOT. Due to this, when i915 PMU tries to stop the engine events, it issues a warn_on because engine lookup fails.

All perf hooks are taking care of this using a pmu->closed flag that is set when PMU unregisters. The stop event seems to have been left out.

Quoted 8 lines

Check for pmu->closed in pmu_event_stop as well.

Based on discussion here -
https://patchwork.freedesktop.org/patch/492079/?series=105790&rev=2

v2: s/is/if/ in commit title

Fixes b00bccb3f0bb ("drm/i915/pmu: Handle PCI unbind")
Cc <[email protected]> # v5.11+
Quoted 17 lines
---
  drivers/gpu/drm/i915/i915_pmu.c | 9 +++++++++
  1 file changed, 9 insertions(+)
drivers/gpu/drm/i915/i915_pmu.c +5 -0
index 108b675088ba..f861863eb7c1 100644
@@ -831,9 +831,18 @@ static void i915_pmu_event_start(struct perf_event *event, int flags)
 
  static void i915_pmu_event_stop(struct perf_event *event, int flags)
  {
+	struct drm_i915_private *i915 =
+		container_of(event->pmu, typeof(*i915), pmu.base);
+	struct i915_pmu *pmu = &i915->pmu;
+
+	if (pmu->closed)

drivers/gpu/drm/i915/i915_pmu.c static void i915_pmu_event_start(struct perf_event *event, int flags) · line 848

Quoted 10 lines
drivers/gpu/drm/i915/i915_pmu.c +4 -0
+		goto out;
+
  	if (flags & PERF_EF_UPDATE)
  		i915_pmu_event_read(event);
  	i915_pmu_disable(event);
+
+out:
  	event->hw.state = PERF_HES_STOPPED;
  }
 

You reminded me of this yesterday and it looks fine to me. Thanks for sending the fix!

Regards,

Tvrtko

Reviewed-by on v1 1/1
#2 lore raw
In reply to Umesh Nerlige Ramappa

Hi Umesh,

Quoted 7 lines · Umesh Nerlige Ramappa

When the driver unbinds, pmu is unregistered and i915->uabi_engines is set to RB_ROOT. Due to this, when i915 PMU tries to stop the engine events, it issues a warn_on because engine lookup fails.

All perf hooks are taking care of this using a pmu->closed flag that is set when PMU unregisters. The stop event seems to have been left out.

Quoted 6 lines

Check for pmu->closed in pmu_event_stop as well.

Based on discussion here -
https://patchwork.freedesktop.org/patch/492079/?series=105790&rev=2

v2: s/is/if/ in commit title

Please, next time version your patches. This is the third time you send this, but there is only one 'v2' changelog.

Quoted 1 line

With Tvrtko's tags:

Andi