From patchwork Thu Aug 16 14:47:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Gordeev X-Patchwork-Id: 1333011 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 7D4283FC33 for ; Thu, 16 Aug 2012 14:48:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932288Ab2HPOr4 (ORCPT ); Thu, 16 Aug 2012 10:47:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54996 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751957Ab2HPOry (ORCPT ); Thu, 16 Aug 2012 10:47:54 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q7GElgDm029971 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 16 Aug 2012 10:47:42 -0400 Received: from dhcp-26-207.brq.redhat.com (dhcp-26-207.brq.redhat.com [10.34.26.207]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q7GEla4d030730 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 16 Aug 2012 10:47:39 -0400 Date: Thu, 16 Aug 2012 16:47:36 +0200 From: Alexander Gordeev To: linux-kernel@vger.kernel.org Cc: Ingo Molnar , Thomas Gleixner , Bjorn Helgaas , Suresh Siddha , Yinghai Lu , Jeff Garzik , Matthew Wilcox , x86@kernel.org, linux-pci@vger.kernel.org, linux-ide@vger.kernel.org Subject: [PATCH 2/5] x86, MSI: Allocate as many multiple IRQs as requested Message-ID: <864757eaf884e27c08f01f54ff6fa81d4af2ac57.1345124063.git.agordeev@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org 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 --- 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 f083049..5a5c92b 100644 --- a/arch/x86/kernel/apic/io_apic.c +++ b/arch/x86/kernel/apic/io_apic.c @@ -3107,16 +3107,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; } @@ -3298,8 +3294,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; @@ -3307,11 +3302,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); @@ -3320,7 +3317,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); @@ -3348,6 +3345,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 {