netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	andrew+netdev@lunn.ch, horms@kernel.org, almasrymina@google.com,
	Jakub Kicinski <kuba@kernel.org>,
	hawk@kernel.org, ilias.apalodimas@linaro.org, jdamato@fastly.com
Subject: [PATCH net-next v2 3/4] net: page_pool: avoid false positive warning if NAPI was never added
Date: Thu,  6 Feb 2025 14:56:37 -0800	[thread overview]
Message-ID: <20250206225638.1387810-4-kuba@kernel.org> (raw)
In-Reply-To: <20250206225638.1387810-1-kuba@kernel.org>

We expect NAPI to be in disabled state when page pool is torn down.
But it is also legal if the NAPI is completely uninitialized.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v2: new patch
v1: https://lore.kernel.org/20250205190131.564456-1-kuba@kernel.org

CC: hawk@kernel.org
CC: ilias.apalodimas@linaro.org
CC: jdamato@fastly.com
---
 net/core/dev.h       | 12 ++++++++++++
 net/core/page_pool.c |  7 ++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/net/core/dev.h b/net/core/dev.h
index a5b166bbd169..caa13e431a6b 100644
--- a/net/core/dev.h
+++ b/net/core/dev.h
@@ -299,6 +299,18 @@ void xdp_do_check_flushed(struct napi_struct *napi);
 static inline void xdp_do_check_flushed(struct napi_struct *napi) { }
 #endif
 
+/* Best effort check that NAPI is not idle (can't be scheduled to run) */
+static inline void napi_assert_will_not_race(const struct napi_struct *napi)
+{
+	/* uninitialized instance, can't race */
+	if (!napi->poll_list.next)
+		return;
+
+	/* SCHED bit is set on disabled instances */
+	WARN_ON(!test_bit(NAPI_STATE_SCHED, &napi->state));
+	WARN_ON(READ_ONCE(napi->list_owner) != -1);
+}
+
 void kick_defer_list_purge(struct softnet_data *sd, unsigned int cpu);
 
 #define XMIT_RECURSION_LIMIT	8
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index f5e908c9e7ad..b940c40ea2f2 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -25,6 +25,7 @@
 
 #include <trace/events/page_pool.h>
 
+#include "dev.h"
 #include "mp_dmabuf_devmem.h"
 #include "netmem_priv.h"
 #include "page_pool_priv.h"
@@ -1140,11 +1141,7 @@ void page_pool_disable_direct_recycling(struct page_pool *pool)
 	if (!pool->p.napi)
 		return;
 
-	/* To avoid races with recycling and additional barriers make sure
-	 * pool and NAPI are unlinked when NAPI is disabled.
-	 */
-	WARN_ON(!test_bit(NAPI_STATE_SCHED, &pool->p.napi->state));
-	WARN_ON(READ_ONCE(pool->p.napi->list_owner) != -1);
+	napi_assert_will_not_race(pool->p.napi);
 
 	mutex_lock(&page_pools_lock);
 	WRITE_ONCE(pool->p.napi, NULL);
-- 
2.48.1


  parent reply	other threads:[~2025-02-06 22:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-06 22:56 [PATCH net-next v2 0/4] net: improve core queue API handling while device is down Jakub Kicinski
2025-02-06 22:56 ` [PATCH net-next v2 1/4] net: refactor netdev_rx_queue_restart() to use local qops Jakub Kicinski
2025-02-06 23:05   ` Mina Almasry
2025-02-06 23:06     ` Jakub Kicinski
2025-02-06 22:56 ` [PATCH net-next v2 2/4] net: devmem: don't call queue stop / start when the interface is down Jakub Kicinski
2025-02-06 23:12   ` Mina Almasry
2025-02-06 22:56 ` Jakub Kicinski [this message]
2025-02-07  0:32   ` [PATCH net-next v2 3/4] net: page_pool: avoid false positive warning if NAPI was never added Mina Almasry
2025-02-06 22:56 ` [PATCH net-next v2 4/4] netdevsim: allow normal queue reset while down Jakub Kicinski
2025-02-07  0:55   ` Mina Almasry
2025-02-08  4:20 ` [PATCH net-next v2 0/4] net: improve core queue API handling while device is down patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250206225638.1387810-4-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=almasrymina@google.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jdamato@fastly.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).