Commit a0d62149 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Jia, Yingbao
Browse files

cpuidle,intel_idle: Fix CPUIDLE_FLAG_IRQ_ENABLE

mainline inclusion
from mainline-v5.19
commit 32d4fd57
category: feature
bugzilla: https://gitee.com/openeuler/intel-kernel/issues/IB1H2A
CVE: NA
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=32d4fd5751eadbe1823a37eb38df85ec5c8e6207



-------------------------------------------------

Intel-SIG: commit 32d4fd57 intel_idle: Fix CPUIDLE_FLAG_IRQ_ENABLE
Backport for GNR intel_idle support and fix on 5.10

Commit c227233a ("intel_idle: enable interrupts before C1 on
Xeons") wrecked intel_idle in two ways:

 - must not have tracing in idle functions
 - must return with IRQs disabled

Additionally, it added a branch for no good reason.

Fixes: c227233a ("intel_idle: enable interrupts before C1 on Xeons")
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
[ rjw: Moved the intel_idle() kerneldoc comment next to the function ]
Cc: 5.16+ <stable@vger.kernel.org> # 5.16+
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
[ yingbao jia: amend commit log ]
Signed-off-by: default avataryingbao jia <yingbao.jia@intel.com>
parent 31421c83
Loading
Loading
Loading
Loading
+25 −9
Original line number Diff line number Diff line
@@ -123,6 +123,18 @@ static unsigned int mwait_substates __initdata;
#define flg2MWAIT(flags) (((flags) >> 24) & 0xFF)
#define MWAIT2flg(eax) ((eax & 0xFF) << 24)

static __always_inline int __intel_idle(struct cpuidle_device *dev,
					struct cpuidle_driver *drv, int index)
{
	struct cpuidle_state *state = &drv->states[index];
	unsigned long eax = flg2MWAIT(state->flags);
	unsigned long ecx = 1; /* break on interrupt flag */

	mwait_idle_with_hints(eax, ecx);

	return index;
}

/**
 * intel_idle - Ask the processor to enter the given idle state.
 * @dev: cpuidle device of the target CPU.
@@ -140,18 +152,19 @@ static unsigned int mwait_substates __initdata;
static __cpuidle int intel_idle(struct cpuidle_device *dev,
				struct cpuidle_driver *drv, int index)
{
	struct cpuidle_state *state = &drv->states[index];
	unsigned long eax = flg2MWAIT(state->flags);
	unsigned long ecx = 1; /* break on interrupt flag */

	if (state->flags & CPUIDLE_FLAG_IRQ_ENABLE)
		local_irq_enable();
	return __intel_idle(dev, drv, index);
}

	mwait_idle_with_hints(eax, ecx);
static __cpuidle int intel_idle_irq(struct cpuidle_device *dev,
					struct cpuidle_driver *drv, int index)
{
	int ret;
	raw_local_irq_enable();
	ret = __intel_idle(dev, drv, index);
	raw_local_irq_disable();

	return index;
	return ret;
}

static __cpuidle int intel_idle_ibrs(struct cpuidle_device *dev,
				     struct cpuidle_driver *drv, int index)
{
@@ -1718,6 +1731,9 @@ static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
		/* Structure copy. */
		drv->states[drv->state_count] = cpuidle_state_table[cstate];

		if (cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_IRQ_ENABLE)
			drv->states[drv->state_count].enter = intel_idle_irq;

		if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
		    cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_IBRS) {
			drv->states[drv->state_count].enter = intel_idle_ibrs;