2 * (C) 2001, 2002, 2003, 2004 Rusty Russell
4 * This code is licenced under the GPL.
6 #include <linux/sched/mm.h>
7 #include <linux/proc_fs.h>
9 #include <linux/init.h>
10 #include <linux/notifier.h>
11 #include <linux/sched/signal.h>
12 #include <linux/sched/hotplug.h>
13 #include <linux/sched/isolation.h>
14 #include <linux/sched/task.h>
15 #include <linux/sched/smt.h>
16 #include <linux/unistd.h>
17 #include <linux/cpu.h>
18 #include <linux/oom.h>
19 #include <linux/rcupdate.h>
20 #include <linux/export.h>
21 #include <linux/bug.h>
22 #include <linux/kthread.h>
23 #include <linux/stop_machine.h>
24 #include <linux/mutex.h>
25 #include <linux/gfp.h>
26 #include <linux/suspend.h>
27 #include <linux/lockdep.h>
28 #include <linux/tick.h>
29 #include <linux/irq.h>
30 #include <linux/nmi.h>
31 #include <linux/smpboot.h>
32 #include <linux/relay.h>
33 #include <linux/slab.h>
34 #include <linux/scs.h>
35 #include <linux/percpu-rwsem.h>
36 #include <linux/cpuset.h>
37 #include <linux/random.h>
39 #include <trace/events/power.h>
40 #define CREATE_TRACE_POINTS
41 #include <trace/events/cpuhp.h>
46 * cpuhp_cpu_state - Per cpu hotplug state storage
47 * @state: The current cpu state
48 * @target: The target state
49 * @thread: Pointer to the hotplug thread
50 * @should_run: Thread should execute
51 * @rollback: Perform a rollback
52 * @single: Single callback invocation
53 * @bringup: Single callback bringup or teardown selector
54 * @cb_state: The state for a single callback (install/uninstall)
55 * @result: Result of the operation
56 * @done_up: Signal completion to the issuer of the task for cpu-up
57 * @done_down: Signal completion to the issuer of the task for cpu-down
59 struct cpuhp_cpu_state {
60 enum cpuhp_state state;
61 enum cpuhp_state target;
62 enum cpuhp_state fail;
64 struct task_struct *thread;
69 struct hlist_node *node;
70 struct hlist_node *last;
71 enum cpuhp_state cb_state;
73 struct completion done_up;
74 struct completion done_down;
78 static DEFINE_PER_CPU(struct cpuhp_cpu_state, cpuhp_state) = {
79 .fail = CPUHP_INVALID,
83 cpumask_t cpus_booted_once_mask;
86 #if defined(CONFIG_LOCKDEP) && defined(CONFIG_SMP)
87 static struct lockdep_map cpuhp_state_up_map =
88 STATIC_LOCKDEP_MAP_INIT("cpuhp_state-up", &cpuhp_state_up_map);
89 static struct lockdep_map cpuhp_state_down_map =
90 STATIC_LOCKDEP_MAP_INIT("cpuhp_state-down", &cpuhp_state_down_map);
93 static inline void cpuhp_lock_acquire(bool bringup)
95 lock_map_acquire(bringup ? &cpuhp_state_up_map : &cpuhp_state_down_map);
98 static inline void cpuhp_lock_release(bool bringup)
100 lock_map_release(bringup ? &cpuhp_state_up_map : &cpuhp_state_down_map);
104 static inline void cpuhp_lock_acquire(bool bringup) { }
105 static inline void cpuhp_lock_release(bool bringup) { }
110 * cpuhp_step - Hotplug state machine step
111 * @name: Name of the step
112 * @startup: Startup function of the step
113 * @teardown: Teardown function of the step
114 * @cant_stop: Bringup/teardown can't be stopped at this step
119 int (*single)(unsigned int cpu);
120 int (*multi)(unsigned int cpu,
121 struct hlist_node *node);
124 int (*single)(unsigned int cpu);
125 int (*multi)(unsigned int cpu,
126 struct hlist_node *node);
128 struct hlist_head list;
133 static DEFINE_MUTEX(cpuhp_state_mutex);
134 static struct cpuhp_step cpuhp_hp_states[];
136 static struct cpuhp_step *cpuhp_get_step(enum cpuhp_state state)
138 return cpuhp_hp_states + state;
142 * cpuhp_invoke_callback _ Invoke the callbacks for a given state
143 * @cpu: The cpu for which the callback should be invoked
144 * @state: The state to do callbacks for
145 * @bringup: True if the bringup callback should be invoked
146 * @node: For multi-instance, do a single entry callback for install/remove
147 * @lastp: For multi-instance rollback, remember how far we got
149 * Called from cpu hotplug and from the state register machinery.
151 static int cpuhp_invoke_callback(unsigned int cpu, enum cpuhp_state state,
152 bool bringup, struct hlist_node *node,
153 struct hlist_node **lastp)
155 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
156 struct cpuhp_step *step = cpuhp_get_step(state);
157 int (*cbm)(unsigned int cpu, struct hlist_node *node);
158 int (*cb)(unsigned int cpu);
161 if (st->fail == state) {
162 st->fail = CPUHP_INVALID;
164 if (!(bringup ? step->startup.single : step->teardown.single))
170 if (!step->multi_instance) {
171 WARN_ON_ONCE(lastp && *lastp);
172 cb = bringup ? step->startup.single : step->teardown.single;
175 trace_cpuhp_enter(cpu, st->target, state, cb);
177 trace_cpuhp_exit(cpu, st->state, state, ret);
180 cbm = bringup ? step->startup.multi : step->teardown.multi;
184 /* Single invocation for instance add/remove */
186 WARN_ON_ONCE(lastp && *lastp);
187 trace_cpuhp_multi_enter(cpu, st->target, state, cbm, node);
188 ret = cbm(cpu, node);
189 trace_cpuhp_exit(cpu, st->state, state, ret);
193 /* State transition. Invoke on all instances */
195 hlist_for_each(node, &step->list) {
196 if (lastp && node == *lastp)
199 trace_cpuhp_multi_enter(cpu, st->target, state, cbm, node);
200 ret = cbm(cpu, node);
201 trace_cpuhp_exit(cpu, st->state, state, ret);
215 /* Rollback the instances if one failed */
216 cbm = !bringup ? step->startup.multi : step->teardown.multi;
220 hlist_for_each(node, &step->list) {
224 trace_cpuhp_multi_enter(cpu, st->target, state, cbm, node);
225 ret = cbm(cpu, node);
226 trace_cpuhp_exit(cpu, st->state, state, ret);
228 * Rollback must not fail,
236 static bool cpuhp_is_ap_state(enum cpuhp_state state)
239 * The extra check for CPUHP_TEARDOWN_CPU is only for documentation
240 * purposes as that state is handled explicitly in cpu_down.
242 return state > CPUHP_BRINGUP_CPU && state != CPUHP_TEARDOWN_CPU;
245 static inline void wait_for_ap_thread(struct cpuhp_cpu_state *st, bool bringup)
247 struct completion *done = bringup ? &st->done_up : &st->done_down;
248 wait_for_completion(done);
251 static inline void complete_ap_thread(struct cpuhp_cpu_state *st, bool bringup)
253 struct completion *done = bringup ? &st->done_up : &st->done_down;
258 * The former STARTING/DYING states, ran with IRQs disabled and must not fail.
260 static bool cpuhp_is_atomic_state(enum cpuhp_state state)
262 return CPUHP_AP_IDLE_DEAD <= state && state < CPUHP_AP_ONLINE;
265 /* Serializes the updates to cpu_online_mask, cpu_present_mask */
266 static DEFINE_MUTEX(cpu_add_remove_lock);
267 bool cpuhp_tasks_frozen;
268 EXPORT_SYMBOL_GPL(cpuhp_tasks_frozen);
271 * The following two APIs (cpu_maps_update_begin/done) must be used when
272 * attempting to serialize the updates to cpu_online_mask & cpu_present_mask.
274 void cpu_maps_update_begin(void)
276 mutex_lock(&cpu_add_remove_lock);
279 void cpu_maps_update_done(void)
281 mutex_unlock(&cpu_add_remove_lock);
285 * If set, cpu_up and cpu_down will return -EBUSY and do nothing.
286 * Should always be manipulated under cpu_add_remove_lock
288 static int cpu_hotplug_disabled;
290 #ifdef CONFIG_HOTPLUG_CPU
292 DEFINE_STATIC_PERCPU_RWSEM(cpu_hotplug_lock);
294 void cpus_read_lock(void)
296 percpu_down_read(&cpu_hotplug_lock);
298 EXPORT_SYMBOL_GPL(cpus_read_lock);
300 int cpus_read_trylock(void)
302 return percpu_down_read_trylock(&cpu_hotplug_lock);
304 EXPORT_SYMBOL_GPL(cpus_read_trylock);
306 void cpus_read_unlock(void)
308 percpu_up_read(&cpu_hotplug_lock);
310 EXPORT_SYMBOL_GPL(cpus_read_unlock);
312 void cpus_write_lock(void)
314 percpu_down_write(&cpu_hotplug_lock);
317 void cpus_write_unlock(void)
319 percpu_up_write(&cpu_hotplug_lock);
322 void lockdep_assert_cpus_held(void)
325 * We can't have hotplug operations before userspace starts running,
326 * and some init codepaths will knowingly not take the hotplug lock.
327 * This is all valid, so mute lockdep until it makes sense to report
330 if (system_state < SYSTEM_RUNNING)
333 percpu_rwsem_assert_held(&cpu_hotplug_lock);
336 static void lockdep_acquire_cpus_lock(void)
338 rwsem_acquire(&cpu_hotplug_lock.dep_map, 0, 0, _THIS_IP_);
341 static void lockdep_release_cpus_lock(void)
343 rwsem_release(&cpu_hotplug_lock.dep_map, _THIS_IP_);
347 * Wait for currently running CPU hotplug operations to complete (if any) and
348 * disable future CPU hotplug (from sysfs). The 'cpu_add_remove_lock' protects
349 * the 'cpu_hotplug_disabled' flag. The same lock is also acquired by the
350 * hotplug path before performing hotplug operations. So acquiring that lock
351 * guarantees mutual exclusion from any currently running hotplug operations.
353 void cpu_hotplug_disable(void)
355 cpu_maps_update_begin();
356 cpu_hotplug_disabled++;
357 cpu_maps_update_done();
359 EXPORT_SYMBOL_GPL(cpu_hotplug_disable);
361 static void __cpu_hotplug_enable(void)
363 if (WARN_ONCE(!cpu_hotplug_disabled, "Unbalanced cpu hotplug enable\n"))
365 cpu_hotplug_disabled--;
368 void cpu_hotplug_enable(void)
370 cpu_maps_update_begin();
371 __cpu_hotplug_enable();
372 cpu_maps_update_done();
374 EXPORT_SYMBOL_GPL(cpu_hotplug_enable);
378 static void lockdep_acquire_cpus_lock(void)
382 static void lockdep_release_cpus_lock(void)
386 #endif /* CONFIG_HOTPLUG_CPU */
389 * Architectures that need SMT-specific errata handling during SMT hotplug
390 * should override this.
392 void __weak arch_smt_update(void) { }
394 #ifdef CONFIG_HOTPLUG_SMT
395 enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED;
397 void __init cpu_smt_disable(bool force)
399 if (!cpu_smt_possible())
403 pr_info("SMT: Force disabled\n");
404 cpu_smt_control = CPU_SMT_FORCE_DISABLED;
406 pr_info("SMT: disabled\n");
407 cpu_smt_control = CPU_SMT_DISABLED;
412 * The decision whether SMT is supported can only be done after the full
413 * CPU identification. Called from architecture code.
415 void __init cpu_smt_check_topology(void)
417 if (!topology_smt_supported())
418 cpu_smt_control = CPU_SMT_NOT_SUPPORTED;
421 static int __init smt_cmdline_disable(char *str)
423 cpu_smt_disable(str && !strcmp(str, "force"));
426 early_param("nosmt", smt_cmdline_disable);
428 static inline bool cpu_smt_allowed(unsigned int cpu)
430 if (cpu_smt_control == CPU_SMT_ENABLED)
433 if (topology_is_primary_thread(cpu))
437 * On x86 it's required to boot all logical CPUs at least once so
438 * that the init code can get a chance to set CR4.MCE on each
439 * CPU. Otherwise, a broadcasted MCE observing CR4.MCE=0b on any
440 * core will shutdown the machine.
442 return !cpumask_test_cpu(cpu, &cpus_booted_once_mask);
445 /* Returns true if SMT is not supported of forcefully (irreversibly) disabled */
446 bool cpu_smt_possible(void)
448 return cpu_smt_control != CPU_SMT_FORCE_DISABLED &&
449 cpu_smt_control != CPU_SMT_NOT_SUPPORTED;
451 EXPORT_SYMBOL_GPL(cpu_smt_possible);
453 static inline bool cpu_smt_allowed(unsigned int cpu) { return true; }
456 static inline enum cpuhp_state
457 cpuhp_set_state(struct cpuhp_cpu_state *st, enum cpuhp_state target)
459 enum cpuhp_state prev_state = st->state;
461 st->rollback = false;
466 st->bringup = st->state < target;
472 cpuhp_reset_state(struct cpuhp_cpu_state *st, enum cpuhp_state prev_state)
477 * If we have st->last we need to undo partial multi_instance of this
478 * state first. Otherwise start undo at the previous state.
487 st->target = prev_state;
488 st->bringup = !st->bringup;
491 /* Regular hotplug invocation of the AP hotplug thread */
492 static void __cpuhp_kick_ap(struct cpuhp_cpu_state *st)
494 if (!st->single && st->state == st->target)
499 * Make sure the above stores are visible before should_run becomes
500 * true. Paired with the mb() above in cpuhp_thread_fun()
503 st->should_run = true;
504 wake_up_process(st->thread);
505 wait_for_ap_thread(st, st->bringup);
508 static int cpuhp_kick_ap(struct cpuhp_cpu_state *st, enum cpuhp_state target)
510 enum cpuhp_state prev_state;
513 prev_state = cpuhp_set_state(st, target);
515 if ((ret = st->result)) {
516 cpuhp_reset_state(st, prev_state);
523 static int bringup_wait_for_ap(unsigned int cpu)
525 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
527 /* Wait for the CPU to reach CPUHP_AP_ONLINE_IDLE */
528 wait_for_ap_thread(st, true);
529 if (WARN_ON_ONCE((!cpu_online(cpu))))
532 /* Unpark the hotplug thread of the target cpu */
533 kthread_unpark(st->thread);
536 * SMT soft disabling on X86 requires to bring the CPU out of the
537 * BIOS 'wait for SIPI' state in order to set the CR4.MCE bit. The
538 * CPU marked itself as booted_once in notify_cpu_starting() so the
539 * cpu_smt_allowed() check will now return false if this is not the
542 if (!cpu_smt_allowed(cpu))
545 if (st->target <= CPUHP_AP_ONLINE_IDLE)
548 return cpuhp_kick_ap(st, st->target);
551 static int bringup_cpu(unsigned int cpu)
553 struct task_struct *idle = idle_thread_get(cpu);
557 * Reset stale stack state from the last time this CPU was online.
559 scs_task_reset(idle);
560 kasan_unpoison_task_stack(idle);
563 * Some architectures have to walk the irq descriptors to
564 * setup the vector space for the cpu which comes online.
565 * Prevent irq alloc/free across the bringup.
569 /* Arch-specific enabling code. */
570 ret = __cpu_up(cpu, idle);
574 return bringup_wait_for_ap(cpu);
577 static int finish_cpu(unsigned int cpu)
579 struct task_struct *idle = idle_thread_get(cpu);
580 struct mm_struct *mm = idle->active_mm;
583 * idle_task_exit() will have switched to &init_mm, now
584 * clean up any remaining active_mm state.
587 idle->active_mm = &init_mm;
593 * Hotplug state machine related functions
596 static void undo_cpu_up(unsigned int cpu, struct cpuhp_cpu_state *st)
598 for (st->state--; st->state > st->target; st->state--)
599 cpuhp_invoke_callback(cpu, st->state, false, NULL, NULL);
602 static inline bool can_rollback_cpu(struct cpuhp_cpu_state *st)
604 if (IS_ENABLED(CONFIG_HOTPLUG_CPU))
607 * When CPU hotplug is disabled, then taking the CPU down is not
608 * possible because takedown_cpu() and the architecture and
609 * subsystem specific mechanisms are not available. So the CPU
610 * which would be completely unplugged again needs to stay around
611 * in the current state.
613 return st->state <= CPUHP_BRINGUP_CPU;
616 static int cpuhp_up_callbacks(unsigned int cpu, struct cpuhp_cpu_state *st,
617 enum cpuhp_state target)
619 enum cpuhp_state prev_state = st->state;
622 while (st->state < target) {
624 ret = cpuhp_invoke_callback(cpu, st->state, true, NULL, NULL);
626 if (can_rollback_cpu(st)) {
627 st->target = prev_state;
628 undo_cpu_up(cpu, st);
637 * The cpu hotplug threads manage the bringup and teardown of the cpus
639 static void cpuhp_create(unsigned int cpu)
641 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
643 init_completion(&st->done_up);
644 init_completion(&st->done_down);
647 static int cpuhp_should_run(unsigned int cpu)
649 struct cpuhp_cpu_state *st = this_cpu_ptr(&cpuhp_state);
651 return st->should_run;
655 * Execute teardown/startup callbacks on the plugged cpu. Also used to invoke
656 * callbacks when a state gets [un]installed at runtime.
658 * Each invocation of this function by the smpboot thread does a single AP
661 * It has 3 modes of operation:
662 * - single: runs st->cb_state
663 * - up: runs ++st->state, while st->state < st->target
664 * - down: runs st->state--, while st->state > st->target
666 * When complete or on error, should_run is cleared and the completion is fired.
668 static void cpuhp_thread_fun(unsigned int cpu)
670 struct cpuhp_cpu_state *st = this_cpu_ptr(&cpuhp_state);
671 bool bringup = st->bringup;
672 enum cpuhp_state state;
674 if (WARN_ON_ONCE(!st->should_run))
678 * ACQUIRE for the cpuhp_should_run() load of ->should_run. Ensures
679 * that if we see ->should_run we also see the rest of the state.
684 * The BP holds the hotplug lock, but we're now running on the AP,
685 * ensure that anybody asserting the lock is held, will actually find
688 lockdep_acquire_cpus_lock();
689 cpuhp_lock_acquire(bringup);
692 state = st->cb_state;
693 st->should_run = false;
698 st->should_run = (st->state < st->target);
699 WARN_ON_ONCE(st->state > st->target);
703 st->should_run = (st->state > st->target);
704 WARN_ON_ONCE(st->state < st->target);
708 WARN_ON_ONCE(!cpuhp_is_ap_state(state));
710 if (cpuhp_is_atomic_state(state)) {
712 st->result = cpuhp_invoke_callback(cpu, state, bringup, st->node, &st->last);
716 * STARTING/DYING must not fail!
718 WARN_ON_ONCE(st->result);
720 st->result = cpuhp_invoke_callback(cpu, state, bringup, st->node, &st->last);
725 * If we fail on a rollback, we're up a creek without no
726 * paddle, no way forward, no way back. We loose, thanks for
729 WARN_ON_ONCE(st->rollback);
730 st->should_run = false;
733 cpuhp_lock_release(bringup);
734 lockdep_release_cpus_lock();
737 complete_ap_thread(st, bringup);
740 /* Invoke a single callback on a remote cpu */
742 cpuhp_invoke_ap_callback(int cpu, enum cpuhp_state state, bool bringup,
743 struct hlist_node *node)
745 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
748 if (!cpu_online(cpu))
751 cpuhp_lock_acquire(false);
752 cpuhp_lock_release(false);
754 cpuhp_lock_acquire(true);
755 cpuhp_lock_release(true);
758 * If we are up and running, use the hotplug thread. For early calls
759 * we invoke the thread function directly.
762 return cpuhp_invoke_callback(cpu, state, bringup, node, NULL);
764 st->rollback = false;
768 st->bringup = bringup;
769 st->cb_state = state;
775 * If we failed and did a partial, do a rollback.
777 if ((ret = st->result) && st->last) {
779 st->bringup = !bringup;
785 * Clean up the leftovers so the next hotplug operation wont use stale
788 st->node = st->last = NULL;
792 static int cpuhp_kick_ap_work(unsigned int cpu)
794 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
795 enum cpuhp_state prev_state = st->state;
798 cpuhp_lock_acquire(false);
799 cpuhp_lock_release(false);
801 cpuhp_lock_acquire(true);
802 cpuhp_lock_release(true);
804 trace_cpuhp_enter(cpu, st->target, prev_state, cpuhp_kick_ap_work);
805 ret = cpuhp_kick_ap(st, st->target);
806 trace_cpuhp_exit(cpu, st->state, prev_state, ret);
811 static struct smp_hotplug_thread cpuhp_threads = {
812 .store = &cpuhp_state.thread,
813 .create = &cpuhp_create,
814 .thread_should_run = cpuhp_should_run,
815 .thread_fn = cpuhp_thread_fun,
816 .thread_comm = "cpuhp/%u",
820 void __init cpuhp_threads_init(void)
822 BUG_ON(smpboot_register_percpu_thread(&cpuhp_threads));
823 kthread_unpark(this_cpu_read(cpuhp_state.thread));
828 * Serialize hotplug trainwrecks outside of the cpu_hotplug_lock
831 * The operation is still serialized against concurrent CPU hotplug via
832 * cpu_add_remove_lock, i.e. CPU map protection. But it is _not_
833 * serialized against other hotplug related activity like adding or
834 * removing of state callbacks and state instances, which invoke either the
835 * startup or the teardown callback of the affected state.
837 * This is required for subsystems which are unfixable vs. CPU hotplug and
838 * evade lock inversion problems by scheduling work which has to be
839 * completed _before_ cpu_up()/_cpu_down() returns.
841 * Don't even think about adding anything to this for any new code or even
842 * drivers. It's only purpose is to keep existing lock order trainwrecks
845 * For cpu_down() there might be valid reasons to finish cleanups which are
846 * not required to be done under cpu_hotplug_lock, but that's a different
847 * story and would be not invoked via this.
849 static void cpu_up_down_serialize_trainwrecks(bool tasks_frozen)
852 * cpusets delegate hotplug operations to a worker to "solve" the
853 * lock order problems. Wait for the worker, but only if tasks are
854 * _not_ frozen (suspend, hibernate) as that would wait forever.
856 * The wait is required because otherwise the hotplug operation
857 * returns with inconsistent state, which could even be observed in
858 * user space when a new CPU is brought up. The CPU plug uevent
859 * would be delivered and user space reacting on it would fail to
860 * move tasks to the newly plugged CPU up to the point where the
861 * work has finished because up to that point the newly plugged CPU
862 * is not assignable in cpusets/cgroups. On unplug that's not
863 * necessarily a visible issue, but it is still inconsistent state,
864 * which is the real problem which needs to be "fixed". This can't
865 * prevent the transient state between scheduling the work and
866 * returning from waiting for it.
869 cpuset_wait_for_hotplug();
872 #ifdef CONFIG_HOTPLUG_CPU
873 #ifndef arch_clear_mm_cpumask_cpu
874 #define arch_clear_mm_cpumask_cpu(cpu, mm) cpumask_clear_cpu(cpu, mm_cpumask(mm))
878 * clear_tasks_mm_cpumask - Safely clear tasks' mm_cpumask for a CPU
881 * This function walks all processes, finds a valid mm struct for each one and
882 * then clears a corresponding bit in mm's cpumask. While this all sounds
883 * trivial, there are various non-obvious corner cases, which this function
884 * tries to solve in a safe manner.
886 * Also note that the function uses a somewhat relaxed locking scheme, so it may
887 * be called only for an already offlined CPU.
889 void clear_tasks_mm_cpumask(int cpu)
891 struct task_struct *p;
894 * This function is called after the cpu is taken down and marked
895 * offline, so its not like new tasks will ever get this cpu set in
896 * their mm mask. -- Peter Zijlstra
897 * Thus, we may use rcu_read_lock() here, instead of grabbing
898 * full-fledged tasklist_lock.
900 WARN_ON(cpu_online(cpu));
902 for_each_process(p) {
903 struct task_struct *t;
906 * Main thread might exit, but other threads may still have
907 * a valid mm. Find one.
909 t = find_lock_task_mm(p);
912 arch_clear_mm_cpumask_cpu(cpu, t->mm);
918 /* Take this CPU down. */
919 static int take_cpu_down(void *_param)
921 struct cpuhp_cpu_state *st = this_cpu_ptr(&cpuhp_state);
922 enum cpuhp_state target = max((int)st->target, CPUHP_AP_OFFLINE);
923 int err, cpu = smp_processor_id();
926 /* Ensure this CPU doesn't handle any more interrupts. */
927 err = __cpu_disable();
932 * We get here while we are in CPUHP_TEARDOWN_CPU state and we must not
933 * do this step again.
935 WARN_ON(st->state != CPUHP_TEARDOWN_CPU);
937 /* Invoke the former CPU_DYING callbacks */
938 for (; st->state > target; st->state--) {
939 ret = cpuhp_invoke_callback(cpu, st->state, false, NULL, NULL);
941 * DYING must not fail!
946 /* Give up timekeeping duties */
947 tick_handover_do_timer();
948 /* Remove CPU from timer broadcasting */
949 tick_offline_cpu(cpu);
950 /* Park the stopper thread */
951 stop_machine_park(cpu);
955 static int takedown_cpu(unsigned int cpu)
957 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
960 /* Park the smpboot threads */
961 kthread_park(per_cpu_ptr(&cpuhp_state, cpu)->thread);
964 * Prevent irq alloc/free while the dying cpu reorganizes the
965 * interrupt affinities.
970 * So now all preempt/rcu users must observe !cpu_active().
972 err = stop_machine_cpuslocked(take_cpu_down, NULL, cpumask_of(cpu));
974 /* CPU refused to die */
976 /* Unpark the hotplug thread so we can rollback there */
977 kthread_unpark(per_cpu_ptr(&cpuhp_state, cpu)->thread);
980 BUG_ON(cpu_online(cpu));
983 * The teardown callback for CPUHP_AP_SCHED_STARTING will have removed
984 * all runnable tasks from the CPU, there's only the idle task left now
985 * that the migration thread is done doing the stop_machine thing.
987 * Wait for the stop thread to go away.
989 wait_for_ap_thread(st, false);
990 BUG_ON(st->state != CPUHP_AP_IDLE_DEAD);
992 /* Interrupts are moved away from the dying cpu, reenable alloc/free */
995 hotplug_cpu__broadcast_tick_pull(cpu);
996 /* This actually kills the CPU. */
999 tick_cleanup_dead_cpu(cpu);
1000 rcutree_migrate_callbacks(cpu);
1004 static void cpuhp_complete_idle_dead(void *arg)
1006 struct cpuhp_cpu_state *st = arg;
1008 complete_ap_thread(st, false);
1011 void cpuhp_report_idle_dead(void)
1013 struct cpuhp_cpu_state *st = this_cpu_ptr(&cpuhp_state);
1015 BUG_ON(st->state != CPUHP_AP_OFFLINE);
1016 rcu_report_dead(smp_processor_id());
1017 st->state = CPUHP_AP_IDLE_DEAD;
1019 * We cannot call complete after rcu_report_dead() so we delegate it
1022 smp_call_function_single(cpumask_first(cpu_online_mask),
1023 cpuhp_complete_idle_dead, st, 0);
1026 static void undo_cpu_down(unsigned int cpu, struct cpuhp_cpu_state *st)
1028 for (st->state++; st->state < st->target; st->state++)
1029 cpuhp_invoke_callback(cpu, st->state, true, NULL, NULL);
1032 static int cpuhp_down_callbacks(unsigned int cpu, struct cpuhp_cpu_state *st,
1033 enum cpuhp_state target)
1035 enum cpuhp_state prev_state = st->state;
1038 for (; st->state > target; st->state--) {
1039 ret = cpuhp_invoke_callback(cpu, st->state, false, NULL, NULL);
1041 st->target = prev_state;
1042 if (st->state < prev_state)
1043 undo_cpu_down(cpu, st);
1050 /* Requires cpu_add_remove_lock to be held */
1051 static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
1052 enum cpuhp_state target)
1054 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
1055 int prev_state, ret = 0;
1057 if (num_online_cpus() == 1)
1060 if (!cpu_present(cpu))
1065 cpuhp_tasks_frozen = tasks_frozen;
1067 prev_state = cpuhp_set_state(st, target);
1069 * If the current CPU state is in the range of the AP hotplug thread,
1070 * then we need to kick the thread.
1072 if (st->state > CPUHP_TEARDOWN_CPU) {
1073 st->target = max((int)target, CPUHP_TEARDOWN_CPU);
1074 ret = cpuhp_kick_ap_work(cpu);
1076 * The AP side has done the error rollback already. Just
1077 * return the error code..
1083 * We might have stopped still in the range of the AP hotplug
1084 * thread. Nothing to do anymore.
1086 if (st->state > CPUHP_TEARDOWN_CPU)
1089 st->target = target;
1092 * The AP brought itself down to CPUHP_TEARDOWN_CPU. So we need
1093 * to do the further cleanups.
1095 ret = cpuhp_down_callbacks(cpu, st, target);
1096 if (ret && st->state == CPUHP_TEARDOWN_CPU && st->state < prev_state) {
1097 cpuhp_reset_state(st, prev_state);
1098 __cpuhp_kick_ap(st);
1102 cpus_write_unlock();
1104 * Do post unplug cleanup. This is still protected against
1105 * concurrent CPU hotplug via cpu_add_remove_lock.
1107 lockup_detector_cleanup();
1109 cpu_up_down_serialize_trainwrecks(tasks_frozen);
1113 static int cpu_down_maps_locked(unsigned int cpu, enum cpuhp_state target)
1115 if (cpu_hotplug_disabled)
1117 return _cpu_down(cpu, 0, target);
1120 static int cpu_down(unsigned int cpu, enum cpuhp_state target)
1124 cpu_maps_update_begin();
1125 err = cpu_down_maps_locked(cpu, target);
1126 cpu_maps_update_done();
1131 * cpu_device_down - Bring down a cpu device
1132 * @dev: Pointer to the cpu device to offline
1134 * This function is meant to be used by device core cpu subsystem only.
1136 * Other subsystems should use remove_cpu() instead.
1138 int cpu_device_down(struct device *dev)
1140 return cpu_down(dev->id, CPUHP_OFFLINE);
1143 int remove_cpu(unsigned int cpu)
1147 lock_device_hotplug();
1148 ret = device_offline(get_cpu_device(cpu));
1149 unlock_device_hotplug();
1153 EXPORT_SYMBOL_GPL(remove_cpu);
1155 void smp_shutdown_nonboot_cpus(unsigned int primary_cpu)
1160 cpu_maps_update_begin();
1163 * Make certain the cpu I'm about to reboot on is online.
1165 * This is inline to what migrate_to_reboot_cpu() already do.
1167 if (!cpu_online(primary_cpu))
1168 primary_cpu = cpumask_first(cpu_online_mask);
1170 for_each_online_cpu(cpu) {
1171 if (cpu == primary_cpu)
1174 error = cpu_down_maps_locked(cpu, CPUHP_OFFLINE);
1176 pr_err("Failed to offline CPU%d - error=%d",
1183 * Ensure all but the reboot CPU are offline.
1185 BUG_ON(num_online_cpus() > 1);
1188 * Make sure the CPUs won't be enabled by someone else after this
1189 * point. Kexec will reboot to a new kernel shortly resetting
1190 * everything along the way.
1192 cpu_hotplug_disabled++;
1194 cpu_maps_update_done();
1198 #define takedown_cpu NULL
1199 #endif /*CONFIG_HOTPLUG_CPU*/
1202 * notify_cpu_starting(cpu) - Invoke the callbacks on the starting CPU
1203 * @cpu: cpu that just started
1205 * It must be called by the arch code on the new cpu, before the new cpu
1206 * enables interrupts and before the "boot" cpu returns from __cpu_up().
1208 void notify_cpu_starting(unsigned int cpu)
1210 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
1211 enum cpuhp_state target = min((int)st->target, CPUHP_AP_ONLINE);
1214 rcu_cpu_starting(cpu); /* Enables RCU usage on this CPU. */
1215 cpumask_set_cpu(cpu, &cpus_booted_once_mask);
1216 while (st->state < target) {
1218 ret = cpuhp_invoke_callback(cpu, st->state, true, NULL, NULL);
1220 * STARTING must not fail!
1227 * Called from the idle task. Wake up the controlling task which brings the
1228 * hotplug thread of the upcoming CPU up and then delegates the rest of the
1229 * online bringup to the hotplug thread.
1231 void cpuhp_online_idle(enum cpuhp_state state)
1233 struct cpuhp_cpu_state *st = this_cpu_ptr(&cpuhp_state);
1235 /* Happens for the boot cpu */
1236 if (state != CPUHP_AP_ONLINE_IDLE)
1240 * Unpart the stopper thread before we start the idle loop (and start
1241 * scheduling); this ensures the stopper task is always available.
1243 stop_machine_unpark(smp_processor_id());
1245 st->state = CPUHP_AP_ONLINE_IDLE;
1246 complete_ap_thread(st, true);
1249 /* Requires cpu_add_remove_lock to be held */
1250 static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target)
1252 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
1253 struct task_struct *idle;
1258 if (!cpu_present(cpu)) {
1264 * The caller of cpu_up() might have raced with another
1265 * caller. Nothing to do.
1267 if (st->state >= target)
1270 if (st->state == CPUHP_OFFLINE) {
1271 /* Let it fail before we try to bring the cpu up */
1272 idle = idle_thread_get(cpu);
1274 ret = PTR_ERR(idle);
1279 cpuhp_tasks_frozen = tasks_frozen;
1281 cpuhp_set_state(st, target);
1283 * If the current CPU state is in the range of the AP hotplug thread,
1284 * then we need to kick the thread once more.
1286 if (st->state > CPUHP_BRINGUP_CPU) {
1287 ret = cpuhp_kick_ap_work(cpu);
1289 * The AP side has done the error rollback already. Just
1290 * return the error code..
1297 * Try to reach the target state. We max out on the BP at
1298 * CPUHP_BRINGUP_CPU. After that the AP hotplug thread is
1299 * responsible for bringing it up to the target state.
1301 target = min((int)target, CPUHP_BRINGUP_CPU);
1302 ret = cpuhp_up_callbacks(cpu, st, target);
1304 cpus_write_unlock();
1306 cpu_up_down_serialize_trainwrecks(tasks_frozen);
1310 static int cpu_up(unsigned int cpu, enum cpuhp_state target)
1314 if (!cpu_possible(cpu)) {
1315 pr_err("can't online cpu %d because it is not configured as may-hotadd at boot time\n",
1317 #if defined(CONFIG_IA64)
1318 pr_err("please check additional_cpus= boot parameter\n");
1323 err = try_online_node(cpu_to_node(cpu));
1327 cpu_maps_update_begin();
1329 if (cpu_hotplug_disabled) {
1333 if (!cpu_smt_allowed(cpu)) {
1338 err = _cpu_up(cpu, 0, target);
1340 cpu_maps_update_done();
1345 * cpu_device_up - Bring up a cpu device
1346 * @dev: Pointer to the cpu device to online
1348 * This function is meant to be used by device core cpu subsystem only.
1350 * Other subsystems should use add_cpu() instead.
1352 int cpu_device_up(struct device *dev)
1354 return cpu_up(dev->id, CPUHP_ONLINE);
1357 int add_cpu(unsigned int cpu)
1361 lock_device_hotplug();
1362 ret = device_online(get_cpu_device(cpu));
1363 unlock_device_hotplug();
1367 EXPORT_SYMBOL_GPL(add_cpu);
1370 * bringup_hibernate_cpu - Bring up the CPU that we hibernated on
1371 * @sleep_cpu: The cpu we hibernated on and should be brought up.
1373 * On some architectures like arm64, we can hibernate on any CPU, but on
1374 * wake up the CPU we hibernated on might be offline as a side effect of
1375 * using maxcpus= for example.
1377 int bringup_hibernate_cpu(unsigned int sleep_cpu)
1381 if (!cpu_online(sleep_cpu)) {
1382 pr_info("Hibernated on a CPU that is offline! Bringing CPU up.\n");
1383 ret = cpu_up(sleep_cpu, CPUHP_ONLINE);
1385 pr_err("Failed to bring hibernate-CPU up!\n");
1392 void bringup_nonboot_cpus(unsigned int setup_max_cpus)
1396 for_each_present_cpu(cpu) {
1397 if (num_online_cpus() >= setup_max_cpus)
1399 if (!cpu_online(cpu))
1400 cpu_up(cpu, CPUHP_ONLINE);
1404 #ifdef CONFIG_PM_SLEEP_SMP
1405 static cpumask_var_t frozen_cpus;
1407 int freeze_secondary_cpus(int primary)
1411 cpu_maps_update_begin();
1412 if (primary == -1) {
1413 primary = cpumask_first(cpu_online_mask);
1414 if (!housekeeping_cpu(primary, HK_FLAG_TIMER))
1415 primary = housekeeping_any_cpu(HK_FLAG_TIMER);
1417 if (!cpu_online(primary))
1418 primary = cpumask_first(cpu_online_mask);
1422 * We take down all of the non-boot CPUs in one shot to avoid races
1423 * with the userspace trying to use the CPU hotplug at the same time
1425 cpumask_clear(frozen_cpus);
1427 pr_info("Disabling non-boot CPUs ...\n");
1428 for_each_online_cpu(cpu) {
1432 if (pm_wakeup_pending()) {
1433 pr_info("Wakeup pending. Abort CPU freeze\n");
1438 trace_suspend_resume(TPS("CPU_OFF"), cpu, true);
1439 error = _cpu_down(cpu, 1, CPUHP_OFFLINE);
1440 trace_suspend_resume(TPS("CPU_OFF"), cpu, false);
1442 cpumask_set_cpu(cpu, frozen_cpus);
1444 pr_err("Error taking CPU%d down: %d\n", cpu, error);
1450 BUG_ON(num_online_cpus() > 1);
1452 pr_err("Non-boot CPUs are not disabled\n");
1455 * Make sure the CPUs won't be enabled by someone else. We need to do
1456 * this even in case of failure as all freeze_secondary_cpus() users are
1457 * supposed to do thaw_secondary_cpus() on the failure path.
1459 cpu_hotplug_disabled++;
1461 cpu_maps_update_done();
1465 void __weak arch_thaw_secondary_cpus_begin(void)
1469 void __weak arch_thaw_secondary_cpus_end(void)
1473 void thaw_secondary_cpus(void)
1477 /* Allow everyone to use the CPU hotplug again */
1478 cpu_maps_update_begin();
1479 __cpu_hotplug_enable();
1480 if (cpumask_empty(frozen_cpus))
1483 pr_info("Enabling non-boot CPUs ...\n");
1485 arch_thaw_secondary_cpus_begin();
1487 for_each_cpu(cpu, frozen_cpus) {
1488 trace_suspend_resume(TPS("CPU_ON"), cpu, true);
1489 error = _cpu_up(cpu, 1, CPUHP_ONLINE);
1490 trace_suspend_resume(TPS("CPU_ON"), cpu, false);
1492 pr_info("CPU%d is up\n", cpu);
1495 pr_warn("Error taking CPU%d up: %d\n", cpu, error);
1498 arch_thaw_secondary_cpus_end();
1500 cpumask_clear(frozen_cpus);
1502 cpu_maps_update_done();
1505 static int __init alloc_frozen_cpus(void)
1507 if (!alloc_cpumask_var(&frozen_cpus, GFP_KERNEL|__GFP_ZERO))
1511 core_initcall(alloc_frozen_cpus);
1514 * When callbacks for CPU hotplug notifications are being executed, we must
1515 * ensure that the state of the system with respect to the tasks being frozen
1516 * or not, as reported by the notification, remains unchanged *throughout the
1517 * duration* of the execution of the callbacks.
1518 * Hence we need to prevent the freezer from racing with regular CPU hotplug.
1520 * This synchronization is implemented by mutually excluding regular CPU
1521 * hotplug and Suspend/Hibernate call paths by hooking onto the Suspend/
1522 * Hibernate notifications.
1525 cpu_hotplug_pm_callback(struct notifier_block *nb,
1526 unsigned long action, void *ptr)
1530 case PM_SUSPEND_PREPARE:
1531 case PM_HIBERNATION_PREPARE:
1532 cpu_hotplug_disable();
1535 case PM_POST_SUSPEND:
1536 case PM_POST_HIBERNATION:
1537 cpu_hotplug_enable();
1548 static int __init cpu_hotplug_pm_sync_init(void)
1551 * cpu_hotplug_pm_callback has higher priority than x86
1552 * bsp_pm_callback which depends on cpu_hotplug_pm_callback
1553 * to disable cpu hotplug to avoid cpu hotplug race.
1555 pm_notifier(cpu_hotplug_pm_callback, 0);
1558 core_initcall(cpu_hotplug_pm_sync_init);
1560 #endif /* CONFIG_PM_SLEEP_SMP */
1564 #endif /* CONFIG_SMP */
1566 /* Boot processor state steps */
1567 static struct cpuhp_step cpuhp_hp_states[] = {
1570 .startup.single = NULL,
1571 .teardown.single = NULL,
1574 [CPUHP_CREATE_THREADS]= {
1575 .name = "threads:prepare",
1576 .startup.single = smpboot_create_threads,
1577 .teardown.single = NULL,
1580 [CPUHP_PERF_PREPARE] = {
1581 .name = "perf:prepare",
1582 .startup.single = perf_event_init_cpu,
1583 .teardown.single = perf_event_exit_cpu,
1585 [CPUHP_RANDOM_PREPARE] = {
1586 .name = "random:prepare",
1587 .startup.single = random_prepare_cpu,
1588 .teardown.single = NULL,
1590 [CPUHP_WORKQUEUE_PREP] = {
1591 .name = "workqueue:prepare",
1592 .startup.single = workqueue_prepare_cpu,
1593 .teardown.single = NULL,
1595 [CPUHP_HRTIMERS_PREPARE] = {
1596 .name = "hrtimers:prepare",
1597 .startup.single = hrtimers_prepare_cpu,
1598 .teardown.single = NULL,
1600 [CPUHP_SMPCFD_PREPARE] = {
1601 .name = "smpcfd:prepare",
1602 .startup.single = smpcfd_prepare_cpu,
1603 .teardown.single = smpcfd_dead_cpu,
1605 [CPUHP_RELAY_PREPARE] = {
1606 .name = "relay:prepare",
1607 .startup.single = relay_prepare_cpu,
1608 .teardown.single = NULL,
1610 [CPUHP_SLAB_PREPARE] = {
1611 .name = "slab:prepare",
1612 .startup.single = slab_prepare_cpu,
1613 .teardown.single = slab_dead_cpu,
1615 [CPUHP_RCUTREE_PREP] = {
1616 .name = "RCU/tree:prepare",
1617 .startup.single = rcutree_prepare_cpu,
1618 .teardown.single = rcutree_dead_cpu,
1621 * On the tear-down path, timers_dead_cpu() must be invoked
1622 * before blk_mq_queue_reinit_notify() from notify_dead(),
1623 * otherwise a RCU stall occurs.
1625 [CPUHP_TIMERS_PREPARE] = {
1626 .name = "timers:prepare",
1627 .startup.single = timers_prepare_cpu,
1628 .teardown.single = timers_dead_cpu,
1630 /* Kicks the plugged cpu into life */
1631 [CPUHP_BRINGUP_CPU] = {
1632 .name = "cpu:bringup",
1633 .startup.single = bringup_cpu,
1634 .teardown.single = finish_cpu,
1637 /* Final state before CPU kills itself */
1638 [CPUHP_AP_IDLE_DEAD] = {
1639 .name = "idle:dead",
1642 * Last state before CPU enters the idle loop to die. Transient state
1643 * for synchronization.
1645 [CPUHP_AP_OFFLINE] = {
1646 .name = "ap:offline",
1649 /* First state is scheduler control. Interrupts are disabled */
1650 [CPUHP_AP_SCHED_STARTING] = {
1651 .name = "sched:starting",
1652 .startup.single = sched_cpu_starting,
1653 .teardown.single = sched_cpu_dying,
1655 [CPUHP_AP_RCUTREE_DYING] = {
1656 .name = "RCU/tree:dying",
1657 .startup.single = NULL,
1658 .teardown.single = rcutree_dying_cpu,
1660 [CPUHP_AP_SMPCFD_DYING] = {
1661 .name = "smpcfd:dying",
1662 .startup.single = NULL,
1663 .teardown.single = smpcfd_dying_cpu,
1665 [CPUHP_AP_HRTIMERS_DYING] = {
1666 .name = "hrtimers:dying",
1667 .startup.single = NULL,
1668 .teardown.single = hrtimers_cpu_dying,
1671 /* Entry state on starting. Interrupts enabled from here on. Transient
1672 * state for synchronsization */
1673 [CPUHP_AP_ONLINE] = {
1674 .name = "ap:online",
1677 * Handled on controll processor until the plugged processor manages
1680 [CPUHP_TEARDOWN_CPU] = {
1681 .name = "cpu:teardown",
1682 .startup.single = NULL,
1683 .teardown.single = takedown_cpu,
1686 /* Handle smpboot threads park/unpark */
1687 [CPUHP_AP_SMPBOOT_THREADS] = {
1688 .name = "smpboot/threads:online",
1689 .startup.single = smpboot_unpark_threads,
1690 .teardown.single = smpboot_park_threads,
1692 [CPUHP_AP_IRQ_AFFINITY_ONLINE] = {
1693 .name = "irq/affinity:online",
1694 .startup.single = irq_affinity_online_cpu,
1695 .teardown.single = NULL,
1697 [CPUHP_AP_PERF_ONLINE] = {
1698 .name = "perf:online",
1699 .startup.single = perf_event_init_cpu,
1700 .teardown.single = perf_event_exit_cpu,
1702 [CPUHP_AP_WATCHDOG_ONLINE] = {
1703 .name = "lockup_detector:online",
1704 .startup.single = lockup_detector_online_cpu,
1705 .teardown.single = lockup_detector_offline_cpu,
1707 [CPUHP_AP_WORKQUEUE_ONLINE] = {
1708 .name = "workqueue:online",
1709 .startup.single = workqueue_online_cpu,
1710 .teardown.single = workqueue_offline_cpu,
1712 [CPUHP_AP_RANDOM_ONLINE] = {
1713 .name = "random:online",
1714 .startup.single = random_online_cpu,
1715 .teardown.single = NULL,
1717 [CPUHP_AP_RCUTREE_ONLINE] = {
1718 .name = "RCU/tree:online",
1719 .startup.single = rcutree_online_cpu,
1720 .teardown.single = rcutree_offline_cpu,
1724 * The dynamically registered state space is here
1728 /* Last state is scheduler control setting the cpu active */
1729 [CPUHP_AP_ACTIVE] = {
1730 .name = "sched:active",
1731 .startup.single = sched_cpu_activate,
1732 .teardown.single = sched_cpu_deactivate,
1736 /* CPU is fully up and running. */
1739 .startup.single = NULL,
1740 .teardown.single = NULL,
1744 /* Sanity check for callbacks */
1745 static int cpuhp_cb_check(enum cpuhp_state state)
1747 if (state <= CPUHP_OFFLINE || state >= CPUHP_ONLINE)
1753 * Returns a free for dynamic slot assignment of the Online state. The states
1754 * are protected by the cpuhp_slot_states mutex and an empty slot is identified
1755 * by having no name assigned.
1757 static int cpuhp_reserve_state(enum cpuhp_state state)
1759 enum cpuhp_state i, end;
1760 struct cpuhp_step *step;
1763 case CPUHP_AP_ONLINE_DYN:
1764 step = cpuhp_hp_states + CPUHP_AP_ONLINE_DYN;
1765 end = CPUHP_AP_ONLINE_DYN_END;
1767 case CPUHP_BP_PREPARE_DYN:
1768 step = cpuhp_hp_states + CPUHP_BP_PREPARE_DYN;
1769 end = CPUHP_BP_PREPARE_DYN_END;
1775 for (i = state; i <= end; i++, step++) {
1779 WARN(1, "No more dynamic states available for CPU hotplug\n");
1783 static int cpuhp_store_callbacks(enum cpuhp_state state, const char *name,
1784 int (*startup)(unsigned int cpu),
1785 int (*teardown)(unsigned int cpu),
1786 bool multi_instance)
1788 /* (Un)Install the callbacks for further cpu hotplug operations */
1789 struct cpuhp_step *sp;
1793 * If name is NULL, then the state gets removed.
1795 * CPUHP_AP_ONLINE_DYN and CPUHP_BP_PREPARE_DYN are handed out on
1796 * the first allocation from these dynamic ranges, so the removal
1797 * would trigger a new allocation and clear the wrong (already
1798 * empty) state, leaving the callbacks of the to be cleared state
1799 * dangling, which causes wreckage on the next hotplug operation.
1801 if (name && (state == CPUHP_AP_ONLINE_DYN ||
1802 state == CPUHP_BP_PREPARE_DYN)) {
1803 ret = cpuhp_reserve_state(state);
1808 sp = cpuhp_get_step(state);
1809 if (name && sp->name)
1812 sp->startup.single = startup;
1813 sp->teardown.single = teardown;
1815 sp->multi_instance = multi_instance;
1816 INIT_HLIST_HEAD(&sp->list);
1820 static void *cpuhp_get_teardown_cb(enum cpuhp_state state)
1822 return cpuhp_get_step(state)->teardown.single;
1826 * Call the startup/teardown function for a step either on the AP or
1827 * on the current CPU.
1829 static int cpuhp_issue_call(int cpu, enum cpuhp_state state, bool bringup,
1830 struct hlist_node *node)
1832 struct cpuhp_step *sp = cpuhp_get_step(state);
1836 * If there's nothing to do, we done.
1837 * Relies on the union for multi_instance.
1839 if ((bringup && !sp->startup.single) ||
1840 (!bringup && !sp->teardown.single))
1843 * The non AP bound callbacks can fail on bringup. On teardown
1844 * e.g. module removal we crash for now.
1847 if (cpuhp_is_ap_state(state))
1848 ret = cpuhp_invoke_ap_callback(cpu, state, bringup, node);
1850 ret = cpuhp_invoke_callback(cpu, state, bringup, node, NULL);
1852 ret = cpuhp_invoke_callback(cpu, state, bringup, node, NULL);
1854 BUG_ON(ret && !bringup);
1859 * Called from __cpuhp_setup_state on a recoverable failure.
1861 * Note: The teardown callbacks for rollback are not allowed to fail!
1863 static void cpuhp_rollback_install(int failedcpu, enum cpuhp_state state,
1864 struct hlist_node *node)
1868 /* Roll back the already executed steps on the other cpus */
1869 for_each_present_cpu(cpu) {
1870 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
1871 int cpustate = st->state;
1873 if (cpu >= failedcpu)
1876 /* Did we invoke the startup call on that cpu ? */
1877 if (cpustate >= state)
1878 cpuhp_issue_call(cpu, state, false, node);
1882 int __cpuhp_state_add_instance_cpuslocked(enum cpuhp_state state,
1883 struct hlist_node *node,
1886 struct cpuhp_step *sp;
1890 lockdep_assert_cpus_held();
1892 sp = cpuhp_get_step(state);
1893 if (sp->multi_instance == false)
1896 mutex_lock(&cpuhp_state_mutex);
1898 if (!invoke || !sp->startup.multi)
1902 * Try to call the startup callback for each present cpu
1903 * depending on the hotplug state of the cpu.
1905 for_each_present_cpu(cpu) {
1906 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
1907 int cpustate = st->state;
1909 if (cpustate < state)
1912 ret = cpuhp_issue_call(cpu, state, true, node);
1914 if (sp->teardown.multi)
1915 cpuhp_rollback_install(cpu, state, node);
1921 hlist_add_head(node, &sp->list);
1923 mutex_unlock(&cpuhp_state_mutex);
1927 int __cpuhp_state_add_instance(enum cpuhp_state state, struct hlist_node *node,
1933 ret = __cpuhp_state_add_instance_cpuslocked(state, node, invoke);
1937 EXPORT_SYMBOL_GPL(__cpuhp_state_add_instance);
1940 * __cpuhp_setup_state_cpuslocked - Setup the callbacks for an hotplug machine state
1941 * @state: The state to setup
1942 * @invoke: If true, the startup function is invoked for cpus where
1943 * cpu state >= @state
1944 * @startup: startup callback function
1945 * @teardown: teardown callback function
1946 * @multi_instance: State is set up for multiple instances which get
1949 * The caller needs to hold cpus read locked while calling this function.
1952 * Positive state number if @state is CPUHP_AP_ONLINE_DYN
1953 * 0 for all other states
1954 * On failure: proper (negative) error code
1956 int __cpuhp_setup_state_cpuslocked(enum cpuhp_state state,
1957 const char *name, bool invoke,
1958 int (*startup)(unsigned int cpu),
1959 int (*teardown)(unsigned int cpu),
1960 bool multi_instance)
1965 lockdep_assert_cpus_held();
1967 if (cpuhp_cb_check(state) || !name)
1970 mutex_lock(&cpuhp_state_mutex);
1972 ret = cpuhp_store_callbacks(state, name, startup, teardown,
1975 dynstate = state == CPUHP_AP_ONLINE_DYN;
1976 if (ret > 0 && dynstate) {
1981 if (ret || !invoke || !startup)
1985 * Try to call the startup callback for each present cpu
1986 * depending on the hotplug state of the cpu.
1988 for_each_present_cpu(cpu) {
1989 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
1990 int cpustate = st->state;
1992 if (cpustate < state)
1995 ret = cpuhp_issue_call(cpu, state, true, NULL);
1998 cpuhp_rollback_install(cpu, state, NULL);
1999 cpuhp_store_callbacks(state, NULL, NULL, NULL, false);
2004 mutex_unlock(&cpuhp_state_mutex);
2006 * If the requested state is CPUHP_AP_ONLINE_DYN, return the
2007 * dynamically allocated state in case of success.
2009 if (!ret && dynstate)
2013 EXPORT_SYMBOL(__cpuhp_setup_state_cpuslocked);
2015 int __cpuhp_setup_state(enum cpuhp_state state,
2016 const char *name, bool invoke,
2017 int (*startup)(unsigned int cpu),
2018 int (*teardown)(unsigned int cpu),
2019 bool multi_instance)
2024 ret = __cpuhp_setup_state_cpuslocked(state, name, invoke, startup,
2025 teardown, multi_instance);
2029 EXPORT_SYMBOL(__cpuhp_setup_state);
2031 int __cpuhp_state_remove_instance(enum cpuhp_state state,
2032 struct hlist_node *node, bool invoke)
2034 struct cpuhp_step *sp = cpuhp_get_step(state);
2037 BUG_ON(cpuhp_cb_check(state));
2039 if (!sp->multi_instance)
2043 mutex_lock(&cpuhp_state_mutex);
2045 if (!invoke || !cpuhp_get_teardown_cb(state))
2048 * Call the teardown callback for each present cpu depending
2049 * on the hotplug state of the cpu. This function is not
2050 * allowed to fail currently!
2052 for_each_present_cpu(cpu) {
2053 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
2054 int cpustate = st->state;
2056 if (cpustate >= state)
2057 cpuhp_issue_call(cpu, state, false, node);
2062 mutex_unlock(&cpuhp_state_mutex);
2067 EXPORT_SYMBOL_GPL(__cpuhp_state_remove_instance);
2070 * __cpuhp_remove_state_cpuslocked - Remove the callbacks for an hotplug machine state
2071 * @state: The state to remove
2072 * @invoke: If true, the teardown function is invoked for cpus where
2073 * cpu state >= @state
2075 * The caller needs to hold cpus read locked while calling this function.
2076 * The teardown callback is currently not allowed to fail. Think
2077 * about module removal!
2079 void __cpuhp_remove_state_cpuslocked(enum cpuhp_state state, bool invoke)
2081 struct cpuhp_step *sp = cpuhp_get_step(state);
2084 BUG_ON(cpuhp_cb_check(state));
2086 lockdep_assert_cpus_held();
2088 mutex_lock(&cpuhp_state_mutex);
2089 if (sp->multi_instance) {
2090 WARN(!hlist_empty(&sp->list),
2091 "Error: Removing state %d which has instances left.\n",
2096 if (!invoke || !cpuhp_get_teardown_cb(state))
2100 * Call the teardown callback for each present cpu depending
2101 * on the hotplug state of the cpu. This function is not
2102 * allowed to fail currently!
2104 for_each_present_cpu(cpu) {
2105 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
2106 int cpustate = st->state;
2108 if (cpustate >= state)
2109 cpuhp_issue_call(cpu, state, false, NULL);
2112 cpuhp_store_callbacks(state, NULL, NULL, NULL, false);
2113 mutex_unlock(&cpuhp_state_mutex);
2115 EXPORT_SYMBOL(__cpuhp_remove_state_cpuslocked);
2117 void __cpuhp_remove_state(enum cpuhp_state state, bool invoke)
2120 __cpuhp_remove_state_cpuslocked(state, invoke);
2123 EXPORT_SYMBOL(__cpuhp_remove_state);
2125 #ifdef CONFIG_HOTPLUG_SMT
2126 static void cpuhp_offline_cpu_device(unsigned int cpu)
2128 struct device *dev = get_cpu_device(cpu);
2130 dev->offline = true;
2131 /* Tell user space about the state change */
2132 kobject_uevent(&dev->kobj, KOBJ_OFFLINE);
2135 static void cpuhp_online_cpu_device(unsigned int cpu)
2137 struct device *dev = get_cpu_device(cpu);
2139 dev->offline = false;
2140 /* Tell user space about the state change */
2141 kobject_uevent(&dev->kobj, KOBJ_ONLINE);
2144 int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval)
2148 cpu_maps_update_begin();
2149 for_each_online_cpu(cpu) {
2150 if (topology_is_primary_thread(cpu))
2152 ret = cpu_down_maps_locked(cpu, CPUHP_OFFLINE);
2156 * As this needs to hold the cpu maps lock it's impossible
2157 * to call device_offline() because that ends up calling
2158 * cpu_down() which takes cpu maps lock. cpu maps lock
2159 * needs to be held as this might race against in kernel
2160 * abusers of the hotplug machinery (thermal management).
2162 * So nothing would update device:offline state. That would
2163 * leave the sysfs entry stale and prevent onlining after
2164 * smt control has been changed to 'off' again. This is
2165 * called under the sysfs hotplug lock, so it is properly
2166 * serialized against the regular offline usage.
2168 cpuhp_offline_cpu_device(cpu);
2171 cpu_smt_control = ctrlval;
2172 cpu_maps_update_done();
2176 int cpuhp_smt_enable(void)
2180 cpu_maps_update_begin();
2181 cpu_smt_control = CPU_SMT_ENABLED;
2182 for_each_present_cpu(cpu) {
2183 /* Skip online CPUs and CPUs on offline nodes */
2184 if (cpu_online(cpu) || !node_online(cpu_to_node(cpu)))
2186 ret = _cpu_up(cpu, 0, CPUHP_ONLINE);
2189 /* See comment in cpuhp_smt_disable() */
2190 cpuhp_online_cpu_device(cpu);
2192 cpu_maps_update_done();
2197 #if defined(CONFIG_SYSFS) && defined(CONFIG_HOTPLUG_CPU)
2198 static ssize_t show_cpuhp_state(struct device *dev,
2199 struct device_attribute *attr, char *buf)
2201 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id);
2203 return sprintf(buf, "%d\n", st->state);
2205 static DEVICE_ATTR(state, 0444, show_cpuhp_state, NULL);
2207 static ssize_t write_cpuhp_target(struct device *dev,
2208 struct device_attribute *attr,
2209 const char *buf, size_t count)
2211 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id);
2212 struct cpuhp_step *sp;
2215 ret = kstrtoint(buf, 10, &target);
2219 #ifdef CONFIG_CPU_HOTPLUG_STATE_CONTROL
2220 if (target < CPUHP_OFFLINE || target > CPUHP_ONLINE)
2223 if (target != CPUHP_OFFLINE && target != CPUHP_ONLINE)
2227 ret = lock_device_hotplug_sysfs();
2231 mutex_lock(&cpuhp_state_mutex);
2232 sp = cpuhp_get_step(target);
2233 ret = !sp->name || sp->cant_stop ? -EINVAL : 0;
2234 mutex_unlock(&cpuhp_state_mutex);
2238 if (st->state < target)
2239 ret = cpu_up(dev->id, target);
2240 else if (st->state > target)
2241 ret = cpu_down(dev->id, target);
2242 else if (WARN_ON(st->target != target))
2243 st->target = target;
2245 unlock_device_hotplug();
2246 return ret ? ret : count;
2249 static ssize_t show_cpuhp_target(struct device *dev,
2250 struct device_attribute *attr, char *buf)
2252 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id);
2254 return sprintf(buf, "%d\n", st->target);
2256 static DEVICE_ATTR(target, 0644, show_cpuhp_target, write_cpuhp_target);
2259 static ssize_t write_cpuhp_fail(struct device *dev,
2260 struct device_attribute *attr,
2261 const char *buf, size_t count)
2263 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id);
2264 struct cpuhp_step *sp;
2267 ret = kstrtoint(buf, 10, &fail);
2271 if (fail < CPUHP_OFFLINE || fail > CPUHP_ONLINE)
2275 * Cannot fail STARTING/DYING callbacks.
2277 if (cpuhp_is_atomic_state(fail))
2281 * Cannot fail anything that doesn't have callbacks.
2283 mutex_lock(&cpuhp_state_mutex);
2284 sp = cpuhp_get_step(fail);
2285 if (!sp->startup.single && !sp->teardown.single)
2287 mutex_unlock(&cpuhp_state_mutex);
2296 static ssize_t show_cpuhp_fail(struct device *dev,
2297 struct device_attribute *attr, char *buf)
2299 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id);
2301 return sprintf(buf, "%d\n", st->fail);
2304 static DEVICE_ATTR(fail, 0644, show_cpuhp_fail, write_cpuhp_fail);
2306 static struct attribute *cpuhp_cpu_attrs[] = {
2307 &dev_attr_state.attr,
2308 &dev_attr_target.attr,
2309 &dev_attr_fail.attr,
2313 static const struct attribute_group cpuhp_cpu_attr_group = {
2314 .attrs = cpuhp_cpu_attrs,
2319 static ssize_t show_cpuhp_states(struct device *dev,
2320 struct device_attribute *attr, char *buf)
2322 ssize_t cur, res = 0;
2325 mutex_lock(&cpuhp_state_mutex);
2326 for (i = CPUHP_OFFLINE; i <= CPUHP_ONLINE; i++) {
2327 struct cpuhp_step *sp = cpuhp_get_step(i);
2330 cur = sprintf(buf, "%3d: %s\n", i, sp->name);
2335 mutex_unlock(&cpuhp_state_mutex);
2338 static DEVICE_ATTR(states, 0444, show_cpuhp_states, NULL);
2340 static struct attribute *cpuhp_cpu_root_attrs[] = {
2341 &dev_attr_states.attr,
2345 static const struct attribute_group cpuhp_cpu_root_attr_group = {
2346 .attrs = cpuhp_cpu_root_attrs,
2351 #ifdef CONFIG_HOTPLUG_SMT
2354 __store_smt_control(struct device *dev, struct device_attribute *attr,
2355 const char *buf, size_t count)
2359 if (sysfs_streq(buf, "on"))
2360 ctrlval = CPU_SMT_ENABLED;
2361 else if (sysfs_streq(buf, "off"))
2362 ctrlval = CPU_SMT_DISABLED;
2363 else if (sysfs_streq(buf, "forceoff"))
2364 ctrlval = CPU_SMT_FORCE_DISABLED;
2368 if (cpu_smt_control == CPU_SMT_FORCE_DISABLED)
2371 if (cpu_smt_control == CPU_SMT_NOT_SUPPORTED)
2374 ret = lock_device_hotplug_sysfs();
2378 if (ctrlval != cpu_smt_control) {
2380 case CPU_SMT_ENABLED:
2381 ret = cpuhp_smt_enable();
2383 case CPU_SMT_DISABLED:
2384 case CPU_SMT_FORCE_DISABLED:
2385 ret = cpuhp_smt_disable(ctrlval);
2390 unlock_device_hotplug();
2391 return ret ? ret : count;
2394 #else /* !CONFIG_HOTPLUG_SMT */
2396 __store_smt_control(struct device *dev, struct device_attribute *attr,
2397 const char *buf, size_t count)
2401 #endif /* CONFIG_HOTPLUG_SMT */
2403 static const char *smt_states[] = {
2404 [CPU_SMT_ENABLED] = "on",
2405 [CPU_SMT_DISABLED] = "off",
2406 [CPU_SMT_FORCE_DISABLED] = "forceoff",
2407 [CPU_SMT_NOT_SUPPORTED] = "notsupported",
2408 [CPU_SMT_NOT_IMPLEMENTED] = "notimplemented",
2412 show_smt_control(struct device *dev, struct device_attribute *attr, char *buf)
2414 const char *state = smt_states[cpu_smt_control];
2416 return snprintf(buf, PAGE_SIZE - 2, "%s\n", state);
2420 store_smt_control(struct device *dev, struct device_attribute *attr,
2421 const char *buf, size_t count)
2423 return __store_smt_control(dev, attr, buf, count);
2425 static DEVICE_ATTR(control, 0644, show_smt_control, store_smt_control);
2428 show_smt_active(struct device *dev, struct device_attribute *attr, char *buf)
2430 return snprintf(buf, PAGE_SIZE - 2, "%d\n", sched_smt_active());
2432 static DEVICE_ATTR(active, 0444, show_smt_active, NULL);
2434 static struct attribute *cpuhp_smt_attrs[] = {
2435 &dev_attr_control.attr,
2436 &dev_attr_active.attr,
2440 static const struct attribute_group cpuhp_smt_attr_group = {
2441 .attrs = cpuhp_smt_attrs,
2446 static int __init cpu_smt_sysfs_init(void)
2448 return sysfs_create_group(&cpu_subsys.dev_root->kobj,
2449 &cpuhp_smt_attr_group);
2452 static int __init cpuhp_sysfs_init(void)
2456 ret = cpu_smt_sysfs_init();
2460 ret = sysfs_create_group(&cpu_subsys.dev_root->kobj,
2461 &cpuhp_cpu_root_attr_group);
2465 for_each_possible_cpu(cpu) {
2466 struct device *dev = get_cpu_device(cpu);
2470 ret = sysfs_create_group(&dev->kobj, &cpuhp_cpu_attr_group);
2476 device_initcall(cpuhp_sysfs_init);
2477 #endif /* CONFIG_SYSFS && CONFIG_HOTPLUG_CPU */
2480 * cpu_bit_bitmap[] is a special, "compressed" data structure that
2481 * represents all NR_CPUS bits binary values of 1<<nr.
2483 * It is used by cpumask_of() to get a constant address to a CPU
2484 * mask value that has a single bit set only.
2487 /* cpu_bit_bitmap[0] is empty - so we can back into it */
2488 #define MASK_DECLARE_1(x) [x+1][0] = (1UL << (x))
2489 #define MASK_DECLARE_2(x) MASK_DECLARE_1(x), MASK_DECLARE_1(x+1)
2490 #define MASK_DECLARE_4(x) MASK_DECLARE_2(x), MASK_DECLARE_2(x+2)
2491 #define MASK_DECLARE_8(x) MASK_DECLARE_4(x), MASK_DECLARE_4(x+4)
2493 const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = {
2495 MASK_DECLARE_8(0), MASK_DECLARE_8(8),
2496 MASK_DECLARE_8(16), MASK_DECLARE_8(24),
2497 #if BITS_PER_LONG > 32
2498 MASK_DECLARE_8(32), MASK_DECLARE_8(40),
2499 MASK_DECLARE_8(48), MASK_DECLARE_8(56),
2502 EXPORT_SYMBOL_GPL(cpu_bit_bitmap);
2504 const DECLARE_BITMAP(cpu_all_bits, NR_CPUS) = CPU_BITS_ALL;
2505 EXPORT_SYMBOL(cpu_all_bits);
2507 #ifdef CONFIG_INIT_ALL_POSSIBLE
2508 struct cpumask __cpu_possible_mask __read_mostly
2511 struct cpumask __cpu_possible_mask __read_mostly;
2513 EXPORT_SYMBOL(__cpu_possible_mask);
2515 struct cpumask __cpu_online_mask __read_mostly;
2516 EXPORT_SYMBOL(__cpu_online_mask);
2518 struct cpumask __cpu_present_mask __read_mostly;
2519 EXPORT_SYMBOL(__cpu_present_mask);
2521 struct cpumask __cpu_active_mask __read_mostly;
2522 EXPORT_SYMBOL(__cpu_active_mask);
2524 atomic_t __num_online_cpus __read_mostly;
2525 EXPORT_SYMBOL(__num_online_cpus);
2527 void init_cpu_present(const struct cpumask *src)
2529 cpumask_copy(&__cpu_present_mask, src);
2532 void init_cpu_possible(const struct cpumask *src)
2534 cpumask_copy(&__cpu_possible_mask, src);
2537 void init_cpu_online(const struct cpumask *src)
2539 cpumask_copy(&__cpu_online_mask, src);
2542 void set_cpu_online(unsigned int cpu, bool online)
2545 * atomic_inc/dec() is required to handle the horrid abuse of this
2546 * function by the reboot and kexec code which invoke it from
2547 * IPI/NMI broadcasts when shutting down CPUs. Invocation from
2548 * regular CPU hotplug is properly serialized.
2550 * Note, that the fact that __num_online_cpus is of type atomic_t
2551 * does not protect readers which are not serialized against
2552 * concurrent hotplug operations.
2555 if (!cpumask_test_and_set_cpu(cpu, &__cpu_online_mask))
2556 atomic_inc(&__num_online_cpus);
2558 if (cpumask_test_and_clear_cpu(cpu, &__cpu_online_mask))
2559 atomic_dec(&__num_online_cpus);
2564 * Activate the first processor.
2566 void __init boot_cpu_init(void)
2568 int cpu = smp_processor_id();
2570 /* Mark the boot cpu "present", "online" etc for SMP and UP case */
2571 set_cpu_online(cpu, true);
2572 set_cpu_active(cpu, true);
2573 set_cpu_present(cpu, true);
2574 set_cpu_possible(cpu, true);
2577 __boot_cpu_id = cpu;
2582 * Must be called _AFTER_ setting up the per_cpu areas
2584 void __init boot_cpu_hotplug_init(void)
2587 cpumask_set_cpu(smp_processor_id(), &cpus_booted_once_mask);
2589 this_cpu_write(cpuhp_state.state, CPUHP_ONLINE);
2593 * These are used for a global "mitigations=" cmdline option for toggling
2594 * optional CPU mitigations.
2596 enum cpu_mitigations {
2597 CPU_MITIGATIONS_OFF,
2598 CPU_MITIGATIONS_AUTO,
2599 CPU_MITIGATIONS_AUTO_NOSMT,
2602 static enum cpu_mitigations cpu_mitigations __ro_after_init =
2603 CPU_MITIGATIONS_AUTO;
2605 static int __init mitigations_parse_cmdline(char *arg)
2607 if (!strcmp(arg, "off"))
2608 cpu_mitigations = CPU_MITIGATIONS_OFF;
2609 else if (!strcmp(arg, "auto"))
2610 cpu_mitigations = CPU_MITIGATIONS_AUTO;
2611 else if (!strcmp(arg, "auto,nosmt"))
2612 cpu_mitigations = CPU_MITIGATIONS_AUTO_NOSMT;
2614 pr_crit("Unsupported mitigations=%s, system may still be vulnerable\n",
2619 early_param("mitigations", mitigations_parse_cmdline);
2621 /* mitigations=off */
2622 bool cpu_mitigations_off(void)
2624 return cpu_mitigations == CPU_MITIGATIONS_OFF;
2626 EXPORT_SYMBOL_GPL(cpu_mitigations_off);
2628 /* mitigations=auto,nosmt */
2629 bool cpu_mitigations_auto_nosmt(void)
2631 return cpu_mitigations == CPU_MITIGATIONS_AUTO_NOSMT;
2633 EXPORT_SYMBOL_GPL(cpu_mitigations_auto_nosmt);