misc fixes for sockopt selftests
Subsystems (3)
Geliang Tang
reviewerv3 cover misc fixes for sockopt selftests
From: Geliang Tang <[email protected]>
v3:
- close(pipefds[1]) in main() instead of process_one_client().
- close(pipefds[0]) on the server side too.
- patch 2 and patch 3 for -next
v2:
- patch 2: we should address this resource leak by adding the missing
close() calls on the server side, rather than by removing the correct
existing ones on the client side.
- patch 3: fix more error messages as Matt suggested.
- Link: https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
This patch series addresses several resource management issues in the MPTCP sockopt selftests.
Geliang Tang (3):
selftests: mptcp: sockopt: fix error messages
selftests: mptcp: close server file descriptors
selftests: mptcp: close server IPC descriptors
tools/testing/selftests/net/mptcp/mptcp_inq.c | 9 +++++-- .../selftests/net/mptcp/mptcp_sockopt.c | 25 +++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-)
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH v3 1/3 selftests: mptcp: sockopt: fix error messages
From: Geliang Tang <[email protected]>
This patch fixes several issues in the error reporting of the MPTCP sockopt selftest:
1. Fix diff not printed: The error messages for counter mismatches had the actual difference ('diff') as argument, but it was missing in the format string. Displaying it makes the debugging easier.
2. Fix variable usage: The error check for 'mptcpi_bytes_acked' incorrectly used 'ret2' (sent bytes) for both the expected value and the difference calculation. It now correctly uses 'ret' (received bytes), which is the expected value for bytes_acked.
3. Fix off-by-one in diff: The calculation for the 'mptcpi_rcv_delta' diff was 's.mptcpi_rcv_delta - ret', which is off-by-one. It has been corrected to 's.mptcpi_rcv_delta - (ret + 1)' to match the expected value in the condition above it.
--- .../testing/selftests/net/mptcp/mptcp_sockopt.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +10 -6
@@ -667,22 +667,26 @@ static void process_one_client(int fd, int pipefd)do_getsockopts (&s, fd, ret, ret2);if (s.mptcpi_rcv_delta != (uint64_t )ret +1 ) -xerror ("mptcpi_rcv_delta %" PRIu64", expect %" PRIu64, s.mptcpi_rcv_delta, ret +1 , s.mptcpi_rcv_delta - ret); +xerror ("mptcpi_rcv_delta %" PRIu64", expect %" PRIu64", diff %" PRId64, + s.mptcpi_rcv_delta, ret +1 , s.mptcpi_rcv_delta - (ret +1 ));/* be nice when running on top of older kernel */ if (s.pkt_stats_avail) {if (s.last_sample.mptcpi_bytes_sent != ret2) -xerror ("mptcpi_bytes_sent %" PRIu64", expect %" PRIu64, +xerror ("mptcpi_bytes_sent %" PRIu64", expect %" PRIu64 +", diff %" PRId64, s.last_sample.mptcpi_bytes_sent, ret2, s.last_sample.mptcpi_bytes_sent - ret2);if (s.last_sample.mptcpi_bytes_received != ret) -xerror ("mptcpi_bytes_received %" PRIu64", expect %" PRIu64, +xerror ("mptcpi_bytes_received %" PRIu64", expect %" PRIu64 +", diff %" PRId64, s.last_sample.mptcpi_bytes_received, ret, s.last_sample.mptcpi_bytes_received - ret);if (s.last_sample.mptcpi_bytes_acked != ret) -xerror ("mptcpi_bytes_acked %" PRIu64", expect %" PRIu64, - s.last_sample.mptcpi_bytes_acked, ret2, - s.last_sample.mptcpi_bytes_acked - ret2); +xerror ("mptcpi_bytes_acked %" PRIu64", expect %" PRIu64 +", diff %" PRId64, + s.last_sample.mptcpi_bytes_acked, ret, + s.last_sample.mptcpi_bytes_acked - ret); }close (fd);
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH v3 2/3 selftests: mptcp: close server file descriptors
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
The server file descriptor ('fd') is opened in server() but never closed. While accepted connections are properly closed in process_one_client(), the main listening socket remains open, causing a resource leak.
This patch ensures the server fd is properly closed after processing clients, bringing the sockopt and inq test cases in line with proper resource cleanup practices.
--- tools/testing/selftests/net/mptcp/mptcp_inq.c | 1 + tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 1 + 2 files changed, 2 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_inq.c +1 -0
@@ -502,6 +502,7 @@ static int server(int unixfd)process_one_client (r, unixfd); +close (fd);return 0 ; }
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +1 -0
@@ -726,6 +726,7 @@ static int server(int pipefd)process_one_client (r, pipefd); +close (fd);return 0 ; }
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH v3 3/3 selftests: mptcp: close server IPC descriptors
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
The client-side function connect_one_server() properly closes its IPC descriptor after use, but the server-side code in both mptcp_sockopt.c and mptcp_inq.c was missing corresponding close() calls for their IPC descriptors, leaving file descriptors open unnecessarily.
This change ensures proper cleanup by:
1. Adding missing close(pipefds[0]/unixfds[0]) in server processes
2. Adding close(pipefds[1]/unixfds[1]) after server() function calls
This ensures both ends of the IPC pipe are properly closed in their respective processes, preventing file descriptor leaks.
--- tools/testing/selftests/net/mptcp/mptcp_inq.c | 8 ++++++-- tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_inq.c +6 -2
@@ -581,8 +581,12 @@ int main(int argc, char *argv[])die_perror ("pipe" ); s =xfork (); -if (s ==0 ) -return server (unixfds[1 ]); +if (s ==0 ) { +close (unixfds[0 ]); + ret =server (unixfds[1 ]); +close (unixfds[1 ]); +return ret; + }close (unixfds[1 ]);
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +6 -2
@@ -852,8 +852,12 @@ int main(int argc, char *argv[])die_perror ("pipe" ); s =xfork (); -if (s ==0 ) -return server (pipefds[1 ]); +if (s ==0 ) { +close (pipefds[0 ]); + ret =server (pipefds[1 ]); +close (pipefds[1 ]); +return ret; + }close (pipefds[1 ]);
Signature · 1 line
2.48.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: Unstable: 1 failed test(s): packetdrill_mp_capable 🔴
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/17664113196
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/b2ddd676d6f6
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1001578
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-normalFor 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)
Hi Geliang,
Quoted 6 lines · Geliang Tang
From: Geliang Tang <[email protected]>
v3:
-close(pipefds[1])inmain()instead ofprocess_one_client().
-close(pipefds[0])on the server side too.
- patch 2 and patch 3 for -next
Thank you for the v3, it looks good to me:
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts
maintainerQuoted 11 lines · Matthieu Baerts
Hi Geliang,
Quoted 6 lines · Geliang Tang
From: Geliang Tang <[email protected]>
v3:
-close(pipefds[1])inmain()instead ofprocess_one_client().
-close(pipefds[0])on the server side too.
- patch 2 and patch 3 for -nextThank you for the v3, it looks good to me:
Now in our tree:
New patches for t/upstream-net and t/upstream:
- 7c7fe7c32111: selftests: mptcp: sockopt: fix error messages
- Results: 334d39b0b584..b48b45f8e99e (export-net)
- Results: 46669ecf1c8e..ed231f9fe47a (export)
New patches for t/upstream:
- eb209d77293c: selftests: mptcp: close server file descriptors
- e08574afdef6: selftests: mptcp: close server IPC descriptors
- Results: ed231f9fe47a..9436c7dff71b (export)
Tests are now in progress:
- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/7394e96db0aa6f0beb5d75295cff4a17a710539d/checks
- export-net:
https://github.com/multipath-tcp/mptcp_net-next/commit/fa24bbd5e317dc576d9918261ba2bd27235e3077/checks
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.