Skip to content

Commit 46e48e2

Browse files
committed
genirq: Move irq resource handling out of spinlocked region
Aside of being conceptually wrong, there is also an actual (hard to trigger and mostly theoretical) problem. CPU0 CPU1 free_irq(X) interrupt X spin_lock(desc->lock) wake irq thread() spin_unlock(desc->lock) spin_lock(desc->lock) remove action() shutdown_irq() release_resources() thread_handler() spin_unlock(desc->lock) access released resources. synchronize_irq() Move the release resources invocation after synchronize_irq() so it's guaranteed that the threaded handler has finished. Move the resource request call out of the desc->lock held region as well, so the invocation context is the same for both request and release. This solves the problems with those functions on RT as well. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Marc Zyngier <marc.zyngier@arm.com> Cc: Heiko Stuebner <heiko@sntech.de> Cc: Julia Cartwright <julia@ni.com> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: Brian Norris <briannorris@chromium.org> Cc: Doug Anderson <dianders@chromium.org> Cc: linux-rockchip@lists.infradead.org Cc: John Keeping <john@metanate.com> Cc: linux-gpio@vger.kernel.org Link: http://lkml.kernel.org/r/20170629214344.117028181@linutronix.de
1 parent 9114014 commit 46e48e2

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

kernel/irq/manage.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,14 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
11681168
new->flags &= ~IRQF_ONESHOT;
11691169

11701170
mutex_lock(&desc->request_mutex);
1171+
if (!desc->action) {
1172+
ret = irq_request_resources(desc);
1173+
if (ret) {
1174+
pr_err("Failed to request resources for %s (irq %d) on irqchip %s\n",
1175+
new->name, irq, desc->irq_data.chip->name);
1176+
goto out_mutex;
1177+
}
1178+
}
11711179

11721180
chip_bus_lock(desc);
11731181

@@ -1271,13 +1279,6 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
12711279
}
12721280

12731281
if (!shared) {
1274-
ret = irq_request_resources(desc);
1275-
if (ret) {
1276-
pr_err("Failed to request resources for %s (irq %d) on irqchip %s\n",
1277-
new->name, irq, desc->irq_data.chip->name);
1278-
goto out_unlock;
1279-
}
1280-
12811282
init_waitqueue_head(&desc->wait_for_threads);
12821283

12831284
/* Setup the type (level, edge polarity) if configured: */
@@ -1386,6 +1387,10 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
13861387

13871388
chip_bus_sync_unlock(desc);
13881389

1390+
if (!desc->action)
1391+
irq_release_resources(desc);
1392+
1393+
out_mutex:
13891394
mutex_unlock(&desc->request_mutex);
13901395

13911396
out_thread:
@@ -1484,7 +1489,6 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
14841489
if (!desc->action) {
14851490
irq_settings_clr_disable_unlazy(desc);
14861491
irq_shutdown(desc);
1487-
irq_release_resources(desc);
14881492
irq_remove_timings(desc);
14891493
}
14901494

@@ -1527,6 +1531,9 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
15271531
}
15281532
}
15291533

1534+
if (!desc->action)
1535+
irq_release_resources(desc);
1536+
15301537
mutex_unlock(&desc->request_mutex);
15311538

15321539
irq_chip_pm_put(&desc->irq_data);

0 commit comments

Comments
 (0)