From: Alexander Gordeev <agordeev@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Bjorn Helgaas <bhelgaas@google.com>,
Suresh Siddha <suresh.b.siddha@intel.com>,
Yinghai Lu <yinghai@kernel.org>, Jeff Garzik <jgarzik@pobox.com>,
Matthew Wilcox <willy@linux.intel.com>,
x86@kernel.org, linux-pci@vger.kernel.org,
linux-ide@vger.kernel.org
Subject: [PATCH v2 -tip 2/5] x86, MSI: Allocate as many multiple IRQs as requested
Date: Mon, 3 Sep 2012 11:18:28 +0200 [thread overview]
Message-ID: <6685ab469cc043dab2780d6c7bf05c52a589fc24.1346653435.git.agordeev@redhat.com> (raw)
In-Reply-To: <cover.1346653435.git.agordeev@redhat.com>
When multiple MSIs are enabled with pci_enable_msi_block() the number of
allocated IRQs 'nvec' is rounded up to the nearest value of power of two.
That could lead to a condition when number of requested and used IRQs is
less than number of actually allocated IRQs.
This fix introduces 'msi_desc::nvec' field to address the above issue -
when non-zero, it holds the number of allocated IRQs. Otherwise, the old
method is used.
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
---
arch/x86/kernel/apic/io_apic.c | 16 +++++++---------
drivers/pci/msi.c | 10 ++++++++--
include/linux/msi.h | 1 +
3 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
index 5fd2577..fbf3916 100644
--- a/arch/x86/kernel/apic/io_apic.c
+++ b/arch/x86/kernel/apic/io_apic.c
@@ -3116,16 +3116,12 @@ static inline void destroy_irqs(unsigned int irq, unsigned int count)
}
static inline int
-can_create_pow_of_two_irqs(unsigned int from, unsigned int count)
+can_create_irqs(unsigned int from, unsigned int count)
{
- if ((count > 1) && (count % 2))
- return -EINVAL;
-
- for (; count; count = count / 2) {
+ for (; count; count = count - 1) {
if (!irq_can_alloc_irqs(from, count))
return count;
}
-
return -ENOSPC;
}
@@ -3307,8 +3303,7 @@ int setup_msi_irqs(struct pci_dev *dev, int nvec)
if (nvec > 1 && !irq_remapping_enabled)
return 1;
- nvec = __roundup_pow_of_two(nvec);
- ret = can_create_pow_of_two_irqs(nr_irqs_gsi, nvec);
+ ret = can_create_irqs(nr_irqs_gsi, nvec);
if (ret != nvec)
return ret;
@@ -3316,11 +3311,13 @@ int setup_msi_irqs(struct pci_dev *dev, int nvec)
msidesc = list_entry(dev->msi_list.next, struct msi_desc, list);
WARN_ON(msidesc->irq);
WARN_ON(msidesc->msi_attrib.multiple);
+ WARN_ON(msidesc->nvec);
node = dev_to_node(&dev->dev);
irq = create_irqs(nr_irqs_gsi, nvec, node);
if (irq == 0)
return -ENOSPC;
+ msidesc->nvec = nvec;
if (!irq_remapping_enabled) {
ret = setup_msi_irq(dev, msidesc, irq, 0);
@@ -3329,7 +3326,7 @@ int setup_msi_irqs(struct pci_dev *dev, int nvec)
return 0;
}
- msidesc->msi_attrib.multiple = ilog2(nvec);
+ msidesc->msi_attrib.multiple = ilog2(__roundup_pow_of_two(nvec));
for (sub_handle = 0; sub_handle < nvec; sub_handle++) {
if (!sub_handle) {
index = msi_alloc_remapped_irq(dev, irq, nvec);
@@ -3357,6 +3354,7 @@ error:
*/
msidesc->irq = 0;
msidesc->msi_attrib.multiple = 0;
+ msidesc->nvec = 0;
return ret;
}
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index a825d78..f0752d1 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -79,7 +79,10 @@ void default_teardown_msi_irqs(struct pci_dev *dev)
int i, nvec;
if (entry->irq == 0)
continue;
- nvec = 1 << entry->msi_attrib.multiple;
+ if (entry->nvec)
+ nvec = entry->nvec;
+ else
+ nvec = 1 << entry->msi_attrib.multiple;
for (i = 0; i < nvec; i++)
arch_teardown_msi_irq(entry->irq + i);
}
@@ -336,7 +339,10 @@ static void free_msi_irqs(struct pci_dev *dev)
int i, nvec;
if (!entry->irq)
continue;
- nvec = 1 << entry->msi_attrib.multiple;
+ if (entry->nvec)
+ nvec = entry->nvec;
+ else
+ nvec = 1 << entry->msi_attrib.multiple;
for (i = 0; i < nvec; i++)
BUG_ON(irq_has_action(entry->irq + i));
}
diff --git a/include/linux/msi.h b/include/linux/msi.h
index ce93a34..6f4dfba 100644
--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -35,6 +35,7 @@ struct msi_desc {
u32 masked; /* mask bits */
unsigned int irq;
+ unsigned int nvec;
struct list_head list;
union {
--
1.7.7.6
--
Regards,
Alexander Gordeev
agordeev@redhat.com
next prev parent reply other threads:[~2012-09-03 9:18 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-03 9:16 [PATCH v2 -tip 0/5] x86, MSI, AHCI: Support multiple MSIs Alexander Gordeev
2012-09-03 9:17 ` [PATCH v2 -tip 1/5] x86, MSI: Support multiple MSIs in presense of IRQ remapping Alexander Gordeev
2012-09-03 18:53 ` Yinghai Lu
2012-09-04 9:32 ` Alexander Gordeev
2012-09-03 9:18 ` Alexander Gordeev [this message]
2012-09-03 9:19 ` [PATCH v2 -tip 3/5] x86, MSI: Minor readability fixes Alexander Gordeev
2012-09-03 9:19 ` [PATCH v2 -tip 4/5] PCI, MSI: Enable multiple MSIs with pci_enable_msi_block_auto() Alexander Gordeev
2012-09-07 20:53 ` Bjorn Helgaas
2012-09-03 9:20 ` [PATCH v2 -tip 5/5] AHCI: Support multiple MSIs Alexander Gordeev
2012-09-27 4:59 ` Jeff Garzik
2012-09-26 12:38 ` [PATCH v2 -tip 0/5] x86, MSI, " Alexander Gordeev
2012-09-27 4:03 ` Ingo Molnar
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=6685ab469cc043dab2780d6c7bf05c52a589fc24.1346653435.git.agordeev@redhat.com \
--to=agordeev@redhat.com \
--cc=bhelgaas@google.com \
--cc=jgarzik@pobox.com \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=suresh.b.siddha@intel.com \
--cc=tglx@linutronix.de \
--cc=willy@linux.intel.com \
--cc=x86@kernel.org \
--cc=yinghai@kernel.org \
/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).