pci: keep API compatibility with mmap values
The function pci_map_resource() returns MAP_FAILED in case of error. When replacing the call to mmap() by rte_mem_map(), the error code became NULL, breaking the API. This function is probably not used outside of DPDK, but it is still a problem for two reasons: - the deprecation process was not followed - the Linux function pci_vfio_mmap_bar() is broken for i40e The error code is reverted to the Unix value MAP_FAILED. Windows needs to define this special value (-1 as in Unix). After proper deprecation process, the API could be changed again if really needed. Because of the switch from mmap() to rte_mem_map(), another part of the API was changed: "int additional_flags" are defined as "additional flags for the mapping range" without mentioning it was directly used in mmap(). Currently it is directly used in rte_mem_map(), that's why the values rte_map_flags must be mapped (sic) on the mmap ones in case of Unix OS. These are side effects of a badly defined API using Unix values. Bugzilla ID: 503 Fixes: 2fd3567e5425 ("pci: use OS generic memory mapping functions") Reported-by: David Marchand <david.marchand@redhat.com> Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com> Tested-by: Lihong Ma <lihongx.ma@intel.com>
This commit is contained in:
parent
3596a037ab
commit
9d2b245937
@ -192,7 +192,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
|
||||
mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
|
||||
(size_t)dev->mem_resource[res_idx].len, 0);
|
||||
close(fd);
|
||||
if (mapaddr == NULL)
|
||||
if (mapaddr == MAP_FAILED)
|
||||
goto error;
|
||||
|
||||
maps[map_idx].phaddr = dev->mem_resource[res_idx].phys_addr;
|
||||
|
@ -345,7 +345,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
|
||||
mapaddr = pci_map_resource(pci_map_addr, fd, 0,
|
||||
(size_t)dev->mem_resource[res_idx].len, 0);
|
||||
close(fd);
|
||||
if (mapaddr == NULL)
|
||||
if (mapaddr == MAP_FAILED)
|
||||
goto error;
|
||||
|
||||
pci_map_addr = RTE_PTR_ADD(mapaddr,
|
||||
|
@ -566,7 +566,7 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res,
|
||||
}
|
||||
|
||||
/* if there's a second part, try to map it */
|
||||
if (map_addr != NULL
|
||||
if (map_addr != MAP_FAILED
|
||||
&& memreg[1].offset && memreg[1].size) {
|
||||
void *second_addr = RTE_PTR_ADD(bar_addr,
|
||||
(uintptr_t)(memreg[1].offset -
|
||||
@ -578,7 +578,7 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res,
|
||||
RTE_MAP_FORCE_ADDRESS);
|
||||
}
|
||||
|
||||
if (map_addr == NULL) {
|
||||
if (map_addr == NULL || map_addr == MAP_FAILED) {
|
||||
munmap(bar_addr, bar->size);
|
||||
bar_addr = MAP_FAILED;
|
||||
RTE_LOG(ERR, EAL, "Failed to map pci BAR%d\n",
|
||||
|
@ -58,7 +58,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
|
||||
"Cannot mmap device resource file %s to address: %p\n",
|
||||
uio_res->maps[i].path,
|
||||
uio_res->maps[i].addr);
|
||||
if (mapaddr != NULL) {
|
||||
if (mapaddr != MAP_FAILED) {
|
||||
/* unmap addrs correctly mapped */
|
||||
for (j = 0; j < i; j++)
|
||||
pci_unmap_resource(
|
||||
|
@ -3,6 +3,9 @@
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#ifndef RTE_EXEC_ENV_WINDOWS
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#include <rte_compat.h>
|
||||
|
||||
@ -22,6 +25,7 @@ enum rte_mem_prot {
|
||||
|
||||
/** Additional flags for memory mapping. */
|
||||
enum rte_map_flags {
|
||||
#ifdef RTE_EXEC_ENV_WINDOWS
|
||||
/** Changes to the mapped memory are visible to other processes. */
|
||||
RTE_MAP_SHARED = 1 << 0,
|
||||
/** Mapping is not backed by a regular file. */
|
||||
@ -35,6 +39,12 @@ enum rte_map_flags {
|
||||
* it is not required to do so, thus mapping with this flag may fail.
|
||||
*/
|
||||
RTE_MAP_FORCE_ADDRESS = 1 << 3
|
||||
#else /* map mmap flags because they are exposed in pci_map_resource() API */
|
||||
RTE_MAP_SHARED = MAP_SHARED,
|
||||
RTE_MAP_ANONYMOUS = MAP_ANONYMOUS,
|
||||
RTE_MAP_PRIVATE = MAP_PRIVATE,
|
||||
RTE_MAP_FORCE_ADDRESS = MAP_FIXED,
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -25,6 +25,12 @@ extern "C" {
|
||||
#define PATH_MAX _MAX_PATH
|
||||
#endif
|
||||
|
||||
/* sys/mman.h
|
||||
* The syscall mmap does not exist on Windows,
|
||||
* but this error code is used in a badly defined DPDK API for PCI mapping.
|
||||
*/
|
||||
#define MAP_FAILED ((void *) -1)
|
||||
|
||||
#define sleep(x) Sleep(1000 * (x))
|
||||
|
||||
#define strerror_r(a, b, c) strerror_s(b, c, a)
|
||||
|
@ -163,6 +163,7 @@ pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
|
||||
__func__, fd, requested_addr, size,
|
||||
(unsigned long long)offset,
|
||||
rte_strerror(rte_errno), mapaddr);
|
||||
mapaddr = MAP_FAILED; /* API uses mmap error code */
|
||||
} else
|
||||
RTE_LOG(DEBUG, EAL, " PCI memory mapped at %p\n", mapaddr);
|
||||
|
||||
|
@ -160,7 +160,7 @@ int rte_pci_addr_parse(const char *str, struct rte_pci_addr *addr);
|
||||
* The additional flags for the mapping range.
|
||||
* @return
|
||||
* - On success, the function returns a pointer to the mapped area.
|
||||
* - On error, NULL is returned.
|
||||
* - On error, MAP_FAILED is returned.
|
||||
*/
|
||||
void *pci_map_resource(void *requested_addr, int fd, off_t offset,
|
||||
size_t size, int additional_flags);
|
||||
|
Loading…
x
Reference in New Issue
Block a user