Commit 3527bfe6 authored by Liu Jian's avatar Liu Jian Committed by Daniel Borkmann
Browse files

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: default avatarLiu Jian <liujian56@huawei.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20220427115150.210213-1-liujian56@huawei.com
parent 9a9a90ca
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -524,6 +524,8 @@ static int sk_psock_skb_ingress_enqueue(struct sk_buff *skb,
{
	int num_sge, copied;

	num_sge = skb_to_sgvec(skb, msg->sg.data, off, len);
	if (num_sge < 0) {
		/* skb linearize may fail with ENOMEM, but lets simply try again
		 * later if this happens. Under memory pressure we don't want to
		 * drop the skb. We need to linearize the skb so that the mapping
@@ -531,9 +533,11 @@ static int sk_psock_skb_ingress_enqueue(struct sk_buff *skb,
		 */
		if (skb_linearize(skb))
			return -EAGAIN;

		num_sge = skb_to_sgvec(skb, msg->sg.data, off, len);
		if (unlikely(num_sge < 0))
			return num_sge;
	}

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