Skip to content

Commit 9114014

Browse files
committed
genirq: Add mutex to irq desc to serialize request/free_irq()
The irq_request/release_resources() callbacks ar currently invoked under desc->lock with interrupts disabled. This is a source of problems on RT and conceptually not required. Add a seperate mutex to struct irq_desc which allows to serialize request/free_irq(), which can be used to move the resource functions out of the desc->lock held region. 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.039220922@linutronix.de
1 parent 3a90795 commit 9114014

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

include/linux/irqdesc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <linux/rcupdate.h>
55
#include <linux/kobject.h>
6+
#include <linux/mutex.h>
67

78
/*
89
* Core internal functions to deal with irq descriptors
@@ -45,6 +46,7 @@ struct pt_regs;
4546
* IRQF_FORCE_RESUME set
4647
* @rcu: rcu head for delayed free
4748
* @kobj: kobject used to represent this struct in sysfs
49+
* @request_mutex: mutex to protect request/free before locking desc->lock
4850
* @dir: /proc/irq/ procfs entry
4951
* @debugfs_file: dentry for the debugfs file
5052
* @name: flow handler name for /proc/interrupts output
@@ -96,6 +98,7 @@ struct irq_desc {
9698
struct rcu_head rcu;
9799
struct kobject kobj;
98100
#endif
101+
struct mutex request_mutex;
99102
int parent_irq;
100103
struct module *owner;
101104
const char *name;

kernel/irq/irqdesc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ static struct irq_desc *alloc_desc(int irq, int node, unsigned int flags,
373373

374374
raw_spin_lock_init(&desc->lock);
375375
lockdep_set_class(&desc->lock, &irq_desc_lock_class);
376+
mutex_init(&desc->request_mutex);
376377
init_rcu_head(&desc->rcu);
377378

378379
desc_set_defaults(irq, desc, node, affinity, owner);

kernel/irq/manage.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,8 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
11671167
if (desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE)
11681168
new->flags &= ~IRQF_ONESHOT;
11691169

1170+
mutex_lock(&desc->request_mutex);
1171+
11701172
chip_bus_lock(desc);
11711173

11721174
/*
@@ -1350,6 +1352,7 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
13501352

13511353
raw_spin_unlock_irqrestore(&desc->lock, flags);
13521354
chip_bus_sync_unlock(desc);
1355+
mutex_unlock(&desc->request_mutex);
13531356

13541357
irq_setup_timings(desc, new);
13551358

@@ -1383,6 +1386,8 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
13831386

13841387
chip_bus_sync_unlock(desc);
13851388

1389+
mutex_unlock(&desc->request_mutex);
1390+
13861391
out_thread:
13871392
if (new->thread) {
13881393
struct task_struct *t = new->thread;
@@ -1446,6 +1451,7 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
14461451
if (!desc)
14471452
return NULL;
14481453

1454+
mutex_lock(&desc->request_mutex);
14491455
chip_bus_lock(desc);
14501456
raw_spin_lock_irqsave(&desc->lock, flags);
14511457

@@ -1521,6 +1527,8 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
15211527
}
15221528
}
15231529

1530+
mutex_unlock(&desc->request_mutex);
1531+
15241532
irq_chip_pm_put(&desc->irq_data);
15251533
module_put(desc->owner);
15261534
kfree(action->secondary);

0 commit comments

Comments
 (0)