diff mbox series

[bpf,v4,1/2] selftests/bpf: Add F_SETFL for fcntl in test_sockmap

Message ID e4efa52c26ca5ae97c7e4e7570d8da9cd44df533.1712639568.git.tanggeliang@kylinos.cn (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series Two fixes for test_sockmap | expand

Checks

Context Check Description
bpf/vmtest-bpf-PR success PR summary
bpf/vmtest-bpf-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-VM_Test-17 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-VM_Test-18 success Logs for set-matrix
bpf/vmtest-bpf-VM_Test-19 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-VM_Test-20 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-VM_Test-34 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-VM_Test-26 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-28 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-VM_Test-35 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-VM_Test-41 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-VM_Test-42 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-16 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-VM_Test-22 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-21 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-25 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-27 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-VM_Test-33 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for bpf
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 1 maintainers not CCed: linux-kselftest@vger.kernel.org
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 17 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-VM_Test-36 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18 and -O2 optimization
bpf/vmtest-bpf-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-VM_Test-13 success Logs for s390x-gcc / test (test_maps, false, 360) / test_maps on s390x with gcc
bpf/vmtest-bpf-VM_Test-15 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-VM_Test-29 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17 and -O2 optimization
bpf/vmtest-bpf-VM_Test-14 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc

Commit Message

Geliang Tang April 9, 2024, 5:18 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.

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(-)

Comments

Martin KaFai Lau April 11, 2024, 6:10 p.m. UTC | #1
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.

Patch 2 looks good. Only patch 2 is applied. Thanks.

>   			}
>   
>   			s->bytes_recvd += recv;
Geliang Tang April 17, 2024, 8:14 a.m. UTC | #2
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;
Martin KaFai Lau April 18, 2024, 12:28 a.m. UTC | #3
On 4/17/24 1:14 AM, Geliang Tang wrote:
> 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.

I don't know what is the correct expectation also. John and JakubS, can you take 
a look?
Geliang Tang April 23, 2024, 10:28 a.m. UTC | #4
On Wed, 2024-04-17 at 17:28 -0700, Martin KaFai Lau wrote:
> On 4/17/24 1:14 AM, Geliang Tang wrote:
> > 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.
> 
> I don't know what is the correct expectation also. John and JakubS,
> can you take 
> a look?

Hello,
New version v5 has been sent. Please review it for me.

Thanks,
-Geliang
Jakub Sitnicki April 25, 2024, 12:26 p.m. UTC | #5
On Tue, Apr 23, 2024 at 12:29 PM Geliang Tang <geliang@kernel.org> wrote:
> New version v5 has been sent. Please review it for me.

Sorry for the long delay. I'm in between laptops. But I will take a
look this week.
diff mbox series

Patch

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;
 			}
 
 			s->bytes_recvd += recv;