Skip to contentSkip to conversation

octeontx2-pf: Fix page pool cache index corruption.

PATCH In review Ratheesh Kannoth 2 participants 3 messages Sep 4, 2023 – Sep 5, 2023

Subsystems (3)
lore
Share & tools
lore

Ratheesh Kannoth

author maintainer
#0 lore raw

PATCH 1/1 octeontx2-pf: Fix page pool cache index corruption.

The access to page pool cache' array and the count' variable is not locked. Page pool cache access is fine as long as there is only one consumer per pool.

octeontx2 driver fills in rx buffers from page pool in NAPI context. If system is stressed and could not allocate buffers, refiiling work will be delegated to a delayed workqueue. This means that there are two cosumers to the page pool cache.

Either workqueue or IRQ/NAPI can be run on other CPU. This will lead to lock less access, hence corruption of cache pool indexes.

To fix this issue, worqueue is removed. If refilling fails in NAPI context, same NAPI is rescheduled with a delay to redo the filling of rx buffers.

Fixes b2e3406a38f0 ("octeontx2-pf: Add support for page pool")
---
 .../ethernet/marvell/octeontx2/nic/cn10k.c    |  5 +-
 .../ethernet/marvell/octeontx2/nic/cn10k.h    |  2 +-
 .../marvell/octeontx2/nic/otx2_common.c       | 59 -------------------
 .../marvell/octeontx2/nic/otx2_common.h       |  3 +-
 .../ethernet/marvell/octeontx2/nic/otx2_pf.c  |  5 +-
 .../marvell/octeontx2/nic/otx2_txrx.c         | 23 ++++++--
 .../marvell/octeontx2/nic/otx2_txrx.h         |  5 +-
 7 files changed, 27 insertions(+), 75 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/cn10k.c +4 -1
index 826f691de259..026698a78f77 100644
@@ -107,12 +107,13 @@ int cn10k_sq_aq_init(void *dev, u16 qidx, u16 sqb_aura)
 }
 
 #define NPA_MAX_BURST 16
-void cn10k_refill_pool_ptrs(void *dev, struct otx2_cq_queue *cq)
+int cn10k_refill_pool_ptrs(void *dev, struct otx2_cq_queue *cq)
 {
 	struct otx2_nic *pfvf = dev;
 	u64 ptrs[NPA_MAX_BURST];
 	int num_ptrs = 1;
 	dma_addr_t bufptr;
+	int cnt = cq->pool_ptrs;
 
 	/* Refill pool with new buffers */
 	while (cq->pool_ptrs) {
@@ -131,6 +132,8 @@ void cn10k_refill_pool_ptrs(void *dev, struct otx2_cq_queue *cq)
 			num_ptrs = 1;
 		}
 	}
+
+	return cnt - cq->pool_ptrs;
 }
 
 void cn10k_sqe_flush(void *dev, struct otx2_snd_queue *sq, int size, int qidx)
drivers/net/ethernet/marvell/octeontx2/nic/cn10k.h +1 -1
index 8ae96815865e..c1861f7de254 100644
@@ -24,7 +24,7 @@ static inline int mtu_to_dwrr_weight(struct otx2_nic *pfvf, int mtu)
 	return weight;
 }
 
-void cn10k_refill_pool_ptrs(void *dev, struct otx2_cq_queue *cq);
+int cn10k_refill_pool_ptrs(void *dev, struct otx2_cq_queue *cq);
 void cn10k_sqe_flush(void *dev, struct otx2_snd_queue *sq, int size, int qidx);
 int cn10k_sq_aq_init(void *dev, u16 qidx, u16 sqb_aura);
 int cn10k_lmtst_init(struct otx2_nic *pfvf);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +0 -59

84 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +1 -2
index 4c6032ee7800..01e2d35ce1e0 100644
@@ -370,7 +370,7 @@ struct dev_hw_ops {
 	int	(*sq_aq_init)(void *dev, u16 qidx, u16 sqb_aura);
 	void	(*sqe_flush)(void *dev, struct otx2_snd_queue *sq,
 			     int size, int qidx);
-	void	(*refill_pool_ptrs)(void *dev, struct otx2_cq_queue *cq);
+	int	(*refill_pool_ptrs)(void *dev, struct otx2_cq_queue *cq);
 	void	(*aura_freeptr)(void *dev, int aura, u64 buf);
 };
 
@@ -493,7 +493,6 @@ struct otx2_nic {
 	struct work_struct	reset_task;
 	struct workqueue_struct	*flr_wq;
 	struct flr_work		*flr_wrk;
-	struct refill_work	*refill_wrk;
 	struct workqueue_struct	*otx2_wq;
 	struct work_struct	rx_mode_work;
 
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +1 -4
index 70b9065f7d10..c5a6d0e4e157 100644
@@ -1902,7 +1902,7 @@ int otx2_stop(struct net_device *netdev)
 	struct otx2_cq_poll *cq_poll = NULL;
 	struct otx2_qset *qset = &pf->qset;
 	struct otx2_rss_info *rss;
-	int qidx, vec, wrk;
+	int qidx, vec;
 
 	/* If the DOWN flag is set resources are already freed */
 	if (pf->flags & OTX2_FLAG_INTF_DOWN)
@@ -1950,9 +1950,6 @@ int otx2_stop(struct net_device *netdev)
 	for (qidx = 0; qidx < netdev->num_tx_queues; qidx++)
 		netdev_tx_reset_queue(netdev_get_tx_queue(netdev, qidx));
 
-	for (wrk = 0; wrk < pf->qset.cq_cnt; wrk++)
-		cancel_delayed_work_sync(&pf->refill_wrk[wrk].pool_refill_work);
-	devm_kfree(pf->dev, pf->refill_wrk);
 
 	kfree(qset->sq);
 	kfree(qset->cq);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +18 -5
index e369baf11530..cf2e631af58b 100644
@@ -424,10 +424,11 @@ static int otx2_rx_napi_handler(struct otx2_nic *pfvf,
 	return processed_cqe;
 }
 
-void otx2_refill_pool_ptrs(void *dev, struct otx2_cq_queue *cq)
+int otx2_refill_pool_ptrs(void *dev, struct otx2_cq_queue *cq)
 {
 	struct otx2_nic *pfvf = dev;
 	dma_addr_t bufptr;
+	int cnt = cq->pool_ptrs;
 
 	while (cq->pool_ptrs) {
 		if (otx2_alloc_buffer(pfvf, cq, &bufptr))
@@ -435,6 +436,8 @@ void otx2_refill_pool_ptrs(void *dev, struct otx2_cq_queue *cq)
 		otx2_aura_freeptr(pfvf, cq->cq_idx, bufptr + OTX2_HEAD_ROOM);
 		cq->pool_ptrs--;
 	}
+
+	return cnt - cq->pool_ptrs;
 }
 
 static int otx2_tx_napi_handler(struct otx2_nic *pfvf,
@@ -521,6 +524,7 @@ int otx2_napi_handler(struct napi_struct *napi, int budget)
 	struct otx2_cq_queue *cq;
 	struct otx2_qset *qset;
 	struct otx2_nic *pfvf;
+	int filled_cnt = -1;
 
 	cq_poll = container_of(napi, struct otx2_cq_poll, napi);
 	pfvf = (struct otx2_nic *)cq_poll->dev;
@@ -541,7 +545,8 @@ int otx2_napi_handler(struct napi_struct *napi, int budget)
 	}
 
 	if (rx_cq && rx_cq->pool_ptrs)
-		pfvf->hw_ops->refill_pool_ptrs(pfvf, rx_cq);
+		filled_cnt = pfvf->hw_ops->refill_pool_ptrs(pfvf, rx_cq);
+
 	/* Clear the IRQ */
 	otx2_write64(pfvf, NIX_LF_CINTX_INT(cq_poll->cint_idx), BIT_ULL(0));
 
@@ -561,10 +566,18 @@ int otx2_napi_handler(struct napi_struct *napi, int budget)
 				otx2_config_irq_coalescing(pfvf, i);
 		}
 
-		/* Re-enable interrupts */
-		otx2_write64(pfvf, NIX_LF_CINTX_ENA_W1S(cq_poll->cint_idx),
-			     BIT_ULL(0));
+		/* Schedule NAPI again to refill rx buffers */
+		if (unlikely(!filled_cnt)) {
+			udelay(1000);
+			napi_schedule(napi);
+		} else {
+			/* Re-enable interrupts */
+			otx2_write64(pfvf,
+				     NIX_LF_CINTX_ENA_W1S(cq_poll->cint_idx),
+				     BIT_ULL(0));
+		}
 	}
+
 	return workdone;
 }
 
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h +2 -3
index 9e3bfbe5c480..bb718c7ad8f3 100644
@@ -128,7 +128,6 @@ struct otx2_cq_queue {
 	u8			cq_idx;
 	u8			cq_type;
 	u8			cint_idx; /* CQ interrupt id */
-	u8			refill_task_sched;
 	u16			cqe_size;
 	u16			pool_ptrs;
 	u32			cqe_cnt;
@@ -170,6 +169,6 @@ void cn10k_sqe_flush(void *dev, struct otx2_snd_queue *sq,
 		     int size, int qidx);
 void otx2_sqe_flush(void *dev, struct otx2_snd_queue *sq,
 		    int size, int qidx);
-void otx2_refill_pool_ptrs(void *dev, struct otx2_cq_queue *cq);
-void cn10k_refill_pool_ptrs(void *dev, struct otx2_cq_queue *cq);
+int otx2_refill_pool_ptrs(void *dev, struct otx2_cq_queue *cq);
+int cn10k_refill_pool_ptrs(void *dev, struct otx2_cq_queue *cq);
 #endif /* OTX2_TXRX_H */
Signature · 1 line
2.25.1
#1 lore raw

On 2023-09-04 20:13:04 [+0530], Ratheesh Kannoth wrote:
…

Quoted 2 lines
Fixes b2e3406a38f0 ("octeontx2-pf: Add support for page pool")
Quoted 7 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +0 -0
index e369baf11530..cf2e631af58b 100644

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c int otx2_napi_handler(struct napi_struct *napi, int budget) · line 571

Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +3 -3
@@ -561,10 +566,18 @@ int otx2_napi_handler(struct napi_struct *napi, int budget)
 				otx2_config_irq_coalescing(pfvf, i);
 		}
 
-		/* Re-enable interrupts */
-		otx2_write64(pfvf, NIX_LF_CINTX_ENA_W1S(cq_poll->cint_idx),
-			     BIT_ULL(0));
+		/* Schedule NAPI again to refill rx buffers */
+		if (unlikely(!filled_cnt)) {
+			udelay(1000);

A delay of 1ms? Short term I would suggest to set up a timer for polling this case instead of delay. On a UP you wouldn't make progress that way.

Long term it might make sense to allocate new page/ memory before handing the current page/skb over to the stack. Should allocation fail then you have at least one slot (your current one) which can ensure that you can receive on further packet (which you either drop on the floor or pass to the stack).

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c int otx2_napi_handler(struct napi_struct *napi, int budget) · line 582

Quoted 11 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +8 -0
+			napi_schedule(napi);
+		} else {
+			/* Re-enable interrupts */
+			otx2_write64(pfvf,
+				     NIX_LF_CINTX_ENA_W1S(cq_poll->cint_idx),
+				     BIT_ULL(0));
+		}
 	}
+
 	return workdone;
 }

Sebastian

author maintainer
#2 lore raw
Quoted 9 lines

From: Sebastian Andrzej Siewior <[email protected]>
Sent: Tuesday, September 5, 2023 1:21 PM
To: Ratheesh Kannoth <[email protected]>
Subject: [EXT] Re: [PATCH net] octeontx2-pf: Fix page pool cache index corruption.

A delay of 1ms? Short term I would suggest to set up a timer for polling this case instead of delay. On a UP you wouldn't make progress that way.

ACK.
We don’t have a UP case, anyway will make the changes.