Skip to content

Commit e392081

Browse files
Björn Töpelborkmann
authored andcommitted
xsk: Check need wakeup flag in sendmsg()
Add a check for need wake up in sendmsg(), so that if a user calls sendmsg() when no wakeup is needed, do not trigger a wakeup. To simplify the need wakeup check in the syscall, unconditionally enable the need wakeup flag for Tx. This has a side-effect for poll(); If poll() is called for a socket without enabled need wakeup, a Tx wakeup is unconditionally performed. The wakeup matrix for AF_XDP now looks like: need wakeup | poll() | sendmsg() | recvmsg() ------------+--------------+-------------+------------ disabled | wake Tx | wake Tx | nop enabled | check flag; | check flag; | check flag; | wake Tx/Rx | wake Tx | wake Rx Signed-off-by: Björn Töpel <[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 45a8668 commit e392081

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

net/xdp/xsk.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,13 +522,17 @@ static int xsk_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)
522522
bool need_wait = !(m->msg_flags & MSG_DONTWAIT);
523523
struct sock *sk = sock->sk;
524524
struct xdp_sock *xs = xdp_sk(sk);
525+
struct xsk_buff_pool *pool;
525526

526527
if (unlikely(!xsk_is_bound(xs)))
527528
return -ENXIO;
528529
if (unlikely(need_wait))
529530
return -EOPNOTSUPP;
530531

531-
return __xsk_sendmsg(sk);
532+
pool = xs->pool;
533+
if (pool->cached_need_wakeup & XDP_WAKEUP_TX)
534+
return __xsk_sendmsg(sk);
535+
return 0;
532536
}
533537

534538
static int xsk_recvmsg(struct socket *sock, struct msghdr *m, size_t len, int flags)

net/xdp/xsk_buff_pool.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,13 @@ static int __xp_assign_dev(struct xsk_buff_pool *pool,
144144
if (err)
145145
return err;
146146

147-
if (flags & XDP_USE_NEED_WAKEUP) {
147+
if (flags & XDP_USE_NEED_WAKEUP)
148148
pool->uses_need_wakeup = true;
149-
/* Tx needs to be explicitly woken up the first time.
150-
* Also for supporting drivers that do not implement this
151-
* feature. They will always have to call sendto().
152-
*/
153-
pool->cached_need_wakeup = XDP_WAKEUP_TX;
154-
}
149+
/* Tx needs to be explicitly woken up the first time. Also
150+
* for supporting drivers that do not implement this
151+
* feature. They will always have to call sendto() or poll().
152+
*/
153+
pool->cached_need_wakeup = XDP_WAKEUP_TX;
155154

156155
dev_hold(netdev);
157156

0 commit comments

Comments
 (0)