Skip to content

Commit

Permalink
skmsg: Schedule psock work if the cached skb exists on the psock
Browse files Browse the repository at this point in the history
In sk_psock_backlog function, for ingress direction skb, if no new data
packet arrives after the skb is cached, the cached skb does not have a
chance to be added to the receive queue of psock. As a result, the cached
skb cannot be received by the upper-layer application. Fix this by reschedule
the psock work to dispose the cached skb in sk_msg_recvmsg function.

Fixes: 604326b ("bpf, sockmap: convert to generic sk_msg interface")
Signed-off-by: Liu Jian <liujian56@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20220907071311.60534-1-liujian56@huawei.com
  • Loading branch information
Liu Jian authored and Daniel Borkmann committed Sep 26, 2022
1 parent 043a735 commit bec2171
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions net/core/skmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,10 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
if (copied + copy > len)
copy = len - copied;
copy = copy_page_to_iter(page, sge->offset, copy, iter);
if (!copy)
return copied ? copied : -EFAULT;
if (!copy) {
copied = copied ? copied : -EFAULT;
goto out;
}

copied += copy;
if (likely(!peek)) {
Expand All @@ -455,7 +457,7 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
* didn't copy the entire length lets just break.
*/
if (copy != sge->length)
return copied;
goto out;
sk_msg_iter_var_next(i);
}

Expand All @@ -477,7 +479,9 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
}
msg_rx = sk_psock_peek_msg(psock);
}

out:
if (psock->work_state.skb && copied > 0)
schedule_work(&psock->work);
return copied;
}
EXPORT_SYMBOL_GPL(sk_msg_recvmsg);
Expand Down

0 comments on commit bec2171

Please sign in to comment.