diff options
author | Mike Travis <travis@sgi.com> | 2008-06-27 13:10:13 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-07-08 07:16:16 -0400 |
commit | 6a2f47ca27fad36f99e8478a3807d4b8c7db80e7 (patch) | |
tree | 9d281e3969e5431b1d330cbdc3ee13d626fba4ee /arch/x86/kernel/setup_percpu.c | |
parent | cd5dce2fb023a6f0168344b7dd8adec30017458e (diff) |
x86: add check for node passed to node_to_cpumask, v3
* When CONFIG_DEBUG_PER_CPU_MAPS is set, the node passed to
node_to_cpumask and node_to_cpumask_ptr should be validated.
If invalid, then a dump_stack is performed and a zero cpumask
is returned.
v2: Slightly different version to remove a compiler warning.
v3: Redone to reflect moving setup.c -> setup_percpu.c
Signed-off-by: Mike Travis <travis@sgi.com>
Cc: Vegard Nossum <vegard.nossum@gmail.com>
Cc: "akpm@linux-foundation.org" <akpm@linux-foundation.org>
Cc: Yinghai Lu <yhlu.kernel@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/x86/kernel/setup_percpu.c')
-rw-r--r-- | arch/x86/kernel/setup_percpu.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c index 7068f95cccc6..43aca2de624a 100644 --- a/arch/x86/kernel/setup_percpu.c +++ b/arch/x86/kernel/setup_percpu.c | |||
@@ -346,6 +346,10 @@ int early_cpu_to_node(int cpu) | |||
346 | return per_cpu(x86_cpu_to_node_map, cpu); | 346 | return per_cpu(x86_cpu_to_node_map, cpu); |
347 | } | 347 | } |
348 | 348 | ||
349 | |||
350 | /* empty cpumask */ | ||
351 | static const cpumask_t cpu_mask_none; | ||
352 | |||
349 | /* | 353 | /* |
350 | * Returns a pointer to the bitmask of CPUs on Node 'node'. | 354 | * Returns a pointer to the bitmask of CPUs on Node 'node'. |
351 | */ | 355 | */ |
@@ -358,13 +362,23 @@ cpumask_t *_node_to_cpumask_ptr(int node) | |||
358 | dump_stack(); | 362 | dump_stack(); |
359 | return &cpu_online_map; | 363 | return &cpu_online_map; |
360 | } | 364 | } |
361 | BUG_ON(node >= nr_node_ids); | 365 | if (node >= nr_node_ids) { |
362 | return &node_to_cpumask_map[node]; | 366 | printk(KERN_WARNING |
367 | "_node_to_cpumask_ptr(%d): node > nr_node_ids(%d)\n", | ||
368 | node, nr_node_ids); | ||
369 | dump_stack(); | ||
370 | return (cpumask_t *)&cpu_mask_none; | ||
371 | } | ||
372 | return (cpumask_t *)&node_to_cpumask_map[node]; | ||
363 | } | 373 | } |
364 | EXPORT_SYMBOL(_node_to_cpumask_ptr); | 374 | EXPORT_SYMBOL(_node_to_cpumask_ptr); |
365 | 375 | ||
366 | /* | 376 | /* |
367 | * Returns a bitmask of CPUs on Node 'node'. | 377 | * Returns a bitmask of CPUs on Node 'node'. |
378 | * | ||
379 | * Side note: this function creates the returned cpumask on the stack | ||
380 | * so with a high NR_CPUS count, excessive stack space is used. The | ||
381 | * node_to_cpumask_ptr function should be used whenever possible. | ||
368 | */ | 382 | */ |
369 | cpumask_t node_to_cpumask(int node) | 383 | cpumask_t node_to_cpumask(int node) |
370 | { | 384 | { |
@@ -374,7 +388,13 @@ cpumask_t node_to_cpumask(int node) | |||
374 | dump_stack(); | 388 | dump_stack(); |
375 | return cpu_online_map; | 389 | return cpu_online_map; |
376 | } | 390 | } |
377 | BUG_ON(node >= nr_node_ids); | 391 | if (node >= nr_node_ids) { |
392 | printk(KERN_WARNING | ||
393 | "node_to_cpumask(%d): node > nr_node_ids(%d)\n", | ||
394 | node, nr_node_ids); | ||
395 | dump_stack(); | ||
396 | return cpu_mask_none; | ||
397 | } | ||
378 | return node_to_cpumask_map[node]; | 398 | return node_to_cpumask_map[node]; |
379 | } | 399 | } |
380 | EXPORT_SYMBOL(node_to_cpumask); | 400 | EXPORT_SYMBOL(node_to_cpumask); |