From: Ben Luo <luoben@linux.alibaba.com>
To: tglx@linutronix.de, alex.williamson@redhat.com
Cc: linux-kernel@vger.kernel.org, tao.ma@linux.alibaba.com,
gerry@linux.alibaba.com, nanhai.zou@linux.alibaba.com
Subject: [PATCH v6 1/3] genirq: enhance error recovery code in free irq
Date: Mon, 2 Sep 2019 12:01:50 +0800 [thread overview]
Message-ID: <d2d582fc17b7a469f9e7294fe0f868a8ed168c0d.1567394624.git.luoben@linux.alibaba.com> (raw)
In-Reply-To: <cover.1567394624.git.luoben@linux.alibaba.com>
In-Reply-To: <cover.1567394624.git.luoben@linux.alibaba.com>
__free_irq()/__free_percpu_irq() need to return if called from IRQ
context because the interrupt handler loop runs with desc->lock dropped
and dev_id can be subject to load and store tearing. Also move WARNs
out of lock region and print out dev_id to help debugging.
Signed-off-by: Ben Luo <luoben@linux.alibaba.com>
---
kernel/irq/manage.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index e8f7f17..10ec3e9 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -1690,7 +1690,10 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id)
struct irqaction *action, **action_ptr;
unsigned long flags;
- WARN(in_interrupt(), "Trying to free IRQ %d from IRQ context!\n", irq);
+ if (WARN(in_interrupt(),
+ "Trying to free IRQ %d (dev_id %p) from IRQ context!\n",
+ irq, dev_id))
+ return NULL;
mutex_lock(&desc->request_mutex);
chip_bus_lock(desc);
@@ -1705,10 +1708,11 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id)
action = *action_ptr;
if (!action) {
- WARN(1, "Trying to free already-free IRQ %d\n", irq);
raw_spin_unlock_irqrestore(&desc->lock, flags);
chip_bus_sync_unlock(desc);
mutex_unlock(&desc->request_mutex);
+ WARN(1, "Trying to free already-free IRQ %d (dev_id %p)\n",
+ irq, dev_id);
return NULL;
}
@@ -2286,7 +2290,10 @@ static struct irqaction *__free_percpu_irq(unsigned int irq, void __percpu *dev_
struct irqaction *action;
unsigned long flags;
- WARN(in_interrupt(), "Trying to free IRQ %d from IRQ context!\n", irq);
+ if (WARN(in_interrupt(),
+ "Trying to free IRQ %d (dev_id %p) from IRQ context!\n",
+ irq, dev_id))
+ return NULL;
if (!desc)
return NULL;
@@ -2295,14 +2302,17 @@ static struct irqaction *__free_percpu_irq(unsigned int irq, void __percpu *dev_
action = desc->action;
if (!action || action->percpu_dev_id != dev_id) {
- WARN(1, "Trying to free already-free IRQ %d\n", irq);
- goto bad;
+ raw_spin_unlock_irqrestore(&desc->lock, flags);
+ WARN(1, "Trying to free already-free IRQ (dev_id %p) %d\n",
+ dev_id, irq);
+ return NULL;
}
if (!cpumask_empty(desc->percpu_enabled)) {
- WARN(1, "percpu IRQ %d still enabled on CPU%d!\n",
- irq, cpumask_first(desc->percpu_enabled));
- goto bad;
+ raw_spin_unlock_irqrestore(&desc->lock, flags);
+ WARN(1, "percpu IRQ %d (dev_id %p) still enabled on CPU%d!\n",
+ irq, dev_id, cpumask_first(desc->percpu_enabled));
+ return NULL;
}
/* Found it - now remove it from the list of entries: */
@@ -2317,10 +2327,6 @@ static struct irqaction *__free_percpu_irq(unsigned int irq, void __percpu *dev_
irq_chip_pm_put(&desc->irq_data);
module_put(desc->owner);
return action;
-
-bad:
- raw_spin_unlock_irqrestore(&desc->lock, flags);
- return NULL;
}
/**
--
1.8.3.1
next prev parent reply other threads:[~2019-09-02 4:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-02 4:01 [PATCH v6 0/3] genirq/vfio: Introduce irq_update_devid() and optimize VFIO irq ops Ben Luo
2019-09-02 4:01 ` Ben Luo [this message]
2019-09-02 4:01 ` [PATCH v6 2/3] genirq: introduce irq_update_devid() Ben Luo
2019-09-02 4:01 ` [PATCH v6 3/3] vfio/pci: make use of irq_update_devid() and optimize irq ops Ben Luo
2019-09-10 6:30 ` [PATCH v6 0/3] genirq/vfio: Introduce irq_update_devid() and optimize VFIO " Ben Luo
2019-09-13 17:44 ` Alex Williamson
2019-09-16 14:16 ` Thomas Gleixner
2019-12-05 10:12 ` Ben Luo
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=d2d582fc17b7a469f9e7294fe0f868a8ed168c0d.1567394624.git.luoben@linux.alibaba.com \
--to=luoben@linux.alibaba.com \
--cc=alex.williamson@redhat.com \
--cc=gerry@linux.alibaba.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nanhai.zou@linux.alibaba.com \
--cc=tao.ma@linux.alibaba.com \
--cc=tglx@linutronix.de \
/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;
as well as URLs for NNTP newsgroup(s).