net: don't touch dev->stats in BPF redirect paths
Subsystems (4)
Jakub Kicinski
maintainerPATCH v2 1/1 net: don't touch dev->stats in BPF redirect paths
Gal reports that BPF redirect increments dev->stats.tx_errors on failure. This is not correct, most modern drivers completely ignore dev->stats so these drops will be invisible to the user. Core code should use the dedicated core stats which are folded into device stats in dev_get_stats().
Note that we're switching from tx_errors to tx_dropped. Core only has tx_dropped, hence presumably users already expect that counter to increment for "stack" Tx issues.
---
v2:
- add note on tx_dropped to the commit msg
v1: https://lore.kernel.org/[email protected]
--- net/core/filter.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/core/filter.c +4 -4
@@ -2289,12 +2289,12 @@ static int __bpf_redirect_neigh_v6(struct sk_buff *skb, struct net_device *dev, err =bpf_out_neigh_v6 (net, skb, dev, nh);if (unlikely (net_xmit_eval (err))) -DEV_STATS_INC (dev, tx_errors); +dev_core_stats_tx_dropped_inc (dev);else ret =NET_XMIT_SUCCESS ; goto out_xmit; out_drop: -DEV_STATS_INC (dev, tx_errors); +dev_core_stats_tx_dropped_inc (dev);kfree_skb (skb); out_xmit:return ret;
@@ -2396,12 +2396,12 @@ static int __bpf_redirect_neigh_v4(struct sk_buff *skb, struct net_device *dev, err =bpf_out_neigh_v4 (net, skb, dev, nh);if (unlikely (net_xmit_eval (err))) -DEV_STATS_INC (dev, tx_errors); +dev_core_stats_tx_dropped_inc (dev);else ret =NET_XMIT_SUCCESS ; goto out_xmit; out_drop: -DEV_STATS_INC (dev, tx_errors); +dev_core_stats_tx_dropped_inc (dev);kfree_skb (skb); out_xmit:return ret;
Signature · 1 line
2.52.0
Quoted 10 lines · Jakub Kicinski
Gal reports that BPF redirect increments
dev->stats.tx_errorson failure. This is not correct, most modern drivers completely ignoredev->statsso these drops will be invisible to the user. Core code should use the dedicated core stats which are folded into device stats indev_get_stats().Note that we're switching from
tx_errorstotx_dropped. Core only hastx_dropped, hence presumably users already expect that counter to increment for "stack" Tx issues.
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Thu, 29 Jan 2026 19:38:27 -0800 you wrote:
Gal reports that BPF redirect increments
dev->stats.tx_errorson failure. This is not correct, most modern drivers completely ignoredev->statsso these drops will be invisible to the user. Core code should use the dedicated core stats which are folded into device stats indev_get_stats().Note that we're switching from
tx_errorstotx_dropped. Core only hastx_dropped, hence presumably users already expect that counter to increment for "stack" Tx issues.[...]
Here is the summary with links:
- [net,v2] net: don't touch dev->stats in BPF redirect paths
https://git.kernel.org/netdev/net/c/fdf3f6800be3
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html