Skip to content

Commit 6df7f76

Browse files
jrfastabborkmann
authored andcommitted
bpf, sockmap: Wake up polling after data copy
When TCP stack has data ready to read sk_data_ready() is called. Sockmap overwrites this with its own handler to call into BPF verdict program. But, the original TCP socket had sock_def_readable that would additionally wake up any user space waiters with sk_wake_async(). Sockmap saved the callback when the socket was created so call the saved data ready callback and then we can wake up any epoll() logic waiting on the read. Note we call on 'copied >= 0' to account for returning 0 when a FIN is received because we need to wake up user for this as well so they can do the recvmsg() -> 0 and detect the shutdown. Fixes: 04919be ("tcp: Introduce tcp_read_skb()") Signed-off-by: John Fastabend <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Reviewed-by: Jakub Sitnicki <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent ea44418 commit 6df7f76

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

net/core/skmsg.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,12 +1199,21 @@ static int sk_psock_verdict_recv(struct sock *sk, struct sk_buff *skb)
11991199
static void sk_psock_verdict_data_ready(struct sock *sk)
12001200
{
12011201
struct socket *sock = sk->sk_socket;
1202+
int copied;
12021203

12031204
trace_sk_data_ready(sk);
12041205

12051206
if (unlikely(!sock || !sock->ops || !sock->ops->read_skb))
12061207
return;
1207-
sock->ops->read_skb(sk, sk_psock_verdict_recv);
1208+
copied = sock->ops->read_skb(sk, sk_psock_verdict_recv);
1209+
if (copied >= 0) {
1210+
struct sk_psock *psock;
1211+
1212+
rcu_read_lock();
1213+
psock = sk_psock(sk);
1214+
psock->saved_data_ready(sk);
1215+
rcu_read_unlock();
1216+
}
12081217
}
12091218

12101219
void sk_psock_start_verdict(struct sock *sk, struct sk_psock *psock)

0 commit comments

Comments
 (0)