All of lore.kernel.org
 help / color / mirror / Atom feed
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>
Cc: Kuniyuki Iwashima <kuniyu@google.com>,
	Kuniyuki Iwashima <kuni1840@gmail.com>,
	intel-wired-lan@lists.osuosl.org
Subject: [PATCH v1 iwl-next 5/5] idpf: Unmap Rx payload pages under DMA-FQ IOMMU.
Date: Wed,  2 Dec 2026 15:57:23 +0900	[thread overview]
Message-ID: <20261202065737.207610-6-kuniyu@google.com> (raw)
In-Reply-To: <20261202065737.207610-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 opt out of page_pool DMA mapping when XDP is disabled under
IOMMU_DOMAIN_DMA_FQ.

Each page tracks active descriptor counts so sub-page fragment
sharing and skb truesize remain unchanged while each page is
unmapped once all of its descriptors complete.

With coherent header split and Rx DMA unmap enabled, we no longer
see huge drops on the server side (84K),

  # ethtool -S eth1 | grep -E 'ingress_drop3|rx-hsplit'
     rx-hsplit: 29763692
     rx-hsplit_hbo: 1782
     ingress_drop3.packets: 488226531   # before neper
     ingress_drop3.bytes: 1988824925613

     rx-hsplit: 58004576
     rx-hsplit_hbo: 2073
     ingress_drop3.packets: 488310980   # after neper
     ingress_drop3.bytes: 1989178010650

and the throughput recovers to 178 Gbps and retransmissions are
reduced by 19x on the client side:

  remote_throughput=178451793325

  TcpInSegs                       14033635           0.0
  TcpOutSegs                      178978164          0.0
  TcpRetransSegs                  1067657            0.0

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
 drivers/net/ethernet/intel/idpf/idpf_txrx.c | 247 +++++++++++++++++++-
 drivers/net/ethernet/intel/idpf/idpf_txrx.h |   8 +-
 2 files changed, 243 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
index 78558c16412f..561e1c19df00 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
@@ -11,6 +11,35 @@
 #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 - DMA mapping slot for an Rx payload page
+ * @dma: base DMA address of the mapped page
+ * @refs: number of active HW descriptors referencing this mapping
+ * @next_free: index of the next free entry, or %IDPF_RX_DMA_INVALID_ID
+ */
+struct idpf_rx_dma_entry {
+	dma_addr_t		dma;
+	u16			refs;
+	u16			next_free;
+};
+
+/**
+ * struct idpf_rx_dma_ring - Per-bufq DMA mapping tracker for Rx payload pages
+ * @cur_page: most recently mapped netmem page for sub-page frag sharing
+ * @page_ids: per-buf_id mapping 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
+ * @entries: flexible array of DMA mapping slots indexed by page ID
+ */
+struct idpf_rx_dma_ring {
+	netmem_ref		cur_page;
+	u16			*page_ids;
+	u16			cur_id;
+	u16			free_head;
+	struct idpf_rx_dma_entry entries[];
+};
 
 #define idpf_tx_buf_next(buf)		(*(u32 *)&(buf)->priv)
 LIBETH_SQE_CHECK_PRIV(u32);
@@ -394,6 +423,60 @@ static void idpf_rx_hdr_buf_rel_all(struct idpf_buf_queue *bufq)
 	bufq->hdr_pp = NULL;
 }
 
+/**
+ * idpf_rx_buf_sync_unmap - Sync Rx payload buffer and unmap page when unused
+ * @bufq: buffer queue owning the descriptor
+ * @buf_id: buffer index in @bufq
+ * @len: received payload length to sync for CPU, or 0 to skip sync
+ *
+ * Syncs CPU access if @len > 0, drops the HW descriptor refcount, and
+ * unmaps the page while resetting @cur_id/@cur_page when refs reaches 0.
+ * Must be called from the owning NAPI poll or control path.
+ */
+static void idpf_rx_buf_sync_unmap(struct idpf_buf_queue *bufq, u32 buf_id,
+				   u32 len)
+{
+	struct idpf_rx_dma_entry *entry;
+	struct idpf_rx_dma_ring *ring;
+	struct page_pool *pp;
+	u16 id;
+
+	if (likely(!idpf_queue_has(DMA_UNMAP, bufq)))
+		return;
+
+	ring = bufq->buf_dma;
+	id = ring->page_ids[buf_id];
+	if (unlikely(id == IDPF_RX_DMA_INVALID_ID))
+		return;
+
+	ring->page_ids[buf_id] = IDPF_RX_DMA_INVALID_ID;
+	entry = &ring->entries[id];
+	pp = bufq->pp;
+
+	if (likely(len)) {
+		const struct libeth_fqe *rx_buf = &bufq->buf[buf_id];
+
+		dma_sync_single_range_for_cpu(pp->p.dev, entry->dma,
+					      rx_buf->offset + pp->p.offset,
+					      len, pp->p.dma_dir);
+	}
+
+	if (--entry->refs)
+		return;
+
+	dma_unmap_page_attrs(pp->p.dev, entry->dma, PAGE_SIZE << pp->p.order,
+			     pp->p.dma_dir,
+			     DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING);
+
+	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;
+}
+
 /**
  * idpf_rx_buf_rel_bufq - Free all Rx buffer resources for a buffer queue
  * @bufq: queue to be cleaned
@@ -418,13 +501,20 @@ static void idpf_rx_buf_rel_bufq(struct idpf_buf_queue *bufq)
 	}
 
 	/* Free all the bufs allocated and given to hw on Rx queue */
-	for (u32 i = 0; i < bufq->desc_count; i++)
-		idpf_rx_page_rel(&bufq->buf[i]);
+	for (u32 i = 0; i < bufq->desc_count; i++) {
+		if (bufq->buf[i].netmem) {
+			idpf_rx_buf_sync_unmap(bufq, i, 0);
+			idpf_rx_page_rel(&bufq->buf[i]);
+		}
+	}
 
 	if (idpf_queue_has(HSPLIT_EN, 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;
 }
@@ -624,6 +714,110 @@ static void idpf_post_buf_refill(struct idpf_sw_queue *refillq, u16 buf_id)
 	refillq->next_to_use = nta;
 }
 
+/**
+ * idpf_rx_buf_dma_map - DMA-map or reuse mapping for an Rx payload buffer
+ * @bufq: buffer queue to map for
+ * @rx_buf: Rx buffer descriptor containing the allocated netmem
+ * @buf_id: buffer index in @bufq
+ *
+ * Reuses the @cur_id DMA mapping for consecutive frags on the same page,
+ * or maps a new page from the free list.  Caller must run in the owning
+ * NAPI poll or control context.
+ *
+ * Return: base DMA address of the mapped page, or %DMA_MAPPING_ERROR.
+ */
+static dma_addr_t idpf_rx_buf_dma_map(struct idpf_buf_queue *bufq,
+				      const struct libeth_fqe *rx_buf,
+				      u32 buf_id)
+{
+	struct idpf_rx_dma_ring *ring = bufq->buf_dma;
+	struct page_pool *pp = bufq->pp;
+	struct idpf_rx_dma_entry *entry;
+	dma_addr_t dma;
+	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 ring->entries[id].dma;
+	}
+
+	id = ring->free_head;
+	if (WARN_ON_ONCE(id == IDPF_RX_DMA_INVALID_ID))
+		return DMA_MAPPING_ERROR;
+
+	dma = dma_map_page_attrs(pp->p.dev, netmem_to_page(rx_buf->netmem), 0,
+				 PAGE_SIZE << pp->p.order, pp->p.dma_dir,
+				 DMA_ATTR_SKIP_CPU_SYNC |
+				 DMA_ATTR_WEAK_ORDERING);
+	if (unlikely(dma_mapping_error(pp->p.dev, dma)))
+		return DMA_MAPPING_ERROR;
+
+	entry = &ring->entries[id];
+	ring->free_head = entry->next_free;
+	entry->dma = dma;
+	entry->refs = 1;
+
+	ring->cur_id = id;
+	ring->cur_page = rx_buf->netmem;
+	ring->page_ids[buf_id] = id;
+
+	return dma;
+}
+
+/**
+ * idpf_rx_buf_alloc - Allocate and DMA-map an Rx payload buffer
+ * @bufq: buffer queue to allocate from
+ * @buf_id: buffer index
+ * @gfp: allocation flags (GFP_KERNEL for initial fill, GFP_ATOMIC from NAPI)
+ *
+ * Return: DMA address for HW, or %DMA_MAPPING_ERROR on allocation failure.
+ */
+static dma_addr_t idpf_rx_buf_alloc(struct idpf_buf_queue *bufq, u32 buf_id,
+				    gfp_t gfp)
+{
+	struct page_pool *pp = bufq->pp;
+	struct libeth_fqe *rx_buf;
+	dma_addr_t dma;
+	u32 truesize;
+
+	if (likely(!idpf_queue_has(DMA_UNMAP, bufq))) {
+		struct libeth_fq_fp fq = {
+			.pp		= pp,
+			.fqes		= bufq->buf,
+			.truesize	= bufq->truesize,
+			.count		= bufq->desc_count,
+		};
+
+		return __libeth_rx_alloc(&fq, buf_id, gfp);
+	}
+
+	truesize = bufq->truesize;
+	rx_buf = &bufq->buf[buf_id];
+	rx_buf->netmem = page_pool_alloc_netmem(pp, &rx_buf->offset,
+						&truesize, gfp | __GFP_NOWARN);
+	if (unlikely(!rx_buf->netmem))
+		return DMA_MAPPING_ERROR;
+
+	rx_buf->truesize = truesize;
+	dma = idpf_rx_buf_dma_map(bufq, rx_buf, buf_id);
+	if (unlikely(dma == DMA_MAPPING_ERROR)) {
+		libeth_rx_recycle_slow(rx_buf->netmem);
+		rx_buf->netmem = 0;
+		return DMA_MAPPING_ERROR;
+	}
+
+	dma_sync_single_range_for_device(pp->p.dev, dma,
+					 rx_buf->offset + pp->p.offset,
+					 truesize - pp->p.offset,
+					 pp->p.dma_dir);
+
+	return dma + rx_buf->offset + pp->p.offset;
+}
+
 /**
  * idpf_rx_update_bufq_desc - Update buffer queue descriptor
  * @bufq: Pointer to the buffer queue
@@ -637,15 +831,10 @@ static int idpf_rx_update_bufq_desc(struct idpf_buf_queue *bufq, u32 buf_id,
 				    struct virtchnl2_splitq_rx_buf_desc *buf_desc,
 				    gfp_t gfp)
 {
-	struct libeth_fq_fp fq = {
-		.pp		= bufq->pp,
-		.fqes		= bufq->buf,
-		.truesize	= bufq->truesize,
-		.count		= bufq->desc_count,
-	};
+	struct libeth_fq_fp fq;
 	dma_addr_t addr;
 
-	addr = __libeth_rx_alloc(&fq, buf_id, gfp);
+	addr = idpf_rx_buf_alloc(bufq, buf_id, gfp);
 	if (addr == DMA_MAPPING_ERROR)
 		return -ENOMEM;
 
@@ -665,9 +854,11 @@ static int idpf_rx_update_bufq_desc(struct idpf_buf_queue *bufq, u32 buf_id,
 	fq.pp = bufq->hdr_pp;
 	fq.fqes = bufq->hdr_buf;
 	fq.truesize = bufq->hdr_truesize;
+	fq.count = bufq->desc_count;
 
 	addr = __libeth_rx_alloc(&fq, buf_id, gfp);
 	if (addr == DMA_MAPPING_ERROR) {
+		idpf_rx_buf_sync_unmap(bufq, buf_id, 0);
 		idpf_rx_page_rel(&bufq->buf[buf_id]);
 		return -ENOMEM;
 	}
@@ -811,24 +1002,56 @@ static int idpf_rx_buf_alloc_all(struct idpf_buf_queue *rxbufq)
 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),
 	};
+	struct iommu_domain *domain;
 	int ret;
 
 	if (idpf_queue_has(XSK, bufq))
 		return idpf_xskfq_init(bufq);
 
+	domain = iommu_get_domain_for_dev(&vport->adapter->pdev->dev);
+	fq.no_dma_map = !fq.xdp && domain && domain->type == IOMMU_DOMAIN_DMA_FQ;
+
 	ret = libeth_rx_fq_create(&fq, &bufq->q_vector->napi);
 	if (ret)
 		return ret;
 
+	if (fq.no_dma_map) {
+		struct idpf_rx_dma_ring *ring;
+		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) {
+			libeth_rx_fq_destroy(&fq);
+			return -ENOMEM;
+		}
+
+		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;
+
+		bufq->buf_dma = ring;
+		idpf_queue_set(DMA_UNMAP, bufq);
+	}
+
 	bufq->pp = fq.pp;
 	bufq->buf = fq.fqes;
 	bufq->truesize = fq.truesize;
@@ -3858,7 +4081,8 @@ idpf_rx_splitq_clean_skb(struct idpf_rx_queue *rxq,
  * This function provides a "bounce buffer" approach to Rx interrupt
  * processing. The advantage to this is that on systems that have
  * expensive overhead for IOMMU access this provides a means of avoiding
- * it by maintaining the mapping of the page to the system.
+ * it by maintaining the mapping of the page to the system, unless
+ * DMA_UNMAP is set under DMA-FQ IOMMU.
  *
  * Return: amount of work completed
  */
@@ -3926,6 +4150,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_sync_unmap(rx_bufq, buf_id, pkt_len);
 
 		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 0df23e01be53..c5a29638891e 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.h
+++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.h
@@ -289,6 +289,7 @@ 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 per packet 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 +306,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,
@@ -726,6 +728,8 @@ libeth_cacheline_set_assert(struct idpf_tx_queue, 64,
 			    offsetofend(struct idpf_tx_queue, tstamp_task),
 			    32);
 
+struct idpf_rx_dma_ring;
+
 /**
  * struct idpf_buf_queue - software structure representing a buffer queue
  * @split_buf: buffer descriptor array
@@ -747,6 +751,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: DMA mapping tracker for payload pages when driver unmaps
  * @q_id: Queue id
  * @size: Length of descriptor ring in bytes
  * @dma: Physical address of ring
@@ -794,6 +799,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);
@@ -808,7 +814,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.911.g883d8bcb20-goog


      parent reply	other threads:[~2026-12-02  6:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  6:57 [PATCH v1 iwl-next 0/5] idpf: Avoid IOVA exhaustion under DMA-FQ IOMMU Kuniyuki Iwashima
2026-12-02  6:57 ` [PATCH v1 iwl-next 1/5] idpf: Reuse idpf_rx_update_bufq_desc() in idpf_rx_post_buf_desc() Kuniyuki Iwashima
2026-12-02  6:57 ` [PATCH v1 iwl-next 2/5] idpf: Use coherent DMA buffer for Rx header split without XDP Kuniyuki Iwashima
2026-12-02  6:57 ` [PATCH v1 iwl-next 3/5] page_pool: Set dma_sync_for_cpu only under PP_FLAG_DMA_MAP Kuniyuki Iwashima
2026-12-02  6:57 ` [PATCH v1 iwl-next 4/5] libeth: Allow opting out of page_pool DMA mapping on Rx Kuniyuki Iwashima
2026-12-02  6:57 ` Kuniyuki Iwashima [this message]

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=20261202065737.207610-6-kuniyu@google.com \
    --to=kuniyu@google.com \
    --cc=aleksander.lobakin@intel.com \
    --cc=anthony.l.nguyen@intel.com \
    --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.