From: Aniruddha Banerjee <aniruddhab@nvidia.com>
To: Marc Zyngier <marc.zyngier@arm.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-tegra@vger.kernel.org" <linux-tegra@vger.kernel.org>,
Jonathan Hunter <jonathanh@nvidia.com>,
Stephen Warren <swarren@nvidia.com>,
Thierry Reding <treding@nvidia.com>,
Vipin Kumar <vipink@nvidia.com>
Subject: [RFC PATCH] irqchip: arm-gic: take gic_lock when updating irq type
Date: Thu, 22 Mar 2018 10:28:59 +0000 [thread overview]
Message-ID: <c20f41d47ed9444b9050bc1f609d4bbe@bgmail101.nvidia.com> (raw)
The kernel documentation states that the irq-chip driver should
handle the locking of the irq-chip registers. 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 irq_controller lock when the
irq_type is updated.
This patch is only for GICv2; however, I have noticed a similar
implementation in GICv3. This patch is sent as an RFC in case I am
missing anything.
Signed-off-by: Aniruddha Banerjee <aniruddhab@nvidia.com>
---
drivers/irqchip/irq-gic.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
index 4c797b43614d..61380f5a2254 100644
--- a/drivers/irqchip/irq-gic.c
+++ b/drivers/irqchip/irq-gic.c
@@ -67,6 +67,8 @@ static void gic_check_cpu_features(void)
#define gic_check_cpu_features() do { } while(0)
#endif
+static DEFINE_RAW_SPINLOCK(irq_controller_lock);
+
union gic_base {
void __iomem *common_base;
void __percpu * __iomem *percpu_base;
@@ -529,6 +531,7 @@ static int gic_set_type(struct irq_data *d, unsigned int type)
{
void __iomem *base = gic_dist_base(d);
unsigned int gicirq = gic_irq(d);
+ int ret;
/* Interrupt configuration for SGIs can't be changed */
if (gicirq < 16)
@@ -539,7 +542,11 @@ static int gic_set_type(struct irq_data *d, unsigned int type)
type != IRQ_TYPE_EDGE_RISING)
return -EINVAL;
- return gic_configure_irq(gicirq, type, base, NULL);
+ raw_spin_lock(&irq_controller_lock);
+ ret = gic_configure_irq(gicirq, type, base, NULL);
+ raw_spin_unlock(&irq_controller_lock);
+
+ return ret;
}
static int gic_irq_set_vcpu_affinity(struct irq_data *d, void *vcpu)
--
2.15.1
next reply other threads:[~2018-03-22 10:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-22 10:28 Aniruddha Banerjee [this message]
2018-03-22 12:19 ` [RFC PATCH] irqchip: arm-gic: take gic_lock when updating irq type Marc Zyngier
2018-03-26 13:19 ` Daniel Thompson
2018-03-26 14:26 ` Marc Zyngier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c20f41d47ed9444b9050bc1f609d4bbe@bgmail101.nvidia.com \
--to=aniruddhab@nvidia.com \
--cc=jonathanh@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=marc.zyngier@arm.com \
--cc=swarren@nvidia.com \
--cc=treding@nvidia.com \
--cc=vipink@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox