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