sched: hmp: fix out-of-range CPU possible
authorChris Redpath <chris.redpath@arm.com>
Wed, 11 Jun 2014 13:08:40 +0000 (14:08 +0100)
committerJon Medhurst <tixy@linaro.org>
Wed, 11 Jun 2014 14:08:35 +0000 (15:08 +0100)
If someone hotplugs all the little CPUs while another CPU is handling
a wakeup, we can potentially return new_cpu == NR_CPUS from
hmp_select_slower_cpu (which is called internally by
hmp_best_little_cpu as well). We will use this to deref the
per_cpu rq array in hmp_next_down_delay which can go boom.

Signed-off-by: Chris Redpath <chris.redpath@arm.com>
Signed-off-by: Jon Medhurst <tixy@linaro.org>
kernel/sched/fair.c

index ffa643ce9116df8fdf69e7447c0be4d3f3d93d9c..26c43b463017e53d391c3cff1e972a670abd9c45 100644 (file)
@@ -4456,7 +4456,11 @@ unlock:
 #else
                new_cpu = hmp_select_slower_cpu(p, prev_cpu);
 #endif
-               if (new_cpu != prev_cpu) {
+               /*
+                * we might have no suitable CPU
+                * in which case new_cpu == NR_CPUS
+                */
+               if (new_cpu < NR_CPUS && new_cpu != prev_cpu) {
                        hmp_next_down_delay(&p->se, new_cpu);
                        trace_sched_hmp_migrate(p, new_cpu, HMP_MIGRATE_WAKEUP);
                        return new_cpu;