Skip to content

Commit 1f85b1f

Browse files
committed
genirq: Add return value to check_irq_resend()
In preparation for an interrupt injection interface which can be used safely by error injection mechanisms. e.g. PCI-E/ AER, add a return value to check_irq_resend() so errors can be propagated to the caller. Split out the software resend code so the ugly #ifdef in check_irq_resend() goes away and the whole thing becomes readable. Fix up the caller in debugfs. The caller in irq_startup() does not care about the return value as this is unconditionally invoked for all interrupts and the resend is best effort anyway. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Marc Zyngier <maz@kernel.org> Link: https://lkml.kernel.org/r/20200306130623.775200917@linutronix.de
1 parent 008f1d6 commit 1f85b1f

3 files changed

Lines changed: 51 additions & 37 deletions

File tree

‎kernel/irq/debugfs.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ static ssize_t irq_debug_write(struct file *file, const char __user *user_buf,
218218
err = -EINVAL;
219219
} else {
220220
desc->istate |= IRQS_PENDING;
221-
check_irq_resend(desc);
222-
err = 0;
221+
err = check_irq_resend(desc);
223222
}
224223

225224
raw_spin_unlock_irqrestore(&desc->lock, flags);

‎kernel/irq/internals.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ irqreturn_t handle_irq_event_percpu(struct irq_desc *desc);
108108
irqreturn_t handle_irq_event(struct irq_desc *desc);
109109

110110
/* Resending of interrupts :*/
111-
void check_irq_resend(struct irq_desc *desc);
111+
int check_irq_resend(struct irq_desc *desc);
112112
bool irq_wait_for_poll(struct irq_desc *desc);
113113
void __irq_wake_thread(struct irq_desc *desc, struct irqaction *action);
114114

‎kernel/irq/resend.c‎

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -47,57 +47,72 @@ static void resend_irqs(unsigned long arg)
4747
/* Tasklet to handle resend: */
4848
static DECLARE_TASKLET(resend_tasklet, resend_irqs, 0);
4949

50+
static int irq_sw_resend(struct irq_desc *desc)
51+
{
52+
unsigned int irq = irq_desc_get_irq(desc);
53+
54+
/*
55+
* Validate whether this interrupt can be safely injected from
56+
* non interrupt context
57+
*/
58+
if (handle_enforce_irqctx(&desc->irq_data))
59+
return -EINVAL;
60+
61+
/*
62+
* If the interrupt is running in the thread context of the parent
63+
* irq we need to be careful, because we cannot trigger it
64+
* directly.
65+
*/
66+
if (irq_settings_is_nested_thread(desc)) {
67+
/*
68+
* If the parent_irq is valid, we retrigger the parent,
69+
* otherwise we do nothing.
70+
*/
71+
if (!desc->parent_irq)
72+
return -EINVAL;
73+
irq = desc->parent_irq;
74+
}
75+
76+
/* Set it pending and activate the softirq: */
77+
set_bit(irq, irqs_resend);
78+
tasklet_schedule(&resend_tasklet);
79+
return 0;
80+
}
81+
82+
#else
83+
static int irq_sw_resend(struct irq_desc *desc)
84+
{
85+
return -EINVAL;
86+
}
5087
#endif
5188

5289
/*
5390
* IRQ resend
5491
*
5592
* Is called with interrupts disabled and desc->lock held.
5693
*/
57-
void check_irq_resend(struct irq_desc *desc)
94+
int check_irq_resend(struct irq_desc *desc)
5895
{
5996
/*
60-
* We do not resend level type interrupts. Level type
61-
* interrupts are resent by hardware when they are still
62-
* active. Clear the pending bit so suspend/resume does not
63-
* get confused.
97+
* We do not resend level type interrupts. Level type interrupts
98+
* are resent by hardware when they are still active. Clear the
99+
* pending bit so suspend/resume does not get confused.
64100
*/
65101
if (irq_settings_is_level(desc)) {
66102
desc->istate &= ~IRQS_PENDING;
67-
return;
103+
return -EINVAL;
68104
}
105+
69106
if (desc->istate & IRQS_REPLAY)
70-
return;
107+
return -EBUSY;
108+
71109
if (desc->istate & IRQS_PENDING) {
72110
desc->istate &= ~IRQS_PENDING;
73111
desc->istate |= IRQS_REPLAY;
74112

75-
if ((!desc->irq_data.chip->irq_retrigger ||
76-
!desc->irq_data.chip->irq_retrigger(&desc->irq_data)) &&
77-
!handle_enforce_irqctx(&desc->irq_data)) {
78-
#ifdef CONFIG_HARDIRQS_SW_RESEND
79-
unsigned int irq = irq_desc_get_irq(desc);
80-
81-
/*
82-
* If the interrupt is running in the thread
83-
* context of the parent irq we need to be
84-
* careful, because we cannot trigger it
85-
* directly.
86-
*/
87-
if (irq_settings_is_nested_thread(desc)) {
88-
/*
89-
* If the parent_irq is valid, we
90-
* retrigger the parent, otherwise we
91-
* do nothing.
92-
*/
93-
if (!desc->parent_irq)
94-
return;
95-
irq = desc->parent_irq;
96-
}
97-
/* Set it pending and activate the softirq: */
98-
set_bit(irq, irqs_resend);
99-
tasklet_schedule(&resend_tasklet);
100-
#endif
101-
}
113+
if (!desc->irq_data.chip->irq_retrigger ||
114+
!desc->irq_data.chip->irq_retrigger(&desc->irq_data))
115+
return irq_sw_resend(desc);
102116
}
117+
return 0;
103118
}

0 commit comments

Comments
 (0)