From: Shai Brandes <shaibran@amazon.com>
To: <stephen@networkplumber.org>
Cc: <dev@dpdk.org>, Shai Brandes <shaibran@amazon.com>,
<stable@dpdk.org>, Amit Bernstein <amitbern@amazon.com>
Subject: [PATCH 10/21] net/ena: fix PCI BAR mapping on 64K page size
Date: Wed, 15 Oct 2025 10:11:22 +0300 [thread overview]
Message-ID: <20251015071122.700-1-shaibran@amazon.com> (raw)
On 64K page systems, DPDK `pci_uio` driver aligns the physical address
to a 64K boundary before assigning a virtual address.
If the original physical BAR address is not 64K-aligned,
this adjustment leads to an incorrect mapping.
This patch ensures the BAR virtual address received in the driver accounts
for both PAGE size and BAR physical offset to correctly map each BAR.
The fix is compatible for every PAGE size, applies to every used BAR,
and supports both 32/64 bit DPDK builds.
Example issue:
- BAR0 physical address: 0x80208000 (not 64K-aligned)
- DPDK aligned physical address: 0x80208000 -> 0x80200000
(masking 0x8000 offset)
- DPDK mapped physical to virtual address: 0x80200000 -> 0x1140000000
- Driver accessed BAR0 virtual address = 0x1140000000
(causing init failure)
- Resolution is to add correct offset to driver BAR0 address:
0x1140000000 + 0x8000
Fixes: 1173fca25af9 ("ena: add polling-mode driver")
Cc: stable@dpdk.org
Signed-off-by: Amit Bernstein <amitbern@amazon.com>
Signed-off-by: Shai Brandes <shaibran@amazon.com>
Reviewed-by: Yosef Raisman <yraisman@amazon.com>
---
doc/guides/rel_notes/release_25_11.rst | 1 +
drivers/net/ena/ena_ethdev.c | 28 ++++++++++++++++++++++----
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/doc/guides/rel_notes/release_25_11.rst b/doc/guides/rel_notes/release_25_11.rst
index a8fbd0a483..9a9eea371d 100644
--- a/doc/guides/rel_notes/release_25_11.rst
+++ b/doc/guides/rel_notes/release_25_11.rst
@@ -58,6 +58,7 @@ New Features
* **Updated Amazon ENA (Elastic Network Adapter) net driver.**
* Added support for retrieving HW timestamps for Rx packets with nanosecond resolution.
+ * Fixed PCI BAR mapping on 64K page size.
* **Added speed 800G.**
diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c
index 5147a754b2..aaa4feb11b 100644
--- a/drivers/net/ena/ena_ethdev.c
+++ b/drivers/net/ena/ena_ethdev.c
@@ -9,6 +9,7 @@
#include <rte_version.h>
#include <rte_net.h>
#include <rte_kvargs.h>
+#include <rte_eal_paging.h>
#include "ena_ethdev.h"
#include "ena_logs.h"
@@ -2364,6 +2365,24 @@ static int ena_init_once(void)
return 0;
}
+/*
+ * Returns PCI BAR virtual address.
+ * If the physical address is not page-aligned,
+ * adjusts the virtual address by the page offset.
+ * Assumes page size is a power of 2.
+ */
+static void *pci_bar_addr(struct rte_pci_device *dev, uint32_t bar)
+{
+ const struct rte_mem_resource *res = &dev->mem_resource[bar];
+ size_t offset = res->phys_addr % rte_mem_page_size();
+ void *vaddr = RTE_PTR_ADD(res->addr, offset);
+
+ PMD_INIT_LOG_LINE(INFO, "PCI BAR [%u]: phys_addr=0x%" PRIx64 ", addr=%p, offset=0x%zx, adjusted_addr=%p",
+ bar, res->phys_addr, res->addr, offset, vaddr);
+
+ return vaddr;
+}
+
static int eth_ena_dev_init(struct rte_eth_dev *eth_dev)
{
struct ena_calc_queue_size_ctx calc_queue_ctx = { 0 };
@@ -2409,16 +2428,17 @@ static int eth_ena_dev_init(struct rte_eth_dev *eth_dev)
intr_handle = pci_dev->intr_handle;
- adapter->regs = pci_dev->mem_resource[ENA_REGS_BAR].addr;
- adapter->dev_mem_base = pci_dev->mem_resource[ENA_MEM_BAR].addr;
-
+ adapter->regs = pci_bar_addr(pci_dev, ENA_REGS_BAR);
if (!adapter->regs) {
PMD_INIT_LOG_LINE(CRIT, "Failed to access registers BAR(%d)",
ENA_REGS_BAR);
return -ENXIO;
}
-
ena_dev->reg_bar = adapter->regs;
+
+ /* Memory BAR may be NULL on non LLQ supported devices */
+ adapter->dev_mem_base = pci_bar_addr(pci_dev, ENA_MEM_BAR);
+
/* Pass device data as a pointer which can be passed to the IO functions
* by the ena_com (for example - the memory allocation).
*/
--
2.17.1
reply other threads:[~2025-10-15 7:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20251015071122.700-1-shaibran@amazon.com \
--to=shaibran@amazon.com \
--cc=amitbern@amazon.com \
--cc=dev@dpdk.org \
--cc=stable@dpdk.org \
--cc=stephen@networkplumber.org \
/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).