Skip to contentSkip to conversation

idpf: queue based scheduling fixes

PATCH In review Joshua Hay 2 participants 5 messages Jun 2 – Jun 10

Subsystems (4)
lore
Share & tools
lore

Joshua Hay

author
#0 lore raw

v2 cover idpf: queue based scheduling fixes

This series fixes some TxQ scheduling mode issues exposed by recent FW changes, as well as some issues reported by Sashiko.

Patch 1 prevents XDP from being enabled if queue based scheduling is not supported by the firmware.

Patch 2 fixes a data race when accessing next_to_clean in IDPF_DESC_UNUSED.

Patch 3 fixes a NULL ptr dereference in the Tx path when queue based scheduling is enabled, and also adds support to process both 4 and 8 byte completion descriptors to avoid timeouts in queue based scheduling mode.

Joshua Hay (3):
idpf: do not enable XDP if queue based scheduling is not supported
idpf: fix next_to_clean data races
idpf: fix skb datapath queue based scheduling crashes and timeouts

 .../ethernet/intel/idpf/idpf_singleq_txrx.c   |  3 +-
 drivers/net/ethernet/intel/idpf/idpf_txrx.c   | 60 ++++++++++++-------
 drivers/net/ethernet/intel/idpf/idpf_txrx.h   | 15 +++--
 drivers/net/ethernet/intel/idpf/xdp.c         | 10 ++++
 4 files changed, 62 insertions(+), 26 deletions(-)
Signature · 1 line
2.39.2
author
#1 lore raw

PATCH v2 1/3 idpf: do not enable XDP if queue based scheduling is not supported

The current XDP implementation uses queue based scheduling for its TxQs. If the FW does not advertise support for queue based scheduling, do not enable XDP. Add the missing capability check at the start of the XDP configuration. This will temporarily break XDP while a flow based implementation is worked on, as well as while FWs with queue based by default are rolled out.

Fixes 705457e7211f ("idpf: implement XDP_SETUP_PROG in ndo_bpf for splitq")

---
v1->v2: use local extack to use pass either properly initialized xdp->extack or NULL to netlink macro.

---
 drivers/net/ethernet/intel/idpf/xdp.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/ethernet/intel/idpf/xdp.c +10 -0
index cbccd4546768..ecec7db4ebc0 100644
@@ -510,6 +510,16 @@ int idpf_xdp(struct net_device *dev, struct netdev_bpf *xdp)
 	if (!idpf_is_queue_model_split(vport->dflt_qv_rsrc.txq_model))
 		goto notsupp;
 
+	if (!idpf_is_cap_ena(vport->adapter, IDPF_OTHER_CAPS,
+			     VIRTCHNL2_CAP_SPLITQ_QSCHED)) {
+		struct netlink_ext_ack *extack = xdp->command == XDP_SETUP_PROG ?
+						 xdp->extack : NULL;
+
+		NL_SET_ERR_MSG_MOD(extack,
+				   "Device does not support requested XDP Tx scheduling mode");
+		goto notsupp;
+	}
+
 	switch (xdp->command) {
 	case XDP_SETUP_PROG:
 		ret = idpf_xdp_setup_prog(vport, xdp);
Signature · 1 line
2.39.2
#2 lore raw

Re: [Intel-wired-lan] [PATCH net v2 1/3] idpf: do not enable XDP if queue based scheduling is not supported

From: Joshua Hay <[email protected]>
Date: Tue, 2 Jun 2026 10:20:22 -0700

Quoted 23 lines

The current XDP implementation uses queue based scheduling for its TxQs. If the FW does not advertise support for queue based scheduling, do not enable XDP. Add the missing capability check at the start of the XDP configuration. This will temporarily break XDP while a flow based implementation is worked on, as well as while FWs with queue based by default are rolled out.

Fixes 705457e7211f ("idpf: implement XDP_SETUP_PROG in ndo_bpf for splitq")

---
v1->v2: use local extack to use pass either properly initialized xdp->extack or NULL to netlink macro.

---
 drivers/net/ethernet/intel/idpf/xdp.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/ethernet/intel/idpf/xdp.c +0 -0
index cbccd4546768..ecec7db4ebc0 100644

drivers/net/ethernet/intel/idpf/xdp.c int idpf_xdp(struct net_device *dev, struct netdev_bpf *xdp) · line 516

Quoted 7 lines
drivers/net/ethernet/intel/idpf/xdp.c +4 -0
@@ -510,6 +510,16 @@ int idpf_xdp(struct net_device *dev, struct netdev_bpf *xdp)
 	if (!idpf_is_queue_model_split(vport->dflt_qv_rsrc.txq_model))
 		goto notsupp;
 
+	if (!idpf_is_cap_ena(vport->adapter, IDPF_OTHER_CAPS,
+			     VIRTCHNL2_CAP_SPLITQ_QSCHED)) {
+		struct netlink_ext_ack *extack = xdp->command == XDP_SETUP_PROG ?
+						 xdp->extack : NULL;

xdp->extack is NULL when removing the program? Interesting.

drivers/net/ethernet/intel/idpf/xdp.c int idpf_xdp(struct net_device *dev, struct netdev_bpf *xdp) · line 525

Quoted 9 lines
drivers/net/ethernet/intel/idpf/xdp.c +6 -0
+
+		NL_SET_ERR_MSG_MOD(extack,
+				   "Device does not support requested XDP Tx scheduling mode");
+		goto notsupp;
+	}
+
 	switch (xdp->command) {
 	case XDP_SETUP_PROG:
 		ret = idpf_xdp_setup_prog(vport, xdp);

Thanks,
Olek

author
#3 lore raw

PATCH v2 2/3 idpf: fix next_to_clean data races

In reply to Joshua Hay

As reported by Sashiko [1], IDPF_DESC_UNUSED() evaluates txq->next_to_clean twice, and next_to_clean can be concurrently updated by NAPI. next_to_clean can change between evaluations, resulting in a miscalculated free descriptor count that is larger than the ring capacity. Consequently, netif_subqueue_maybe_stop() could incorrectly determine there is room in the queue, bypassing the stop mechanism and allowing active in-flight descriptors to be overwritten.

This patch is based on commit 9eab46b7cb8d ("e1000: fix data race between tx_ring->next_to_clean").

---
 drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c | 3 ++-
 drivers/net/ethernet/intel/idpf/idpf_txrx.c         | 9 ++++++---
 drivers/net/ethernet/intel/idpf/idpf_txrx.h         | 9 ++++++---
 3 files changed, 14 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +2 -1
index e3ddf18dcbf5..a0e3de3ed0a9 100644
@@ -558,7 +558,8 @@ static bool idpf_tx_singleq_clean(struct idpf_tx_queue *tx_q, int napi_budget,
 	} while (likely(budget));
 
 	ntc += tx_q->desc_count;
-	tx_q->next_to_clean = ntc;
+	/* Sync with IDPF_DESC_UNUSED called from idpf_tx_singleq_frame. */
+	smp_store_release(&tx_q->next_to_clean, ntc);
 
 	*cleaned += ss.packets;
 
drivers/net/ethernet/intel/idpf/idpf_txrx.c +6 -3
index 34fc85cbb3f4..9cc4fbd13313 100644
@@ -2073,8 +2073,10 @@ static void idpf_tx_splitq_clean(struct idpf_tx_queue *tx_q, u16 end,
 	struct idpf_tx_buf *tx_buf;
 
 	if (descs_only) {
-		/* Bump ring index to mark as cleaned. */
-		tx_q->next_to_clean = end;
+		/* Bump ring index to mark as cleaned and sync with
+		 * IDPF_DESC_UNUSED called from idpf_txq_has_room.
+		 */
+		smp_store_release(&tx_q->next_to_clean, end);
 		return;
 	}
 
@@ -2111,7 +2113,8 @@ static void idpf_tx_splitq_clean(struct idpf_tx_queue *tx_q, u16 end,
 		idpf_tx_splitq_clean_bump_ntc(tx_q, ntc, tx_desc, tx_buf);
 	}
 
-	tx_q->next_to_clean = ntc;
+	/* Sync with IDPF_DESC_UNUSED called from idpf_txq_has_room. */
+	smp_store_release(&tx_q->next_to_clean, ntc);
 }
 
 /**
drivers/net/ethernet/intel/idpf/idpf_txrx.h +6 -3
index 4be5b3b6d3ed..8eadc2682c96 100644
@@ -119,9 +119,12 @@ do {								\
 #define IDPF_RXD_EOF_SPLITQ		VIRTCHNL2_RX_FLEX_DESC_ADV_STATUS0_EOF_M
 #define IDPF_RXD_EOF_SINGLEQ		VIRTCHNL2_RX_BASE_DESC_STATUS_EOF_M
 
-#define IDPF_DESC_UNUSED(txq)     \
-	((((txq)->next_to_clean > (txq)->next_to_use) ? 0 : (txq)->desc_count) + \
-	(txq)->next_to_clean - (txq)->next_to_use - 1)
+#define IDPF_DESC_UNUSED(txq)						\
+({									\
+	unsigned int ntc = smp_load_acquire(&(txq)->next_to_clean);	\
+	unsigned int ntu = READ_ONCE((txq)->next_to_use);		\
+	(ntc > ntu ? 0 : (txq)->desc_count) + ntc - ntu - 1;		\
+})
 
 #define IDPF_TX_COMPLQ_OVERFLOW_THRESH(txcq)	((txcq)->desc_count >> 1)
 /* Determine the absolute number of completions pending, i.e. the number of
Signature · 1 line
2.39.2
author
#4 lore raw

PATCH v2 3/3 idpf: fix skb datapath queue based scheduling crashes and timeouts

In reply to Joshua Hay

The splitq Tx resource checks were assuming that the queues were using flow based scheduling and checking the refillqs for free buffers. However, the Tx refillqs are not allocated when using queue based scheduling resulting in a NULL ptr dereference. Adjust the Tx resource checks to only check available descriptor resources when using queue based scheduling. Because queue based scheduling does not have any notion of descriptor only completions, there cannot be any packets in flight, meaning there is no need to check for pending completions.

The driver also only supported 8 byte completion descriptors in the skb datapath previously. However, currently the FW only supports 4 byte completion descriptors when using queue based scheduling. This meant we were skipping over completions, resulting in Tx timeouts. Add support to process both 4 and 8 byte completion descriptors, depending on the scheduling mode. Cache the next_to_clean completion descriptor in the completion queue struct, and fetch this descriptor before the start of each cleaning loop. Access the next descriptor in the loop by calculating the index based on raw byte count.

As reported by Sashiko [1], add a dma_rmb to read ownership (gen) bit in the completion descriptor before any other fields.

Fixes 0c3f135e840d ("idpf: stop Tx if there are insufficient buffer resources")
Fixes 1c325aac10a8 ("idpf: configure resources for TX queues")

---
v1->v2: add dma_rmb after completion desc gen bit read

---
 drivers/net/ethernet/intel/idpf/idpf_txrx.c | 51 +++++++++++++--------
 drivers/net/ethernet/intel/idpf/idpf_txrx.h |  6 ++-
 2 files changed, 38 insertions(+), 19 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_txrx.c +33 -18
index 9cc4fbd13313..54ef86ebf11f 100644
@@ -270,11 +270,9 @@ static int idpf_tx_desc_alloc(const struct idpf_vport *vport,
 static int idpf_compl_desc_alloc(const struct idpf_vport *vport,
 				 struct idpf_compl_queue *complq)
 {
-	u32 desc_size;
-
-	desc_size = idpf_queue_has(FLOW_SCH_EN, complq) ?
-		    sizeof(*complq->comp) : sizeof(*complq->comp_4b);
-	complq->size = array_size(complq->desc_count, desc_size);
+	complq->desc_sz = idpf_queue_has(FLOW_SCH_EN, complq) ?
+			  sizeof(*complq->comp) : sizeof(*complq->comp_4b);
+	complq->size = array_size(complq->desc_count, complq->desc_sz);
 
 	complq->desc_ring = dma_alloc_coherent(complq->netdev->dev.parent,
 					       complq->size, &complq->dma,
@@ -284,6 +282,7 @@ static int idpf_compl_desc_alloc(const struct idpf_vport *vport,
 
 	complq->next_to_use = 0;
 	complq->next_to_clean = 0;
+	complq->ntc_desc = complq->comp;
 	idpf_queue_set(GEN_CHK, complq);
 
 	idpf_xsk_setup_queue(vport, complq,
@@ -2196,7 +2195,7 @@ static void idpf_tx_handle_rs_completion(struct idpf_tx_queue *txq,
 static bool idpf_tx_clean_complq(struct idpf_compl_queue *complq, int budget,
 				 int *cleaned)
 {
-	struct idpf_splitq_tx_compl_desc *tx_desc;
+	struct idpf_splitq_tx_compl_desc *tx_desc = complq->ntc_desc;
 	s16 ntc = complq->next_to_clean;
 	struct idpf_netdev_priv *np;
 	unsigned int complq_budget;
@@ -2204,7 +2203,6 @@ static bool idpf_tx_clean_complq(struct idpf_compl_queue *complq, int budget,
 	int i;
 
 	complq_budget = complq->clean_budget;
-	tx_desc = &complq->comp[ntc];
 	ntc -= complq->desc_count;
 
 	do {
@@ -2221,6 +2219,8 @@ static bool idpf_tx_clean_complq(struct idpf_compl_queue *complq, int budget,
 		if (idpf_queue_has(GEN_CHK, complq) != gen)
 			break;
 
+		dma_rmb();
+
 		/* Find necessary info of TX queue to clean buffers */
 		rel_tx_qid = le16_get_bits(tx_desc->common.qid_comptype_gen,
 					   IDPF_TXD_COMPLQ_QID_M);
@@ -2260,11 +2260,12 @@ static bool idpf_tx_clean_complq(struct idpf_compl_queue *complq, int budget,
 		u64_stats_update_end(&tx_q->stats_sync);
 
 fetch_next_desc:
-		tx_desc++;
+		tx_desc = (struct idpf_splitq_tx_compl_desc *)
+				((u8 *)tx_desc + complq->desc_sz);
 		ntc++;
 		if (unlikely(!ntc)) {
 			ntc -= complq->desc_count;
-			tx_desc = &complq->comp[0];
+			tx_desc = complq->comp;
 			idpf_queue_change(GEN_CHK, complq);
 		}
 
@@ -2274,6 +2275,8 @@ static bool idpf_tx_clean_complq(struct idpf_compl_queue *complq, int budget,
 		complq_budget--;
 	} while (likely(complq_budget));
 
+	complq->ntc_desc = tx_desc;
+
 	/* Store the state of the complq to be used later in deciding if a
 	 * TXQ can be started again
 	 */
@@ -2440,21 +2443,32 @@ static int idpf_txq_has_room(struct idpf_tx_queue *tx_q, u32 descs_needed,
  * @tx_q: the queue to be checked
  * @descs_needed: number of descriptors required for this packet
  * @bufs_needed: number of buffers needed for this packet
+ * @flow: true if queue uses flow based scheduling, false if queue based scheduling
  *
  * Return: 0 if stop is not needed
  */
 static int idpf_tx_maybe_stop_splitq(struct idpf_tx_queue *tx_q,
-				     u32 descs_needed,
-				     u32 bufs_needed)
+				     u32 descs_needed, u32 bufs_needed,
+				     bool flow)
 {
-	/* Since we have multiple resources to check for splitq, our
+	/* Since we have multiple resources to check for flow based splitq, our
 	 * start,stop_thrs becomes a boolean check instead of a count
 	 * threshold.
 	 */
-	if (netif_subqueue_maybe_stop(tx_q->netdev, tx_q->idx,
-				      idpf_txq_has_room(tx_q, descs_needed,
-							bufs_needed),
-				      1, 1))
+	if (flow && netif_subqueue_maybe_stop(tx_q->netdev, tx_q->idx,
+					      idpf_txq_has_room(tx_q,
+								descs_needed,
+								bufs_needed),
+					      1, 1))
+		return 0;
+
+	/* For queue based splitq, there is no need to check the number of
+	 * pending completions since we cannot reuse descriptors until we get
+	 * completions, so we only need to check for descriptor resources.
+	 */
+	if (!flow && netif_subqueue_maybe_stop(tx_q->netdev, tx_q->idx,
+					       IDPF_DESC_UNUSED(tx_q),
+					       descs_needed, descs_needed))
 		return 0;
 
 	u64_stats_update_begin(&tx_q->stats_sync);
@@ -3024,6 +3038,7 @@ static bool idpf_tx_splitq_need_re(struct idpf_tx_queue *tx_q)
 static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb,
 					struct idpf_tx_queue *tx_q)
 {
+	bool flow = idpf_queue_has(FLOW_SCH_EN, tx_q);
 	struct idpf_tx_splitq_params tx_params = {
 		.prev_ntu = tx_q->next_to_use,
 	};
@@ -3043,7 +3058,7 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb,
 
 	/* Check for splitq specific TX resources */
 	count += (IDPF_TX_DESCS_PER_CACHE_LINE + tso);
-	if (idpf_tx_maybe_stop_splitq(tx_q, count, buf_count)) {
+	if (idpf_tx_maybe_stop_splitq(tx_q, count, buf_count, flow)) {
 		idpf_tx_buf_hw_update(tx_q, tx_q->next_to_use, false);
 
 		return NETDEV_TX_BUSY;
@@ -3075,7 +3090,7 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb,
 		idpf_tx_set_tstamp_desc(ctx_desc, idx);
 	}
 
-	if (idpf_queue_has(FLOW_SCH_EN, tx_q)) {
+	if (flow) {
 		struct idpf_sw_queue *refillq = tx_q->refillq;
 
 		/* Save refillq state in case of a packet rollback.  Otherwise,
drivers/net/ethernet/intel/idpf/idpf_txrx.h +5 -1
index 8eadc2682c96..2a03ec586161 100644
@@ -810,11 +810,13 @@ libeth_cacheline_set_assert(struct idpf_buf_queue, 64, 24, 32);
  * @txq_grp: See struct idpf_txq_group
  * @flags: See enum idpf_queue_flags_t
  * @desc_count: Number of descriptors
+ * @desc_sz: Descriptor size in bytes
  * @clean_budget: queue cleaning budget
  * @netdev: &net_device corresponding to this queue
  * @next_to_use: Next descriptor to use. Relevant in both split & single txq
  *		 and bufq.
  * @next_to_clean: Next descriptor to clean
+ * @ntc_desc: Pointer to next_to_clean descriptor for next NAPI poll
  * @num_completions: Only relevant for TX completion queue. It tracks the
  *		     number of completions received to compare against the
  *		     number of completions pending, as accumulated by the
@@ -836,6 +838,7 @@ struct idpf_compl_queue {
 
 	DECLARE_BITMAP(flags, __IDPF_Q_FLAGS_NBITS);
 	u32 desc_count;
+	u32 desc_sz;
 
 	u32 clean_budget;
 	struct net_device *netdev;
@@ -844,6 +847,7 @@ struct idpf_compl_queue {
 	__cacheline_group_begin_aligned(read_write);
 	u32 next_to_use;
 	u32 next_to_clean;
+	struct idpf_splitq_tx_compl_desc *ntc_desc;
 
 	aligned_u64 num_completions;
 	__cacheline_group_end_aligned(read_write);
@@ -856,7 +860,7 @@ struct idpf_compl_queue {
 	struct idpf_q_vector *q_vector;
 	__cacheline_group_end_aligned(cold);
 };
-libeth_cacheline_set_assert(struct idpf_compl_queue, 40, 16, 24);
+libeth_cacheline_set_assert(struct idpf_compl_queue, 48, 24, 24);
 
 /**
  * struct idpf_sw_queue
Signature · 1 line
2.39.2