From nobody Sat Feb 7 23:12:01 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 407CF7D077 for ; Thu, 29 Feb 2024 14:23:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709216624; cv=none; b=u2N86rTEDh6deHKnKCWUcu9vYyxCY2D2BglAJWtDN1pST7LuAxXDDhZ6PPbYNZd1tq2jUBtx+JxTykqyBAtXjfA4g0Tuyf0OBQwsE6Gpv3MdJwn7zXuK/Lu+hp8prWzAdEb24llmzzipeTOi4G2gBFMhaETJqXvwlfAif+3SBRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709216624; c=relaxed/simple; bh=55zY29d/udGnwxmlXArsqLI2//BoHZlNbwI2T6gnHa0=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=annw+5e0rw77gkcX2Qu4iEgLWN5tHVO7A+QLcZmiFv0swBa1YeTRNwSKtwAzMeM4yI+hmmcO597iNKCA8FeBXutQIp52XVJXbOUIJomLXe7y+ivefGwMMWu6BybhcEKdWXqlr3H/o9iOT22Vwj28rouSuSECbmWqOpWv88z1osE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=iUrN2S+N; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=C6geCrle; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iUrN2S+N"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="C6geCrle" Message-ID: <20240229142248.266708822@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709216616; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=B2ejJz0qvL4jeeFT2KaF7scEKPWGORNFA2dKFt8UgLE=; b=iUrN2S+NTli3nENJPs7zEEU6lAsSJdtgYDc9lkZY1OomCHRMd5yh9HonHdSUuiwipCe4Kd nnurYBBpb+Ff8kinKlHG6fRpD5tL5mXJTnfucuq5OyE4plz2w0MDBAmFG5rcx0QoXxJ2ZO Jz8iWrpcoj6JXY3uup34p3yiV4NVu5AS1hS64XQQSOERqVUzJWnXtuGgHHydMXciEaesvL 48F+5JgFMeYNI/HOzJEpXp40kMlHqHK17iMxUhZKA+7r4M1gMvuUYwNrxgWjzc10Ui9Q/d oK0DOJykitjbhZN8kwpmHlWBaDahVnLr43T75mUDr+ZIcbtVCjrdxSgajV9LLg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709216616; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=B2ejJz0qvL4jeeFT2KaF7scEKPWGORNFA2dKFt8UgLE=; b=C6geCrlePlpAOvHxrTnAQXKX1fJbKeUGszlgICNxUaOo2FBTakEpwqjJOlsFPOeIA/2PV6 tgwCv0qEhBzHBqAA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Steven Rostedt , "Paul E. McKenney" , Borislav Petkov Subject: [patch 1/6] sched/idle: Conditionally handle tick broadcast in default_idle_call() References: <20240229141407.283316443@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Thu, 29 Feb 2024 15:23:36 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X86 has a idle routine for AMD CPUs which are affected by erratum 400. On the affected CPUs the local APIC timer stops in the C1E halt state. It therefore requires tick broadcasting. The invocation of tick_broadcast_enter()/exit() from this function violates the RCU constraints because it can end up in lockdep or tracing, which rightfully triggers a warning. tick_broadcast_enter()/exit() must be invoked before ct_cpuidle_enter() and after ct_cpuidle_exit() in default_idle_call(). Add a static branch conditional invocation of tick_broadcast_enter()/exit() into this function to allow X86 to replace the AMD specific idle code. It's guarded by a config switch which will be selected by X86. Otherwise it's a NOOP. Reported-by: Borislav Petkov Signed-off-by: Thomas Gleixner Tested-by: Borislav Petkov (AMD) --- include/linux/cpu.h | 2 ++ include/linux/tick.h | 3 +++ kernel/sched/idle.c | 21 +++++++++++++++++++++ kernel/time/Kconfig | 5 +++++ 4 files changed, 31 insertions(+) --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -196,6 +196,8 @@ void arch_cpu_idle(void); void arch_cpu_idle_prepare(void); void arch_cpu_idle_enter(void); void arch_cpu_idle_exit(void); +void arch_tick_broadcast_enter(void); +void arch_tick_broadcast_exit(void); void __noreturn arch_cpu_idle_dead(void); =20 #ifdef CONFIG_ARCH_HAS_CPU_FINALIZE_INIT --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -12,6 +12,7 @@ #include #include #include +#include =20 #ifdef CONFIG_GENERIC_CLOCKEVENTS extern void __init tick_init(void); @@ -69,6 +70,8 @@ extern void tick_broadcast_control(enum static inline void tick_broadcast_control(enum tick_broadcast_mode mode) {= } #endif /* BROADCAST */ =20 +extern struct static_key_false arch_needs_tick_broadcast; + #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_HOTPLU= G_CPU) extern void tick_offline_cpu(unsigned int cpu); #else --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -81,6 +81,25 @@ void __weak arch_cpu_idle(void) cpu_idle_force_poll =3D 1; } =20 +#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST_IDLE +DEFINE_STATIC_KEY_FALSE(arch_needs_tick_broadcast); + +static inline void cond_tick_broadcast_enter(void) +{ + if (static_branch_unlikely(&arch_needs_tick_broadcast)) + tick_broadcast_enter(); +} + +static inline void cond_tick_broadcast_exit(void) +{ + if (static_branch_unlikely(&arch_needs_tick_broadcast)) + tick_broadcast_exit(); +} +#else +static inline void cond_tick_broadcast_enter(void) { } +static inline void cond_tick_broadcast_exit(void) { } +#endif + /** * default_idle_call - Default CPU idle routine. * @@ -90,6 +109,7 @@ void __cpuidle default_idle_call(void) { instrumentation_begin(); if (!current_clr_polling_and_test()) { + cond_tick_broadcast_enter(); trace_cpu_idle(1, smp_processor_id()); stop_critical_timings(); =20 @@ -99,6 +119,7 @@ void __cpuidle default_idle_call(void) =20 start_critical_timings(); trace_cpu_idle(PWR_EVENT_EXIT, smp_processor_id()); + cond_tick_broadcast_exit(); } local_irq_enable(); instrumentation_end(); --- a/kernel/time/Kconfig +++ b/kernel/time/Kconfig @@ -39,6 +39,11 @@ config GENERIC_CLOCKEVENTS_BROADCAST bool depends on GENERIC_CLOCKEVENTS =20 +# Handle broadcast in default_idle_call() +config GENERIC_CLOCKEVENTS_BROADCAST_IDLE + bool + depends on GENERIC_CLOCKEVENTS_BROADCAST + # Automatically adjust the min. reprogramming time for # clock event device config GENERIC_CLOCKEVENTS_MIN_ADJUST From nobody Sat Feb 7 23:12:01 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 862EA12AAC1 for ; Thu, 29 Feb 2024 14:23:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709216623; cv=none; b=rDx/jkPoXGxsf8ZkajlbLVIQqx99UT9+mmKoCeaoEH5YOPS4rksKmP2hirccRwWu4epXo3aUTQ6HNmblQwcg8cmqQIDiRJ1TvxU570PzF4Z3S43g4IS3MNqC2MFnAWrhRRRIzdbcHXIlouzOJ1249aYgSKmoiGF0Uwadr3lul38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709216623; c=relaxed/simple; bh=kLDDncfMIoSPBawEujdd+4tOaINTsXZmxPLVrOH1Mso=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=fibr1sKsB7aM00z3jypUbPgv0mveI30cm5SVUDF6Ou8OmeLClehYOsm2wzvb3GwBUFuzRFD8HpzE8zvtYRbW7ScySXskj2lOdVbPTwrZXiSql/+d034pDN69eSsAztR9/Lji15cA4/NK5tIL69L4jV6HQcHfZewVdJ+1J+m2fns= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=c4jRcutT; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cGnSZjKl; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="c4jRcutT"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cGnSZjKl" Message-ID: <20240229142248.329708185@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709216617; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=NwhFXWiIfv03GUNxMbXr1/eiWot+mUon4MYYqtAsfLk=; b=c4jRcutTzFfHbzAqlu7h87okmmgm8AJHNxVr8cp0XiCrtyDJM6V61QkM3JM4ZSJtFX1DDx Uzr9wF8XjSC3f1DJk9KdBvlP3GRsdOUFmoYCig+ji47WRcVNHbCP8WRV7rpP542lnb7tRE ZOlo+1i7AeW11TlM04lG80/iD/EOB+slfKBr0Ok3W2BDQLss2yQ7yuq5hADpqL4Av6Zk3z LLbwASBQuT2pdhSpv9S1SCzyMza2Cf8ofvTWFxURMe4qla2G/lUTFtoxAGm3NOKI6+vyT2 sBfaEqVQsGszGk3iFDVJ4Dl/UQ4t9qEmnn6jlzEhgZs5kQ7iBHNlhRc9u7G3Ow== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709216617; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=NwhFXWiIfv03GUNxMbXr1/eiWot+mUon4MYYqtAsfLk=; b=cGnSZjKlw69F5tPrAxUo5pqjKGbhSMDoasLn+3YkL9b70Ol1cygv3AkMBn8Erj07HBQa8W QLiE+zIOwvZ7UoDA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Steven Rostedt , "Paul E. McKenney" , Borislav Petkov Subject: [patch 2/6] x86/idle: Sanitize X86_BUG_AMD_E400 handling References: <20240229141407.283316443@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Thu, 29 Feb 2024 15:23:37 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" amd_e400_idle(), the idle routine for AMD CPUs which are affected by erratum 400 violates the RCU constraints by invoking tick_broadcast_enter() and tick_broadcast_exit() after the core code has marked RCU non-idle. The functions can end up in lockdep or tracing, which rightfully triggers a RCU warning. The core code provides now a static branch conditional invocation of the broadcast functions. Remove amd_e400_idle(), enforce default_idle() and enable the static branch on affected CPUs to cure this. Reported-by: Borislav Petkov Signed-off-by: Thomas Gleixner Tested-by: Borislav Petkov (AMD) --- arch/x86/Kconfig | 1 + arch/x86/kernel/process.c | 41 ++++++++--------------------------------- 2 files changed, 9 insertions(+), 33 deletions(-) --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -147,6 +147,7 @@ config X86 select EDAC_ATOMIC_SCRUB select EDAC_SUPPORT select GENERIC_CLOCKEVENTS_BROADCAST if X86_64 || (X86_32 && X86_LOCAL_AP= IC) + select GENERIC_CLOCKEVENTS_BROADCAST_IDLE if GENERIC_CLOCKEVENTS_BROADCAST select GENERIC_CLOCKEVENTS_MIN_ADJUST select GENERIC_CMOS_UPDATE select GENERIC_CPU_AUTOPROBE --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -846,31 +846,6 @@ void __noreturn stop_this_cpu(void *dumm } =20 /* - * AMD Erratum 400 aware idle routine. We handle it the same way as C3 pow= er - * states (local apic timer and TSC stop). - * - * XXX this function is completely buggered vs RCU and tracing. - */ -static void amd_e400_idle(void) -{ - /* - * We cannot use static_cpu_has_bug() here because X86_BUG_AMD_APIC_C1E - * gets set after static_cpu_has() places have been converted via - * alternatives. - */ - if (!boot_cpu_has_bug(X86_BUG_AMD_APIC_C1E)) { - default_idle(); - return; - } - - tick_broadcast_enter(); - - default_idle(); - - tick_broadcast_exit(); -} - -/* * Prefer MWAIT over HALT if MWAIT is supported, MWAIT_CPUID leaf * exists and whenever MONITOR/MWAIT extensions are present there is at * least one C1 substate. @@ -890,8 +865,8 @@ static int prefer_mwait_c1_over_halt(con if (!cpu_has(c, X86_FEATURE_MWAIT)) return 0; =20 - /* Monitor has a bug. Fallback to HALT */ - if (boot_cpu_has_bug(X86_BUG_MONITOR)) + /* Monitor has a bug or APIC stops in C1E. Fallback to HALT */ + if (boot_cpu_has_bug(X86_BUG_MONITOR) || boot_cpu_has_bug(X86_BUG_AMD_API= C_C1E)) return 0; =20 cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &edx); @@ -942,17 +917,15 @@ void select_idle_routine(const struct cp if (x86_idle_set() || boot_option_idle_override =3D=3D IDLE_POLL) return; =20 - if (boot_cpu_has_bug(X86_BUG_AMD_E400)) { - pr_info("using AMD E400 aware idle routine\n"); - static_call_update(x86_idle, amd_e400_idle); - } else if (prefer_mwait_c1_over_halt(c)) { + if (prefer_mwait_c1_over_halt(c)) { pr_info("using mwait in idle threads\n"); static_call_update(x86_idle, mwait_idle); } else if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) { pr_info("using TDX aware idle routine\n"); static_call_update(x86_idle, tdx_safe_halt); - } else + } else { static_call_update(x86_idle, default_idle); + } } =20 void amd_e400_c1e_apic_setup(void) @@ -985,7 +958,9 @@ void __init arch_post_acpi_subsys_init(v =20 if (!boot_cpu_has(X86_FEATURE_NONSTOP_TSC)) mark_tsc_unstable("TSC halt in AMD C1E"); - pr_info("System has AMD C1E enabled\n"); + + static_branch_enable(&arch_needs_tick_broadcast); + pr_info("System has AMD C1E erratum E400. Workaround enabled.\n"); } =20 static int __init idle_setup(char *str) From nobody Sat Feb 7 23:12:01 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DAF9012E1E3 for ; Thu, 29 Feb 2024 14:23:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709216623; cv=none; b=sYLMlEdSjLFVa+dY3XFnHEAYvAYPHdjOA8WSDAaOiF4oL+8M3KkmmWVPpMqs1W8qgHkQ09V4TWB9KgWBEQgsmCKCIMsDbsNzwKkvAJCQndwwEEAi11/Qom+x3AHMqDhjCUjbvNHciBWPHCn6M9lrBPkvSCc5w+dVtcQficvCtyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709216623; c=relaxed/simple; bh=oeg0kEbXFXlw0/cW4ak9QngSFlXFHmiohtL35YQM4Yc=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=VZrqUhDS5mu7TnuNX8qaLV5i0HHLgmLTKpr/ghmZi87Xs1wvZSVb7OdDATEQ6MIgMWG38mNfAP/7AsUgQz4Nd1ONXbD+8IKYn0trH6yqwsbacwSQNLfAuxbmyugYHH08xc4yDf6zVlv50nApEhQUng9fstLr13mno7QsQTRSrfM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=HW/R8PJP; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=vs+Vo4oz; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HW/R8PJP"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vs+Vo4oz" Message-ID: <20240229142248.392017685@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709216619; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=Atj5tI/wQAeX3+mHod6Chan4BMI8xFQMxbYKR6KaLnk=; b=HW/R8PJPEVN3RwQ0leIB6iAt07gJng02l9rCWeR4jo39BtXeLQQ8KJGZeGICXLTTUJjHCY vvP0kE4z+DQ97CpvguN7nva0qiYDTRaOgWmPhifXtdgZKrB7rs5DbcqRldSBPHKupHupOc bSIon7eodjLO2ddH/L5CMZHn7fTpBZ/qAcdb8KWlqEYBVT4vxJCOZsA7cTVgpL3T9QvLHu v+L6RKc45ocjTnaK8Ff39+IX7T4L886KmsR+59DP9+3hqM0ztj20vzp4hTj4mC8EoAgZU+ /Hx6LG838jpgefRWXCX73i4HPC+qfz3ZBNn2HNlukCyZxwHSvq1dqqI8YnBUAw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709216619; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=Atj5tI/wQAeX3+mHod6Chan4BMI8xFQMxbYKR6KaLnk=; b=vs+Vo4ozht/yHfoiPScLoNFWqBLtKWWIF8TccoZWL4gz0F60YU727MAndiTxw5BdRHtdWN BKG+JtB5jP17JXAw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Steven Rostedt , "Paul E. McKenney" Subject: [patch 3/6] x86/idle: Clean up idle selection References: <20240229141407.283316443@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Thu, 29 Feb 2024 15:23:38 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Clean up the code to make it readable. No functional change. Signed-off-by: Thomas Gleixner Tested-by: Borislav Petkov (AMD) --- arch/x86/kernel/process.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -910,11 +910,13 @@ static __cpuidle void mwait_idle(void) =20 void select_idle_routine(const struct cpuinfo_x86 *c) { -#ifdef CONFIG_SMP - if (boot_option_idle_override =3D=3D IDLE_POLL && smp_num_siblings > 1) - pr_warn_once("WARNING: polling idle and HT enabled, performance may degr= ade\n"); -#endif - if (x86_idle_set() || boot_option_idle_override =3D=3D IDLE_POLL) + if (boot_option_idle_override =3D=3D IDLE_POLL) { + if (IS_ENABLED(CONFIG_SMP) && smp_num_siblings > 1) + pr_warn_once("WARNING: polling idle and HT enabled, performance may deg= rade\n"); + return; + } + + if (x86_idle_set()) return; =20 if (prefer_mwait_c1_over_halt(c)) { From nobody Sat Feb 7 23:12:01 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DAF4812E1CC for ; Thu, 29 Feb 2024 14:23:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709216624; cv=none; b=hL+UlSINz/SRVByhQwbQLO0N6X24+O1B6ErlnXts+pjIMjIblSbJMTLkv2yk8a8Ef7e1omkwHkJr+8i2h/dC39Ycew0MXa4T9FPFBBVx7fZ4d6Jmj+bQ8M9WB29LnSJmBKKxN0E2yKxBm2ieCQb+qCNxgXtuZYeGbQ2Ab3Okhss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709216624; c=relaxed/simple; bh=4gP+iCapKlXKlht2djclMxdp9+iBcME2VXu0sjNJfdY=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=TzTi13fwB0QnoqV3sHBqPCCE5pEDUvMtJGFmV4LSYWWehY3QIijt5D8/WvEYbkjOKI7VdhrnjA6gGgJwJkzU5skP3LgHmdo8V8UH2I6guh/XLR6heVxOiVT8mBEAJqBGKqeEtqsQa3RL8u6xlAfU3r8EFD7Kx0jGtwJbCyZpgiw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gQxTa00y; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=wht6X27n; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gQxTa00y"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wht6X27n" Message-ID: <20240229142248.455616019@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709216620; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=5zOS4RmiqmuxETrUeHDkk2a5VYE4kSbamD+YHfMNWQI=; b=gQxTa00y5xXOnO+IsbeQpXwy0aF7+r804PplTpYmFwo3UCQHh2zhkCjgDXY9ylKgsECxD+ bRq471S+WVE8Gbmhz3YjVkvMxTUPpgkde/anMmbl4FQUmNOCZRp0nvPx8nxK58V5LYTfS2 W6CD4MnuV/99WwLbvwOEM8CQPVvmpcFWjR6JLZtJp31pQy5GscAJAzn/dNvHbBOkzgtB3U 1yTa7uWypi16DwEEs0E8UCQfGPeFVJuei7VaP9Hc0D3cu4Ox7UfH6GP1jcKCGcJGtNF/oP MHs9GBcsMgnAr6AkZyjOMCag1poyYi9zdsfAsfi//A7vSmu9sqUikTQQLAR77Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709216620; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=5zOS4RmiqmuxETrUeHDkk2a5VYE4kSbamD+YHfMNWQI=; b=wht6X27nW2dY56wOgfMT4WpRGpikBJZUKKltKmZUE7iUq32/vSKbWZii1rHIT3siqAVr+r i1he2N7vAGxefxCQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Steven Rostedt , "Paul E. McKenney" Subject: [patch 4/6] x86/idle: Cleanup idle_setup() References: <20240229141407.283316443@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Thu, 29 Feb 2024 15:23:40 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Updating the static call for x86_idle() from idle_setup() is counter intuitive. Let select_idle_routine() handle it like the other idle choices, which allows to simplify the idle selection later on. While at it rewrite comments and return a proper error code and not -1. Signed-off-by: Thomas Gleixner Tested-by: Borislav Petkov (AMD) --- arch/x86/kernel/process.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -857,8 +857,8 @@ static int prefer_mwait_c1_over_halt(con { u32 eax, ebx, ecx, edx; =20 - /* User has disallowed the use of MWAIT. Fallback to HALT */ - if (boot_option_idle_override =3D=3D IDLE_NOMWAIT) + /* If override is enforced on the command line, fall back to HALT. */ + if (boot_option_idle_override !=3D IDLE_NO_OVERRIDE) return 0; =20 /* MWAIT is not supported on this platform. Fallback to HALT */ @@ -975,24 +975,14 @@ static int __init idle_setup(char *str) boot_option_idle_override =3D IDLE_POLL; cpu_idle_poll_ctrl(true); } else if (!strcmp(str, "halt")) { - /* - * When the boot option of idle=3Dhalt is added, halt is - * forced to be used for CPU idle. In such case CPU C2/C3 - * won't be used again. - * To continue to load the CPU idle driver, don't touch - * the boot_option_idle_override. - */ - static_call_update(x86_idle, default_idle); + /* 'idle=3Dhalt' HALT for idle. C-states are disabled. */ boot_option_idle_override =3D IDLE_HALT; } else if (!strcmp(str, "nomwait")) { - /* - * If the boot option of "idle=3Dnomwait" is added, - * it means that mwait will be disabled for CPU C1/C2/C3 - * states. - */ + /* 'idle=3Dnomwait' disables MWAIT for idle */ boot_option_idle_override =3D IDLE_NOMWAIT; - } else - return -1; + } else { + return -EINVAL; + } =20 return 0; } From nobody Sat Feb 7 23:12:01 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4AB513774A for ; Thu, 29 Feb 2024 14:23:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709216626; cv=none; b=r/sejhlvD4hlwz8iI0zTPalADv7qDBhW2jm8GfDE+dMsbqpwKQ28oIda2GXU33He3u0iGYnglLYvmliNYLQKZqPeyTxhWym0kXykJ36WoDlxYRJpf1swPdrEb85BdujKqeHgqW+rcw/B9nn6UvzPWxhzyOhKahCm3BDI2oXIE6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709216626; c=relaxed/simple; bh=yV1Vbm8kbRpxhEC85aNrHys8axlAFGfQgZDSVAUbcdE=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=A6neTgu2g58A8Tb6QF36pP4iJUQgzi0ylg8IthObA+8Hozthbw5ekViaqVjItao7C2aOVAO7b6PILV8feSf87Nowj0Ob0X5njEN6PBtNI7BunhdrmHtqO20QkSkJwoRjQlor17X5FVVa8cs2xgziQDnwNnIVXv5SvOxqL/f/G1Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yvLz7rhS; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=2dO8eOrS; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yvLz7rhS"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2dO8eOrS" Message-ID: <20240229142248.518723854@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709216621; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=el2DwwRk9lMlTFOxyOulzJroAc1k+VvNXpXzxagNgoY=; b=yvLz7rhSaw7axm8/3n1DA19ePmitL+wj35rPIcC2uDQouACfyuWIG8QNkxPZ84Fxy/V6fY +Yj9D/MrXBivgT38Wlo/L1SFAKfvmVlaWNjgd0IsO8CSsoa9oTglFryHEhOClNSG8OEvcC y50bYPR81kaN4CHRkr2d66hMUXNdnaEY+MjcBXgNscjAKvf4Ot21ckaJLS17DcQ7ImMecZ Q3QiNHgjWSzX7MAxXCEgG7wH6tvBhk0AXqJTtQncMTFLj6kMxAvH8+3qmI9eLlj+4neQMJ 1jYd+yci1tODDM4s4pcqzvbK/Vf9jWPXMBnxBeKsyZ3JyiDp1J/2TZW41FLyGQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709216621; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=el2DwwRk9lMlTFOxyOulzJroAc1k+VvNXpXzxagNgoY=; b=2dO8eOrSh2R+3dVq5vLwiMqoKO7zRcwIEj8IOfIAsdhwBy9B0nxo3sLA0q1TBXVJIlRIrr AN7GyaXVojKHS/CA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Steven Rostedt , "Paul E. McKenney" Subject: [patch 5/6] x86/idle: Let prefer_mwait_c1_over_halt() return bool References: <20240229141407.283316443@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Thu, 29 Feb 2024 15:23:41 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The return value is truly boolean. Make it so. No functional change. Signed-off-by: Thomas Gleixner Tested-by: Borislav Petkov (AMD) --- arch/x86/kernel/process.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -853,21 +853,21 @@ void __noreturn stop_this_cpu(void *dumm * Do not prefer MWAIT if MONITOR instruction has a bug or idle=3Dnomwait * is passed to kernel commandline parameter. */ -static int prefer_mwait_c1_over_halt(const struct cpuinfo_x86 *c) +static bool prefer_mwait_c1_over_halt(const struct cpuinfo_x86 *c) { u32 eax, ebx, ecx, edx; =20 /* If override is enforced on the command line, fall back to HALT. */ if (boot_option_idle_override !=3D IDLE_NO_OVERRIDE) - return 0; + return false; =20 /* MWAIT is not supported on this platform. Fallback to HALT */ if (!cpu_has(c, X86_FEATURE_MWAIT)) - return 0; + return false; =20 /* Monitor has a bug or APIC stops in C1E. Fallback to HALT */ if (boot_cpu_has_bug(X86_BUG_MONITOR) || boot_cpu_has_bug(X86_BUG_AMD_API= C_C1E)) - return 0; + return false; =20 cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &edx); =20 @@ -876,13 +876,13 @@ static int prefer_mwait_c1_over_halt(con * with EAX=3D0, ECX=3D0. */ if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED)) - return 1; + return true; =20 /* * If MWAIT extensions are available, there should be at least one * MWAIT C1 substate present. */ - return (edx & MWAIT_C1_SUBSTATE_MASK); + return !!(edx & MWAIT_C1_SUBSTATE_MASK); } =20 /* From nobody Sat Feb 7 23:12:01 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39FC41361CF for ; Thu, 29 Feb 2024 14:23:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709216625; cv=none; b=HlTqmkGoIiIS6fkFJgWDV9Gaw0FuyykzWpae1hQhAwJ9zdgedwGsMsJyGrqMYTfi/FWqsCA/SLAGPB9lS9QrlER6JQOlPos16xNmrJgrnO5DIIlP8z5psWv81o95weyqfQcUnc9Y3jEVB1vWDiheKMVIaudrQ+Bh4cYcY3tszD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709216625; c=relaxed/simple; bh=RYjgrsnTa5ZE0/Y2Vs7u3YT+7pEEBNYqFqB94PRnE9Y=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=tbRKIK63v6NKdmYHkegnSVRzR6YgrQdrubXjOOa07P52mLKoAoi9mskikfxm0QBJ63NeeXRq03uMJ/Wabopi08nBgohL43pZU9aY2OEseXKtridKV9eQiKuKCUpNWm0KyJg6hLt5S7cHsV8Eo9Sut3MR2v+v+W8xgGXMVLBdX0s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rCgrKLzN; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=wrb4cDbK; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rCgrKLzN"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wrb4cDbK" Message-ID: <20240229142248.582321500@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709216622; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=LNNG9Jq+5CN9Sd6cMwb+ZtsoydO1GTY3u/PKYA5LbYI=; b=rCgrKLzNnXAJY4Zz0SDVlmyfrwrDTu1tzaZdnmqkKGsPyT8ZvfLWIrxWM0KMMstuUsF4Mp 97wJ0KRpLX6QqeXkvlcbzkZQVfpZTMeusQ4GBJuZER5nrB0oSySQjs0AzfJSWSo8t/SRlr 6lLWUnEMzXPgViZs+oRCFLTeMEc0F3U2qS13dPNPZHXS6TvXvP0W5ncMekrVxuZsiIRpi2 wMqd3IdOQbEng36tO+U9mAnPrkmhi6cJ/bFcwdWjGMAArLWEQs5+WwLIbJjU9ztNBM6IPl E95s9nm1Kd+xIsyPUcrcQshE/PJ1PCWiSk79ZsF5ydZsFZ225Rrg5yCAEIz7MQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709216622; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=LNNG9Jq+5CN9Sd6cMwb+ZtsoydO1GTY3u/PKYA5LbYI=; b=wrb4cDbKtuppv+wHBLyf/kbGN8Bpl/sOApjOH/vE/24sPbalv/MlJMr3qmAp2IwJTtjcka 4qMjKjSYLXXY0ODA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Steven Rostedt , "Paul E. McKenney" Subject: [patch 6/6] x86/idle: Select idle routine only once References: <20240229141407.283316443@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Thu, 29 Feb 2024 15:23:42 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The idle routine selection is done on every CPU bringup operation and has a guard in place which is effective after the first invocation, which is a pointless exercise. Invoke it once on the boot CPU and mark the related functions __init. Signed-off-by: Thomas Gleixner Tested-by: Borislav Petkov (AMD) --- arch/x86/include/asm/processor.h | 2 +- arch/x86/kernel/cpu/common.c | 4 ++-- arch/x86/kernel/process.c | 10 ++++------ 3 files changed, 7 insertions(+), 9 deletions(-) --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -555,7 +555,7 @@ static inline void load_sp0(unsigned lon =20 unsigned long __get_wchan(struct task_struct *p); =20 -extern void select_idle_routine(const struct cpuinfo_x86 *c); +extern void select_idle_routine(void); extern void amd_e400_c1e_apic_setup(void); =20 extern unsigned long boot_option_idle_override; --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1938,8 +1938,6 @@ static void identify_cpu(struct cpuinfo_ /* Init Machine Check Exception if available. */ mcheck_cpu_init(c); =20 - select_idle_routine(c); - #ifdef CONFIG_NUMA numa_add_cpu(smp_processor_id()); #endif @@ -2343,6 +2341,8 @@ void __init arch_cpu_finalize_init(void) { identify_boot_cpu(); =20 + select_idle_routine(); + /* * identify_boot_cpu() initialized SMT support information, let the * core code know. --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -853,8 +853,9 @@ void __noreturn stop_this_cpu(void *dumm * Do not prefer MWAIT if MONITOR instruction has a bug or idle=3Dnomwait * is passed to kernel commandline parameter. */ -static bool prefer_mwait_c1_over_halt(const struct cpuinfo_x86 *c) +static __init bool prefer_mwait_c1_over_halt(void) { + const struct cpuinfo_x86 *c =3D &boot_cpu_data; u32 eax, ebx, ecx, edx; =20 /* If override is enforced on the command line, fall back to HALT. */ @@ -908,7 +909,7 @@ static __cpuidle void mwait_idle(void) __current_clr_polling(); } =20 -void select_idle_routine(const struct cpuinfo_x86 *c) +void __init select_idle_routine(void) { if (boot_option_idle_override =3D=3D IDLE_POLL) { if (IS_ENABLED(CONFIG_SMP) && smp_num_siblings > 1) @@ -916,10 +917,7 @@ void select_idle_routine(const struct cp return; } =20 - if (x86_idle_set()) - return; - - if (prefer_mwait_c1_over_halt(c)) { + if (prefer_mwait_c1_over_halt()) { pr_info("using mwait in idle threads\n"); static_call_update(x86_idle, mwait_idle); } else if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) {