Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp629327img; Fri, 22 Mar 2019 05:29:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqw9VG3BMEwTjb58cgowJeKM/50L+9v4yjn+BMuPCrkfgQ82R1K9KuAm6Guu20UXv8fyWzje X-Received: by 2002:a17:902:765:: with SMTP id 92mr8979966pli.95.1553257791326; Fri, 22 Mar 2019 05:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553257791; cv=none; d=google.com; s=arc-20160816; b=mgzH5mHW26YJ1Zkl75dIae67bVRvLeH8MMQgjkVGupR1XRCY+B/pAh2qrks8ZcDyac qgcyNK8GorJ/yL9/QYNpisNUqdglKlSGwLg8ZCZvyKTfao3HoKrxu03DCLndABEbH9i1 qMNuhaheEEoDJa+kvE3h9vL0g72hXPwdJ0DddGQmigt6s379NOTrWfzTL9/4oaGRCCLh LwGlcZ2k+46w0jOkf75PXgeHgnauuiSwBgWIaUpqfcAWHB3C6nWDUd7J8k7T3MJh8h5T 1oR+KvKTTSVJWgxaiK13n3KHI4CPRwToF8SAaMwGmocC61Rk4CU4UYSwkwKdOlfB95J1 cnaA== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+GxH+h35uZvg0m9FoRDQp0K/XpdpHv25cXe+A9tI420=; b=qeQVUZxvI+DgOKGPwXwPWlP7em4lBnIE+DSYCqp/L94ggMgMw7ax3WhWMLgC81irj5 mtQouwppm8A8FQGRmqeftJzHrsljAm/2vW9NVgcBtpwRThg9LcM/Y3SNtXDWMklxFUoF x7dg/KvwyLirlKrHRPd28CpcOr8MCn8bwI/rkYs0KhjaeGiguiL/GEFrwhRgId+uDnoi WPXSqZGIsrFbM6lpKbAwRStJ9roE4Mc8fIEAByLpkk1Qh+/NwPVvvUUbssI9cao3asSB SRb7hTEYD5TQ16uX87ldzvud0Y5tlajJk4nCKW5dE/vjrXkys56jyAfp8J2ILb28pCuS cODA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JJc87Kk9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r201si6125533pgr.445.2019.03.22.05.29.33; Fri, 22 Mar 2019 05:29:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JJc87Kk9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390965AbfCVM1c (ORCPT + 99 others); Fri, 22 Mar 2019 08:27:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:39008 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391008AbfCVM13 (ORCPT ); Fri, 22 Mar 2019 08:27:29 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 89C47218B0; Fri, 22 Mar 2019 12:27:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553257649; bh=A0KFbWB3KBrSd1f+WHHL+5tJjA4WCLsnWkbrrWTBBrg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JJc87Kk9BZ9SCvWeLbHr2vLPe1/c5gVPIkV02F7J41/i9pvdOvaFH/6EKaPmTeMbM gXCzP/NnYJlLSn1WerzaGn+V35IFvK8/BuMVn0TQsuxEDQJ+8Ex39yJ/9NRM4fZfdX ebN48OnTxhHVvXf7h8U2r0u2aiKhmE8DHOZ1/Cfk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "He, Bo" , "Zhang, Jun" , "Paul E. McKenney" , "xiao, jin" , Jie A Subject: [PATCH 4.19 262/280] rcu: Do RCU GP kthread self-wakeup from softirq and interrupt Date: Fri, 22 Mar 2019 12:16:55 +0100 Message-Id: <20190322111344.165568516@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111306.356185024@linuxfoundation.org> References: <20190322111306.356185024@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhang, Jun commit 1d1f898df6586c5ea9aeaf349f13089c6fa37903 upstream. The rcu_gp_kthread_wake() function is invoked when it might be necessary to wake the RCU grace-period kthread. Because self-wakeups are normally a useless waste of CPU cycles, if rcu_gp_kthread_wake() is invoked from this kthread, it naturally refuses to do the wakeup. Unfortunately, natural though it might be, this heuristic fails when rcu_gp_kthread_wake() is invoked from an interrupt or softirq handler that interrupted the grace-period kthread just after the final check of the wait-event condition but just before the schedule() call. In this case, a wakeup is required, even though the call to rcu_gp_kthread_wake() is within the RCU grace-period kthread's context. Failing to provide this wakeup can result in grace periods failing to start, which in turn results in out-of-memory conditions. This race window is quite narrow, but it actually did happen during real testing. It would of course need to be fixed even if it was strictly theoretical in nature. This patch does not Cc stable because it does not apply cleanly to earlier kernel versions. Fixes: 48a7639ce80c ("rcu: Make callers awaken grace-period kthread") Reported-by: "He, Bo" Co-developed-by: "Zhang, Jun" Co-developed-by: "He, Bo" Co-developed-by: "xiao, jin" Co-developed-by: Bai, Jie A Signed-off: "Zhang, Jun" Signed-off: "He, Bo" Signed-off: "xiao, jin" Signed-off: Bai, Jie A Signed-off-by: "Zhang, Jun" [ paulmck: Switch from !in_softirq() to "!in_interrupt() && !in_serving_softirq() to avoid redundant wakeups and to also handle the interrupt-handler scenario as well as the softirq-handler scenario that actually occurred in testing. ] Signed-off-by: Paul E. McKenney Link: https://lkml.kernel.org/r/CD6925E8781EFD4D8E11882D20FC406D52A11F61@SHSMSX104.ccr.corp.intel.com Signed-off-by: Greg Kroah-Hartman --- kernel/rcu/tree.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -1689,15 +1689,23 @@ static bool rcu_future_gp_cleanup(struct } /* - * Awaken the grace-period kthread for the specified flavor of RCU. - * Don't do a self-awaken, and don't bother awakening when there is - * nothing for the grace-period kthread to do (as in several CPUs - * raced to awaken, and we lost), and finally don't try to awaken - * a kthread that has not yet been created. + * Awaken the grace-period kthread. Don't do a self-awaken (unless in + * an interrupt or softirq handler), and don't bother awakening when there + * is nothing for the grace-period kthread to do (as in several CPUs raced + * to awaken, and we lost), and finally don't try to awaken a kthread that + * has not yet been created. If all those checks are passed, track some + * debug information and awaken. + * + * So why do the self-wakeup when in an interrupt or softirq handler + * in the grace-period kthread's context? Because the kthread might have + * been interrupted just as it was going to sleep, and just after the final + * pre-sleep check of the awaken condition. In this case, a wakeup really + * is required, and is therefore supplied. */ static void rcu_gp_kthread_wake(struct rcu_state *rsp) { - if (current == rsp->gp_kthread || + if ((current == rsp->gp_kthread && + !in_interrupt() && !in_serving_softirq()) || !READ_ONCE(rsp->gp_flags) || !rsp->gp_kthread) return;