Skip to content

Commit 3527bfe

Browse files
liujian56borkmann
authored andcommitted
bpf, sockmap: Call skb_linearize only when required in sk_psock_skb_ingress_enqueue
The skb_to_sgvec fails only when the number of frag_list and frags exceeds MAX_MSG_FRAGS. Therefore, we can call skb_linearize only when the conversion fails. Signed-off-by: Liu Jian <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: John Fastabend <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 9a9a90c commit 3527bfe

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

net/core/skmsg.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -524,16 +524,20 @@ static int sk_psock_skb_ingress_enqueue(struct sk_buff *skb,
524524
{
525525
int num_sge, copied;
526526

527-
/* skb linearize may fail with ENOMEM, but lets simply try again
528-
* later if this happens. Under memory pressure we don't want to
529-
* drop the skb. We need to linearize the skb so that the mapping
530-
* in skb_to_sgvec can not error.
531-
*/
532-
if (skb_linearize(skb))
533-
return -EAGAIN;
534527
num_sge = skb_to_sgvec(skb, msg->sg.data, off, len);
535-
if (unlikely(num_sge < 0))
536-
return num_sge;
528+
if (num_sge < 0) {
529+
/* skb linearize may fail with ENOMEM, but lets simply try again
530+
* later if this happens. Under memory pressure we don't want to
531+
* drop the skb. We need to linearize the skb so that the mapping
532+
* in skb_to_sgvec can not error.
533+
*/
534+
if (skb_linearize(skb))
535+
return -EAGAIN;
536+
537+
num_sge = skb_to_sgvec(skb, msg->sg.data, off, len);
538+
if (unlikely(num_sge < 0))
539+
return num_sge;
540+
}
537541

538542
copied = len;
539543
msg->sg.start = 0;

0 commit comments

Comments
 (0)