mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bixuan Cui <cuibixuan@huawei.com>
To: <maz@kernel.org>, <tglx@linutronix.de>
Cc: <john.wanghui@huawei.com>, <yangyingliang@huawei.com>,
	<dingtianhong@huawei.com>, <cuibixuan@huawei.com>,
	<wangxiongfeng2@huawei.com>, <linux-kernel@vger.kernel.org>
Subject: [PATCH] genirq/msi: Fix unpaired calls in msi
Date: Tue, 18 May 2021 11:31:17 +0800	[thread overview]
Message-ID: <20210518033117.78104-1-cuibixuan@huawei.com> (raw)

There are unpaired calls in the msi:

msi_domain_alloc_irqs() {
        ...
        __irq_domain_alloc_irqs()
        ...
        irq_domain_activate_irq()
}

msi_domain_free_irqs() {
        ...
        irq_domain_free_irqs()
}

When msi_domain_alloc_irqs() and msi_domain_free_irqs() are called in
pairs, the irq_domain_deactivate_irq() is missing calls.

This problem occurs during PCI initialization.After pci_msi_setup_msi_irqs
is executed (invoke irq_domain_activate_irq to initialize the MSI irq),
error_cleanup_irqs() of pcie_port_device_register() is executed.
As follows:

pcie_port_device_register() {
	...

	error_cleanup_irqs:
		pci_free_irq_vectors(dev);
}

Invoking Procedure:
	pcie_port_device_register
	-> goto error_cleanup_irqs
	-> pci_free_irq_vectors(dev);
	    pci_disable_msi
	        free_msi_irqs
		    pci_msi_teardown_msi_irqs
		        msi_domain_free_irqs // no deactivate before free
			    irq_domain_free_irqs

Signed-off-by: Bixuan Cui <cuibixuan@huawei.com>
---
 kernel/irq/msi.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c
index c41965e348b5..8828d4863c5d 100644
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -476,11 +476,6 @@ int __msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,
 	return 0;
 
 cleanup:
-	for_each_msi_vector(desc, i, dev) {
-		irq_data = irq_domain_get_irq_data(domain, i);
-		if (irqd_is_activated(irq_data))
-			irq_domain_deactivate_irq(irq_data);
-	}
 	msi_domain_free_irqs(domain, dev);
 	return ret;
 }
@@ -506,6 +501,14 @@ int msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,
 void __msi_domain_free_irqs(struct irq_domain *domain, struct device *dev)
 {
 	struct msi_desc *desc;
+	struct irq_data *irq_data;
+	int i;
+
+	for_each_msi_vector(desc, i, dev) {
+		irq_data = irq_domain_get_irq_data(domain, i);
+		if (irqd_is_activated(irq_data))
+			irq_domain_deactivate_irq(irq_data);
+	}
 
 	for_each_msi_entry(desc, dev) {
 		/*
-- 
2.17.1


             reply	other threads:[~2021-05-18  2:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-18  3:31 Bixuan Cui [this message]
2021-06-01  7:53 ` Bixuan Cui
2021-08-10 13:59 ` [tip: irq/urgent] genirq/msi: Ensure deactivation on teardown tip-bot2 for Bixuan Cui

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=20210518033117.78104-1-cuibixuan@huawei.com \
    --to=cuibixuan@huawei.com \
    --cc=dingtianhong@huawei.com \
    --cc=john.wanghui@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=wangxiongfeng2@huawei.com \
    --cc=yangyingliang@huawei.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

all inboxes | Powered by JetHome®