From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gavin Shan Subject: [PATCH 2/3] drivers/vfio/pci: Fix wrong MSI interrupt count Date: Mon, 3 Mar 2014 11:24:01 +0800 Message-ID: <1393817042-13758-2-git-send-email-shangw@linux.vnet.ibm.com> References: <1393817042-13758-1-git-send-email-shangw@linux.vnet.ibm.com> Cc: alex.williamson@redhat.com, benh@kernel.crashing.org, aik@ozlabs.ru, Gavin Shan To: kvm@vger.kernel.org Return-path: Received: from e37.co.us.ibm.com ([32.97.110.158]:55141 "EHLO e37.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751759AbaCCDYS (ORCPT ); Sun, 2 Mar 2014 22:24:18 -0500 Received: from /spool/local by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 2 Mar 2014 20:24:18 -0700 Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 002CD3E4003E for ; Sun, 2 Mar 2014 20:24:15 -0700 (MST) Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by b03cxnp08027.gho.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s233NmUE65273958 for ; Mon, 3 Mar 2014 04:23:48 +0100 Received: from d03av03.boulder.ibm.com (localhost [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s233OFPv020645 for ; Sun, 2 Mar 2014 20:24:15 -0700 In-Reply-To: <1393817042-13758-1-git-send-email-shangw@linux.vnet.ibm.com> Sender: kvm-owner@vger.kernel.org List-ID: According PCI local bus specification, the register of Message Control for MSI (offset: 2, length: 2) has bit#0 to enable or disable MSI logic and it shouldn't be part contributing to the calculation of MSI interrupt count. The patch fixes above issue. Also, the patch renames local variable "flags" to "ctl" for both MSI and MSIx case. Signed-off-by: Gavin Shan --- drivers/vfio/pci/vfio_pci.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 7ba0424..5760ea6 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -190,25 +190,23 @@ static int vfio_pci_get_irq_count(struct vfio_pci_device *vdev, int irq_type) } else if (irq_type == VFIO_PCI_MSI_IRQ_INDEX) { u8 pos; - u16 flags; + u16 ctl; pos = vdev->pdev->msi_cap; if (pos) { pci_read_config_word(vdev->pdev, - pos + PCI_MSI_FLAGS, &flags); - - return 1 << (flags & PCI_MSI_FLAGS_QMASK); + pos + PCI_MSI_FLAGS, &ctl); + return 1 << ((ctl & PCI_MSI_FLAGS_QMASK) >> 1); } } else if (irq_type == VFIO_PCI_MSIX_IRQ_INDEX) { u8 pos; - u16 flags; + u16 ctl; pos = vdev->pdev->msix_cap; if (pos) { pci_read_config_word(vdev->pdev, - pos + PCI_MSIX_FLAGS, &flags); - - return (flags & PCI_MSIX_FLAGS_QSIZE) + 1; + pos + PCI_MSIX_FLAGS, &ctl); + return (ctl & PCI_MSIX_FLAGS_QSIZE) + 1; } } else if (irq_type == VFIO_PCI_ERR_IRQ_INDEX) if (pci_is_pcie(vdev->pdev)) -- 1.7.10.4