Re: [PATCH v3 2/2] irqchip/atmel-aic: Fix potential deadlock in ->xlate()

From: Boris Brezillon
Date: Tue Sep 13 2016 - 10:15:23 EST


On Tue, 13 Sep 2016 15:58:29 +0200
Boris Brezillon <boris.brezillon@xxxxxxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxxxxxx>
> Fixes: b1479ebb7720 ("irqchip: atmel-aic: Add atmel AIC/AIC5 drivers")
> Cc: <stable@xxxxxxxxxxxxxxx>
> Acked-by: Marc Zyngier <marc.zyngier@xxxxxxx>
> ---
> 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;
> }