* [PATCH bpf-next] bpf, sockmap: Call skb_linearize only when required in sk_psock_skb_ingress_enqueue
@ 2022-04-27 11:51 Liu Jian
2022-04-27 21:59 ` John Fastabend
2022-04-28 21:50 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Liu Jian @ 2022-04-27 11:51 UTC (permalink / raw)
To: john.fastabend, daniel, jakub, davem, kuba, pabeni, ast, andrii,
kafai, songliubraving, yhs, kpsingh, netdev, bpf
Cc: liujian56
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 <liujian56@huawei.com>
---
net/core/skmsg.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/net/core/skmsg.c b/net/core/skmsg.c
index cc381165ea08..22b983ade0e7 100644
--- a/net/core/skmsg.c
+++ b/net/core/skmsg.c
@@ -524,16 +524,20 @@ static int sk_psock_skb_ingress_enqueue(struct sk_buff *skb,
{
int num_sge, copied;
- /* 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
- * in skb_to_sgvec can not error.
- */
- 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;
+ 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
+ * in skb_to_sgvec can not error.
+ */
+ 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;
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [PATCH bpf-next] bpf, sockmap: Call skb_linearize only when required in sk_psock_skb_ingress_enqueue
2022-04-27 11:51 [PATCH bpf-next] bpf, sockmap: Call skb_linearize only when required in sk_psock_skb_ingress_enqueue Liu Jian
@ 2022-04-27 21:59 ` John Fastabend
2022-04-28 21:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: John Fastabend @ 2022-04-27 21:59 UTC (permalink / raw)
To: Liu Jian, john.fastabend, daniel, jakub, davem, kuba, pabeni,
ast, andrii, kafai, songliubraving, yhs, kpsingh, netdev, bpf
Cc: liujian56
Liu Jian wrote:
> 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 <liujian56@huawei.com>
> ---
Looks good. I guess performance improvement for some use cases with lots of packets that
no longer need linearizing must be fairly good.
Acked-by: John Fastabend <john.fastabend@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] bpf, sockmap: Call skb_linearize only when required in sk_psock_skb_ingress_enqueue
2022-04-27 11:51 [PATCH bpf-next] bpf, sockmap: Call skb_linearize only when required in sk_psock_skb_ingress_enqueue Liu Jian
2022-04-27 21:59 ` John Fastabend
@ 2022-04-28 21:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-04-28 21:50 UTC (permalink / raw)
To: Liu Jian
Cc: john.fastabend, daniel, jakub, davem, kuba, pabeni, ast, andrii,
kafai, songliubraving, yhs, kpsingh, netdev, bpf
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:
On Wed, 27 Apr 2022 19:51:50 +0800 you wrote:
> 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 <liujian56@huawei.com>
> ---
> net/core/skmsg.c | 22 +++++++++++++---------
> 1 file changed, 13 insertions(+), 9 deletions(-)
Here is the summary with links:
- [bpf-next] bpf, sockmap: Call skb_linearize only when required in sk_psock_skb_ingress_enqueue
https://git.kernel.org/bpf/bpf-next/c/3527bfe6a92d
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-28 21:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-27 11:51 [PATCH bpf-next] bpf, sockmap: Call skb_linearize only when required in sk_psock_skb_ingress_enqueue Liu Jian
2022-04-27 21:59 ` John Fastabend
2022-04-28 21:50 ` patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.