From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 0DA96A0A0E;
	Fri,  7 May 2021 20:10:39 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 876444013F;
	Fri,  7 May 2021 20:10:38 +0200 (CEST)
Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com
 [209.85.215.182])
 by mails.dpdk.org (Postfix) with ESMTP id AEB4240040
 for <dev@dpdk.org>; Fri,  7 May 2021 20:10:37 +0200 (CEST)
Received: by mail-pg1-f182.google.com with SMTP id m190so7764618pga.2
 for <dev@dpdk.org>; Fri, 07 May 2021 11:10:37 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google;
 h=from:to:cc:subject:date:message-id:mime-version;
 bh=okW/zRKrk87luxDF8cWXg7cCJrDJ5PWKlwogdeL/8Pc=;
 b=HJUJr33LmDIsWJXZ1FJSdR2u/NDrK6O1Qzjf5F8mF6f0r7cs8x6AT56sU8CKbnXRDC
 YyFGgZcMxxnw3BsnDaKFCl6OwBZeIg7LLIdzbhw014CFpbq16ZbTnMfm3ffzSPUuMjsl
 THoMjaS0Bmh99jyQCp9qWsVRuzxGDcYiwyUJI=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version;
 bh=okW/zRKrk87luxDF8cWXg7cCJrDJ5PWKlwogdeL/8Pc=;
 b=m/Ybecba5m0URPAyiSdM7jDZsoxyiHTgR4YRo/Xcp91KvYaGoseRk9JI99RGdS4hFK
 Rt5JCgaeNNGGRCASn9e0wvWELboRXBTNgBZZXG4qSISJBOu3QkeEmy84bGPfyQIpLrt2
 E296LxGLJ5vidLVxK9g8q2ct/XgTP1WPgvmatydih5QMDMJUi4Cc6SNpACo2OEu2tnlr
 fdrYEc2h4oD1CbskRcYQFkoDNEbEpJyO7eSwgGesCxikQj1G3YKFCWa8jjCBILRqti9y
 FVvulr4k7Ire+FUSNLo/D/HoFUUNMYGcCMIpyE2hkwjxJGVABSJ0atPtgnAutCOha9we
 pKjQ==
X-Gm-Message-State: AOAM532U2GoXQWBmhpS15d51r3FtEzN+bBr5qYjBQseGEYj2cYIV3KIm
 RKsx8gA7jN94CMMMOg9F6Fzk/Q==
X-Google-Smtp-Source: ABdhPJy5lEBVLINt0J+ujiWY1nPwaeVuhSFtA5OXxjYAIPk9YJro2R4oBdzNB8huX3C+Q7PQdlcltg==
X-Received: by 2002:aa7:9190:0:b029:22d:6789:cc83 with SMTP id
 x16-20020aa791900000b029022d6789cc83mr11587888pfa.9.1620411036609; 
 Fri, 07 May 2021 11:10:36 -0700 (PDT)
Received: from localhost.localdomain ([192.19.231.250])
 by smtp.gmail.com with ESMTPSA id v185sm5046648pfb.190.2021.05.07.11.10.32
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 07 May 2021 11:10:35 -0700 (PDT)
From: Lance Richardson <lance.richardson@broadcom.com>
To: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>,
 Narcisa Ana Maria Vasile <navasile@linux.microsoft.com>,
 Dmitry Malloy <dmitrym@microsoft.com>,
 Pallavi Kadam <pallavi.kadam@intel.com>
Cc: dev@dpdk.org,
	stable@dpdk.org
Date: Fri,  7 May 2021 14:10:25 -0400
Message-Id: <20210507181025.84012-1-lance.richardson@broadcom.com>
X-Mailer: git-send-email 2.25.1
MIME-Version: 1.0
Content-Type: multipart/signed; protocol="application/pkcs7-signature";
 micalg=sha-256; boundary="0000000000004054f005c1c158ba"
X-Content-Filtered-By: Mailman/MimeDel 2.1.29
Subject: [dpdk-dev] [PATCH] eal: fix memory mapping for 32-bit targets
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

--0000000000004054f005c1c158ba
Content-Transfer-Encoding: 8bit

For 32-bit targets, size_t is normally a 32-bit type and
does not have sufficient range to represent 64-bit offsets
that can are needed when mapping PCI addresses. Use off_t
instead, which is usually a 64-bit type when compiled with
_D_FILE_OFFSET_BITS=64 as is the case for DPDK.

Found when attempting to run 32-bit Linux dpdk-testpmd
using VFIO driver:

    EAL: pci_map_resource(): cannot map resource(63, 0xc0010000, \
    0x200000, 0x20000000000): Invalid argument ((nil))

Fixes: c4b89ecb64ea ("eal: introduce memory management wrappers")
Cc: stable@dpdk.org
Signed-off-by: Lance Richardson <lance.richardson@broadcom.com>
---
 lib/eal/include/rte_eal_paging.h |  2 +-
 lib/eal/unix/eal_unix_memory.c   | 10 +++++-----
 lib/eal/windows/eal_memory.c     |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/lib/eal/include/rte_eal_paging.h b/lib/eal/include/rte_eal_paging.h
index ed98e70e9e..2c05025ffc 100644
--- a/lib/eal/include/rte_eal_paging.h
+++ b/lib/eal/include/rte_eal_paging.h
@@ -61,7 +61,7 @@ enum rte_map_flags {
 __rte_internal
 void *
 rte_mem_map(void *requested_addr, size_t size, int prot, int flags,
-	int fd, size_t offset);
+	int fd, off_t offset);
 
 /**
  * OS-independent implementation of POSIX munmap(3).
diff --git a/lib/eal/unix/eal_unix_memory.c b/lib/eal/unix/eal_unix_memory.c
index ec7156df96..51a42e1a43 100644
--- a/lib/eal/unix/eal_unix_memory.c
+++ b/lib/eal/unix/eal_unix_memory.c
@@ -24,14 +24,14 @@
 
 static void *
 mem_map(void *requested_addr, size_t size, int prot, int flags,
-	int fd, size_t offset)
+	int fd, off_t offset)
 {
 	void *virt = mmap(requested_addr, size, prot, flags, fd, offset);
 	if (virt == MAP_FAILED) {
 		RTE_LOG(DEBUG, EAL,
-			"Cannot mmap(%p, 0x%zx, 0x%x, 0x%x, %d, 0x%zx): %s\n",
-			requested_addr, size, prot, flags, fd, offset,
-			strerror(errno));
+			"Cannot mmap(%p, 0x%zx, 0x%x, 0x%x, %d, 0x%llx): %s\n",
+			requested_addr, size, prot, flags, fd,
+			(unsigned long long)offset, strerror(errno));
 		rte_errno = errno;
 		return NULL;
 	}
@@ -106,7 +106,7 @@ mem_rte_to_sys_prot(int prot)
 
 void *
 rte_mem_map(void *requested_addr, size_t size, int prot, int flags,
-	int fd, size_t offset)
+	int fd, off_t offset)
 {
 	int sys_flags = 0;
 	int sys_prot;
diff --git a/lib/eal/windows/eal_memory.c b/lib/eal/windows/eal_memory.c
index 2cf5a5e649..f1c4b03e96 100644
--- a/lib/eal/windows/eal_memory.c
+++ b/lib/eal/windows/eal_memory.c
@@ -508,7 +508,7 @@ eal_mem_set_dump(void *virt, size_t size, bool dump)
 
 void *
 rte_mem_map(void *requested_addr, size_t size, int prot, int flags,
-	int fd, size_t offset)
+	int fd, off_t offset)
 {
 	HANDLE file_handle = INVALID_HANDLE_VALUE;
 	HANDLE mapping_handle = INVALID_HANDLE_VALUE;
-- 
2.25.1


--0000000000004054f005c1c158ba--