From patchwork Mon Apr 23 16:42:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 8052 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 1C26C23E22 for ; Mon, 23 Apr 2012 16:42:50 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id D87B5A181B8 for ; Mon, 23 Apr 2012 16:42:49 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so23096175iag.11 for ; Mon, 23 Apr 2012 09:42:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-content-scanned:x-cbid:x-gm-message-state; bh=fLuEAFJqfivG7wE9ipSO7qRlv8yh2iPIxk8WGuzsB8w=; b=HJwfTw40VaGjQLe9BT6hieOj1mSMhoXb/HVCG+n4jLXElo8YS+mmfcWLHRxW68DYYq fOnZvAvMFEYRxsNv4NjnKqYoMDnr4eYGaPp5M0oVaSjaeXg6z8zOlkJBCjuwOICQWx1G V9EFBfWGcbIvkZr77hYjFwpzOBPhndtX8wescVpEsd/Fd4lWj553w5WE4DhK+Kzx6irb R1WZ6FbX6rPRQJybeNWX4YJ1i7+HAVUpsgG5Tvt+jbythsJQBk0uEIGCWpRnzFqPuLiq PIPJ/Q6y6ar9IKDzW1/cbwWD87bJkCYmjHxIWbbeJhG3YUglty/etIVweveGA/3w3iOW YQhw== Received: by 10.50.17.201 with SMTP id q9mr7235144igd.19.1335199369621; Mon, 23 Apr 2012 09:42:49 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.137.198 with SMTP id x6csp125353ibt; Mon, 23 Apr 2012 09:42:49 -0700 (PDT) Received: by 10.182.31.102 with SMTP id z6mr2895150obh.78.1335199369092; Mon, 23 Apr 2012 09:42:49 -0700 (PDT) Received: from e36.co.us.ibm.com (e36.co.us.ibm.com. [32.97.110.154]) by mx.google.com with ESMTPS id oo4si1311093obc.26.2012.04.23.09.42.48 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Apr 2012 09:42:49 -0700 (PDT) Received-SPF: pass (google.com: domain of paulmck@linux.vnet.ibm.com designates 32.97.110.154 as permitted sender) client-ip=32.97.110.154; Authentication-Results: mx.google.com; spf=pass (google.com: domain of paulmck@linux.vnet.ibm.com designates 32.97.110.154 as permitted sender) smtp.mail=paulmck@linux.vnet.ibm.com Received: from /spool/local by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 23 Apr 2012 10:42:48 -0600 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 23 Apr 2012 10:42:46 -0600 Received: from d03relay02.boulder.ibm.com (d03relay02.boulder.ibm.com [9.17.195.227]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 631B019D8053; Mon, 23 Apr 2012 10:42:32 -0600 (MDT) Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay02.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q3NGgZcd117566; Mon, 23 Apr 2012 10:42:38 -0600 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q3NGgTbJ018634; Mon, 23 Apr 2012 10:42:31 -0600 Received: from paulmck-ThinkPad-W500 ([9.47.24.152]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q3NGgTuZ018615; Mon, 23 Apr 2012 10:42:29 -0600 Received: by paulmck-ThinkPad-W500 (Postfix, from userid 1000) id 665E2E523C; Mon, 23 Apr 2012 09:42:29 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: mingo@elte.hu, laijs@cn.fujitsu.com, dipankar@in.ibm.com, akpm@linux-foundation.org, mathieu.desnoyers@polymtl.ca, josh@joshtriplett.org, niv@us.ibm.com, tglx@linutronix.de, peterz@infradead.org, rostedt@goodmis.org, Valdis.Kletnieks@vt.edu, dhowells@redhat.com, eric.dumazet@gmail.com, darren@dvhart.com, fweisbec@gmail.com, patches@linaro.org, "Paul E. McKenney" , "Paul E. McKenney" Subject: [PATCH RFC tip/core/rcu 1/6] rcu: Stabilize use of num_online_cpus() for GP short circuit Date: Mon, 23 Apr 2012 09:42:22 -0700 Message-Id: <1335199347-13926-1-git-send-email-paulmck@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.8 In-Reply-To: <20120423164159.GA13819@linux.vnet.ibm.com> References: <20120423164159.GA13819@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12042316-3352-0000-0000-0000043699A3 X-Gm-Message-State: ALoCoQl02ITp4hTSAC0UBoU9xxZ9GP7jJAxdMBSKF5tkLsZ18kdrBMbictS78NBHQskvb6AwN0T2 From: "Paul E. McKenney" The rcu_blocking_is_gp() function tests to see if there is only one online CPU, and if so, synchronize_sched() and friends become no-ops. However, for larger systems, num_online_cpus() scans a large vector, and might be preempted while doing so. While preempted, any number of CPUs might come online and go offline, potentially resulting in num_online_cpus() returning 1 when there never had only been one CPU online. This would result in a too-short RCU grace period, which could in turn result in total failure. This commit therefore protects the num_online_cpus() with preempt_disable(). Signed-off-by: Paul E. McKenney Signed-off-by: Paul E. McKenney --- include/linux/rcutree.h | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/include/linux/rcutree.h b/include/linux/rcutree.h index e8ee5dd..997179f 100644 --- a/include/linux/rcutree.h +++ b/include/linux/rcutree.h @@ -101,8 +101,13 @@ extern void rcu_sched_force_quiescent_state(void); /* A context switch is a grace period for RCU-sched and RCU-bh. */ static inline int rcu_blocking_is_gp(void) { + int ret; + might_sleep(); /* Check for RCU read-side critical section. */ - return num_online_cpus() == 1; + preempt_disable(); /* Prevent CPU hotplug from confusing us. */ + ret = num_online_cpus() == 1; + preempt_enable(); + return ret; } extern void rcu_scheduler_starting(void);