From: Kuniyuki Iwashima <kuniyu@google.com>
To: Alexander Lobakin <aleksander.lobakin@intel.com>,
Tony Nguyen <anthony.l.nguyen@intel.com>,
Przemek Kitszel <przemyslaw.kitszel@intel.com>,
Jesper Dangaard Brouer <hawk@kernel.org>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Brian Vazquez <brianvv@google.com>,
David Decotigny <decot@google.com>, Li Li <boolli@google.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
Kuniyuki Iwashima <kuni1840@gmail.com>,
intel-wired-lan@lists.osuosl.org
Subject: [PATCH v2 iwl-next 5/5] idpf: Unmap Rx payload pages above mapped threshold under DMA-FQ IOMMU.
Date: Sat, 5 Dec 2026 21:52:23 +0900 [thread overview]
Message-ID: <20261205125237.2290932-6-kuniyu@google.com> (raw)
In-Reply-To: <20261205125237.2290932-1-kuniyu@google.com>
In splitq mode under an IOMMU DMA-FQ domain, page_pool keeps
every Rx payload page DMA-mapped until it is released back to the
pool.
When running tcp_stream with 100000 flows,
# tcp_stream -6 --suicide-length=2000 --min-rto=5 --num-threads=256 \
--test-length=30 --num-flows=100000 --num-ports=20 -B 65536
on the server side, Rx payload pages pinned in socket queues
saturate the 32-bit IOVA window, causing every subsequent DMA
mapping (including Tx in idpf_tx_splitq_frame()) to contend on
alloc_iova(), and perf shows heavy contention with 13.8M dropped
packets:
21.62% switchto-defaul [kernel.kallsyms] [k] queued_spin_lock_slowpath
|
---queued_spin_lock_slowpath
_raw_spin_lock_irqsave
alloc_iova
alloc_iova_fast
iommu_dma_alloc_iova
__iommu_dma_map
__iommu_dma_map_phys
iommu_dma_map_phys
dma_map_phys
idpf_tx_splitq_frame
dev_hard_start_xmit
sch_direct_xmit
__qdisc_run
# ethtool -S eth1 | grep -E 'ingress_drop3|rx-hsplit'
rx-hsplit: 92006
rx-hsplit_hbo: 393
ingress_drop3.packets: 488310980 # before neper
ingress_drop3.bytes: 1989178010650
rx-hsplit: 27779097
rx-hsplit_hbo: 611
ingress_drop3.packets: 502138587 # after neper
ingress_drop3.bytes: 2046991419840
# dmesg
...
[ 1291.279869] idpf 0000:01:00.0: Using 56-bit DMA addresses
On the client side, we can see many retransmissions, and the
throughput is 161 Gbps w/ 200G NIC.
remote_throughput=161031856462
TcpInSegs 19235891 0.0
TcpOutSegs 225122216 0.0
TcpRetransSegs 20767366 0.0
Even with iommu.forcedac=1, IOVA nodes continue accumulating across
the IOMMU rbtree because iova_depot_work_func() drains only one
magazine (127 PFNs) every 100 ms, which still leads to alloc_iova()
soft lockup under heavy churn.
Let's unmap Rx payload pages early in splitq mode once active DMA
mappings exceed a per-queue threshold when XDP is disabled and the
device is DMA-coherent under IOMMU_DOMAIN_DMA_FQ.
Under those conditions, we opt in via page_pool_enable_dma_unmap(),
allocate a per-bufq tracking ring (bufq->buf_dma), and set a new
IDPF_Q_DMA_UNMAP flag on the buffer queue.
Instead of unmapping every page unconditionally, normal page_pool
DMA caching is kept while page_pool_dma_mapped_pages() stays at or
below ring->thresh, avoiding per-page IOMMU map/unmap overhead for
healthy low-flow workloads.
ring->thresh splits a 2G IOVA budget evenly across all buffer queues
of all vports on the adapter, floored above the pages needed to fill
the HW ring and page_pool alloc cache so large multi-queue rings
stay in normal recycling mode while idle.
Once page_pool_dma_mapped_pages() exceeds ring->thresh, new pages
(at offset 0) are tracked with active descriptor refcounts across
sub-page fragments and unmapped via page_pool_dma_unmap_netmem()
once all of their descriptors complete in idpf_rx_splitq_clean().
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
v2:
* Switch from unconditional DMA unmapping (fq.no_dma_map) to
threshold-based early unmapping via page_pool_dma_unmap_netmem()
* Fall back to normal page_pool caching if ring allocation fails
---
drivers/net/ethernet/intel/idpf/idpf_txrx.c | 212 ++++++++++++++++++--
drivers/net/ethernet/intel/idpf/idpf_txrx.h | 7 +-
2 files changed, 203 insertions(+), 16 deletions(-)
diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
index fb6a2ea25dc5..a21f21cf66ec 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
@@ -3,6 +3,7 @@
#include <linux/dma-mapping.h>
#include <linux/iommu.h>
+#include <linux/sizes.h>
#include "idpf.h"
#include "idpf_ptp.h"
@@ -11,6 +12,37 @@
#include "xsk.h"
#define IDPF_RX_HDR_BUF_SIZE ALIGN(LIBETH_MAX_HEAD, LIBETH_RX_BUF_STRIDE)
+#define IDPF_RX_DMA_INVALID_ID U16_MAX
+
+/**
+ * struct idpf_rx_dma_entry - Early-unmap tracker slot for an Rx payload page
+ * @refs: number of active HW descriptors referencing this page
+ * @next_free: index of the next free entry, or %IDPF_RX_DMA_INVALID_ID
+ */
+struct idpf_rx_dma_entry {
+ u16 refs;
+ u16 next_free;
+};
+
+/**
+ * struct idpf_rx_dma_ring - Per-bufq early-unmap tracker for Rx payload pages
+ * @cur_page: most recently tracked netmem page for sub-page frag sharing
+ * @page_ids: per-buf_id tracker slot index, or %IDPF_RX_DMA_INVALID_ID
+ * @cur_id: entry index corresponding to @cur_page, or %IDPF_RX_DMA_INVALID_ID
+ * @free_head: head of the free entry list, or %IDPF_RX_DMA_INVALID_ID
+ * @active: number of tracked entries currently in use
+ * @thresh: page_pool DMA-mapped page threshold above which pages are unmapped
+ * @entries: flexible array of early-unmap slots indexed by tracker ID
+ */
+struct idpf_rx_dma_ring {
+ netmem_ref cur_page;
+ u16 *page_ids;
+ u16 cur_id;
+ u16 free_head;
+ u16 active;
+ u32 thresh;
+ struct idpf_rx_dma_entry entries[];
+};
#define idpf_tx_buf_next(buf) (*(u32 *)&(buf)->priv)
LIBETH_SQE_CHECK_PRIV(u32);
@@ -395,6 +427,49 @@ static void idpf_rx_hdr_buf_rel_all(struct idpf_buf_queue *bufq)
bufq->hdr_pp = NULL;
}
+/**
+ * idpf_rx_buf_dma_unmap - Unmap tracked Rx payload page when all descriptors finish
+ * @bufq: buffer queue owning the descriptor
+ * @buf_id: buffer index in @bufq
+ *
+ * Drops the HW descriptor refcount for a tracked page and asks page_pool to
+ * unmap it early once @refs reaches 0. Must be called from the owning NAPI
+ * poll.
+ */
+static void idpf_rx_buf_dma_unmap(struct idpf_buf_queue *bufq, u32 buf_id)
+{
+ struct idpf_rx_dma_entry *entry;
+ struct idpf_rx_dma_ring *ring;
+ u16 id;
+
+ if (!idpf_queue_has(DMA_UNMAP, bufq))
+ return;
+
+ ring = bufq->buf_dma;
+ if (!ring->active)
+ return;
+
+ id = ring->page_ids[buf_id];
+ if (id == IDPF_RX_DMA_INVALID_ID)
+ return;
+
+ ring->page_ids[buf_id] = IDPF_RX_DMA_INVALID_ID;
+ entry = &ring->entries[id];
+ if (--entry->refs)
+ return;
+
+ page_pool_dma_unmap_netmem(bufq->pp, bufq->buf[buf_id].netmem);
+
+ if (ring->cur_id == id) {
+ ring->cur_id = IDPF_RX_DMA_INVALID_ID;
+ ring->cur_page = 0;
+ }
+
+ entry->next_free = ring->free_head;
+ ring->free_head = id;
+ ring->active--;
+}
+
/**
* idpf_rx_buf_rel_bufq - Free all Rx buffer resources for a buffer queue
* @bufq: queue to be cleaned
@@ -426,6 +501,9 @@ static void idpf_rx_buf_rel_bufq(struct idpf_buf_queue *bufq)
idpf_rx_hdr_buf_rel_all(bufq);
libeth_rx_fq_destroy(&fq);
+ kvfree(bufq->buf_dma);
+ bufq->buf_dma = NULL;
+ idpf_queue_clear(DMA_UNMAP, bufq);
bufq->buf = NULL;
bufq->pp = NULL;
}
@@ -625,6 +703,56 @@ static void idpf_post_buf_refill(struct idpf_sw_queue *refillq, u16 buf_id)
refillq->next_to_use = nta;
}
+/**
+ * idpf_rx_buf_dma_track - Track Rx payload page for early unmap above threshold
+ * @bufq: buffer queue owning the descriptor
+ * @rx_buf: Rx buffer containing the allocated netmem
+ * @buf_id: buffer index in @bufq
+ *
+ * Increments the descriptor refcount for consecutive frags on an already-tracked
+ * page, or starts tracking a fresh page when page_pool DMA-mapped pages exceed
+ * @ring->thresh. Must be called from the owning NAPI poll or control path.
+ */
+static void idpf_rx_buf_dma_track(struct idpf_buf_queue *bufq,
+ const struct libeth_fqe *rx_buf, u32 buf_id)
+{
+ struct idpf_rx_dma_ring *ring = bufq->buf_dma;
+ struct idpf_rx_dma_entry *entry;
+ u16 id;
+
+ if (ring->cur_id != IDPF_RX_DMA_INVALID_ID &&
+ ring->cur_page == rx_buf->netmem) {
+ id = ring->cur_id;
+ ring->entries[id].refs++;
+ ring->page_ids[buf_id] = id;
+ return;
+ }
+
+ if (rx_buf->offset || page_pool_dma_mapped_pages(bufq->pp) <= ring->thresh) {
+ if (unlikely(ring->cur_id != IDPF_RX_DMA_INVALID_ID)) {
+ ring->cur_id = IDPF_RX_DMA_INVALID_ID;
+ ring->cur_page = 0;
+ }
+ return;
+ }
+
+ id = ring->free_head;
+ if (WARN_ON_ONCE(id == IDPF_RX_DMA_INVALID_ID)) {
+ ring->cur_id = IDPF_RX_DMA_INVALID_ID;
+ ring->cur_page = 0;
+ return;
+ }
+
+ entry = &ring->entries[id];
+ ring->free_head = entry->next_free;
+ ring->active++;
+ entry->refs = 1;
+
+ ring->cur_id = id;
+ ring->cur_page = rx_buf->netmem;
+ ring->page_ids[buf_id] = id;
+}
+
/**
* idpf_rx_update_bufq_desc - Update buffer queue descriptor
* @bufq: Pointer to the buffer queue
@@ -656,23 +784,22 @@ static int idpf_rx_update_bufq_desc(struct idpf_buf_queue *bufq, u32 buf_id,
if (idpf_queue_has(HSPLIT_COHERENT, bufq)) {
buf_desc->hdr_addr = cpu_to_le64(bufq->hdr_buf_pa +
(dma_addr_t)buf_id * IDPF_RX_HDR_BUF_SIZE);
- return 0;
- }
-
- if (!idpf_queue_has(HSPLIT_EN, bufq))
- return 0;
-
- fq.pp = bufq->hdr_pp;
- fq.fqes = bufq->hdr_buf;
- fq.truesize = bufq->hdr_truesize;
+ } else if (idpf_queue_has(HSPLIT_EN, bufq)) {
+ fq.pp = bufq->hdr_pp;
+ fq.fqes = bufq->hdr_buf;
+ fq.truesize = bufq->hdr_truesize;
+
+ addr = __libeth_rx_alloc(&fq, buf_id, gfp);
+ if (addr == DMA_MAPPING_ERROR) {
+ idpf_rx_page_rel(&bufq->buf[buf_id]);
+ return -ENOMEM;
+ }
- addr = __libeth_rx_alloc(&fq, buf_id, gfp);
- if (addr == DMA_MAPPING_ERROR) {
- idpf_rx_page_rel(&bufq->buf[buf_id]);
- return -ENOMEM;
+ buf_desc->hdr_addr = cpu_to_le64(addr);
}
- buf_desc->hdr_addr = cpu_to_le64(addr);
+ if (idpf_queue_has(DMA_UNMAP, bufq))
+ idpf_rx_buf_dma_track(bufq, &bufq->buf[buf_id], buf_id);
return 0;
}
@@ -851,13 +978,14 @@ static void idpf_rx_hdr_buf_alloc_coherent(struct idpf_rxq_group *rx_qgrp,
static int idpf_rx_bufs_init(struct idpf_buf_queue *bufq,
enum libeth_fqe_type type)
{
+ struct idpf_vport *vport = bufq->q_vector->vport;
struct libeth_fq fq = {
.truesize = bufq->truesize,
.count = bufq->desc_count,
.type = type,
.buf_len = IDPF_RX_MAX_BUF_SZ,
.hsplit = idpf_queue_has(HSPLIT_EN, bufq),
- .xdp = idpf_xdp_enabled(bufq->q_vector->vport),
+ .xdp = idpf_xdp_enabled(vport),
.nid = idpf_q_vector_to_mem(bufq->q_vector),
};
int ret;
@@ -869,6 +997,59 @@ static int idpf_rx_bufs_init(struct idpf_buf_queue *bufq,
if (ret)
return ret;
+ if (PP_DMA_INDEX_BITS && !fq.xdp &&
+ !dma_dev_need_sync(&vport->adapter->pdev->dev)) {
+ struct iommu_domain *domain;
+
+ domain = iommu_get_domain_for_dev(&vport->adapter->pdev->dev);
+ if (domain && domain->type == IOMMU_DOMAIN_DMA_FQ) {
+ struct idpf_rx_dma_ring *ring;
+ u32 min_thresh, num_bufqs = 0;
+ size_t size;
+
+ size = size_add(struct_size(ring, entries, bufq->desc_count),
+ array_size(sizeof(*ring->page_ids),
+ bufq->desc_count));
+ ring = kvzalloc_node(size, GFP_KERNEL, fq.nid);
+ if (ring) {
+ ring->page_ids =
+ (u16 *)&ring->entries[bufq->desc_count];
+ ring->cur_id = IDPF_RX_DMA_INVALID_ID;
+ ring->free_head = 0;
+ for (u32 i = 0; i < bufq->desc_count; i++) {
+ ring->entries[i].next_free = i + 1;
+ ring->page_ids[i] =
+ IDPF_RX_DMA_INVALID_ID;
+ }
+ ring->entries[bufq->desc_count - 1].next_free =
+ IDPF_RX_DMA_INVALID_ID;
+
+ idpf_for_each_vport(vport->adapter, v)
+ num_bufqs +=
+ v->dflt_qv_rsrc.num_rxq_grp *
+ v->dflt_qv_rsrc.num_bufqs_per_qgrp;
+ num_bufqs = max_t(u32, 1, num_bufqs);
+
+ min_thresh = DIV_ROUND_UP_ULL((u64)bufq->desc_count *
+ fq.truesize,
+ PAGE_SIZE << fq.pp->p.order) +
+ PP_ALLOC_CACHE_SIZE;
+ /* Leave 2G headroom in the 32-bit window
+ * across all vports, while keeping normal
+ * caching for pages posted to HW rings.
+ */
+ ring->thresh = max_t(u32, min_thresh,
+ (SZ_2G >>
+ (PAGE_SHIFT + fq.pp->p.order)) /
+ num_bufqs);
+
+ page_pool_enable_dma_unmap(fq.pp);
+ bufq->buf_dma = ring;
+ idpf_queue_set(DMA_UNMAP, bufq);
+ }
+ }
+ }
+
bufq->pp = fq.pp;
bufq->buf = fq.fqes;
bufq->truesize = fq.truesize;
@@ -3948,6 +4129,7 @@ static int idpf_rx_splitq_clean(struct idpf_rx_queue *rxq, int budget)
buf_id = le16_to_cpu(rx_desc->buf_id);
rx_buf = &rx_bufq->buf[buf_id];
+ idpf_rx_buf_dma_unmap(rx_bufq, buf_id);
if (!coherent_hdr && !rx_bufq->hdr_pp)
goto payload;
diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.h b/drivers/net/ethernet/intel/idpf/idpf_txrx.h
index 3fad569d27b8..01ccd04dc003 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.h
+++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.h
@@ -289,6 +289,8 @@ struct idpf_ptype_state {
* @__IDPF_Q_RSC_EN: enable Receive Side Coalescing on Rx (splitq)
* @__IDPF_Q_HSPLIT_EN: enable header split on Rx (splitq)
* @__IDPF_Q_HSPLIT_COHERENT: use coherent DMA buffer for Rx header split
+ * @__IDPF_Q_DMA_UNMAP: unmap Rx payload pages above mapped threshold under
+ * DMA-FQ IOMMU
* @__IDPF_Q_PTP: indicates whether the Rx timestamping is enabled for the
* queue
* @__IDPF_Q_NOIRQ: queue is polling-driven and has no interrupt
@@ -305,6 +307,7 @@ enum idpf_queue_flags_t {
__IDPF_Q_RSC_EN,
__IDPF_Q_HSPLIT_EN,
__IDPF_Q_HSPLIT_COHERENT,
+ __IDPF_Q_DMA_UNMAP,
__IDPF_Q_PTP,
__IDPF_Q_NOIRQ,
__IDPF_Q_XDP,
@@ -751,6 +754,7 @@ libeth_cacheline_set_assert(struct idpf_tx_queue, 64,
* @pending: number of buffers to refill (Xsk)
* @hdr_truesize: truesize for buffer headers
* @truesize: truesize for data buffers
+ * @buf_dma: early-unmap tracker for payload pages under DMA-FQ IOMMU
* @q_id: Queue id
* @size: Length of descriptor ring in bytes
* @dma: Physical address of ring
@@ -798,6 +802,7 @@ struct idpf_buf_queue {
u32 pending;
u32 hdr_truesize;
u32 truesize;
+ struct idpf_rx_dma_ring *buf_dma;
__cacheline_group_end_aligned(read_write);
__cacheline_group_begin_aligned(cold);
@@ -812,7 +817,7 @@ struct idpf_buf_queue {
u16 rx_buf_size;
__cacheline_group_end_aligned(cold);
};
-libeth_cacheline_set_assert(struct idpf_buf_queue, 64, 24, 32);
+libeth_cacheline_set_assert(struct idpf_buf_queue, 64, 32, 32);
/**
* struct idpf_compl_queue - software structure representing a completion queue
--
2.56.1.915.g69d5ec7298-goog
next prev parent reply other threads:[~2026-12-05 12:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 12:52 [PATCH v2 iwl-next 0/5] idpf: Avoid IOVA exhaustion under DMA-FQ IOMMU Kuniyuki Iwashima
2026-12-05 12:52 ` [PATCH v2 iwl-next 1/5] idpf: Reuse idpf_rx_update_bufq_desc() in idpf_rx_post_buf_desc() Kuniyuki Iwashima
2026-12-05 12:52 ` [PATCH v2 iwl-next 2/5] idpf: Use coherent DMA buffer for Rx header split without XDP Kuniyuki Iwashima
2026-12-05 12:52 ` [PATCH v2 iwl-next 3/5] netmem: Annotate data-races around pp_magic Kuniyuki Iwashima
2026-12-05 12:52 ` [PATCH v2 iwl-next 4/5] page_pool: Allow drivers to unmap DMA before returning pages Kuniyuki Iwashima
2026-12-05 13:15 ` sashiko-bot
2026-12-05 12:52 ` Kuniyuki Iwashima [this message]
2026-12-05 13:16 ` [PATCH v2 iwl-next 5/5] idpf: Unmap Rx payload pages above mapped threshold under DMA-FQ IOMMU sashiko-bot
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=20261205125237.2290932-6-kuniyu@google.com \
--to=kuniyu@google.com \
--cc=aleksander.lobakin@intel.com \
--cc=anthony.l.nguyen@intel.com \
--cc=boolli@google.com \
--cc=brianvv@google.com \
--cc=decot@google.com \
--cc=hawk@kernel.org \
--cc=ilias.apalodimas@linaro.org \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=kuni1840@gmail.com \
--cc=przemyslaw.kitszel@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.