idpf: add flow-based XDP fallback for FWs without Tx FIFO support
Subsystems (6)
Alexander Lobakin
maintainerv4 cover idpf: add flow-based XDP fallback for FWs without Tx FIFO support
From the first days of XDP implementation in idpf, it relied and worked solely on top of the queue-based scheduling Tx mode, which basically means simple FIFO. However, turned out not every firmware supports this mode and XDP doesn't work there at all.
Start with some good Sashiko findings. One empty XDPSQE which idpf requires is always reserved only in XSk xmit code, but not in the rest of cases. XDPCQE parsing can end up with partial reads on BE systems. XDPSQ configuration code can pass out-of-bounds values to cpu_to_mem() in rare cases (nr_cpu_ids < num_xdpsq).
Then, introduce the flow-based fallback for all XDP paths which is always supported by any FW. The actual implementation is selected during XDP program setup basing on the caps that the FW advertises, so that firmwares that already work correctly won't get performance regressions the fallback brings.
Alexander Lobakin (4):
idpf: always reserve one empty descriptor on XDPSQs
idpf: enforce strict ordering on BE when reading XDPCQEs
idpf: fix possible out-of-bound cpu_to_mem() when configuring XDPSQs
idpf: add flow-based XDP fallback for FWs without Tx FIFO support
drivers/net/ethernet/intel/idpf/idpf_txrx.h | 18 ++- drivers/net/ethernet/intel/idpf/xdp.h | 60 ++++++++ include/net/libeth/xdp.h | 13 ++ drivers/net/ethernet/intel/idpf/idpf_txrx.c | 19 ++- drivers/net/ethernet/intel/idpf/xdp.c | 155 ++++++++++++++++++-- drivers/net/ethernet/intel/idpf/xsk.c | 2 +- 6 files changed, 244 insertions(+), 23 deletions(-)
---
From v3[0]:
* new fix (0002): fix out-of-bound cpu_to_mem() when nr_cpu_ids is lower than the number of XDPSQs (Sashiko).
From v2[1]:
* new fix (0001): fix already existing issue with not reserving a required free Tx descriptor in case of XDP Tx, xmit, and XSk Tx (Sashiko);
* new fix (0002): enforce strict ordering when parsing XDPCQEs on Big Endian (Intel's Sashiko);
* rewrite the bitmap set-reset implementation from scratch to fix fix S/G: HW generates a completion per packet, not per descriptor (Sashiko);
* fix excessive allocations, possible pointer overwrites, and corner case static key imbalance when setting up XDPSQs (Intel's Sashiko).
From v1[2]:
* rework static key management: move to idpf_xdpsqs_{get,put}() to avoid refcount imbalance issues as .ndo_bpf() is not always called in pairs (hardware reset etc.) (Sashiko, Intel's Sashiko);
* don't zero the whole pending window but only the frames sent since the last batch to avoid missed OOO completions (Intel's Sashiko);
* micro-optimize idpf_xdpsq_set_rs{,_fb}().
Sorry I've had health issues for the last year. I hope I'll be restoring my usual "usefulness" (reviews, submissions) on the LKML bit by bit.
[0] https://lore.kernel.org/intel-wired-lan/[email protected]
[1] https://lore.kernel.org/intel-wired-lan/[email protected]
[2] https://lore.kernel.org/intel-wired-lan/[email protected]
Signature · 1 line
2.56.1
Alexander Lobakin
maintainerPATCH v4 1/4 idpf: always reserve one empty descriptor on XDPSQs
idpf-powered HW requires at least one Tx descriptor to be always free, so that head and tail are never equal, otherwise the HW will deadlock. This is already taken into account in the XSk xmit code, however, not in regular XDP Tx, xmit, and XSk Tx -- these are much slower and are in fact almost unable to trigger that.
Either way, be better safe than sorry and always reserve one empty Tx descriptor by passing free - 1 (this can't underflow since free is always at least 1 due to this reservation).
Found by Sashiko.
--- drivers/net/ethernet/intel/idpf/xdp.c | 2 +- drivers/net/ethernet/intel/idpf/xsk.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/idpf/xdp.c +1 -1
@@ -351,7 +351,7 @@ static u32 idpf_xdp_tx_prep(void *_xdpsq, struct libeth_xdpsq *sq) .xdp_tx = &xdpsq->xdp_tx, }; -return free; +return free -1 ; }LIBETH_XDP_DEFINE_START ();
drivers/net/ethernet/intel/idpf/xsk.c +1 -1
@@ -294,7 +294,7 @@ static u32 idpf_xsk_tx_prep(void *_xdpsq, struct libeth_xdpsq *sq) .xdp_tx = &xdpsq->xdp_tx, }; -return free; +return free -1 ; }static u32 idpf_xsk_xmit_prep (void *_xdpsq,struct libeth_xdpsq *sq)
Signature · 1 line
2.56.1
Alexander Lobakin
maintainerPATCH v4 2/4 idpf: enforce strict ordering on BE when reading XDPCQEs
In reply to Alexander LobakinOn Little Endian platforms, everything we need from the completion descriptor is read at once, while on Big Endian we read it field-by-field. Depending on the compiler and optimization settings, reads can be combined or stay distinct. The latter leaves us with no barrier and with possible stale completion index or tag.
Change the logic a bit and read only the "readiness" field first on Big Endian, then perform strictly-ordered read of the cookie after making sure it is valid.
The Little Endian code remains intact. Found by Sashiko.
--- drivers/net/ethernet/intel/idpf/xdp.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/idpf/xdp.c +7 -2
@@ -236,8 +236,7 @@ static int idpf_xdp_parse_cqe(const struct idpf_splitq_4b_tx_compl_desc *desc,#ifdef __LIBETH_WORD_ACCESS val = *(const u32 *)desc;#else - val = ((u32 )le16_to_cpu (desc->q_head_compl_tag.q_head) <<16 ) | -le16_to_cpu (desc->qid_comptype_gen); + val =le16_to_cpu (desc->qid_comptype_gen);#endif if (!!(val &IDPF_TXD_COMPLQ_GEN_M ) != gen)return -ENODATA ;
@@ -247,7 +246,13 @@ static int idpf_xdp_parse_cqe(const struct idpf_splitq_4b_tx_compl_desc *desc, IDPF_TXD_COMPLT_RS)))return -EINVAL ; +#ifdef __LIBETH_WORD_ACCESSreturn upper_16_bits (val); +#else +dma_rmb (); + +return le16_to_cpu (desc->q_head_compl_tag.q_head); +#endif }u32 idpf_xdpsq_poll (struct idpf_tx_queue *xdpsq,u32 budget)
Signature · 1 line
2.56.1
Alexander Lobakin
maintainerPATCH v4 3/4 idpf: fix possible out-of-bound cpu_to_mem() when configuring XDPSQs
In reply to Alexander LobakinThe number of XDPSQs is calculated by libeth as either nr_cpu_ids or the number of RQs if the latter is bigger. In this case, although it's pretty hard to achieve on idpf, passing XDPSQ index to cpu_to_mem() directly would trigger out-of-bound read of percpu data.
Wrap the index by nr_cpu_ids just in case when picking the closest node with memory to allocate cleanup timers.
Found by Sashiko.
--- drivers/net/ethernet/intel/idpf/xdp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/idpf/xdp.c +1 -1
@@ -164,7 +164,7 @@ int idpf_xdpsqs_get(const struct idpf_vport *vport)for (u32 i =0 ; i < vport->num_xdp_txq; i++) { timers[i] =kzalloc_node (sizeof (*timers[i]),GFP_KERNEL , -cpu_to_mem (i)); +cpu_to_mem (i % nr_cpu_ids));if (!timers[i]) {for (int j = i -1 ; j >=0 ; j--)kfree (timers[j]);
Signature · 1 line
2.56.1
Alexander Lobakin
maintainerPATCH v4 4/4 idpf: add flow-based XDP fallback for FWs without Tx FIFO support
In reply to Alexander LobakinFrom the first days of XDP implementation in idpf, it relied and worked solely on top of the queue-based scheduling Tx mode, which basically means simple FIFO. However, turned out not every firmware supports this mode and XDP doesn't work there at all.
Since the flow-based scheduling Tx mode is mandatory and supported by every FW, introduce a simple fallback guarded by a static key to not hurt the more performant mode. The FB mode generates a completion for each packet and never guarantees that there won't be any out-of-order completions. Serialize that using a bitmap of completed descriptors and report contiguous blocks of free bits to match XDP and XSk expectations and avoid further code complication. In case of multi-buffer frames, only the bit corresponding to the first descriptor is toggled as there will be only one completion for the entire packet carrying the index of this first descriptor.
The usage of a bitmap on hotpath might sound scary, but this fallback is able to reach around 70% of the QB mode's performance, which is comparable to what ice gives us. The main bottlenecks are unlikely()s and one completion per each packet, while in the QB mode we have one completion per batch (which might contain 64 or even 128 frames), plus the size of the completion descriptor is 8 bytes in this mode (4 bytes in the QB mode), which means a lot of additional PCI traffic.
bloat-o-meter shows .text increase in about 2 Kb without adding new functions or uninlining any of the existing ones. I played a bunch with inlining and uninlining certain pieces or the whole fallback, but the compiler collapses and optimizes libeth templates so hardly so that each additional external call only makes things worse.
--- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 18 ++- drivers/net/ethernet/intel/idpf/xdp.h | 60 +++++++++ include/net/libeth/xdp.h | 13 ++ drivers/net/ethernet/intel/idpf/idpf_txrx.c | 19 ++- drivers/net/ethernet/intel/idpf/xdp.c | 142 +++++++++++++++++++- 5 files changed, 234 insertions(+), 18 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_txrx.h +11 -7
@@ -628,12 +628,14 @@ libeth_cacheline_set_assert(struct idpf_rx_queue,* @clean_budget: singleq only, queue cleaning budget * @cleaned_pkts: Number of packets cleaned for the above said case * @refillq: Pointer to refill queue +* @cached_tstamp_caps: Tx timestamp capabilities negotiated with the CP +* @tstamp_task: Work that handles Tx timestamp read * @pending: number of pending descriptors to send in QB * @xdp_tx: number of pending &xdp_buff or &xdp_frame buffers * @timer: timer for XDP Tx queue cleanup * @xdp_lock: lock for XDP Tx queues sharing -* @cached_tstamp_caps: Tx timestamp capabilities negotiated with the CP -* @tstamp_task: Work that handles Tx timestamp read +* @pending_mask: mask of buffers waiting for completion in the FB XDP mode +* @curr_tag: current completion tag written to Tx descs in the FB XDP mode * @stats_sync: See struct u64_stats_sync * @q_stats: See union idpf_tx_queue_stats * @q_id: Queue id
@@ -695,6 +697,9 @@ struct idpf_tx_queue {u16 cleaned_pkts;struct idpf_sw_queue *refillq; + +struct idpf_ptp_vport_tx_tstamp_caps *cached_tstamp_caps; +struct work_struct *tstamp_task; };struct {u32 pending;
@@ -702,12 +707,12 @@ struct idpf_tx_queue {struct libeth_xdpsq_timer *timer;struct libeth_xdpsq_lock xdp_lock; + +unsigned long *pending_mask; +u32 curr_tag; }; }; -struct idpf_ptp_vport_tx_tstamp_caps *cached_tstamp_caps; -struct work_struct *tstamp_task; -struct u64_stats_sync stats_sync;struct idpf_tx_queue_stats q_stats;__cacheline_group_end_aligned (read_write);
@@ -724,8 +729,7 @@ struct idpf_tx_queue {__cacheline_group_end_aligned (cold); }; libeth_cacheline_set_assert(struct idpf_tx_queue, 64, -104 + - offsetof(struct idpf_tx_queue , cached_tstamp_caps) - +96 + offsetof(struct idpf_tx_queue , tstamp_task) - offsetofend(struct idpf_tx_queue, timer) + offsetof(struct idpf_tx_queue , q_stats) - offsetofend(struct idpf_tx_queue, tstamp_task),
drivers/net/ethernet/intel/idpf/xdp.h +60 -0
84 lines not on this page · raw message
include/net/libeth/xdp.h +13 -0
@@ -430,6 +430,19 @@ struct libeth_xdpsq {struct libeth_xdpsq_lock *lock; }; +/** +* libeth_xdpsq_to_sq - get SQ pointer from an XDPSQ pointer +* @xdpsq: &libeth_xdpsq corresponding to the queue +* @type: typeof() of the driver Tx queue structure +* @member: name of the NTU field inside @type +* +* Some of the sending callbacks take only &libeth_xdpsq pointer and no pointer +* to the actual driver Tx queue structure. Use this helper to quickly jump to +* the latter when needed. +*/ +#define libeth_xdpsq_to_sq (xdpsq, type, member) \ + container_of_const((xdpsq)->ntu, type, member) +/** * struct libeth_xdp_tx_desc - abstraction for an XDP Tx descriptor * @addr: DMA address of the frame
drivers/net/ethernet/intel/idpf/idpf_txrx.c +15 -4
@@ -179,10 +179,11 @@ static int idpf_tx_buf_alloc_all(struct idpf_tx_queue *tx_q)/* Allocate book keeping buffers only. Buffers to be supplied to HW * are allocated by kernel network stack and received as part of skb */ -if (idpf_queue_has (FLOW_SCH_EN , tx_q)) +if (idpf_queue_has (FLOW_SCH_EN , tx_q) && !idpf_queue_has (XDP , tx_q)) tx_q->buf_pool_size =U16_MAX ;else tx_q->buf_pool_size = tx_q->desc_count; + tx_q->tx_buf =kzalloc_objs (*tx_q->tx_buf, tx_q->buf_pool_size);if (!tx_q->tx_buf)return -ENOMEM ;
@@ -227,7 +228,7 @@ static int idpf_tx_desc_alloc(const struct idpf_vport *vport,idpf_xsk_setup_queue (vport, tx_q,VIRTCHNL2_QUEUE_TYPE_TX ); -if (!idpf_queue_has (FLOW_SCH_EN , tx_q)) +if (!idpf_queue_has (FLOW_SCH_EN , tx_q) ||idpf_queue_has (XDP , tx_q))return 0 ; refillq = tx_q->refillq;
@@ -1054,6 +1055,13 @@ static void idpf_clean_queue_set(const struct idpf_queue_set *qs)if (idpf_queue_has (XDP , q->txq)) { q->txq->pending =0 ; q->txq->xdp_tx =0 ; + +if (static_branch_unlikely (&idpf_xdp_fb) && +idpf_queue_has (FLOW_SCH_EN , q->txq)) { +bitmap_zero (q->txq->pending_mask, + q->txq->desc_count); + q->txq->curr_tag =U32_MAX ; + } }else { q->txq->txq_grp->num_completions_pending =0 ; }
@@ -1316,7 +1324,8 @@ static void idpf_txq_group_rel(struct idpf_q_vec_rsrc *rsrc)if (!txq_grp->txqs[j])continue ; -if (idpf_queue_has (FLOW_SCH_EN , txq_grp->txqs[j])) { +if (idpf_queue_has (FLOW_SCH_EN , txq_grp->txqs[j]) && + !idpf_queue_has (XDP , txq_grp->txqs[j])) {kfree (txq_grp->txqs[j]->refillq); txq_grp->txqs[j]->refillq =NULL ; }
@@ -1439,6 +1448,8 @@ static int idpf_vport_init_fast_path_txqs(struct idpf_vport *vport, {struct idpf_ptp_vport_tx_tstamp_caps *caps = vport->tx_tstamp_caps;struct work_struct *tstamp_task = &vport->tstamp_task; +/* __IDPF_Q_XDP is never set yet at this point */ +u32 end =min_not_zero (rsrc->xdp_txq_offset,U32_MAX );int k =0 ; vport->txqs =kzalloc_objs (*vport->txqs, rsrc->num_txq);
@@ -1453,7 +1464,7 @@ static int idpf_vport_init_fast_path_txqs(struct idpf_vport *vport, vport->txqs[k] = tx_grp->txqs[j]; vport->txqs[k]->idx = k; -if (!caps) +if (!caps || k >= end)continue ; vport->txqs[k]->cached_tstamp_caps = caps;
drivers/net/ethernet/intel/idpf/xdp.c +135 -7
212 lines not on this page · raw message
Signature · 1 line
2.56.1