linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: bhelgaas@google.com
Cc: bart.vanassche@sandisk.com, tglx@linutronix.de,
	linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org
Subject: [PATCH] PCI/MSI: don't apply affinity if there aren't enough vectors left
Date: Mon, 30 Jan 2017 13:15:41 +0100	[thread overview]
Message-ID: <1485778541-28994-1-git-send-email-hch@lst.de> (raw)

Bart reported a problem wіth an out of bounds access in the low-level
IRQ affinity code, which we root caused to the qla2xxx driver assigning
all it's MSI-X vectors to the pre and post vectors, and not having any
left for the actually spread IRQs.

This fixes this issue by not asking for affinity assignment when there
are not vectors to assign left.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Fixes: 402723ad ("PCI/MSI: Provide pci_alloc_irq_vectors_affinity()")
Reported-by: Bart Van Assche <bart.vanassche@sandisk.com>
Tested-by: Bart Van Assche <bart.vanassche@sandisk.com>
---
 drivers/pci/msi.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 50c5003..7f73bac 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -1206,6 +1206,16 @@ int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
 	if (flags & PCI_IRQ_AFFINITY) {
 		if (!affd)
 			affd = &msi_default_affd;
+
+		if (affd->pre_vectors + affd->post_vectors > min_vecs)
+			return -EINVAL;
+
+		/*
+		 * If there aren't any vectors left after applying the pre/post
+		 * vectors don't bother with assigning affinity.
+		 */
+		if (affd->pre_vectors + affd->post_vectors == min_vecs)
+			affd = NULL;
 	} else {
 		if (WARN_ON(affd))
 			affd = NULL;
-- 
2.1.4


             reply	other threads:[~2017-01-30 12:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-30 12:15 Christoph Hellwig [this message]
2017-02-02 17:36 ` [PATCH] PCI/MSI: don't apply affinity if there aren't enough vectors left Bjorn Helgaas
2017-02-02 18:32   ` Christoph Hellwig
2017-02-02 22:38     ` Bjorn Helgaas

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=1485778541-28994-1-git-send-email-hch@lst.de \
    --to=hch@lst.de \
    --cc=bart.vanassche@sandisk.com \
    --cc=bhelgaas@google.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --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).