[2/4] bus/pci/bsd: Map resources at EAL baseaddr

Message ID 20250506174046.1136711-3-jfree@FreeBSD.org (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series BSD PCI Fixes |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jake Freeland May 6, 2025, 5:40 p.m. UTC
Provide the EAL base address as a hint to mmap(2), so device resources
are not mapped where malloc(3) et al. make allocations.

This makes mapping conflicts less likely for secondary processes that
make memory allocations before initializing EAL.

Signed-off-by: Jake Freeland <jfree@FreeBSD.org>
---
 drivers/bus/pci/bsd/pci.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
  

Comments

Burakov, Anatoly May 8, 2025, 11:31 a.m. UTC | #1
On 5/6/2025 7:40 PM, Jake Freeland wrote:
> Provide the EAL base address as a hint to mmap(2), so device resources
> are not mapped where malloc(3) et al. make allocations.
> 
> This makes mapping conflicts less likely for secondary processes that
> make memory allocations before initializing EAL.
> 
> Signed-off-by: Jake Freeland <jfree@FreeBSD.org>
> ---

I remember attempting to fix this issue by reserving some amount of 
address space for PCI devices in a similar way memory subsystem reserves 
its address space. This doesn't quite do that but is as good a fix as it 
can get without major rework IMO.

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
  

Patch

diff --git a/drivers/bus/pci/bsd/pci.c b/drivers/bus/pci/bsd/pci.c
index 5e2e09d5a4..0581daf130 100644
--- a/drivers/bus/pci/bsd/pci.c
+++ b/drivers/bus/pci/bsd/pci.c
@@ -182,7 +182,15 @@  pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
 
 	/* if matching map is found, then use it */
 	offset = res_idx * pagesz;
-	mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+
+	/*
+	 * Use baseaddr as a hint to avoid mapping resources where
+	 * malloc(3) et al. usually make allocations. This reduces
+	 * mapping conflicts in secondary processes that make
+	 * memory allocations before initializing EAL.
+	 */
+	mapaddr = pci_map_resource((void *)rte_eal_get_baseaddr(),
+			fd, (off_t)offset,
 			(size_t)dev->mem_resource[res_idx].len, 0);
 	close(fd);
 	if (mapaddr == NULL)