powerpc: Fix cpu_online_cores_map to return only online threads mask
[firefly-linux-kernel-4.4.55.git] / arch / powerpc / include / asm / cputhreads.h
index 4c8ad592ae3351d96f7e225411d9f551657c5bc7..ba42e46ea58eeed448d3d7abb5c67f5570e96bca 100644 (file)
@@ -25,15 +25,15 @@ extern cpumask_t threads_core_mask;
 #define threads_per_core       1
 #define threads_per_subcore    1
 #define threads_shift          0
-#define threads_core_mask      (CPU_MASK_CPU0)
+#define threads_core_mask      (*get_cpu_mask(0))
 #endif
 
 /* cpu_thread_mask_to_cores - Return a cpumask of one per cores
  *                            hit by the argument
  *
- * @threads:   a cpumask of threads
+ * @threads:   a cpumask of online threads
  *
- * This function returns a cpumask which will have one "cpu" (or thread)
+ * This function returns a cpumask which will have one online cpu's
  * bit set for each core that has at least one thread set in the argument.
  *
  * This can typically be used for things like IPI for tlb invalidations
@@ -42,13 +42,16 @@ extern cpumask_t threads_core_mask;
 static inline cpumask_t cpu_thread_mask_to_cores(const struct cpumask *threads)
 {
        cpumask_t       tmp, res;
-       int             i;
+       int             i, cpu;
 
        cpumask_clear(&res);
        for (i = 0; i < NR_CPUS; i += threads_per_core) {
                cpumask_shift_left(&tmp, &threads_core_mask, i);
-               if (cpumask_intersects(threads, &tmp))
-                       cpumask_set_cpu(i, &res);
+               if (cpumask_intersects(threads, &tmp)) {
+                       cpu = cpumask_next_and(-1, &tmp, cpu_online_mask);
+                       if (cpu < nr_cpu_ids)
+                               cpumask_set_cpu(cpu, &res);
+               }
        }
        return res;
 }