From: Daniel Borkmann <daniel@iogearbox.net>
To: netdev@vger.kernel.org
Cc: bpf@vger.kernel.org, kuba@kernel.org, davem@davemloft.net,
razor@blackwall.org, pabeni@redhat.com, willemb@google.com,
sdf@fomichev.me, john.fastabend@gmail.com, martin.lau@kernel.org,
jordan@jrife.io, maciej.fijalkowski@intel.com,
magnus.karlsson@intel.com, dw@davidwei.uk, toke@redhat.com,
yangzhenze@bytedance.com, wangdongdong.6@bytedance.com
Subject: [PATCH net-next v3 10/15] xsk: Proxy pool management for mapped queues
Date: Mon, 20 Oct 2025 18:23:50 +0200 [thread overview]
Message-ID: <20251020162355.136118-11-daniel@iogearbox.net> (raw)
In-Reply-To: <20251020162355.136118-1-daniel@iogearbox.net>
Similarly what we do for net_mp_{open,close}_rxq for mapped queues,
proxy also the xsk_{reg,clear}_pool_at_qid via __netif_get_rx_queue_peer
such that when a virtual netdev picked a mapped rxq, the request gets
through to the real rxq in the physical netdev.
Change the function signatures for queue_id to unsigned int in order
to pass the queue_id parameter into __netif_get_rx_queue_peer. The
proxying is only relevant for queue_id < dev->real_num_rx_queues since
right now its only supported for rxqs.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Co-developed-by: David Wei <dw@davidwei.uk>
Signed-off-by: David Wei <dw@davidwei.uk>
---
include/net/xdp_sock_drv.h | 4 ++--
net/xdp/xsk.c | 33 ++++++++++++++++++++++++++++-----
net/xdp/xsk.h | 5 ++---
3 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h
index 242e34f771cc..25c37fab00bc 100644
--- a/include/net/xdp_sock_drv.h
+++ b/include/net/xdp_sock_drv.h
@@ -29,7 +29,7 @@ bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc);
u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, u32 max);
void xsk_tx_release(struct xsk_buff_pool *pool);
struct xsk_buff_pool *xsk_get_pool_from_qid(struct net_device *dev,
- u16 queue_id);
+ unsigned int queue_id);
void xsk_set_rx_need_wakeup(struct xsk_buff_pool *pool);
void xsk_set_tx_need_wakeup(struct xsk_buff_pool *pool);
void xsk_clear_rx_need_wakeup(struct xsk_buff_pool *pool);
@@ -296,7 +296,7 @@ static inline void xsk_tx_release(struct xsk_buff_pool *pool)
}
static inline struct xsk_buff_pool *
-xsk_get_pool_from_qid(struct net_device *dev, u16 queue_id)
+xsk_get_pool_from_qid(struct net_device *dev, unsigned int queue_id)
{
return NULL;
}
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 985e0cac965d..9e55ea0f5fde 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -23,6 +23,8 @@
#include <linux/netdevice.h>
#include <linux/rculist.h>
#include <linux/vmalloc.h>
+
+#include <net/netdev_queues.h>
#include <net/xdp_sock_drv.h>
#include <net/busy_poll.h>
#include <net/netdev_lock.h>
@@ -111,7 +113,7 @@ bool xsk_uses_need_wakeup(struct xsk_buff_pool *pool)
EXPORT_SYMBOL(xsk_uses_need_wakeup);
struct xsk_buff_pool *xsk_get_pool_from_qid(struct net_device *dev,
- u16 queue_id)
+ unsigned int queue_id)
{
if (queue_id < dev->real_num_rx_queues)
return dev->_rx[queue_id].pool;
@@ -122,12 +124,19 @@ struct xsk_buff_pool *xsk_get_pool_from_qid(struct net_device *dev,
}
EXPORT_SYMBOL(xsk_get_pool_from_qid);
-void xsk_clear_pool_at_qid(struct net_device *dev, u16 queue_id)
+void xsk_clear_pool_at_qid(struct net_device *dev, unsigned int queue_id)
{
+ bool needs_unlock = false;
+
+ if (queue_id < dev->real_num_rx_queues)
+ WARN_ON_ONCE(!netif_get_rx_queue_peer_locked(&dev, &queue_id,
+ &needs_unlock));
if (queue_id < dev->num_rx_queues)
dev->_rx[queue_id].pool = NULL;
if (queue_id < dev->num_tx_queues)
dev->_tx[queue_id].pool = NULL;
+ if (needs_unlock)
+ netdev_unlock(dev);
}
/* The buffer pool is stored both in the _rx struct and the _tx struct as we do
@@ -135,14 +144,26 @@ void xsk_clear_pool_at_qid(struct net_device *dev, u16 queue_id)
* This might also change during run time.
*/
int xsk_reg_pool_at_qid(struct net_device *dev, struct xsk_buff_pool *pool,
- u16 queue_id)
+ unsigned int queue_id)
{
+ bool needs_unlock = false;
+ int ret = 0;
+
if (queue_id >= max_t(unsigned int,
dev->real_num_rx_queues,
dev->real_num_tx_queues))
return -EINVAL;
if (xsk_get_pool_from_qid(dev, queue_id))
return -EBUSY;
+ if (queue_id < dev->real_num_rx_queues) {
+ if (!netif_get_rx_queue_peer_locked(&dev, &queue_id,
+ &needs_unlock))
+ return -EBUSY;
+ }
+ if (xsk_get_pool_from_qid(dev, queue_id)) {
+ ret = -EBUSY;
+ goto out;
+ }
pool->netdev = dev;
pool->queue_id = queue_id;
@@ -151,8 +172,10 @@ int xsk_reg_pool_at_qid(struct net_device *dev, struct xsk_buff_pool *pool,
dev->_rx[queue_id].pool = pool;
if (queue_id < dev->real_num_tx_queues)
dev->_tx[queue_id].pool = pool;
-
- return 0;
+out:
+ if (needs_unlock)
+ netdev_unlock(dev);
+ return ret;
}
static int __xsk_rcv_zc(struct xdp_sock *xs, struct xdp_buff_xsk *xskb, u32 len,
diff --git a/net/xdp/xsk.h b/net/xdp/xsk.h
index a4bc4749faac..54d9a7736fd2 100644
--- a/net/xdp/xsk.h
+++ b/net/xdp/xsk.h
@@ -41,8 +41,7 @@ static inline struct xdp_sock *xdp_sk(struct sock *sk)
void xsk_map_try_sock_delete(struct xsk_map *map, struct xdp_sock *xs,
struct xdp_sock __rcu **map_entry);
-void xsk_clear_pool_at_qid(struct net_device *dev, u16 queue_id);
+void xsk_clear_pool_at_qid(struct net_device *dev, unsigned int queue_id);
int xsk_reg_pool_at_qid(struct net_device *dev, struct xsk_buff_pool *pool,
- u16 queue_id);
-
+ unsigned int queue_id);
#endif /* XSK_H_ */
--
2.43.0
next prev parent reply other threads:[~2025-10-20 16:24 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-20 16:23 [PATCH net-next v3 00/15] netkit: Support for io_uring zero-copy and AF_XDP Daniel Borkmann
2025-10-20 16:23 ` [PATCH net-next v3 01/15] net: Add bind-queue operation Daniel Borkmann
2025-10-22 11:19 ` Nikolay Aleksandrov
2025-10-24 2:12 ` Jakub Kicinski
2025-10-24 10:15 ` Daniel Borkmann
2025-10-24 18:11 ` Stanislav Fomichev
2025-10-24 19:17 ` Daniel Borkmann
2025-10-20 16:23 ` [PATCH net-next v3 02/15] net: Implement netdev_nl_bind_queue_doit Daniel Borkmann
2025-10-22 11:17 ` Nikolay Aleksandrov
2025-10-22 11:26 ` Daniel Borkmann
2025-10-23 10:17 ` Paolo Abeni
2025-10-23 12:46 ` Daniel Borkmann
2025-10-23 10:27 ` Paolo Abeni
2025-10-23 12:48 ` Daniel Borkmann
2025-10-24 2:08 ` Jakub Kicinski
2025-10-28 21:59 ` David Wei
2025-10-28 23:44 ` Jakub Kicinski
2025-10-29 0:38 ` David Wei
2025-10-24 2:28 ` Jakub Kicinski
2025-10-28 22:41 ` David Wei
2025-10-29 16:46 ` Daniel Borkmann
2025-10-24 18:20 ` Stanislav Fomichev
2025-10-24 19:15 ` Daniel Borkmann
2025-10-20 16:23 ` [PATCH net-next v3 03/15] net: Add peer info to queue-get response Daniel Borkmann
2025-10-22 11:23 ` Nikolay Aleksandrov
2025-10-24 2:33 ` Jakub Kicinski
2025-10-24 12:59 ` Daniel Borkmann
2025-10-24 23:18 ` Jakub Kicinski
2025-10-29 2:08 ` David Wei
2025-10-29 22:47 ` Jakub Kicinski
2025-10-20 16:23 ` [PATCH net-next v3 04/15] net, ethtool: Disallow peered real rxqs to be resized Daniel Borkmann
2025-10-22 11:25 ` Nikolay Aleksandrov
2025-10-20 16:23 ` [PATCH net-next v3 05/15] net: Proxy net_mp_{open,close}_rxq for mapped queues Daniel Borkmann
2025-10-22 12:50 ` Nikolay Aleksandrov
2025-10-24 18:36 ` Stanislav Fomichev
2025-10-29 2:07 ` David Wei
2025-10-20 16:23 ` [PATCH net-next v3 06/15] xsk: Move NETDEV_XDP_ACT_ZC into generic header Daniel Borkmann
2025-10-22 12:51 ` Nikolay Aleksandrov
2025-10-20 16:23 ` [PATCH net-next v3 07/15] xsk: Move pool registration into single function Daniel Borkmann
2025-10-22 12:52 ` Nikolay Aleksandrov
2025-10-20 16:23 ` [PATCH net-next v3 08/15] xsk: Add small helper xp_pool_bindable Daniel Borkmann
2025-10-22 12:52 ` Nikolay Aleksandrov
2025-10-20 16:23 ` [PATCH net-next v3 09/15] xsk: Change xsk_rcv_check to check netdev/queue_id from pool Daniel Borkmann
2025-10-20 16:23 ` Daniel Borkmann [this message]
2025-10-20 16:23 ` [PATCH net-next v3 11/15] netkit: Add single device mode for netkit Daniel Borkmann
2025-10-22 13:13 ` Nikolay Aleksandrov
2025-10-20 16:23 ` [PATCH net-next v3 12/15] netkit: Document fast vs slowpath members via macros Daniel Borkmann
2025-10-22 13:02 ` Nikolay Aleksandrov
2025-10-20 16:23 ` [PATCH net-next v3 13/15] netkit: Implement rtnl_link_ops->alloc and ndo_queue_create Daniel Borkmann
2025-10-22 13:00 ` Nikolay Aleksandrov
2025-10-20 16:23 ` [PATCH net-next v3 14/15] netkit: Add io_uring zero-copy support for TCP Daniel Borkmann
2025-10-22 13:12 ` Nikolay Aleksandrov
2025-10-20 16:23 ` [PATCH net-next v3 15/15] netkit: Add xsk support for af_xdp applications Daniel Borkmann
2025-10-22 14:27 ` Nikolay Aleksandrov
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=20251020162355.136118-11-daniel@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=dw@davidwei.uk \
--cc=john.fastabend@gmail.com \
--cc=jordan@jrife.io \
--cc=kuba@kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=martin.lau@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.org \
--cc=sdf@fomichev.me \
--cc=toke@redhat.com \
--cc=wangdongdong.6@bytedance.com \
--cc=willemb@google.com \
--cc=yangzhenze@bytedance.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).