[dpdk-dev] [PATCH] pci: keep API compatibility with mmap values

Burakov, Anatoly anatoly.burakov at intel.com
Fri Jul 10 17:39:02 CEST 2020


On 10-Jul-20 12:53 PM, Thomas Monjalon wrote:
> 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")
> Cc: talshn at mellanox.com
> 
> Reported-by: David Marchand <david.marchand at redhat.com>
> Signed-off-by: Thomas Monjalon <thomas at monjalon.net>
> ---

<snip>

>   					/* unmap addrs correctly mapped */
>   					for (j = 0; j < i; j++)
>   						pci_unmap_resource(
> diff --git a/lib/librte_eal/include/rte_eal_paging.h b/lib/librte_eal/include/rte_eal_paging.h
> index ed98e70e9e..680a7f2505 100644
> --- a/lib/librte_eal/include/rte_eal_paging.h
> +++ b/lib/librte_eal/include/rte_eal_paging.h
> @@ -3,6 +3,7 @@
>    */
>   
>   #include <stdint.h>
> +#include <sys/mman.h>
>   
>   #include <rte_compat.h>
>   
> @@ -22,6 +23,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 +37,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

I'm probably missing something, but why is this needed? Doesn't 
rte_mem_map() automatically translate these flags into proper ones? 
pci_map_resource() will call rte_mem_map(), and that will translate 
these flags into their Unix equivalents.

-- 
Thanks,
Anatoly


More information about the dev mailing list