migration.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/irq.h>
  3. #include <linux/interrupt.h>
  4. #include "internals.h"
  5. /**
  6. * irq_fixup_move_pending - Cleanup irq move pending from a dying CPU
  7. * @desc: Interrupt descriptor to clean up
  8. * @force_clear: If set clear the move pending bit unconditionally.
  9. * If not set, clear it only when the dying CPU is the
  10. * last one in the pending mask.
  11. *
  12. * Returns true if the pending bit was set and the pending mask contains an
  13. * online CPU other than the dying CPU.
  14. */
  15. bool irq_fixup_move_pending(struct irq_desc *desc, bool force_clear)
  16. {
  17. struct irq_data *data = irq_desc_get_irq_data(desc);
  18. if (!irqd_is_setaffinity_pending(data))
  19. return false;
  20. /*
  21. * The outgoing CPU might be the last online target in a pending
  22. * interrupt move. If that's the case clear the pending move bit.
  23. */
  24. if (!cpumask_intersects(desc->pending_mask, cpu_online_mask)) {
  25. irqd_clr_move_pending(data);
  26. return false;
  27. }
  28. if (force_clear)
  29. irqd_clr_move_pending(data);
  30. return true;
  31. }
  32. void irq_force_complete_move(struct irq_desc *desc)
  33. {
  34. for (struct irq_data *d = irq_desc_get_irq_data(desc); d; d = irqd_get_parent_data(d)) {
  35. if (d->chip && d->chip->irq_force_complete_move) {
  36. d->chip->irq_force_complete_move(d);
  37. return;
  38. }
  39. }
  40. }
  41. void irq_move_masked_irq(struct irq_data *idata)
  42. {
  43. struct irq_desc *desc = irq_data_to_desc(idata);
  44. struct irq_data *data = &desc->irq_data;
  45. struct irq_chip *chip = data->chip;
  46. if (likely(!irqd_is_setaffinity_pending(data)))
  47. return;
  48. irqd_clr_move_pending(data);
  49. /*
  50. * Paranoia: cpu-local interrupts shouldn't be calling in here anyway.
  51. */
  52. if (irqd_is_per_cpu(data)) {
  53. WARN_ON(1);
  54. return;
  55. }
  56. if (unlikely(cpumask_empty(desc->pending_mask)))
  57. return;
  58. if (!chip->irq_set_affinity)
  59. return;
  60. assert_raw_spin_locked(&desc->lock);
  61. /*
  62. * If there was a valid mask to work with, please
  63. * do the disable, re-program, enable sequence.
  64. * This is *not* particularly important for level triggered
  65. * but in a edge trigger case, we might be setting rte
  66. * when an active trigger is coming in. This could
  67. * cause some ioapics to mal-function.
  68. * Being paranoid i guess!
  69. *
  70. * For correct operation this depends on the caller
  71. * masking the irqs.
  72. */
  73. if (cpumask_intersects(desc->pending_mask, cpu_online_mask)) {
  74. int ret;
  75. ret = irq_do_set_affinity(data, desc->pending_mask, false);
  76. /*
  77. * If the there is a cleanup pending in the underlying
  78. * vector management, reschedule the move for the next
  79. * interrupt. Leave desc->pending_mask intact.
  80. */
  81. if (ret == -EBUSY) {
  82. irqd_set_move_pending(data);
  83. return;
  84. }
  85. }
  86. cpumask_clear(desc->pending_mask);
  87. }
  88. void __irq_move_irq(struct irq_data *idata)
  89. {
  90. bool masked;
  91. /*
  92. * Get top level irq_data when CONFIG_IRQ_DOMAIN_HIERARCHY is enabled,
  93. * and it should be optimized away when CONFIG_IRQ_DOMAIN_HIERARCHY is
  94. * disabled. So we avoid an "#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY" here.
  95. */
  96. idata = irq_desc_get_irq_data(irq_data_to_desc(idata));
  97. if (unlikely(irqd_irq_disabled(idata)))
  98. return;
  99. /*
  100. * Be careful vs. already masked interrupts. If this is a
  101. * threaded interrupt with ONESHOT set, we can end up with an
  102. * interrupt storm.
  103. */
  104. masked = irqd_irq_masked(idata);
  105. if (!masked)
  106. idata->chip->irq_mask(idata);
  107. irq_move_masked_irq(idata);
  108. if (!masked)
  109. idata->chip->irq_unmask(idata);
  110. }
  111. bool irq_can_move_in_process_context(struct irq_data *data)
  112. {
  113. /*
  114. * Get the top level irq_data in the hierarchy, which is optimized
  115. * away when CONFIG_IRQ_DOMAIN_HIERARCHY is disabled.
  116. */
  117. data = irq_desc_get_irq_data(irq_data_to_desc(data));
  118. return irq_can_move_pcntxt(data);
  119. }