From patchwork Thu Sep 20 18:48:18 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: 11590 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 DF93323E54 for ; Thu, 20 Sep 2012 18:48:49 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 49A4AA1823C for ; Thu, 20 Sep 2012 18:48:49 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so3419662iej.11 for ; Thu, 20 Sep 2012 11:48: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=7roy8JBeH3dFoj0PrmhNZssxscmP+6ocE5FYQFV+yE4=; b=c1tDBSX/uSoyK6Ni8ezNnlxXtO1oCbcEnYFsQfdio4H/T89Pl0OBbEnARhwYK1j1r6 jbqWgIQmv85S9ucmLeS8FHZ2MbwPIXkL7DxsnGA8NpNCaAbH4Mk9OjbtT6vGKRLTj7dn 1hAqTx7/zf+di/ztnb9j/b8FLIwu05gFh3LibZp9pbi6zFyjMJDposH1nJJzkHx1P+gX ZUhSytm12QsUWQ/8QfmIrI69jRvlmTzhMU4X2L5oVt7HT+ZTuHtgHquxdEsBLav5Ftdo y1sQ24G9ZLy3AxuqMKRmUynpgONXKANdZcB20gHkV75ONAHzLR6c8cvqNVJS7dRPlNk8 Onqg== Received: by 10.42.110.130 with SMTP id q2mr2126280icp.53.1348166929037; Thu, 20 Sep 2012 11:48: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.50.184.232 with SMTP id ex8csp92201igc; Thu, 20 Sep 2012 11:48:48 -0700 (PDT) Received: by 10.60.5.193 with SMTP id u1mr2082497oeu.111.1348166928501; Thu, 20 Sep 2012 11:48:48 -0700 (PDT) Received: from e38.co.us.ibm.com (e38.co.us.ibm.com. [32.97.110.159]) by mx.google.com with ESMTPS id zm6si5734893obb.55.2012.09.20.11.48.48 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 20 Sep 2012 11:48:48 -0700 (PDT) Received-SPF: pass (google.com: domain of paulmck@linux.vnet.ibm.com designates 32.97.110.159 as permitted sender) client-ip=32.97.110.159; Authentication-Results: mx.google.com; spf=pass (google.com: domain of paulmck@linux.vnet.ibm.com designates 32.97.110.159 as permitted sender) smtp.mail=paulmck@linux.vnet.ibm.com Received: from /spool/local by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 20 Sep 2012 12:48:47 -0600 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 20 Sep 2012 12:48:46 -0600 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id D611119D8051 for ; Thu, 20 Sep 2012 12:48:45 -0600 (MDT) Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q8KImhe7141980 for ; Thu, 20 Sep 2012 12:48:43 -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 q8KImSO3021403 for ; Thu, 20 Sep 2012 12:48:41 -0600 Received: from paulmck-ThinkPad-W500 ([9.47.24.72]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q8KImNWM020789; Thu, 20 Sep 2012 12:48:25 -0600 Received: by paulmck-ThinkPad-W500 (Postfix, from userid 1000) id F2535EC537; Thu, 20 Sep 2012 11:48:22 -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, sbw@mit.edu, patches@linaro.org, "Paul E. McKenney" Subject: [PATCH tip/core/rcu 22/23] rcu: Handle unbalanced rcu_node configurations with few CPUs Date: Thu, 20 Sep 2012 11:48:18 -0700 Message-Id: <1348166900-18716-22-git-send-email-paulmck@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.8 In-Reply-To: <1348166900-18716-1-git-send-email-paulmck@linux.vnet.ibm.com> References: <20120920184751.GA18657@linux.vnet.ibm.com> <1348166900-18716-1-git-send-email-paulmck@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12092018-5518-0000-0000-000007CEF3FB X-Gm-Message-State: ALoCoQkDeRQzxQnYxLeOvJ9D954o314gfvGpQ2Exja0CexsdyAXsAWcc4X8X+5FtsyYNS5df3/q7 From: "Paul E. McKenney" If CONFIG_RCU_FANOUT_EXACT=y, if there are not enough CPUs (according to nr_cpu_ids) to require more than a single rcu_node structure, but if NR_CPUS is larger than would fit into a single rcu_node structure, then the current rcu_init_levelspread() code is subject to integer overflow in the eight-bit ->levelspread[] array in the rcu_state structure. In this case, the solution is -not- to increase the size of the elements in this array because the values in that array should be constrained to the number of bits in an unsigned long. Instead, this commit replaces NR_CPUS with nr_cpu_ids in the rcu_init_levelspread() function's initialization of the cprv local variable. This results in all of the arithmetic being consistently based off of the nr_cpu_ids value, thus avoiding the overflow, which was caused by the mixing of nr_cpu_ids and NR_CPUS. Reported-by: Mike Galbraith Signed-off-by: Paul E. McKenney --- kernel/rcutree.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/kernel/rcutree.c b/kernel/rcutree.c index 7a91dd4..5068e51 100644 --- a/kernel/rcutree.c +++ b/kernel/rcutree.c @@ -2721,7 +2721,7 @@ static void __init rcu_init_levelspread(struct rcu_state *rsp) int cprv; int i; - cprv = NR_CPUS; + cprv = nr_cpu_ids; for (i = rcu_num_lvls - 1; i >= 0; i--) { ccur = rsp->levelcnt[i]; rsp->levelspread[i] = (cprv + ccur - 1) / ccur;