Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4237230pxb; Tue, 17 Nov 2020 15:25:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkMbAGZ1ECxO3M+HO9MB1bas5OijjkLQVXjjrN0+bjN7IzuoIYT6nmjY6vkwDCC/r6yZoY X-Received: by 2002:a17:906:9445:: with SMTP id z5mr12834592ejx.165.1605655513371; Tue, 17 Nov 2020 15:25:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605655513; cv=none; d=google.com; s=arc-20160816; b=C8lvKLu/PYNSfvVX2J5gcdsf83WEWOQJ/ETHPvdcNAZx+ISd8OD8MaFjVZA6UXBx+F NujMezO14DnYVDEJlpC2qTRc6d54oqnEA4fEOnaLFLO9ZQVR9283O5NMp6/1A0AYPtND Gmj6E33QwPgVYs3jvrhra5kTRk/dnKscVCWbSD39vb9SPXhyLA0K4ju9M+70xN0LRZax 8ga703GhYLROVKmzjNkmRiDuinLzRw4hXDMOoMCeDlYw12ewCiICinFPAJuW8atzTHFi 68E50zF7scPV7PGCM8h//rX3YmWXIgiJqZ9XrMWhJjug8I/rfHnfxJmnwF/0PvuDm/gg F9mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PqTucxK+Xw24pDxWNrMrQc6dBy5DDtbN0w21uUUW7+k=; b=QQBXIYXxxx8r+6SGJzbSfYbMiXebUTpIN3fgKYXdPvdHTq5lppk524JxTDheIrk91b jtspkcpPvx4r6wEUfQ4JdXzDUoe0GUgkwIx7OAR7GgMS1hj9rIAKn27FERkDsWZ5aqPy uRWGqclY0/TDrfDX8jTSbSKOJ19tDook4v3D1kfVYMwW+ruZwGvC4zzaU0tVDOEBg4cq xb8aul/E1sDAA0VVEVX4vGDh44lYT2h5hqauADhFWC6+0btbAFj2V+8RutE2mNq8D6K1 bpeimunKlwmUuUrtGxSjFXs8SIHGS2PY4117pIIhdGR5rp2U8/BsTcUCoAEnnZ9vDmNq krGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=DMrT2Jbf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h14si1831859ejc.179.2020.11.17.15.24.50; Tue, 17 Nov 2020 15:25:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=DMrT2Jbf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729764AbgKQXVo (ORCPT + 99 others); Tue, 17 Nov 2020 18:21:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729172AbgKQXUu (ORCPT ); Tue, 17 Nov 2020 18:20:50 -0500 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE44BC0613CF for ; Tue, 17 Nov 2020 15:20:50 -0800 (PST) Received: by mail-qv1-xf2c.google.com with SMTP id z17so87634qvy.11 for ; Tue, 17 Nov 2020 15:20:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PqTucxK+Xw24pDxWNrMrQc6dBy5DDtbN0w21uUUW7+k=; b=DMrT2JbfIok6BMejkHIlxakaldKvrVqvafoZS8YbTx9hoSCl6sB93/HCTahVB7j7F0 o75VFTcLuGmhHbEX9wQgELOYjf1l4GpeIuY0wdIGreYP40cixCuAjy5pO2mRcIO5wmRu 1thTNbzjFwAYo86wd84sqgvYCMS0ACATqxjPA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PqTucxK+Xw24pDxWNrMrQc6dBy5DDtbN0w21uUUW7+k=; b=tJEBju2dLmIbMbQSxiNW/7gPgQusxDFPiEIW2mDvnrmuFYKqMnwrAaswfatRZcRmEz GC9GBxnyCNzi2icKefO5Yef2DH2zovpC2F3Px1+dTSWDLLtZaY8t7oqRXZ77Or9hs0sF y9G1vD8lRuE03e4pK0HshfzF3Bj6lZd7BzkFSt2WK2rbu3qrtn6C/AHjktq/NezEhMg7 mM9kVN8OPhySChnsKJph4WAWTxkaURsAWGHBKVnKwwVIFe0aVaU0vk+/LHNxiDpy32sX eRVFcLFc13lfbGwee9mTj6A/n/aOXnWVNX1xqX1Urt5BJkzbP3zMAXFTrzuuTkFVmF/J 2mPQ== X-Gm-Message-State: AOAM532r7Gv2See/vsqWVtMNWCKceINGdPytogeiTb3ELecfOiiYFgkK o0QgpAtpBCVhoT1xyk2GEBMU6w== X-Received: by 2002:ad4:4e13:: with SMTP id dl19mr2165035qvb.24.1605655249886; Tue, 17 Nov 2020 15:20:49 -0800 (PST) Received: from joelaf.cam.corp.google.com ([2620:15c:6:411:cad3:ffff:feb3:bd59]) by smtp.gmail.com with ESMTPSA id d12sm14555544qtp.77.2020.11.17.15.20.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 15:20:49 -0800 (PST) From: "Joel Fernandes (Google)" To: Nishanth Aravamudan , Julien Desfossez , Peter Zijlstra , Tim Chen , Vineeth Pillai , Aaron Lu , Aubrey Li , tglx@linutronix.de, linux-kernel@vger.kernel.org Cc: mingo@kernel.org, torvalds@linux-foundation.org, fweisbec@gmail.com, keescook@chromium.org, kerrnel@google.com, Phil Auld , Valentin Schneider , Mel Gorman , Pawan Gupta , Paolo Bonzini , joel@joelfernandes.org, vineeth@bitbyteword.org, Chen Yu , Christian Brauner , Agata Gruza , Antonio Gomez Iglesias , graf@amazon.com, konrad.wilk@oracle.com, dfaggioli@suse.com, pjt@google.com, rostedt@goodmis.org, derkling@google.com, benbjiang@tencent.com, Alexandre Chartre , James.Bottomley@hansenpartnership.com, OWeisse@umich.edu, Dhaval Giani , Junaid Shahid , jsbarnes@google.com, chris.hyser@oracle.com, Ben Segall , Josh Don , Hao Luo , Tom Lendacky , Aubrey Li , "Paul E. McKenney" , Tim Chen Subject: [PATCH -tip 19/32] entry/idle: Enter and exit kernel protection during idle entry and exit Date: Tue, 17 Nov 2020 18:19:49 -0500 Message-Id: <20201117232003.3580179-20-joel@joelfernandes.org> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog In-Reply-To: <20201117232003.3580179-1-joel@joelfernandes.org> References: <20201117232003.3580179-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a generic_idle_{enter,exit} helper function to enter and exit kernel protection when entering and exiting idle, respectively. While at it, remove a stale RCU comment. Reviewed-by: Alexandre Chartre Tested-by: Julien Desfossez Signed-off-by: Joel Fernandes (Google) --- include/linux/entry-common.h | 18 ++++++++++++++++++ kernel/sched/idle.c | 11 ++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h index 022e1f114157..8f34ae625f83 100644 --- a/include/linux/entry-common.h +++ b/include/linux/entry-common.h @@ -454,4 +454,22 @@ static inline bool entry_kernel_protected(void) return IS_ENABLED(CONFIG_SCHED_CORE) && sched_core_kernel_protected() && _TIF_UNSAFE_RET != 0; } + +/** + * generic_idle_enter - General tasks to perform during idle entry. + */ +static inline void generic_idle_enter(void) +{ + /* Entering idle ends the protected kernel region. */ + sched_core_unsafe_exit(); +} + +/** + * generic_idle_exit - General tasks to perform during idle exit. + */ +static inline void generic_idle_exit(void) +{ + /* Exiting idle (re)starts the protected kernel region. */ + sched_core_unsafe_enter(); +} #endif diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index 8bdb214eb78f..ee4f91396c31 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -8,6 +8,7 @@ */ #include "sched.h" +#include #include /* Linker adds these: start and end of __cpuidle functions */ @@ -54,6 +55,7 @@ __setup("hlt", cpu_idle_nopoll_setup); static noinline int __cpuidle cpu_idle_poll(void) { + generic_idle_enter(); trace_cpu_idle(0, smp_processor_id()); stop_critical_timings(); rcu_idle_enter(); @@ -66,6 +68,7 @@ static noinline int __cpuidle cpu_idle_poll(void) rcu_idle_exit(); start_critical_timings(); trace_cpu_idle(PWR_EVENT_EXIT, smp_processor_id()); + generic_idle_exit(); return 1; } @@ -156,11 +159,7 @@ static void cpuidle_idle_call(void) return; } - /* - * The RCU framework needs to be told that we are entering an idle - * section, so no more rcu read side critical sections and one more - * step to the grace period - */ + generic_idle_enter(); if (cpuidle_not_available(drv, dev)) { tick_nohz_idle_stop_tick(); @@ -225,6 +224,8 @@ static void cpuidle_idle_call(void) */ if (WARN_ON_ONCE(irqs_disabled())) local_irq_enable(); + + generic_idle_exit(); } /* -- 2.29.2.299.gdc1121823c-goog