Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1208719pxb; Thu, 4 Mar 2021 06:12:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJzD4Q4zTmLsC0WC2MZeT5qtIYDfvwypA4bGaqiZjCCN912XkANEfkGBeIByDtcGCqZj0FbP X-Received: by 2002:a17:906:1c4f:: with SMTP id l15mr4398346ejg.148.1614867143346; Thu, 04 Mar 2021 06:12:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614867143; cv=none; d=google.com; s=arc-20160816; b=x0EGE/9SjAlzEMNmz7QhVEsItMfLDnGeu2GmNQDPOr+V6j03PjeQmK8StBUcXSMeov lVbyE20tVZgNa140wr+0toRUpGNyxMQNCbkQOsdCMJbTcuSjeUoQatMd5QAR+7bTUoHL jUY7ujql3S069ldgNpnUQ9BGkM/l64LUc8TlO13AJLCeF0uzA/cOj8Xxs88j6kojUMmi gBza3fpJQg695xYySDsrN3OmSB7FrNgBb59BlSJ2C2mPk/osDJZoCmdWkqvtUekgYV6Y xsnvhsc8I9zj1KAOHj3ZXNXvmA8pC2Dfxd4Wg11hQisi2XZD9W1wrhrmDlOA04ViVbCx 74sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=TZTDO9yX46pHJwwKD+ePso6RALucs+Ynfe7vYga5Wek=; b=1ETPcAwP0OMJlsqqJ1+p4iwv/aAO778ZV5yoEbsLlewfGgJBKo9aMDHX1CRJkP/Ysp LSePBzQUKqqerOetW2KQgpQx392ov2RfDIxNwDAhZOhTbbBjr1xyl0y4YLNj10cnWLYv ySvaT7iyrDi+8X3uOf2mROsJA1GxM0vTKckI5jV+HbqyYNtz0Aliaah9WC96bK04jUBG x/bF0MLpPTDZDnunkRZsNH7+acTHp4n9TMQxsmHpwulWi7ZAbFWgqoziPLJo+joU4gC0 K4d7QhhRXIIy72kyxQ6wRgq8EeQGdRfZLA3REBmAF7dDjIDL9JInWRO1juYXPQIeDXy7 fzQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Cr4TpiYn; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn4si18993839ejc.686.2021.03.04.06.11.59; Thu, 04 Mar 2021 06:12:23 -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=@kernel.org header.s=k20201202 header.b=Cr4TpiYn; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353174AbhCDBDG (ORCPT + 99 others); Wed, 3 Mar 2021 20:03:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:45664 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240689AbhCDAXz (ORCPT ); Wed, 3 Mar 2021 19:23:55 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 95AB764EFD; Thu, 4 Mar 2021 00:23:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614817393; bh=86HZnrwDd4o9/nc/AAg1/g535ilMOsE2DsnD8/PVHx0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cr4TpiYnhsgzk7ExsfTqp5Va0v1PSqt6qD/EYu/yzBLzGuStEUhKHkRu0QDkD7l6o 0mdokteESmQlT+qKDrUl3YtgefTneLfJQe0yQSL46oRJBekw3CTtD8IFdwFTbu9Eku IuvEcJ1JCRz11QD2XAyLr0Q1P5HUQ6afDVt9cKMTDgcAo1sgkhodT2tomUtw/lPcD2 K96IHMllmkHlZoRz1WEytVS46Z7gWd4bzjJn9fFtpqStutQ6HFCJ0mo+o/h06HMDKm Nq2uOWSevnCYlHEPmUWDkgVxVHiLaNY0IuAbdNycTSWiBlrML7OVypDOOhnq4/yPWi BpxXzW4Lz+ZGw== 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, 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, Frederic Weisbecker , Neeraj Upadhyay , Boqun Feng , "Paul E . McKenney" Subject: [PATCH tip/core/rcu 04/12] rcu/nocb: Forbid NOCB toggling on offline CPUs Date: Wed, 3 Mar 2021 16:23:03 -0800 Message-Id: <20210304002311.23655-4-paulmck@kernel.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20210304002225.GA23492@paulmck-ThinkPad-P72> References: <20210304002225.GA23492@paulmck-ThinkPad-P72> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Frederic Weisbecker It makes no sense to de-offload an offline CPU because that CPU will never invoke any remaining callbacks. It also makes little sense to offload an offline CPU because any pending RCU callbacks were migrated when that CPU went offline. Yes, it is in theory possible to use a number of tricks to permit offloading and deoffloading offline CPUs in certain cases, but in practice it is far better to have the simple and deterministic rule "Toggling the offload state of an offline CPU is forbidden". For but one example, consider that an offloaded offline CPU might have millions of callbacks queued. Best to just say "no". This commit therefore forbids toggling of the offloaded state of offline CPUs. Reported-by: Paul E. McKenney Cc: Josh Triplett Cc: Lai Jiangshan Cc: Joel Fernandes Cc: Neeraj Upadhyay Cc: Boqun Feng Signed-off-by: Frederic Weisbecker Signed-off-by: Paul E. McKenney --- kernel/rcu/tree.c | 3 +-- kernel/rcu/tree_plugin.h | 57 ++++++++++++++++++------------------------------ 2 files changed, 22 insertions(+), 38 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 03503e2..ee77858 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -4086,8 +4086,7 @@ int rcutree_prepare_cpu(unsigned int cpu) raw_spin_unlock_rcu_node(rnp); /* irqs remain disabled. */ /* * Lock in case the CB/GP kthreads are still around handling - * old callbacks (longer term we should flush all callbacks - * before completing CPU offline) + * old callbacks. */ rcu_nocb_lock(rdp); if (rcu_segcblist_empty(&rdp->cblist)) /* No early-boot CBs? */ diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h index 013142d..9fd8588 100644 --- a/kernel/rcu/tree_plugin.h +++ b/kernel/rcu/tree_plugin.h @@ -2399,23 +2399,18 @@ static int rdp_offload_toggle(struct rcu_data *rdp, return 0; } -static int __rcu_nocb_rdp_deoffload(struct rcu_data *rdp) +static long rcu_nocb_rdp_deoffload(void *arg) { + struct rcu_data *rdp = arg; struct rcu_segcblist *cblist = &rdp->cblist; unsigned long flags; int ret; + WARN_ON_ONCE(rdp->cpu != raw_smp_processor_id()); + pr_info("De-offloading %d\n", rdp->cpu); rcu_nocb_lock_irqsave(rdp, flags); - /* - * If there are still pending work offloaded, the offline - * CPU won't help much handling them. - */ - if (cpu_is_offline(rdp->cpu) && !rcu_segcblist_empty(&rdp->cblist)) { - rcu_nocb_unlock_irqrestore(rdp, flags); - return -EBUSY; - } ret = rdp_offload_toggle(rdp, false, flags); swait_event_exclusive(rdp->nocb_state_wq, @@ -2446,14 +2441,6 @@ static int __rcu_nocb_rdp_deoffload(struct rcu_data *rdp) return ret; } -static long rcu_nocb_rdp_deoffload(void *arg) -{ - struct rcu_data *rdp = arg; - - WARN_ON_ONCE(rdp->cpu != raw_smp_processor_id()); - return __rcu_nocb_rdp_deoffload(rdp); -} - int rcu_nocb_cpu_deoffload(int cpu) { struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu); @@ -2466,12 +2453,14 @@ int rcu_nocb_cpu_deoffload(int cpu) mutex_lock(&rcu_state.barrier_mutex); cpus_read_lock(); if (rcu_rdp_is_offloaded(rdp)) { - if (cpu_online(cpu)) + if (cpu_online(cpu)) { ret = work_on_cpu(cpu, rcu_nocb_rdp_deoffload, rdp); - else - ret = __rcu_nocb_rdp_deoffload(rdp); - if (!ret) - cpumask_clear_cpu(cpu, rcu_nocb_mask); + if (!ret) + cpumask_clear_cpu(cpu, rcu_nocb_mask); + } else { + pr_info("NOCB: Can't CB-deoffload an offline CPU\n"); + ret = -EINVAL; + } } cpus_read_unlock(); mutex_unlock(&rcu_state.barrier_mutex); @@ -2480,12 +2469,14 @@ int rcu_nocb_cpu_deoffload(int cpu) } EXPORT_SYMBOL_GPL(rcu_nocb_cpu_deoffload); -static int __rcu_nocb_rdp_offload(struct rcu_data *rdp) +static long rcu_nocb_rdp_offload(void *arg) { + struct rcu_data *rdp = arg; struct rcu_segcblist *cblist = &rdp->cblist; unsigned long flags; int ret; + WARN_ON_ONCE(rdp->cpu != raw_smp_processor_id()); /* * For now we only support re-offload, ie: the rdp must have been * offloaded on boot first. @@ -2525,14 +2516,6 @@ static int __rcu_nocb_rdp_offload(struct rcu_data *rdp) return ret; } -static long rcu_nocb_rdp_offload(void *arg) -{ - struct rcu_data *rdp = arg; - - WARN_ON_ONCE(rdp->cpu != raw_smp_processor_id()); - return __rcu_nocb_rdp_offload(rdp); -} - int rcu_nocb_cpu_offload(int cpu) { struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu); @@ -2541,12 +2524,14 @@ int rcu_nocb_cpu_offload(int cpu) mutex_lock(&rcu_state.barrier_mutex); cpus_read_lock(); if (!rcu_rdp_is_offloaded(rdp)) { - if (cpu_online(cpu)) + if (cpu_online(cpu)) { ret = work_on_cpu(cpu, rcu_nocb_rdp_offload, rdp); - else - ret = __rcu_nocb_rdp_offload(rdp); - if (!ret) - cpumask_set_cpu(cpu, rcu_nocb_mask); + if (!ret) + cpumask_set_cpu(cpu, rcu_nocb_mask); + } else { + pr_info("NOCB: Can't CB-offload an offline CPU\n"); + ret = -EINVAL; + } } cpus_read_unlock(); mutex_unlock(&rcu_state.barrier_mutex); -- 2.9.5