From nobody Mon Sep 15 07:33:21 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 275B6C54EBD for ; Fri, 13 Jan 2023 12:33:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241492AbjAMMc6 (ORCPT ); Fri, 13 Jan 2023 07:32:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232924AbjAMMcH (ORCPT ); Fri, 13 Jan 2023 07:32:07 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78664482B2; Fri, 13 Jan 2023 04:31:07 -0800 (PST) Date: Fri, 13 Jan 2023 12:31:05 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1673613066; 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=XIsWwDqWfy/ICsC/hB7LDFqPaGuaV3/AWDHrZFnwnws=; b=x9s7gNo5TOrek9xM+HIMmgpqTdD4vvL5G5Eh0P22O9GaHyLi3BrMq5lDpf6KaE+IfoulkS f5xOVSgG/WZvNfg0Kl0oFQvLo8gn+/N12W/0QmCWZ9/tWWCBni7LbKW8W7nOemxdsDQutT 8+DqBxxvmXRGiuNyOMXEWXZWg7AqwRfJkbD2Ohek7ig8lfT+a6hPFd0XncR5TCYgCVXknA 2XED6IwAi7Q5MaXJseCmb4cH9xibb6kWuRbzsHJZvAavgwQBAmXuEjmD+j327kCKO+hV25 NrdLFmVUn6u3tWKKh0y0XQLNKzxDmBxYEfGgJmL2OH89K8AP8NSQ91bSdQTEYg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1673613066; 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=XIsWwDqWfy/ICsC/hB7LDFqPaGuaV3/AWDHrZFnwnws=; b=necIWaIjSh+UV6sg2sLmawxjQxwREVNANZbaYtrXvQaXmJseZ056U4XcPGGP6P9RrTN+e1 EFto7Wvc0+taBtDQ== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] cpuidle: Ensure ct_cpuidle_enter() is always called from noinstr/__cpuidle Cc: "Peter Zijlstra (Intel)" , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230112195542.212914195@infradead.org> References: <20230112195542.212914195@infradead.org> MIME-Version: 1.0 Message-ID: <167361306572.4906.1431899164056778685.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/core branch of tip: Commit-ID: 17cc2b5525856d7374f09b28ba1faf1fa61b2352 Gitweb: https://git.kernel.org/tip/17cc2b5525856d7374f09b28ba1faf1fa= 61b2352 Author: Peter Zijlstra AuthorDate: Thu, 12 Jan 2023 20:44:01 +01:00 Committer: Ingo Molnar CommitterDate: Fri, 13 Jan 2023 11:48:17 +01:00 cpuidle: Ensure ct_cpuidle_enter() is always called from noinstr/__cpuidle Tracing (kprobes included) and other compiler instrumentation relies on a normal kernel runtime. Therefore all functions that disable RCU should be noinstr, as should all functions that are called while RCU is disabled. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20230112195542.212914195@infradead.org --- drivers/cpuidle/cpuidle.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 08374c7..73f7d8b 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -137,11 +137,13 @@ int cpuidle_find_deepest_state(struct cpuidle_driver = *drv, } =20 #ifdef CONFIG_SUSPEND -static void enter_s2idle_proper(struct cpuidle_driver *drv, - struct cpuidle_device *dev, int index) +static noinstr void enter_s2idle_proper(struct cpuidle_driver *drv, + struct cpuidle_device *dev, int index) { - ktime_t time_start, time_end; struct cpuidle_state *target_state =3D &drv->states[index]; + ktime_t time_start, time_end; + + instrumentation_begin(); =20 time_start =3D ns_to_ktime(local_clock()); =20 @@ -152,13 +154,18 @@ static void enter_s2idle_proper(struct cpuidle_driver= *drv, * suspended is generally unsafe. */ stop_critical_timings(); - if (!(target_state->flags & CPUIDLE_FLAG_RCU_IDLE)) + if (!(target_state->flags & CPUIDLE_FLAG_RCU_IDLE)) { ct_cpuidle_enter(); + /* Annotate away the indirect call */ + instrumentation_begin(); + } target_state->enter_s2idle(dev, drv, index); if (WARN_ON_ONCE(!irqs_disabled())) raw_local_irq_disable(); - if (!(target_state->flags & CPUIDLE_FLAG_RCU_IDLE)) + if (!(target_state->flags & CPUIDLE_FLAG_RCU_IDLE)) { + instrumentation_end(); ct_cpuidle_exit(); + } tick_unfreeze(); start_critical_timings(); =20 @@ -166,6 +173,7 @@ static void enter_s2idle_proper(struct cpuidle_driver *= drv, =20 dev->states_usage[index].s2idle_time +=3D ktime_us_delta(time_end, time_s= tart); dev->states_usage[index].s2idle_usage++; + instrumentation_end(); } =20 /** @@ -200,8 +208,9 @@ int cpuidle_enter_s2idle(struct cpuidle_driver *drv, st= ruct cpuidle_device *dev) * @drv: cpuidle driver for this cpu * @index: index into the states table in @drv of the state to enter */ -int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver = *drv, - int index) +noinstr int cpuidle_enter_state(struct cpuidle_device *dev, + struct cpuidle_driver *drv, + int index) { int entered_state; =20 @@ -209,6 +218,8 @@ int cpuidle_enter_state(struct cpuidle_device *dev, str= uct cpuidle_driver *drv, bool broadcast =3D !!(target_state->flags & CPUIDLE_FLAG_TIMER_STOP); ktime_t time_start, time_end; =20 + instrumentation_begin(); + /* * Tell the time framework to switch to a broadcast timer because our * local timer will be shut down. If a local timer is used from another @@ -235,15 +246,21 @@ int cpuidle_enter_state(struct cpuidle_device *dev, s= truct cpuidle_driver *drv, time_start =3D ns_to_ktime(local_clock()); =20 stop_critical_timings(); - if (!(target_state->flags & CPUIDLE_FLAG_RCU_IDLE)) + if (!(target_state->flags & CPUIDLE_FLAG_RCU_IDLE)) { ct_cpuidle_enter(); + /* Annotate away the indirect call */ + instrumentation_begin(); + } =20 entered_state =3D target_state->enter(dev, drv, index); + if (WARN_ONCE(!irqs_disabled(), "%ps leaked IRQ state", target_state->ent= er)) raw_local_irq_disable(); =20 - if (!(target_state->flags & CPUIDLE_FLAG_RCU_IDLE)) + if (!(target_state->flags & CPUIDLE_FLAG_RCU_IDLE)) { + instrumentation_end(); ct_cpuidle_exit(); + } start_critical_timings(); =20 sched_clock_idle_wakeup_event(); @@ -306,6 +323,8 @@ int cpuidle_enter_state(struct cpuidle_device *dev, str= uct cpuidle_driver *drv, dev->states_usage[index].rejected++; } =20 + instrumentation_end(); + return entered_state; }