Skip to contentSkip to conversation

Add F_SETFL for fcntl

PATCH Superseded Geliang Tang 4 participants 7 messages Apr 8, 2024

Subsystems (4)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

v3 cover Add F_SETFL for fcntl

From: Geliang Tang <[email protected]>

Two fixes for test_sockmap:

Patch 1, v3 of "selftests/bpf: Add F_SETFL for fcntl":
- detect nonblock flag automaticly, then test_sockmap can run in both block and nonblock modes.
- use continue instead of again in v2.

Patch 2, fix for umount cgroup2 error.

Geliang Tang (2):
selftests/bpf: Add F_SETFL for fcntl in test_sockmap selftests/bpf: Fix umount cgroup2 error in test_sockmap

 tools/testing/selftests/bpf/test_sockmap.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Signature · 1 line
2.40.1
author reviewer
#1 lore raw

PATCH v3 1/2 selftests/bpf: Add F_SETFL for fcntl in test_sockmap

From: Geliang Tang <[email protected]>

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 will fail.

Fixes 16962b2404ac ("bpf: sockmap, add selftests")
---
 tools/testing/selftests/bpf/test_sockmap.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/test_sockmap.c +4 -1
index 024a0faafb3b..4f32a5eb3864 100644
@@ -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
@@ -678,6 +678,9 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
 					perror("recv failed()");
 					goto out_errno;
 				}
+				fd_flags = fcntl(fd, F_GETFL);
+				if (fd_flags & O_NONBLOCK)
+					continue;
 			}
 
 			s->bytes_recvd += recv;
Signature · 1 line
2.40.1
reviewer Acked-by on v3 1/2
#2 lore raw

Re: [PATCH bpf-next v3 1/2] selftests/bpf: Add F_SETFL for fcntl in test_sockmap

Quoted 8 lines · Geliang Tang

From: Geliang Tang <[email protected]>

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.

Quoted 5 lines

In nonblock mode, if EWOULDBLOCK is received, continue receiving, otherwise some subtests of test_sockmap will fail.

Fixes 16962b2404ac ("bpf: sockmap, add selftests")
#3 lore raw

Re: [PATCH bpf-next v3 1/2] selftests/bpf: Add F_SETFL for fcntl in test_sockmap

In reply to Geliang Tang
Quoted 22 lines · Geliang Tang

From: Geliang Tang <[email protected]>

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 will fail.

Fixes 16962b2404ac ("bpf: sockmap, add selftests")
---
  tools/testing/selftests/bpf/test_sockmap.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/test_sockmap.c +0 -0
index 024a0faafb3b..4f32a5eb3864 100644

tools/testing/selftests/bpf/test_sockmap.c static int msg_loop(int fd, int iov_count, int iov_length, int cnt, · line 606

Quoted 5 lines
tools/testing/selftests/bpf/test_sockmap.c +1 -1
@@ -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);

Should it just error out here if fcntl did fail (unlikely?) ...

tools/testing/selftests/bpf/test_sockmap.c static int msg_loop(int fd, int iov_count, int iov_length, int cnt, · line 682

Quoted 9 lines
tools/testing/selftests/bpf/test_sockmap.c +2 -0
  		/* 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 +678,9 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
  					perror("recv failed()");
  					goto out_errno;
  				}
+				fd_flags = fcntl(fd, F_GETFL);
+				if (fd_flags & O_NONBLOCK)

... then no need to test fd_flags here?

pw-bot: cr

Quoted 4 lines
tools/testing/selftests/bpf/test_sockmap.c +1 -0
+					continue;
  			}
 
  			s->bytes_recvd += recv;
author reviewer
#4 lore raw

PATCH v3 2/2 selftests/bpf: Fix umount cgroup2 error in test_sockmap

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

This patch fixes the following "umount cgroup2" error in test_sockmap.c:

(cgroup_helpers.c:353: errno: Device or resource busy) umount cgroup2

Cgroup fd cg_fd should be closed before cleanup_cgroup_environment().

Fixes 13a5f3ffd202 ("bpf: Selftests, sockmap test prog run without setting cgroup")
---
 tools/testing/selftests/bpf/test_sockmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/test_sockmap.c +1 -1
index 4f32a5eb3864..520b7d0dadda 100644
@@ -2107,9 +2107,9 @@ int main(int argc, char **argv)
 		free(options.whitelist);
 	if (options.blacklist)
 		free(options.blacklist);
+	close(cg_fd);
 	if (cg_created)
 		cleanup_cgroup_environment();
-	close(cg_fd);
 	return err;
 }
 
Signature · 1 line
2.40.1
reviewer Acked-by on v3 2/2
#5 lore raw

Re: [PATCH bpf-next v3 2/2] selftests/bpf: Fix umount cgroup2 error in test_sockmap

Quoted 10 lines · Geliang Tang

From: Geliang Tang <[email protected]>

This patch fixes the following "umount cgroup2" error in test_sockmap.c:

(cgroup_helpers.c:353: errno: Device or resource busy) umount cgroup2

Cgroup fd cg_fd should be closed before cleanup_cgroup_environment().

Fixes 13a5f3ffd202 ("bpf: Selftests, sockmap test prog run without setting cgroup")
#6 lore raw
In reply to Geliang Tang

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: Unstable: 1 failed test(s): packetdrill_sockopts 🔴
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/8593412186

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

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)