Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2819815imm; Mon, 10 Sep 2018 07:00:54 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZdlbyeKBOus28WCDa2PCRy4FfjzVvwOMGgsobHAdgzTMmIp1jE6/49AcKVxz6VW+7c9VOy X-Received: by 2002:a62:571b:: with SMTP id l27-v6mr23878518pfb.29.1536588054091; Mon, 10 Sep 2018 07:00:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536588054; cv=none; d=google.com; s=arc-20160816; b=QN+mGUPmxvZO5awL1Dbo6rnmImc8EkKHmKna4nJdX4P8Gh00Hx2BvwalECqTzemF0i 05GX3lftHYAR6e1XPE/FJ0i9ouCl6aDBZnhXyPiilj5QwB9x+wpUu1tO31d2bg6MI3Jr aan230+7MevgMz1Bz21vBf5pGH93KJYXN7uAo9yFbQOfga/nADsKTE9aGDTVb/sEVtyJ MzgSgVK52WEjLvR87NldKPpE4NoPhFrkkib+zDbFzfdTTmcV3Zfk8silI0VfXYCHduN+ vRJCVjQNTc5O9m9H7kzewC0YGIx1f1/bazToOhgvJtegFuI9idmIezlvMtAaQ2JcEHck XbnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=464AHvkeesgidwZ/wa0Pjh8+DvQQdiKh2h/NIY4LaKM=; b=OgKbSW6BH/rj50rWqEEUJvQPgyRCnYL88nMCp7w2knHGtCWME9V8ZlLwY0tNqsl99I PaffzrM1ft+5xccLcz262tDx/xbyk2r0qRzMHw2+jc8+4I7gm8ybJJY1u4aAQjKH5/s3 ++4MGhwA/2dI0A2THUjGccrHGIzXVLK35udRWzdL8Kju45U61IbhYmMxGkW1bLDuWXHK tNdgXj4zQeJ3JtZAg1qjWF3bBjRbqCvLOjtoE56z3uY4Z0AuiNjoxNyTvPAAyOq+MRvW dKBVKlgJWaGQaP6bm0Y5BT7OtS252EqZ4HOU638ZaYnb8hvTjrlD8ANFasNQyR9Tq8jP 7VqA== ARC-Authentication-Results: i=1; mx.google.com; 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 d13-v6si17910725plj.286.2018.09.10.07.00.09; Mon, 10 Sep 2018 07:00:54 -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; 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 S1728820AbeIJSug (ORCPT + 99 others); Mon, 10 Sep 2018 14:50:36 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:39535 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728184AbeIJSug (ORCPT ); Mon, 10 Sep 2018 14:50:36 -0400 Received: from bigeasy by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1fzMfo-00013A-4g; Mon, 10 Sep 2018 15:56:16 +0200 Date: Mon, 10 Sep 2018 15:56:16 +0200 From: Sebastian Andrzej Siewior To: linux-kernel@vger.kernel.org Cc: Boqun Feng , "Paul E. McKenney" , Peter Zijlstra , "Aneesh Kumar K.V" , tglx@linutronix.de, Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan Subject: [PATCH] rcu: Use cpus_read_lock() while looking at cpu_online_mask Message-ID: <20180910135615.tr3cvipwbhq6xug4@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It was possible that sync_rcu_exp_select_cpus() enqueued something on CPU0 while CPU0 was offline. Such a work item wouldn't be processed until CPU0 gets back online. This problem was addressed in commit fcc6354365015 ("rcu: Make expedited GPs handle CPU 0 being offline"). I don't think the issue fully addressed. Assume grplo = 0 and grphi = 7 and sync_rcu_exp_select_cpus() is invoked on CPU1. The preempt_disable() section on CPU1 won't ensure that CPU0 remains online between looking at cpu_online_mask and invoking queue_work_on() on CPU1. Use cpus_read_lock() to ensure that `cpu' is not going down between looking at cpu_online_mask at invoking queue_work_on() and waiting for its completion. It is added around the loop + flush_work() which is similar to work_on_cpu_safe() (and we can have multiple jobs running on NUMA systems). Fixes: fcc6354365015 ("rcu: Make expedited GPs handle CPU 0 being offline") Signed-off-by: Sebastian Andrzej Siewior --- kernel/rcu/tree_exp.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h index 01b6ddeb4f050..a104cf91e6b90 100644 --- a/kernel/rcu/tree_exp.h +++ b/kernel/rcu/tree_exp.h @@ -479,6 +479,7 @@ static void sync_rcu_exp_select_cpus(struct rcu_state *rsp, sync_exp_reset_tree(rsp); trace_rcu_exp_grace_period(rsp->name, rcu_exp_gp_seq_endval(rsp), TPS("select")); + cpus_read_lock(); /* Schedule work for each leaf rcu_node structure. */ rcu_for_each_leaf_node(rsp, rnp) { rnp->exp_need_flush = false; @@ -493,13 +494,11 @@ static void sync_rcu_exp_select_cpus(struct rcu_state *rsp, continue; } INIT_WORK(&rnp->rew.rew_work, sync_rcu_exp_select_node_cpus); - preempt_disable(); cpu = cpumask_next(rnp->grplo - 1, cpu_online_mask); /* If all offline, queue the work on an unbound CPU. */ if (unlikely(cpu > rnp->grphi)) cpu = WORK_CPU_UNBOUND; queue_work_on(cpu, rcu_par_gp_wq, &rnp->rew.rew_work); - preempt_enable(); rnp->exp_need_flush = true; } @@ -507,6 +506,7 @@ static void sync_rcu_exp_select_cpus(struct rcu_state *rsp, rcu_for_each_leaf_node(rsp, rnp) if (rnp->exp_need_flush) flush_work(&rnp->rew.rew_work); + cpus_read_unlock(); } static void synchronize_sched_expedited_wait(struct rcu_state *rsp) -- 2.19.0.rc2