mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RCF PATCH] genirq/debugfs: Triggering of interrupts from userspace
@ 2017-07-20 15:51 Marc Zyngier
  2017-08-16 14:50 ` Thomas Gleixner
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Zyngier @ 2017-07-20 15:51 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: linux-kernel

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 on the irqchip driver to expose
a irq_set_irqchip_state(IRQCHIP_STATE_PENDING) callback.

To use this feature:

echo -n trigger > /sys/kernel/debug/irq/irqs/IRQNUM

WARNING: This is 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>
---
 kernel/irq/debugfs.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/kernel/irq/debugfs.c b/kernel/irq/debugfs.c
index 4d384edc0c64..8b59bf121066 100644
--- a/kernel/irq/debugfs.c
+++ b/kernel/irq/debugfs.c
@@ -5,6 +5,7 @@
  */
 #include <linux/irqdomain.h>
 #include <linux/irq.h>
+#include <linux/uaccess.h>
 
 #include "internals.h"
 
@@ -171,8 +172,32 @@ static int irq_debug_open(struct inode *inode, struct file *file)
 	return single_open(file, irq_debug_show, inode->i_private);
 }
 
+static ssize_t irq_debug_write(struct file *file, const char __user *user_buf,
+			       size_t count, loff_t *ppos)
+{
+	struct irq_desc *desc = file_inode(file)->i_private;
+	char buf[8] = { 0, };
+	size_t size;
+
+	size = min(sizeof(buf) - 1, count);
+	if (copy_from_user(buf, user_buf, size))
+		return -EFAULT;
+
+	if (!strncmp(buf, "trigger", size)) {
+		int err;
+
+		err = irq_set_irqchip_state(irq_desc_get_irq(desc),
+					    IRQCHIP_STATE_PENDING, true);
+		if (err)
+			return err;
+	}
+
+	return count;
+}
+
 static const struct file_operations dfs_irq_ops = {
 	.open		= irq_debug_open,
+	.write		= irq_debug_write,
 	.read		= seq_read,
 	.llseek		= seq_lseek,
 	.release	= single_release,
@@ -186,7 +211,7 @@ void irq_add_debugfs_entry(unsigned int irq, struct irq_desc *desc)
 		return;
 
 	sprintf(name, "%d", irq);
-	desc->debugfs_file = debugfs_create_file(name, 0444, irq_dir, desc,
+	desc->debugfs_file = debugfs_create_file(name, 0644, irq_dir, desc,
 						 &dfs_irq_ops);
 }
 
-- 
2.11.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RCF PATCH] genirq/debugfs: Triggering of interrupts from userspace
  2017-07-20 15:51 [RCF PATCH] genirq/debugfs: Triggering of interrupts from userspace Marc Zyngier
@ 2017-08-16 14:50 ` Thomas Gleixner
  2017-08-16 14:58   ` Marc Zyngier
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Gleixner @ 2017-08-16 14:50 UTC (permalink / raw)
  To: Marc Zyngier; +Cc: linux-kernel

On Thu, 20 Jul 2017, Marc Zyngier wrote:
> 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 on the irqchip driver to expose
> a irq_set_irqchip_state(IRQCHIP_STATE_PENDING) callback.

I like that, but can we please extend that to utilize the irq resend
mechanism:

	desc = ....;

	chip_bus_lock(desc);
        raw_spin_lock_irq(&desc->lock);

	if (has_set_state(desc))
		set_state(desc);
	else
		check_irq_resend(desc);

or something to that effect?

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RCF PATCH] genirq/debugfs: Triggering of interrupts from userspace
  2017-08-16 14:50 ` Thomas Gleixner
@ 2017-08-16 14:58   ` Marc Zyngier
  0 siblings, 0 replies; 3+ messages in thread
From: Marc Zyngier @ 2017-08-16 14:58 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: linux-kernel

On 16/08/17 15:50, Thomas Gleixner wrote:
> On Thu, 20 Jul 2017, Marc Zyngier wrote:
>> 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 on the irqchip driver to expose
>> a irq_set_irqchip_state(IRQCHIP_STATE_PENDING) callback.
> 
> I like that, but can we please extend that to utilize the irq resend
> mechanism:
> 
> 	desc = ....;
> 
> 	chip_bus_lock(desc);
>         raw_spin_lock_irq(&desc->lock);
> 
> 	if (has_set_state(desc))
> 		set_state(desc);
> 	else
> 		check_irq_resend(desc);
> 
> or something to that effect?
Definitely. That'd allow more HW to be supported. I'll have a look.

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-08-16 14:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-20 15:51 [RCF PATCH] genirq/debugfs: Triggering of interrupts from userspace Marc Zyngier
2017-08-16 14:50 ` Thomas Gleixner
2017-08-16 14:58   ` Marc Zyngier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®