From patchwork Wed Apr 15 18:19:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 227953 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAAF9C2BA19 for ; Wed, 15 Apr 2020 18:20:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A0B2021D94 for ; Wed, 15 Apr 2020 18:20:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586974807; bh=agncuew4ZdoCbDCq4QOkdrOq37rTMuNaw6J1yUgTE+k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Qav/FbINdk36V2+k+eXs6Hhp6RR+qf5Jle0LpHYwyMG7UGIFVVxKFY8pEIoGouY6v gLmF9w7ZBFWx/w5QhSYZN2qQ26hV45vOrWWaaHXkn5tWGti1tDWJw+TWL2mv+QyTmw O84jpr91QOKJ8d/nLoaYFnAm0Hoq7V/JqW+wgMNc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2441415AbgDOSUF (ORCPT ); Wed, 15 Apr 2020 14:20:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:38052 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2441402AbgDOST5 (ORCPT ); Wed, 15 Apr 2020 14:19:57 -0400 Received: from paulmck-ThinkPad-P72.home (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B4F55221E9; Wed, 15 Apr 2020 18:19:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586974797; bh=agncuew4ZdoCbDCq4QOkdrOq37rTMuNaw6J1yUgTE+k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WTzX5ijiwbfh1nOuzQxy+vNeNB92m0yBeEisPdDcNb1GimTKB14BiJVmN5AMW89ZW /EUX4GuRqZFPkei2R6qK75SWTfCR7IaSt+BjnmVpaSoez9GV95aRUQiCz6wDQNEEam Y8Pep60Q+0qRU5q9q6yHVomZqTMMR8GlxyrpGzSI= From: paulmck@kernel.org To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com, mingo@kernel.org, jiangshanlai@gmail.com, dipankar@in.ibm.com, akpm@linux-foundation.org, mathieu.desnoyers@efficios.com, josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org, rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com, fweisbec@gmail.com, oleg@redhat.com, joel@joelfernandes.org, "Paul E. McKenney" , "# 5 . 5 . x" Subject: [PATCH v4 tip/core/rcu 38/38] rcu: Don't acquire lock in NMI handler in rcu_nmi_enter_common() Date: Wed, 15 Apr 2020 11:19:41 -0700 Message-Id: <20200415181941.11653-38-paulmck@kernel.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20200415181856.GA11037@paulmck-ThinkPad-P72> References: <20200415181856.GA11037@paulmck-ThinkPad-P72> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: "Paul E. McKenney" The rcu_nmi_enter_common() function can be invoked both in interrupt and NMI handlers. If it is invoked from process context (as opposed to userspace or idle context) on a nohz_full CPU, it might acquire the CPU's leaf rcu_node structure's ->lock. Because this lock is held only with interrupts disabled, this is safe from an interrupt handler, but doing so from an NMI handler can result in self-deadlock. This commit therefore adds "irq" to the "if" condition so as to only acquire the ->lock from irq handlers or process context, never from an NMI handler. Fixes: 5b14557b073c ("rcu: Avoid tick_dep_set_cpu() misordering") Reported-by: Thomas Gleixner Signed-off-by: Paul E. McKenney Reviewed-by: Joel Fernandes (Google) Cc: # 5.5.x --- kernel/rcu/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 7dd7a17..573fd78 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -876,7 +876,7 @@ static __always_inline void rcu_nmi_enter_common(bool irq) rcu_cleanup_after_idle(); incby = 1; - } else if (tick_nohz_full_cpu(rdp->cpu) && + } else if (irq && tick_nohz_full_cpu(rdp->cpu) && rdp->dynticks_nmi_nesting == DYNTICK_IRQ_NONIDLE && READ_ONCE(rdp->rcu_urgent_qs) && !READ_ONCE(rdp->rcu_forced_tick)) {