Skip to content

Commit 536e2e3

Browse files
Marc ZyngierKAGA-KOKO
authored andcommitted
genirq/debugfs: Triggering of interrupts from userspace
When developing new (and therefore buggy) interrupt related code, it can sometimes be useful to inject interrupts without having to rely on a device to actually generate them. This functionnality relies either on the irqchip driver to expose a irq_set_irqchip_state(IRQCHIP_STATE_PENDING) callback, or on the core code to be able to retrigger a (edge-only) interrupt. To use this feature: echo -n trigger > /sys/kernel/debug/irq/irqs/IRQNUM WARNING: This is DANGEROUS, and strictly a debug feature. Do not use it on a production system. Your HW is likely to catch fire, your data to be corrupted, and reporting this will make you look an even bigger fool than the idiot who wrote this patch. Signed-off-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/20170818081156.9264-1-marc.zyngier@arm.com
1 parent 7cb2fad commit 536e2e3

1 file changed

Lines changed: 49 additions & 1 deletion

File tree

‎kernel/irq/debugfs.c‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#include <linux/irqdomain.h>
77
#include <linux/irq.h>
8+
#include <linux/uaccess.h>
89

910
#include "internals.h"
1011

@@ -171,8 +172,55 @@ static int irq_debug_open(struct inode *inode, struct file *file)
171172
return single_open(file, irq_debug_show, inode->i_private);
172173
}
173174

175+
static ssize_t irq_debug_write(struct file *file, const char __user *user_buf,
176+
size_t count, loff_t *ppos)
177+
{
178+
struct irq_desc *desc = file_inode(file)->i_private;
179+
char buf[8] = { 0, };
180+
size_t size;
181+
182+
size = min(sizeof(buf) - 1, count);
183+
if (copy_from_user(buf, user_buf, size))
184+
return -EFAULT;
185+
186+
if (!strncmp(buf, "trigger", size)) {
187+
unsigned long flags;
188+
int err;
189+
190+
/* Try the HW interface first */
191+
err = irq_set_irqchip_state(irq_desc_get_irq(desc),
192+
IRQCHIP_STATE_PENDING, true);
193+
if (!err)
194+
return count;
195+
196+
/*
197+
* Otherwise, try to inject via the resend interface,
198+
* which may or may not succeed.
199+
*/
200+
chip_bus_lock(desc);
201+
raw_spin_lock_irqsave(&desc->lock, flags);
202+
203+
if (irq_settings_is_level(desc)) {
204+
/* Can't do level, sorry */
205+
err = -EINVAL;
206+
} else {
207+
desc->istate |= IRQS_PENDING;
208+
check_irq_resend(desc);
209+
err = 0;
210+
}
211+
212+
raw_spin_unlock_irqrestore(&desc->lock, flags);
213+
chip_bus_sync_unlock(desc);
214+
215+
return err ? err : count;
216+
}
217+
218+
return count;
219+
}
220+
174221
static const struct file_operations dfs_irq_ops = {
175222
.open = irq_debug_open,
223+
.write = irq_debug_write,
176224
.read = seq_read,
177225
.llseek = seq_lseek,
178226
.release = single_release,
@@ -186,7 +234,7 @@ void irq_add_debugfs_entry(unsigned int irq, struct irq_desc *desc)
186234
return;
187235

188236
sprintf(name, "%d", irq);
189-
desc->debugfs_file = debugfs_create_file(name, 0444, irq_dir, desc,
237+
desc->debugfs_file = debugfs_create_file(name, 0644, irq_dir, desc,
190238
&dfs_irq_ops);
191239
}
192240

0 commit comments

Comments
 (0)