diff mbox series

[bpf-next] selftests/bpf: Add F_SETFL for fcntl

Message ID b67101632c6858d281f105b5d4e1bc62dd6b7d27.1712133039.git.tanggeliang@kylinos.cn (mailing list archive)
State New, archived
Headers show
Series [bpf-next] selftests/bpf: Add F_SETFL for fcntl | expand

Checks

Context Check Description
matttbe/build success Build and static analysis OK
matttbe/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
matttbe/shellcheck success MPTCP selftests files have not been modified
matttbe/KVM_Validation__normal success Success! ✅
matttbe/KVM_Validation__debug success Success! ✅
matttbe/KVM_Validation__btf__only_bpftest_all_ success Success! ✅

Commit Message

Geliang Tang April 3, 2024, 8:32 a.m. UTC
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.

Fixes: 16962b2404ac ("bpf: sockmap, add selftests")
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/bpf/test_sockmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

MPTCP CI April 3, 2024, 9:26 a.m. UTC | #1
Hi Geliang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/8535893261

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/81bb737cfc7b
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=840962


If there are some issues, you can reproduce them using the same environment as
the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

    https://github.com/multipath-tcp/mptcp-upstream-virtme-docker


Please note that despite all the efforts that have been already done to have a
stable tests suite when executed on a public CI like here, it is possible some
reported issues are not due to your modifications. Still, do not hesitate to
help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Jakub Sitnicki April 3, 2024, 12:05 p.m. UTC | #2
Hi Geliang,

On Wed, Apr 03, 2024 at 04:32 PM +08, 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.
>
> Fixes: 16962b2404ac ("bpf: sockmap, add selftests")
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>  tools/testing/selftests/bpf/test_sockmap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c
> index 024a0faafb3b..34d6a1e6f664 100644
> --- a/tools/testing/selftests/bpf/test_sockmap.c
> +++ b/tools/testing/selftests/bpf/test_sockmap.c
> @@ -603,7 +603,7 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
>  		struct timeval timeout;
>  		fd_set w;
>  
> -		fcntl(fd, fd_flags);
> +		fcntl(fd, F_SETFL, fd_flags);
>  		/* 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

Good catch. But we also need to figure out why some tests failing with
this patch applied and fix them in one go:

# 6/ 7  sockmap::txmsg test skb:FAIL
#21/ 7 sockhash::txmsg test skb:FAIL
#36/ 7 sockhash:ktls:txmsg test skb:FAIL
Pass: 42 Fail: 3

I'm seeing this error message when running `test_sockmap`:

detected skb data error with skb ingress update @iov[0]:0 "00 00 00 00" != "PASS"
data verify msg failed: Unknown error -5
rx thread exited with err 1.

I'd also:
- add an error check for fnctl, so we don't regress,
- get rid of fd_flags, pass O_NONBLOCK flag directly to fnctl.

Thanks,
-jkbs
John Fastabend April 3, 2024, 10:29 p.m. UTC | #3
Jakub Sitnicki wrote:
> Hi Geliang,
> 
> On Wed, Apr 03, 2024 at 04:32 PM +08, 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.
> >
> > Fixes: 16962b2404ac ("bpf: sockmap, add selftests")
> > Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> > ---
> >  tools/testing/selftests/bpf/test_sockmap.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c
> > index 024a0faafb3b..34d6a1e6f664 100644
> > --- a/tools/testing/selftests/bpf/test_sockmap.c
> > +++ b/tools/testing/selftests/bpf/test_sockmap.c
> > @@ -603,7 +603,7 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
> >  		struct timeval timeout;
> >  		fd_set w;
> >  
> > -		fcntl(fd, fd_flags);
> > +		fcntl(fd, F_SETFL, fd_flags);
> >  		/* 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
> 
> Good catch. But we also need to figure out why some tests failing with
> this patch applied and fix them in one go:
> 
> # 6/ 7  sockmap::txmsg test skb:FAIL
> #21/ 7 sockhash::txmsg test skb:FAIL
> #36/ 7 sockhash:ktls:txmsg test skb:FAIL
> Pass: 42 Fail: 3
> 
> I'm seeing this error message when running `test_sockmap`:
> 
> detected skb data error with skb ingress update @iov[0]:0 "00 00 00 00" != "PASS"
> data verify msg failed: Unknown error -5
> rx thread exited with err 1.

I have a theory this is a real bug in the SK_SKB_STREAM_PARSER which has an
issue with wakup logic. Maybe we wakeup the poll/select logic before the
data is copied and because the recv() is actually nonblocking now we get
the error.

> 
> I'd also:
> - add an error check for fnctl, so we don't regress,
> - get rid of fd_flags, pass O_NONBLOCK flag directly to fnctl.
> 
> Thanks,
> -jkbs
Geliang Tang April 4, 2024, 12:27 a.m. UTC | #4
Hi Jakub,
 
On Wed, 2024-04-03 at 15:29 -0700, John Fastabend wrote:
> Jakub Sitnicki wrote:
> > Hi Geliang,
> > 
> > On Wed, Apr 03, 2024 at 04:32 PM +08, 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.
> > > 
> > > Fixes: 16962b2404ac ("bpf: sockmap, add selftests")
> > > Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> > > ---
> > >  tools/testing/selftests/bpf/test_sockmap.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/tools/testing/selftests/bpf/test_sockmap.c
> > > b/tools/testing/selftests/bpf/test_sockmap.c
> > > index 024a0faafb3b..34d6a1e6f664 100644
> > > --- a/tools/testing/selftests/bpf/test_sockmap.c
> > > +++ b/tools/testing/selftests/bpf/test_sockmap.c
> > > @@ -603,7 +603,7 @@ static int msg_loop(int fd, int iov_count,
> > > int iov_length, int cnt,
> > >  		struct timeval timeout;
> > >  		fd_set w;
> > >  
> > > -		fcntl(fd, fd_flags);
> > > +		fcntl(fd, F_SETFL, fd_flags);
> > >  		/* 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
> > 
> > Good catch. But we also need to figure out why some tests failing
> > with
> > this patch applied and fix them in one go:
> > 
> > # 6/ 7  sockmap::txmsg test skb:FAIL
> > #21/ 7 sockhash::txmsg test skb:FAIL
> > #36/ 7 sockhash:ktls:txmsg test skb:FAIL
> > Pass: 42 Fail: 3

Sorry, I didn't notice these fails in my testing before, they do exist.
I'll try to fix them and sent a v2 soon.

Thanks,
-Geliang

> > 
> > I'm seeing this error message when running `test_sockmap`:
> > 
> > detected skb data error with skb ingress update @iov[0]:0 "00 00 00
> > 00" != "PASS"
> > data verify msg failed: Unknown error -5
> > rx thread exited with err 1.
> 
> I have a theory this is a real bug in the SK_SKB_STREAM_PARSER which
> has an
> issue with wakup logic. Maybe we wakeup the poll/select logic before
> the
> data is copied and because the recv() is actually nonblocking now we
> get
> the error.
> 
> > 
> > I'd also:
> > - add an error check for fnctl, so we don't regress,
> > - get rid of fd_flags, pass O_NONBLOCK flag directly to fnctl.
> > 
> > Thanks,
> > -jkbs
> 
>
John Fastabend April 5, 2024, 4:47 a.m. UTC | #5
Geliang Tang wrote:
> Hi Jakub,
>  
> On Wed, 2024-04-03 at 15:29 -0700, John Fastabend wrote:
> > Jakub Sitnicki wrote:
> > > Hi Geliang,
> > > 
> > > On Wed, Apr 03, 2024 at 04:32 PM +08, 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.
> > > > 
> > > > Fixes: 16962b2404ac ("bpf: sockmap, add selftests")
> > > > Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> > > > ---
> > > >  tools/testing/selftests/bpf/test_sockmap.c | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > 
> > > > diff --git a/tools/testing/selftests/bpf/test_sockmap.c
> > > > b/tools/testing/selftests/bpf/test_sockmap.c
> > > > index 024a0faafb3b..34d6a1e6f664 100644
> > > > --- a/tools/testing/selftests/bpf/test_sockmap.c
> > > > +++ b/tools/testing/selftests/bpf/test_sockmap.c
> > > > @@ -603,7 +603,7 @@ static int msg_loop(int fd, int iov_count,
> > > > int iov_length, int cnt,
> > > >  		struct timeval timeout;
> > > >  		fd_set w;
> > > >  
> > > > -		fcntl(fd, fd_flags);
> > > > +		fcntl(fd, F_SETFL, fd_flags);
> > > >  		/* 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
> > > 
> > > Good catch. But we also need to figure out why some tests failing
> > > with
> > > this patch applied and fix them in one go:
> > > 
> > > # 6/ 7  sockmap::txmsg test skb:FAIL
> > > #21/ 7 sockhash::txmsg test skb:FAIL
> > > #36/ 7 sockhash:ktls:txmsg test skb:FAIL
> > > Pass: 42 Fail: 3
> 
> Sorry, I didn't notice these fails in my testing before, they do exist.
> I'll try to fix them and sent a v2 soon.

Not 100% sure but a hint. I would look into where the stream parser
is waking up the sock here. I'm not sure there is an easy fix tbh.
I can help look at this soon as well if you don't beat me to a fix.

Thanks for looking into it.

> 
> Thanks,
> -Geliang
Geliang Tang April 7, 2024, 8:29 a.m. UTC | #6
On Thu, 2024-04-04 at 21:47 -0700, John Fastabend wrote:
> Geliang Tang wrote:
> > Hi Jakub,
> >  
> > On Wed, 2024-04-03 at 15:29 -0700, John Fastabend wrote:
> > > Jakub Sitnicki wrote:
> > > > Hi Geliang,
> > > > 
> > > > On Wed, Apr 03, 2024 at 04:32 PM +08, 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.
> > > > > 
> > > > > Fixes: 16962b2404ac ("bpf: sockmap, add selftests")
> > > > > Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> > > > > ---
> > > > >  tools/testing/selftests/bpf/test_sockmap.c | 2 +-
> > > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > > 
> > > > > diff --git a/tools/testing/selftests/bpf/test_sockmap.c
> > > > > b/tools/testing/selftests/bpf/test_sockmap.c
> > > > > index 024a0faafb3b..34d6a1e6f664 100644
> > > > > --- a/tools/testing/selftests/bpf/test_sockmap.c
> > > > > +++ b/tools/testing/selftests/bpf/test_sockmap.c
> > > > > @@ -603,7 +603,7 @@ static int msg_loop(int fd, int
> > > > > iov_count,
> > > > > int iov_length, int cnt,
> > > > >  		struct timeval timeout;
> > > > >  		fd_set w;
> > > > >  
> > > > > -		fcntl(fd, fd_flags);
> > > > > +		fcntl(fd, F_SETFL, fd_flags);
> > > > >  		/* 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
> > > > 
> > > > Good catch. But we also need to figure out why some tests
> > > > failing
> > > > with
> > > > this patch applied and fix them in one go:
> > > > 
> > > > # 6/ 7  sockmap::txmsg test skb:FAIL
> > > > #21/ 7 sockhash::txmsg test skb:FAIL
> > > > #36/ 7 sockhash:ktls:txmsg test skb:FAIL
> > > > Pass: 42 Fail: 3
> > 
> > Sorry, I didn't notice these fails in my testing before, they do
> > exist.
> > I'll try to fix them and sent a v2 soon.
> 
> Not 100% sure but a hint. I would look into where the stream parser
> is waking up the sock here. I'm not sure there is an easy fix tbh.
> I can help look at this soon as well if you don't beat me to a fix.
> 
> Thanks for looking into it.

I just sent a v2, please review it for me.

Thanks,
-Geliang

> 
> > 
> > Thanks,
> > -Geliang
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c
index 024a0faafb3b..34d6a1e6f664 100644
--- a/tools/testing/selftests/bpf/test_sockmap.c
+++ b/tools/testing/selftests/bpf/test_sockmap.c
@@ -603,7 +603,7 @@  static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
 		struct timeval timeout;
 		fd_set w;
 
-		fcntl(fd, fd_flags);
+		fcntl(fd, F_SETFL, fd_flags);
 		/* 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