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, sdf@fomichev.me,
hramamurthy@google.com, kuniyu@amazon.com, jdamato@fastly.com
Subject: [PATCH net-next 2/8] net: designate XSK pool pointers in queues as "ops protected"
Date: Mon, 7 Apr 2025 12:01:11 -0700 [thread overview]
Message-ID: <20250407190117.16528-3-kuba@kernel.org> (raw)
In-Reply-To: <20250407190117.16528-1-kuba@kernel.org>
Read accesses go via xsk_get_pool_from_qid(), the call coming
from the core and gve look safe (other "ops locked" drivers
don't support XSK).
Write accesses go via xsk_reg_pool_at_qid() and xsk_clear_pool_at_qid().
Former is already under the ops lock, latter needs to be locked when
coming from the workqueue via xp_clear_dev().
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
---
include/linux/netdevice.h | 1 +
include/net/netdev_rx_queue.h | 6 +++---
net/xdp/xsk.c | 2 ++
net/xdp/xsk_buff_pool.c | 7 ++++++-
4 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 8e9be80bc167..7242fb8a22fc 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -688,6 +688,7 @@ struct netdev_queue {
/* Subordinate device that the queue has been assigned to */
struct net_device *sb_dev;
#ifdef CONFIG_XDP_SOCKETS
+ /* "ops protected", see comment about net_device::lock */
struct xsk_buff_pool *pool;
#endif
diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h
index b2238b551dce..8cdcd138b33f 100644
--- a/include/net/netdev_rx_queue.h
+++ b/include/net/netdev_rx_queue.h
@@ -20,12 +20,12 @@ struct netdev_rx_queue {
struct net_device *dev;
netdevice_tracker dev_tracker;
+ /* All fields below are "ops protected",
+ * see comment about net_device::lock
+ */
#ifdef CONFIG_XDP_SOCKETS
struct xsk_buff_pool *pool;
#endif
- /* NAPI instance for the queue
- * "ops protected", see comment about net_device::lock
- */
struct napi_struct *napi;
struct pp_memory_provider_params mp_params;
} ____cacheline_aligned_in_smp;
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 5696af45bcf7..2ecf063a2c38 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -1654,7 +1654,9 @@ static int xsk_notifier(struct notifier_block *this,
xsk_unbind_dev(xs);
/* Clear device references. */
+ netdev_lock_ops(dev);
xp_clear_dev(xs->pool);
+ netdev_unlock_ops(dev);
}
mutex_unlock(&xs->mutex);
}
diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
index 25a76c5ce0f1..c7e50fd86c6a 100644
--- a/net/xdp/xsk_buff_pool.c
+++ b/net/xdp/xsk_buff_pool.c
@@ -279,9 +279,14 @@ static void xp_release_deferred(struct work_struct *work)
{
struct xsk_buff_pool *pool = container_of(work, struct xsk_buff_pool,
work);
+ struct net_device *netdev = pool->netdev;
rtnl_lock();
- xp_clear_dev(pool);
+ if (netdev) {
+ netdev_lock_ops(netdev);
+ xp_clear_dev(pool);
+ netdev_unlock_ops(netdev);
+ }
rtnl_unlock();
if (pool->fq) {
--
2.49.0
next prev parent reply other threads:[~2025-04-07 19:01 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-07 19:01 [PATCH net-next 0/8] net: depend on instance lock for queue related netlink ops Jakub Kicinski
2025-04-07 19:01 ` [PATCH net-next 1/8] net: avoid potential race between netdev_get_by_index_lock() and netns switch Jakub Kicinski
2025-04-08 2:40 ` Joe Damato
2025-04-07 19:01 ` Jakub Kicinski [this message]
2025-04-08 2:17 ` [PATCH net-next 2/8] net: designate XSK pool pointers in queues as "ops protected" Joe Damato
2025-04-08 14:59 ` Jakub Kicinski
2025-04-07 19:01 ` [PATCH net-next 3/8] netdev: add "ops compat locking" helpers Jakub Kicinski
2025-04-08 2:41 ` Joe Damato
2025-04-07 19:01 ` [PATCH net-next 4/8] netdev: don't hold rtnl_lock over nl queue info get when possible Jakub Kicinski
2025-04-08 2:28 ` Joe Damato
2025-04-07 19:01 ` [PATCH net-next 5/8] xdp: double protect netdev->xdp_flags with netdev->lock Jakub Kicinski
2025-04-08 2:30 ` Joe Damato
2025-04-07 19:01 ` [PATCH net-next 6/8] netdev: depend on netdev->lock for xdp features Jakub Kicinski
2025-04-08 2:31 ` Joe Damato
2025-04-07 19:01 ` [PATCH net-next 7/8] docs: netdev: break down the instance locking info per ops struct Jakub Kicinski
2025-04-08 2:34 ` Joe Damato
2025-04-08 15:08 ` Jakub Kicinski
2025-04-07 19:01 ` [PATCH net-next 8/8] netdev: depend on netdev->lock for qstats in ops locked drivers Jakub Kicinski
2025-04-08 2:37 ` Joe Damato
2025-04-08 0:28 ` [PATCH net-next 0/8] net: depend on instance lock for queue related netlink ops Stanislav Fomichev
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=20250407190117.16528-3-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=hramamurthy@google.com \
--cc=jdamato@fastly.com \
--cc=kuniyu@amazon.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
/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).