netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2] net: fix hangup on napi_disable for threaded napi
@ 2021-04-09 15:24 Paolo Abeni
  2021-04-09 15:28 ` Eric Dumazet
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Paolo Abeni @ 2021-04-09 15:24 UTC (permalink / raw)
  To: netdev; +Cc: David S. Miller, Jakub Kicinski, Eric Dumazet, Wei Wang

napi_disable() is subject to an hangup, when the threaded
mode is enabled and the napi is under heavy traffic.

If the relevant napi has been scheduled and the napi_disable()
kicks in before the next napi_threaded_wait() completes - so
that the latter quits due to the napi_disable_pending() condition,
the existing code leaves the NAPI_STATE_SCHED bit set and the
napi_disable() loop waiting for such bit will hang.

This patch addresses the issue by dropping the NAPI_STATE_DISABLE
bit test in napi_thread_wait(). The later napi_threaded_poll()
iteration will take care of clearing the NAPI_STATE_SCHED.

This also addresses a related problem reported by Jakub:
before this patch a napi_disable()/napi_enable() pair killed
the napi thread, effectively disabling the threaded mode.
On the patched kernel napi_disable() simply stops scheduling
the relevant thread.

v1 -> v2:
  - let the main napi_thread_poll() loop clear the SCHED bit

Reported-by: Jakub Kicinski <kuba@kernel.org>
Fixes: 29863d41bb6e ("net: implement threaded-able napi poll loop support")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
 net/core/dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 0f72ff5d34ba..af8c1ea040b9 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -6992,7 +6992,7 @@ static int napi_thread_wait(struct napi_struct *napi)
 
 	set_current_state(TASK_INTERRUPTIBLE);
 
-	while (!kthread_should_stop() && !napi_disable_pending(napi)) {
+	while (!kthread_should_stop()) {
 		/* Testing SCHED_THREADED bit here to make sure the current
 		 * kthread owns this napi and could poll on this napi.
 		 * Testing SCHED bit is not enough because SCHED bit might be
@@ -7010,6 +7010,7 @@ static int napi_thread_wait(struct napi_struct *napi)
 		set_current_state(TASK_INTERRUPTIBLE);
 	}
 	__set_current_state(TASK_RUNNING);
+
 	return -1;
 }
 
-- 
2.26.2


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

* Re: [PATCH net v2] net: fix hangup on napi_disable for threaded napi
  2021-04-09 15:24 [PATCH net v2] net: fix hangup on napi_disable for threaded napi Paolo Abeni
@ 2021-04-09 15:28 ` Eric Dumazet
  2021-04-09 15:35 ` Heiner Kallweit
  2021-04-09 20:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: Eric Dumazet @ 2021-04-09 15:28 UTC (permalink / raw)
  To: Paolo Abeni; +Cc: netdev, David S. Miller, Jakub Kicinski, Wei Wang

On Fri, Apr 9, 2021 at 5:25 PM Paolo Abeni <pabeni@redhat.com> wrote:
>
> napi_disable() is subject to an hangup, when the threaded
> mode is enabled and the napi is under heavy traffic.
>
> If the relevant napi has been scheduled and the napi_disable()
> kicks in before the next napi_threaded_wait() completes - so
> that the latter quits due to the napi_disable_pending() condition,
> the existing code leaves the NAPI_STATE_SCHED bit set and the
> napi_disable() loop waiting for such bit will hang.
>
> This patch addresses the issue by dropping the NAPI_STATE_DISABLE
> bit test in napi_thread_wait(). The later napi_threaded_poll()
> iteration will take care of clearing the NAPI_STATE_SCHED.
>
> This also addresses a related problem reported by Jakub:
> before this patch a napi_disable()/napi_enable() pair killed
> the napi thread, effectively disabling the threaded mode.
> On the patched kernel napi_disable() simply stops scheduling
> the relevant thread.
>
> v1 -> v2:
>   - let the main napi_thread_poll() loop clear the SCHED bit
>
> Reported-by: Jakub Kicinski <kuba@kernel.org>
> Fixes: 29863d41bb6e ("net: implement threaded-able napi poll loop support")
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> ---

Reviewed-by: Eric Dumazet <edumazet@google.com>

Thanks !

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

* Re: [PATCH net v2] net: fix hangup on napi_disable for threaded napi
  2021-04-09 15:24 [PATCH net v2] net: fix hangup on napi_disable for threaded napi Paolo Abeni
  2021-04-09 15:28 ` Eric Dumazet
@ 2021-04-09 15:35 ` Heiner Kallweit
  2021-04-09 15:52   ` Eric Dumazet
  2021-04-09 20:00 ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 5+ messages in thread
From: Heiner Kallweit @ 2021-04-09 15:35 UTC (permalink / raw)
  To: Paolo Abeni, netdev
  Cc: David S. Miller, Jakub Kicinski, Eric Dumazet, Wei Wang

On 09.04.2021 17:24, Paolo Abeni wrote:
> napi_disable() is subject to an hangup, when the threaded
> mode is enabled and the napi is under heavy traffic.
> 
> If the relevant napi has been scheduled and the napi_disable()
> kicks in before the next napi_threaded_wait() completes - so
> that the latter quits due to the napi_disable_pending() condition,
> the existing code leaves the NAPI_STATE_SCHED bit set and the
> napi_disable() loop waiting for such bit will hang.
> 
> This patch addresses the issue by dropping the NAPI_STATE_DISABLE
> bit test in napi_thread_wait(). The later napi_threaded_poll()
> iteration will take care of clearing the NAPI_STATE_SCHED.
> 
> This also addresses a related problem reported by Jakub:
> before this patch a napi_disable()/napi_enable() pair killed
> the napi thread, effectively disabling the threaded mode.
> On the patched kernel napi_disable() simply stops scheduling
> the relevant thread.
> 
> v1 -> v2:
>   - let the main napi_thread_poll() loop clear the SCHED bit
> 
> Reported-by: Jakub Kicinski <kuba@kernel.org>
> Fixes: 29863d41bb6e ("net: implement threaded-able napi poll loop support")
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> ---
>  net/core/dev.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 0f72ff5d34ba..af8c1ea040b9 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -6992,7 +6992,7 @@ static int napi_thread_wait(struct napi_struct *napi)
>  
>  	set_current_state(TASK_INTERRUPTIBLE);
>  
> -	while (!kthread_should_stop() && !napi_disable_pending(napi)) {
> +	while (!kthread_should_stop()) {
>  		/* Testing SCHED_THREADED bit here to make sure the current
>  		 * kthread owns this napi and could poll on this napi.
>  		 * Testing SCHED bit is not enough because SCHED bit might be
> @@ -7010,6 +7010,7 @@ static int napi_thread_wait(struct napi_struct *napi)
>  		set_current_state(TASK_INTERRUPTIBLE);
>  	}
>  	__set_current_state(TASK_RUNNING);
> +
>  	return -1;
>  }
>  
> 

Unrelated to the actual issue:
I wonder why -1 is returned, that's unusual in kernel. The return value
is used as bool, so why not return a bool?

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

* Re: [PATCH net v2] net: fix hangup on napi_disable for threaded napi
  2021-04-09 15:35 ` Heiner Kallweit
@ 2021-04-09 15:52   ` Eric Dumazet
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Dumazet @ 2021-04-09 15:52 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: Paolo Abeni, netdev, David S. Miller, Jakub Kicinski, Wei Wang

On Fri, Apr 9, 2021 at 5:35 PM Heiner Kallweit <hkallweit1@gmail.com> wrote:
>

>
> Unrelated to the actual issue:
> I wonder why -1 is returned, that's unusual in kernel. The return value
> is used as bool, so why not return a bool?

This is a leftover of a prior implementation that returned 3 values.

No bug here really, this is a matter of taste I suppose.

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

* Re: [PATCH net v2] net: fix hangup on napi_disable for threaded napi
  2021-04-09 15:24 [PATCH net v2] net: fix hangup on napi_disable for threaded napi Paolo Abeni
  2021-04-09 15:28 ` Eric Dumazet
  2021-04-09 15:35 ` Heiner Kallweit
@ 2021-04-09 20:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-04-09 20:00 UTC (permalink / raw)
  To: Paolo Abeni; +Cc: netdev, davem, kuba, edumazet, weiwan

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Fri,  9 Apr 2021 17:24:17 +0200 you wrote:
> napi_disable() is subject to an hangup, when the threaded
> mode is enabled and the napi is under heavy traffic.
> 
> If the relevant napi has been scheduled and the napi_disable()
> kicks in before the next napi_threaded_wait() completes - so
> that the latter quits due to the napi_disable_pending() condition,
> the existing code leaves the NAPI_STATE_SCHED bit set and the
> napi_disable() loop waiting for such bit will hang.
> 
> [...]

Here is the summary with links:
  - [net,v2] net: fix hangup on napi_disable for threaded napi
    https://git.kernel.org/netdev/net/c/27f0ad71699d

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] 5+ messages in thread

end of thread, other threads:[~2021-04-09 20:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-09 15:24 [PATCH net v2] net: fix hangup on napi_disable for threaded napi Paolo Abeni
2021-04-09 15:28 ` Eric Dumazet
2021-04-09 15:35 ` Heiner Kallweit
2021-04-09 15:52   ` Eric Dumazet
2021-04-09 20:00 ` 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;
as well as URLs for NNTP newsgroup(s).