Skip to content

Commit 613e9e8

Browse files
kuba-mooPaolo Abeni
authored andcommitted
eth: fbnic: fix accounting of XDP packets
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: 5213ff0 ("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>
1 parent 7e617d5 commit 613e9e8

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

drivers/net/ethernet/meta/fbnic/fbnic_txrx.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,7 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *nv,
12421242
/* Walk the completion queue collecting the heads reported by NIC */
12431243
while (likely(packets < budget)) {
12441244
struct sk_buff *skb = ERR_PTR(-EINVAL);
1245+
u32 pkt_bytes;
12451246
u64 rcd;
12461247

12471248
if ((*raw_rcd & cpu_to_le64(FBNIC_RCD_DONE)) == done)
@@ -1272,37 +1273,38 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *nv,
12721273
/* We currently ignore the action table index */
12731274
break;
12741275
case FBNIC_RCD_TYPE_META:
1275-
if (unlikely(pkt->add_frag_failed))
1276-
skb = NULL;
1277-
else if (likely(!fbnic_rcd_metadata_err(rcd)))
1276+
if (likely(!fbnic_rcd_metadata_err(rcd) &&
1277+
!pkt->add_frag_failed)) {
1278+
pkt_bytes = xdp_get_buff_len(&pkt->buff);
12781279
skb = fbnic_run_xdp(nv, pkt);
1280+
}
12791281

12801282
/* Populate skb and invalidate XDP */
12811283
if (!IS_ERR_OR_NULL(skb)) {
12821284
fbnic_populate_skb_fields(nv, rcd, skb, qt,
12831285
&csum_complete,
12841286
&csum_none);
1285-
1286-
packets++;
1287-
bytes += skb->len;
1288-
12891287
napi_gro_receive(&nv->napi, skb);
12901288
} else if (skb == ERR_PTR(-FBNIC_XDP_TX)) {
12911289
pkt_tail = nv->qt[0].sub1.tail;
1292-
bytes += xdp_get_buff_len(&pkt->buff);
1290+
} else if (PTR_ERR(skb) == -FBNIC_XDP_CONSUME) {
1291+
fbnic_put_pkt_buff(qt, pkt, 1);
12931292
} else {
1294-
if (!skb) {
1293+
if (!skb)
12951294
alloc_failed++;
1296-
dropped++;
1297-
} else if (skb == ERR_PTR(-FBNIC_XDP_LEN_ERR)) {
1295+
1296+
if (skb == ERR_PTR(-FBNIC_XDP_LEN_ERR))
12981297
length_errors++;
1299-
} else {
1298+
else
13001299
dropped++;
1301-
}
13021300

13031301
fbnic_put_pkt_buff(qt, pkt, 1);
1302+
goto next_dont_count;
13041303
}
13051304

1305+
packets++;
1306+
bytes += pkt_bytes;
1307+
next_dont_count:
13061308
pkt->buff.data_hard_start = NULL;
13071309

13081310
break;
@@ -1319,8 +1321,6 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *nv,
13191321
u64_stats_update_begin(&rcq->stats.syncp);
13201322
rcq->stats.packets += packets;
13211323
rcq->stats.bytes += bytes;
1322-
/* Re-add ethernet header length (removed in fbnic_build_skb) */
1323-
rcq->stats.bytes += ETH_HLEN * packets;
13241324
rcq->stats.dropped += dropped;
13251325
rcq->stats.rx.alloc_failed += alloc_failed;
13261326
rcq->stats.rx.csum_complete += csum_complete;

0 commit comments

Comments
 (0)