Skip to content

Commit cab303b

Browse files
KAGA-KOKOrafaeljw
authored andcommitted
genirq: Add sanity checks for PM options on shared interrupt lines
Account the IRQF_NO_SUSPEND and IRQF_RESUME_EARLY actions on shared interrupt lines and yell loudly if there is a mismatch. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 8df2e02 commit cab303b

4 files changed

Lines changed: 60 additions & 0 deletions

File tree

‎include/linux/irqdesc.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ struct irq_desc;
3636
* @threads_oneshot: bitfield to handle shared oneshot threads
3737
* @threads_active: number of irqaction threads currently running
3838
* @wait_for_threads: wait queue for sync_irq to wait for threaded handlers
39+
* @nr_actions: number of installed actions on this descriptor
40+
* @no_suspend_depth: number of irqactions on a irq descriptor with
41+
* IRQF_NO_SUSPEND set
42+
* @force_resume_depth: number of irqactions on a irq descriptor with
43+
* IRQF_FORCE_RESUME set
3944
* @dir: /proc/irq/ procfs entry
4045
* @name: flow handler name for /proc/interrupts output
4146
*/
@@ -68,6 +73,11 @@ struct irq_desc {
6873
unsigned long threads_oneshot;
6974
atomic_t threads_active;
7075
wait_queue_head_t wait_for_threads;
76+
#ifdef CONFIG_PM_SLEEP
77+
unsigned int nr_actions;
78+
unsigned int no_suspend_depth;
79+
unsigned int force_resume_depth;
80+
#endif
7181
#ifdef CONFIG_PROC_FS
7282
struct proc_dir_entry *dir;
7383
#endif

‎kernel/irq/internals.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,13 @@ static inline void kstat_incr_irqs_this_cpu(unsigned int irq, struct irq_desc *d
194194
__this_cpu_inc(*desc->kstat_irqs);
195195
__this_cpu_inc(kstat.irqs_sum);
196196
}
197+
198+
#ifdef CONFIG_PM_SLEEP
199+
void irq_pm_install_action(struct irq_desc *desc, struct irqaction *action);
200+
void irq_pm_remove_action(struct irq_desc *desc, struct irqaction *action);
201+
#else
202+
static inline void
203+
irq_pm_install_action(struct irq_desc *desc, struct irqaction *action) { }
204+
static inline void
205+
irq_pm_remove_action(struct irq_desc *desc, struct irqaction *action) { }
206+
#endif

‎kernel/irq/manage.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,8 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
12001200
new->irq = irq;
12011201
*old_ptr = new;
12021202

1203+
irq_pm_install_action(desc, new);
1204+
12031205
/* Reset broken irq detection when installing new handler */
12041206
desc->irq_count = 0;
12051207
desc->irqs_unhandled = 0;
@@ -1318,6 +1320,8 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
13181320
/* Found it - now remove it from the list of entries: */
13191321
*action_ptr = action->next;
13201322

1323+
irq_pm_remove_action(desc, action);
1324+
13211325
/* If this was the last handler, shut down the IRQ line: */
13221326
if (!desc->action) {
13231327
irq_shutdown(desc);

‎kernel/irq/pm.c‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,42 @@
1313

1414
#include "internals.h"
1515

16+
/*
17+
* Called from __setup_irq() with desc->lock held after @action has
18+
* been installed in the action chain.
19+
*/
20+
void irq_pm_install_action(struct irq_desc *desc, struct irqaction *action)
21+
{
22+
desc->nr_actions++;
23+
24+
if (action->flags & IRQF_FORCE_RESUME)
25+
desc->force_resume_depth++;
26+
27+
WARN_ON_ONCE(desc->force_resume_depth &&
28+
desc->force_resume_depth != desc->nr_actions);
29+
30+
if (action->flags & IRQF_NO_SUSPEND)
31+
desc->no_suspend_depth++;
32+
33+
WARN_ON_ONCE(desc->no_suspend_depth &&
34+
desc->no_suspend_depth != desc->nr_actions);
35+
}
36+
37+
/*
38+
* Called from __free_irq() with desc->lock held after @action has
39+
* been removed from the action chain.
40+
*/
41+
void irq_pm_remove_action(struct irq_desc *desc, struct irqaction *action)
42+
{
43+
desc->nr_actions--;
44+
45+
if (action->flags & IRQF_FORCE_RESUME)
46+
desc->force_resume_depth--;
47+
48+
if (action->flags & IRQF_NO_SUSPEND)
49+
desc->no_suspend_depth--;
50+
}
51+
1652
static void suspend_device_irq(struct irq_desc *desc, int irq)
1753
{
1854
if (!desc->action || (desc->action->flags & IRQF_NO_SUSPEND))

0 commit comments

Comments
 (0)