Skip to contentSkip to conversation

Add af_xdp support for cn10k

PATCH Superseded Suman Ghosh 2 participants 9 messages Jan 7, 2025 – Jan 8, 2025

Subsystems (3)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover Add af_xdp support for cn10k

This patchset includes changes to support AF_XDP for cn10k chipsets. Both non-zero copy and zero copy will be supported after these changes. Also, the RSS will be reconfigured once a particular receive queue is added/removed to/from AF_XDP support.

Patch #1: octeontx2-pf: Add AF_XDP non-zero copy support

Patch #2: octeontx2-pf: AF_XDP zero copy receive support

Patch #3: octeontx2-pf: Reconfigure RSS table after enabling AF_XDP zerocopy on rx queue

Patch #4: octeontx2-pf: Don't unmap page pool buffer used by XDP

Patch #5: octeontx2-pf: Prepare for AF_XDP transmit

Patch #6: octeontx2-pf: AF_XDP zero copy transmit support

Geetha sowjanya (1):
octeontx2-pf: Don't unmap page pool buffer used by XDP

Hariprasad Kelam (2):
Octeontx2-pf: Prepare for AF_XDP
octeontx2-pf: AF_XDP zero copy transmit support

Suman Ghosh (3):
octeontx2-pf: Add AF_XDP non-zero copy support
octeontx2-pf: AF_XDP zero copy receive support
octeontx2-pf: Reconfigure RSS table after enabling AF_XDP zerocopy on
rx queue

 .../ethernet/marvell/octeontx2/nic/Makefile   |   2 +-
 .../ethernet/marvell/octeontx2/nic/cn10k.c    |   6 +-
 .../marvell/octeontx2/nic/otx2_common.c       | 128 +++++++---
 .../marvell/octeontx2/nic/otx2_common.h       |  22 +-
 .../marvell/octeontx2/nic/otx2_ethtool.c      |   6 +-
 .../ethernet/marvell/octeontx2/nic/otx2_pf.c  |  25 +-
 .../marvell/octeontx2/nic/otx2_txrx.c         | 161 ++++++++++---
 .../marvell/octeontx2/nic/otx2_txrx.h         |   8 +
 .../ethernet/marvell/octeontx2/nic/otx2_vf.c  |   4 +
 .../ethernet/marvell/octeontx2/nic/otx2_xsk.c | 225 ++++++++++++++++++
 .../ethernet/marvell/octeontx2/nic/otx2_xsk.h |  24 ++
 .../ethernet/marvell/octeontx2/nic/qos_sq.c   |   2 +-
 12 files changed, 541 insertions(+), 72 deletions(-)
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_xsk.c
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_xsk.h
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/6 octeontx2-pf: Add AF_XDP non-zero copy support

For XDP, page_pool APIs are getting used now. But the memory type was not getting set due to which XDP_REDIRECT and hence AF_XDP was not working. This patch ads the memory type MEM_TYPE_PAGE_POOL as the memory model of the XDP program.

---
 .../ethernet/marvell/octeontx2/nic/otx2_common.c    |  8 +++++++-
 .../ethernet/marvell/octeontx2/nic/otx2_common.h    |  1 +
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c  | 13 ++++++++++---
 3 files changed, 18 insertions(+), 4 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +7 -1
index 2b49bfec7869..161cf33ef89e 100644
@@ -1047,6 +1047,7 @@ static int otx2_cq_init(struct otx2_nic *pfvf, u16 qidx)
 	int err, pool_id, non_xdp_queues;
 	struct nix_aq_enq_req *aq;
 	struct otx2_cq_queue *cq;
+	struct otx2_pool *pool;
 
 	cq = &qset->cq[qidx];
 	cq->cq_idx = qidx;
@@ -1055,8 +1056,13 @@ static int otx2_cq_init(struct otx2_nic *pfvf, u16 qidx)
 		cq->cq_type = CQ_RX;
 		cq->cint_idx = qidx;
 		cq->cqe_cnt = qset->rqe_cnt;
-		if (pfvf->xdp_prog)
+		if (pfvf->xdp_prog) {
+			pool = &qset->pool[qidx];
 			xdp_rxq_info_reg(&cq->xdp_rxq, pfvf->netdev, qidx, 0);
+			xdp_rxq_info_reg_mem_model(&cq->xdp_rxq,
+						   MEM_TYPE_PAGE_POOL,
+						   pool->page_pool);
+		}
 	} else if (qidx < non_xdp_queues) {
 		cq->cq_type = CQ_TX;
 		cq->cint_idx = qidx - pfvf->hw.rx_queues;
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +1 -0
index 65814e3dc93f..3748941bbaf1 100644
@@ -21,6 +21,7 @@
 #include <linux/time64.h>
 #include <linux/dim.h>
 #include <uapi/linux/if_macsec.h>
+#include <net/page_pool/helpers.h>
 
 #include <mbox.h>
 #include <npc.h>
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +10 -3
index 224cef938927..ed8b37eb2054 100644
@@ -96,7 +96,7 @@ static unsigned int frag_num(unsigned int i)
 
 static void otx2_xdp_snd_pkt_handler(struct otx2_nic *pfvf,
 				     struct otx2_snd_queue *sq,
-				 struct nix_cqe_tx_s *cqe)
+				     struct nix_cqe_tx_s *cqe)
 {
 	struct nix_send_comp_s *snd_comp = &cqe->comp;
 	struct sg_list *sg;
@@ -109,6 +109,11 @@ static void otx2_xdp_snd_pkt_handler(struct otx2_nic *pfvf,
 	otx2_dma_unmap_page(pfvf, sg->dma_addr[0],
 			    sg->size[0], DMA_TO_DEVICE);
 	page = virt_to_page(phys_to_virt(pa));
+	if (page->pp) {
+		page_pool_recycle_direct(page->pp, page);
+		return;
+	}
+
 	put_page(page);
 }
 
@@ -1419,6 +1424,7 @@ static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
 				     bool *need_xdp_flush)
 {
 	unsigned char *hard_start;
+	struct otx2_pool *pool;
 	int qidx = cq->cq_idx;
 	struct xdp_buff xdp;
 	struct page *page;
@@ -1426,6 +1432,7 @@ static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
 	u32 act;
 	int err;
 
+	pool = &pfvf->qset.pool[qidx];
 	iova = cqe->sg.seg_addr - OTX2_HEAD_ROOM;
 	pa = otx2_iova_to_phys(pfvf->iommu_domain, iova);
 	page = virt_to_page(phys_to_virt(pa));
@@ -1456,7 +1463,7 @@ static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
 			*need_xdp_flush = true;
 			return true;
 		}
-		put_page(page);
+		page_pool_recycle_direct(pool->page_pool, page);
 		break;
 	default:
 		bpf_warn_invalid_xdp_action(pfvf->netdev, prog, act);
@@ -1467,7 +1474,7 @@ static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
 	case XDP_DROP:
 		otx2_dma_unmap_page(pfvf, iova, pfvf->rbsize,
 				    DMA_FROM_DEVICE);
-		put_page(page);
+		page_pool_recycle_direct(pool->page_pool, page);
 		cq->pool_ptrs++;
 		return true;
 	}
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/6 octeontx2-pf: AF_XDP zero copy receive support

In reply to Suman Ghosh

This patch adds support to AF_XDP zero copy support for CN10K. This patch specifically adds receive side support. In this approach once a xdp program with zero copy support on a specific rx queue is enabled, then that receive queue is disabled/detached from the existing kernel queue and re-assigned to the umem memory.

---
 .../ethernet/marvell/octeontx2/nic/Makefile   |   2 +-
 .../ethernet/marvell/octeontx2/nic/cn10k.c    |   6 +-
 .../marvell/octeontx2/nic/otx2_common.c       | 120 +++++++++---
 .../marvell/octeontx2/nic/otx2_common.h       |  11 +-
 .../ethernet/marvell/octeontx2/nic/otx2_pf.c  |  17 +-
 .../marvell/octeontx2/nic/otx2_txrx.c         |  60 +++++-
 .../marvell/octeontx2/nic/otx2_txrx.h         |   6 +
 .../ethernet/marvell/octeontx2/nic/otx2_vf.c  |   4 +
 .../ethernet/marvell/octeontx2/nic/otx2_xsk.c | 182 ++++++++++++++++++
 .../ethernet/marvell/octeontx2/nic/otx2_xsk.h |  21 ++
 .../ethernet/marvell/octeontx2/nic/qos_sq.c   |   2 +-
 11 files changed, 378 insertions(+), 53 deletions(-)
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_xsk.c
 create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/otx2_xsk.h
drivers/net/ethernet/marvell/octeontx2/nic/Makefile +1 -1
index cb6513ab35e7..69e0778f9ac1 100644
@@ -9,7 +9,7 @@ obj-$(CONFIG_RVU_ESWITCH) += rvu_rep.o
 
 rvu_nicpf-y := otx2_pf.o otx2_common.o otx2_txrx.o otx2_ethtool.o \
                otx2_flows.o otx2_tc.o cn10k.o otx2_dmac_flt.o \
-               otx2_devlink.o qos_sq.o qos.o
+               otx2_devlink.o qos_sq.o qos.o otx2_xsk.o
 rvu_nicvf-y := otx2_vf.o
 rvu_rep-y := rep.o
 
drivers/net/ethernet/marvell/octeontx2/nic/cn10k.c +5 -1
index a15cc86635d6..9a2865c60850 100644
@@ -112,9 +112,12 @@ int cn10k_refill_pool_ptrs(void *dev, struct otx2_cq_queue *cq)
 	struct otx2_nic *pfvf = dev;
 	int cnt = cq->pool_ptrs;
 	u64 ptrs[NPA_MAX_BURST];
+	struct otx2_pool *pool;
 	dma_addr_t bufptr;
 	int num_ptrs = 1;
 
+	pool = &pfvf->qset.pool[cq->cq_idx];
+
 	/* Refill pool with new buffers */
 	while (cq->pool_ptrs) {
 		if (otx2_alloc_buffer(pfvf, cq, &bufptr)) {
@@ -124,7 +127,8 @@ int cn10k_refill_pool_ptrs(void *dev, struct otx2_cq_queue *cq)
 			break;
 		}
 		cq->pool_ptrs--;
-		ptrs[num_ptrs] = (u64)bufptr + OTX2_HEAD_ROOM;
+		ptrs[num_ptrs] = pool->xsk_pool ? (u64)bufptr : (u64)bufptr + OTX2_HEAD_ROOM;
+
 		num_ptrs++;
 		if (num_ptrs == NPA_MAX_BURST || cq->pool_ptrs == 0) {
 			__cn10k_aura_freeptr(pfvf, cq->cq_idx, ptrs,
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +89 -31

236 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +10 -1
index 3748941bbaf1..40ee21ae6c72 100644
@@ -532,6 +532,7 @@ struct otx2_nic {
 
 	/* Inline ipsec */
 	struct cn10k_ipsec	ipsec;
+	unsigned long		*af_xdp_zc_qidx;
 };
 
 static inline bool is_otx2_lbkvf(struct pci_dev *pdev)
@@ -1003,7 +1004,7 @@ void otx2_txschq_free_one(struct otx2_nic *pfvf, u16 lvl, u16 schq);
 void otx2_free_pending_sqe(struct otx2_nic *pfvf);
 void otx2_sqb_flush(struct otx2_nic *pfvf);
 int otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool,
-		    dma_addr_t *dma);
+		    dma_addr_t *dma, int qidx, int idx);
 int otx2_rxtx_enable(struct otx2_nic *pfvf, bool enable);
 void otx2_ctx_disable(struct mbox *mbox, int type, bool npa);
 int otx2_nix_config_bp(struct otx2_nic *pfvf, bool enable);
@@ -1033,6 +1034,14 @@ void otx2_pfaf_mbox_destroy(struct otx2_nic *pf);
 void otx2_disable_mbox_intr(struct otx2_nic *pf);
 void otx2_disable_napi(struct otx2_nic *pf);
 irqreturn_t otx2_cq_intr_handler(int irq, void *cq_irq);
+int otx2_init_rsrc(struct pci_dev *pdev, struct otx2_nic *pf);
+int otx2_aura_aq_init(struct otx2_nic *pfvf, int aura_id,
+		      int pool_id, int numptrs);
+int otx2_pool_aq_init(struct otx2_nic *pfvf, u16 pool_id,
+		      int stack_pages, int numptrs, int buf_size, int type);
+int otx2_set_hw_capabilities(struct otx2_nic *pfvf);
+int otx2_rq_init(struct otx2_nic *pfvf, u16 qidx, u16 lpb_aura);
+int otx2_cq_init(struct otx2_nic *pfvf, u16 qidx);
 
 /* RSS configuration APIs*/
 int otx2_rss_init(struct otx2_nic *pfvf);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +8 -9
index e1dde93e8af8..e10c7841fd8b 100644
@@ -27,6 +27,7 @@
 #include "qos.h"
 #include <rvu_trace.h>
 #include "cn10k_ipsec.h"
+#include "otx2_xsk.h"
 
 #define DRV_NAME	"rvu_nicpf"
 #define DRV_STRING	"Marvell RVU NIC Physical Function Driver"
@@ -1662,9 +1663,7 @@ void otx2_free_hw_resources(struct otx2_nic *pf)
 	struct nix_lf_free_req *free_req;
 	struct mbox *mbox = &pf->mbox;
 	struct otx2_cq_queue *cq;
-	struct otx2_pool *pool;
 	struct msg_req *req;
-	int pool_id;
 	int qidx;
 
 	/* Ensure all SQE are processed */
@@ -1705,13 +1704,6 @@ void otx2_free_hw_resources(struct otx2_nic *pf)
 	/* Free RQ buffer pointers*/
 	otx2_free_aura_ptr(pf, AURA_NIX_RQ);
 
-	for (qidx = 0; qidx < pf->hw.rx_queues; qidx++) {
-		pool_id = otx2_get_pool_idx(pf, AURA_NIX_RQ, qidx);
-		pool = &pf->qset.pool[pool_id];
-		page_pool_destroy(pool->page_pool);
-		pool->page_pool = NULL;
-	}
-
 	otx2_free_cq_res(pf);
 
 	/* Free all ingress bandwidth profiles allocated */
@@ -2789,6 +2781,8 @@ static int otx2_xdp(struct net_device *netdev, struct netdev_bpf *xdp)
 	switch (xdp->command) {
 	case XDP_SETUP_PROG:
 		return otx2_xdp_setup(pf, xdp->prog);
+	case XDP_SETUP_XSK_POOL:
+		return otx2_xsk_pool_setup(pf, xdp->xsk.pool, xdp->xsk.queue_id);
 	default:
 		return -EINVAL;
 	}
@@ -2866,6 +2860,7 @@ static const struct net_device_ops otx2_netdev_ops = {
 	.ndo_set_vf_vlan	= otx2_set_vf_vlan,
 	.ndo_get_vf_config	= otx2_get_vf_config,
 	.ndo_bpf		= otx2_xdp,
+	.ndo_xsk_wakeup		= otx2_xsk_wakeup,
 	.ndo_xdp_xmit           = otx2_xdp_xmit,
 	.ndo_setup_tc		= otx2_setup_tc,
 	.ndo_set_vf_trust	= otx2_ndo_set_vf_trust,
@@ -3204,6 +3199,10 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	/* Enable link notifications */
 	otx2_cgx_config_linkevents(pf, true);
 
+	pf->af_xdp_zc_qidx = bitmap_zalloc(qcount, GFP_KERNEL);
+	if (!pf->af_xdp_zc_qidx)
+		goto err_pf_sriov_init;
+
 #ifdef CONFIG_DCB
 	err = otx2_dcbnl_set_ops(netdev);
 	if (err)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +51 -9

137 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h +6 -0
index d23810963fdb..401a4eb04441 100644
@@ -12,6 +12,7 @@
 #include <linux/iommu.h>
 #include <linux/if_vlan.h>
 #include <net/xdp.h>
+#include <net/xdp_sock_drv.h>
 
 #define LBK_CHAN_BASE	0x000
 #define SDP_CHAN_BASE	0x700
@@ -127,7 +128,11 @@ struct otx2_pool {
 	struct qmem		*stack;
 	struct qmem		*fc_addr;
 	struct page_pool	*page_pool;
+	struct xsk_buff_pool	*xsk_pool;
+	struct xdp_buff		**xdp;
+	u16			xdp_cnt;
 	u16			rbsize;
+	u16			xdp_top;
 };
 
 struct otx2_cq_queue {
@@ -144,6 +149,7 @@ struct otx2_cq_queue {
 	void			*cqe_base;
 	struct qmem		*cqe;
 	struct otx2_pool	*rbpool;
+	bool			xsk_zc_en;
 	struct xdp_rxq_info xdp_rxq;
 } ____cacheline_aligned_in_smp;
 
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +4 -0
index e926c6ce96cf..9bb7e5c3e227 100644
@@ -722,6 +722,10 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (err)
 		goto err_shutdown_tc;
 
+	vf->af_xdp_zc_qidx = bitmap_zalloc(qcount, GFP_KERNEL);
+	if (!vf->af_xdp_zc_qidx)
+		goto err_shutdown_tc;
+
 #ifdef CONFIG_DCB
 	err = otx2_dcbnl_set_ops(netdev);
 	if (err)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_xsk.c new file +182 -0

182 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_xsk.h new file +21 -0
new file mode 100644
index 000000000000..022b3433edbb
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Marvell RVU PF/VF Netdev Devlink
+ *
+ * Copyright (C) 2024 Marvell.
+ *
+ */
+
+#ifndef	OTX2_XSK_H
+#define	OTX2_XSK_H
+
+struct otx2_nic;
+struct xsk_buff_pool;
+
+int otx2_xsk_pool_setup(struct otx2_nic *pf, struct xsk_buff_pool *pool, u16 qid);
+int otx2_xsk_pool_enable(struct otx2_nic *pf, struct xsk_buff_pool *pool, u16 qid);
+int otx2_xsk_pool_disable(struct otx2_nic *pf, u16 qid);
+int otx2_xsk_pool_alloc_buf(struct otx2_nic *pfvf, struct otx2_pool *pool,
+			    dma_addr_t *dma, int idx);
+int otx2_xsk_wakeup(struct net_device *dev, u32 queue_id, u32 flags);
+
+#endif /* OTX2_XSK_H */
drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c +1 -1
index 9d887bfc3108..c5dbae0e513b 100644
@@ -82,7 +82,7 @@ static int otx2_qos_sq_aura_pool_init(struct otx2_nic *pfvf, int qidx)
 	}
 
 	for (ptr = 0; ptr < num_sqbs; ptr++) {
-		err = otx2_alloc_rbuf(pfvf, pool, &bufptr);
+		err = otx2_alloc_rbuf(pfvf, pool, &bufptr, pool_id, ptr);
 		if (err)
 			goto sqb_free;
 		pfvf->hw_ops->aura_freeptr(pfvf, pool_id, bufptr);
Signature · 1 line
2.25.1
#5 lore raw

PATCH 3/6 octeontx2-pf: Reconfigure RSS table after enabling AF_XDP zerocopy on rx queue

In reply to Suman Ghosh

RSS table needs to be reconfigured once a rx queue is enabled or disabled for AF_XDP zerocopy support. After enabling UMEM on a rx queue, that queue should not be part of RSS queue selection algorithm. Similarly the queue should be considered again after UMEM is disabled.

---
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c  | 4 ++++
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c | 6 +++++-
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_xsk.c     | 4 ++++
 3 files changed, 13 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +4 -0
index d653e0136cf4..9d7c0f0b0b56 100644
@@ -331,6 +331,10 @@ int otx2_set_rss_table(struct otx2_nic *pfvf, int ctx_id)
 	rss_ctx = rss->rss_ctx[ctx_id];
 	/* Get memory to put this msg */
 	for (idx = 0; idx < rss->rss_size; idx++) {
+		/* Ignore the queue if AF_XDP zero copy is enabled */
+		if (test_bit(rss_ctx->ind_tbl[idx], pfvf->af_xdp_zc_qidx))
+			continue;
+
 		aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
 		if (!aq) {
 			/* The shared memory buffer can be full.
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +5 -1
index 2d53dc77ef1e..010385b29988 100644
@@ -910,8 +910,12 @@ static int otx2_get_rxfh(struct net_device *dev,
 		return -ENOENT;
 
 	if (indir) {
-		for (idx = 0; idx < rss->rss_size; idx++)
+		for (idx = 0; idx < rss->rss_size; idx++) {
+			/* Ignore if the rx queue is AF_XDP zero copy enabled */
+			if (test_bit(rss_ctx->ind_tbl[idx], pfvf->af_xdp_zc_qidx))
+				continue;
 			indir[idx] = rss_ctx->ind_tbl[idx];
+		}
 	}
 	if (rxfh->key)
 		memcpy(rxfh->key, rss->key, sizeof(rss->key));
drivers/net/ethernet/marvell/octeontx2/nic/otx2_xsk.c +4 -0
index 69098c6a6fed..f6bbe18016ba 100644
@@ -130,6 +130,8 @@ int otx2_xsk_pool_enable(struct otx2_nic *pf, struct xsk_buff_pool *pool, u16 qi
 
 	set_bit(qidx, pf->af_xdp_zc_qidx);
 	otx2_clean_up_rq(pf, qidx);
+	/* Reconfigure RSS table as 'qidx' cannot be part of RSS now */
+	otx2_set_rss_table(pf, DEFAULT_RSS_CONTEXT_GROUP);
 	/* Kick start the NAPI context so that receiving will start */
 	return otx2_xsk_wakeup(pf->netdev, qidx, XDP_WAKEUP_RX);
 }
@@ -146,6 +148,8 @@ int otx2_xsk_pool_disable(struct otx2_nic *pf, u16 qidx)
 	otx2_clean_up_rq(pf, qidx);
 	clear_bit(qidx, pf->af_xdp_zc_qidx);
 	xsk_pool_dma_unmap(pool, DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING);
+	/* Reconfigure RSS table as 'qidx' now need to be part of RSS now */
+	otx2_set_rss_table(pf, DEFAULT_RSS_CONTEXT_GROUP);
 
 	return 0;
 }
Signature · 1 line
2.25.1
#6 lore raw

PATCH 4/6 octeontx2-pf: Don't unmap page pool buffer used by XDP

In reply to Suman Ghosh

From: Geetha sowjanya <[email protected]>

When xdp buffers are from page pool do not dma unmap the buffers. DMA map/unmap are handled by the page_pool APIs.

---
 .../marvell/octeontx2/nic/otx2_common.h       |  3 +-
 .../ethernet/marvell/octeontx2/nic/otx2_pf.c  |  8 +++--
 .../marvell/octeontx2/nic/otx2_txrx.c         | 32 ++++++++++++-------
 .../marvell/octeontx2/nic/otx2_txrx.h         |  1 +
 4 files changed, 30 insertions(+), 14 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +2 -1
index 40ee21ae6c72..dc68d2aa0a0e 100644
@@ -1104,7 +1104,8 @@ int otx2_del_macfilter(struct net_device *netdev, const u8 *mac);
 int otx2_add_macfilter(struct net_device *netdev, const u8 *mac);
 int otx2_enable_rxvlan(struct otx2_nic *pf, bool enable);
 int otx2_install_rxvlan_offload_flow(struct otx2_nic *pfvf);
-bool otx2_xdp_sq_append_pkt(struct otx2_nic *pfvf, u64 iova, int len, u16 qidx);
+bool otx2_xdp_sq_append_pkt(struct otx2_nic *pfvf, u64 iova, int len,
+			    u16 qidx, u16 flags);
 u16 otx2_get_max_mtu(struct otx2_nic *pfvf);
 int otx2_handle_ntuple_tc_features(struct net_device *netdev,
 				   netdev_features_t features);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +6 -2
index e10c7841fd8b..c6205cf2eb03 100644
@@ -2693,11 +2693,15 @@ static int otx2_xdp_xmit_tx(struct otx2_nic *pf, struct xdp_frame *xdpf,
 	if (dma_mapping_error(pf->dev, dma_addr))
 		return -ENOMEM;
 
-	err = otx2_xdp_sq_append_pkt(pf, dma_addr, xdpf->len, qidx);
+	err = otx2_xdp_sq_append_pkt(pf, dma_addr, xdpf->len,
+				     qidx, XDP_REDIRECT);
 	if (!err) {
 		otx2_dma_unmap_page(pf, dma_addr, xdpf->len, DMA_TO_DEVICE);
 		page = virt_to_page(xdpf->data);
-		put_page(page);
+		if (page->pp)
+			page_pool_recycle_direct(page->pp, page);
+		else
+			put_page(page);
 		return -ENOMEM;
 	}
 	return 0;
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +21 -11
index 741b4ce6d0ff..c8b11d45debf 100644
@@ -102,19 +102,20 @@ static void otx2_xdp_snd_pkt_handler(struct otx2_nic *pfvf,
 	struct nix_send_comp_s *snd_comp = &cqe->comp;
 	struct sg_list *sg;
 	struct page *page;
-	u64 pa;
+	u64 pa, iova;
 
 	sg = &sq->sg[snd_comp->sqe_id];
 
-	pa = otx2_iova_to_phys(pfvf->iommu_domain, sg->dma_addr[0]);
-	otx2_dma_unmap_page(pfvf, sg->dma_addr[0],
-			    sg->size[0], DMA_TO_DEVICE);
+	iova = sg->dma_addr[0] - OTX2_HEAD_ROOM;
+	pa = otx2_iova_to_phys(pfvf->iommu_domain, iova);
 	page = virt_to_page(phys_to_virt(pa));
+	if (sg->flags & XDP_REDIRECT)
+		otx2_dma_unmap_page(pfvf, sg->dma_addr[0], sg->size[0], DMA_TO_DEVICE);
+
 	if (page->pp) {
 		page_pool_recycle_direct(page->pp, page);
 		return;
 	}
-
 	put_page(page);
 }
 
@@ -1379,7 +1380,7 @@ void otx2_free_pending_sqe(struct otx2_nic *pfvf)
 }
 
 static void otx2_xdp_sqe_add_sg(struct otx2_snd_queue *sq, u64 dma_addr,
-				int len, int *offset)
+				int len, int *offset, u16 flags)
 {
 	struct nix_sqe_sg_s *sg = NULL;
 	u64 *iova = NULL;
@@ -1396,9 +1397,11 @@ static void otx2_xdp_sqe_add_sg(struct otx2_snd_queue *sq, u64 dma_addr,
 	sq->sg[sq->head].dma_addr[0] = dma_addr;
 	sq->sg[sq->head].size[0] = len;
 	sq->sg[sq->head].num_segs = 1;
+	sq->sg[sq->head].flags = flags;
 }
 
-bool otx2_xdp_sq_append_pkt(struct otx2_nic *pfvf, u64 iova, int len, u16 qidx)
+bool otx2_xdp_sq_append_pkt(struct otx2_nic *pfvf, u64 iova, int len,
+			    u16 qidx, u16 flags)
 {
 	struct nix_sqe_hdr_s *sqe_hdr;
 	struct otx2_snd_queue *sq;
@@ -1424,7 +1427,7 @@ bool otx2_xdp_sq_append_pkt(struct otx2_nic *pfvf, u64 iova, int len, u16 qidx)
 
 	offset = sizeof(*sqe_hdr);
 
-	otx2_xdp_sqe_add_sg(sq, iova, len, &offset);
+	otx2_xdp_sqe_add_sg(sq, iova, len, &offset, flags);
 	sqe_hdr->sizem1 = (offset / 16) - 1;
 	pfvf->hw_ops->sqe_flush(pfvf, sq, offset, qidx);
 
@@ -1477,8 +1480,8 @@ static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
 	case XDP_TX:
 		qidx += pfvf->hw.tx_queues;
 		cq->pool_ptrs++;
-		return otx2_xdp_sq_append_pkt(pfvf, iova,
-					      cqe->sg.seg_size, qidx);
+		return otx2_xdp_sq_append_pkt(pfvf, cqe->sg.seg_addr,
+					      cqe->sg.seg_size, qidx, XDP_TX);
 	case XDP_REDIRECT:
 		cq->pool_ptrs++;
 		if (xsk_buff) {
@@ -1497,7 +1500,14 @@ static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
 			*need_xdp_flush = true;
 			return true;
 		}
-		page_pool_recycle_direct(pool->page_pool, page);
+		if (page->pp) {
+			page_pool_recycle_direct(pool->page_pool, page);
+			return false;
+		}
+
+		otx2_dma_unmap_page(pfvf, iova, pfvf->rbsize,
+				    DMA_FROM_DEVICE);
+		put_page(page);
 		break;
 	default:
 		bpf_warn_invalid_xdp_action(pfvf->netdev, prog, act);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h +1 -0
index 401a4eb04441..8f346fbc8221 100644
@@ -77,6 +77,7 @@ struct otx2_rcv_queue {
 
 struct sg_list {
 	u16	num_segs;
+	u16	flags;
 	u64	skb;
 	u64	size[OTX2_MAX_FRAGS_IN_SQE];
 	u64	dma_addr[OTX2_MAX_FRAGS_IN_SQE];
Signature · 1 line
2.25.1
#7 lore raw

PATCH 5/6 octeontx2-pf: Prepare for AF_XDP transmit

In reply to Suman Ghosh

From: Hariprasad Kelam <[email protected]>

Implement necessary APIs required for AF_XDP transmit.

---
 .../marvell/octeontx2/nic/otx2_common.h       |  1 +
 .../marvell/octeontx2/nic/otx2_txrx.c         | 25 +++++++++++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +1 -0
index dc68d2aa0a0e..24faf9dc41e6 100644
@@ -1186,4 +1186,5 @@ static inline int mcam_entry_cmp(const void *a, const void *b)
 dma_addr_t otx2_dma_map_skb_frag(struct otx2_nic *pfvf,
 				 struct sk_buff *skb, int seg, int *len);
 void otx2_dma_unmap_skb_frags(struct otx2_nic *pfvf, struct sg_list *sg);
+int otx2_read_free_sqe(struct otx2_nic *pfvf, u16 qidx);
 #endif /* OTX2_COMMON_H */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +23 -2
index c8b11d45debf..80769c8ffb9a 100644
@@ -22,6 +22,12 @@
 #include "cn10k.h"
 
 #define CQE_ADDR(CQ, idx) ((CQ)->cqe_base + ((CQ)->cqe_size * (idx)))
+#define READ_FREE_SQE(SQ, free_sqe)						   \
+	do {							                   \
+		typeof(SQ) _SQ = (SQ);						   \
+		free_sqe = (((_SQ)->cons_head - (_SQ)->head - 1 + (_SQ)->sqe_cnt)  \
+			   & ((_SQ)->sqe_cnt - 1));                                \
+	} while (0)
 #define PTP_PORT	        0x13F
 /* PTPv2 header Original Timestamp starts at byte offset 34 and
  * contains 6 byte seconds field and 4 byte nano seconds field.
@@ -1163,7 +1169,7 @@ bool otx2_sq_append_skb(void *dev, struct netdev_queue *txq,
 	/* Check if there is enough room between producer
 	 * and consumer index.
 	 */
-	free_desc = (sq->cons_head - sq->head - 1 + sq->sqe_cnt) & (sq->sqe_cnt - 1);
+	READ_FREE_SQE(sq, free_desc);
 	if (free_desc < sq->sqe_thresh)
 		return false;
 
@@ -1400,6 +1406,21 @@ static void otx2_xdp_sqe_add_sg(struct otx2_snd_queue *sq, u64 dma_addr,
 	sq->sg[sq->head].flags = flags;
 }
 
+int otx2_read_free_sqe(struct otx2_nic *pfvf, u16 qidx)
+{
+	struct otx2_snd_queue *sq;
+	int free_sqe;
+
+	sq = &pfvf->qset.sq[qidx];
+	READ_FREE_SQE(sq, free_sqe);
+	if (free_sqe < sq->sqe_thresh) {
+		netdev_warn(pfvf->netdev, "No free sqe for Send queue%d\n", qidx);
+		return 0;
+	}
+
+	return free_sqe - sq->sqe_thresh;
+}
+
 bool otx2_xdp_sq_append_pkt(struct otx2_nic *pfvf, u64 iova, int len,
 			    u16 qidx, u16 flags)
 {
@@ -1408,7 +1429,7 @@ bool otx2_xdp_sq_append_pkt(struct otx2_nic *pfvf, u64 iova, int len,
 	int offset, free_sqe;
 
 	sq = &pfvf->qset.sq[qidx];
-	free_sqe = (sq->num_sqbs - *sq->aura_fc_addr) * sq->sqe_per_sqb;
+	READ_FREE_SQE(sq, free_sqe);
 	if (free_sqe < sq->sqe_thresh)
 		return false;
 
Signature · 1 line
2.25.1
#8 lore raw

PATCH 6/6 octeontx2-pf: AF_XDP zero copy transmit support

In reply to Suman Ghosh

From: Hariprasad Kelam <[email protected]>

This patch implements below changes,

1. To avoid concurrency with normal traffic uses
XDP queues.

2. Since there are chances that XDP and AF_XDP can fall under same queue uses separate flags to handle dma buffers.

---
 .../marvell/octeontx2/nic/otx2_common.c       |  4 ++
 .../marvell/octeontx2/nic/otx2_common.h       |  6 +++
 .../ethernet/marvell/octeontx2/nic/otx2_pf.c  |  2 +-
 .../marvell/octeontx2/nic/otx2_txrx.c         | 45 +++++++++++++++----
 .../marvell/octeontx2/nic/otx2_txrx.h         |  1 +
 .../ethernet/marvell/octeontx2/nic/otx2_xsk.c | 43 +++++++++++++++++-
 .../ethernet/marvell/octeontx2/nic/otx2_xsk.h |  3 ++
 7 files changed, 92 insertions(+), 12 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +4 -0
index 9d7c0f0b0b56..c1fdb8b943cd 100644
@@ -1037,6 +1037,10 @@ int otx2_sq_init(struct otx2_nic *pfvf, u16 qidx, u16 sqb_aura)
 
 	sq->stats.bytes = 0;
 	sq->stats.pkts = 0;
+	/* Attach XSK_BUFF_POOL to XDP queue */
+	if (qidx > pfvf->hw.xdp_queues)
+		otx2_attach_xsk_buff(pfvf, sq, (qidx - pfvf->hw.xdp_queues));
+
 
 	chan_offset = qidx % pfvf->hw.tx_chan_cnt;
 	err = pfvf->hw_ops->sq_aq_init(pfvf, qidx, chan_offset, sqb_aura);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +6 -0
index 24faf9dc41e6..69a8c6132cd3 100644
@@ -129,6 +129,12 @@ enum otx2_errcodes_re {
 	ERRCODE_IL4_CSUM = 0x22,
 };
 
+enum otx2_xdp_action {
+	OTX2_XDP_TX	  = BIT(0),
+	OTX2_XDP_REDIRECT = BIT(1),
+	OTX2_AF_XDP_FRAME = BIT(2),
+};
+
 struct otx2_dev_stats {
 	u64 rx_bytes;
 	u64 rx_frames;
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +1 -1
index c6205cf2eb03..15bbd7e39eb0 100644
@@ -2694,7 +2694,7 @@ static int otx2_xdp_xmit_tx(struct otx2_nic *pf, struct xdp_frame *xdpf,
 		return -ENOMEM;
 
 	err = otx2_xdp_sq_append_pkt(pf, dma_addr, xdpf->len,
-				     qidx, XDP_REDIRECT);
+				     qidx, OTX2_XDP_REDIRECT);
 	if (!err) {
 		otx2_dma_unmap_page(pf, dma_addr, xdpf->len, DMA_TO_DEVICE);
 		page = virt_to_page(xdpf->data);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +36 -9

104 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h +1 -0
index 8f346fbc8221..2fd8b768e8c7 100644
@@ -106,6 +106,7 @@ struct otx2_snd_queue {
 	/* SQE ring and CPT response queue for Inline IPSEC */
 	struct qmem		*sqe_ring;
 	struct qmem		*cpt_resp;
+	struct xsk_buff_pool    *xsk_pool;
 } ____cacheline_aligned_in_smp;
 
 enum cq_type {
drivers/net/ethernet/marvell/octeontx2/nic/otx2_xsk.c +41 -2

67 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_xsk.h +3 -0
index 022b3433edbb..8047fafee8fe 100644
@@ -17,5 +17,8 @@ int otx2_xsk_pool_disable(struct otx2_nic *pf, u16 qid);
 int otx2_xsk_pool_alloc_buf(struct otx2_nic *pfvf, struct otx2_pool *pool,
 			    dma_addr_t *dma, int idx);
 int otx2_xsk_wakeup(struct net_device *dev, u32 queue_id, u32 flags);
+void otx2_zc_napi_handler(struct otx2_nic *pfvf, struct xsk_buff_pool *pool,
+			  int queue, int budget);
+void otx2_attach_xsk_buff(struct otx2_nic *pfvf, struct otx2_snd_queue *sq, int qidx);
 
 #endif /* OTX2_XSK_H */
Signature · 1 line
2.25.1
reviewer
#3 lore raw

Re: [net-next PATCH 2/6] octeontx2-pf: AF_XDP zero copy receive support

In reply to Suman Ghosh
Quoted 7 lines · Suman Ghosh

This patch adds support to AF_XDP zero copy support for CN10K. This patch specifically adds receive side support. In this approach once a xdp program with zero copy support on a specific rx queue is enabled, then that receive queue is disabled/detached from the existing kernel queue and re-assigned to the umem memory.

Hi Suman,

I'd like to bring to your attention a number of minor issues flagged by Smatch.

...

Quoted 1 line
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +0 -0

...

Quoted 19 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +2 -1
@@ -1298,6 +1311,7 @@ void otx2_free_aura_ptr(struct otx2_nic *pfvf, int type)
 	int pool_id, pool_start = 0, pool_end = 0, size = 0;
 	struct otx2_pool *pool;
 	u64 iova;
+	int idx;
 
 	if (type == AURA_NIX_SQ) {
 		pool_start = otx2_get_pool_idx(pfvf, type, 0);
@@ -1312,8 +1326,8 @@ void otx2_free_aura_ptr(struct otx2_nic *pfvf, int type)
 
 	/* Free SQB and RQB pointers from the aura pool */
 	for (pool_id = pool_start; pool_id < pool_end; pool_id++) {
-		iova = otx2_aura_allocptr(pfvf, pool_id);
 		pool = &pfvf->qset.pool[pool_id];
+		iova = otx2_aura_allocptr(pfvf, pool_id);
 		while (iova) {
 			if (type == AURA_NIX_RQ)
 				iova -= OTX2_HEAD_ROOM;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c void otx2_free_aura_ptr(struct otx2_nic *pfvf, int type) · line 1346

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +7 -0
@@ -1323,6 +1337,13 @@ void otx2_free_aura_ptr(struct otx2_nic *pfvf, int type)
 			iova = otx2_aura_allocptr(pfvf, pool_id);
 		}
 	}
+
+	for (idx = 0 ; idx < pool->xdp_cnt; idx++) {
+		if (!pool->xdp[idx])
+			continue;
+
+		xsk_buff_free(pool->xdp[idx]);
+	}

Looking over otx2_pool_init(), I am wondering if the loop above run should over all (non AURA_NIX_RQ) pools, rather than the last pool covered by the preceding loop.

This was flagged by Smatch, because it is concerned that pool may be used unset above, presumably if the preceding loop iterates zero times (I'm unsure if that can happen in practice).

...

Quoted 1 line
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +0 -0

...

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 3205

Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +4 -0
@@ -3204,6 +3199,10 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	/* Enable link notifications */
 	otx2_cgx_config_linkevents(pf, true);
 
+	pf->af_xdp_zc_qidx = bitmap_zalloc(qcount, GFP_KERNEL);
+	if (!pf->af_xdp_zc_qidx)
+		goto err_pf_sriov_init;
+

This goto will result in the function returning err.
However, here err is 0. Should it be set to a negative error value instead?

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +0 -0
 #ifdef CONFIG_DCB
 	err = otx2_dcbnl_set_ops(netdev);
 	if (err)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +0 -0

...

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

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +1 -0
@@ -571,6 +574,7 @@ int otx2_napi_handler(struct napi_struct *napi, int budget)
 		if (pfvf->flags & OTX2_FLAG_ADPTV_INT_COAL_ENABLED)
 			otx2_adjust_adaptive_coalese(pfvf, cq_poll);
 
+		pool = &pfvf->qset.pool[cq->cq_idx];

I am also unsure if this can happen in practice, but Smatch is concerned that cq may be used uninitialised here. It does seem that could theoretically be the case if, in the for loop towards the top of this function, cq_poll->cq_ids[i] is always CINT_INVALID_CQ.

Quoted 3 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +0 -0
 		if (unlikely(!filled_cnt)) {
 			struct refill_work *work;
 			struct delayed_work *dwork;

...

Quoted 11 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +1 -1
@@ -1426,13 +1440,24 @@ static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
 	unsigned char *hard_start;
 	struct otx2_pool *pool;
 	int qidx = cq->cq_idx;
-	struct xdp_buff xdp;
+	struct xdp_buff xdp, *xsk_buff = NULL;
 	struct page *page;
 	u64 iova, pa;
 	u32 act;
 	int err;
 

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf, · line 1458

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +9 -0
 	pool = &pfvf->qset.pool[qidx];
+
+	if (pool->xsk_pool) {
+		xsk_buff = pool->xdp[--cq->rbpool->xdp_top];
+		if (!xsk_buff)
+			return false;
+
+		xsk_buff->data_end = xsk_buff->data + cqe->sg.seg_size;
+		act = bpf_prog_run_xdp(prog, xsk_buff);
+		goto handle_xdp_verdict;

iova is not initialised until a few lines further down, which does not occur in the case of this condition.

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf, · line 1476

Quoted 13 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +3 -0
+	}
+
 	iova = cqe->sg.seg_addr - OTX2_HEAD_ROOM;
 	pa = otx2_iova_to_phys(pfvf->iommu_domain, iova);
 	page = virt_to_page(phys_to_virt(pa));
@@ -1445,6 +1470,7 @@ static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
 
 	act = bpf_prog_run_xdp(prog, &xdp);
 
+handle_xdp_verdict:
 	switch (act) {
 	case XDP_PASS:
 		break;

The lines lines of this function, between the hunk above and the one below looks like this:

	case XDP_TX:
		qidx += pfvf->hw.tx_queues;
		cq->pool_ptrs++;
		return otx2_xdp_sq_append_pkt(pfvf, iova,

The above uses iova, but in the case that we got here via goto handle_xdp_verdict it is uninitialised.

...

drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 727

Quoted 11 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +3 -0
index e926c6ce96cf..9bb7e5c3e227 100644
@@ -722,6 +722,10 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (err)
 		goto err_shutdown_tc;
 
+	vf->af_xdp_zc_qidx = bitmap_zalloc(qcount, GFP_KERNEL);
+	if (!vf->af_xdp_zc_qidx)
+		goto err_shutdown_tc;

Along the same lines of my comment on otx2_probe():
should err be set to a negative error value here?

...

Signature · 1 line
pw-bot: changes-requested
#4 lore raw

RE: [EXTERNAL] Re: [net-next PATCH 2/6] octeontx2-pf: AF_XDP zero copy receive support

Hi Simon,

Quoted 12 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c void otx2_free_aura_ptr(struct otx2_nic *pfvf,

Quoted 11 lines

@@ void otx2_free_aura_ptr(struct otx2_nic *pfvf, int type)

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +1 -1
 	/* Free SQB and RQB pointers from the aura pool */
 	for (pool_id = pool_start; pool_id < pool_end; pool_id++) {
-		iova = otx2_aura_allocptr(pfvf, pool_id);
 		pool = &pfvf->qset.pool[pool_id];
+		iova = otx2_aura_allocptr(pfvf, pool_id);
 		while (iova) {
 			if (type == AURA_NIX_RQ)
 				iova -= OTX2_HEAD_ROOM;
@@ -1323,6 +1337,13 @@ void otx2_free_aura_ptr(struct otx2_nic *pfvf,

int type)

Quoted 14 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c void otx2_free_aura_ptr(struct otx2_nic *pfvf, int type) · line 1346

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +7 -0
 			iova = otx2_aura_allocptr(pfvf, pool_id);
 		}
 	}
+
+	for (idx = 0 ; idx < pool->xdp_cnt; idx++) {
+		if (!pool->xdp[idx])
+			continue;
+
+		xsk_buff_free(pool->xdp[idx]);
+	}

Looking over otx2_pool_init(), I am wondering if the loop above run should over all (non AURA_NIX_RQ) pools, rather than the last pool covered by the preceding loop.

[Suman] Yes, you are right. Thanks for catching this, will update in v2.

Quoted 4 lines

This was flagged by Smatch, because it is concerned that pool may be used unset above, presumably if the preceding loop iterates zero times (I'm unsure if that can happen in practice).

[Suman] Will update the logic in v2.

Quoted 13 lines

...

Quoted 2 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +0 -0

...

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c static int otx2_probe(struct pci_dev *pdev,

Quoted 1 line
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +0 -0
@@ -3204,6 +3199,10 @@ static int otx2_probe(struct pci_dev *pdev,

const struct pci_device_id *id)

Quoted 3 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +0 -0
 	/* Enable link notifications */
 	otx2_cgx_config_linkevents(pf, true);
 
Quoted 8 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 3205

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +4 -0
+	pf->af_xdp_zc_qidx = bitmap_zalloc(qcount, GFP_KERNEL);
+	if (!pf->af_xdp_zc_qidx)
+		goto err_pf_sriov_init;
+

This goto will result in the function returning err. However, here err is 0. Should it be set to a negative error value instead?

[Suman] Yes, will update in v2

Quoted 39 lines
Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +0 -0
 #ifdef CONFIG_DCB
 	err = otx2_dcbnl_set_ops(netdev);
 	if (err)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +0 -0

...

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c int otx2_napi_handler(struct napi_struct *napi,

Quoted 1 line
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +0 -0
@@ -571,6 +574,7 @@ int otx2_napi_handler(struct napi_struct *napi,

int budget)

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

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +1 -0
 		if (pfvf->flags & OTX2_FLAG_ADPTV_INT_COAL_ENABLED)
 			otx2_adjust_adaptive_coalese(pfvf, cq_poll);
 
+		pool = &pfvf->qset.pool[cq->cq_idx];

I am also unsure if this can happen in practice, but Smatch is concerned that cq may be used uninitialised here. It does seem that could theoretically be the case if, in the for loop towards the top of this function, cq_poll->cq_ids[i] is always CINT_INVALID_CQ.

Quoted 3 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +0 -0
 		if (unlikely(!filled_cnt)) {
 			struct refill_work *work;
 			struct delayed_work *dwork;

...

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c static bool otx2_xdp_rcv_pkt_handler(struct

Quoted 1 line
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +0 -0
@@ -1426,13 +1440,24 @@ static bool otx2_xdp_rcv_pkt_handler(struct

otx2_nic *pfvf,

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +1 -1
 	unsigned char *hard_start;
 	struct otx2_pool *pool;
 	int qidx = cq->cq_idx;
-	struct xdp_buff xdp;
+	struct xdp_buff xdp, *xsk_buff = NULL;
 	struct page *page;
 	u64 iova, pa;
 	u32 act;
 	int err;
 
Quoted 13 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf, · line 1458

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +9 -0
 	pool = &pfvf->qset.pool[qidx];
+
+	if (pool->xsk_pool) {
+		xsk_buff = pool->xdp[--cq->rbpool->xdp_top];
+		if (!xsk_buff)
+			return false;
+
+		xsk_buff->data_end = xsk_buff->data + cqe->sg.seg_size;
+		act = bpf_prog_run_xdp(prog, xsk_buff);
+		goto handle_xdp_verdict;

iova is not initialised until a few lines further down, which does not occur in the case of this condition.

[Suman] I think the patch ordering is wrong.
"patch#4: octeontx2-pf: Don't unmap page pool buffer used by XDP" is fixing this. I will update the patch order.

Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +2 -0
+	}
+
 	iova = cqe->sg.seg_addr - OTX2_HEAD_ROOM;
 	pa = otx2_iova_to_phys(pfvf->iommu_domain, iova);
 	page = virt_to_page(phys_to_virt(pa)); @@ -1445,6 +1470,7 @@ static

bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,

act = bpf_prog_run_xdp(prog, &xdp);

Quoted 7 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf, · line 1476

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +1 -0
+handle_xdp_verdict:
 	switch (act) {
 	case XDP_PASS:
 		break;

The lines lines of this function, between the hunk above and the one below looks like this:

[Suman] replied above.

Quoted 8 lines
	case XDP_TX:
		qidx += pfvf->hw.tx_queues;
		cq->pool_ptrs++;
		return otx2_xdp_sq_append_pkt(pfvf, iova,

The above uses iova, but in the case that we got here via goto handle_xdp_verdict it is uninitialised.

[Suman] same as above.

Quoted 13 lines

...

drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c static int otx2vf_probe(struct pci_dev *pdev,

Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +0 -0
index e926c6ce96cf..9bb7e5c3e227 100644
@@ -722,6 +722,10 @@ static int otx2vf_probe(struct pci_dev *pdev,

const struct pci_device_id *id)

Quoted 3 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +0 -0
 	if (err)
 		goto err_shutdown_tc;
 
Quoted 6 lines

drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 727

Quoted 3 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +3 -0
+	vf->af_xdp_zc_qidx = bitmap_zalloc(qcount, GFP_KERNEL);
+	if (!vf->af_xdp_zc_qidx)
+		goto err_shutdown_tc;

Along the same lines of my comment on otx2_probe():
should err be set to a negative error value here?

[Suman] yes, will update in v2

Quoted 5 lines

...

--
pw-bot: changes-requested