migration.c 2.9 KB

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