diff options
author | Heiko Carstens <heiko.carstens@de.ibm.com> | 2016-12-02 07:16:02 -0500 |
---|---|---|
committer | Martin Schwidefsky <schwidefsky@de.ibm.com> | 2016-12-07 01:22:41 -0500 |
commit | 307b3114eff6ba981c8eddbce327b4a82158bfe3 (patch) | |
tree | a167d837d59f4197575f8b6bf84decbd3d97aafa | |
parent | 11a247e376669323b0d9f56fbdb5c163c6310112 (diff) |
s390/numa: always use logical cpu and core ids
The toptree algorithm uses the physical core ids to create a mapping
between cores and nodes (to_node_id array within emu_cores structure).
The core ids are used as an index into an array which size depends on
CONFIG_NR_CPUS. If the physical core ids are larger, this will result
in out-of-bounds write accesses.
Generate logical core ids instead to avoid this.
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
-rw-r--r-- | arch/s390/include/asm/smp.h | 6 | ||||
-rw-r--r-- | arch/s390/numa/mode_emu.c | 2 |
2 files changed, 7 insertions, 1 deletions
diff --git a/arch/s390/include/asm/smp.h b/arch/s390/include/asm/smp.h index 0cc383b9be7f..8116b7b63af3 100644 --- a/arch/s390/include/asm/smp.h +++ b/arch/s390/include/asm/smp.h | |||
@@ -69,6 +69,12 @@ static inline void smp_stop_cpu(void) | |||
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 | ||
72 | /* Return thread 0 CPU number as base CPU */ | ||
73 | static inline int smp_get_base_cpu(int cpu) | ||
74 | { | ||
75 | return cpu - (cpu % (smp_cpu_mtid + 1)); | ||
76 | } | ||
77 | |||
72 | #ifdef CONFIG_HOTPLUG_CPU | 78 | #ifdef CONFIG_HOTPLUG_CPU |
73 | extern int smp_rescan_cpus(void); | 79 | extern int smp_rescan_cpus(void); |
74 | extern void __noreturn cpu_die(void); | 80 | extern void __noreturn cpu_die(void); |
diff --git a/arch/s390/numa/mode_emu.c b/arch/s390/numa/mode_emu.c index 37e0bb835516..b83109328fec 100644 --- a/arch/s390/numa/mode_emu.c +++ b/arch/s390/numa/mode_emu.c | |||
@@ -360,7 +360,7 @@ static struct toptree *toptree_from_topology(void) | |||
360 | drawer = toptree_get_child(node, top->drawer_id); | 360 | drawer = toptree_get_child(node, top->drawer_id); |
361 | book = toptree_get_child(drawer, top->book_id); | 361 | book = toptree_get_child(drawer, top->book_id); |
362 | mc = toptree_get_child(book, top->socket_id); | 362 | mc = toptree_get_child(book, top->socket_id); |
363 | core = toptree_get_child(mc, top->core_id); | 363 | core = toptree_get_child(mc, smp_get_base_cpu(cpu)); |
364 | if (!drawer || !book || !mc || !core) | 364 | if (!drawer || !book || !mc || !core) |
365 | panic("NUMA emulation could not allocate memory"); | 365 | panic("NUMA emulation could not allocate memory"); |
366 | cpumask_set_cpu(cpu, &core->mask); | 366 | cpumask_set_cpu(cpu, &core->mask); |