Skip to content

Commit ca2e1a6

Browse files
mfijalkoborkmann
authored andcommitted
xsk: Mark napi_id on sendmsg()
When application runs in busy poll mode and does not receive a single packet but only sends them, it is currently impossible to get into napi_busy_loop() as napi_id is only marked on Rx side in xsk_rcv_check(). In there, napi_id is being taken from xdp_rxq_info carried by xdp_buff. From Tx perspective, we do not have access to it. What we have handy is the xsk pool. Xsk pool works on a pool of internal xdp_buff wrappers called xdp_buff_xsk. AF_XDP ZC enabled drivers call xp_set_rxq_info() so each of xdp_buff_xsk has a valid pointer to xdp_rxq_info of underlying queue. Therefore, on Tx side, napi_id can be pulled from xs->pool->heads[0].xdp.rxq->napi_id. Hide this pointer chase under helper function, xsk_pool_get_napi_id(). Do this only for sockets working in ZC mode as otherwise rxq pointers would not be initialized. Signed-off-by: Maciej Fijalkowski <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Magnus Karlsson <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 33f32e5 commit ca2e1a6

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

include/net/xdp_sock_drv.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ static inline void xsk_pool_set_rxq_info(struct xsk_buff_pool *pool,
4444
xp_set_rxq_info(pool, rxq);
4545
}
4646

47+
static inline unsigned int xsk_pool_get_napi_id(struct xsk_buff_pool *pool)
48+
{
49+
#ifdef CONFIG_NET_RX_BUSY_POLL
50+
return pool->heads[0].xdp.rxq->napi_id;
51+
#else
52+
return 0;
53+
#endif
54+
}
55+
4756
static inline void xsk_pool_dma_unmap(struct xsk_buff_pool *pool,
4857
unsigned long attrs)
4958
{
@@ -198,6 +207,11 @@ static inline void xsk_pool_set_rxq_info(struct xsk_buff_pool *pool,
198207
{
199208
}
200209

210+
static inline unsigned int xsk_pool_get_napi_id(struct xsk_buff_pool *pool)
211+
{
212+
return 0;
213+
}
214+
201215
static inline void xsk_pool_dma_unmap(struct xsk_buff_pool *pool,
202216
unsigned long attrs)
203217
{

net/xdp/xsk.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,11 @@ static int __xsk_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len
639639
if (unlikely(need_wait))
640640
return -EOPNOTSUPP;
641641

642-
if (sk_can_busy_loop(sk))
642+
if (sk_can_busy_loop(sk)) {
643+
if (xs->zc)
644+
__sk_mark_napi_id_once(sk, xsk_pool_get_napi_id(xs->pool));
643645
sk_busy_loop(sk, 1); /* only support non-blocking sockets */
646+
}
644647

645648
if (xs->zc && xsk_no_wakeup(sk))
646649
return 0;

0 commit comments

Comments
 (0)