From: "Burakov, Anatoly" <anatoly.burakov@intel.com>
To: Jake Freeland <jfree@FreeBSD.org>,
Chenbo Xia <chenbox@nvidia.com>,
"Nipun Gupta" <nipun.gupta@amd.com>,
Tyler Retzlaff <roretzla@linux.microsoft.com>,
Bruce Richardson <bruce.richardson@intel.com>
Cc: <dev@dpdk.org>
Subject: Re: [PATCH 1/4] bus/pci: Use force-noreplace flag when mapping PCI resources
Date: Thu, 8 May 2025 13:32:50 +0200 [thread overview]
Message-ID: <53d50d81-75ae-4d23-89b2-bfd6e5733550@intel.com> (raw)
In-Reply-To: <20250506174046.1136711-2-jfree@FreeBSD.org>
On 5/6/2025 7:40 PM, Jake Freeland wrote:
> When mapping PCI resources in secondary processes, use the
> RTE_MAP_FORCE_ADDRESS_NOREPLACE flag to indicate that the
> mapping must be made at the provided address.
>
> Without this flag, the kernel might return a different address for
> the mapping, even if the requested region was available.
>
> Signed-off-by: Jake Freeland <jfree@FreeBSD.org>
> ---
> drivers/bus/pci/pci_common_uio.c | 4 +++-
> lib/eal/common/eal_private.h | 7 ++++++-
> lib/eal/include/rte_eal_paging.h | 7 ++++++-
> lib/eal/unix/eal_unix_memory.c | 8 +++++++-
> 4 files changed, 22 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/bus/pci/pci_common_uio.c b/drivers/bus/pci/pci_common_uio.c
> index 30503bd23a..71974e9f56 100644
> --- a/drivers/bus/pci/pci_common_uio.c
> +++ b/drivers/bus/pci/pci_common_uio.c
> @@ -10,6 +10,7 @@
> #include <sys/mman.h>
>
> #include <rte_eal.h>
> +#include <rte_eal_paging.h>
> #include <rte_pci.h>
> #include <rte_bus_pci.h>
> #include <rte_tailq.h>
> @@ -58,7 +59,8 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>
> void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
> fd, (off_t)uio_res->maps[i].offset,
> - (size_t)uio_res->maps[i].size, 0);
> + (size_t)uio_res->maps[i].size,
> + RTE_MAP_FORCE_ADDRESS_NOREPLACE);
>
> /* fd is not needed in secondary process, close it */
> close(fd);
> diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h
> index 04ba8ddb86..aaeb140eaf 100644
> --- a/lib/eal/common/eal_private.h
> +++ b/lib/eal/common/eal_private.h
> @@ -211,7 +211,12 @@ enum eal_mem_reserve_flags {
> * @see RTE_MAP_FORCE_ADDRESS for description of possible consequences
> * (although implementations are not required to use it).
> */
> - EAL_RESERVE_FORCE_ADDRESS = 1 << 1
> + EAL_RESERVE_FORCE_ADDRESS = 1 << 1,
> + /**
> + * Force reserving memory at the requested address, but fail if a
> + * preexisting mapping collides with the request.
> + */
> + EAL_RESERVE_FORCE_ADDRESS_NOREPLACE = 1 << 2,
> };
>
> /**
> diff --git a/lib/eal/include/rte_eal_paging.h b/lib/eal/include/rte_eal_paging.h
> index c60317d0f5..7b1983b615 100644
> --- a/lib/eal/include/rte_eal_paging.h
> +++ b/lib/eal/include/rte_eal_paging.h
> @@ -34,7 +34,12 @@ enum rte_map_flags {
> * may remove all other mappings in the requested region. However,
> * it is not required to do so, thus mapping with this flag may fail.
> */
> - RTE_MAP_FORCE_ADDRESS = 1 << 3
> + RTE_MAP_FORCE_ADDRESS = 1 << 3,
> + /**
> + * Force mapping to the requested address, but fail if a preexisting
> + * mapping collides with the request.
> + */
> + RTE_MAP_FORCE_ADDRESS_NOREPLACE = 1 << 4,
> };
>
> /**
> diff --git a/lib/eal/unix/eal_unix_memory.c b/lib/eal/unix/eal_unix_memory.c
> index c540f1e838..61e914b8db 100644
> --- a/lib/eal/unix/eal_unix_memory.c
> +++ b/lib/eal/unix/eal_unix_memory.c
> @@ -17,11 +17,13 @@
> #ifdef RTE_EXEC_ENV_LINUX
> #define EAL_DONTDUMP MADV_DONTDUMP
> #define EAL_DODUMP MADV_DODUMP
> +#define EAL_FIXED_NOREPLACE MAP_FIXED_NOREPLACE
Is this available in all supported Linux kernel versions?
--
Thanks,
Anatoly
next prev parent reply other threads:[~2025-05-08 11:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-06 17:40 [PATCH 0/4] BSD PCI Fixes Jake Freeland
2025-05-06 17:40 ` [PATCH 1/4] bus/pci: Use force-noreplace flag when mapping PCI resources Jake Freeland
2025-05-08 11:32 ` Burakov, Anatoly [this message]
2025-05-06 17:40 ` [PATCH 2/4] bus/pci/bsd: Map resources at EAL baseaddr Jake Freeland
2025-05-08 11:31 ` Burakov, Anatoly
2025-05-06 17:40 ` [PATCH 3/4] bus/pci/bsd: Eliminate potential overflow Jake Freeland
2025-05-08 11:28 ` Burakov, Anatoly
2025-05-06 17:40 ` [PATCH 4/4] bus/pci/bsd: Fix device existence check Jake Freeland
2025-05-08 11:27 ` Burakov, Anatoly
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53d50d81-75ae-4d23-89b2-bfd6e5733550@intel.com \
--to=anatoly.burakov@intel.com \
--cc=bruce.richardson@intel.com \
--cc=chenbox@nvidia.com \
--cc=dev@dpdk.org \
--cc=jfree@FreeBSD.org \
--cc=nipun.gupta@amd.com \
--cc=roretzla@linux.microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).