diff mbox series

[net-next] net: warn if NAPI instance wasn't shut down

Message ID 20250203215816.1294081-1-kuba@kernel.org (mailing list archive)
State Accepted
Commit 9dd05df8403bda5b68178b795c554b3940628bb6
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: warn if NAPI instance wasn't shut down | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 2 this patch: 2
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 5 this patch: 5
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 79 this patch: 79
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-02-04--00-00 (tests: 886)

Commit Message

Jakub Kicinski Feb. 3, 2025, 9:58 p.m. UTC
Drivers should always disable a NAPI instance before removing it.
If they don't the instance may be queued for polling.
Since commit 86e25f40aa1e ("net: napi: Add napi_config")
we also remove the NAPI from the busy polling hash table
in napi_disable(), so not disabling would leave a stale
entry there.

Use of busy polling is relatively uncommon so bugs may be lurking
in the drivers. Add an explicit warning.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 net/core/dev.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Joe Damato Feb. 4, 2025, 1:48 a.m. UTC | #1
On Mon, Feb 03, 2025 at 01:58:16PM -0800, Jakub Kicinski wrote:
> Drivers should always disable a NAPI instance before removing it.
> If they don't the instance may be queued for polling.
> Since commit 86e25f40aa1e ("net: napi: Add napi_config")
> we also remove the NAPI from the busy polling hash table
> in napi_disable(), so not disabling would leave a stale
> entry there.
> 
> Use of busy polling is relatively uncommon so bugs may be lurking
> in the drivers. Add an explicit warning.
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
>  net/core/dev.c | 3 +++
>  1 file changed, 3 insertions(+)
> 

Let's find out how many bugs are lurking:

Reviewed-by: Joe Damato <jdamato@fastly.com>
Eric Dumazet Feb. 4, 2025, 5:24 a.m. UTC | #2
On Mon, Feb 3, 2025 at 10:58 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> Drivers should always disable a NAPI instance before removing it.
> If they don't the instance may be queued for polling.
> Since commit 86e25f40aa1e ("net: napi: Add napi_config")
> we also remove the NAPI from the busy polling hash table
> in napi_disable(), so not disabling would leave a stale
> entry there.
>
> Use of busy polling is relatively uncommon so bugs may be lurking
> in the drivers. Add an explicit warning.
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
>  net/core/dev.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/net/core/dev.c b/net/core/dev.c
> index c0021cbd28fc..2b141f20b13b 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -7071,6 +7071,9 @@ void __netif_napi_del_locked(struct napi_struct *napi)
>         if (!test_and_clear_bit(NAPI_STATE_LISTED, &napi->state))
>                 return;
>
> +       /* Make sure NAPI is disabled (or was never enabled). */
> +       WARN_ON(!test_bit(NAPI_STATE_SCHED, &napi->state));
> +
>         if (napi->config) {
>                 napi->index = -1;
>                 napi->config = NULL;
> --
> 2.48.1
>

This makes sense. Although a WARN_ON_ONCE() might avoid some noise.

Reviewed-by: Eric Dumazet <edumazet@google.com>
patchwork-bot+netdevbpf@kernel.org Feb. 5, 2025, 2:20 a.m. UTC | #3
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon,  3 Feb 2025 13:58:16 -0800 you wrote:
> Drivers should always disable a NAPI instance before removing it.
> If they don't the instance may be queued for polling.
> Since commit 86e25f40aa1e ("net: napi: Add napi_config")
> we also remove the NAPI from the busy polling hash table
> in napi_disable(), so not disabling would leave a stale
> entry there.
> 
> [...]

Here is the summary with links:
  - [net-next] net: warn if NAPI instance wasn't shut down
    https://git.kernel.org/netdev/net-next/c/9dd05df8403b

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/core/dev.c b/net/core/dev.c
index c0021cbd28fc..2b141f20b13b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -7071,6 +7071,9 @@  void __netif_napi_del_locked(struct napi_struct *napi)
 	if (!test_and_clear_bit(NAPI_STATE_LISTED, &napi->state))
 		return;
 
+	/* Make sure NAPI is disabled (or was never enabled). */
+	WARN_ON(!test_bit(NAPI_STATE_SCHED, &napi->state));
+
 	if (napi->config) {
 		napi->index = -1;
 		napi->config = NULL;