public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] net: add SKB_DROP_REASON_RECURSION_LIMIT
@ 2026-03-12 20:18 Eric Dumazet
  2026-03-12 20:18 ` [PATCH net-next 1/2] net: dropreason: " Eric Dumazet
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Eric Dumazet @ 2026-03-12 20:18 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, netdev, eric.dumazet, Eric Dumazet

Add a new drop reason : SKB_DROP_REASON_RECURSION_LIMIT

Used for packets dropped in a too deep virtual device chain,
from tunnels and __dev_queue_xmit()

__dev_queue_xmit() can also return SKB_DROP_REASON_DEV_READY

Eric Dumazet (2):
  net: dropreason: add SKB_DROP_REASON_RECURSION_LIMIT
  net: plumb drop reasons to __dev_queue_xmit()

 include/net/dropreason-core.h |  3 ++
 include/net/ip6_tunnel.h      |  2 +-
 net/core/dev.c                | 83 ++++++++++++++++++-----------------
 net/ipv4/ip_tunnel_core.c     |  2 +-
 4 files changed, 48 insertions(+), 42 deletions(-)

-- 
2.53.0.880.g73c4285caa-goog


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net-next 1/2] net: dropreason: add SKB_DROP_REASON_RECURSION_LIMIT
  2026-03-12 20:18 [PATCH net-next 0/2] net: add SKB_DROP_REASON_RECURSION_LIMIT Eric Dumazet
@ 2026-03-12 20:18 ` Eric Dumazet
  2026-03-13 20:14   ` Joe Damato
  2026-03-12 20:18 ` [PATCH net-next 2/2] net: plumb drop reasons to __dev_queue_xmit() Eric Dumazet
  2026-03-14 16:00 ` [PATCH net-next 0/2] net: add SKB_DROP_REASON_RECURSION_LIMIT patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2026-03-12 20:18 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, netdev, eric.dumazet, Eric Dumazet

ip[6]tunnel_xmit() can drop packets if a too deep recursion level
is detected.

Add SKB_DROP_REASON_RECURSION_LIMIT drop reason.

We will use this reason later in __dev_queue_xmit().

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 include/net/dropreason-core.h | 3 +++
 include/net/ip6_tunnel.h      | 2 +-
 net/ipv4/ip_tunnel_core.c     | 2 +-
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h
index 5c8c2eb3d2c5b038683b78952106e374cf3b68d1..de61dd5dbfd9dc7d91d22d79a510d42fb69eb60a 100644
--- a/include/net/dropreason-core.h
+++ b/include/net/dropreason-core.h
@@ -123,6 +123,7 @@
 	FN(PFMEMALLOC)	\
 	FN(PSP_INPUT)			\
 	FN(PSP_OUTPUT)			\
+	FN(RECURSION_LIMIT)		\
 	FNe(MAX)
 
 /**
@@ -582,6 +583,8 @@ enum skb_drop_reason {
 	SKB_DROP_REASON_PSP_INPUT,
 	/** @SKB_DROP_REASON_PSP_OUTPUT: PSP output checks failed */
 	SKB_DROP_REASON_PSP_OUTPUT,
+	/** @SKB_DROP_REASON_RECURSION_LIMIT: Dead loop on virtual device. */
+	SKB_DROP_REASON_RECURSION_LIMIT,
 	/**
 	 * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which
 	 * shouldn't be used as a real 'reason' - only for tracing code gen
diff --git a/include/net/ip6_tunnel.h b/include/net/ip6_tunnel.h
index 359b595f1df93663b3e32c006d936427e8c8b20c..b99805ee2fd14bef6c7bc4daa6e8dfbc34984e4e 100644
--- a/include/net/ip6_tunnel.h
+++ b/include/net/ip6_tunnel.h
@@ -162,7 +162,7 @@ static inline void ip6tunnel_xmit(struct sock *sk, struct sk_buff *skb,
 					     dev->name);
 			DEV_STATS_INC(dev, tx_errors);
 		}
-		kfree_skb(skb);
+		kfree_skb_reason(skb, SKB_DROP_REASON_RECURSION_LIMIT);
 		return;
 	}
 
diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
index 5683c328990f49df2954af9d890b5f24150caeb2..f430d6f0463e7ab5761e98047a866d304a49abb2 100644
--- a/net/ipv4/ip_tunnel_core.c
+++ b/net/ipv4/ip_tunnel_core.c
@@ -65,7 +65,7 @@ void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
 			DEV_STATS_INC(dev, tx_errors);
 		}
 		ip_rt_put(rt);
-		kfree_skb(skb);
+		kfree_skb_reason(skb, SKB_DROP_REASON_RECURSION_LIMIT);
 		return;
 	}
 
-- 
2.53.0.880.g73c4285caa-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 2/2] net: plumb drop reasons to __dev_queue_xmit()
  2026-03-12 20:18 [PATCH net-next 0/2] net: add SKB_DROP_REASON_RECURSION_LIMIT Eric Dumazet
  2026-03-12 20:18 ` [PATCH net-next 1/2] net: dropreason: " Eric Dumazet
@ 2026-03-12 20:18 ` Eric Dumazet
  2026-03-13 20:18   ` Joe Damato
  2026-03-14 16:00 ` [PATCH net-next 0/2] net: add SKB_DROP_REASON_RECURSION_LIMIT patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2026-03-12 20:18 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, netdev, eric.dumazet, Eric Dumazet

Add drop reasons to __dev_queue_xmit():

- SKB_DROP_REASON_DEV_READY : device is not UP.

- SKB_DROP_REASON_RECURSION_LIMIT : recursion limit on virtual device is hit.

Also add an unlikely() for the SKB_DROP_REASON_DEV_READY case,
and reduce indentation level.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/core/dev.c | 83 ++++++++++++++++++++++++++------------------------
 1 file changed, 43 insertions(+), 40 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index f48dc299e4b270f2fedba11e669d4940e73f0d4d..200d44883fc130dcc80afa1ddccce68bf3ff592c 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4745,9 +4745,10 @@ int __dev_queue_xmit(struct sk_buff *skb, struct net_device *sb_dev)
 {
 	struct net_device *dev = skb->dev;
 	struct netdev_queue *txq = NULL;
-	struct Qdisc *q;
-	int rc = -ENOMEM;
+	enum skb_drop_reason reason;
+	int cpu, rc = -ENOMEM;
 	bool again = false;
+	struct Qdisc *q;
 
 	skb_reset_mac_header(skb);
 	skb_assert_len(skb);
@@ -4816,59 +4817,61 @@ int __dev_queue_xmit(struct sk_buff *skb, struct net_device *sb_dev)
 	 * Check this and shot the lock. It is not prone from deadlocks.
 	 *Either shot noqueue qdisc, it is even simpler 8)
 	 */
-	if (dev->flags & IFF_UP) {
-		int cpu = smp_processor_id(); /* ok because BHs are off */
+	if (unlikely(!(dev->flags & IFF_UP))) {
+		reason = SKB_DROP_REASON_DEV_READY;
+		goto drop;
+	}
 
-		if (!netif_tx_owned(txq, cpu)) {
-			bool is_list = false;
+	cpu = smp_processor_id(); /* ok because BHs are off */
 
-			if (dev_xmit_recursion())
-				goto recursion_alert;
+	if (likely(!netif_tx_owned(txq, cpu))) {
+		bool is_list = false;
 
-			skb = validate_xmit_skb(skb, dev, &again);
-			if (!skb)
-				goto out;
+		if (dev_xmit_recursion())
+			goto recursion_alert;
 
-			HARD_TX_LOCK(dev, txq, cpu);
+		skb = validate_xmit_skb(skb, dev, &again);
+		if (!skb)
+			goto out;
 
-			if (!netif_xmit_stopped(txq)) {
-				is_list = !!skb->next;
+		HARD_TX_LOCK(dev, txq, cpu);
 
-				dev_xmit_recursion_inc();
-				skb = dev_hard_start_xmit(skb, dev, txq, &rc);
-				dev_xmit_recursion_dec();
+		if (!netif_xmit_stopped(txq)) {
+			is_list = !!skb->next;
 
-				/* GSO segments a single SKB into
-				 * a list of frames. TCP expects error
-				 * to mean none of the data was sent.
-				 */
-				if (is_list)
-					rc = NETDEV_TX_OK;
-			}
-			HARD_TX_UNLOCK(dev, txq);
-			if (!skb) /* xmit completed */
-				goto out;
+			dev_xmit_recursion_inc();
+			skb = dev_hard_start_xmit(skb, dev, txq, &rc);
+			dev_xmit_recursion_dec();
 
-			net_crit_ratelimited("Virtual device %s asks to queue packet!\n",
-					     dev->name);
-			/* NETDEV_TX_BUSY or queue was stopped */
-			if (!is_list)
-				rc = -ENETDOWN;
-		} else {
-			/* Recursion is detected! It is possible,
-			 * unfortunately
+			/* GSO segments a single SKB into a list of frames.
+			 * TCP expects error to mean none of the data was sent.
 			 */
-recursion_alert:
-			net_crit_ratelimited("Dead loop on virtual device %s, fix it urgently!\n",
-					     dev->name);
-			rc = -ENETDOWN;
+			if (is_list)
+				rc = NETDEV_TX_OK;
 		}
+		HARD_TX_UNLOCK(dev, txq);
+		if (!skb) /* xmit completed */
+			goto out;
+
+		net_crit_ratelimited("Virtual device %s asks to queue packet!\n",
+				     dev->name);
+		/* NETDEV_TX_BUSY or queue was stopped */
+		if (!is_list)
+			rc = -ENETDOWN;
+	} else {
+		/* Recursion is detected! It is possible unfortunately. */
+recursion_alert:
+		net_crit_ratelimited("Dead loop on virtual device %s, fix it urgently!\n",
+				     dev->name);
+		rc = -ENETDOWN;
 	}
 
+	reason = SKB_DROP_REASON_RECURSION_LIMIT;
+drop:
 	rcu_read_unlock_bh();
 
 	dev_core_stats_tx_dropped_inc(dev);
-	kfree_skb_list(skb);
+	kfree_skb_list_reason(skb, reason);
 	return rc;
 out:
 	rcu_read_unlock_bh();
-- 
2.53.0.880.g73c4285caa-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 1/2] net: dropreason: add SKB_DROP_REASON_RECURSION_LIMIT
  2026-03-12 20:18 ` [PATCH net-next 1/2] net: dropreason: " Eric Dumazet
@ 2026-03-13 20:14   ` Joe Damato
  0 siblings, 0 replies; 6+ messages in thread
From: Joe Damato @ 2026-03-13 20:14 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	netdev, eric.dumazet

On Thu, Mar 12, 2026 at 08:18:23PM +0000, Eric Dumazet wrote:
> ip[6]tunnel_xmit() can drop packets if a too deep recursion level
> is detected.
> 
> Add SKB_DROP_REASON_RECURSION_LIMIT drop reason.
> 
> We will use this reason later in __dev_queue_xmit().
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> ---
>  include/net/dropreason-core.h | 3 +++
>  include/net/ip6_tunnel.h      | 2 +-
>  net/ipv4/ip_tunnel_core.c     | 2 +-
>  3 files changed, 5 insertions(+), 2 deletions(-)

Reviewed-by: Joe Damato <joe@dama.to>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 2/2] net: plumb drop reasons to __dev_queue_xmit()
  2026-03-12 20:18 ` [PATCH net-next 2/2] net: plumb drop reasons to __dev_queue_xmit() Eric Dumazet
@ 2026-03-13 20:18   ` Joe Damato
  0 siblings, 0 replies; 6+ messages in thread
From: Joe Damato @ 2026-03-13 20:18 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	netdev, eric.dumazet

On Thu, Mar 12, 2026 at 08:18:24PM +0000, Eric Dumazet wrote:
> Add drop reasons to __dev_queue_xmit():
> 
> - SKB_DROP_REASON_DEV_READY : device is not UP.
> 
> - SKB_DROP_REASON_RECURSION_LIMIT : recursion limit on virtual device is hit.
> 
> Also add an unlikely() for the SKB_DROP_REASON_DEV_READY case,
> and reduce indentation level.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> ---
>  net/core/dev.c | 83 ++++++++++++++++++++++++++------------------------
>  1 file changed, 43 insertions(+), 40 deletions(-)

Reviewed-by: Joe Damato <joe@dama.to>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 0/2] net: add SKB_DROP_REASON_RECURSION_LIMIT
  2026-03-12 20:18 [PATCH net-next 0/2] net: add SKB_DROP_REASON_RECURSION_LIMIT Eric Dumazet
  2026-03-12 20:18 ` [PATCH net-next 1/2] net: dropreason: " Eric Dumazet
  2026-03-12 20:18 ` [PATCH net-next 2/2] net: plumb drop reasons to __dev_queue_xmit() Eric Dumazet
@ 2026-03-14 16:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-03-14 16:00 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: davem, kuba, pabeni, horms, netdev, eric.dumazet

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 12 Mar 2026 20:18:22 +0000 you wrote:
> Add a new drop reason : SKB_DROP_REASON_RECURSION_LIMIT
> 
> Used for packets dropped in a too deep virtual device chain,
> from tunnels and __dev_queue_xmit()
> 
> __dev_queue_xmit() can also return SKB_DROP_REASON_DEV_READY
> 
> [...]

Here is the summary with links:
  - [net-next,1/2] net: dropreason: add SKB_DROP_REASON_RECURSION_LIMIT
    https://git.kernel.org/netdev/net-next/c/d15d3de94a47
  - [net-next,2/2] net: plumb drop reasons to __dev_queue_xmit()
    https://git.kernel.org/netdev/net-next/c/045f977dd4eb

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-03-14 16:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-12 20:18 [PATCH net-next 0/2] net: add SKB_DROP_REASON_RECURSION_LIMIT Eric Dumazet
2026-03-12 20:18 ` [PATCH net-next 1/2] net: dropreason: " Eric Dumazet
2026-03-13 20:14   ` Joe Damato
2026-03-12 20:18 ` [PATCH net-next 2/2] net: plumb drop reasons to __dev_queue_xmit() Eric Dumazet
2026-03-13 20:18   ` Joe Damato
2026-03-14 16:00 ` [PATCH net-next 0/2] net: add SKB_DROP_REASON_RECURSION_LIMIT patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox