firewire: ohci: Use tasklet_disable_in_atomic() where required
[linux-2.6-microblaze.git] / kernel / softirq.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  *      linux/kernel/softirq.c
4  *
5  *      Copyright (C) 1992 Linus Torvalds
6  *
7  *      Rewritten. Old one was good in 2.2, but in 2.3 it was immoral. --ANK (990903)
8  */
9
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
12 #include <linux/export.h>
13 #include <linux/kernel_stat.h>
14 #include <linux/interrupt.h>
15 #include <linux/init.h>
16 #include <linux/mm.h>
17 #include <linux/notifier.h>
18 #include <linux/percpu.h>
19 #include <linux/cpu.h>
20 #include <linux/freezer.h>
21 #include <linux/kthread.h>
22 #include <linux/rcupdate.h>
23 #include <linux/ftrace.h>
24 #include <linux/smp.h>
25 #include <linux/smpboot.h>
26 #include <linux/tick.h>
27 #include <linux/irq.h>
28 #include <linux/wait_bit.h>
29
30 #include <asm/softirq_stack.h>
31
32 #define CREATE_TRACE_POINTS
33 #include <trace/events/irq.h>
34
35 /*
36    - No shared variables, all the data are CPU local.
37    - If a softirq needs serialization, let it serialize itself
38      by its own spinlocks.
39    - Even if softirq is serialized, only local cpu is marked for
40      execution. Hence, we get something sort of weak cpu binding.
41      Though it is still not clear, will it result in better locality
42      or will not.
43
44    Examples:
45    - NET RX softirq. It is multithreaded and does not require
46      any global serialization.
47    - NET TX softirq. It kicks software netdevice queues, hence
48      it is logically serialized per device, but this serialization
49      is invisible to common code.
50    - Tasklets: serialized wrt itself.
51  */
52
53 #ifndef __ARCH_IRQ_STAT
54 DEFINE_PER_CPU_ALIGNED(irq_cpustat_t, irq_stat);
55 EXPORT_PER_CPU_SYMBOL(irq_stat);
56 #endif
57
58 static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
59
60 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
61
62 const char * const softirq_to_name[NR_SOFTIRQS] = {
63         "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "IRQ_POLL",
64         "TASKLET", "SCHED", "HRTIMER", "RCU"
65 };
66
67 /*
68  * we cannot loop indefinitely here to avoid userspace starvation,
69  * but we also don't want to introduce a worst case 1/HZ latency
70  * to the pending events, so lets the scheduler to balance
71  * the softirq load for us.
72  */
73 static void wakeup_softirqd(void)
74 {
75         /* Interrupts are disabled: no need to stop preemption */
76         struct task_struct *tsk = __this_cpu_read(ksoftirqd);
77
78         if (tsk && tsk->state != TASK_RUNNING)
79                 wake_up_process(tsk);
80 }
81
82 /*
83  * If ksoftirqd is scheduled, we do not want to process pending softirqs
84  * right now. Let ksoftirqd handle this at its own rate, to get fairness,
85  * unless we're doing some of the synchronous softirqs.
86  */
87 #define SOFTIRQ_NOW_MASK ((1 << HI_SOFTIRQ) | (1 << TASKLET_SOFTIRQ))
88 static bool ksoftirqd_running(unsigned long pending)
89 {
90         struct task_struct *tsk = __this_cpu_read(ksoftirqd);
91
92         if (pending & SOFTIRQ_NOW_MASK)
93                 return false;
94         return tsk && (tsk->state == TASK_RUNNING) &&
95                 !__kthread_should_park(tsk);
96 }
97
98 #ifdef CONFIG_TRACE_IRQFLAGS
99 DEFINE_PER_CPU(int, hardirqs_enabled);
100 DEFINE_PER_CPU(int, hardirq_context);
101 EXPORT_PER_CPU_SYMBOL_GPL(hardirqs_enabled);
102 EXPORT_PER_CPU_SYMBOL_GPL(hardirq_context);
103 #endif
104
105 /*
106  * preempt_count and SOFTIRQ_OFFSET usage:
107  * - preempt_count is changed by SOFTIRQ_OFFSET on entering or leaving
108  *   softirq processing.
109  * - preempt_count is changed by SOFTIRQ_DISABLE_OFFSET (= 2 * SOFTIRQ_OFFSET)
110  *   on local_bh_disable or local_bh_enable.
111  * This lets us distinguish between whether we are currently processing
112  * softirq and whether we just have bh disabled.
113  */
114
115 #ifdef CONFIG_TRACE_IRQFLAGS
116 /*
117  * This is for softirq.c-internal use, where hardirqs are disabled
118  * legitimately:
119  */
120 void __local_bh_disable_ip(unsigned long ip, unsigned int cnt)
121 {
122         unsigned long flags;
123
124         WARN_ON_ONCE(in_irq());
125
126         raw_local_irq_save(flags);
127         /*
128          * The preempt tracer hooks into preempt_count_add and will break
129          * lockdep because it calls back into lockdep after SOFTIRQ_OFFSET
130          * is set and before current->softirq_enabled is cleared.
131          * We must manually increment preempt_count here and manually
132          * call the trace_preempt_off later.
133          */
134         __preempt_count_add(cnt);
135         /*
136          * Were softirqs turned off above:
137          */
138         if (softirq_count() == (cnt & SOFTIRQ_MASK))
139                 lockdep_softirqs_off(ip);
140         raw_local_irq_restore(flags);
141
142         if (preempt_count() == cnt) {
143 #ifdef CONFIG_DEBUG_PREEMPT
144                 current->preempt_disable_ip = get_lock_parent_ip();
145 #endif
146                 trace_preempt_off(CALLER_ADDR0, get_lock_parent_ip());
147         }
148 }
149 EXPORT_SYMBOL(__local_bh_disable_ip);
150 #endif /* CONFIG_TRACE_IRQFLAGS */
151
152 static void __local_bh_enable(unsigned int cnt)
153 {
154         lockdep_assert_irqs_disabled();
155
156         if (preempt_count() == cnt)
157                 trace_preempt_on(CALLER_ADDR0, get_lock_parent_ip());
158
159         if (softirq_count() == (cnt & SOFTIRQ_MASK))
160                 lockdep_softirqs_on(_RET_IP_);
161
162         __preempt_count_sub(cnt);
163 }
164
165 /*
166  * Special-case - softirqs can safely be enabled by __do_softirq(),
167  * without processing still-pending softirqs:
168  */
169 void _local_bh_enable(void)
170 {
171         WARN_ON_ONCE(in_irq());
172         __local_bh_enable(SOFTIRQ_DISABLE_OFFSET);
173 }
174 EXPORT_SYMBOL(_local_bh_enable);
175
176 void __local_bh_enable_ip(unsigned long ip, unsigned int cnt)
177 {
178         WARN_ON_ONCE(in_irq());
179         lockdep_assert_irqs_enabled();
180 #ifdef CONFIG_TRACE_IRQFLAGS
181         local_irq_disable();
182 #endif
183         /*
184          * Are softirqs going to be turned on now:
185          */
186         if (softirq_count() == SOFTIRQ_DISABLE_OFFSET)
187                 lockdep_softirqs_on(ip);
188         /*
189          * Keep preemption disabled until we are done with
190          * softirq processing:
191          */
192         __preempt_count_sub(cnt - 1);
193
194         if (unlikely(!in_interrupt() && local_softirq_pending())) {
195                 /*
196                  * Run softirq if any pending. And do it in its own stack
197                  * as we may be calling this deep in a task call stack already.
198                  */
199                 do_softirq();
200         }
201
202         preempt_count_dec();
203 #ifdef CONFIG_TRACE_IRQFLAGS
204         local_irq_enable();
205 #endif
206         preempt_check_resched();
207 }
208 EXPORT_SYMBOL(__local_bh_enable_ip);
209
210 static inline void invoke_softirq(void)
211 {
212         if (ksoftirqd_running(local_softirq_pending()))
213                 return;
214
215         if (!force_irqthreads) {
216 #ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK
217                 /*
218                  * We can safely execute softirq on the current stack if
219                  * it is the irq stack, because it should be near empty
220                  * at this stage.
221                  */
222                 __do_softirq();
223 #else
224                 /*
225                  * Otherwise, irq_exit() is called on the task stack that can
226                  * be potentially deep already. So call softirq in its own stack
227                  * to prevent from any overrun.
228                  */
229                 do_softirq_own_stack();
230 #endif
231         } else {
232                 wakeup_softirqd();
233         }
234 }
235
236 asmlinkage __visible void do_softirq(void)
237 {
238         __u32 pending;
239         unsigned long flags;
240
241         if (in_interrupt())
242                 return;
243
244         local_irq_save(flags);
245
246         pending = local_softirq_pending();
247
248         if (pending && !ksoftirqd_running(pending))
249                 do_softirq_own_stack();
250
251         local_irq_restore(flags);
252 }
253
254 /*
255  * We restart softirq processing for at most MAX_SOFTIRQ_RESTART times,
256  * but break the loop if need_resched() is set or after 2 ms.
257  * The MAX_SOFTIRQ_TIME provides a nice upper bound in most cases, but in
258  * certain cases, such as stop_machine(), jiffies may cease to
259  * increment and so we need the MAX_SOFTIRQ_RESTART limit as
260  * well to make sure we eventually return from this method.
261  *
262  * These limits have been established via experimentation.
263  * The two things to balance is latency against fairness -
264  * we want to handle softirqs as soon as possible, but they
265  * should not be able to lock up the box.
266  */
267 #define MAX_SOFTIRQ_TIME  msecs_to_jiffies(2)
268 #define MAX_SOFTIRQ_RESTART 10
269
270 #ifdef CONFIG_TRACE_IRQFLAGS
271 /*
272  * When we run softirqs from irq_exit() and thus on the hardirq stack we need
273  * to keep the lockdep irq context tracking as tight as possible in order to
274  * not miss-qualify lock contexts and miss possible deadlocks.
275  */
276
277 static inline bool lockdep_softirq_start(void)
278 {
279         bool in_hardirq = false;
280
281         if (lockdep_hardirq_context()) {
282                 in_hardirq = true;
283                 lockdep_hardirq_exit();
284         }
285
286         lockdep_softirq_enter();
287
288         return in_hardirq;
289 }
290
291 static inline void lockdep_softirq_end(bool in_hardirq)
292 {
293         lockdep_softirq_exit();
294
295         if (in_hardirq)
296                 lockdep_hardirq_enter();
297 }
298 #else
299 static inline bool lockdep_softirq_start(void) { return false; }
300 static inline void lockdep_softirq_end(bool in_hardirq) { }
301 #endif
302
303 asmlinkage __visible void __softirq_entry __do_softirq(void)
304 {
305         unsigned long end = jiffies + MAX_SOFTIRQ_TIME;
306         unsigned long old_flags = current->flags;
307         int max_restart = MAX_SOFTIRQ_RESTART;
308         struct softirq_action *h;
309         bool in_hardirq;
310         __u32 pending;
311         int softirq_bit;
312
313         /*
314          * Mask out PF_MEMALLOC as the current task context is borrowed for the
315          * softirq. A softirq handled, such as network RX, might set PF_MEMALLOC
316          * again if the socket is related to swapping.
317          */
318         current->flags &= ~PF_MEMALLOC;
319
320         pending = local_softirq_pending();
321
322         __local_bh_disable_ip(_RET_IP_, SOFTIRQ_OFFSET);
323         in_hardirq = lockdep_softirq_start();
324         account_softirq_enter(current);
325
326 restart:
327         /* Reset the pending bitmask before enabling irqs */
328         set_softirq_pending(0);
329
330         local_irq_enable();
331
332         h = softirq_vec;
333
334         while ((softirq_bit = ffs(pending))) {
335                 unsigned int vec_nr;
336                 int prev_count;
337
338                 h += softirq_bit - 1;
339
340                 vec_nr = h - softirq_vec;
341                 prev_count = preempt_count();
342
343                 kstat_incr_softirqs_this_cpu(vec_nr);
344
345                 trace_softirq_entry(vec_nr);
346                 h->action(h);
347                 trace_softirq_exit(vec_nr);
348                 if (unlikely(prev_count != preempt_count())) {
349                         pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
350                                vec_nr, softirq_to_name[vec_nr], h->action,
351                                prev_count, preempt_count());
352                         preempt_count_set(prev_count);
353                 }
354                 h++;
355                 pending >>= softirq_bit;
356         }
357
358         if (__this_cpu_read(ksoftirqd) == current)
359                 rcu_softirq_qs();
360         local_irq_disable();
361
362         pending = local_softirq_pending();
363         if (pending) {
364                 if (time_before(jiffies, end) && !need_resched() &&
365                     --max_restart)
366                         goto restart;
367
368                 wakeup_softirqd();
369         }
370
371         account_softirq_exit(current);
372         lockdep_softirq_end(in_hardirq);
373         __local_bh_enable(SOFTIRQ_OFFSET);
374         WARN_ON_ONCE(in_interrupt());
375         current_restore_flags(old_flags, PF_MEMALLOC);
376 }
377
378 /**
379  * irq_enter_rcu - Enter an interrupt context with RCU watching
380  */
381 void irq_enter_rcu(void)
382 {
383         __irq_enter_raw();
384
385         if (is_idle_task(current) && (irq_count() == HARDIRQ_OFFSET))
386                 tick_irq_enter();
387
388         account_hardirq_enter(current);
389 }
390
391 /**
392  * irq_enter - Enter an interrupt context including RCU update
393  */
394 void irq_enter(void)
395 {
396         rcu_irq_enter();
397         irq_enter_rcu();
398 }
399
400 static inline void tick_irq_exit(void)
401 {
402 #ifdef CONFIG_NO_HZ_COMMON
403         int cpu = smp_processor_id();
404
405         /* Make sure that timer wheel updates are propagated */
406         if ((idle_cpu(cpu) && !need_resched()) || tick_nohz_full_cpu(cpu)) {
407                 if (!in_irq())
408                         tick_nohz_irq_exit();
409         }
410 #endif
411 }
412
413 static inline void __irq_exit_rcu(void)
414 {
415 #ifndef __ARCH_IRQ_EXIT_IRQS_DISABLED
416         local_irq_disable();
417 #else
418         lockdep_assert_irqs_disabled();
419 #endif
420         account_hardirq_exit(current);
421         preempt_count_sub(HARDIRQ_OFFSET);
422         if (!in_interrupt() && local_softirq_pending())
423                 invoke_softirq();
424
425         tick_irq_exit();
426 }
427
428 /**
429  * irq_exit_rcu() - Exit an interrupt context without updating RCU
430  *
431  * Also processes softirqs if needed and possible.
432  */
433 void irq_exit_rcu(void)
434 {
435         __irq_exit_rcu();
436          /* must be last! */
437         lockdep_hardirq_exit();
438 }
439
440 /**
441  * irq_exit - Exit an interrupt context, update RCU and lockdep
442  *
443  * Also processes softirqs if needed and possible.
444  */
445 void irq_exit(void)
446 {
447         __irq_exit_rcu();
448         rcu_irq_exit();
449          /* must be last! */
450         lockdep_hardirq_exit();
451 }
452
453 /*
454  * This function must run with irqs disabled!
455  */
456 inline void raise_softirq_irqoff(unsigned int nr)
457 {
458         __raise_softirq_irqoff(nr);
459
460         /*
461          * If we're in an interrupt or softirq, we're done
462          * (this also catches softirq-disabled code). We will
463          * actually run the softirq once we return from
464          * the irq or softirq.
465          *
466          * Otherwise we wake up ksoftirqd to make sure we
467          * schedule the softirq soon.
468          */
469         if (!in_interrupt())
470                 wakeup_softirqd();
471 }
472
473 void raise_softirq(unsigned int nr)
474 {
475         unsigned long flags;
476
477         local_irq_save(flags);
478         raise_softirq_irqoff(nr);
479         local_irq_restore(flags);
480 }
481
482 void __raise_softirq_irqoff(unsigned int nr)
483 {
484         lockdep_assert_irqs_disabled();
485         trace_softirq_raise(nr);
486         or_softirq_pending(1UL << nr);
487 }
488
489 void open_softirq(int nr, void (*action)(struct softirq_action *))
490 {
491         softirq_vec[nr].action = action;
492 }
493
494 /*
495  * Tasklets
496  */
497 struct tasklet_head {
498         struct tasklet_struct *head;
499         struct tasklet_struct **tail;
500 };
501
502 static DEFINE_PER_CPU(struct tasklet_head, tasklet_vec);
503 static DEFINE_PER_CPU(struct tasklet_head, tasklet_hi_vec);
504
505 static void __tasklet_schedule_common(struct tasklet_struct *t,
506                                       struct tasklet_head __percpu *headp,
507                                       unsigned int softirq_nr)
508 {
509         struct tasklet_head *head;
510         unsigned long flags;
511
512         local_irq_save(flags);
513         head = this_cpu_ptr(headp);
514         t->next = NULL;
515         *head->tail = t;
516         head->tail = &(t->next);
517         raise_softirq_irqoff(softirq_nr);
518         local_irq_restore(flags);
519 }
520
521 void __tasklet_schedule(struct tasklet_struct *t)
522 {
523         __tasklet_schedule_common(t, &tasklet_vec,
524                                   TASKLET_SOFTIRQ);
525 }
526 EXPORT_SYMBOL(__tasklet_schedule);
527
528 void __tasklet_hi_schedule(struct tasklet_struct *t)
529 {
530         __tasklet_schedule_common(t, &tasklet_hi_vec,
531                                   HI_SOFTIRQ);
532 }
533 EXPORT_SYMBOL(__tasklet_hi_schedule);
534
535 static bool tasklet_clear_sched(struct tasklet_struct *t)
536 {
537         if (test_and_clear_bit(TASKLET_STATE_SCHED, &t->state)) {
538                 wake_up_var(&t->state);
539                 return true;
540         }
541
542         WARN_ONCE(1, "tasklet SCHED state not set: %s %pS\n",
543                   t->use_callback ? "callback" : "func",
544                   t->use_callback ? (void *)t->callback : (void *)t->func);
545
546         return false;
547 }
548
549 static void tasklet_action_common(struct softirq_action *a,
550                                   struct tasklet_head *tl_head,
551                                   unsigned int softirq_nr)
552 {
553         struct tasklet_struct *list;
554
555         local_irq_disable();
556         list = tl_head->head;
557         tl_head->head = NULL;
558         tl_head->tail = &tl_head->head;
559         local_irq_enable();
560
561         while (list) {
562                 struct tasklet_struct *t = list;
563
564                 list = list->next;
565
566                 if (tasklet_trylock(t)) {
567                         if (!atomic_read(&t->count)) {
568                                 if (tasklet_clear_sched(t)) {
569                                         if (t->use_callback)
570                                                 t->callback(t);
571                                         else
572                                                 t->func(t->data);
573                                 }
574                                 tasklet_unlock(t);
575                                 continue;
576                         }
577                         tasklet_unlock(t);
578                 }
579
580                 local_irq_disable();
581                 t->next = NULL;
582                 *tl_head->tail = t;
583                 tl_head->tail = &t->next;
584                 __raise_softirq_irqoff(softirq_nr);
585                 local_irq_enable();
586         }
587 }
588
589 static __latent_entropy void tasklet_action(struct softirq_action *a)
590 {
591         tasklet_action_common(a, this_cpu_ptr(&tasklet_vec), TASKLET_SOFTIRQ);
592 }
593
594 static __latent_entropy void tasklet_hi_action(struct softirq_action *a)
595 {
596         tasklet_action_common(a, this_cpu_ptr(&tasklet_hi_vec), HI_SOFTIRQ);
597 }
598
599 void tasklet_setup(struct tasklet_struct *t,
600                    void (*callback)(struct tasklet_struct *))
601 {
602         t->next = NULL;
603         t->state = 0;
604         atomic_set(&t->count, 0);
605         t->callback = callback;
606         t->use_callback = true;
607         t->data = 0;
608 }
609 EXPORT_SYMBOL(tasklet_setup);
610
611 void tasklet_init(struct tasklet_struct *t,
612                   void (*func)(unsigned long), unsigned long data)
613 {
614         t->next = NULL;
615         t->state = 0;
616         atomic_set(&t->count, 0);
617         t->func = func;
618         t->use_callback = false;
619         t->data = data;
620 }
621 EXPORT_SYMBOL(tasklet_init);
622
623 #if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT)
624 /*
625  * Do not use in new code. Waiting for tasklets from atomic contexts is
626  * error prone and should be avoided.
627  */
628 void tasklet_unlock_spin_wait(struct tasklet_struct *t)
629 {
630         while (test_bit(TASKLET_STATE_RUN, &(t)->state)) {
631                 if (IS_ENABLED(CONFIG_PREEMPT_RT)) {
632                         /*
633                          * Prevent a live lock when current preempted soft
634                          * interrupt processing or prevents ksoftirqd from
635                          * running. If the tasklet runs on a different CPU
636                          * then this has no effect other than doing the BH
637                          * disable/enable dance for nothing.
638                          */
639                         local_bh_disable();
640                         local_bh_enable();
641                 } else {
642                         cpu_relax();
643                 }
644         }
645 }
646 EXPORT_SYMBOL(tasklet_unlock_spin_wait);
647 #endif
648
649 void tasklet_kill(struct tasklet_struct *t)
650 {
651         if (in_interrupt())
652                 pr_notice("Attempt to kill tasklet from interrupt\n");
653
654         while (test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
655                 wait_var_event(&t->state, !test_bit(TASKLET_STATE_SCHED, &t->state));
656
657         tasklet_unlock_wait(t);
658         tasklet_clear_sched(t);
659 }
660 EXPORT_SYMBOL(tasklet_kill);
661
662 #if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT)
663 void tasklet_unlock(struct tasklet_struct *t)
664 {
665         smp_mb__before_atomic();
666         clear_bit(TASKLET_STATE_RUN, &t->state);
667         smp_mb__after_atomic();
668         wake_up_var(&t->state);
669 }
670 EXPORT_SYMBOL_GPL(tasklet_unlock);
671
672 void tasklet_unlock_wait(struct tasklet_struct *t)
673 {
674         wait_var_event(&t->state, !test_bit(TASKLET_STATE_RUN, &t->state));
675 }
676 EXPORT_SYMBOL_GPL(tasklet_unlock_wait);
677 #endif
678
679 void __init softirq_init(void)
680 {
681         int cpu;
682
683         for_each_possible_cpu(cpu) {
684                 per_cpu(tasklet_vec, cpu).tail =
685                         &per_cpu(tasklet_vec, cpu).head;
686                 per_cpu(tasklet_hi_vec, cpu).tail =
687                         &per_cpu(tasklet_hi_vec, cpu).head;
688         }
689
690         open_softirq(TASKLET_SOFTIRQ, tasklet_action);
691         open_softirq(HI_SOFTIRQ, tasklet_hi_action);
692 }
693
694 static int ksoftirqd_should_run(unsigned int cpu)
695 {
696         return local_softirq_pending();
697 }
698
699 static void run_ksoftirqd(unsigned int cpu)
700 {
701         local_irq_disable();
702         if (local_softirq_pending()) {
703                 /*
704                  * We can safely run softirq on inline stack, as we are not deep
705                  * in the task stack here.
706                  */
707                 __do_softirq();
708                 local_irq_enable();
709                 cond_resched();
710                 return;
711         }
712         local_irq_enable();
713 }
714
715 #ifdef CONFIG_HOTPLUG_CPU
716 static int takeover_tasklets(unsigned int cpu)
717 {
718         /* CPU is dead, so no lock needed. */
719         local_irq_disable();
720
721         /* Find end, append list for that CPU. */
722         if (&per_cpu(tasklet_vec, cpu).head != per_cpu(tasklet_vec, cpu).tail) {
723                 *__this_cpu_read(tasklet_vec.tail) = per_cpu(tasklet_vec, cpu).head;
724                 __this_cpu_write(tasklet_vec.tail, per_cpu(tasklet_vec, cpu).tail);
725                 per_cpu(tasklet_vec, cpu).head = NULL;
726                 per_cpu(tasklet_vec, cpu).tail = &per_cpu(tasklet_vec, cpu).head;
727         }
728         raise_softirq_irqoff(TASKLET_SOFTIRQ);
729
730         if (&per_cpu(tasklet_hi_vec, cpu).head != per_cpu(tasklet_hi_vec, cpu).tail) {
731                 *__this_cpu_read(tasklet_hi_vec.tail) = per_cpu(tasklet_hi_vec, cpu).head;
732                 __this_cpu_write(tasklet_hi_vec.tail, per_cpu(tasklet_hi_vec, cpu).tail);
733                 per_cpu(tasklet_hi_vec, cpu).head = NULL;
734                 per_cpu(tasklet_hi_vec, cpu).tail = &per_cpu(tasklet_hi_vec, cpu).head;
735         }
736         raise_softirq_irqoff(HI_SOFTIRQ);
737
738         local_irq_enable();
739         return 0;
740 }
741 #else
742 #define takeover_tasklets       NULL
743 #endif /* CONFIG_HOTPLUG_CPU */
744
745 static struct smp_hotplug_thread softirq_threads = {
746         .store                  = &ksoftirqd,
747         .thread_should_run      = ksoftirqd_should_run,
748         .thread_fn              = run_ksoftirqd,
749         .thread_comm            = "ksoftirqd/%u",
750 };
751
752 static __init int spawn_ksoftirqd(void)
753 {
754         cpuhp_setup_state_nocalls(CPUHP_SOFTIRQ_DEAD, "softirq:dead", NULL,
755                                   takeover_tasklets);
756         BUG_ON(smpboot_register_percpu_thread(&softirq_threads));
757
758         return 0;
759 }
760 early_initcall(spawn_ksoftirqd);
761
762 /*
763  * [ These __weak aliases are kept in a separate compilation unit, so that
764  *   GCC does not inline them incorrectly. ]
765  */
766
767 int __init __weak early_irq_init(void)
768 {
769         return 0;
770 }
771
772 int __init __weak arch_probe_nr_irqs(void)
773 {
774         return NR_IRQS_LEGACY;
775 }
776
777 int __init __weak arch_early_irq_init(void)
778 {
779         return 0;
780 }
781
782 unsigned int __weak arch_dynirq_lower_bound(unsigned int from)
783 {
784         return from;
785 }