* [PATCH v1 iwl-next 1/5] idpf: Reuse idpf_rx_update_bufq_desc() in idpf_rx_post_buf_desc().
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 ` 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
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-02 6:57 UTC (permalink / raw)
To: Alexander Lobakin, Tony Nguyen, Przemek Kitszel
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, intel-wired-lan
idpf_rx_post_buf_desc() and idpf_rx_update_bufq_desc() duplicate
the same header and payload buffer allocation and descriptor setup
logic, except that idpf_rx_post_buf_desc() allocates with
GFP_KERNEL for the initial ring fill while idpf_rx_clean_refillq()
allocates with GFP_ATOMIC from NAPI.
Also, in later commits we will extend buffer allocation to support
coherent header buffers and custom DMA mapping.
Let's add a gfp_t gfp parameter to idpf_rx_update_bufq_desc(), move
it up, and reuse it in idpf_rx_post_buf_desc().
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
drivers/net/ethernet/intel/idpf/idpf_txrx.c | 123 ++++++++------------
1 file changed, 50 insertions(+), 73 deletions(-)
diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
index b1f072ac2cea..7a33ab913069 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
@@ -595,48 +595,68 @@ static void idpf_post_buf_refill(struct idpf_sw_queue *refillq, u16 buf_id)
}
/**
- * idpf_rx_post_buf_desc - Post buffer to bufq descriptor ring
- * @bufq: buffer queue to post to
- * @buf_id: buffer id to post
- *
- * Only used for the initial fill, from process context, so it allocates
- * with GFP_KERNEL.
+ * idpf_rx_update_bufq_desc - Update buffer queue descriptor
+ * @bufq: Pointer to the buffer queue
+ * @buf_id: buffer ID
+ * @buf_desc: Buffer queue descriptor
+ * @gfp: allocation flags (GFP_KERNEL for initial fill, GFP_ATOMIC from NAPI)
*
- * Return: %false if buffer could not be allocated, %true otherwise.
+ * Return: 0 on success and negative on failure.
*/
-static bool idpf_rx_post_buf_desc(struct idpf_buf_queue *bufq, u16 buf_id)
+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 virtchnl2_splitq_rx_buf_desc *splitq_rx_desc = NULL;
struct libeth_fq_fp fq = {
- .count = bufq->desc_count,
+ .pp = bufq->pp,
+ .fqes = bufq->buf,
+ .truesize = bufq->truesize,
+ .count = bufq->desc_count,
};
- u16 nta = bufq->next_to_alloc;
dma_addr_t addr;
- splitq_rx_desc = &bufq->split_buf[nta];
+ addr = __libeth_rx_alloc(&fq, buf_id, gfp);
+ if (addr == DMA_MAPPING_ERROR)
+ return -ENOMEM;
+
+ buf_desc->pkt_addr = cpu_to_le64(addr);
+ buf_desc->qword0.buf_id = cpu_to_le16(buf_id);
- if (idpf_queue_has(HSPLIT_EN, bufq)) {
- fq.pp = bufq->hdr_pp;
- fq.fqes = bufq->hdr_buf;
- fq.truesize = bufq->hdr_truesize;
+ if (!idpf_queue_has(HSPLIT_EN, bufq))
+ return 0;
- addr = __libeth_rx_alloc(&fq, buf_id, GFP_KERNEL);
- if (addr == DMA_MAPPING_ERROR)
- return false;
+ fq.pp = bufq->hdr_pp;
+ fq.fqes = bufq->hdr_buf;
+ fq.truesize = bufq->hdr_truesize;
- splitq_rx_desc->hdr_addr = cpu_to_le64(addr);
+ addr = __libeth_rx_alloc(&fq, buf_id, gfp);
+ if (addr == DMA_MAPPING_ERROR) {
+ idpf_rx_page_rel(&bufq->buf[buf_id]);
+ return -ENOMEM;
}
- fq.pp = bufq->pp;
- fq.fqes = bufq->buf;
- fq.truesize = bufq->truesize;
+ buf_desc->hdr_addr = cpu_to_le64(addr);
- addr = __libeth_rx_alloc(&fq, buf_id, GFP_KERNEL);
- if (addr == DMA_MAPPING_ERROR)
- return false;
+ return 0;
+}
- splitq_rx_desc->pkt_addr = cpu_to_le64(addr);
- splitq_rx_desc->qword0.buf_id = cpu_to_le16(buf_id);
+/**
+ * idpf_rx_post_buf_desc - Post buffer to bufq descriptor ring
+ * @bufq: buffer queue to post to
+ * @buf_id: buffer id to post
+ *
+ * Only used for the initial fill, from process context, so it allocates
+ * with GFP_KERNEL.
+ *
+ * Return: %false if buffer could not be allocated, %true otherwise.
+ */
+static bool idpf_rx_post_buf_desc(struct idpf_buf_queue *bufq, u16 buf_id)
+{
+ u16 nta = bufq->next_to_alloc;
+
+ if (idpf_rx_update_bufq_desc(bufq, buf_id, &bufq->split_buf[nta],
+ GFP_KERNEL))
+ return false;
nta++;
if (unlikely(nta == bufq->desc_count))
@@ -3759,50 +3779,6 @@ static int idpf_rx_splitq_clean(struct idpf_rx_queue *rxq, int budget)
return rs.packets;
}
-/**
- * idpf_rx_update_bufq_desc - Update buffer queue descriptor
- * @bufq: Pointer to the buffer queue
- * @buf_id: buffer ID
- * @buf_desc: Buffer queue descriptor
- *
- * Return: 0 on success and negative on failure.
- */
-static int idpf_rx_update_bufq_desc(struct idpf_buf_queue *bufq, u32 buf_id,
- struct virtchnl2_splitq_rx_buf_desc *buf_desc)
-{
- struct libeth_fq_fp fq = {
- .pp = bufq->pp,
- .fqes = bufq->buf,
- .truesize = bufq->truesize,
- .count = bufq->desc_count,
- };
- dma_addr_t addr;
-
- addr = libeth_rx_alloc(&fq, buf_id);
- if (addr == DMA_MAPPING_ERROR)
- return -ENOMEM;
-
- buf_desc->pkt_addr = cpu_to_le64(addr);
- buf_desc->qword0.buf_id = cpu_to_le16(buf_id);
-
- if (!idpf_queue_has(HSPLIT_EN, bufq))
- return 0;
-
- fq.pp = bufq->hdr_pp;
- fq.fqes = bufq->hdr_buf;
- fq.truesize = bufq->hdr_truesize;
-
- addr = libeth_rx_alloc(&fq, buf_id);
- if (addr == DMA_MAPPING_ERROR) {
- idpf_rx_page_rel(&bufq->buf[buf_id]);
- return -ENOMEM;
- }
-
- buf_desc->hdr_addr = cpu_to_le64(addr);
-
- return 0;
-}
-
/**
* idpf_rx_clean_refillq - Clean refill queue buffers
* @bufq: buffer queue to post buffers back to
@@ -3830,7 +3806,8 @@ static void idpf_rx_clean_refillq(struct idpf_buf_queue *bufq,
break;
buf_id = FIELD_GET(IDPF_RFL_BI_BUFID_M, refill_desc);
- failure = idpf_rx_update_bufq_desc(bufq, buf_id, buf_desc);
+ failure = idpf_rx_update_bufq_desc(bufq, buf_id, buf_desc,
+ GFP_ATOMIC);
if (failure)
break;
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v1 iwl-next 2/5] idpf: Use coherent DMA buffer for Rx header split without XDP.
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 ` Kuniyuki Iwashima
2026-12-02 7:19 ` sashiko-bot
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
` (2 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-02 6:57 UTC (permalink / raw)
To: Alexander Lobakin, Tony Nguyen, Przemek Kitszel
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, intel-wired-lan
With header split enabled under an IOMMU DMA domain, idpf uses
page_pool backed by 4K pages for Rx header buffers.
Since a single 4K page is sliced across multiple header buffers,
queued skbs in socket receive and out-of-order queues pin these
pages and retain their DMA mappings, exhausting the 32-bit IOVA
window and causing alloc_iova() contention and Rx drops.
Commit 90912f9f4f2d ("idpf: convert header split mode to libeth +
napi_build_skb()") removed coherent header allocation, so we
reintroduce a coherent copy path only for DMA-coherent devices
under IOMMU DMA domains without XDP to prevent pinned header pages
from exhausting the 32-bit IOVA window.
Rx headers are small and fixed-size, so copying headers into
napi_alloc_skb() from a pre-allocated buffer eliminates per-packet
IOMMU mapping churn and header page pinning.
Let's allocate a single coherent DMA buffer array per buffer
queue when header split is enabled on a DMA-coherent device under
an IOMMU DMA domain without XDP.
If dma_alloc_coherent_node() fails, the queue group falls back to
the existing page_pool path.
On Rx, idpf_rx_splitq_clean_skb() copies headers from the coherent
array (or the full frame when pkt_len <= L1_CACHE_BYTES, or
ETH_HLEN otherwise on header buffer overflow) into napi_alloc_skb()
and attaches payload fragments directly.
If an allocation or bounds check fails mid-frame, rxq->rx_drop
drops remaining descriptors of a multi-descriptor frame across
NAPI polls.
Note that idpf_rx_rsc() also calls pskb_may_pull() to linearise
IP and TCP headers on header buffer overflow.
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
drivers/net/ethernet/intel/idpf/idpf_txrx.c | 261 ++++++++++++++++++--
drivers/net/ethernet/intel/idpf/idpf_txrx.h | 22 +-
2 files changed, 262 insertions(+), 21 deletions(-)
diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
index 7a33ab913069..78558c16412f 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
@@ -1,12 +1,17 @@
// SPDX-License-Identifier: GPL-2.0-only
/* Copyright (C) 2023 Intel Corporation */
+#include <linux/dma-mapping.h>
+#include <linux/iommu.h>
+
#include "idpf.h"
#include "idpf_ptp.h"
#include "idpf_virtchnl.h"
#include "xdp.h"
#include "xsk.h"
+#define IDPF_RX_HDR_BUF_SIZE ALIGN(LIBETH_MAX_HEAD, LIBETH_RX_BUF_STRIDE)
+
#define idpf_tx_buf_next(buf) (*(u32 *)&(buf)->priv)
LIBETH_SQE_CHECK_PRIV(u32);
@@ -361,10 +366,25 @@ static void idpf_rx_page_rel(struct libeth_fqe *rx_buf)
*/
static void idpf_rx_hdr_buf_rel_all(struct idpf_buf_queue *bufq)
{
- struct libeth_fq fq = {
- .fqes = bufq->hdr_buf,
- .pp = bufq->hdr_pp,
- };
+ struct libeth_fq fq;
+
+ if (idpf_queue_has(HSPLIT_COHERENT, bufq)) {
+ if (!bufq->hdr_buf_va)
+ return;
+
+ dma_free_coherent(&bufq->q_vector->vport->adapter->pdev->dev,
+ bufq->desc_count * IDPF_RX_HDR_BUF_SIZE,
+ bufq->hdr_buf_va, bufq->hdr_buf_pa);
+ bufq->hdr_buf_va = NULL;
+ bufq->hdr_buf_pa = 0;
+ return;
+ }
+
+ if (!bufq->hdr_pp)
+ return;
+
+ fq.fqes = bufq->hdr_buf;
+ fq.pp = bufq->hdr_pp;
for (u32 i = 0; i < bufq->desc_count; i++)
idpf_rx_page_rel(&bufq->hdr_buf[i]);
@@ -385,6 +405,9 @@ static void idpf_rx_buf_rel_bufq(struct idpf_buf_queue *bufq)
.pp = bufq->pp,
};
+ if (idpf_queue_has(HSPLIT_COHERENT, bufq))
+ idpf_rx_hdr_buf_rel_all(bufq);
+
/* queue already cleared, nothing to do */
if (!bufq->buf)
return;
@@ -442,8 +465,15 @@ static void idpf_rx_desc_rel(struct idpf_rx_queue *rxq, struct device *dev,
if (!rxq)
return;
- if (!idpf_queue_has(XSK, rxq))
- libeth_xdp_return_stash(&rxq->xdp);
+ if (!idpf_queue_has(XSK, rxq)) {
+ if (idpf_queue_has(HSPLIT_COHERENT, rxq)) {
+ dev_kfree_skb_any(rxq->skb);
+ rxq->skb = NULL;
+ rxq->rx_drop = false;
+ } else {
+ libeth_xdp_return_stash(&rxq->xdp);
+ }
+ }
if (!idpf_is_queue_model_split(model))
idpf_rx_buf_rel_all(rxq);
@@ -622,6 +652,13 @@ static int idpf_rx_update_bufq_desc(struct idpf_buf_queue *bufq, u32 buf_id,
buf_desc->pkt_addr = cpu_to_le64(addr);
buf_desc->qword0.buf_id = cpu_to_le16(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;
@@ -746,7 +783,8 @@ static int idpf_rx_buf_alloc_all(struct idpf_buf_queue *rxbufq)
{
int err = 0;
- if (idpf_queue_has(HSPLIT_EN, rxbufq)) {
+ if (idpf_queue_has(HSPLIT_EN, rxbufq) &&
+ !idpf_queue_has(HSPLIT_COHERENT, rxbufq)) {
err = idpf_rx_hdr_buf_alloc_all(rxbufq);
if (err)
goto rx_buf_alloc_all_out;
@@ -799,6 +837,46 @@ static int idpf_rx_bufs_init(struct idpf_buf_queue *bufq,
return idpf_rx_buf_alloc_all(bufq);
}
+static void idpf_rx_hdr_buf_alloc_coherent(struct idpf_rxq_group *rx_qgrp,
+ u16 num_bufqs)
+{
+ struct idpf_buf_queue *bufq = &rx_qgrp->splitq.bufq_sets[0].bufq;
+ struct device *dev = &bufq->q_vector->vport->adapter->pdev->dev;
+
+ if (!idpf_queue_has(HSPLIT_COHERENT, bufq))
+ return;
+
+ for (unsigned int j = 0; j < num_bufqs; j++) {
+ dma_addr_t pa;
+ void *va;
+
+ bufq = &rx_qgrp->splitq.bufq_sets[j].bufq;
+ va = dma_alloc_coherent_node(dev,
+ bufq->desc_count * IDPF_RX_HDR_BUF_SIZE,
+ &pa, GFP_KERNEL | __GFP_NOWARN,
+ idpf_q_vector_to_mem(bufq->q_vector));
+ if (!va)
+ goto fallback;
+
+ bufq->hdr_buf_va = va;
+ bufq->hdr_buf_pa = pa;
+ bufq->rx_hbuf_size = IDPF_RX_HDR_BUF_SIZE;
+ }
+
+ return;
+
+fallback:
+ for (unsigned int j = 0; j < num_bufqs; j++) {
+ bufq = &rx_qgrp->splitq.bufq_sets[j].bufq;
+ idpf_rx_hdr_buf_rel_all(bufq);
+ idpf_queue_clear(HSPLIT_COHERENT, bufq);
+ }
+
+ for (unsigned int j = 0; j < rx_qgrp->splitq.num_rxq_sets; j++)
+ idpf_queue_clear(HSPLIT_COHERENT,
+ &rx_qgrp->splitq.rxq_sets[j]->rxq);
+}
+
/**
* idpf_rx_bufs_init_all - Initialize all RX bufs
* @vport: pointer to vport struct
@@ -834,6 +912,9 @@ int idpf_rx_bufs_init_all(struct idpf_vport *vport,
continue;
}
+ idpf_rx_hdr_buf_alloc_coherent(rx_qgrp,
+ rsrc->num_bufqs_per_qgrp);
+
/* Otherwise, allocate bufs for the buffer queues */
for (unsigned int j = 0; j < rsrc->num_bufqs_per_qgrp; j++) {
enum libeth_fqe_type type;
@@ -1850,8 +1931,10 @@ static int idpf_rxq_group_alloc(struct idpf_vport *vport,
u16 num_rxq)
{
struct idpf_adapter *adapter = vport->adapter;
+ struct device *dev = &adapter->pdev->dev;
struct idpf_rxq_group *rxq_grps;
- bool hs, rsc;
+ struct iommu_domain *domain;
+ bool hs, rsc, coherent_hdr;
int err;
rxq_grps = kzalloc_objs(struct idpf_rxq_group, rsrc->num_rxq_grp);
@@ -1861,6 +1944,11 @@ static int idpf_rxq_group_alloc(struct idpf_vport *vport,
hs = idpf_vport_get_hsplit(vport) == ETHTOOL_TCP_DATA_SPLIT_ENABLED;
rsc = idpf_is_feature_ena(vport, NETIF_F_GRO_HW);
+ domain = iommu_get_domain_for_dev(dev);
+ coherent_hdr = hs && !idpf_xdp_enabled(vport) &&
+ domain && iommu_is_dma_domain(domain) &&
+ !dma_dev_need_sync(dev);
+
for (unsigned int i = 0; i < rsrc->num_rxq_grp; i++) {
struct idpf_rxq_group *rx_qgrp = &rxq_grps[i];
@@ -1906,6 +1994,7 @@ static int idpf_rxq_group_alloc(struct idpf_vport *vport,
q->rx_buffer_low_watermark = IDPF_LOW_WATERMARK;
idpf_queue_assign(HSPLIT_EN, q, hs);
+ idpf_queue_assign(HSPLIT_COHERENT, q, coherent_hdr);
idpf_queue_assign(RSC_EN, q, rsc);
bufq_set->refillqs = kcalloc(num_rxq, swq_size,
@@ -1949,6 +2038,7 @@ static int idpf_rxq_group_alloc(struct idpf_vport *vport,
&rx_qgrp->splitq.bufq_sets[1].refillqs[j];
idpf_queue_assign(HSPLIT_EN, q, hs);
+ idpf_queue_assign(HSPLIT_COHERENT, q, coherent_hdr);
idpf_queue_assign(RSC_EN, q, rsc);
q->rx_ptype_lkup = adapter->splitq_pt_lkup;
@@ -3450,14 +3540,20 @@ static int idpf_rx_rsc(struct idpf_rx_queue *rxq, struct sk_buff *skb,
if (unlikely(!(ipv4 ^ ipv6)))
return -EINVAL;
+ if (unlikely(eth_type_vlan(skb->protocol)))
+ l3_start = VLAN_HLEN;
+
+ if (unlikely(!pskb_may_pull(skb, l3_start +
+ (ipv4 ? sizeof(struct iphdr) :
+ sizeof(struct ipv6hdr)) +
+ sizeof(struct tcphdr))))
+ return -EINVAL;
+
rsc_segments = DIV_ROUND_UP(skb->data_len, rsc_seg_len);
NAPI_GRO_CB(skb)->count = rsc_segments;
skb_shinfo(skb)->gso_size = rsc_seg_len;
- if (unlikely(eth_type_vlan(skb->protocol)))
- l3_start = VLAN_HLEN;
-
skb_set_network_header(skb, l3_start);
if (ipv4) {
@@ -3638,13 +3734,122 @@ static bool idpf_rx_splitq_test_staterr(const u8 stat_err_field,
* Return: %true if the buffer is an EOP buffer, %false otherwise, indicating
* that this is in fact a non-EOP buffer.
*/
-static bool idpf_rx_splitq_is_eop(struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc)
+static bool
+idpf_rx_splitq_is_eop(const struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc)
{
/* if we are the last buffer then there is nothing else to do */
return likely(idpf_rx_splitq_test_staterr(rx_desc->status_err0_qw1,
IDPF_RXD_EOF_SPLITQ));
}
+static void
+idpf_rx_splitq_clean_skb(struct idpf_rx_queue *rxq,
+ const struct idpf_buf_queue *rx_bufq,
+ const struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc,
+ struct libeth_fqe *rx_buf, u16 buf_id, u32 hdr_len,
+ u32 pkt_len, struct sk_buff **skb_p,
+ struct libeth_rq_napi_stats *rs)
+{
+ bool sync = libeth_rx_sync_for_cpu(rx_buf, pkt_len);
+ bool eop = idpf_rx_splitq_is_eop(rx_desc);
+ struct sk_buff *skb = *skb_p;
+
+ if (unlikely(rxq->rx_drop)) {
+ if (sync)
+ libeth_rx_recycle_slow(rx_buf->netmem);
+ if (eop)
+ rxq->rx_drop = false;
+ return;
+ }
+
+ if (!skb) {
+ const void *va;
+ u32 copy;
+
+ if (hdr_len) {
+ if (unlikely(hdr_len > IDPF_RX_HDR_BUF_SIZE))
+ goto drop_sync;
+
+ va = rx_bufq->hdr_buf_va +
+ (size_t)buf_id * IDPF_RX_HDR_BUF_SIZE;
+ copy = hdr_len;
+
+ rs->hsplit++;
+ } else {
+ u64_stats_update_begin(&rxq->stats_sync);
+ u64_stats_inc(&rxq->q_stats.hsplit_buf_ovf);
+ u64_stats_update_end(&rxq->stats_sync);
+
+ if (!sync)
+ goto drop;
+
+ if (unlikely(netmem_is_net_iov(rx_buf->netmem)))
+ goto drop_sync;
+
+ copy = pkt_len <= L1_CACHE_BYTES ? pkt_len : ETH_HLEN;
+ va = page_address(__netmem_to_page(rx_buf->netmem)) +
+ rx_buf->offset + rx_bufq->pp->p.offset;
+ rx_buf->offset += copy;
+ pkt_len -= copy;
+ }
+
+ skb = napi_alloc_skb(rxq->napi, copy);
+ if (unlikely(!skb))
+ goto drop_sync;
+
+ skb_put_data(skb, va, copy);
+ if (sync && !pkt_len) {
+ libeth_rx_recycle_slow(rx_buf->netmem);
+ sync = false;
+ }
+ }
+
+ if (sync) {
+ int nr_frags = skb_shinfo(skb)->nr_frags;
+
+ if (unlikely(nr_frags >= MAX_SKB_FRAGS)) {
+ dev_kfree_skb_any(skb);
+ *skb_p = NULL;
+ goto drop_sync;
+ }
+
+ skb_mark_for_recycle(skb);
+ skb_add_rx_frag_netmem(skb, nr_frags, rx_buf->netmem,
+ rx_buf->offset + rx_bufq->pp->p.offset,
+ pkt_len, rx_buf->truesize);
+ }
+
+ if (!eop) {
+ *skb_p = skb;
+ return;
+ }
+
+ rs->packets++;
+ rs->bytes += skb->len;
+ if (skb_is_nonlinear(skb))
+ rs->fragments += skb_shinfo(skb)->nr_frags + 1;
+
+ skb_record_rx_queue(skb, rxq->idx);
+ skb->protocol = eth_type_trans(skb, rxq->napi->dev);
+
+ if (unlikely(__idpf_rx_process_skb_fields(rxq, skb, rx_desc))) {
+ napi_consume_skb(skb, true);
+ *skb_p = NULL;
+ return;
+ }
+
+ napi_gro_receive(rxq->napi, skb);
+ *skb_p = NULL;
+ return;
+
+drop_sync:
+ if (sync)
+ libeth_rx_recycle_slow(rx_buf->netmem);
+drop:
+ if (!eop)
+ rxq->rx_drop = true;
+}
+
/**
* idpf_rx_splitq_clean - Clean completed descriptors from Rx queue
* @rxq: Rx descriptor queue to retrieve receive buffer queue
@@ -3659,15 +3864,19 @@ static bool idpf_rx_splitq_is_eop(struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_de
*/
static int idpf_rx_splitq_clean(struct idpf_rx_queue *rxq, int budget)
{
+ bool coherent_hdr = idpf_queue_has(HSPLIT_COHERENT, rxq);
+ struct sk_buff *skb = coherent_hdr ? rxq->skb : NULL;
struct idpf_buf_queue *rx_bufq = NULL;
struct libeth_rq_napi_stats rs = { };
u16 ntc = rxq->next_to_clean;
LIBETH_XDP_ONSTACK_BUFF(xdp);
LIBETH_XDP_ONSTACK_BULK(bq);
- libeth_xdp_tx_init_bulk(&bq, rxq->xdp_prog, rxq->xdp_rxq.dev,
- rxq->xdpsqs, rxq->num_xdp_txq);
- libeth_xdp_init_buff(xdp, &rxq->xdp, &rxq->xdp_rxq);
+ if (!coherent_hdr) {
+ libeth_xdp_tx_init_bulk(&bq, rxq->xdp_prog, rxq->xdp_rxq.dev,
+ rxq->xdpsqs, rxq->num_xdp_txq);
+ libeth_xdp_init_buff(xdp, &rxq->xdp, &rxq->xdp_rxq);
+ }
/* Process Rx packets bounded by budget */
while (likely(rs.packets < budget)) {
@@ -3718,7 +3927,7 @@ static int idpf_rx_splitq_clean(struct idpf_rx_queue *rxq, int budget)
rx_buf = &rx_bufq->buf[buf_id];
- if (!rx_bufq->hdr_pp)
+ if (!coherent_hdr && !rx_bufq->hdr_pp)
goto payload;
#define __HBO_BIT VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_HBO_M
@@ -3734,6 +3943,16 @@ static int idpf_rx_splitq_clean(struct idpf_rx_queue *rxq, int budget)
#undef __HDR_LEN_MASK
#undef __HBO_BIT
+ if (coherent_hdr) {
+ idpf_rx_splitq_clean_skb(rxq, rx_bufq, rx_desc, rx_buf,
+ buf_id, hdr_len, pkt_len, &skb,
+ &rs);
+ rx_buf->netmem = 0;
+ idpf_post_buf_refill(refillq, buf_id);
+ IDPF_RX_BUMP_NTC(rxq, ntc);
+ continue;
+ }
+
hdr = &rx_bufq->hdr_buf[buf_id];
if (unlikely(!hdr_len && !xdp->data)) {
@@ -3765,10 +3984,14 @@ static int idpf_rx_splitq_clean(struct idpf_rx_queue *rxq, int budget)
idpf_xdp_run_pass(xdp, &bq, rxq->napi, &rs, rx_desc);
}
- idpf_xdp_finalize_rx(&bq);
+ if (coherent_hdr) {
+ rxq->skb = skb;
+ } else {
+ idpf_xdp_finalize_rx(&bq);
+ libeth_xdp_save_buff(&rxq->xdp, xdp);
+ }
rxq->next_to_clean = ntc;
- libeth_xdp_save_buff(&rxq->xdp, xdp);
u64_stats_update_begin(&rxq->stats_sync);
u64_stats_add(&rxq->q_stats.packets, rs.packets);
@@ -3858,7 +4081,7 @@ static void idpf_rx_clean_refillq_all(struct idpf_buf_queue *bufq, int nid)
int i;
page_pool_nid_changed(bufq->pp, nid);
- if (bufq->hdr_pp)
+ if (!idpf_queue_has(HSPLIT_COHERENT, bufq) && bufq->hdr_pp)
page_pool_nid_changed(bufq->hdr_pp, nid);
bufq_set = container_of(bufq, struct idpf_bufq_set, bufq);
diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.h b/drivers/net/ethernet/intel/idpf/idpf_txrx.h
index ad54fc5bc8bb..0df23e01be53 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.h
+++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.h
@@ -288,6 +288,7 @@ struct idpf_ptype_state {
* @__IDPF_Q_CRC_EN: enable CRC offload in singleq mode
* @__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_PTP: indicates whether the Rx timestamping is enabled for the
* queue
* @__IDPF_Q_NOIRQ: queue is polling-driven and has no interrupt
@@ -303,6 +304,7 @@ enum idpf_queue_flags_t {
__IDPF_Q_CRC_EN,
__IDPF_Q_RSC_EN,
__IDPF_Q_HSPLIT_EN,
+ __IDPF_Q_HSPLIT_COHERENT,
__IDPF_Q_PTP,
__IDPF_Q_NOIRQ,
__IDPF_Q_XDP,
@@ -491,6 +493,8 @@ struct idpf_tx_queue_stats {
* @xdp: XDP buffer with the current frame
* @xsk: current XDP buffer in XSk mode
* @pool: XSk pool if installed
+ * @skb: partially built skb in coherent header split mode
+ * @rx_drop: drop remaining descriptors of the current Rx packet
* @cached_phc_time: Cached PHC time for the Rx queue
* @stats_sync: See struct u64_stats_sync
* @q_stats: See union idpf_rx_queue_stats
@@ -552,6 +556,10 @@ struct idpf_rx_queue {
struct libeth_xdp_buff *xsk;
struct xsk_buff_pool *pool;
};
+ struct {
+ struct sk_buff *skb;
+ bool rx_drop;
+ };
};
u64 cached_phc_time;
@@ -727,6 +735,8 @@ libeth_cacheline_set_assert(struct idpf_tx_queue, 64,
* @pool: &xsk_buff_pool on XSk queues
* @hdr_buf: &libeth_fqe for header buffers
* @hdr_pp: &page_pool for header buffers
+ * @hdr_buf_va: virtual address of coherent header buffer array
+ * @hdr_buf_pa: DMA address of coherent header buffer array
* @tail: Tail offset
* @flags: See enum idpf_queue_flags_t
* @desc_count: Number of descriptors
@@ -758,8 +768,16 @@ struct idpf_buf_queue {
struct xsk_buff_pool *pool;
};
};
- struct libeth_fqe *hdr_buf;
- struct page_pool *hdr_pp;
+ union {
+ struct {
+ struct libeth_fqe *hdr_buf;
+ struct page_pool *hdr_pp;
+ };
+ struct {
+ void *hdr_buf_va;
+ dma_addr_t hdr_buf_pa;
+ };
+ };
void __iomem *tail;
DECLARE_BITMAP(flags, __IDPF_Q_FLAGS_NBITS);
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v1 iwl-next 2/5] idpf: Use coherent DMA buffer for Rx header split without XDP.
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 7:19 ` sashiko-bot
2026-12-02 7:33 ` Kuniyuki Iwashima
0 siblings, 1 reply; 9+ messages in thread
From: sashiko-bot @ 2026-12-02 7:19 UTC (permalink / raw)
To: Kuniyuki Iwashima; +Cc: intel-wired-lan
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] idpf: wrong RSC segment count in idpf_rx_rsc() on header
buffer overflow
--
commit 3759b354320e7c5e9977e8bab71b077ad23bfb55
Author: Kuniyuki Iwashima <kuniyu@google.com>
idpf: Use coherent DMA buffer for Rx header split without XDP.
This commit allocates a coherent DMA buffer array per buffer queue for Rx
header split on DMA-coherent devices under an IOMMU DMA domain without XDP,
copying Rx headers into napi_alloc_skb() to avoid pinning page_pool header
pages.
> diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
> index 7a33ab9130693..78558c16412f3 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
[ ... ]
> @@ -3450,14 +3540,20 @@ static int idpf_rx_rsc(struct idpf_rx_queue *rxq, struct sk_buff *skb,
> if (unlikely(!(ipv4 ^ ipv6)))
> return -EINVAL;
>
> + if (unlikely(eth_type_vlan(skb->protocol)))
> + l3_start = VLAN_HLEN;
> +
> + if (unlikely(!pskb_may_pull(skb, l3_start +
> + (ipv4 ? sizeof(struct iphdr) :
> + sizeof(struct ipv6hdr)) +
> + sizeof(struct tcphdr))))
> + return -EINVAL;
> +
> rsc_segments = DIV_ROUND_UP(skb->data_len, rsc_seg_len);
[Severity: Medium]
Does idpf_rx_rsc() miscalculate rsc_segments on header buffer overflow when
TCP options are present?
When hdr_len is 0 and pkt_len > L1_CACHE_BYTES, idpf_rx_splitq_clean_skb()
copies only ETH_HLEN bytes into the linear skb area and leaves the L3/L4
headers and payload in frags[0]. pskb_may_pull() here only pulls the fixed
L3 header and the 20-byte base struct tcphdr, leaving any TCP options (such
as the 12-byte TCP timestamp option) in skb->data_len when
DIV_ROUND_UP(skb->data_len, rsc_seg_len) runs. For an RSC packet with N
full segments of rsc_seg_len bytes plus TCP options, rsc_segments and
skb_shinfo(skb)->gso_segs become N + 1 instead of N, causing
tcp_gro_receive() to flush the packet without aggregation (or
tcp_gso_segment() to drop a 1-MSS RSC packet with -EINVAL). Also, if
hdr_len is 0 and pkt_len <= L1_CACHE_BYTES, the entire frame is copied into
linear data so skb->data_len is 0, setting rsc_segments and gso_segs to 0.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202065737.207610-1-kuniyu@google.com?part=2
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v1 iwl-next 2/5] idpf: Use coherent DMA buffer for Rx header split without XDP.
2026-12-02 7:19 ` sashiko-bot
@ 2026-12-02 7:33 ` Kuniyuki Iwashima
0 siblings, 0 replies; 9+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-02 7:33 UTC (permalink / raw)
To: sashiko-reviews; +Cc: intel-wired-lan
On Wed, 02 Dec 2026 07:19:15 +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] idpf: wrong RSC segment count in idpf_rx_rsc() on header
> buffer overflow
> --
>
> commit 3759b354320e7c5e9977e8bab71b077ad23bfb55
> Author: Kuniyuki Iwashima <kuniyu@google.com>
>
> idpf: Use coherent DMA buffer for Rx header split without XDP.
>
> This commit allocates a coherent DMA buffer array per buffer queue for Rx
> header split on DMA-coherent devices under an IOMMU DMA domain without XDP,
> copying Rx headers into napi_alloc_skb() to avoid pinning page_pool header
> pages.
>
> > diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
> > index 7a33ab9130693..78558c16412f3 100644
> > --- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c
> > +++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
>
> [ ... ]
>
> > @@ -3450,14 +3540,20 @@ static int idpf_rx_rsc(struct idpf_rx_queue *rxq, struct sk_buff *skb,
> > if (unlikely(!(ipv4 ^ ipv6)))
> > return -EINVAL;
> >
> > + if (unlikely(eth_type_vlan(skb->protocol)))
> > + l3_start = VLAN_HLEN;
> > +
> > + if (unlikely(!pskb_may_pull(skb, l3_start +
> > + (ipv4 ? sizeof(struct iphdr) :
> > + sizeof(struct ipv6hdr)) +
> > + sizeof(struct tcphdr))))
> > + return -EINVAL;
> > +
> > rsc_segments = DIV_ROUND_UP(skb->data_len, rsc_seg_len);
>
> [Severity: Medium]
> Does idpf_rx_rsc() miscalculate rsc_segments on header buffer overflow when
> TCP options are present?
Oops, will fix it in v2.
>
> When hdr_len is 0 and pkt_len > L1_CACHE_BYTES, idpf_rx_splitq_clean_skb()
> copies only ETH_HLEN bytes into the linear skb area and leaves the L3/L4
> headers and payload in frags[0]. pskb_may_pull() here only pulls the fixed
> L3 header and the 20-byte base struct tcphdr, leaving any TCP options (such
> as the 12-byte TCP timestamp option) in skb->data_len when
> DIV_ROUND_UP(skb->data_len, rsc_seg_len) runs. For an RSC packet with N
> full segments of rsc_seg_len bytes plus TCP options, rsc_segments and
> skb_shinfo(skb)->gso_segs become N + 1 instead of N, causing
> tcp_gro_receive() to flush the packet without aggregation (or
> tcp_gso_segment() to drop a 1-MSS RSC packet with -EINVAL). Also, if
> hdr_len is 0 and pkt_len <= L1_CACHE_BYTES, the entire frame is copied into
> linear data so skb->data_len is 0, setting rsc_segments and gso_segs to 0.
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261202065737.207610-1-kuniyu@google.com?part=2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v1 iwl-next 3/5] page_pool: Set dma_sync_for_cpu only under PP_FLAG_DMA_MAP.
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 ` 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 ` [PATCH v1 iwl-next 5/5] idpf: Unmap Rx payload pages under DMA-FQ IOMMU Kuniyuki Iwashima
4 siblings, 0 replies; 9+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-02 6:57 UTC (permalink / raw)
To: Alexander Lobakin, Tony Nguyen, Przemek Kitszel
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, intel-wired-lan
page_pool_init() currently sets pool->dma_sync_for_cpu to true
unconditionally even when PP_FLAG_DMA_MAP is not set, so callers
that rely on page_pool_dma_sync_netmem_for_cpu() must check
pp->dma_map or manually clear dma_sync_for_cpu.
Since syncing an unmapped page is invalid, let's set
pool->dma_sync_for_cpu to true only under PP_FLAG_DMA_MAP.
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
net/core/page_pool.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index d7c88c0b67e5..4b723bf60325 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -202,7 +202,6 @@ static int page_pool_init(struct page_pool *pool,
memcpy(&pool->slow, ¶ms->slow, sizeof(pool->slow));
pool->cpuid = cpuid;
- pool->dma_sync_for_cpu = true;
/* Validate only known flags were used */
if (pool->slow.flags & ~PP_FLAG_ALL)
@@ -221,6 +220,7 @@ static int page_pool_init(struct page_pool *pool,
return -EINVAL;
pool->dma_map = true;
+ pool->dma_sync_for_cpu = true;
}
if (pool->slow.flags & PP_FLAG_DMA_SYNC_DEV) {
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v1 iwl-next 4/5] libeth: Allow opting out of page_pool DMA mapping on Rx.
2026-12-02 6:57 [PATCH v1 iwl-next 0/5] idpf: Avoid IOVA exhaustion under DMA-FQ IOMMU Kuniyuki Iwashima
` (2 preceding siblings ...)
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 ` Kuniyuki Iwashima
2026-12-02 6:57 ` [PATCH v1 iwl-next 5/5] idpf: Unmap Rx payload pages under DMA-FQ IOMMU Kuniyuki Iwashima
4 siblings, 0 replies; 9+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-02 6:57 UTC (permalink / raw)
To: Alexander Lobakin, Tony Nguyen, Przemek Kitszel
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, intel-wired-lan
libeth_rx_fq_create() always configures PP_FLAG_DMA_MAP and
PP_FLAG_DMA_SYNC_DEV, so drivers cannot manage page_pool DMA
mappings themselves.
Let's add a no_dma_map flag to struct libeth_fq to omit
PP_FLAG_DMA_MAP and PP_FLAG_DMA_SYNC_DEV.
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
drivers/net/ethernet/intel/libeth/rx.c | 3 ++-
include/net/libeth/rx.h | 2 ++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/intel/libeth/rx.c b/drivers/net/ethernet/intel/libeth/rx.c
index 0c1a565a1b3a..c9ab17b16fef 100644
--- a/drivers/net/ethernet/intel/libeth/rx.c
+++ b/drivers/net/ethernet/intel/libeth/rx.c
@@ -153,7 +153,8 @@ int libeth_rx_fq_create(struct libeth_fq *fq, void *napi_dev)
{
struct napi_struct *napi = fq->no_napi ? NULL : napi_dev;
struct page_pool_params pp = {
- .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV,
+ .flags = fq->no_dma_map ? 0 :
+ (PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV),
.order = LIBETH_RX_PAGE_ORDER,
.pool_size = fq->count,
.nid = fq->nid,
diff --git a/include/net/libeth/rx.h b/include/net/libeth/rx.h
index 1333850f421a..9e721cf2aac6 100644
--- a/include/net/libeth/rx.h
+++ b/include/net/libeth/rx.h
@@ -70,6 +70,7 @@ enum libeth_fqe_type {
* @hsplit: flag whether header split is enabled
* @xdp: flag indicating whether XDP is enabled
* @no_napi: the queue is not a data queue and does not have NAPI
+ * @no_dma_map: opt out of page_pool DMA mapping
* @buf_len: HW-writeable length per each buffer
* @nid: ID of the closest NUMA node with memory
*/
@@ -87,6 +88,7 @@ struct libeth_fq {
bool hsplit:1;
bool xdp:1;
bool no_napi:1;
+ bool no_dma_map:1;
u32 buf_len;
int nid;
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v1 iwl-next 5/5] idpf: Unmap Rx payload pages under DMA-FQ IOMMU.
2026-12-02 6:57 [PATCH v1 iwl-next 0/5] idpf: Avoid IOVA exhaustion under DMA-FQ IOMMU Kuniyuki Iwashima
` (3 preceding siblings ...)
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
2026-12-02 7:13 ` sashiko-bot
4 siblings, 1 reply; 9+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-02 6:57 UTC (permalink / raw)
To: Alexander Lobakin, Tony Nguyen, Przemek Kitszel
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, intel-wired-lan
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
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v1 iwl-next 5/5] idpf: Unmap Rx payload pages under DMA-FQ IOMMU.
2026-12-02 6:57 ` [PATCH v1 iwl-next 5/5] idpf: Unmap Rx payload pages under DMA-FQ IOMMU Kuniyuki Iwashima
@ 2026-12-02 7:13 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-02 7:13 UTC (permalink / raw)
To: Kuniyuki Iwashima; +Cc: intel-wired-lan
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] idpf: dangling bufq->xsk_buf pointer in idpf_xskfq_rel()
[1]
--
commit 102db293b209cf2d45959e6eb23ac7fd38343bc6
Author: Kuniyuki Iwashima <kuniyu@google.com>
idpf: Unmap Rx payload pages under DMA-FQ IOMMU.
This commit opts out of page_pool DMA mapping in splitq mode when XDP is
disabled under IOMMU_DOMAIN_DMA_FQ, tracking active descriptor counts per
page and unmapping each payload page once all of its descriptors complete.
> diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
> index 78558c16412f3..561e1c19df006 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
[ ... ]
> @@ -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]);
> + }
> + }
[Severity: Critical]
This problem wasn't introduced by this patch, but can idpf_xskfq_rel()
leave a dangling pointer in bufq->xsk_buf (which shares an anonymous union
with bufq->buf) [1]?
drivers/net/ethernet/intel/idpf/xsk.c:idpf_xskfq_rel() {
struct libeth_xskfq fq = {
.fqes = bufq->xsk_buf,
};
libeth_xskfq_destroy(&fq);
...
}
When disabling or reconfiguring an XSk pool on a running interface via
idpf_xsk_pool_setup(), idpf_rx_buf_rel_bufq() calls idpf_xskfq_rel(bufq)
and returns without clearing bufq->xsk_buf, and idpf_xsk_clear_queue()
then clears __IDPF_Q_XSK. If re-enabling the queue pair in
idpf_qp_switch() fails before bufq->buf is reallocated, a later
idpf_vport_stop() calls idpf_rx_buf_rel_bufq() with __IDPF_Q_XSK cleared
and a non-NULL dangling bufq->buf, causing this loop to walk the freed XSk
pointer array as struct libeth_fqe entries (use-after-free and
out-of-bounds reads) before libeth_rx_fq_destroy() double-frees bufq->buf.
[1] https://sashiko.dev/#/bug/linux-35f48909-5f9a-4fd2-90be-88cfbcea1d44
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202065737.207610-1-kuniyu@google.com?part=5
^ permalink raw reply [flat|nested] 9+ messages in thread