From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757311AbYFZQ0o (ORCPT ); Thu, 26 Jun 2008 12:26:44 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1757406AbYFZQ0b (ORCPT ); Thu, 26 Jun 2008 12:26:31 -0400 Received: from relay2.sgi.com ([192.48.171.30]:52904 "EHLO relay.sgi.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752254AbYFZQ0a (ORCPT ); Thu, 26 Jun 2008 12:26:30 -0400 Message-ID: <4863C334.2090007@sgi.com> Date: Thu, 26 Jun 2008 09:26:28 -0700 From: Mike Travis User-Agent: Thunderbird 2.0.0.6 (X11/20070801) MIME-Version: 1.0 To: Ingo Molnar CC: Vegard Nossum , "akpm@linux-foundation.org" , mm-commits@vger.kernel.org, Yinghai Lu , Ingo Molnar , LKML Subject: [PATCH 1/1] x86: Add check for node passed to node_to_cpumask References: <200806090918.m599Ib0G012837@imap1.linux-foundation.org> <19f34abd0806090420r4100241cgb4b828441de3b102@mail.gmail.com> <20080609113547.GA1534@elte.hu> <484D54F2.4070603@sgi.com> <20080626113229.GB29619@elte.hu> In-Reply-To: <20080626113229.GB29619@elte.hu> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Subject: [PATCH 1/1] x86: Add check for node passed to node_to_cpumask * When CONFIG_DEBUG_PER_CPU_MAPS is set, the node passed to node_to_cpumask and node_to_cpumask_ptr should be validated. Based on "Thu Jun 26 09:23:55 PDT 2008" tip/master... ;-) Signed-off-by: Mike Travis --- arch/x86/kernel/setup.c | 26 +++++++++++++++++++++++--- include/asm-x86/topology.h | 7 ++++++- 2 files changed, 29 insertions(+), 4 deletions(-) --- linux-2.6.tip.orig/arch/x86/kernel/setup.c +++ linux-2.6.tip/arch/x86/kernel/setup.c @@ -377,6 +377,10 @@ int early_cpu_to_node(int cpu) return per_cpu(x86_cpu_to_node_map, cpu); } + +/* empty cpumask */ +static const cpumask_t cpu_mask_none; + /* * Returns a pointer to the bitmask of CPUs on Node 'node'. */ @@ -389,13 +393,23 @@ cpumask_t *_node_to_cpumask_ptr(int node dump_stack(); return &cpu_online_map; } - BUG_ON(node >= nr_node_ids); - return &node_to_cpumask_map[node]; + if (node >= nr_node_ids) { + printk(KERN_WARNING + "_node_to_cpumask_ptr(%d): node > nr_node_ids(%d)\n", + node, nr_node_ids); + dump_stack(); + return &cpu_mask_none; + } + return (cpumask_t *)&node_to_cpumask_map[node]; } EXPORT_SYMBOL(_node_to_cpumask_ptr); /* * Returns a bitmask of CPUs on Node 'node'. + * + * Side note: this function creates the returned cpumask on the stack + * so with a high NR_CPUS count, excessive stack space is used. The + * node_to_cpumask_ptr function should be used whenever possible. */ cpumask_t node_to_cpumask(int node) { @@ -405,7 +419,13 @@ cpumask_t node_to_cpumask(int node) dump_stack(); return cpu_online_map; } - BUG_ON(node >= nr_node_ids); + if (node >= nr_node_ids) { + printk(KERN_WARNING + "node_to_cpumask(%d): node > nr_node_ids(%d)\n", + node, nr_node_ids); + dump_stack(); + return cpu_mask_none; + } return node_to_cpumask_map[node]; } EXPORT_SYMBOL(node_to_cpumask); --- linux-2.6.tip.orig/include/asm-x86/topology.h +++ linux-2.6.tip/include/asm-x86/topology.h @@ -57,7 +57,12 @@ static inline int cpu_to_node(int cpu) } #define early_cpu_to_node(cpu) cpu_to_node(cpu) -/* Returns a bitmask of CPUs on Node 'node'. */ +/* Returns a bitmask of CPUs on Node 'node'. + * + * Side note: this function creates the returned cpumask on the stack + * so with a high NR_CPUS count, excessive stack space is used. The + * node_to_cpumask_ptr function should be used whenever possible. + */ static inline cpumask_t node_to_cpumask(int node) { return node_to_cpumask_map[node];