From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <rahul.lakkireddy@chelsio.com>
Received: from stargate3.asicdesigners.com (stargate.chelsio.com
 [67.207.112.58]) by dpdk.org (Postfix) with ESMTP id 89BB1569E
 for <dev@dpdk.org>; Mon, 13 Jul 2015 10:52:28 +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 t6D8qLnf002439;
 Mon, 13 Jul 2015 01:52:22 -0700
From: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
To: dev@dpdk.org
Date: Mon, 13 Jul 2015 14:21:45 +0530
Message-Id: <b5f3fef8563eab3e0120dfdf3b7a5026a7654b84.1436773804.git.rahul.lakkireddy@chelsio.com>
X-Mailer: git-send-email 2.4.1
In-Reply-To: <2eeeff646a329cca169033f541de3e96cec3a27a.1435067129.git.rahul.lakkireddy@chelsio.com>
References: <2eeeff646a329cca169033f541de3e96cec3a27a.1435067129.git.rahul.lakkireddy@chelsio.com>
Cc: Felix Marti <felix@chelsio.com>, Kumar Sanghvi <kumaras@chelsio.com>,
 Nirranjan Kirubaharan <nirranjan@chelsio.com>
Subject: [dpdk-dev] [PATCH v3] 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 <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Mon, 13 Jul 2015 08:52:29 -0000

When using vfio, the probe fails for BAR > 0 after the
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.

The fix is to use unsigned long for the offset and size.

This is based on patch by Alejandro Lucero <alejandro.lucero@netronome.com>
posted at below:

http://dpdk.org/ml/archives/dev/2015-June/020201.html

and updated with diff from below to fix 32-bit compilation:

http://dpdk.org/ml/archives/dev/2015-July/020963.html

Fixes: 90a1633b2347 ("eal/linux: allow to map BARs with MSI-X tables")
Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
Signed-off-by: Kumar Sanghvi <kumaras@chelsio.com>
---
v3:
- Use unsigned long instead and updated the commit log.

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 | 4 ++--
 1 file changed, 2 insertions(+), 2 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..6127f5f 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -728,7 +728,7 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
 		struct vfio_region_info reg = { .argsz = sizeof(reg) };
 		void *bar_addr;
 		struct memreg {
-			uint32_t offset, size;
+			unsigned long offset, size;
 		} memreg[2] = {};
 
 		reg.index = i;
@@ -771,7 +771,7 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
 				RTE_LOG(DEBUG, EAL,
 					"Trying to map BAR %d that contains the MSI-X "
 					"table. Trying offsets: "
-					"%04x:%04x, %04x:%04x\n", i,
+					"0x%04lx:0x%04lx, 0x%04lx:0x%04lx\n", i,
 					memreg[0].offset, memreg[0].size,
 					memreg[1].offset, memreg[1].size);
 			}
-- 
2.4.1