]> git.droids-corp.org - dpdk.git/commitdiff
eal: fix memory mapping on 32-bit target
authorLance Richardson <lance.richardson@broadcom.com>
Sat, 8 May 2021 14:27:53 +0000 (10:27 -0400)
committerThomas Monjalon <thomas@monjalon.net>
Tue, 11 May 2021 21:01:06 +0000 (23:01 +0200)
For 32-bit targets, size_t is normally a 32-bit type and
does not have sufficient range to represent 64-bit offsets
that are needed when mapping PCI addresses.
Use uint64_t instead.

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>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
lib/eal/include/rte_eal_paging.h
lib/eal/unix/eal_unix_memory.c
lib/eal/windows/eal_memory.c

index ed98e70e9ee3d500795619ba72e29b35e53ea9ab..c60317d0f5233e3d25481130dddbcd60acaa247e 100644 (file)
@@ -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, uint64_t offset);
 
 /**
  * OS-independent implementation of POSIX munmap(3).
index ec7156df96b27d084ddadb91ea5a26136d23083a..68ae93bd6e779c7ce3f9702b248c6f41db9bd3c7 100644 (file)
@@ -5,6 +5,7 @@
 #include <string.h>
 #include <sys/mman.h>
 #include <unistd.h>
+#include <inttypes.h>
 
 #include <rte_eal_paging.h>
 #include <rte_errno.h>
 
 static void *
 mem_map(void *requested_addr, size_t size, int prot, int flags,
-       int fd, size_t offset)
+       int fd, uint64_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%"PRIx64"): %s\n",
+                   requested_addr, size, prot, flags, fd, offset,
+                   strerror(errno));
                rte_errno = errno;
                return NULL;
        }
@@ -106,7 +107,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, uint64_t offset)
 {
        int sys_flags = 0;
        int sys_prot;
index 2cf5a5e649c951a975fc7420cf5223ce2162c1cd..4db048ccb5e10a17eef5b1cd7770d3b788d1645c 100644 (file)
@@ -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, uint64_t offset)
 {
        HANDLE file_handle = INVALID_HANDLE_VALUE;
        HANDLE mapping_handle = INVALID_HANDLE_VALUE;