Skip to content

Commit 3b2074c

Browse files
committed
Merge tag 'irq-core-2025-09-29' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull irq core updates from Thomas Gleixner: "A set of updates for the interrupt core subsystem: - Introduce irq_chip_[startup|shutdown]_parent() to prepare for addressing a few short comings in the PCI/MSI interrupt subsystem. It allows to utilize the interrupt chip startup/shutdown callbacks for initializing the interrupt chip hierarchy properly on certain RISCV implementations and provides a mechanism to reduce the overhead of masking and unmasking PCI/MSI interrupts during operation when the underlying MSI provider can mask the interrupt. The actual usage comes with the interrupt driver pull request. - Add generic error handling for devm_request_*_irq() This allows to remove the zoo of random error printk's all over the usage sites. - Add a mechanism to warn about long-running interrupt handlers Long running interrupt handlers can introduce latencies and tracking them down is a tedious task. The tracking has to be enabled with a threshold on the kernel command line and utilizes a static branch to remove the overhead when disabled. - Update and extend the selftests which validate the CPU hotplug interrupt migration logic - Allow dropping the per CPU softirq lock on PREEMPT_RT kernels, which causes contention and latencies all over the place. The serialization requirements have been pushed down into the actual affected usage sites already. - The usual small cleanups and improvements" * tag 'irq-core-2025-09-29' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: softirq: Allow to drop the softirq-BKL lock on PREEMPT_RT softirq: Provide a handshake for canceling tasklets via polling genirq/test: Ensure CPU 1 is online for hotplug test genirq/test: Drop CONFIG_GENERIC_IRQ_MIGRATION assumptions genirq/test: Depend on SPARSE_IRQ genirq/test: Fail early if interrupt request fails genirq/test: Factor out fake-virq setup genirq/test: Select IRQ_DOMAIN genirq/test: Fix depth tests on architectures with NOREQUEST by default. genirq: Add support for warning on long-running interrupt handlers genirq/devres: Add error handling in devm_request_*_irq() genirq: Add irq_chip_(startup/shutdown)_parent() genirq: Remove GENERIC_IRQ_LEGACY
2 parents 1d17e80 + 3253cb4 commit 3b2074c

10 files changed

Lines changed: 344 additions & 106 deletions

File tree

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2606,6 +2606,11 @@
26062606
for it. Intended to get systems with badly broken
26072607
firmware running.
26082608

2609+
irqhandler.duration_warn_us= [KNL]
2610+
Warn if an IRQ handler exceeds the specified duration
2611+
threshold in microseconds. Useful for identifying
2612+
long-running IRQs in the system.
2613+
26092614
irqpoll [HW]
26102615
When an interrupt is not handled search all handlers
26112616
for it. Also check all handlers each timer

include/linux/irq.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ extern int irq_chip_set_parent_state(struct irq_data *data,
669669
extern int irq_chip_get_parent_state(struct irq_data *data,
670670
enum irqchip_irq_state which,
671671
bool *state);
672+
extern void irq_chip_shutdown_parent(struct irq_data *data);
673+
extern unsigned int irq_chip_startup_parent(struct irq_data *data);
672674
extern void irq_chip_enable_parent(struct irq_data *data);
673675
extern void irq_chip_disable_parent(struct irq_data *data);
674676
extern void irq_chip_ack_parent(struct irq_data *data);
@@ -976,10 +978,6 @@ static inline void irq_free_desc(unsigned int irq)
976978
irq_free_descs(irq, 1);
977979
}
978980

979-
#ifdef CONFIG_GENERIC_IRQ_LEGACY
980-
void irq_init_desc(unsigned int irq);
981-
#endif
982-
983981
/**
984982
* struct irq_chip_regs - register offsets for struct irq_gci
985983
* @enable: Enable register offset to reg_base

kernel/Kconfig.preempt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ config PREEMPT_RT
103103
Select this if you are building a kernel for systems which
104104
require real-time guarantees.
105105

106+
config PREEMPT_RT_NEEDS_BH_LOCK
107+
bool "Enforce softirq synchronisation on PREEMPT_RT"
108+
depends on PREEMPT_RT
109+
help
110+
Enforce synchronisation across the softirqs context. On PREEMPT_RT
111+
the softirq is preemptible. This enforces the same per-CPU BLK
112+
semantic non-PREEMPT_RT builds have. This should not be needed
113+
because per-CPU locks were added to avoid the per-CPU BKL.
114+
115+
This switch provides the old behaviour for testing reasons. Select
116+
this if you suspect an error with preemptible softirq and want test
117+
the old synchronized behaviour.
118+
106119
config PREEMPT_COUNT
107120
bool
108121

kernel/irq/Kconfig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ menu "IRQ subsystem"
66
config MAY_HAVE_SPARSE_IRQ
77
bool
88

9-
# Legacy support, required for itanic
10-
config GENERIC_IRQ_LEGACY
11-
bool
12-
139
# Enable the generic irq autoprobe mechanism
1410
config GENERIC_IRQ_PROBE
1511
bool
@@ -147,7 +143,9 @@ config GENERIC_IRQ_KEXEC_CLEAR_VM_FORWARD
147143
config IRQ_KUNIT_TEST
148144
bool "KUnit tests for IRQ management APIs" if !KUNIT_ALL_TESTS
149145
depends on KUNIT=y
146+
depends on SPARSE_IRQ
150147
default KUNIT_ALL_TESTS
148+
select IRQ_DOMAIN
151149
imply SMP
152150
help
153151
This option enables KUnit tests for the IRQ subsystem API. These are

kernel/irq/chip.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,43 @@ int irq_chip_get_parent_state(struct irq_data *data,
12591259
}
12601260
EXPORT_SYMBOL_GPL(irq_chip_get_parent_state);
12611261

1262+
/**
1263+
* irq_chip_shutdown_parent - Shutdown the parent interrupt
1264+
* @data: Pointer to interrupt specific data
1265+
*
1266+
* Invokes the irq_shutdown() callback of the parent if available or falls
1267+
* back to irq_chip_disable_parent().
1268+
*/
1269+
void irq_chip_shutdown_parent(struct irq_data *data)
1270+
{
1271+
struct irq_data *parent = data->parent_data;
1272+
1273+
if (parent->chip->irq_shutdown)
1274+
parent->chip->irq_shutdown(parent);
1275+
else
1276+
irq_chip_disable_parent(data);
1277+
}
1278+
EXPORT_SYMBOL_GPL(irq_chip_shutdown_parent);
1279+
1280+
/**
1281+
* irq_chip_startup_parent - Startup the parent interrupt
1282+
* @data: Pointer to interrupt specific data
1283+
*
1284+
* Invokes the irq_startup() callback of the parent if available or falls
1285+
* back to irq_chip_enable_parent().
1286+
*/
1287+
unsigned int irq_chip_startup_parent(struct irq_data *data)
1288+
{
1289+
struct irq_data *parent = data->parent_data;
1290+
1291+
if (parent->chip->irq_startup)
1292+
return parent->chip->irq_startup(parent);
1293+
1294+
irq_chip_enable_parent(data);
1295+
return 0;
1296+
}
1297+
EXPORT_SYMBOL_GPL(irq_chip_startup_parent);
1298+
12621299
/**
12631300
* irq_chip_enable_parent - Enable the parent interrupt (defaults to unmask if
12641301
* NULL)

kernel/irq/devres.c

Lines changed: 87 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,22 @@ static int devm_irq_match(struct device *dev, void *res, void *data)
3030
return this->irq == match->irq && this->dev_id == match->dev_id;
3131
}
3232

33-
/**
34-
* devm_request_threaded_irq - allocate an interrupt line for a managed device
35-
* @dev: device to request interrupt for
36-
* @irq: Interrupt line to allocate
37-
* @handler: Function to be called when the IRQ occurs
38-
* @thread_fn: function to be called in a threaded interrupt context. NULL
39-
* for devices which handle everything in @handler
40-
* @irqflags: Interrupt type flags
41-
* @devname: An ascii name for the claiming device, dev_name(dev) if NULL
42-
* @dev_id: A cookie passed back to the handler function
43-
*
44-
* Except for the extra @dev argument, this function takes the
45-
* same arguments and performs the same function as
46-
* request_threaded_irq(). IRQs requested with this function will be
47-
* automatically freed on driver detach.
48-
*
49-
* If an IRQ allocated with this function needs to be freed
50-
* separately, devm_free_irq() must be used.
51-
*/
52-
int devm_request_threaded_irq(struct device *dev, unsigned int irq,
53-
irq_handler_t handler, irq_handler_t thread_fn,
54-
unsigned long irqflags, const char *devname,
55-
void *dev_id)
33+
static int devm_request_result(struct device *dev, int rc, unsigned int irq,
34+
irq_handler_t handler, irq_handler_t thread_fn,
35+
const char *devname)
36+
{
37+
if (rc >= 0)
38+
return rc;
39+
40+
return dev_err_probe(dev, rc, "request_irq(%u) %ps %ps %s\n",
41+
irq, handler, thread_fn, devname ? : "");
42+
}
43+
44+
static int __devm_request_threaded_irq(struct device *dev, unsigned int irq,
45+
irq_handler_t handler,
46+
irq_handler_t thread_fn,
47+
unsigned long irqflags,
48+
const char *devname, void *dev_id)
5649
{
5750
struct irq_devres *dr;
5851
int rc;
@@ -78,28 +71,48 @@ int devm_request_threaded_irq(struct device *dev, unsigned int irq,
7871

7972
return 0;
8073
}
81-
EXPORT_SYMBOL(devm_request_threaded_irq);
8274

8375
/**
84-
* devm_request_any_context_irq - allocate an interrupt line for a managed device
85-
* @dev: device to request interrupt for
86-
* @irq: Interrupt line to allocate
87-
* @handler: Function to be called when the IRQ occurs
88-
* @irqflags: Interrupt type flags
89-
* @devname: An ascii name for the claiming device, dev_name(dev) if NULL
90-
* @dev_id: A cookie passed back to the handler function
76+
* devm_request_threaded_irq - allocate an interrupt line for a managed device with error logging
77+
* @dev: Device to request interrupt for
78+
* @irq: Interrupt line to allocate
79+
* @handler: Function to be called when the interrupt occurs
80+
* @thread_fn: Function to be called in a threaded interrupt context. NULL
81+
* for devices which handle everything in @handler
82+
* @irqflags: Interrupt type flags
83+
* @devname: An ascii name for the claiming device, dev_name(dev) if NULL
84+
* @dev_id: A cookie passed back to the handler function
9185
*
92-
* Except for the extra @dev argument, this function takes the
93-
* same arguments and performs the same function as
94-
* request_any_context_irq(). IRQs requested with this function will be
95-
* automatically freed on driver detach.
86+
* Except for the extra @dev argument, this function takes the same
87+
* arguments and performs the same function as request_threaded_irq().
88+
* Interrupts requested with this function will be automatically freed on
89+
* driver detach.
90+
*
91+
* If an interrupt allocated with this function needs to be freed
92+
* separately, devm_free_irq() must be used.
93+
*
94+
* When the request fails, an error message is printed with contextual
95+
* information (device name, interrupt number, handler functions and
96+
* error code). Don't add extra error messages at the call sites.
9697
*
97-
* If an IRQ allocated with this function needs to be freed
98-
* separately, devm_free_irq() must be used.
98+
* Return: 0 on success or a negative error number.
9999
*/
100-
int devm_request_any_context_irq(struct device *dev, unsigned int irq,
101-
irq_handler_t handler, unsigned long irqflags,
102-
const char *devname, void *dev_id)
100+
int devm_request_threaded_irq(struct device *dev, unsigned int irq,
101+
irq_handler_t handler, irq_handler_t thread_fn,
102+
unsigned long irqflags, const char *devname,
103+
void *dev_id)
104+
{
105+
int rc = __devm_request_threaded_irq(dev, irq, handler, thread_fn,
106+
irqflags, devname, dev_id);
107+
108+
return devm_request_result(dev, rc, irq, handler, thread_fn, devname);
109+
}
110+
EXPORT_SYMBOL(devm_request_threaded_irq);
111+
112+
static int __devm_request_any_context_irq(struct device *dev, unsigned int irq,
113+
irq_handler_t handler,
114+
unsigned long irqflags,
115+
const char *devname, void *dev_id)
103116
{
104117
struct irq_devres *dr;
105118
int rc;
@@ -124,6 +137,40 @@ int devm_request_any_context_irq(struct device *dev, unsigned int irq,
124137

125138
return rc;
126139
}
140+
141+
/**
142+
* devm_request_any_context_irq - allocate an interrupt line for a managed device with error logging
143+
* @dev: Device to request interrupt for
144+
* @irq: Interrupt line to allocate
145+
* @handler: Function to be called when the interrupt occurs
146+
* @irqflags: Interrupt type flags
147+
* @devname: An ascii name for the claiming device, dev_name(dev) if NULL
148+
* @dev_id: A cookie passed back to the handler function
149+
*
150+
* Except for the extra @dev argument, this function takes the same
151+
* arguments and performs the same function as request_any_context_irq().
152+
* Interrupts requested with this function will be automatically freed on
153+
* driver detach.
154+
*
155+
* If an interrupt allocated with this function needs to be freed
156+
* separately, devm_free_irq() must be used.
157+
*
158+
* When the request fails, an error message is printed with contextual
159+
* information (device name, interrupt number, handler functions and
160+
* error code). Don't add extra error messages at the call sites.
161+
*
162+
* Return: IRQC_IS_HARDIRQ or IRQC_IS_NESTED on success, or a negative error
163+
* number.
164+
*/
165+
int devm_request_any_context_irq(struct device *dev, unsigned int irq,
166+
irq_handler_t handler, unsigned long irqflags,
167+
const char *devname, void *dev_id)
168+
{
169+
int rc = __devm_request_any_context_irq(dev, irq, handler, irqflags,
170+
devname, dev_id);
171+
172+
return devm_request_result(dev, rc, irq, handler, NULL, devname);
173+
}
127174
EXPORT_SYMBOL(devm_request_any_context_irq);
128175

129176
/**

kernel/irq/handle.c

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,44 @@ void __irq_wake_thread(struct irq_desc *desc, struct irqaction *action)
136136
wake_up_process(action->thread);
137137
}
138138

139+
static DEFINE_STATIC_KEY_FALSE(irqhandler_duration_check_enabled);
140+
static u64 irqhandler_duration_threshold_ns __ro_after_init;
141+
142+
static int __init irqhandler_duration_check_setup(char *arg)
143+
{
144+
unsigned long val;
145+
int ret;
146+
147+
ret = kstrtoul(arg, 0, &val);
148+
if (ret) {
149+
pr_err("Unable to parse irqhandler.duration_warn_us setting: ret=%d\n", ret);
150+
return 0;
151+
}
152+
153+
if (!val) {
154+
pr_err("Invalid irqhandler.duration_warn_us setting, must be > 0\n");
155+
return 0;
156+
}
157+
158+
irqhandler_duration_threshold_ns = val * 1000;
159+
static_branch_enable(&irqhandler_duration_check_enabled);
160+
161+
return 1;
162+
}
163+
__setup("irqhandler.duration_warn_us=", irqhandler_duration_check_setup);
164+
165+
static inline void irqhandler_duration_check(u64 ts_start, unsigned int irq,
166+
const struct irqaction *action)
167+
{
168+
u64 delta_ns = local_clock() - ts_start;
169+
170+
if (unlikely(delta_ns > irqhandler_duration_threshold_ns)) {
171+
pr_warn_ratelimited("[CPU%u] long duration of IRQ[%u:%ps], took: %llu us\n",
172+
smp_processor_id(), irq, action->handler,
173+
div_u64(delta_ns, NSEC_PER_USEC));
174+
}
175+
}
176+
139177
irqreturn_t __handle_irq_event_percpu(struct irq_desc *desc)
140178
{
141179
irqreturn_t retval = IRQ_NONE;
@@ -155,7 +193,16 @@ irqreturn_t __handle_irq_event_percpu(struct irq_desc *desc)
155193
lockdep_hardirq_threaded();
156194

157195
trace_irq_handler_entry(irq, action);
158-
res = action->handler(irq, action->dev_id);
196+
197+
if (static_branch_unlikely(&irqhandler_duration_check_enabled)) {
198+
u64 ts_start = local_clock();
199+
200+
res = action->handler(irq, action->dev_id);
201+
irqhandler_duration_check(ts_start, irq, action);
202+
} else {
203+
res = action->handler(irq, action->dev_id);
204+
}
205+
159206
trace_irq_handler_exit(irq, action, res);
160207

161208
if (WARN_ONCE(!irqs_disabled(),"irq %u handler %pS enabled interrupts\n",

0 commit comments

Comments
 (0)