Skip to content

Commit d8c216c

Browse files
rjwysockilenb
authored andcommitted
cpuidle: Make cpuidle_enable_device() call poll_idle_init()
The following scenario is possible with the current cpuidle code and the ACPI cpuidle driver: (1) acpi_processor_cst_has_changed() is called, (2) cpuidle_disable_device() is called, (3) cpuidle_remove_state_sysfs() is called to remove the (presumably outdated) states info from sysfs, (3) acpi_processor_get_power_info() is called, the first entry in the pr->power.states[] table is filled with zeros, (4) acpi_processor_setup_cpuidle() is called and it doesn't fill the first entry in pr->power.states[], (5) cpuidle_enable_device() is called, (6) __cpuidle_register_device() is _not_ called, since the device has already been registered, (7) Consequently, poll_idle_init() is _not_ called either, (8) cpuidle_add_state_sysfs() is called to create the sysfs attributes for the new states and it uses the bogus first table entry from acpi_processor_get_power_info() for creating state0. This problem is avoided if cpuidle_enable_device() unconditionally calls poll_idle_init(). Reported-by: Len Brown <len.brown@intel.com> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Signed-off-by: Len Brown <len.brown@intel.com> cc: stable@kernel.org
1 parent ddbd550 commit d8c216c

1 file changed

Lines changed: 41 additions & 41 deletions

File tree

‎drivers/cpuidle/cpuidle.c‎

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,45 @@ void cpuidle_resume_and_unlock(void)
154154

155155
EXPORT_SYMBOL_GPL(cpuidle_resume_and_unlock);
156156

157+
#ifdef CONFIG_ARCH_HAS_CPU_RELAX
158+
static int poll_idle(struct cpuidle_device *dev, struct cpuidle_state *st)
159+
{
160+
ktime_t t1, t2;
161+
s64 diff;
162+
int ret;
163+
164+
t1 = ktime_get();
165+
local_irq_enable();
166+
while (!need_resched())
167+
cpu_relax();
168+
169+
t2 = ktime_get();
170+
diff = ktime_to_us(ktime_sub(t2, t1));
171+
if (diff > INT_MAX)
172+
diff = INT_MAX;
173+
174+
ret = (int) diff;
175+
return ret;
176+
}
177+
178+
static void poll_idle_init(struct cpuidle_device *dev)
179+
{
180+
struct cpuidle_state *state = &dev->states[0];
181+
182+
cpuidle_set_statedata(state, NULL);
183+
184+
snprintf(state->name, CPUIDLE_NAME_LEN, "C0");
185+
snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
186+
state->exit_latency = 0;
187+
state->target_residency = 0;
188+
state->power_usage = -1;
189+
state->flags = CPUIDLE_FLAG_POLL;
190+
state->enter = poll_idle;
191+
}
192+
#else
193+
static void poll_idle_init(struct cpuidle_device *dev) {}
194+
#endif /* CONFIG_ARCH_HAS_CPU_RELAX */
195+
157196
/**
158197
* cpuidle_enable_device - enables idle PM for a CPU
159198
* @dev: the CPU
@@ -178,6 +217,8 @@ int cpuidle_enable_device(struct cpuidle_device *dev)
178217
return ret;
179218
}
180219

220+
poll_idle_init(dev);
221+
181222
if ((ret = cpuidle_add_state_sysfs(dev)))
182223
return ret;
183224

@@ -232,45 +273,6 @@ void cpuidle_disable_device(struct cpuidle_device *dev)
232273

233274
EXPORT_SYMBOL_GPL(cpuidle_disable_device);
234275

235-
#ifdef CONFIG_ARCH_HAS_CPU_RELAX
236-
static int poll_idle(struct cpuidle_device *dev, struct cpuidle_state *st)
237-
{
238-
ktime_t t1, t2;
239-
s64 diff;
240-
int ret;
241-
242-
t1 = ktime_get();
243-
local_irq_enable();
244-
while (!need_resched())
245-
cpu_relax();
246-
247-
t2 = ktime_get();
248-
diff = ktime_to_us(ktime_sub(t2, t1));
249-
if (diff > INT_MAX)
250-
diff = INT_MAX;
251-
252-
ret = (int) diff;
253-
return ret;
254-
}
255-
256-
static void poll_idle_init(struct cpuidle_device *dev)
257-
{
258-
struct cpuidle_state *state = &dev->states[0];
259-
260-
cpuidle_set_statedata(state, NULL);
261-
262-
snprintf(state->name, CPUIDLE_NAME_LEN, "C0");
263-
snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
264-
state->exit_latency = 0;
265-
state->target_residency = 0;
266-
state->power_usage = -1;
267-
state->flags = CPUIDLE_FLAG_POLL;
268-
state->enter = poll_idle;
269-
}
270-
#else
271-
static void poll_idle_init(struct cpuidle_device *dev) {}
272-
#endif /* CONFIG_ARCH_HAS_CPU_RELAX */
273-
274276
/**
275277
* __cpuidle_register_device - internal register function called before register
276278
* and enable routines
@@ -291,8 +293,6 @@ static int __cpuidle_register_device(struct cpuidle_device *dev)
291293

292294
init_completion(&dev->kobj_unregister);
293295

294-
poll_idle_init(dev);
295-
296296
/*
297297
* cpuidle driver should set the dev->power_specified bit
298298
* before registering the device if the driver provides

0 commit comments

Comments
 (0)