stop_machine.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. /*
  2. * kernel/stop_machine.c
  3. *
  4. * Copyright (C) 2008, 2005 IBM Corporation.
  5. * Copyright (C) 2008, 2005 Rusty Russell rusty@rustcorp.com.au
  6. * Copyright (C) 2010 SUSE Linux Products GmbH
  7. * Copyright (C) 2010 Tejun Heo <tj@kernel.org>
  8. *
  9. * This file is released under the GPLv2 and any later version.
  10. */
  11. #include <linux/completion.h>
  12. #include <linux/cpu.h>
  13. #include <linux/init.h>
  14. #include <linux/kthread.h>
  15. #include <linux/export.h>
  16. #include <linux/percpu.h>
  17. #include <linux/sched.h>
  18. #include <linux/stop_machine.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/kallsyms.h>
  21. #include <linux/smpboot.h>
  22. #include <linux/atomic.h>
  23. #include <linux/nmi.h>
  24. /*
  25. * Structure to determine completion condition and record errors. May
  26. * be shared by works on different cpus.
  27. */
  28. struct cpu_stop_done {
  29. atomic_t nr_todo; /* nr left to execute */
  30. int ret; /* collected return value */
  31. struct completion completion; /* fired if nr_todo reaches 0 */
  32. };
  33. /* the actual stopper, one per every possible cpu, enabled on online cpus */
  34. struct cpu_stopper {
  35. struct task_struct *thread;
  36. raw_spinlock_t lock;
  37. bool enabled; /* is this stopper enabled? */
  38. struct list_head works; /* list of pending works */
  39. struct cpu_stop_work stop_work; /* for stop_cpus */
  40. };
  41. static DEFINE_PER_CPU(struct cpu_stopper, cpu_stopper);
  42. static bool stop_machine_initialized = false;
  43. /* static data for stop_cpus */
  44. static DEFINE_MUTEX(stop_cpus_mutex);
  45. static bool stop_cpus_in_progress;
  46. static void cpu_stop_init_done(struct cpu_stop_done *done, unsigned int nr_todo)
  47. {
  48. memset(done, 0, sizeof(*done));
  49. atomic_set(&done->nr_todo, nr_todo);
  50. init_completion(&done->completion);
  51. }
  52. /* signal completion unless @done is NULL */
  53. static void cpu_stop_signal_done(struct cpu_stop_done *done)
  54. {
  55. if (atomic_dec_and_test(&done->nr_todo))
  56. complete(&done->completion);
  57. }
  58. static void __cpu_stop_queue_work(struct cpu_stopper *stopper,
  59. struct cpu_stop_work *work)
  60. {
  61. list_add_tail(&work->list, &stopper->works);
  62. wake_up_process(stopper->thread);
  63. }
  64. /* queue @work to @stopper. if offline, @work is completed immediately */
  65. static bool cpu_stop_queue_work(unsigned int cpu, struct cpu_stop_work *work)
  66. {
  67. struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
  68. unsigned long flags;
  69. bool enabled;
  70. raw_spin_lock_irqsave(&stopper->lock, flags);
  71. enabled = stopper->enabled;
  72. if (enabled)
  73. __cpu_stop_queue_work(stopper, work);
  74. else if (work->done)
  75. cpu_stop_signal_done(work->done);
  76. raw_spin_unlock_irqrestore(&stopper->lock, flags);
  77. return enabled;
  78. }
  79. /**
  80. * stop_one_cpu - stop a cpu
  81. * @cpu: cpu to stop
  82. * @fn: function to execute
  83. * @arg: argument to @fn
  84. *
  85. * Execute @fn(@arg) on @cpu. @fn is run in a process context with
  86. * the highest priority preempting any task on the cpu and
  87. * monopolizing it. This function returns after the execution is
  88. * complete.
  89. *
  90. * This function doesn't guarantee @cpu stays online till @fn
  91. * completes. If @cpu goes down in the middle, execution may happen
  92. * partially or fully on different cpus. @fn should either be ready
  93. * for that or the caller should ensure that @cpu stays online until
  94. * this function completes.
  95. *
  96. * CONTEXT:
  97. * Might sleep.
  98. *
  99. * RETURNS:
  100. * -ENOENT if @fn(@arg) was not executed because @cpu was offline;
  101. * otherwise, the return value of @fn.
  102. */
  103. int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg)
  104. {
  105. struct cpu_stop_done done;
  106. struct cpu_stop_work work = { .fn = fn, .arg = arg, .done = &done };
  107. cpu_stop_init_done(&done, 1);
  108. if (!cpu_stop_queue_work(cpu, &work))
  109. return -ENOENT;
  110. /*
  111. * In case @cpu == smp_proccessor_id() we can avoid a sleep+wakeup
  112. * cycle by doing a preemption:
  113. */
  114. cond_resched();
  115. wait_for_completion(&done.completion);
  116. return done.ret;
  117. }
  118. /* This controls the threads on each CPU. */
  119. enum multi_stop_state {
  120. /* Dummy starting state for thread. */
  121. MULTI_STOP_NONE,
  122. /* Awaiting everyone to be scheduled. */
  123. MULTI_STOP_PREPARE,
  124. /* Disable interrupts. */
  125. MULTI_STOP_DISABLE_IRQ,
  126. /* Run the function */
  127. MULTI_STOP_RUN,
  128. /* Exit */
  129. MULTI_STOP_EXIT,
  130. };
  131. struct multi_stop_data {
  132. cpu_stop_fn_t fn;
  133. void *data;
  134. /* Like num_online_cpus(), but hotplug cpu uses us, so we need this. */
  135. unsigned int num_threads;
  136. const struct cpumask *active_cpus;
  137. enum multi_stop_state state;
  138. atomic_t thread_ack;
  139. };
  140. static void set_state(struct multi_stop_data *msdata,
  141. enum multi_stop_state newstate)
  142. {
  143. /* Reset ack counter. */
  144. atomic_set(&msdata->thread_ack, msdata->num_threads);
  145. smp_wmb();
  146. msdata->state = newstate;
  147. }
  148. /* Last one to ack a state moves to the next state. */
  149. static void ack_state(struct multi_stop_data *msdata)
  150. {
  151. if (atomic_dec_and_test(&msdata->thread_ack))
  152. set_state(msdata, msdata->state + 1);
  153. }
  154. /* This is the cpu_stop function which stops the CPU. */
  155. static int multi_cpu_stop(void *data)
  156. {
  157. struct multi_stop_data *msdata = data;
  158. enum multi_stop_state curstate = MULTI_STOP_NONE;
  159. int cpu = smp_processor_id(), err = 0;
  160. unsigned long flags;
  161. bool is_active;
  162. /*
  163. * When called from stop_machine_from_inactive_cpu(), irq might
  164. * already be disabled. Save the state and restore it on exit.
  165. */
  166. local_save_flags(flags);
  167. if (!msdata->active_cpus)
  168. is_active = cpu == cpumask_first(cpu_online_mask);
  169. else
  170. is_active = cpumask_test_cpu(cpu, msdata->active_cpus);
  171. /* Simple state machine */
  172. do {
  173. /* Chill out and ensure we re-read multi_stop_state. */
  174. cpu_relax();
  175. if (msdata->state != curstate) {
  176. curstate = msdata->state;
  177. switch (curstate) {
  178. case MULTI_STOP_DISABLE_IRQ:
  179. local_irq_disable();
  180. hard_irq_disable();
  181. break;
  182. case MULTI_STOP_RUN:
  183. if (is_active)
  184. err = msdata->fn(msdata->data);
  185. break;
  186. default:
  187. break;
  188. }
  189. ack_state(msdata);
  190. } else if (curstate > MULTI_STOP_PREPARE) {
  191. /*
  192. * At this stage all other CPUs we depend on must spin
  193. * in the same loop. Any reason for hard-lockup should
  194. * be detected and reported on their side.
  195. */
  196. touch_nmi_watchdog();
  197. }
  198. } while (curstate != MULTI_STOP_EXIT);
  199. local_irq_restore(flags);
  200. return err;
  201. }
  202. static int cpu_stop_queue_two_works(int cpu1, struct cpu_stop_work *work1,
  203. int cpu2, struct cpu_stop_work *work2)
  204. {
  205. struct cpu_stopper *stopper1 = per_cpu_ptr(&cpu_stopper, cpu1);
  206. struct cpu_stopper *stopper2 = per_cpu_ptr(&cpu_stopper, cpu2);
  207. int err;
  208. retry:
  209. raw_spin_lock_irq(&stopper1->lock);
  210. raw_spin_lock_nested(&stopper2->lock, SINGLE_DEPTH_NESTING);
  211. err = -ENOENT;
  212. if (!stopper1->enabled || !stopper2->enabled)
  213. goto unlock;
  214. /*
  215. * Ensure that if we race with __stop_cpus() the stoppers won't get
  216. * queued up in reverse order leading to system deadlock.
  217. *
  218. * We can't miss stop_cpus_in_progress if queue_stop_cpus_work() has
  219. * queued a work on cpu1 but not on cpu2, we hold both locks.
  220. *
  221. * It can be falsely true but it is safe to spin until it is cleared,
  222. * queue_stop_cpus_work() does everything under preempt_disable().
  223. */
  224. err = -EDEADLK;
  225. if (unlikely(stop_cpus_in_progress))
  226. goto unlock;
  227. err = 0;
  228. __cpu_stop_queue_work(stopper1, work1);
  229. __cpu_stop_queue_work(stopper2, work2);
  230. unlock:
  231. raw_spin_unlock(&stopper2->lock);
  232. raw_spin_unlock_irq(&stopper1->lock);
  233. if (unlikely(err == -EDEADLK)) {
  234. while (stop_cpus_in_progress)
  235. cpu_relax();
  236. goto retry;
  237. }
  238. return err;
  239. }
  240. /**
  241. * stop_two_cpus - stops two cpus
  242. * @cpu1: the cpu to stop
  243. * @cpu2: the other cpu to stop
  244. * @fn: function to execute
  245. * @arg: argument to @fn
  246. *
  247. * Stops both the current and specified CPU and runs @fn on one of them.
  248. *
  249. * returns when both are completed.
  250. */
  251. int stop_two_cpus(unsigned int cpu1, unsigned int cpu2, cpu_stop_fn_t fn, void *arg)
  252. {
  253. struct cpu_stop_done done;
  254. struct cpu_stop_work work1, work2;
  255. struct multi_stop_data msdata;
  256. msdata = (struct multi_stop_data){
  257. .fn = fn,
  258. .data = arg,
  259. .num_threads = 2,
  260. .active_cpus = cpumask_of(cpu1),
  261. };
  262. work1 = work2 = (struct cpu_stop_work){
  263. .fn = multi_cpu_stop,
  264. .arg = &msdata,
  265. .done = &done
  266. };
  267. cpu_stop_init_done(&done, 2);
  268. set_state(&msdata, MULTI_STOP_PREPARE);
  269. if (cpu1 > cpu2)
  270. swap(cpu1, cpu2);
  271. if (cpu_stop_queue_two_works(cpu1, &work1, cpu2, &work2))
  272. return -ENOENT;
  273. wait_for_completion(&done.completion);
  274. return done.ret;
  275. }
  276. /**
  277. * stop_one_cpu_nowait - stop a cpu but don't wait for completion
  278. * @cpu: cpu to stop
  279. * @fn: function to execute
  280. * @arg: argument to @fn
  281. * @work_buf: pointer to cpu_stop_work structure
  282. *
  283. * Similar to stop_one_cpu() but doesn't wait for completion. The
  284. * caller is responsible for ensuring @work_buf is currently unused
  285. * and will remain untouched until stopper starts executing @fn.
  286. *
  287. * CONTEXT:
  288. * Don't care.
  289. *
  290. * RETURNS:
  291. * true if cpu_stop_work was queued successfully and @fn will be called,
  292. * false otherwise.
  293. */
  294. bool stop_one_cpu_nowait(unsigned int cpu, cpu_stop_fn_t fn, void *arg,
  295. struct cpu_stop_work *work_buf)
  296. {
  297. *work_buf = (struct cpu_stop_work){ .fn = fn, .arg = arg, };
  298. return cpu_stop_queue_work(cpu, work_buf);
  299. }
  300. static bool queue_stop_cpus_work(const struct cpumask *cpumask,
  301. cpu_stop_fn_t fn, void *arg,
  302. struct cpu_stop_done *done)
  303. {
  304. struct cpu_stop_work *work;
  305. unsigned int cpu;
  306. bool queued = false;
  307. /*
  308. * Disable preemption while queueing to avoid getting
  309. * preempted by a stopper which might wait for other stoppers
  310. * to enter @fn which can lead to deadlock.
  311. */
  312. preempt_disable();
  313. stop_cpus_in_progress = true;
  314. for_each_cpu(cpu, cpumask) {
  315. work = &per_cpu(cpu_stopper.stop_work, cpu);
  316. work->fn = fn;
  317. work->arg = arg;
  318. work->done = done;
  319. if (cpu_stop_queue_work(cpu, work))
  320. queued = true;
  321. }
  322. stop_cpus_in_progress = false;
  323. preempt_enable();
  324. return queued;
  325. }
  326. static int __stop_cpus(const struct cpumask *cpumask,
  327. cpu_stop_fn_t fn, void *arg)
  328. {
  329. struct cpu_stop_done done;
  330. cpu_stop_init_done(&done, cpumask_weight(cpumask));
  331. if (!queue_stop_cpus_work(cpumask, fn, arg, &done))
  332. return -ENOENT;
  333. wait_for_completion(&done.completion);
  334. return done.ret;
  335. }
  336. /**
  337. * stop_cpus - stop multiple cpus
  338. * @cpumask: cpus to stop
  339. * @fn: function to execute
  340. * @arg: argument to @fn
  341. *
  342. * Execute @fn(@arg) on online cpus in @cpumask. On each target cpu,
  343. * @fn is run in a process context with the highest priority
  344. * preempting any task on the cpu and monopolizing it. This function
  345. * returns after all executions are complete.
  346. *
  347. * This function doesn't guarantee the cpus in @cpumask stay online
  348. * till @fn completes. If some cpus go down in the middle, execution
  349. * on the cpu may happen partially or fully on different cpus. @fn
  350. * should either be ready for that or the caller should ensure that
  351. * the cpus stay online until this function completes.
  352. *
  353. * All stop_cpus() calls are serialized making it safe for @fn to wait
  354. * for all cpus to start executing it.
  355. *
  356. * CONTEXT:
  357. * Might sleep.
  358. *
  359. * RETURNS:
  360. * -ENOENT if @fn(@arg) was not executed at all because all cpus in
  361. * @cpumask were offline; otherwise, 0 if all executions of @fn
  362. * returned 0, any non zero return value if any returned non zero.
  363. */
  364. int stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg)
  365. {
  366. int ret;
  367. /* static works are used, process one request at a time */
  368. mutex_lock(&stop_cpus_mutex);
  369. ret = __stop_cpus(cpumask, fn, arg);
  370. mutex_unlock(&stop_cpus_mutex);
  371. return ret;
  372. }
  373. /**
  374. * try_stop_cpus - try to stop multiple cpus
  375. * @cpumask: cpus to stop
  376. * @fn: function to execute
  377. * @arg: argument to @fn
  378. *
  379. * Identical to stop_cpus() except that it fails with -EAGAIN if
  380. * someone else is already using the facility.
  381. *
  382. * CONTEXT:
  383. * Might sleep.
  384. *
  385. * RETURNS:
  386. * -EAGAIN if someone else is already stopping cpus, -ENOENT if
  387. * @fn(@arg) was not executed at all because all cpus in @cpumask were
  388. * offline; otherwise, 0 if all executions of @fn returned 0, any non
  389. * zero return value if any returned non zero.
  390. */
  391. int try_stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg)
  392. {
  393. int ret;
  394. /* static works are used, process one request at a time */
  395. if (!mutex_trylock(&stop_cpus_mutex))
  396. return -EAGAIN;
  397. ret = __stop_cpus(cpumask, fn, arg);
  398. mutex_unlock(&stop_cpus_mutex);
  399. return ret;
  400. }
  401. static int cpu_stop_should_run(unsigned int cpu)
  402. {
  403. struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
  404. unsigned long flags;
  405. int run;
  406. raw_spin_lock_irqsave(&stopper->lock, flags);
  407. run = !list_empty(&stopper->works);
  408. raw_spin_unlock_irqrestore(&stopper->lock, flags);
  409. return run;
  410. }
  411. static void cpu_stopper_thread(unsigned int cpu)
  412. {
  413. struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
  414. struct cpu_stop_work *work;
  415. repeat:
  416. work = NULL;
  417. raw_spin_lock_irq(&stopper->lock);
  418. if (!list_empty(&stopper->works)) {
  419. work = list_first_entry(&stopper->works,
  420. struct cpu_stop_work, list);
  421. list_del_init(&work->list);
  422. }
  423. raw_spin_unlock_irq(&stopper->lock);
  424. if (work) {
  425. cpu_stop_fn_t fn = work->fn;
  426. void *arg = work->arg;
  427. struct cpu_stop_done *done = work->done;
  428. int ret;
  429. /* cpu stop callbacks must not sleep, make in_atomic() == T */
  430. preempt_count_inc();
  431. ret = fn(arg);
  432. if (done) {
  433. if (ret)
  434. done->ret = ret;
  435. cpu_stop_signal_done(done);
  436. }
  437. preempt_count_dec();
  438. WARN_ONCE(preempt_count(),
  439. "cpu_stop: %pf(%p) leaked preempt count\n", fn, arg);
  440. goto repeat;
  441. }
  442. }
  443. void stop_machine_park(int cpu)
  444. {
  445. struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
  446. /*
  447. * Lockless. cpu_stopper_thread() will take stopper->lock and flush
  448. * the pending works before it parks, until then it is fine to queue
  449. * the new works.
  450. */
  451. stopper->enabled = false;
  452. kthread_park(stopper->thread);
  453. }
  454. extern void sched_set_stop_task(int cpu, struct task_struct *stop);
  455. static void cpu_stop_create(unsigned int cpu)
  456. {
  457. sched_set_stop_task(cpu, per_cpu(cpu_stopper.thread, cpu));
  458. }
  459. static void cpu_stop_park(unsigned int cpu)
  460. {
  461. struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
  462. WARN_ON(!list_empty(&stopper->works));
  463. }
  464. void stop_machine_unpark(int cpu)
  465. {
  466. struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
  467. stopper->enabled = true;
  468. kthread_unpark(stopper->thread);
  469. }
  470. static struct smp_hotplug_thread cpu_stop_threads = {
  471. .store = &cpu_stopper.thread,
  472. .thread_should_run = cpu_stop_should_run,
  473. .thread_fn = cpu_stopper_thread,
  474. .thread_comm = "migration/%u",
  475. .create = cpu_stop_create,
  476. .park = cpu_stop_park,
  477. .selfparking = true,
  478. };
  479. static int __init cpu_stop_init(void)
  480. {
  481. unsigned int cpu;
  482. for_each_possible_cpu(cpu) {
  483. struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
  484. raw_spin_lock_init(&stopper->lock);
  485. INIT_LIST_HEAD(&stopper->works);
  486. }
  487. BUG_ON(smpboot_register_percpu_thread(&cpu_stop_threads));
  488. stop_machine_unpark(raw_smp_processor_id());
  489. stop_machine_initialized = true;
  490. return 0;
  491. }
  492. early_initcall(cpu_stop_init);
  493. static int __stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus)
  494. {
  495. struct multi_stop_data msdata = {
  496. .fn = fn,
  497. .data = data,
  498. .num_threads = num_online_cpus(),
  499. .active_cpus = cpus,
  500. };
  501. if (!stop_machine_initialized) {
  502. /*
  503. * Handle the case where stop_machine() is called
  504. * early in boot before stop_machine() has been
  505. * initialized.
  506. */
  507. unsigned long flags;
  508. int ret;
  509. WARN_ON_ONCE(msdata.num_threads != 1);
  510. local_irq_save(flags);
  511. hard_irq_disable();
  512. ret = (*fn)(data);
  513. local_irq_restore(flags);
  514. return ret;
  515. }
  516. /* Set the initial state and stop all online cpus. */
  517. set_state(&msdata, MULTI_STOP_PREPARE);
  518. return stop_cpus(cpu_online_mask, multi_cpu_stop, &msdata);
  519. }
  520. int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus)
  521. {
  522. int ret;
  523. /* No CPUs can come up or down during this. */
  524. get_online_cpus();
  525. ret = __stop_machine(fn, data, cpus);
  526. put_online_cpus();
  527. return ret;
  528. }
  529. EXPORT_SYMBOL_GPL(stop_machine);
  530. /**
  531. * stop_machine_from_inactive_cpu - stop_machine() from inactive CPU
  532. * @fn: the function to run
  533. * @data: the data ptr for the @fn()
  534. * @cpus: the cpus to run the @fn() on (NULL = any online cpu)
  535. *
  536. * This is identical to stop_machine() but can be called from a CPU which
  537. * is not active. The local CPU is in the process of hotplug (so no other
  538. * CPU hotplug can start) and not marked active and doesn't have enough
  539. * context to sleep.
  540. *
  541. * This function provides stop_machine() functionality for such state by
  542. * using busy-wait for synchronization and executing @fn directly for local
  543. * CPU.
  544. *
  545. * CONTEXT:
  546. * Local CPU is inactive. Temporarily stops all active CPUs.
  547. *
  548. * RETURNS:
  549. * 0 if all executions of @fn returned 0, any non zero return value if any
  550. * returned non zero.
  551. */
  552. int stop_machine_from_inactive_cpu(cpu_stop_fn_t fn, void *data,
  553. const struct cpumask *cpus)
  554. {
  555. struct multi_stop_data msdata = { .fn = fn, .data = data,
  556. .active_cpus = cpus };
  557. struct cpu_stop_done done;
  558. int ret;
  559. /* Local CPU must be inactive and CPU hotplug in progress. */
  560. BUG_ON(cpu_active(raw_smp_processor_id()));
  561. msdata.num_threads = num_active_cpus() + 1; /* +1 for local */
  562. /* No proper task established and can't sleep - busy wait for lock. */
  563. while (!mutex_trylock(&stop_cpus_mutex))
  564. cpu_relax();
  565. /* Schedule work on other CPUs and execute directly for local CPU */
  566. set_state(&msdata, MULTI_STOP_PREPARE);
  567. cpu_stop_init_done(&done, num_active_cpus());
  568. queue_stop_cpus_work(cpu_active_mask, multi_cpu_stop, &msdata,
  569. &done);
  570. ret = multi_cpu_stop(&msdata);
  571. /* Busy wait for completion. */
  572. while (!completion_done(&done.completion))
  573. cpu_relax();
  574. mutex_unlock(&stop_cpus_mutex);
  575. return ret ?: done.ret;
  576. }