* [PATCHv4] irqchip: arm-gic: take gic_lock when updating irq type
@ 2018-03-28 13:42 Aniruddha Banerjee
2018-03-28 14:36 ` Marc Zyngier
0 siblings, 1 reply; 2+ messages in thread
From: Aniruddha Banerjee @ 2018-03-28 13:42 UTC (permalink / raw)
To: marc.zyngier, linux-kernel, linux-tegra
Cc: aniruddhab, stable, vipink, strasi, swarren, jonathanh, talho, treding
From: Aniruddha Banerjee <aniruddhab@nvidia.com>
The kernel documentation states that the locking of the irq-chip
registers should be handled by the irq-chip driver. In the irq-gic,
the accesses to the irqchip are seemingly not protected and multiple
writes to SPIs from different irq descriptors do RMW requests without
taking the irq-chip lock. When multiple irqs call the request_irq at
the same time, there can be a simultaneous write at the gic
distributor, leading to a race. Acquire the gic_lock when the
irq_type is updated.
Cc: stable@vger.kernel.org
Signed-off-by: Aniruddha Banerjee <aniruddhab@nvidia.com>
---
Change from V1:
* Moved the spinlock from irq-gic to irq-gic common, so that the fix
is valid for GIC v1/v2/v3.
Change from V2:
* Fixup the Signed-off-by line.
Change from V3:
* Change raw_spin_lock to raw_spin_lock_irqsave and spin_unlock to
raw_spin_unlock_irqrestore to protect against a potential deadlock
when an interrupt handler changes the trigger type of any interrupt.
drivers/irqchip/irq-gic-common.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/irqchip/irq-gic-common.c b/drivers/irqchip/irq-gic-common.c
index 9ae71804b5dd..1c2ca8d51a70 100644
--- a/drivers/irqchip/irq-gic-common.c
+++ b/drivers/irqchip/irq-gic-common.c
@@ -21,6 +21,8 @@
#include "irq-gic-common.h"
+static DEFINE_RAW_SPINLOCK(irq_controller_lock);
+
static const struct gic_kvm_info *gic_kvm_info;
const struct gic_kvm_info *gic_get_kvm_info(void)
@@ -52,11 +54,13 @@ int gic_configure_irq(unsigned int irq, unsigned int type,
u32 confoff = (irq / 16) * 4;
u32 val, oldval;
int ret = 0;
+ unsigned long flags;
/*
* Read current configuration register, and insert the config
* for "irq", depending on "type".
*/
+ raw_spin_lock_irqsave(&irq_controller_lock, flags);
val = oldval = readl_relaxed(base + GIC_DIST_CONFIG + confoff);
if (type & IRQ_TYPE_LEVEL_MASK)
val &= ~confmask;
@@ -64,8 +68,10 @@ int gic_configure_irq(unsigned int irq, unsigned int type,
val |= confmask;
/* If the current configuration is the same, then we are done */
- if (val == oldval)
+ if (val == oldval) {
+ raw_spin_unlock_irqrestore(&irq_controller_lock, flags);
return 0;
+ }
/*
* Write back the new configuration, and possibly re-enable
@@ -83,6 +89,7 @@ int gic_configure_irq(unsigned int irq, unsigned int type,
pr_warn("GIC: PPI%d is secure or misconfigured\n",
irq - 16);
}
+ raw_spin_unlock_irqrestore(&irq_controller_lock, flags);
if (sync_access)
sync_access();
--
2.16.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCHv4] irqchip: arm-gic: take gic_lock when updating irq type
2018-03-28 13:42 [PATCHv4] irqchip: arm-gic: take gic_lock when updating irq type Aniruddha Banerjee
@ 2018-03-28 14:36 ` Marc Zyngier
0 siblings, 0 replies; 2+ messages in thread
From: Marc Zyngier @ 2018-03-28 14:36 UTC (permalink / raw)
To: Aniruddha Banerjee
Cc: linux-kernel, linux-tegra, aniruddhab, stable, vipink, strasi,
swarren, jonathanh, talho, treding
On Wed, 28 Mar 2018 14:42:00 +0100,
Aniruddha Banerjee wrote:
>
> From: Aniruddha Banerjee <aniruddhab@nvidia.com>
>
> The kernel documentation states that the locking of the irq-chip
> registers should be handled by the irq-chip driver. In the irq-gic,
> the accesses to the irqchip are seemingly not protected and multiple
> writes to SPIs from different irq descriptors do RMW requests without
> taking the irq-chip lock. When multiple irqs call the request_irq at
> the same time, there can be a simultaneous write at the gic
> distributor, leading to a race. Acquire the gic_lock when the
> irq_type is updated.
>
> Cc: stable@vger.kernel.org
>
> Signed-off-by: Aniruddha Banerjee <aniruddhab@nvidia.com>
I've applied this after having reworked the commit log a bit.
Thanks,
M.
--
Jazz is not dead, it just smell funny.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-03-28 14:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-28 13:42 [PATCHv4] irqchip: arm-gic: take gic_lock when updating irq type Aniruddha Banerjee
2018-03-28 14:36 ` Marc Zyngier
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.