You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "Sarthak-Pandey (via GitHub)" <gi...@apache.org> on 2026/10/12 12:45:43 UTC
[PR] drivers/net: fix ABBA deadlock in netdev_upper_txavail under forwarding [nuttx]
Sarthak-Pandey opened a new pull request, #20622:
URL: https://github.com/apache/nuttx/pull/20622
## Summary
Fixes cross-deadlock (ABBA) between network devices under full-duplex forwarding / NAT (#20619).
### Problem
In full-duplex forwarding / NAT scenarios between two network devices (such as SoftAP + Station mode with `wlan0` and `wlan1`), both netdev RX worker threads deadlock:
1. `netdev-wlan0` holds `netdev_lock(wlan0)` during packet reception and forward processing. When forwarding to `wlan1`, it invokes `netdev_txnotify_dev(wlan1)` -> `wlan1->d_txavail()`. `netdev_upper_txavail()` was unconditionally calling `netdev_upper_txavail_work(upper)` synchronously, attempting to acquire `netdev_lock(wlan1)`.
2. Simultaneously, `netdev-wlan1` holds `netdev_lock(wlan1)` and forwards a packet to `wlan0`, attempting to synchronously acquire `netdev_lock(wlan0)`.
3. This creates a classic ABBA deadlock where both worker threads wait on each other's device lock permanently.
### Solution
In `netdev_upper_txavail()`, inspect `upper->lower->rxtype`:
- If `rxtype == NETDEV_RX_DIRECT`, invoke `netdev_upper_txavail_work(upper)` directly.
- Otherwise (`NETDEV_RX_THREAD`, `NETDEV_RX_THREAD_RSS`, `NETDEV_RX_WORK`), delegate via `netdev_upper_queue_work(dev)`. This asynchronously notifies the target device worker via semaphore post (`nxsem_post`), avoiding synchronous cross-device mutex contention.
Fixes: #20619
## Impact
- **Users**: Resolves network freeze/wedge under bi-directional / full-duplex traffic through NAT / IP forwarding across two network interfaces.
- **Compatibility**: No API change or breaking change; aligns with the pattern used in `netdev_lower_txdone()`.
- **Security / Safety**: Eliminates cross-thread deadlock vulnerability.
## Testing
- Build host: Ubuntu / Windows (riscv32-esp-elf-gcc / CMake)
- Target: ESP32-C3 SuperMini (esp32c3-supermini:nsh) with `CONFIG_NET_IPFORWARD=y`, `CONFIG_NET_NAT=y`, `ESPRESSIF_WIFI_STATION_SOFTAP=y`.
- Verified code structure and coding style adherence with NuttX standards.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] drivers/net: fix ABBA deadlock in netdev_upper_txavail under forwarding [nuttx]
Posted by "Sarthak-Pandey (via GitHub)" <gi...@apache.org>.
Sarthak-Pandey commented on code in PR #20622:
URL: https://github.com/apache/nuttx/pull/20622#discussion_r4258328143
##########
drivers/net/netdev_upperhalf.c:
##########
@@ -882,7 +883,17 @@ static inline void netdev_upper_queue_work(FAR struct net_driver_s *dev)
static int netdev_upper_txavail(FAR struct net_driver_s *dev)
{
- netdev_upper_txavail_work(dev->d_private);
+ FAR struct netdev_upperhalf_s *upper = dev->d_private;
+
+ if (upper->lower->rxtype == NETDEV_RX_DIRECT)
+ {
+ netdev_upper_txavail_work(upper);
+ }
+ else
+ {
+ netdev_upper_queue_work(dev);
+ }
+
Review Comment:
"Thanks @raiden00pl! That makes complete sense — using nxrmutex_trylock ensures we transmit immediately when the lock is free or held by the current thread to prevent txq overflow, while still avoiding the ABBA deadlock when the peer thread holds the lock. Applied the suggested change!"
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] drivers/net: fix ABBA deadlock in netdev_upper_txavail under forwarding [nuttx]
Posted by "Sarthak-Pandey (via GitHub)" <gi...@apache.org>.
Sarthak-Pandey commented on PR #20622:
URL: https://github.com/apache/nuttx/pull/20622#issuecomment-6175725291
Yeah I am working on it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] drivers/net: fix ABBA deadlock in netdev_upper_txavail under forwarding [nuttx]
Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis merged PR #20622:
URL: https://github.com/apache/nuttx/pull/20622
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] drivers/net: fix ABBA deadlock in netdev_upper_txavail under forwarding [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #20622:
URL: https://github.com/apache/nuttx/pull/20622#discussion_r4260587419
##########
drivers/net/netdev_upperhalf.c:
##########
@@ -889,8 +889,19 @@ static int netdev_upper_txavail(FAR struct net_driver_s *dev)
{
netdev_upper_txavail_work(upper);
}
+ else if (nxrmutex_trylock(&dev->d_lock) >= 0)
Review Comment:
merge to the first patch
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] drivers/net: fix ABBA deadlock in netdev_upper_txavail under forwarding [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #20622:
URL: https://github.com/apache/nuttx/pull/20622#issuecomment-6175675168
@Sarthak-Pandey please fix the conflict.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] drivers/net: fix ABBA deadlock in netdev_upper_txavail under forwarding [nuttx]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #20622:
URL: https://github.com/apache/nuttx/pull/20622#issuecomment-6130795205
<!-- membrowse-pr-comment -->
## <img src="https://membrowse.com/membrowse-logo.svg" height="24" align="top"> MemBrowse Memory Report
*No memory changes detected for:*
- [arduino-mega2560](https://membrowse.com/public/apache/nuttx/target/arduino-mega2560/compare?head=97f13ad4b6ffeff90932c74c7ccb99d9c2b4fc1a&base=1381c1b26877efa181efc99b7322ddfee4096e79)
- [esp32-devkitc](https://membrowse.com/public/apache/nuttx/target/esp32-devkitc/compare?head=97f13ad4b6ffeff90932c74c7ccb99d9c2b4fc1a&base=1381c1b26877efa181efc99b7322ddfee4096e79)
- [hifive1-revb](https://membrowse.com/public/apache/nuttx/target/hifive1-revb/compare?head=97f13ad4b6ffeff90932c74c7ccb99d9c2b4fc1a&base=1381c1b26877efa181efc99b7322ddfee4096e79)
- [mirtoo](https://membrowse.com/public/apache/nuttx/target/mirtoo/compare?head=97f13ad4b6ffeff90932c74c7ccb99d9c2b4fc1a&base=1381c1b26877efa181efc99b7322ddfee4096e79)
- [qemu-armv8a](https://membrowse.com/public/apache/nuttx/target/qemu-armv8a/compare?head=97f13ad4b6ffeff90932c74c7ccb99d9c2b4fc1a&base=1381c1b26877efa181efc99b7322ddfee4096e79)
- [qemu-intel64](https://membrowse.com/public/apache/nuttx/target/qemu-intel64/compare?head=97f13ad4b6ffeff90932c74c7ccb99d9c2b4fc1a&base=1381c1b26877efa181efc99b7322ddfee4096e79)
- [rx65n-rsk2mb](https://membrowse.com/public/apache/nuttx/target/rx65n-rsk2mb/compare?head=97f13ad4b6ffeff90932c74c7ccb99d9c2b4fc1a&base=1381c1b26877efa181efc99b7322ddfee4096e79)
- [s698pm-dkit](https://membrowse.com/public/apache/nuttx/target/s698pm-dkit/compare?head=97f13ad4b6ffeff90932c74c7ccb99d9c2b4fc1a&base=1381c1b26877efa181efc99b7322ddfee4096e79)
- [stm32-nucleo-f103rb](https://membrowse.com/public/apache/nuttx/target/stm32-nucleo-f103rb/compare?head=97f13ad4b6ffeff90932c74c7ccb99d9c2b4fc1a&base=1381c1b26877efa181efc99b7322ddfee4096e79)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] drivers/net: fix ABBA deadlock in netdev_upper_txavail under forwarding [nuttx]
Posted by "raiden00pl (via GitHub)" <gi...@apache.org>.
raiden00pl commented on code in PR #20622:
URL: https://github.com/apache/nuttx/pull/20622#discussion_r4258070350
##########
drivers/net/netdev_upperhalf.c:
##########
@@ -882,7 +883,17 @@ static inline void netdev_upper_queue_work(FAR struct net_driver_s *dev)
static int netdev_upper_txavail(FAR struct net_driver_s *dev)
{
- netdev_upper_txavail_work(dev->d_private);
+ FAR struct netdev_upperhalf_s *upper = dev->d_private;
+
+ if (upper->lower->rxtype == NETDEV_RX_DIRECT)
+ {
+ netdev_upper_txavail_work(upper);
+ }
+ else
+ {
+ netdev_upper_queue_work(dev);
+ }
+
Review Comment:
```suggestion
if (upper->lower->rxtype == NETDEV_RX_DIRECT)
{
netdev_upper_txavail_work(upper);
}
else if (nxrmutex_trylock(&dev->d_lock) >= 0)
{
/* Lock free or held by us: transmit now so txq can't overflow.
* Drop the extra reference of the recursive lock.
*/
netdev_upper_txavail_work(upper);
nxrmutex_unlock(&dev->d_lock);
}
else
{
/* Locked by another thread: don't wait (ABBA when forwarding) */
netdev_upper_queue_work(dev);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] drivers/net: fix ABBA deadlock in netdev_upper_txavail under forwarding [nuttx]
Posted by "Sarthak-Pandey (via GitHub)" <gi...@apache.org>.
Sarthak-Pandey commented on PR #20622:
URL: https://github.com/apache/nuttx/pull/20622#issuecomment-6139522317
Thank you for the review and approval! All CI checks are passing, but the PR is still blocked by the requirement for at least two approving reviews from reviewers with write access.
Could another maintainer please review this PR when convenient? Also, please let me know if there are any additional requirements or concerns preventing it from being merged.
Thank you for your time and consideration!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org