Skip to contentSkip to conversation

net: warn if NAPI instance wasn't shut down

PATCH Applied Jakub Kicinski 4 participants 4 messages Feb 3, 2025 – Feb 5, 2025

Subsystems (2)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 net: warn if NAPI instance wasn't shut down

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.

---
 net/core/dev.c | 3 +++
 1 file changed, 3 insertions(+)
net/core/dev.c +3 -0
index c0021cbd28fc..2b141f20b13b 100644
@@ -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;
Signature · 1 line
2.48.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jakub Kicinski

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.

Quoted 8 lines

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

---
 net/core/dev.c | 3 +++
 1 file changed, 3 insertions(+)

Let's find out how many bugs are lurking:

Reviewed-by on v1 1/1
#2 lore raw
In reply to Jakub Kicinski
Quoted 31 lines · Jakub Kicinski

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.

---
 net/core/dev.c | 3 +++
 1 file changed, 3 insertions(+)
net/core/dev.c +3 -1
index c0021cbd28fc..2b141f20b13b 100644
@@ -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;
--
Quoted 2 lines

2.48.1

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

#3 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · 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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html