Skip to contentSkip to conversation

net: erspan: set lltx to avoid sch_direct_xmit deadlock

PATCH Superseded Yun Zhou 3 participants 6 messages Jul 13 – Jul 20

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Yun Zhou

author
#0 lore raw

PATCH v2 1/1 net: erspan: set lltx to avoid sch_direct_xmit deadlock

erspan_xmit() re-enters the network stack via ip_tunnel_xmit(), causing nested acquisition of _xmit_lock on the underlay device while already holding the ERSPAN device's _xmit_lock. Both are ARPHRD_ETHER and share the same lockdep class, creating an ABBA deadlock:

sch_direct_xmit [lock erspan] -> erspan_xmit -> ip_tunnel_xmit -> ip_output -> __dev_queue_xmit -> sch_direct_xmit [lock underlay]

Set dev->lltx = true so HARD_TX_LOCK() skips the spinlock for ERSPAN. This is safe as erspan_xmit() has no shared mutable state: o_seqno is atomic, stats use atomic_long_inc, and dst_cache is per-CPU. GRETAP, the sibling device with identical xmit structure, already sets lltx.

Reported-by [email protected]
Fixes 84e54fe0a5ea ("gre: introduce native tunnel support for ERSPAN")

---
v2:
- change subject prefix to [PATCH net]

 net/ipv4/ip_gre.c | 2 ++
 1 file changed, 2 insertions(+)
net/ipv4/ip_gre.c +2 -0
index 3efdfb4ffa21..9fbff16cda1d 100644
@@ -1363,6 +1363,8 @@ static int erspan_tunnel_init(struct net_device *dev)
 	dev->features		|= GRE_FEATURES;
 	dev->hw_features	|= GRE_FEATURES;
 	dev->priv_flags		|= IFF_LIVE_ADDR_CHANGE;
+	/* Skip TX lock: xmit re-enters stack, risking ABBA with underlay */
+	dev->lltx = true;
 	netif_keep_dst(dev);
 
 	return ip_tunnel_init(dev);
Signature · 1 line
2.43.0
author
#1 lore raw

Hi Ido,

Could you please help review this patch when you have a moment?

Thanks,
Yun

Quoted 37 lines · Yun Zhou

erspan_xmit() re-enters the network stack via ip_tunnel_xmit(), causing nested acquisition of _xmit_lock on the underlay device while already holding the ERSPAN device's _xmit_lock. Both are ARPHRD_ETHER and share the same lockdep class, creating an ABBA deadlock:

   sch_direct_xmit [lock erspan] -> erspan_xmit -> ip_tunnel_xmit ->
   ip_output -> __dev_queue_xmit -> sch_direct_xmit [lock underlay]

Set dev->lltx = true so HARD_TX_LOCK() skips the spinlock for ERSPAN. This is safe as erspan_xmit() has no shared mutable state: o_seqno is atomic, stats use atomic_long_inc, and dst_cache is per-CPU. GRETAP, the sibling device with identical xmit structure, already sets lltx.

Reported-by [email protected]
Fixes 84e54fe0a5ea ("gre: introduce native tunnel support for ERSPAN")

---
v2:
- change subject prefix to [PATCH net]

  net/ipv4/ip_gre.c | 2 ++
  1 file changed, 2 insertions(+)
net/ipv4/ip_gre.c +2 -0
index 3efdfb4ffa21..9fbff16cda1d 100644
@@ -1363,6 +1363,8 @@ static int erspan_tunnel_init(struct net_device *dev)
  	dev->features		|= GRE_FEATURES;
  	dev->hw_features	|= GRE_FEATURES;
  	dev->priv_flags		|= IFF_LIVE_ADDR_CHANGE;
+	/* Skip TX lock: xmit re-enters stack, risking ABBA with underlay */
+	dev->lltx = true;
  	netif_keep_dst(dev);
 
  	return ip_tunnel_init(dev);
maintainer
#2 lore raw
In reply to Yun Zhou
Quoted 5 lines · Yun Zhou

erspan_xmit() re-enters the network stack via ip_tunnel_xmit(), causing nested acquisition of _xmit_lock on the underlay device while already holding the ERSPAN device's _xmit_lock. Both are ARPHRD_ETHER and share the same lockdep class, creating an ABBA deadlock:

Quoted 7 lines

sch_direct_xmit [lock erspan] -> erspan_xmit -> ip_tunnel_xmit -> ip_output -> __dev_queue_xmit -> sch_direct_xmit [lock underlay]

Set dev->lltx = true so HARD_TX_LOCK() skips the spinlock for ERSPAN. This is safe as erspan_xmit() has no shared mutable state: o_seqno is atomic, stats use atomic_long_inc, and dst_cache is per-CPU. GRETAP, the sibling device with identical xmit structure, already sets lltx.

erspan_xmit() (unlike gre_tap_xmit()) is performing non-atomic __clear_bit() on shared tunnel flags and KCSAN will probably flag it.

Eric had a patch [1] that changes erspan_xmit() to use a private copy of these flags. I think it's better to wait for Eric's patch to be merged before setting lltx.

Eric, can you please submit v2 of your patch to net?

Also, doesn't ip6erspan suffer from the same problem? Please try to reproduce and fix.

[1] https://lore.kernel.org/netdev/[email protected]/

Quoted 28 lines
Reported-by [email protected]
Fixes 84e54fe0a5ea ("gre: introduce native tunnel support for ERSPAN")

---
v2:
- change subject prefix to [PATCH net]

 net/ipv4/ip_gre.c | 2 ++
 1 file changed, 2 insertions(+)
net/ipv4/ip_gre.c +2 -0
index 3efdfb4ffa21..9fbff16cda1d 100644
@@ -1363,6 +1363,8 @@ static int erspan_tunnel_init(struct net_device *dev)
 	dev->features		|= GRE_FEATURES;
 	dev->hw_features	|= GRE_FEATURES;
 	dev->priv_flags		|= IFF_LIVE_ADDR_CHANGE;
+	/* Skip TX lock: xmit re-enters stack, risking ABBA with underlay */
+	dev->lltx = true;
 	netif_keep_dst(dev);
 
 	return ip_tunnel_init(dev);
Signature · 1 line
2.43.0
author
#3 lore raw
Quoted 20 lines · Ido Schimmel

CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 5 lines · Yun Zhou

erspan_xmit() re-enters the network stack via ip_tunnel_xmit(), causing nested acquisition of _xmit_lock on the underlay device while already holding the ERSPAN device's _xmit_lock. Both are ARPHRD_ETHER and share the same lockdep class, creating an ABBA deadlock:

Quoted 7 lines
   sch_direct_xmit [lock erspan] -> erspan_xmit -> ip_tunnel_xmit ->
   ip_output -> __dev_queue_xmit -> sch_direct_xmit [lock underlay]

Set dev->lltx = true so HARD_TX_LOCK() skips the spinlock for ERSPAN. This is safe as erspan_xmit() has no shared mutable state: o_seqno is atomic, stats use atomic_long_inc, and dst_cache is per-CPU. GRETAP, the sibling device with identical xmit structure, already sets lltx.

erspan_xmit() (unlike gre_tap_xmit()) is performing non-atomic __clear_bit() on shared tunnel flags and KCSAN will probably flag it.

Quoted 9 lines

Eric had a patch [1] that changes erspan_xmit() to use a private copy of these flags. I think it's better to wait for Eric's patch to be merged before setting lltx.

Eric, can you please submit v2 of your patch to net?

Also, doesn't ip6erspan suffer from the same problem? Please try to reproduce and fix.

Yes, ip6erspan has the same problem. I will fix it in v3.

Thanks,
Yun

#4 lore raw
In reply to Ido Schimmel
Quoted 15 lines · Ido Schimmel
Quoted 5 lines · Yun Zhou

erspan_xmit() re-enters the network stack via ip_tunnel_xmit(), causing nested acquisition of _xmit_lock on the underlay device while already holding the ERSPAN device's _xmit_lock. Both are ARPHRD_ETHER and share the same lockdep class, creating an ABBA deadlock:

Quoted 7 lines

sch_direct_xmit [lock erspan] -> erspan_xmit -> ip_tunnel_xmit -> ip_output -> __dev_queue_xmit -> sch_direct_xmit [lock underlay]

Set dev->lltx = true so HARD_TX_LOCK() skips the spinlock for ERSPAN. This is safe as erspan_xmit() has no shared mutable state: o_seqno is atomic, stats use atomic_long_inc, and dst_cache is per-CPU. GRETAP, the sibling device with identical xmit structure, already sets lltx.

Quoted 8 lines

erspan_xmit() (unlike gre_tap_xmit()) is performing non-atomic __clear_bit() on shared tunnel flags and KCSAN will probably flag it.

Eric had a patch [1] that changes erspan_xmit() to use a private copy of these flags. I think it's better to wait for Eric's patch to be merged before setting lltx.

Eric, can you please submit v2 of your patch to net?

Sure, I can work on it today. Thanks!

Quoted 34 lines

Also, doesn't ip6erspan suffer from the same problem? Please try to reproduce and fix.

[1] https://lore.kernel.org/netdev/[email protected]/

Quoted 28 lines
Reported-by [email protected]
Fixes 84e54fe0a5ea ("gre: introduce native tunnel support for ERSPAN")

---
v2:
- change subject prefix to [PATCH net]

 net/ipv4/ip_gre.c | 2 ++
 1 file changed, 2 insertions(+)
net/ipv4/ip_gre.c +2 -1
index 3efdfb4ffa21..9fbff16cda1d 100644
@@ -1363,6 +1363,8 @@ static int erspan_tunnel_init(struct net_device *dev)
      dev->features           |= GRE_FEATURES;
      dev->hw_features        |= GRE_FEATURES;
      dev->priv_flags         |= IFF_LIVE_ADDR_CHANGE;
+     /* Skip TX lock: xmit re-enters stack, risking ABBA with underlay */
+     dev->lltx = true;
      netif_keep_dst(dev);
 
      return ip_tunnel_init(dev);
--

2.43.0

author
#5 lore raw
In reply to Ido Schimmel
Quoted 20 lines · Ido Schimmel

CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 5 lines · Yun Zhou

erspan_xmit() re-enters the network stack via ip_tunnel_xmit(), causing nested acquisition of _xmit_lock on the underlay device while already holding the ERSPAN device's _xmit_lock. Both are ARPHRD_ETHER and share the same lockdep class, creating an ABBA deadlock:

Quoted 7 lines
   sch_direct_xmit [lock erspan] -> erspan_xmit -> ip_tunnel_xmit ->
   ip_output -> __dev_queue_xmit -> sch_direct_xmit [lock underlay]

Set dev->lltx = true so HARD_TX_LOCK() skips the spinlock for ERSPAN. This is safe as erspan_xmit() has no shared mutable state: o_seqno is atomic, stats use atomic_long_inc, and dst_cache is per-CPU. GRETAP, the sibling device with identical xmit structure, already sets lltx.

erspan_xmit() (unlike gre_tap_xmit()) is performing non-atomic __clear_bit() on shared tunnel flags and KCSAN will probably flag it.

Quoted 9 lines

Eric had a patch [1] that changes erspan_xmit() to use a private copy of these flags. I think it's better to wait for Eric's patch to be merged before setting lltx.

Eric, can you please submit v2 of your patch to net?

Also, doesn't ip6erspan suffer from the same problem? Please try to reproduce and fix.

The following command sequence can reproduce the problem:

ip link set lo up

ip addr add fd00:a::1/128 dev lo
ip addr add fd00:b::1/128 dev lo

ip link add ip6erspan_dev type ip6erspan \
local fd00:a::1 remote fd00:a::2 \
seq key 1 erspan_ver 1 erspan 1
ip link set ip6erspan_dev up

ip link add ip6gretap_dev type ip6gretap \
    local fd00:b::1 remote fd00:b::2 seq

ip link set ip6gretap_dev up

ip -6 route add fd00:a::2/128 dev ip6gretap_dev
ip -6 route add fd00:b::2/128 dev ip6erspan_dev

ip -6 neigh add fd00:a::2 lladdr 00:11:22:33:44:55 dev ip6gretap_dev ip -6 neigh add fd00:b::2 lladdr 00:11:22:33:44:66 dev ip6erspan_dev