[v2] eal: fix memory mapping for 32-bit targets
Checks
Commit Message
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 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>
---
v2: Use uint64_t instead of off_t (off_t is unknown to Windows).
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(-)
Comments
2021-05-07 15:06 (UTC-0400), Lance Richardson:
[...]
> diff --git a/lib/eal/unix/eal_unix_memory.c b/lib/eal/unix/eal_unix_memory.c
> index ec7156df96..41a94a7511 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, 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%llx): %s\n",
> + requested_addr, size, prot, flags, fd,
> + (unsigned long long)offset, strerror(errno));
Why not PRIx64?
On Fri, May 7, 2021 at 4:51 PM Dmitry Kozlyuk <dmitry.kozliuk@gmail.com> wrote:
>
> 2021-05-07 15:06 (UTC-0400), Lance Richardson:
> [...]
> > diff --git a/lib/eal/unix/eal_unix_memory.c b/lib/eal/unix/eal_unix_memory.c
> > index ec7156df96..41a94a7511 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, 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%llx): %s\n",
> > + requested_addr, size, prot, flags, fd,
> > + (unsigned long long)offset, strerror(errno));
>
> Why not PRIx64?
Good point. %llx made sense for off_t.
Thanks,
Lance
@@ -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).
@@ -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, 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%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, uint64_t offset)
{
int sys_flags = 0;
int sys_prot;
@@ -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;