From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from stargate3.asicdesigners.com (stargate.chelsio.com [67.207.112.58]) by dpdk.org (Postfix) with ESMTP id 3BC55E72 for ; Tue, 23 Jun 2015 17:02:06 +0200 (CEST) Received: from localhost (scalar.blr.asicdesigners.com [10.193.185.94]) by stargate3.asicdesigners.com (8.13.8/8.13.8) with ESMTP id t5NF20Gp010701; Tue, 23 Jun 2015 08:02:01 -0700 From: Rahul Lakkireddy To: dev@dpdk.org Date: Tue, 23 Jun 2015 20:30:53 +0530 Message-Id: <2eeeff646a329cca169033f541de3e96cec3a27a.1435067129.git.rahul.lakkireddy@chelsio.com> X-Mailer: git-send-email 2.4.1 In-Reply-To: <61d1c9174f7f9159d4005dd2cea16c7719cec964.1434462470.git.rahul.lakkireddy@chelsio.com> References: <61d1c9174f7f9159d4005dd2cea16c7719cec964.1434462470.git.rahul.lakkireddy@chelsio.com> Cc: Felix Marti , Kumar Sanghvi , Nirranjan Kirubaharan Subject: [dpdk-dev] [PATCH v2] vfio: Fix overflow while assigning vfio BAR region offset and size X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Jun 2015 15:02:06 -0000 When using vfio, the probe fails over Chelsio T5 adapters after commit-id 90a1633b2 (eal/linux: allow to map BARs with MSI-X tables). While debugging further, found that the BAR region offset and size read from vfio are u64, but are assigned to uint32_t variables. This results in the u64 value getting truncated to 0 and passing wrong offset and size to mmap for subsequent BAR regions (i.e. trying to overwrite previously allocated BAR 0 region). The fix is to use these region offset and size directly rather than assigning to uint32_t variables. Fixes: 90a1633b2347 ("eal/linux: allow to map BARs with MSI-X tables") Signed-off-by: Rahul Lakkireddy Signed-off-by: Kumar Sanghvi --- v2: - For fixing 32-bit build failure, rather than converting uint32_t var to uint64_t as done in v1, taking a different approach instead to revert a part of above commit-id so as to use the original region offset and size directly. - Add the commit-id that this patch fixes and update commit log. lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c index 426953a..ff974f5 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c @@ -775,9 +775,6 @@ pci_vfio_map_resource(struct rte_pci_device *dev) memreg[0].offset, memreg[0].size, memreg[1].offset, memreg[1].size); } - } else { - memreg[0].offset = reg.offset; - memreg[0].size = reg.size; } /* try to figure out an address */ @@ -815,6 +812,15 @@ pci_vfio_map_resource(struct rte_pci_device *dev) MAP_FIXED); } + if (!map_addr) { + /* Not a BAR containing MSI-X */ + map_addr = pci_map_resource(bar_addr, + vfio_dev_fd, + reg.offset, + reg.size, + MAP_FIXED); + } + if (map_addr == MAP_FAILED || !map_addr) { munmap(bar_addr, reg.size); bar_addr = MAP_FAILED; -- 2.4.1