Skip to content

Commit 00433ea

Browse files
dedekindrafaeljw
authored andcommitted
intel_idle: improve C-state flags handling robustness
The following C-state flags are currently mutually-exclusive and should not be combined: * IRQ_ENABLE * IBRS * XSTATE There is a warning for the situation when the IRQ_ENABLE flag is combined with the IBRS flag, but no warnings for other combinations. This is inconsistent and prone to errors. Improve the situation by adding warnings for all the unexpected combinations. Add a couple of helpful commentaries too. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Reviewed-by: Zhang Rui <rui.zhang@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 1abffbd commit 00433ea

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

drivers/idle/intel_idle.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,20 +1896,28 @@ static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
18961896
drv->states[drv->state_count] = cpuidle_state_table[cstate];
18971897
state = &drv->states[drv->state_count];
18981898

1899-
if ((state->flags & CPUIDLE_FLAG_IRQ_ENABLE) || force_irq_on) {
1900-
pr_info("forced intel_idle_irq for state %d\n", cstate);
1901-
state->enter = intel_idle_irq;
1902-
}
1903-
1904-
if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
1905-
state->flags & CPUIDLE_FLAG_IBRS) {
1899+
if (state->flags & CPUIDLE_FLAG_INIT_XSTATE) {
1900+
/*
1901+
* Combining with XSTATE with IBRS or IRQ_ENABLE flags
1902+
* is not currently supported but this driver.
1903+
*/
1904+
WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IBRS);
1905+
WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
1906+
state->enter = intel_idle_xstate;
1907+
} else if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
1908+
state->flags & CPUIDLE_FLAG_IBRS) {
1909+
/*
1910+
* IBRS mitigation requires that C-states are entered
1911+
* with interrupts disabled.
1912+
*/
19061913
WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
19071914
state->enter = intel_idle_ibrs;
1915+
} else if ((state->flags & CPUIDLE_FLAG_IRQ_ENABLE) ||
1916+
force_irq_on) {
1917+
pr_info("forced intel_idle_irq for state %d\n", cstate);
1918+
state->enter = intel_idle_irq;
19081919
}
19091920

1910-
if (state->flags & CPUIDLE_FLAG_INIT_XSTATE)
1911-
state->enter = intel_idle_xstate;
1912-
19131921
if ((disabled_states_mask & BIT(drv->state_count)) ||
19141922
((icpu->use_acpi || force_use_acpi) &&
19151923
intel_idle_off_by_default(mwait_hint) &&

0 commit comments

Comments
 (0)