* @fn() runs.
  *
  * This can be thought of as a very heavy write lock, equivalent to
- * grabbing every spinlock in the kernel. */
+ * grabbing every spinlock in the kernel.
+ *
+ * Protects against CPU hotplug.
+ */
 int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus);
 
+/**
+ * stop_machine_cpuslocked: freeze the machine on all CPUs and run this function
+ * @fn: the function to run
+ * @data: the data ptr for the @fn()
+ * @cpus: the cpus to run the @fn() on (NULL = any online cpu)
+ *
+ * Same as above. Must be called from with in a cpus_read_lock() protected
+ * region. Avoids nested calls to cpus_read_lock().
+ */
+int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus);
+
 int stop_machine_from_inactive_cpu(cpu_stop_fn_t fn, void *data,
                                   const struct cpumask *cpus);
 #else  /* CONFIG_SMP || CONFIG_HOTPLUG_CPU */
 
-static inline int stop_machine(cpu_stop_fn_t fn, void *data,
-                                const struct cpumask *cpus)
+static inline int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *data,
+                                         const struct cpumask *cpus)
 {
        unsigned long flags;
        int ret;
        return ret;
 }
 
+static inline int stop_machine(cpu_stop_fn_t fn, void *data,
+                              const struct cpumask *cpus)
+{
+       return stop_machine_cpuslocked(fn, data, cpus);
+}
+
 static inline int stop_machine_from_inactive_cpu(cpu_stop_fn_t fn, void *data,
                                                 const struct cpumask *cpus)
 {
 
 }
 early_initcall(cpu_stop_init);
 
-static int __stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus)
+int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *data,
+                           const struct cpumask *cpus)
 {
        struct multi_stop_data msdata = {
                .fn = fn,
                .active_cpus = cpus,
        };
 
+       lockdep_assert_cpus_held();
+
        if (!stop_machine_initialized) {
                /*
                 * Handle the case where stop_machine() is called
        int ret;
 
        /* No CPUs can come up or down during this. */
-       get_online_cpus();
-       ret = __stop_machine(fn, data, cpus);
-       put_online_cpus();
+       cpus_read_lock();
+       ret = stop_machine_cpuslocked(fn, data, cpus);
+       cpus_read_unlock();
        return ret;
 }
 EXPORT_SYMBOL_GPL(stop_machine);