]> www.infradead.org Git - users/hch/misc.git/commitdiff
eth: fbnic: fix accounting of XDP packets
authorJakub Kicinski <kuba@kernel.org>
Tue, 7 Oct 2025 23:26:46 +0000 (16:26 -0700)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 9 Oct 2025 09:10:02 +0000 (11:10 +0200)
Make XDP-handled packets appear in the Rx stats. The driver has been
counting XDP_TX packets on the Tx ring, but there wasn't much accounting
on the Rx side (the Rx bytes appear to be incremented on XDP_TX but
XDP_DROP / XDP_ABORT are only counted as Rx drops).

Counting XDP_TX packets (not just bytes) in Rx stats looks like
a simple bug of omission.

The XDP_DROP handling appears to be intentional. Whether XDP_DROP
packets should be counted in interface-level Rx stats is a bit
unclear historically. When we were defining qstats, however,
we clarified based on operational experience that in this context:

  name: rx-packets
  doc: |
    Number of wire packets successfully received and passed to the stack.
    For drivers supporting XDP, XDP is considered the first layer
    of the stack, so packets consumed by XDP are still counted here.

fbnic does not obey this requirement. Since XDP support has been added
in current release cycle, instead of splitting interface and qstat
handling - make them both follow the qstat definition.

Another small tweak here is that we count bytes as received on the wire
rather than post-XDP bytes (xdp_get_buff_len() vs skb->len).

Reviewed-by: Simon Horman <horms@kernel.org>
Fixes: 5213ff086344 ("eth: fbnic: Collect packet statistics for XDP")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://patch.msgid.link/20251007232653.2099376-3-kuba@kernel.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c

index cf773cc78e40451bbc4e36212f7faa85709b2c5c..a56dc148f66d74b01d18239f3c96aeed6c865726 100644 (file)
@@ -1242,6 +1242,7 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *nv,
        /* Walk the completion queue collecting the heads reported by NIC */
        while (likely(packets < budget)) {
                struct sk_buff *skb = ERR_PTR(-EINVAL);
+               u32 pkt_bytes;
                u64 rcd;
 
                if ((*raw_rcd & cpu_to_le64(FBNIC_RCD_DONE)) == done)
@@ -1272,37 +1273,38 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *nv,
                        /* We currently ignore the action table index */
                        break;
                case FBNIC_RCD_TYPE_META:
-                       if (unlikely(pkt->add_frag_failed))
-                               skb = NULL;
-                       else if (likely(!fbnic_rcd_metadata_err(rcd)))
+                       if (likely(!fbnic_rcd_metadata_err(rcd) &&
+                                  !pkt->add_frag_failed)) {
+                               pkt_bytes = xdp_get_buff_len(&pkt->buff);
                                skb = fbnic_run_xdp(nv, pkt);
+                       }
 
                        /* Populate skb and invalidate XDP */
                        if (!IS_ERR_OR_NULL(skb)) {
                                fbnic_populate_skb_fields(nv, rcd, skb, qt,
                                                          &csum_complete,
                                                          &csum_none);
-
-                               packets++;
-                               bytes += skb->len;
-
                                napi_gro_receive(&nv->napi, skb);
                        } else if (skb == ERR_PTR(-FBNIC_XDP_TX)) {
                                pkt_tail = nv->qt[0].sub1.tail;
-                               bytes += xdp_get_buff_len(&pkt->buff);
+                       } else if (PTR_ERR(skb) == -FBNIC_XDP_CONSUME) {
+                               fbnic_put_pkt_buff(qt, pkt, 1);
                        } else {
-                               if (!skb) {
+                               if (!skb)
                                        alloc_failed++;
-                                       dropped++;
-                               } else if (skb == ERR_PTR(-FBNIC_XDP_LEN_ERR)) {
+
+                               if (skb == ERR_PTR(-FBNIC_XDP_LEN_ERR))
                                        length_errors++;
-                               } else {
+                               else
                                        dropped++;
-                               }
 
                                fbnic_put_pkt_buff(qt, pkt, 1);
+                               goto next_dont_count;
                        }
 
+                       packets++;
+                       bytes += pkt_bytes;
+next_dont_count:
                        pkt->buff.data_hard_start = NULL;
 
                        break;
@@ -1319,8 +1321,6 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *nv,
        u64_stats_update_begin(&rcq->stats.syncp);
        rcq->stats.packets += packets;
        rcq->stats.bytes += bytes;
-       /* Re-add ethernet header length (removed in fbnic_build_skb) */
-       rcq->stats.bytes += ETH_HLEN * packets;
        rcq->stats.dropped += dropped;
        rcq->stats.rx.alloc_failed += alloc_failed;
        rcq->stats.rx.csum_complete += csum_complete;