Skip to contentSkip to conversation

net: don't touch dev->stats in BPF redirect paths

PATCH Superseded Jakub Kicinski 4 participants 5 messages Jan 28 – Jan 29

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 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().

Fixes b4ab31414970 ("bpf: Add redirect_neigh helper as redirect drop-in")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 net/core/filter.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
net/core/filter.c +4 -4
index 616e0520a0bb..2c21735798a5 100644
@@ -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
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Jakub Kicinski

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().

#2 lore raw
In reply to Jakub Kicinski
Quoted 10 lines · Jakub Kicinski

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().

Fixes b4ab31414970 ("bpf: Add redirect_neigh helper as redirect drop-in")

Aha, this kinda makes my mlx5 fix redundant.
I'm debating whether I should send a revert?

net/core/filter.c static int __bpf_redirect_neigh_v6(struct sk_buff *skb, struct net_device *dev, · line 2292

Quoted 10 lines
net/core/filter.c +1 -1
index 616e0520a0bb..2c21735798a5 100644
@@ -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);

The commit message didn't mention anything about changing tx_errors to tx_dropped.

maintainer Acked-by on v1 1/1
#4 lore raw
In reply to Jakub Kicinski
Quoted 10 lines · Jakub Kicinski

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().

Fixes b4ab31414970 ("bpf: Add redirect_neigh helper as redirect drop-in")
author maintainer
#3 lore raw
In reply to Gal Pressman
Quoted 7 lines · On Thu, 29 Jan 2026 09:45:10 +0200 Gal Pressman wrote:
Quoted 6 lines · Jakub Kicinski

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().

Quoted 7 lines
Quoted 4 lines
Fixes b4ab31414970 ("bpf: Add redirect_neigh helper as redirect drop-in")

Aha, this kinda makes my mlx5 fix redundant.
I'm debating whether I should send a revert?

Up to you, it doesn't hurt.
I guess the main reason to revert would be to catch similar bugs in the future, given the popularity of mlx5, but up to you if you want to be exposed to such bugs :)

Quoted 6 lines
Quoted 6 lines
net/core/filter.c +0 -0
index 616e0520a0bb..2c21735798a5 100644
@@ -2289,12 +2289,12 @@ static int __bpf_redirect_neigh_v6(struct sk_buff *skb, struct net_device *dev,
 
Quoted 7 lines

net/core/filter.c static int __bpf_redirect_neigh_v6(struct sk_buff *skb, struct net_device *dev, · line 2292

Quoted 4 lines
net/core/filter.c +1 -1
 	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);  

The commit message didn't mention anything about changing tx_errors to tx_dropped.

Fair, let me respin with a note.