604-v5.12-net-fix-hangup-on-napi_disable-for-threaded-napi.patch 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. From: Paolo Abeni <[email protected]>
  2. Date: Fri, 9 Apr 2021 17:24:17 +0200
  3. Subject: [PATCH] net: fix hangup on napi_disable for threaded napi
  4. napi_disable() is subject to an hangup, when the threaded
  5. mode is enabled and the napi is under heavy traffic.
  6. If the relevant napi has been scheduled and the napi_disable()
  7. kicks in before the next napi_threaded_wait() completes - so
  8. that the latter quits due to the napi_disable_pending() condition,
  9. the existing code leaves the NAPI_STATE_SCHED bit set and the
  10. napi_disable() loop waiting for such bit will hang.
  11. This patch addresses the issue by dropping the NAPI_STATE_DISABLE
  12. bit test in napi_thread_wait(). The later napi_threaded_poll()
  13. iteration will take care of clearing the NAPI_STATE_SCHED.
  14. This also addresses a related problem reported by Jakub:
  15. before this patch a napi_disable()/napi_enable() pair killed
  16. the napi thread, effectively disabling the threaded mode.
  17. On the patched kernel napi_disable() simply stops scheduling
  18. the relevant thread.
  19. v1 -> v2:
  20. - let the main napi_thread_poll() loop clear the SCHED bit
  21. Reported-by: Jakub Kicinski <[email protected]>
  22. Fixes: 29863d41bb6e ("net: implement threaded-able napi poll loop support")
  23. Signed-off-by: Paolo Abeni <[email protected]>
  24. Reviewed-by: Eric Dumazet <[email protected]>
  25. Link: https://lore.kernel.org/r/883923fa22745a9589e8610962b7dc59df09fb1f.1617981844.git.pabeni@redhat.com
  26. Signed-off-by: Jakub Kicinski <[email protected]>
  27. ---
  28. --- a/net/core/dev.c
  29. +++ b/net/core/dev.c
  30. @@ -7007,7 +7007,7 @@ static int napi_thread_wait(struct napi_
  31. set_current_state(TASK_INTERRUPTIBLE);
  32. - while (!kthread_should_stop() && !napi_disable_pending(napi)) {
  33. + while (!kthread_should_stop()) {
  34. /* Testing SCHED_THREADED bit here to make sure the current
  35. * kthread owns this napi and could poll on this napi.
  36. * Testing SCHED bit is not enough because SCHED bit might be
  37. @@ -7025,6 +7025,7 @@ static int napi_thread_wait(struct napi_
  38. set_current_state(TASK_INTERRUPTIBLE);
  39. }
  40. __set_current_state(TASK_RUNNING);
  41. +
  42. return -1;
  43. }