From: Geliang Tang <geliang@kernel.org>
To: Martin KaFai Lau <martin.lau@linux.dev>
Cc: Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Mykola Lysenko <mykolal@fb.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
Jakub Sitnicki <jakub@cloudflare.com>,
bpf@vger.kernel.org, Geliang Tang <geliang@kernel.org>
Subject: Re: [PATCH bpf v4 1/2] selftests/bpf: Add F_SETFL for fcntl in test_sockmap
Date: Wed, 17 Apr 2024 16:14:28 +0800 [thread overview]
Message-ID: <Zh+E5JlEM6fisrFS@t480> (raw)
In-Reply-To: <e2aaa0f0-7641-4d26-9256-1151976235f1@linux.dev>
[-- Attachment #1: Type: text/plain, Size: 2189 bytes --]
Hi Martin,
On Thu, Apr 11, 2024 at 11:10:49AM -0700, Martin KaFai Lau wrote:
> On 4/8/24 10:18 PM, Geliang Tang wrote:
> > From: Geliang Tang <tanggeliang@kylinos.cn>
> >
> > Incorrect arguments are passed to fcntl() in test_sockmap.c when invoking
> > it to set file status flags. If O_NONBLOCK is used as 2nd argument and
> > passed into fcntl, -EINVAL will be returned (See do_fcntl() in fs/fcntl.c).
> > The correct approach is to use F_SETFL as 2nd argument, and O_NONBLOCK as
> > 3rd one.
> >
> > In nonblock mode, if EWOULDBLOCK is received, continue receiving, otherwise
> > some subtests of test_sockmap fail.
> >
> > Fixes: 16962b2404ac ("bpf: sockmap, add selftests")
> > Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> > Acked-by: Yonghong Song <yonghong.song@linux.dev>
> > ---
> > tools/testing/selftests/bpf/test_sockmap.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c
> > index 024a0faafb3b..4feed253fca2 100644
> > --- a/tools/testing/selftests/bpf/test_sockmap.c
> > +++ b/tools/testing/selftests/bpf/test_sockmap.c
> > @@ -603,7 +603,9 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
> > struct timeval timeout;
> > fd_set w;
> > - fcntl(fd, fd_flags);
> > + if (fcntl(fd, F_SETFL, fd_flags))
> > + goto out_errno;
> > +
> > /* Account for pop bytes noting each iteration of apply will
> > * call msg_pop_data helper so we need to account for this
> > * by calculating the number of apply iterations. Note user
> > @@ -678,6 +680,7 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
> > perror("recv failed()");
> > goto out_errno;
> > }
> > + continue;
>
> From looking at it again, there is a select() earlier, so it should not hit
> EWOULDBLOCK.
Can the patch in the attachment be accepted? It can work, but I'm not sure
if it has changed the behavior of this test. Anyway, I would like to hear
your opinion.
Thanks,
-Geliang
>
> Patch 2 looks good. Only patch 2 is applied. Thanks.
>
> > }
> > s->bytes_recvd += recv;
[-- Attachment #2: 0001-selftests-bpf-Add-F_SETFL-for-fcntl-in-test_sockmap.patch --]
[-- Type: text/x-diff, Size: 1994 bytes --]
From d20ac7e06d9e869094f452d8c2dcdc316508dcc8 Mon Sep 17 00:00:00 2001
Message-Id: <d20ac7e06d9e869094f452d8c2dcdc316508dcc8.1713340686.git.tanggeliang@kylinos.cn>
From: Geliang Tang <tanggeliang@kylinos.cn>
Date: Wed, 3 Apr 2024 16:08:21 +0800
Subject: [PATCH] selftests/bpf: Add F_SETFL for fcntl in test_sockmap
Incorrect arguments are passed to fcntl() in test_sockmap.c when invoking
it to set file status flags. If O_NONBLOCK is used as 2nd argument and
passed into fcntl, -EINVAL will be returned (See do_fcntl() in fs/fcntl.c).
The correct approach is to use F_SETFL as 2nd argument, and O_NONBLOCK as
3rd one.
In nonblock mode, if EWOULDBLOCK is received, continue receiving, otherwise
some subtests of test_sockmap fail.
Fixes: 16962b2404ac ("bpf: sockmap, add selftests")
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
---
tools/testing/selftests/bpf/test_sockmap.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c
index 024a0faafb3b..8130f465afb9 100644
--- a/tools/testing/selftests/bpf/test_sockmap.c
+++ b/tools/testing/selftests/bpf/test_sockmap.c
@@ -603,7 +603,9 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
struct timeval timeout;
fd_set w;
- fcntl(fd, fd_flags);
+ if (fcntl(fd, F_SETFL, fd_flags))
+ goto out_errno;
+
/* Account for pop bytes noting each iteration of apply will
* call msg_pop_data helper so we need to account for this
* by calculating the number of apply iterations. Note user
@@ -1531,10 +1533,10 @@ static void test_txmsg_skb(int cgrp, struct sockmap_options *opt)
txmsg_ktls_skb_drop = 1;
test_exec(cgrp, opt);
- txmsg_ktls_skb_drop = 0;
txmsg_ktls_skb_redir = 1;
test_exec(cgrp, opt);
txmsg_ktls_skb_redir = 0;
+ txmsg_ktls_skb_drop = 0;
/* Tests that omit skb_parser */
txmsg_omit_skb_parser = 1;
--
2.40.1
next prev parent reply other threads:[~2024-04-17 8:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-09 5:18 [PATCH bpf v4 0/2] Two fixes for test_sockmap Geliang Tang
2024-04-09 5:18 ` [PATCH bpf v4 1/2] selftests/bpf: Add F_SETFL for fcntl in test_sockmap Geliang Tang
2024-04-11 18:10 ` Martin KaFai Lau
2024-04-17 8:14 ` Geliang Tang [this message]
2024-04-18 0:28 ` Martin KaFai Lau
2024-04-23 10:28 ` Geliang Tang
2024-04-25 12:26 ` Jakub Sitnicki
2024-04-09 5:18 ` [PATCH bpf v4 2/2] selftests/bpf: Fix umount cgroup2 error " Geliang Tang
2024-04-09 6:07 ` [PATCH bpf v4 0/2] Two fixes for test_sockmap MPTCP CI
2024-04-11 18:10 ` patchwork-bot+netdevbpf
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=Zh+E5JlEM6fisrFS@t480 \
--to=geliang@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=jakub@cloudflare.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=sdf@google.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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.