From nobody Fri Dec 19 16:53:36 2025 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 ACC2119CC3D; Sat, 15 Feb 2025 10:55:59 +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=1739616961; cv=none; b=SDmJWxrvqgfXQHbZYd40/C0obnMpsJ9lpx6NBhte1jh7/gxg8hIqGrEm6CVfph8tZWUT/w9gNB7Qh4R0XDvHGp0LSAdNwNbh2Iqt9hUZ5ExjtgFv9Mw5HlCPehfdzLQLStn8AiIXjgYOBkTR9xR+Ue7c8g+sRioGSCu2HT4DFEU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739616961; c=relaxed/simple; bh=8O8yWa4JNktk/uv1oypFkFQwFMHhFkVkTcZPFq1yMWU=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=sDFPg3adTIyNuOpiFtqSRlbiu8oKbj0vGbtu9Q4UHE3XafbXY38xFTPj+szITa6OrYlg+nUBUErjPKbBvMVAT4D7miKUl0C8Z1QsA2aldt52B1+uUrRYpz6UBUarIIna1HUsePMvNk0545TaX9eJMSYfcrnyBMl59dyp567Y2Sw= 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=sUXyXsdJ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=vq2qdn/Q; 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="sUXyXsdJ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vq2qdn/Q" Date: Sat, 15 Feb 2025 10:55:57 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1739616958; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=62eE9xHp8rG2e/+PSOw3vDtld8Mviy7aPJkKv1ym8WE=; b=sUXyXsdJJ0/HTn5Pxs1/M/48xImsTJpz1nzW+JjcyF8XwC9IDzRqWdw5nFPr7l6Ze5UiLA mp33zkel2YbW0S2ZxxdIlrodn+fdeQ03HjNmEOnRdy7jcS+fcZH39pPtqtUbXKKyw7ehPq u6f6tqPyBYD3ivYtOt6p0d2Bqz2FuTu2q4acXCHQheCOEHG0kAOcX6HL4Ef8wjJxV669xo kNOFIjaC+YLmmTQNxE4cNd8ON3dT6xRBvSjQP3MW6EGTuO/Kqq7jd7vx+upi0E9cUgicKT hoYtN7Wc7/WP8Mv4/wzz+FUAD7QTVM3RMFhLflSkzINk67QMBsjHX5nZ6LdNAw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1739616958; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=62eE9xHp8rG2e/+PSOw3vDtld8Mviy7aPJkKv1ym8WE=; b=vq2qdn/QzIMCDoIR4W7ehCdY/J3mqLoDecoLjLUQNGjOp1Y6lGLBtDyux86HxH7mFtEJRF JU8OZ2vGwnPodlBw== From: "tip-bot2 for Yafang Shao" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched: Don't define sched_clock_irqtime as static key Cc: Dan Carpenter , Yafang Shao , "Peter Zijlstra (Intel)" , Vincent Guittot , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20250205032438.14668-1-laoar.shao@gmail.com> References: <20250205032438.14668-1-laoar.shao@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <173961695743.10177.17683780278419896262.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the sched/core branch of tip: Commit-ID: b9f2b29b94943b08157e3dfc970baabc7944dbc3 Gitweb: https://git.kernel.org/tip/b9f2b29b94943b08157e3dfc970baabc7= 944dbc3 Author: Yafang Shao AuthorDate: Wed, 05 Feb 2025 11:24:38 +08:00 Committer: Peter Zijlstra CommitterDate: Fri, 14 Feb 2025 10:32:00 +01:00 sched: Don't define sched_clock_irqtime as static key The sched_clock_irqtime was defined as a static key in commit 8722903cbb8f ('sched: Define sched_clock_irqtime as static key'). However, this change introduces a 'sleeping in atomic context' warning, as shown below: arch/x86/kernel/tsc.c:1214 mark_tsc_unstable() warn: sleeping in atomic context As analyzed by Dan, the affected code path is as follows: vcpu_load() <- disables preempt -> kvm_arch_vcpu_load() -> mark_tsc_unstable() <- sleeps virt/kvm/kvm_main.c 166 void vcpu_load(struct kvm_vcpu *vcpu) 167 { 168 int cpu =3D get_cpu(); ^^^^^^^^^^ This get_cpu() disables preemption. 169 170 __this_cpu_write(kvm_running_vcpu, vcpu); 171 preempt_notifier_register(&vcpu->preempt_notifier); 172 kvm_arch_vcpu_load(vcpu, cpu); 173 put_cpu(); 174 } arch/x86/kvm/x86.c 4979 if (unlikely(vcpu->cpu !=3D cpu) || kvm_check_tsc_unstable(= )) { 4980 s64 tsc_delta =3D !vcpu->arch.last_host_tsc ? 0 : 4981 rdtsc() - vcpu->arch.last_host_tsc; 4982 if (tsc_delta < 0) 4983 mark_tsc_unstable("KVM discovered backwards= TSC"); arch/x86/kernel/tsc.c 1206 void mark_tsc_unstable(char *reason) 1207 { 1208 if (tsc_unstable) 1209 return; 1210 1211 tsc_unstable =3D 1; 1212 if (using_native_sched_clock()) 1213 clear_sched_clock_stable(); --> 1214 disable_sched_clock_irqtime(); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ kernel/jump_label.c 245 void static_key_disable(struct static_key *key) 246 { 247 cpus_read_lock(); ^^^^^^^^^^^^^^^^ This lock has a might_sleep() in it which triggers the static checker warning. 248 static_key_disable_cpuslocked(key); 249 cpus_read_unlock(); 250 } Let revert this change for now as {disable,enable}_sched_clock_irqtime are used in many places, as pointed out by Sean, including the following: The code path in clocksource_watchdog(): clocksource_watchdog() | -> spin_lock(&watchdog_lock); | -> __clocksource_unstable() | -> clocksource.mark_unstable() =3D=3D tsc_cs_mark_unstable() | -> disable_sched_clock_irqtime() And the code path in sched_clock_register(): /* Cannot register a sched_clock with interrupts on */ local_irq_save(flags); ... /* Enable IRQ time accounting if we have a fast enough sched_clock() */ if (irqtime > 0 || (irqtime =3D=3D -1 && rate >=3D 1000000)) enable_sched_clock_irqtime(); local_irq_restore(flags); [lkp@intel.com: reported a build error in the prev version] Closes: https://lore.kernel.org/kvm/37a79ba3-9ce0-479c-a5b0-2bd75d573ed3@st= anley.mountain/ Fixes: 8722903cbb8f ("sched: Define sched_clock_irqtime as static key") Reported-by: Dan Carpenter Debugged-by: Dan Carpenter Debugged-by: Sean Christopherson Debugged-by: Michal Koutn=C3=BD Signed-off-by: Yafang Shao Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Vincent Guittot Link: https://lkml.kernel.org/r/20250205032438.14668-1-laoar.shao@gmail.com --- kernel/sched/cputime.c | 8 ++++---- kernel/sched/sched.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index 5d9143d..6dab485 100644 --- a/kernel/sched/cputime.c +++ b/kernel/sched/cputime.c @@ -9,8 +9,6 @@ =20 #ifdef CONFIG_IRQ_TIME_ACCOUNTING =20 -DEFINE_STATIC_KEY_FALSE(sched_clock_irqtime); - /* * There are no locks covering percpu hardirq/softirq time. * They are only modified in vtime_account, on corresponding CPU @@ -24,14 +22,16 @@ DEFINE_STATIC_KEY_FALSE(sched_clock_irqtime); */ DEFINE_PER_CPU(struct irqtime, cpu_irqtime); =20 +int sched_clock_irqtime; + void enable_sched_clock_irqtime(void) { - static_branch_enable(&sched_clock_irqtime); + sched_clock_irqtime =3D 1; } =20 void disable_sched_clock_irqtime(void) { - static_branch_disable(&sched_clock_irqtime); + sched_clock_irqtime =3D 0; } =20 static void irqtime_account_delta(struct irqtime *irqtime, u64 delta, diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 38e0e32..ab16d3d 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -3259,11 +3259,11 @@ struct irqtime { }; =20 DECLARE_PER_CPU(struct irqtime, cpu_irqtime); -DECLARE_STATIC_KEY_FALSE(sched_clock_irqtime); +extern int sched_clock_irqtime; =20 static inline int irqtime_enabled(void) { - return static_branch_likely(&sched_clock_irqtime); + return sched_clock_irqtime; } =20 /*