From: John Fastabend <john.fastabend@gmail.com>
To: zijianzhang@bytedance.com, bpf@vger.kernel.org
Cc: martin.lau@linux.dev, daniel@iogearbox.net,
john.fastabend@gmail.com, ast@kernel.org, andrii@kernel.org,
eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev,
kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com,
jolsa@kernel.org, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com,
shuah@kernel.org, jakub@cloudflare.com, liujian56@huawei.com,
zijianzhang@bytedance.com, cong.wang@bytedance.com
Subject: RE: [PATCH bpf 8/8] bpf, sockmap: Fix sk_msg_reset_curr
Date: Fri, 25 Oct 2024 22:05:15 -0700 [thread overview]
Message-ID: <671c788b7322c_656c20869@john.notmuch> (raw)
In-Reply-To: <20241020110345.1468595-9-zijianzhang@bytedance.com>
zijianzhang@ wrote:
> From: Zijian Zhang <zijianzhang@bytedance.com>
>
> Found in the test_txmsg_pull in test_sockmap,
> ```
> txmsg_cork = 512;
> opt->iov_length = 3;
> opt->iov_count = 1;
> opt->rate = 512;
> ```
> The first sendmsg will send an sk_msg with size 3, and bpf_msg_pull_data
> will be invoked the first time. sk_msg_reset_curr will reset the copybreak
> from 3 to 0, then the second sendmsg will write into copybreak starting at
> 0 which overwrites the first sendmsg. The same problem happens in push and
> pop test. Thus, fix sk_msg_reset_curr to restore the correct copybreak.
>
> Fixes: bb9aefde5bba ("bpf: sockmap, updating the sg structure should also update curr")
> Signed-off-by: Zijian Zhang <zijianzhang@bytedance.com>
Hi Zijian, question on below.
> ---
> net/core/filter.c | 20 +++++++++-----------
> 1 file changed, 9 insertions(+), 11 deletions(-)
>
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 8e1a8a8d8d55..b725d3a2fdb8 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -2619,18 +2619,16 @@ BPF_CALL_2(bpf_msg_cork_bytes, struct sk_msg *, msg, u32, bytes)
>
I find push_data a bit easier to think through so allow me to walk
through a push example.
If we setup so that curr=0 and copybreak=3 then call
push_data(skmsg, 2, 2);
When we get to the sk_msg_reset_curr we should have a layout,
msg->sg.data[0] = length(2) equal to original [0,2]
msg->sg.data[1] = length(2)
msg->sg.data[2] = legnth(1) equal to original [3]
The current before the reset curr will be,
curr = 1
copybreak = 3
> static void sk_msg_reset_curr(struct sk_msg *msg)
> {
> - u32 i = msg->sg.start;
> - u32 len = 0;
> -
with above context i = 0
> - do {
> - len += sk_msg_elem(msg, i)->length;
> - sk_msg_iter_var_next(i);
> - if (len >= msg->sg.size)
> - break;
> - } while (i != msg->sg.end);
When we exit loop,
i = 3
len = 5
msg->sg.curr = 3
msg->sg.copybreak = 0
So we zero the copy break and set curr = 3. The next send
should happen over sg.curr=3? What did I miss?
> + if (!msg->sg.size) {
> + msg->sg.curr = msg->sg.start;
> + msg->sg.copybreak = 0;
> + } else {
> + u32 i = msg->sg.end;
>
> - msg->sg.curr = i;
> - msg->sg.copybreak = 0;
> + sk_msg_iter_var_prev(i);
With this curr will always point to the end-1 but I'm not sure this can
handle the case where we have done sk_msg_alloc() so we have start/end
setup. And then on a copy fault for example we might have curr pointing
somewhere in the middle of that. I think I will need to construct the
example, but I believe this is originally why the 'i' is discovered
by sg walk vs simpler end.
> + msg->sg.curr = i;
> + msg->sg.copybreak = msg->sg.data[i].length;
This does seem more accurate then simply zero'ing out the copybreak
which is a good thing.
> + }
> }
>
> static const struct bpf_func_proto bpf_msg_cork_bytes_proto = {
> --
> 2.20.1
>
next prev parent reply other threads:[~2024-10-26 5:05 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-20 11:03 [PATCH bpf 0/8] Fixes to bpf_msg_push/pop_data and test_sockmap zijianzhang
2024-10-20 11:03 ` [PATCH bpf 1/8] selftests/bpf: Add txmsg_pass to pull/push/pop in test_sockmap zijianzhang
2024-10-24 4:06 ` John Fastabend
2024-10-20 11:03 ` [PATCH bpf 2/8] selftests/bpf: Fix SENDPAGE data logic " zijianzhang
2024-10-24 4:47 ` John Fastabend
2024-10-20 11:03 ` [PATCH bpf 3/8] selftests/bpf: Fix total_bytes in msg_loop_rx " zijianzhang
2024-10-24 4:48 ` John Fastabend
2024-10-20 11:03 ` [PATCH bpf 4/8] selftests/bpf: Add push/pop checking for msg_verify_data " zijianzhang
2024-10-24 5:20 ` John Fastabend
2024-10-20 11:03 ` [PATCH bpf 5/8] selftests/bpf: Add more tests for test_txmsg_push_pop " zijianzhang
2024-10-25 5:00 ` John Fastabend
2024-10-20 11:03 ` [PATCH bpf 6/8] bpf, sockmap: Several fixes to bpf_msg_push_data zijianzhang
2024-10-20 11:03 ` [PATCH bpf 7/8] bpf, sockmap: Several fixes to bpf_msg_pop_data zijianzhang
2024-10-25 5:20 ` John Fastabend
2024-10-20 11:03 ` [PATCH bpf 8/8] bpf, sockmap: Fix sk_msg_reset_curr zijianzhang
2024-10-26 5:05 ` John Fastabend [this message]
2024-10-26 6:17 ` Zijian Zhang
2024-10-24 4:06 ` [PATCH bpf 0/8] Fixes to bpf_msg_push/pop_data and test_sockmap John Fastabend
2024-10-24 14:43 ` Daniel Borkmann
2024-10-24 17:56 ` Zijian Zhang
2024-10-24 18:12 ` Daniel Borkmann
2024-10-24 20:48 ` Zijian Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=671c788b7322c_656c20869@john.notmuch \
--to=john.fastabend@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cong.wang@bytedance.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@google.com \
--cc=haoluo@google.com \
--cc=jakub@cloudflare.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=liujian56@huawei.com \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
--cc=zijianzhang@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.