From patchwork Fri Jan 13 12:31:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 43223 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp242649wrt; Fri, 13 Jan 2023 04:34:05 -0800 (PST) X-Google-Smtp-Source: AMrXdXtWz65l4og4wWKzuJ4c1zahJKXHPo9XGRjd9xbynaNQlXE5hstWGuYsh+ZHpWAtUNR/9zBm X-Received: by 2002:a17:906:b00d:b0:7c1:435c:d777 with SMTP id v13-20020a170906b00d00b007c1435cd777mr67264147ejy.9.1673613245063; Fri, 13 Jan 2023 04:34:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673613245; cv=none; d=google.com; s=arc-20160816; b=EjzJ+XE76X1iFx6vpFStB2z23uPTMlP9s8wr7XYFx1pRswP5Ti9wxu2mGPe/cKLf// yEj4U4swSBzGF+csmktWSxw6P2rzVPgcQjccLo/jHyv1i12xXeMrvK9oYIawGf5diPR6 sjhClIROEPKpKIXzmmHSGNa0Zj0Z0UcoU+u5E0u/pq+mJbqld3F0l62dM+3F5SI3NmuF jx0CD16xAZwjCsLsJllC8pL5ZUUQ9gnXPla/mjvQU/BS1c/LnAhajOP/wJn4jKQVbvOk 2S42ftN7KPldwjktQ8BxQSko3K1+YgdgE730TIlNzF2nLMSQ5R+wpEhwEahqHc+ZaylR DTxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=XIsWwDqWfy/ICsC/hB7LDFqPaGuaV3/AWDHrZFnwnws=; b=q7OIRebjN1lTIGqWt3KDArazLMePx5dEZNYbb9xShwQtuOSurvIZgGofoEQnC+DM4k vzF1vfrowaRl4qbVef1LL4r1hnRtPElwLSMOjVRaCfWCQeiKHtianiDVlTmC3OZozJvA 27knWg/mIDcfkpagJz7lUwp6tOzpdO5mBoP5F+79h5rOpbYMgdK5um6VxLkeio6hc7R2 cDrEuKdrLn5Wyd8rzFUN76JKzzkuf4DQmRUgb7W4lu0vMlhlGUszvaxAI4xfVvod1RZf pRsiXYnrRh3F4++hq/Qu7gHxHA9BJNdG6vZnF6GlVP7b8mUGKZAJC/7LIUqBIwkOti7r 8bNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=x9s7gNo5; dkim=neutral (no key) header.i=@linutronix.de header.b=necIWaIj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f15-20020a50d54f000000b0048fd69cf2absi20435898edj.63.2023.01.13.04.33.40; Fri, 13 Jan 2023 04:34:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=x9s7gNo5; dkim=neutral (no key) header.i=@linutronix.de header.b=necIWaIj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240882AbjAMMc4 (ORCPT + 99 others); Fri, 13 Jan 2023 07:32:56 -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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754848333814146868?= X-GMAIL-MSGID: =?utf-8?q?1754910682244462185?= The following commit has been merged into the sched/core branch of tip: Commit-ID: 17cc2b5525856d7374f09b28ba1faf1fa61b2352 Gitweb: https://git.kernel.org/tip/17cc2b5525856d7374f09b28ba1faf1fa61b2352 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, } #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 = &drv->states[index]; + ktime_t time_start, time_end; + + instrumentation_begin(); time_start = ns_to_ktime(local_clock()); @@ -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(); @@ -166,6 +173,7 @@ static void enter_s2idle_proper(struct cpuidle_driver *drv, dev->states_usage[index].s2idle_time += ktime_us_delta(time_end, time_start); dev->states_usage[index].s2idle_usage++; + instrumentation_end(); } /** @@ -200,8 +208,9 @@ int cpuidle_enter_s2idle(struct cpuidle_driver *drv, struct 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; @@ -209,6 +218,8 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, bool broadcast = !!(target_state->flags & CPUIDLE_FLAG_TIMER_STOP); ktime_t time_start, time_end; + 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, struct cpuidle_driver *drv, time_start = ns_to_ktime(local_clock()); 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(); + } entered_state = target_state->enter(dev, drv, index); + if (WARN_ONCE(!irqs_disabled(), "%ps leaked IRQ state", target_state->enter)) 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(); + } start_critical_timings(); sched_clock_idle_wakeup_event(); @@ -306,6 +323,8 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, dev->states_usage[index].rejected++; } + instrumentation_end(); + return entered_state; }