Skip to contentSkip to conversation

linux/interrupt.h: allow "guard" notation to disable and reenable IRQ

PATCH In review Dmitry Torokhov 2 participants 4 messages May 30, 2024 – Jun 6, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux/interrupt.h: allow "guard" notation to disable and reenable IRQ

Drivers often need to first disable an interrupt, carry out some action, and then reenable the interrupt. Introduce support for the "guard" notation for this so that the following is possible:

	...

	scoped_cond_guard(mutex_intr, return -EINTR, &data->sysfs_mutex) {
		guard(disable_irq)(&client->irq);

		error = elan_acquire_baseline(data);
		if (error)
			return error;
	}

	...
---
 include/linux/interrupt.h | 4 ++++
 1 file changed, 4 insertions(+)
include/linux/interrupt.h +4 -0
index 5c9bdd3ffccc..3a36e64119c8 100644
@@ -5,6 +5,7 @@
 
 #include <linux/kernel.h>
 #include <linux/bitops.h>
+#include <linux/cleanup.h>
 #include <linux/cpumask.h>
 #include <linux/irqreturn.h>
 #include <linux/irqnr.h>
@@ -235,6 +236,9 @@ extern void enable_percpu_irq(unsigned int irq, unsigned int type);
 extern bool irq_percpu_is_enabled(unsigned int irq);
 extern void irq_wake_thread(unsigned int irq, void *dev_id);
 
+DEFINE_LOCK_GUARD_1(disable_irq, int,
+		    disable_irq(*_T->lock), enable_irq(*_T->lock))
+
 extern void disable_nmi_nosync(unsigned int irq);
 extern void disable_percpu_nmi(unsigned int irq);
 extern void enable_nmi(unsigned int irq);
Signature · 5 lines
2.45.1.288.g0e0cd299f1-goog


-- 
Dmitry
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Dmitry Torokhov

Drivers often need to first disable an interrupt, carry out some action, and then reenable the interrupt. Introduce support for the "guard" notation for this so that the following is possible:

	...

	scoped_cond_guard(mutex_intr, return -EINTR, &data->sysfs_mutex) {
		guard(disable_irq)(&client->irq);

		error = elan_acquire_baseline(data);
		if (error)
			return error;
	}

	...
Quoted 1 line

I assume you want to carry this through the input tree, so you can modify the drivers.

If so:

#2 lore raw
Quoted 17 lines · Thomas Gleixner
Quoted 16 lines · Dmitry Torokhov

Drivers often need to first disable an interrupt, carry out some action, and then reenable the interrupt. Introduce support for the "guard" notation for this so that the following is possible:

	...

	scoped_cond_guard(mutex_intr, return -EINTR, &data->sysfs_mutex) {
		guard(disable_irq)(&client->irq);

		error = elan_acquire_baseline(data);
		if (error)
			return error;
	}

	...
Quoted 8 lines
Quoted 1 line

I assume you want to carry this through the input tree, so you can modify the drivers.

If so:

Thanks Thomas. I'll stick this patch into an immutable branch off v6.9 in case you (or someone else) wants to pull it in and start using it.

Thanks.

Signature · 1 line
Dmitry
#3 lore raw
Quoted 23 lines · Dmitry Torokhov
Quoted 22 lines · Thomas Gleixner
Quoted 16 lines · Dmitry Torokhov

Drivers often need to first disable an interrupt, carry out some action, and then reenable the interrupt. Introduce support for the "guard" notation for this so that the following is possible:

	...

	scoped_cond_guard(mutex_intr, return -EINTR, &data->sysfs_mutex) {
		guard(disable_irq)(&client->irq);

		error = elan_acquire_baseline(data);
		if (error)
			return error;
	}

	...
Quoted 1 line

I assume you want to carry this through the input tree, so you can modify the drivers.

Quoted 6 lines
Quoted 3 lines

If so:

Thanks Thomas. I'll stick this patch into an immutable branch off v6.9 in case you (or someone else) wants to pull it in and start using it.

I made:

git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git ib/6.9-disable-irq-guard

Thanks.

Signature · 1 line
Dmitry