Skip to content

Commit fe200ae

Browse files
committed
genirq: Mark polled irqs and defer the real handler
With the chip.end() function gone we might run into a situation where a poll call runs and the real interrupt comes in, sees IRQ_INPROGRESS and disables the line. That might be a perfect working one, which will then be masked forever. So mark them polled while the poll runs. When the real handler sees IRQ_INPROGRESS it checks the poll flag and waits for the polling to complete. Add the necessary amount of sanity checks to it to avoid deadlocks. Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent d05c65f commit fe200ae

4 files changed

Lines changed: 61 additions & 28 deletions

File tree

‎include/linux/irq.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ typedef void (*irq_flow_handler_t)(unsigned int irq,
7171
#define IRQ_SUSPENDED 0x04000000 /* IRQ has gone through suspend sequence */
7272
#define IRQ_ONESHOT 0x08000000 /* IRQ is not unmasked after hardirq */
7373
#define IRQ_NESTED_THREAD 0x10000000 /* IRQ is nested into another, no own handler thread */
74+
#define IRQ_POLL_INPROGRESS 0x20000000 /* IRQ poll is in progress */
7475

7576
#define IRQF_MODIFY_MASK \
7677
(IRQ_TYPE_SENSE_MASK | IRQ_NOPROBE | IRQ_NOREQUEST | \

‎kernel/irq/chip.c‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,13 @@ void handle_nested_irq(unsigned int irq)
448448
}
449449
EXPORT_SYMBOL_GPL(handle_nested_irq);
450450

451+
static bool irq_check_poll(struct irq_desc *desc)
452+
{
453+
if (!(desc->status & IRQ_POLL_INPROGRESS))
454+
return false;
455+
return irq_wait_for_poll(desc);
456+
}
457+
451458
/**
452459
* handle_simple_irq - Simple and software-decoded IRQs.
453460
* @irq: the interrupt number
@@ -469,7 +476,9 @@ handle_simple_irq(unsigned int irq, struct irq_desc *desc)
469476
raw_spin_lock(&desc->lock);
470477

471478
if (unlikely(desc->status & IRQ_INPROGRESS))
472-
goto out_unlock;
479+
if (!irq_check_poll(desc))
480+
goto out_unlock;
481+
473482
desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
474483
kstat_incr_irqs_this_cpu(irq, desc);
475484

@@ -510,7 +519,9 @@ handle_level_irq(unsigned int irq, struct irq_desc *desc)
510519
mask_ack_irq(desc);
511520

512521
if (unlikely(desc->status & IRQ_INPROGRESS))
513-
goto out_unlock;
522+
if (!irq_check_poll(desc))
523+
goto out_unlock;
524+
514525
desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
515526
kstat_incr_irqs_this_cpu(irq, desc);
516527

@@ -558,7 +569,8 @@ handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
558569
raw_spin_lock(&desc->lock);
559570

560571
if (unlikely(desc->status & IRQ_INPROGRESS))
561-
goto out;
572+
if (!irq_check_poll(desc))
573+
goto out;
562574

563575
desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
564576
kstat_incr_irqs_this_cpu(irq, desc);
@@ -620,9 +632,11 @@ handle_edge_irq(unsigned int irq, struct irq_desc *desc)
620632
*/
621633
if (unlikely((desc->status & (IRQ_INPROGRESS | IRQ_DISABLED)) ||
622634
!desc->action)) {
623-
desc->status |= (IRQ_PENDING | IRQ_MASKED);
624-
mask_ack_irq(desc);
625-
goto out_unlock;
635+
if (!irq_check_poll(desc)) {
636+
desc->status |= (IRQ_PENDING | IRQ_MASKED);
637+
mask_ack_irq(desc);
638+
goto out_unlock;
639+
}
626640
}
627641
kstat_incr_irqs_this_cpu(irq, desc);
628642

‎kernel/irq/internals.h‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern void init_kstat_irqs(struct irq_desc *desc, int node, int nr);
2828

2929
/* Resending of interrupts :*/
3030
void check_irq_resend(struct irq_desc *desc, unsigned int irq);
31+
bool irq_wait_for_poll(struct irq_desc *desc);
3132

3233
#ifdef CONFIG_PROC_FS
3334
extern void register_irq_proc(unsigned int irq, struct irq_desc *desc);
@@ -47,16 +48,6 @@ extern int irq_select_affinity_usr(unsigned int irq, struct cpumask *mask);
4748

4849
extern void irq_set_thread_affinity(struct irq_desc *desc);
4950

50-
#ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
51-
static inline void irq_end(unsigned int irq, struct irq_desc *desc)
52-
{
53-
if (desc->irq_data.chip && desc->irq_data.chip->end)
54-
desc->irq_data.chip->end(irq);
55-
}
56-
#else
57-
static inline void irq_end(unsigned int irq, struct irq_desc *desc) { }
58-
#endif
59-
6051
/* Inline functions for support of irq chips on slow busses */
6152
static inline void chip_bus_lock(struct irq_desc *desc)
6253
{

‎kernel/irq/spurious.c‎

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,45 @@ static DEFINE_TIMER(poll_spurious_irq_timer, poll_spurious_irqs, 0, 0);
2424
static int irq_poll_cpu;
2525
static atomic_t irq_poll_active;
2626

27+
/*
28+
* We wait here for a poller to finish.
29+
*
30+
* If the poll runs on this CPU, then we yell loudly and return
31+
* false. That will leave the interrupt line disabled in the worst
32+
* case, but it should never happen.
33+
*
34+
* We wait until the poller is done and then recheck disabled and
35+
* action (about to be disabled). Only if it's still active, we return
36+
* true and let the handler run.
37+
*/
38+
bool irq_wait_for_poll(struct irq_desc *desc)
39+
{
40+
if (WARN_ONCE(irq_poll_cpu == smp_processor_id(),
41+
"irq poll in progress on cpu %d for irq %d\n",
42+
smp_processor_id(), desc->irq_data.irq))
43+
return false;
44+
45+
#ifdef CONFIG_SMP
46+
do {
47+
raw_spin_unlock(&desc->lock);
48+
while (desc->status & IRQ_INPROGRESS)
49+
cpu_relax();
50+
raw_spin_lock(&desc->lock);
51+
} while (desc->status & IRQ_INPROGRESS);
52+
/* Might have been disabled in meantime */
53+
return !(desc->status & IRQ_DISABLED) && desc->action;
54+
#else
55+
return false;
56+
#endif
57+
}
58+
2759
/*
2860
* Recovery handler for misrouted interrupts.
2961
*/
3062
static int try_one_irq(int irq, struct irq_desc *desc, bool force)
3163
{
3264
struct irqaction *action;
33-
int ok = 0, work = 0;
65+
int ok = 0;
3466

3567
raw_spin_lock(&desc->lock);
3668

@@ -64,10 +96,9 @@ static int try_one_irq(int irq, struct irq_desc *desc, bool force)
6496
goto out;
6597
}
6698

67-
/* Honour the normal IRQ locking */
68-
desc->status |= IRQ_INPROGRESS;
99+
/* Honour the normal IRQ locking and mark it poll in progress */
100+
desc->status |= IRQ_INPROGRESS | IRQ_POLL_INPROGRESS;
69101
do {
70-
work++;
71102
desc->status &= ~IRQ_PENDING;
72103
raw_spin_unlock(&desc->lock);
73104
if (handle_IRQ_event(irq, action) != IRQ_NONE)
@@ -76,14 +107,7 @@ static int try_one_irq(int irq, struct irq_desc *desc, bool force)
76107
action = desc->action;
77108
} while ((desc->status & IRQ_PENDING) && action);
78109

79-
desc->status &= ~IRQ_INPROGRESS;
80-
/*
81-
* If we did actual work for the real IRQ line we must let the
82-
* IRQ controller clean up too
83-
*/
84-
if (work > 1)
85-
irq_end(irq, desc);
86-
110+
desc->status &= ~(IRQ_INPROGRESS | IRQ_POLL_INPROGRESS);
87111
out:
88112
raw_spin_unlock(&desc->lock);
89113
return ok;
@@ -238,6 +262,9 @@ try_misrouted_irq(unsigned int irq, struct irq_desc *desc,
238262
void note_interrupt(unsigned int irq, struct irq_desc *desc,
239263
irqreturn_t action_ret)
240264
{
265+
if (desc->status & IRQ_POLL_INPROGRESS)
266+
return;
267+
241268
if (unlikely(action_ret != IRQ_HANDLED)) {
242269
/*
243270
* If we are seeing only the odd spurious IRQ caused by

0 commit comments

Comments
 (0)