Skip to content

Commit 19ee5e8

Browse files
mwiniarsjnikula
authored andcommitted
drm/i915/pmu: Avoid using globals for CPU hotplug state
Attempting to bind / unbind module from devices where we have both integrated and discreete GPU handled by i915 can lead to leaks and warnings from cpuhp: Error: Removing state XXX which has instances left. Let's move the state to i915_pmu. Fixes: 0548867 ("drm/i915/pmu: Support multiple GPUs") Signed-off-by: Michał Winiarski <[email protected]> Cc: Chris Wilson <[email protected]> Cc: Michal Wajdeczko <[email protected]> Cc: Tvrtko Ursulin <[email protected]> Reviewed-by: Chris Wilson <[email protected]> Signed-off-by: Chris Wilson <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit f5a179d) Signed-off-by: Jani Nikula <[email protected]>
1 parent eee1893 commit 19ee5e8

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

drivers/gpu/drm/i915/i915_pmu.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ static void free_event_attributes(struct i915_pmu *pmu)
10421042

10431043
static int i915_pmu_cpu_online(unsigned int cpu, struct hlist_node *node)
10441044
{
1045-
struct i915_pmu *pmu = hlist_entry_safe(node, typeof(*pmu), node);
1045+
struct i915_pmu *pmu = hlist_entry_safe(node, typeof(*pmu), cpuhp.node);
10461046

10471047
GEM_BUG_ON(!pmu->base.event_init);
10481048

@@ -1055,7 +1055,7 @@ static int i915_pmu_cpu_online(unsigned int cpu, struct hlist_node *node)
10551055

10561056
static int i915_pmu_cpu_offline(unsigned int cpu, struct hlist_node *node)
10571057
{
1058-
struct i915_pmu *pmu = hlist_entry_safe(node, typeof(*pmu), node);
1058+
struct i915_pmu *pmu = hlist_entry_safe(node, typeof(*pmu), cpuhp.node);
10591059
unsigned int target;
10601060

10611061
GEM_BUG_ON(!pmu->base.event_init);
@@ -1072,8 +1072,6 @@ static int i915_pmu_cpu_offline(unsigned int cpu, struct hlist_node *node)
10721072
return 0;
10731073
}
10741074

1075-
static enum cpuhp_state cpuhp_slot = CPUHP_INVALID;
1076-
10771075
static int i915_pmu_register_cpuhp_state(struct i915_pmu *pmu)
10781076
{
10791077
enum cpuhp_state slot;
@@ -1087,21 +1085,22 @@ static int i915_pmu_register_cpuhp_state(struct i915_pmu *pmu)
10871085
return ret;
10881086

10891087
slot = ret;
1090-
ret = cpuhp_state_add_instance(slot, &pmu->node);
1088+
ret = cpuhp_state_add_instance(slot, &pmu->cpuhp.node);
10911089
if (ret) {
10921090
cpuhp_remove_multi_state(slot);
10931091
return ret;
10941092
}
10951093

1096-
cpuhp_slot = slot;
1094+
pmu->cpuhp.slot = slot;
10971095
return 0;
10981096
}
10991097

11001098
static void i915_pmu_unregister_cpuhp_state(struct i915_pmu *pmu)
11011099
{
1102-
WARN_ON(cpuhp_slot == CPUHP_INVALID);
1103-
WARN_ON(cpuhp_state_remove_instance(cpuhp_slot, &pmu->node));
1104-
cpuhp_remove_multi_state(cpuhp_slot);
1100+
WARN_ON(pmu->cpuhp.slot == CPUHP_INVALID);
1101+
WARN_ON(cpuhp_state_remove_instance(pmu->cpuhp.slot, &pmu->cpuhp.node));
1102+
cpuhp_remove_multi_state(pmu->cpuhp.slot);
1103+
pmu->cpuhp.slot = CPUHP_INVALID;
11051104
}
11061105

11071106
static bool is_igp(struct drm_i915_private *i915)
@@ -1128,6 +1127,7 @@ void i915_pmu_register(struct drm_i915_private *i915)
11281127
spin_lock_init(&pmu->lock);
11291128
hrtimer_init(&pmu->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
11301129
pmu->timer.function = i915_sample;
1130+
pmu->cpuhp.slot = CPUHP_INVALID;
11311131

11321132
if (!is_igp(i915)) {
11331133
pmu->name = kasprintf(GFP_KERNEL,

drivers/gpu/drm/i915/i915_pmu.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ struct i915_pmu_sample {
3939

4040
struct i915_pmu {
4141
/**
42-
* @node: List node for CPU hotplug handling.
42+
* @cpuhp: Struct used for CPU hotplug handling.
4343
*/
44-
struct hlist_node node;
44+
struct {
45+
struct hlist_node node;
46+
enum cpuhp_state slot;
47+
} cpuhp;
4548
/**
4649
* @base: PMU base.
4750
*/

0 commit comments

Comments
 (0)