* [PATCH v3 1/2] genirq: Provide irq_gc_{lock_irqsave,unlock_irqrestore}() helpers
@ 2016-09-13 13:58 Boris Brezillon
2016-09-13 13:58 ` [PATCH v3 2/2] irqchip/atmel-aic: Fix potential deadlock in ->xlate() Boris Brezillon
0 siblings, 1 reply; 3+ messages in thread
From: Boris Brezillon @ 2016-09-13 13:58 UTC (permalink / raw)
To: Thomas Gleixner, Jason Cooper, Marc Zyngier
Cc: Nicolas Ferre, Alexandre Belloni, linux-kernel, Boris Brezillon,
stable
Some irqchip drivers need to take the generic chip lock outside of the
irq context.
Provide the irq_gc_{lock_irqsave,unlock_irqrestore}() helpers to allow
one to disable irqs while entering a critical section protected by
gc->lock.
Note that we do not provide optimized version of these helpers for !SMP,
because they are not called from the hot-path.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Cc: <stable@vger.kernel.org>
---
include/linux/irq.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/linux/irq.h b/include/linux/irq.h
index b52424eaa0ed..b13668f97648 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -945,6 +945,12 @@ static inline void irq_gc_lock(struct irq_chip_generic *gc) { }
static inline void irq_gc_unlock(struct irq_chip_generic *gc) { }
#endif
+#define irq_gc_lock_irqsave(gc, flags) \
+ raw_spin_lock_irqsave(&(gc)->lock, flags)
+
+#define irq_gc_unlock_irqrestore(gc, flags) \
+ raw_spin_unlock_irqrestore(&(gc)->lock, flags)
+
static inline void irq_reg_writel(struct irq_chip_generic *gc,
u32 val, int reg_offset)
{
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH v3 2/2] irqchip/atmel-aic: Fix potential deadlock in ->xlate() 2016-09-13 13:58 [PATCH v3 1/2] genirq: Provide irq_gc_{lock_irqsave,unlock_irqrestore}() helpers Boris Brezillon @ 2016-09-13 13:58 ` Boris Brezillon 2016-09-13 14:15 ` Boris Brezillon 0 siblings, 1 reply; 3+ messages in thread From: Boris Brezillon @ 2016-09-13 13:58 UTC (permalink / raw) To: Thomas Gleixner, Jason Cooper, Marc Zyngier Cc: Nicolas Ferre, Alexandre Belloni, linux-kernel, Boris Brezillon, stable aic5_irq_domain_xlate() and aic_irq_domain_xlate() take the generic chip lock without disabling interrupts, which can lead to a deadlock if an interrupt occurs while the lock is held in one of these functions. Replace irq_gc_{lock,unlock}() calls by raw_spin_{lock_irqsave,unlock_irqrestore}() ones to prevent this bug from happening. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Fixes: b1479ebb7720 ("irqchip: atmel-aic: Add atmel AIC/AIC5 drivers") Cc: <stable@vger.kernel.org> Acked-by: Marc Zyngier <marc.zyngier@arm.com> --- Changes in v3: - introduce and use the irq_gc_{lock_irqsave,unlock_irqrestore}() helpers Changes in v2: - add Marc's ack - fix stable ML address fixup! irqchip/atmel-aic: Fix potential deadlock in ->xlate() --- drivers/irqchip/irq-atmel-aic.c | 5 +++-- drivers/irqchip/irq-atmel-aic5.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/irqchip/irq-atmel-aic.c b/drivers/irqchip/irq-atmel-aic.c index 112e17c2768b..37f952dd9fc9 100644 --- a/drivers/irqchip/irq-atmel-aic.c +++ b/drivers/irqchip/irq-atmel-aic.c @@ -176,6 +176,7 @@ static int aic_irq_domain_xlate(struct irq_domain *d, { struct irq_domain_chip_generic *dgc = d->gc; struct irq_chip_generic *gc; + unsigned long flags; unsigned smr; int idx; int ret; @@ -194,11 +195,11 @@ static int aic_irq_domain_xlate(struct irq_domain *d, gc = dgc->gc[idx]; - irq_gc_lock(gc); + irq_gc_lock_irqsave(gc, flags); smr = irq_reg_readl(gc, AT91_AIC_SMR(*out_hwirq)); aic_common_set_priority(intspec[2], &smr); irq_reg_writel(gc, smr, AT91_AIC_SMR(*out_hwirq)); - irq_gc_unlock(gc); + irq_gc_unlock_irqrestore(gc, flags); return ret; } diff --git a/drivers/irqchip/irq-atmel-aic5.c b/drivers/irqchip/irq-atmel-aic5.c index 4f0d068e1abe..2a624d87a035 100644 --- a/drivers/irqchip/irq-atmel-aic5.c +++ b/drivers/irqchip/irq-atmel-aic5.c @@ -258,6 +258,7 @@ static int aic5_irq_domain_xlate(struct irq_domain *d, unsigned int *out_type) { struct irq_chip_generic *bgc = irq_get_domain_generic_chip(d, 0); + unsigned long flags; unsigned smr; int ret; @@ -269,12 +270,12 @@ static int aic5_irq_domain_xlate(struct irq_domain *d, if (ret) return ret; - irq_gc_lock(bgc); + irq_gc_lock_irqsave(bgc, flags); irq_reg_writel(bgc, *out_hwirq, AT91_AIC5_SSR); smr = irq_reg_readl(bgc, AT91_AIC5_SMR); aic_common_set_priority(intspec[2], &smr); irq_reg_writel(bgc, smr, AT91_AIC5_SMR); - irq_gc_unlock(bgc); + irq_gc_unlock_irqrestore(bgc, flags); return ret; } -- 2.7.4 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3 2/2] irqchip/atmel-aic: Fix potential deadlock in ->xlate() 2016-09-13 13:58 ` [PATCH v3 2/2] irqchip/atmel-aic: Fix potential deadlock in ->xlate() Boris Brezillon @ 2016-09-13 14:15 ` Boris Brezillon 0 siblings, 0 replies; 3+ messages in thread From: Boris Brezillon @ 2016-09-13 14:15 UTC (permalink / raw) To: Thomas Gleixner, Jason Cooper, Marc Zyngier Cc: Nicolas Ferre, Alexandre Belloni, linux-kernel, stable On Tue, 13 Sep 2016 15:58:29 +0200 Boris Brezillon <boris.brezillon@free-electrons.com> wrote: > aic5_irq_domain_xlate() and aic_irq_domain_xlate() take the generic chip > lock without disabling interrupts, which can lead to a deadlock if an > interrupt occurs while the lock is held in one of these functions. > > Replace irq_gc_{lock,unlock}() calls by > raw_spin_{lock_irqsave,unlock_irqrestore}() ones to prevent this bug from Sorry, I forgot to update my commit message: s/raw_spin_/irq_gc_/. Thomas, can you fix that when applying, or should I send a new version? > happening. > > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> > Fixes: b1479ebb7720 ("irqchip: atmel-aic: Add atmel AIC/AIC5 drivers") > Cc: <stable@vger.kernel.org> > Acked-by: Marc Zyngier <marc.zyngier@arm.com> > --- > Changes in v3: > - introduce and use the irq_gc_{lock_irqsave,unlock_irqrestore}() helpers > > Changes in v2: > - add Marc's ack > - fix stable ML address > > fixup! irqchip/atmel-aic: Fix potential deadlock in ->xlate() > --- > drivers/irqchip/irq-atmel-aic.c | 5 +++-- > drivers/irqchip/irq-atmel-aic5.c | 5 +++-- > 2 files changed, 6 insertions(+), 4 deletions(-) > > diff --git a/drivers/irqchip/irq-atmel-aic.c b/drivers/irqchip/irq-atmel-aic.c > index 112e17c2768b..37f952dd9fc9 100644 > --- a/drivers/irqchip/irq-atmel-aic.c > +++ b/drivers/irqchip/irq-atmel-aic.c > @@ -176,6 +176,7 @@ static int aic_irq_domain_xlate(struct irq_domain *d, > { > struct irq_domain_chip_generic *dgc = d->gc; > struct irq_chip_generic *gc; > + unsigned long flags; > unsigned smr; > int idx; > int ret; > @@ -194,11 +195,11 @@ static int aic_irq_domain_xlate(struct irq_domain *d, > > gc = dgc->gc[idx]; > > - irq_gc_lock(gc); > + irq_gc_lock_irqsave(gc, flags); > smr = irq_reg_readl(gc, AT91_AIC_SMR(*out_hwirq)); > aic_common_set_priority(intspec[2], &smr); > irq_reg_writel(gc, smr, AT91_AIC_SMR(*out_hwirq)); > - irq_gc_unlock(gc); > + irq_gc_unlock_irqrestore(gc, flags); > > return ret; > } > diff --git a/drivers/irqchip/irq-atmel-aic5.c b/drivers/irqchip/irq-atmel-aic5.c > index 4f0d068e1abe..2a624d87a035 100644 > --- a/drivers/irqchip/irq-atmel-aic5.c > +++ b/drivers/irqchip/irq-atmel-aic5.c > @@ -258,6 +258,7 @@ static int aic5_irq_domain_xlate(struct irq_domain *d, > unsigned int *out_type) > { > struct irq_chip_generic *bgc = irq_get_domain_generic_chip(d, 0); > + unsigned long flags; > unsigned smr; > int ret; > > @@ -269,12 +270,12 @@ static int aic5_irq_domain_xlate(struct irq_domain *d, > if (ret) > return ret; > > - irq_gc_lock(bgc); > + irq_gc_lock_irqsave(bgc, flags); > irq_reg_writel(bgc, *out_hwirq, AT91_AIC5_SSR); > smr = irq_reg_readl(bgc, AT91_AIC5_SMR); > aic_common_set_priority(intspec[2], &smr); > irq_reg_writel(bgc, smr, AT91_AIC5_SMR); > - irq_gc_unlock(bgc); > + irq_gc_unlock_irqrestore(bgc, flags); > > return ret; > } ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-09-13 14:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-13 13:58 [PATCH v3 1/2] genirq: Provide irq_gc_{lock_irqsave,unlock_irqrestore}() helpers Boris Brezillon
2016-09-13 13:58 ` [PATCH v3 2/2] irqchip/atmel-aic: Fix potential deadlock in ->xlate() Boris Brezillon
2016-09-13 14:15 ` Boris Brezillon
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).