Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4185639pxu; Tue, 20 Oct 2020 10:12:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtoN1GUtIb8VUbfVgZX+zHZIhDdf8gwXoc8hT9llyXQRQRBWKouxS0pjPHvscOvaPL/WqJ X-Received: by 2002:aa7:d488:: with SMTP id b8mr3672568edr.21.1603213927589; Tue, 20 Oct 2020 10:12:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603213927; cv=none; d=google.com; s=arc-20160816; b=hVNG3K5hYoj4h9Eh8yhnXcLqimjbC/qmA/GNB41OEvbkVH0/QJT6cTzVRmDixtGGzl cKTbby+sBqctA1P5Ue74uu7fY6PMxCYur2r8HXQd9MtaDfJciFP7Uwen28u8vsBGQ6Vw UYNLS1IJUfveuP/49Y62jBE0vRhLI6YBokaFDnXEfB7RGxR/GFzmObRfTCvFEeMuQBt9 3qebE1YKhajRTNP1w/cvCcErq8qMYrTWZj3k6M6SI1upSs8m4QQdodd/9MtZZmMltAG8 VqXHpQm0MPoEjbztz+k2rGloQI1JssYyZQXaxklFVCPK7Z/ay3VL/k1MqK1KbeS0zPaH zExw== 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=XhAgMxTS7FfrTqbn56ueMD2c1ZEFO5mefcH6CTcX4Lk=; b=cmJttUVBJw9JfV3JUDzGm+y2hd2zG7puCIHZPYvN/OlEPFoX8z41OTcYVvGEmJe+jt tH6HstD5v/pu/Qg6aUPssEztVgBOj6OlAJ9hK+1gGZqiJGYYlhO4h5Uw6dPkZZFN8+mg a5DC5nYxj6DPFjvfMXGAA6dw12P7GuU2qse7Ra1ufpva4hdIv3eMhlh636KgwTzunThQ LSiLIh40P6N44Zri/j2o2UFqCgMd1KLRNp9ro8XRkVUuh+EblkoRG21JeHYPw2Aj/G7h 2jLAd2H/ucdSaN6neKRnATjr0COl/u3gokq1e0be8kDw4lg7c9LD2as3Wb62Ovwutzuf F1lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=sxmA9+Qg; 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 f10si1641413eds.576.2020.10.20.10.11.44; Tue, 20 Oct 2020 10:12:07 -0700 (PDT) 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=sxmA9+Qg; 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 S2390241AbgJTBoi (ORCPT + 99 others); Mon, 19 Oct 2020 21:44:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390215AbgJTBo2 (ORCPT ); Mon, 19 Oct 2020 21:44:28 -0400 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75DF9C0613CE for ; Mon, 19 Oct 2020 18:44:28 -0700 (PDT) Received: by mail-il1-x142.google.com with SMTP id z2so277898ilh.11 for ; Mon, 19 Oct 2020 18:44:28 -0700 (PDT) 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=XhAgMxTS7FfrTqbn56ueMD2c1ZEFO5mefcH6CTcX4Lk=; b=sxmA9+QgClJD5dFZcx9OJB/9pGKo8MtzWP09NaVve7lizrAKmJUO4PJ7Y0nxdKWjHM 5Jri84L80ilytpPSOuZs/NriReCWaYT7CE6Ms/Jal4MDhXrfYq5FZ1WJXYN4FmCvTNAE qyOtInr68ifGvHz2tMTBzDGXBcZ8tw3Byp7Ik= 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=XhAgMxTS7FfrTqbn56ueMD2c1ZEFO5mefcH6CTcX4Lk=; b=DPlWYAWy4YVnA0+bZgf5QWzy338AfNWEC5aaYth4PMOAowfiY+ncYsEK2R5s1xr27V FOmarXbBwIyZYUEdjEBv5UA8BoNhRLZdx6veZfKgdyP/OmPnuQNpIYGzw2R2nwC7EUu3 n5IEV8VXSg4qhwVV6QxAeVNlkpp/q3n2sUJ7elSTiZ2o78bORtPO+D0vgdSzdU9a5Wcf eOSZw0TVN4gtRlxZ9GGFVVF/3wu6CSJBEoRpgW8f9lZ7FJXdUEbdKnNObyBNwU0Aktmx s5dgipvHgF4U1TBZ/qFZcoyCcRvgTqFKdGyddAhC8eWfjB4++7QT0c85EUqXgGnTfStU n20Q== X-Gm-Message-State: AOAM531s7efi1CCJgBGq7FZFTVLCNIrI1khTaTdBQlriF+pWSaBjbJKE eHWiAfN2Wkw21OgRB7xgBDZqRg== X-Received: by 2002:a92:b00e:: with SMTP id x14mr275750ilh.4.1603158267791; Mon, 19 Oct 2020 18:44:27 -0700 (PDT) Received: from joelaf.cam.corp.google.com ([2620:15c:6:12:cad3:ffff:feb3:bd59]) by smtp.gmail.com with ESMTPSA id t22sm485306ili.9.2020.10.19.18.44.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Oct 2020 18:44:27 -0700 (PDT) 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, Aubrey Li , "Paul E. McKenney" , Tim Chen Subject: [PATCH v8 -tip 14/26] entry/idle: Enter and exit kernel protection during idle entry and exit Date: Mon, 19 Oct 2020 21:43:24 -0400 Message-Id: <20201020014336.2076526-15-joel@joelfernandes.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201020014336.2076526-1-joel@joelfernandes.org> References: <20201020014336.2076526-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. 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 260216de357b..879562d920f2 100644 --- a/include/linux/entry-common.h +++ b/include/linux/entry-common.h @@ -402,4 +402,22 @@ void irqentry_exit_cond_resched(void); */ void noinstr irqentry_exit(struct pt_regs *regs, irqentry_state_t state); +/** + * generic_idle_enter - Called during entry into idle for housekeeping. + */ +static inline void generic_idle_enter(void) +{ + /* Entering idle ends the protected kernel region. */ + sched_core_unsafe_exit(); +} + +/** + * generic_idle_enter - Called when exiting idle for housekeeping. + */ +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 a74926be80ac..029ba61576f2 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.0.rc1.297.gfa9743e501-goog