lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260115074909.245852-2-crajank@nvidia.com>
Date: Thu, 15 Jan 2026 09:49:08 +0200
From: Ciju Rajan K <crajank@...dia.com>
To: <hdegoede@...hat.com>, <ilpo.jarvinen@...ux.intel.com>,
	<tglx@...utronix.de>
CC: <christophe.jaillet@...adoo.fr>, <andriy.shevchenko@...ux.intel.com>,
	<vadimp@...dia.com>, <platform-driver-x86@...r.kernel.org>,
	<linux-kernel@...r.kernel.org>, Ciju Rajan K <crajank@...dia.com>
Subject: [PATCH platform-next v4 1/2] kernel/irq: Add generic interrupt storm detection mechanism

If the hardware is broken, it is possible that faulty device will
flood interrupt handler with false events. For example, if fan or
power supply has damaged presence pin, it will cause permanent
generation of plugged in / plugged out events. As a result, interrupt
handler will consume a lot of CPU resources and will keep raising
"UDEV" events to the user space.

This patch provides a mechanism for detecting interrupt storm.
Use the following criteria: if the specific interrupt was generated
'N' times during 'T' seconds, such device is to be considered as
broken and user will be notified through a call back function.
This feature can be used by any kernel subsystems or drivers.

The implementation includes:

- irq_storm_cb_t: Callback function type for storm notifications
- struct irq_storm: Per-IRQ storm detection data structure
- irq_register_storm_detection(): Register storm detection with
				  configurable parameters
- irq_unregister_storm_detection(): Unregister storm detection
- Integration with note_interrupt() for automatic storm checking

Callback API parameters:
- irq: interrupt number to monitor
- max_freq: maximum allowed frequency (interrupts per second)
- dev_id: device identifier passed to callback

Suggested-by: Thomas Gleixner <tglx@...utronix.de>
Signed-off-by: Ciju Rajan K <crajank@...dia.com>
---
 include/linux/interrupt.h | 13 ++++++
 include/linux/irqdesc.h   | 20 +++++++++
 kernel/irq/manage.c       |  4 ++
 kernel/irq/spurious.c     | 87 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 124 insertions(+)

diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index 266f2b39213a..9fbda5d08a8f 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -20,6 +20,7 @@
 #include <asm/ptrace.h>
 #include <asm/irq.h>
 #include <asm/sections.h>
+#include <linux/jiffies.h>
 
 /*
  * These correspond to the IORESOURCE_IRQ_* defines in
@@ -139,6 +140,14 @@ struct irqaction {
 	struct proc_dir_entry	*dir;
 } ____cacheline_internodealigned_in_smp;
 
+/**
+ * irq_storm_cb_t - callback function type for interrupt storm detection
+ * @irq: interrupt number that is storming
+ * @freq: detected frequency (interrupts per second)
+ * @dev_id: device identifier passed during registration
+ */
+typedef void (*irq_storm_cb_t)(unsigned int irq, unsigned int freq, void *dev_id);
+
 extern irqreturn_t no_action(int cpl, void *dev_id);
 
 /*
@@ -331,6 +340,10 @@ extern int irq_force_affinity(unsigned int irq, const struct cpumask *cpumask);
 extern int irq_can_set_affinity(unsigned int irq);
 extern int irq_select_affinity(unsigned int irq);
 
+extern bool irq_register_storm_detection(unsigned int irq, unsigned int max_freq,
+					 irq_storm_cb_t cb, void *dev_id);
+extern void irq_unregister_storm_detection(unsigned int irq);
+
 extern int __irq_apply_affinity_hint(unsigned int irq, const struct cpumask *m,
 				     bool setaffinity);
 
diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h
index 17902861de76..d27f02371a6c 100644
--- a/include/linux/irqdesc.h
+++ b/include/linux/irqdesc.h
@@ -17,6 +17,9 @@ struct irq_desc;
 struct irq_domain;
 struct pt_regs;
 
+/* Forward declaration - full definition in interrupt.h */
+typedef void (*irq_storm_cb_t)(unsigned int, unsigned int, void *);
+
 /**
  * struct irqstat - interrupt statistics
  * @cnt:	real-time interrupt count
@@ -29,6 +32,22 @@ struct irqstat {
 #endif
 };
 
+/**
+ * struct irq_storm - interrupt storm detection data
+ * @max_cnt:		maximum interrupt count per time window
+ * @last_cnt:		last total interrupt count snapshot
+ * @next_period:	next time period boundary (jiffies)
+ * @cb:			callback function to invoke on storm detection
+ * @dev_id:		device identifier for callback
+ */
+struct irq_storm {
+	unsigned long		max_cnt;
+	unsigned long		last_cnt;
+	unsigned long		next_period;
+	irq_storm_cb_t		cb;
+	void			*dev_id;
+};
+
 /**
  * struct irq_desc - interrupt descriptor
  * @irq_common_data:	per irq and chip data passed down to chip functions
@@ -101,6 +120,7 @@ struct irq_desc {
 #ifdef CONFIG_PROC_FS
 	struct proc_dir_entry	*dir;
 #endif
+	struct irq_storm	*irq_storm;
 #ifdef CONFIG_GENERIC_IRQ_DEBUGFS
 	struct dentry		*debugfs_file;
 	const char		*dev_name;
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 349ae7979da0..d413bf11ffde 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -1951,6 +1951,10 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id)
 		irq_release_resources(desc);
 		chip_bus_sync_unlock(desc);
 		irq_remove_timings(desc);
+		if (desc->irq_storm) {
+			kfree(desc->irq_storm);
+			desc->irq_storm = NULL;
+		}
 	}
 
 	mutex_unlock(&desc->request_mutex);
diff --git a/kernel/irq/spurious.c b/kernel/irq/spurious.c
index 73280ccb74b0..525dc0e384f1 100644
--- a/kernel/irq/spurious.c
+++ b/kernel/irq/spurious.c
@@ -22,6 +22,90 @@ static DEFINE_TIMER(poll_spurious_irq_timer, poll_spurious_irqs);
 int irq_poll_cpu;
 static atomic_t irq_poll_active;
 
+/* Minimum frequency threshold */
+#define IRQ_STORM_MIN_FREQ_HZ		50
+#define IRQ_STORM_MAX_FREQ_SCALE	(IRQ_STORM_MIN_FREQ_HZ * 2)
+/* Time window over which storm check is performed */
+#define IRQ_STORM_PERIOD_WINDOW_MS	(IRQ_STORM_MIN_FREQ_HZ * 20)
+
+
+/**
+ * irq_register_storm_detection - register interrupt storm detection for an IRQ
+ * @irq: interrupt number
+ * @max_freq: maximum allowed frequency (interrupts per second)
+ * @cb: callback function to invoke when storm is detected
+ * @dev_id: device identifier passed to callback
+ *
+ * Returns: true on success, false on failure
+ */
+bool irq_register_storm_detection(unsigned int irq, unsigned int max_freq,
+				  irq_storm_cb_t cb, void *dev_id)
+{
+	struct irq_storm *storm;
+	bool ret = false;
+
+	if (max_freq < IRQ_STORM_MIN_FREQ_HZ || !cb)
+		return false;
+
+	storm = kzalloc(sizeof(*storm), GFP_KERNEL);
+	if (!storm)
+		return false;
+
+	/* Adjust to count per 10ms */
+	storm->max_cnt = max_freq / (IRQ_STORM_MAX_FREQ_SCALE);
+	storm->cb = cb;
+	storm->dev_id = dev_id;
+
+	scoped_irqdesc_get_and_buslock(irq, IRQ_GET_DESC_CHECK_GLOBAL) {
+		if (scoped_irqdesc->action && !scoped_irqdesc->irq_storm) {
+			storm->last_cnt = scoped_irqdesc->tot_count;
+			storm->next_period = jiffies + msecs_to_jiffies(IRQ_STORM_PERIOD_WINDOW_MS);
+			scoped_irqdesc->irq_storm = storm;
+			ret = true;
+		}
+	}
+
+	if (!ret)
+		kfree(storm);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(irq_register_storm_detection);
+
+/**
+ * irq_unregister_storm_detection - unregister interrupt storm detection
+ * @irq: interrupt number
+ */
+void irq_unregister_storm_detection(unsigned int irq)
+{
+	scoped_irqdesc_get_and_buslock(irq, IRQ_GET_DESC_CHECK_GLOBAL) {
+		if (scoped_irqdesc->irq_storm) {
+			kfree(scoped_irqdesc->irq_storm);
+			scoped_irqdesc->irq_storm = NULL;
+		}
+	}
+}
+EXPORT_SYMBOL_GPL(irq_unregister_storm_detection);
+
+static void irq_storm_check(struct irq_desc *desc)
+{
+	struct irq_storm *storm = desc->irq_storm;
+	unsigned long delta, now = jiffies;
+
+	if (!time_after_eq(now, storm->next_period))
+		return;
+
+	storm->next_period = now + msecs_to_jiffies(IRQ_STORM_PERIOD_WINDOW_MS);
+	delta = desc->tot_count - storm->last_cnt;
+	storm->last_cnt = desc->tot_count;
+	if (delta > storm->max_cnt) {
+		/* Calculate actual frequency: interrupts per second */
+		storm->cb(irq_desc_get_irq(desc),
+			(delta * (IRQ_STORM_MAX_FREQ_SCALE)),
+			storm->dev_id);
+	}
+}
+
 /*
  * Recovery handler for misrouted interrupts.
  */
@@ -231,6 +315,9 @@ void note_interrupt(struct irq_desc *desc, irqreturn_t action_ret)
 		return;
 	}
 
+	if (desc->irq_storm && action_ret == IRQ_HANDLED)
+		irq_storm_check(desc);
+
 	/*
 	 * We cannot call note_interrupt from the threaded handler
 	 * because we need to look at the compound of all handlers
-- 
2.47.3


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ