@@ -55,4 +55,6 @@ struct arm_cpuidle_irq_context { };
#define arm_cpuidle_save_irq_context(c) (void)c
#define arm_cpuidle_restore_irq_context(c) (void)c
+#include <asm-generic/cpuidle.h>
+
#endif
@@ -38,4 +38,7 @@ struct arm_cpuidle_irq_context { };
#define arm_cpuidle_save_irq_context(c) (void)c
#define arm_cpuidle_restore_irq_context(c) (void)c
#endif
+
+#include <asm-generic/cpuidle.h>
+
#endif
@@ -102,4 +102,8 @@ static inline void report_invalid_psscr_val(u64 psscr_val, int err)
#endif
+#ifndef __ASSEMBLY__
+#include <asm-generic/cpuidle.h>
+#endif
+
#endif
@@ -21,4 +21,6 @@ static inline void cpu_do_idle(void)
wait_for_interrupt();
}
+#include <asm-generic/cpuidle.h>
+
#endif
new file mode 100644
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_CPUIDLE_H
+#define _ASM_X86_CPUIDLE_H
+
+#include <asm/cpufeature.h>
+
+static inline bool arch_cpuidle_mwait_needs_ipi(void)
+{
+ return boot_cpu_has_bug(X86_BUG_MONITOR);
+}
+
+#endif /* _ASM_X86_CPUIDLE_H */
@@ -23,6 +23,7 @@
#include <linux/perf_event.h>
#include <acpi/processor.h>
#include <linux/context_tracking.h>
+#include <asm/cpuidle.h>
/*
* Include the apic definitions for x86 to have the APIC timer related defines
@@ -806,7 +807,8 @@ static int acpi_processor_setup_cstates(struct acpi_processor *pr)
if (cx->type == ACPI_STATE_C1 || cx->type == ACPI_STATE_C2)
drv->safe_state_index = count;
- if (cx->entry_method == ACPI_CSTATE_FFH)
+ if (cx->entry_method == ACPI_CSTATE_FFH &&
+ !arch_cpuidle_mwait_needs_ipi())
state->flags |= CPUIDLE_FLAG_MWAIT;
/*
@@ -56,6 +56,7 @@
#include <asm/mwait.h>
#include <asm/spec-ctrl.h>
#include <asm/fpu/api.h>
+#include <asm/cpuidle.h>
#define INTEL_IDLE_VERSION "0.5.1"
@@ -1787,7 +1788,10 @@ static void __init intel_idle_init_cstates_acpi(struct cpuidle_driver *drv)
if (cx->type > ACPI_STATE_C1)
state->target_residency *= 3;
- state->flags = MWAIT2flg(cx->address) | CPUIDLE_FLAG_MWAIT;
+ state->flags = MWAIT2flg(cx->address);
+
+ if (!arch_cpuidle_mwait_needs_ipi())
+ state->flags |= CPUIDLE_FLAG_MWAIT;
if (cx->type > ACPI_STATE_C2)
state->flags |= CPUIDLE_FLAG_TLB_FLUSHED;
@@ -2073,7 +2077,8 @@ static bool __init intel_idle_verify_cstate(unsigned int mwait_hint)
static void state_update_enter_method(struct cpuidle_state *state, int cstate)
{
- state->flags |= CPUIDLE_FLAG_MWAIT;
+ if (!arch_cpuidle_mwait_needs_ipi())
+ state->flags |= CPUIDLE_FLAG_MWAIT;
if (state->flags & CPUIDLE_FLAG_INIT_XSTATE) {
/*
@@ -13,6 +13,7 @@ mandatory-y += cacheflush.h
mandatory-y += cfi.h
mandatory-y += checksum.h
mandatory-y += compat.h
+mandatory-y += cpuidle.h
mandatory-y += current.h
mandatory-y += delay.h
mandatory-y += device.h
new file mode 100644
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_CPUIDLE_H
+#define __ASM_CPUIDLE_H
+
+static inline bool arch_cpuidle_mwait_needs_ipi(void)
+{
+ return true;
+}
+
+#endif /* __ASM_CPUIDLE_H */
Buggy MWAIT implementations can't carry the CPUIDLE_FLAG_MWAIT flag because they require IPIs to wake up. Therefore they shouldn't be called with TIF_NR_POLLING. Reported-by: Rafael J. Wysocki <rafael@kernel.org> Signed-off-by: Frederic Weisbecker <frederic@kernel.org> --- arch/arm/include/asm/cpuidle.h | 2 ++ arch/arm64/include/asm/cpuidle.h | 3 +++ arch/powerpc/include/asm/cpuidle.h | 4 ++++ arch/riscv/include/asm/cpuidle.h | 2 ++ arch/x86/include/asm/cpuidle.h | 12 ++++++++++++ drivers/acpi/processor_idle.c | 4 +++- drivers/idle/intel_idle.c | 9 +++++++-- include/asm-generic/Kbuild | 1 + include/asm-generic/cpuidle.h | 10 ++++++++++ 9 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 arch/x86/include/asm/cpuidle.h create mode 100644 include/asm-generic/cpuidle.h