From: Joe Damato <jdamato@fastly.com>
To: netdev@vger.kernel.org
Cc: gerhard@engleder-embedded.com, jasowang@redhat.com,
leiyang@redhat.com, mkarsten@uwaterloo.ca,
Jakub Kicinski <kuba@kernel.org>, Joe Damato <jdamato@fastly.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Andrew Lunn <andrew+netdev@lunn.ch>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Lorenzo Bianconi <lorenzo@kernel.org>,
Alexander Lobakin <aleksander.lobakin@intel.com>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH net-next v2 1/4] net: protect queue -> napi linking with netdev_lock()
Date: Thu, 16 Jan 2025 05:52:56 +0000 [thread overview]
Message-ID: <20250116055302.14308-2-jdamato@fastly.com> (raw)
In-Reply-To: <20250116055302.14308-1-jdamato@fastly.com>
From: Jakub Kicinski <kuba@kernel.org>
netdev netlink is the only reader of netdev_{,rx_}queue->napi,
and it already holds netdev->lock. Switch protection of the
writes to netdev->lock as well.
Add netif_queue_set_napi_locked() for API completeness,
but the expectation is that most current drivers won't have
to worry about locking any more. Today they jump thru hoops
to take rtnl_lock.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Joe Damato <jdamato@fastly.com>
---
v2:
- Added in v2 from Jakub.
include/linux/netdevice.h | 9 +++++++--
include/net/netdev_rx_queue.h | 2 +-
net/core/dev.c | 16 +++++++++++++---
3 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 8308d9c75918..c7201642e9fb 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -690,7 +690,7 @@ struct netdev_queue {
* slow- / control-path part
*/
/* NAPI instance for the queue
- * Readers and writers must hold RTNL
+ * Readers and writers must hold netdev->lock
*/
struct napi_struct *napi;
@@ -2458,7 +2458,8 @@ struct net_device {
* Partially protects (writers must hold both @lock and rtnl_lock):
* @up
*
- * Also protects some fields in struct napi_struct.
+ * Also protects some fields in:
+ * struct napi_struct, struct netdev_queue, struct netdev_rx_queue
*
* Ordering: take after rtnl_lock.
*/
@@ -2685,6 +2686,10 @@ static inline void *netdev_priv(const struct net_device *dev)
void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index,
enum netdev_queue_type type,
struct napi_struct *napi);
+void netif_queue_set_napi_locked(struct net_device *dev,
+ unsigned int queue_index,
+ enum netdev_queue_type type,
+ struct napi_struct *napi);
static inline void netdev_lock(struct net_device *dev)
{
diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h
index 596836abf7bf..9fcac0b43b71 100644
--- a/include/net/netdev_rx_queue.h
+++ b/include/net/netdev_rx_queue.h
@@ -23,7 +23,7 @@ struct netdev_rx_queue {
struct xsk_buff_pool *pool;
#endif
/* NAPI instance for the queue
- * Readers and writers must hold RTNL
+ * Readers and writers must hold netdev->lock
*/
struct napi_struct *napi;
struct pp_memory_provider_params mp_params;
diff --git a/net/core/dev.c b/net/core/dev.c
index 782ae3ff3f8d..528478cd8615 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -6851,14 +6851,24 @@ EXPORT_SYMBOL(dev_set_threaded);
*/
void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index,
enum netdev_queue_type type, struct napi_struct *napi)
+{
+ netdev_lock(dev);
+ netif_queue_set_napi_locked(dev, queue_index, type, napi);
+ netdev_unlock(dev);
+}
+EXPORT_SYMBOL(netif_queue_set_napi);
+
+void netif_queue_set_napi_locked(struct net_device *dev,
+ unsigned int queue_index,
+ enum netdev_queue_type type,
+ struct napi_struct *napi)
{
struct netdev_rx_queue *rxq;
struct netdev_queue *txq;
if (WARN_ON_ONCE(napi && !napi->dev))
return;
- if (dev->reg_state >= NETREG_REGISTERED)
- ASSERT_RTNL();
+ netdev_assert_locked_or_invisible(dev);
switch (type) {
case NETDEV_QUEUE_TYPE_RX:
@@ -6873,7 +6883,7 @@ void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index,
return;
}
}
-EXPORT_SYMBOL(netif_queue_set_napi);
+EXPORT_SYMBOL(netif_queue_set_napi_locked);
static void napi_restore_config(struct napi_struct *n)
{
--
2.25.1
next prev parent reply other threads:[~2025-01-16 5:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-16 5:52 [PATCH net-next v2 0/4] virtio_net: Link queues to NAPIs Joe Damato
2025-01-16 5:52 ` Joe Damato [this message]
2025-01-16 5:52 ` [PATCH net-next v2 2/4] virtio_net: Prepare for NAPI to queue mapping Joe Damato
2025-01-16 5:52 ` [PATCH net-next v2 3/4] virtio_net: Map NAPIs to queues Joe Damato
2025-01-16 7:53 ` Xuan Zhuo
2025-01-16 16:09 ` Joe Damato
2025-01-16 20:28 ` Gerhard Engleder
2025-01-21 17:57 ` Joe Damato
2025-01-20 1:58 ` Jason Wang
2025-01-21 17:55 ` Joe Damato
2025-01-16 5:52 ` [PATCH net-next v2 4/4] virtio_net: Use persistent NAPI config Joe Damato
2025-01-16 7:56 ` Xuan Zhuo
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=20250116055302.14308-2-jdamato@fastly.com \
--to=jdamato@fastly.com \
--cc=aleksander.lobakin@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=bigeasy@linutronix.de \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gerhard@engleder-embedded.com \
--cc=horms@kernel.org \
--cc=jasowang@redhat.com \
--cc=kuba@kernel.org \
--cc=leiyang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=mkarsten@uwaterloo.ca \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.