aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/irq/manage.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/irq/manage.c')
-rw-r--r--kernel/irq/manage.c157
1 files changed, 86 insertions, 71 deletions
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 89a3ea82569b..8c548232ba39 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -7,6 +7,8 @@
7 * This file contains driver APIs to the irq subsystem. 7 * This file contains driver APIs to the irq subsystem.
8 */ 8 */
9 9
10#define pr_fmt(fmt) "genirq: " fmt
11
10#include <linux/irq.h> 12#include <linux/irq.h>
11#include <linux/kthread.h> 13#include <linux/kthread.h>
12#include <linux/module.h> 14#include <linux/module.h>
@@ -14,6 +16,7 @@
14#include <linux/interrupt.h> 16#include <linux/interrupt.h>
15#include <linux/slab.h> 17#include <linux/slab.h>
16#include <linux/sched.h> 18#include <linux/sched.h>
19#include <linux/task_work.h>
17 20
18#include "internals.h" 21#include "internals.h"
19 22
@@ -139,6 +142,25 @@ static inline void
139irq_get_pending(struct cpumask *mask, struct irq_desc *desc) { } 142irq_get_pending(struct cpumask *mask, struct irq_desc *desc) { }
140#endif 143#endif
141 144
145int irq_do_set_affinity(struct irq_data *data, const struct cpumask *mask,
146 bool force)
147{
148 struct irq_desc *desc = irq_data_to_desc(data);
149 struct irq_chip *chip = irq_data_get_irq_chip(data);
150 int ret;
151
152 ret = chip->irq_set_affinity(data, mask, false);
153 switch (ret) {
154 case IRQ_SET_MASK_OK:
155 cpumask_copy(data->affinity, mask);
156 case IRQ_SET_MASK_OK_NOCOPY:
157 irq_set_thread_affinity(desc);
158 ret = 0;
159 }
160
161 return ret;
162}
163
142int __irq_set_affinity_locked(struct irq_data *data, const struct cpumask *mask) 164int __irq_set_affinity_locked(struct irq_data *data, const struct cpumask *mask)
143{ 165{
144 struct irq_chip *chip = irq_data_get_irq_chip(data); 166 struct irq_chip *chip = irq_data_get_irq_chip(data);
@@ -149,14 +171,7 @@ int __irq_set_affinity_locked(struct irq_data *data, const struct cpumask *mask)
149 return -EINVAL; 171 return -EINVAL;
150 172
151 if (irq_can_move_pcntxt(data)) { 173 if (irq_can_move_pcntxt(data)) {
152 ret = chip->irq_set_affinity(data, mask, false); 174 ret = irq_do_set_affinity(data, mask, false);
153 switch (ret) {
154 case IRQ_SET_MASK_OK:
155 cpumask_copy(data->affinity, mask);
156 case IRQ_SET_MASK_OK_NOCOPY:
157 irq_set_thread_affinity(desc);
158 ret = 0;
159 }
160 } else { 175 } else {
161 irqd_set_move_pending(data); 176 irqd_set_move_pending(data);
162 irq_copy_pending(desc, mask); 177 irq_copy_pending(desc, mask);
@@ -280,9 +295,8 @@ EXPORT_SYMBOL_GPL(irq_set_affinity_notifier);
280static int 295static int
281setup_affinity(unsigned int irq, struct irq_desc *desc, struct cpumask *mask) 296setup_affinity(unsigned int irq, struct irq_desc *desc, struct cpumask *mask)
282{ 297{
283 struct irq_chip *chip = irq_desc_get_chip(desc);
284 struct cpumask *set = irq_default_affinity; 298 struct cpumask *set = irq_default_affinity;
285 int ret, node = desc->irq_data.node; 299 int node = desc->irq_data.node;
286 300
287 /* Excludes PER_CPU and NO_BALANCE interrupts */ 301 /* Excludes PER_CPU and NO_BALANCE interrupts */
288 if (!irq_can_set_affinity(irq)) 302 if (!irq_can_set_affinity(irq))
@@ -308,13 +322,7 @@ setup_affinity(unsigned int irq, struct irq_desc *desc, struct cpumask *mask)
308 if (cpumask_intersects(mask, nodemask)) 322 if (cpumask_intersects(mask, nodemask))
309 cpumask_and(mask, mask, nodemask); 323 cpumask_and(mask, mask, nodemask);
310 } 324 }
311 ret = chip->irq_set_affinity(&desc->irq_data, mask, false); 325 irq_do_set_affinity(&desc->irq_data, mask, false);
312 switch (ret) {
313 case IRQ_SET_MASK_OK:
314 cpumask_copy(desc->irq_data.affinity, mask);
315 case IRQ_SET_MASK_OK_NOCOPY:
316 irq_set_thread_affinity(desc);
317 }
318 return 0; 326 return 0;
319} 327}
320#else 328#else
@@ -566,7 +574,7 @@ int __irq_set_trigger(struct irq_desc *desc, unsigned int irq,
566 * flow-types? 574 * flow-types?
567 */ 575 */
568 pr_debug("No set_type function for IRQ %d (%s)\n", irq, 576 pr_debug("No set_type function for IRQ %d (%s)\n", irq,
569 chip ? (chip->name ? : "unknown") : "unknown"); 577 chip ? (chip->name ? : "unknown") : "unknown");
570 return 0; 578 return 0;
571 } 579 }
572 580
@@ -600,7 +608,7 @@ int __irq_set_trigger(struct irq_desc *desc, unsigned int irq,
600 ret = 0; 608 ret = 0;
601 break; 609 break;
602 default: 610 default:
603 pr_err("setting trigger mode %lu for irq %u failed (%pF)\n", 611 pr_err("Setting trigger mode %lu for irq %u failed (%pF)\n",
604 flags, irq, chip->irq_set_type); 612 flags, irq, chip->irq_set_type);
605 } 613 }
606 if (unmask) 614 if (unmask)
@@ -773,11 +781,39 @@ static void wake_threads_waitq(struct irq_desc *desc)
773 wake_up(&desc->wait_for_threads); 781 wake_up(&desc->wait_for_threads);
774} 782}
775 783
784static void irq_thread_dtor(struct task_work *unused)
785{
786 struct task_struct *tsk = current;
787 struct irq_desc *desc;
788 struct irqaction *action;
789
790 if (WARN_ON_ONCE(!(current->flags & PF_EXITING)))
791 return;
792
793 action = kthread_data(tsk);
794
795 pr_err("exiting task \"%s\" (%d) is an active IRQ thread (irq %d)\n",
796 tsk->comm ? tsk->comm : "", tsk->pid, action->irq);
797
798
799 desc = irq_to_desc(action->irq);
800 /*
801 * If IRQTF_RUNTHREAD is set, we need to decrement
802 * desc->threads_active and wake possible waiters.
803 */
804 if (test_and_clear_bit(IRQTF_RUNTHREAD, &action->thread_flags))
805 wake_threads_waitq(desc);
806
807 /* Prevent a stale desc->threads_oneshot */
808 irq_finalize_oneshot(desc, action);
809}
810
776/* 811/*
777 * Interrupt handler thread 812 * Interrupt handler thread
778 */ 813 */
779static int irq_thread(void *data) 814static int irq_thread(void *data)
780{ 815{
816 struct task_work on_exit_work;
781 static const struct sched_param param = { 817 static const struct sched_param param = {
782 .sched_priority = MAX_USER_RT_PRIO/2, 818 .sched_priority = MAX_USER_RT_PRIO/2,
783 }; 819 };
@@ -793,7 +829,9 @@ static int irq_thread(void *data)
793 handler_fn = irq_thread_fn; 829 handler_fn = irq_thread_fn;
794 830
795 sched_setscheduler(current, SCHED_FIFO, &param); 831 sched_setscheduler(current, SCHED_FIFO, &param);
796 current->irq_thread = 1; 832
833 init_task_work(&on_exit_work, irq_thread_dtor, NULL);
834 task_work_add(current, &on_exit_work, false);
797 835
798 while (!irq_wait_for_interrupt(action)) { 836 while (!irq_wait_for_interrupt(action)) {
799 irqreturn_t action_ret; 837 irqreturn_t action_ret;
@@ -815,45 +853,11 @@ static int irq_thread(void *data)
815 * cannot touch the oneshot mask at this point anymore as 853 * cannot touch the oneshot mask at this point anymore as
816 * __setup_irq() might have given out currents thread_mask 854 * __setup_irq() might have given out currents thread_mask
817 * again. 855 * again.
818 *
819 * Clear irq_thread. Otherwise exit_irq_thread() would make
820 * fuzz about an active irq thread going into nirvana.
821 */ 856 */
822 current->irq_thread = 0; 857 task_work_cancel(current, irq_thread_dtor);
823 return 0; 858 return 0;
824} 859}
825 860
826/*
827 * Called from do_exit()
828 */
829void exit_irq_thread(void)
830{
831 struct task_struct *tsk = current;
832 struct irq_desc *desc;
833 struct irqaction *action;
834
835 if (!tsk->irq_thread)
836 return;
837
838 action = kthread_data(tsk);
839
840 printk(KERN_ERR
841 "exiting task \"%s\" (%d) is an active IRQ thread (irq %d)\n",
842 tsk->comm ? tsk->comm : "", tsk->pid, action->irq);
843
844 desc = irq_to_desc(action->irq);
845
846 /*
847 * If IRQTF_RUNTHREAD is set, we need to decrement
848 * desc->threads_active and wake possible waiters.
849 */
850 if (test_and_clear_bit(IRQTF_RUNTHREAD, &action->thread_flags))
851 wake_threads_waitq(desc);
852
853 /* Prevent a stale desc->threads_oneshot */
854 irq_finalize_oneshot(desc, action);
855}
856
857static void irq_setup_forced_threading(struct irqaction *new) 861static void irq_setup_forced_threading(struct irqaction *new)
858{ 862{
859 if (!force_irqthreads) 863 if (!force_irqthreads)
@@ -878,7 +882,6 @@ static int
878__setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new) 882__setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
879{ 883{
880 struct irqaction *old, **old_ptr; 884 struct irqaction *old, **old_ptr;
881 const char *old_name = NULL;
882 unsigned long flags, thread_mask = 0; 885 unsigned long flags, thread_mask = 0;
883 int ret, nested, shared = 0; 886 int ret, nested, shared = 0;
884 cpumask_var_t mask; 887 cpumask_var_t mask;
@@ -972,10 +975,8 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
972 */ 975 */
973 if (!((old->flags & new->flags) & IRQF_SHARED) || 976 if (!((old->flags & new->flags) & IRQF_SHARED) ||
974 ((old->flags ^ new->flags) & IRQF_TRIGGER_MASK) || 977 ((old->flags ^ new->flags) & IRQF_TRIGGER_MASK) ||
975 ((old->flags ^ new->flags) & IRQF_ONESHOT)) { 978 ((old->flags ^ new->flags) & IRQF_ONESHOT))
976 old_name = old->name;
977 goto mismatch; 979 goto mismatch;
978 }
979 980
980 /* All handlers must agree on per-cpuness */ 981 /* All handlers must agree on per-cpuness */
981 if ((old->flags & IRQF_PERCPU) != 982 if ((old->flags & IRQF_PERCPU) !=
@@ -1031,6 +1032,27 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
1031 * all existing action->thread_mask bits. 1032 * all existing action->thread_mask bits.
1032 */ 1033 */
1033 new->thread_mask = 1 << ffz(thread_mask); 1034 new->thread_mask = 1 << ffz(thread_mask);
1035
1036 } else if (new->handler == irq_default_primary_handler) {
1037 /*
1038 * The interrupt was requested with handler = NULL, so
1039 * we use the default primary handler for it. But it
1040 * does not have the oneshot flag set. In combination
1041 * with level interrupts this is deadly, because the
1042 * default primary handler just wakes the thread, then
1043 * the irq lines is reenabled, but the device still
1044 * has the level irq asserted. Rinse and repeat....
1045 *
1046 * While this works for edge type interrupts, we play
1047 * it safe and reject unconditionally because we can't
1048 * say for sure which type this interrupt really
1049 * has. The type flags are unreliable as the
1050 * underlying chip implementation can override them.
1051 */
1052 pr_err("Threaded irq requested with handler=NULL and !ONESHOT for irq %d\n",
1053 irq);
1054 ret = -EINVAL;
1055 goto out_mask;
1034 } 1056 }
1035 1057
1036 if (!shared) { 1058 if (!shared) {
@@ -1078,7 +1100,7 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
1078 1100
1079 if (nmsk != omsk) 1101 if (nmsk != omsk)
1080 /* hope the handler works with current trigger mode */ 1102 /* hope the handler works with current trigger mode */
1081 pr_warning("IRQ %d uses trigger mode %u; requested %u\n", 1103 pr_warning("irq %d uses trigger mode %u; requested %u\n",
1082 irq, nmsk, omsk); 1104 irq, nmsk, omsk);
1083 } 1105 }
1084 1106
@@ -1115,14 +1137,13 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
1115 return 0; 1137 return 0;
1116 1138
1117mismatch: 1139mismatch:
1118#ifdef CONFIG_DEBUG_SHIRQ
1119 if (!(new->flags & IRQF_PROBE_SHARED)) { 1140 if (!(new->flags & IRQF_PROBE_SHARED)) {
1120 printk(KERN_ERR "IRQ handler type mismatch for IRQ %d\n", irq); 1141 pr_err("Flags mismatch irq %d. %08x (%s) vs. %08x (%s)\n",
1121 if (old_name) 1142 irq, new->flags, new->name, old->flags, old->name);
1122 printk(KERN_ERR "current handler: %s\n", old_name); 1143#ifdef CONFIG_DEBUG_SHIRQ
1123 dump_stack(); 1144 dump_stack();
1124 }
1125#endif 1145#endif
1146 }
1126 ret = -EBUSY; 1147 ret = -EBUSY;
1127 1148
1128out_mask: 1149out_mask:
@@ -1204,12 +1225,6 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
1204 /* Found it - now remove it from the list of entries: */ 1225 /* Found it - now remove it from the list of entries: */
1205 *action_ptr = action->next; 1226 *action_ptr = action->next;
1206 1227
1207 /* Currently used only by UML, might disappear one day: */
1208#ifdef CONFIG_IRQ_RELEASE_METHOD
1209 if (desc->irq_data.chip->release)
1210 desc->irq_data.chip->release(irq, dev_id);
1211#endif
1212
1213 /* If this was the last handler, shut down the IRQ line: */ 1228 /* If this was the last handler, shut down the IRQ line: */
1214 if (!desc->action) 1229 if (!desc->action)
1215 irq_shutdown(desc); 1230 irq_shutdown(desc);