Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3786297ybk; Tue, 19 May 2020 12:56:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpgTm6nKpcf+k2a8P1MY7tmzN7rPqUSyCQCVa5xB71q3jcFSDXlwOReB2DuXaVBpV4lpJD X-Received: by 2002:a17:906:f112:: with SMTP id gv18mr829093ejb.142.1589918196345; Tue, 19 May 2020 12:56:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589918196; cv=none; d=google.com; s=arc-20160816; b=V4bMrcG6B28WEQcEJYM6Z7Jpr/mnWcfVnMRRauZlNIVVIiju7PcdFJaSxX0OZnt+oX zcFS3Dksh2LSJirRhCr8tyuQTElc7AeKj2mq0KW6w7HomzfpjAJoDjVt6mhVINQ3p8fi xxalh/HPfAkb3J1AebN2GE9ZxyYKDgTdhm/ovddnBcmrbkpbhLotaVCNCrkw4KyMuyoh wrw29KaWEiyELWVz7g81Eo565phjdFk7h+5CkZMEiOpr4hqNAnoP7beg1v4CfKxKLOb+ PLhP+cQCgJgBWDS/EoLy1LWz+1wysWt7xUneRvVZZ39mV1f4x09Sa0N9TyjBNqjSefyH nykw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=37/Ie0CqVwdH3hKZGZrb9k90CGl/guS24GJYnCJE2FY=; b=ayZU7yFf1cH80CqCBNUbsIzDjFiezrnHrZTccfOjuXRnOb8Y5+51xqgPpsT6XKTTov AyHIVunOf0m8xgkQKooXqbsK7YVY4i7JDtnhUVyR6PGjOxYWLlzJG+WvsaXLasm9lsCV 4VhHFXt1QMB/jAQ7tFprf/ykVyjjRAeFuJcn2xshVyS/DQq5pZ9BKBq8G+ubBGMbz4h9 wIQmmvac+MR0r9TLjAiUHP7UGcJubP81wApKgrkE5Vxj9ZcAp7JmDTNNMNsMrRIVaWMf pQVBLmkQiwlwryn35K2fWopv5CQhidysyiy9M7ACC7ATnaWwfvzixbBKLdN8kwGJG9JB fBAA== ARC-Authentication-Results: i=1; mx.google.com; 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 g20si252282edh.441.2020.05.19.12.56.12; Tue, 19 May 2020 12:56:36 -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; 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 S1726747AbgESTxh (ORCPT + 99 others); Tue, 19 May 2020 15:53:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726944AbgESTwk (ORCPT ); Tue, 19 May 2020 15:52:40 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 745A3C08C5C0; Tue, 19 May 2020 12:52:40 -0700 (PDT) Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jb8Hw-0007p8-ML; Tue, 19 May 2020 21:52:32 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 373FD1C047E; Tue, 19 May 2020 21:52:32 +0200 (CEST) Date: Tue, 19 May 2020 19:52:32 -0000 From: "tip-bot2 for Thomas Gleixner" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: core/rcu] rcu: Provide rcu_irq_exit_preempt() Cc: Thomas Gleixner , "Paul E. McKenney" , Alexandre Chartre , Peter Zijlstra , x86 , LKML In-Reply-To: <20200505134904.364456424@linutronix.de> References: <20200505134904.364456424@linutronix.de> MIME-Version: 1.0 Message-ID: <158991795212.17951.14774229487753958998.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the core/rcu branch of tip: Commit-ID: 8ae0ae6737ad449c8ae21e2bb01d9736f360a933 Gitweb: https://git.kernel.org/tip/8ae0ae6737ad449c8ae21e2bb01d9736f360a933 Author: Thomas Gleixner AuthorDate: Sun, 03 May 2020 15:08:52 +02:00 Committer: Thomas Gleixner CommitterDate: Tue, 19 May 2020 15:51:21 +02:00 rcu: Provide rcu_irq_exit_preempt() Interrupts and exceptions invoke rcu_irq_enter() on entry and need to invoke rcu_irq_exit() before they either return to the interrupted code or invoke the scheduler due to preemption. The general assumption is that RCU idle code has to have preemption disabled so that a return from interrupt cannot schedule. So the return from interrupt code invokes rcu_irq_exit() and preempt_schedule_irq(). If there is any imbalance in the rcu_irq/nmi* invocations or RCU idle code had preemption enabled then this goes unnoticed until the CPU goes idle or some other RCU check is executed. Provide rcu_irq_exit_preempt() which can be invoked from the interrupt/exception return code in case that preemption is enabled. It invokes rcu_irq_exit() and contains a few sanity checks in case that CONFIG_PROVE_RCU is enabled to catch such issues directly. Signed-off-by: Thomas Gleixner Reviewed-by: Paul E. McKenney Reviewed-by: Alexandre Chartre Acked-by: Peter Zijlstra Link: https://lkml.kernel.org/r/20200505134904.364456424@linutronix.de --- include/linux/rcutiny.h | 1 + include/linux/rcutree.h | 1 + kernel/rcu/tree.c | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/include/linux/rcutiny.h b/include/linux/rcutiny.h index 3465ba7..980eb78 100644 --- a/include/linux/rcutiny.h +++ b/include/linux/rcutiny.h @@ -71,6 +71,7 @@ static inline void rcu_irq_enter(void) { } static inline void rcu_irq_exit_irqson(void) { } static inline void rcu_irq_enter_irqson(void) { } static inline void rcu_irq_exit(void) { } +static inline void rcu_irq_exit_preempt(void) { } static inline void exit_rcu(void) { } static inline bool rcu_preempt_need_deferred_qs(struct task_struct *t) { diff --git a/include/linux/rcutree.h b/include/linux/rcutree.h index fbc2627..02016e0 100644 --- a/include/linux/rcutree.h +++ b/include/linux/rcutree.h @@ -47,6 +47,7 @@ void rcu_idle_enter(void); void rcu_idle_exit(void); void rcu_irq_enter(void); void rcu_irq_exit(void); +void rcu_irq_exit_preempt(void); void rcu_irq_enter_irqson(void); void rcu_irq_exit_irqson(void); diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 9454016..62ee012 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -743,6 +743,28 @@ void noinstr rcu_irq_exit(void) rcu_nmi_exit(); } +/** + * rcu_irq_exit_preempt - Inform RCU that current CPU is exiting irq + * towards in kernel preemption + * + * Same as rcu_irq_exit() but has a sanity check that scheduling is safe + * from RCU point of view. Invoked from return from interrupt before kernel + * preemption. + */ +void rcu_irq_exit_preempt(void) +{ + lockdep_assert_irqs_disabled(); + rcu_nmi_exit(); + + RCU_LOCKDEP_WARN(__this_cpu_read(rcu_data.dynticks_nesting) <= 0, + "RCU dynticks_nesting counter underflow/zero!"); + RCU_LOCKDEP_WARN(__this_cpu_read(rcu_data.dynticks_nmi_nesting) != + DYNTICK_IRQ_NONIDLE, + "Bad RCU dynticks_nmi_nesting counter\n"); + RCU_LOCKDEP_WARN(rcu_dynticks_curr_cpu_in_eqs(), + "RCU in extended quiescent state!"); +} + /* * Wrapper for rcu_irq_exit() where interrupts are enabled. *