mptcp: add statistics for mptcp socket in use
Subsystems (3)
v8 cover mptcp: add statistics for mptcp socket in use
From: Menglong Dong <[email protected]>
In the 1th patch, we do some code cleanup with replease 'sock->sk' with 'sk'. In the 2th patch, we add statistics for mptcp socket in use. In the 3th patch, we make mptcp_connect can exit when receive 'SIGUSR1' with '-r' flag. And in the 4th patch, we add the testing for this commit.
With the commit e8695e504942("mptcp: don't orphan ssk in mptcp_close()"), I belive that the testing of diag.sh can pass now. In fallback and simultaneous close case, the msk can't release normal (sometimes?) without that commit, and makes the testing fail. Enn...let's just see that the CI is saying~
Changes since v7:
- remove the MPTCP_INUSE flag and do the statistics according to the creation and destruction of the token in the 2th patch.
Changes since v6:
- check all processes exit in flush_pids() in the 4th patch
Changes since v5:
- introduce MPTCP_INUSE flag to store if msk is in use, as I find that it's not correct to check is a msk is in use by !sk_unhashed(sk) in mptcp_destroy_common(), because the token can be release in mptcp_check_fastclose()
- add the 3th patch
- reuse __chk_nr in 4th patch
Changes since v4:
- rebase to solve merge conflict
Changes since v3:
- rename MPTCP_DESTROIED to MPTCP_DESTROYED in the 2th patch
Changes since v2:
- add testing
Changes since v1:
- split the code cleanup into the 1th patch.
- decrease the statistics for listening mptcp socket inuse with mptcp_listen_inuse_dec()
- add MPTCP_DESTROIED flags to store if mptcp_destroy_common() was called on the msk. For fallback case, we need to decrease the statistics only once, and mptcp_destroy_common() can be called more than once.
Menglong Dong (4):
mptcp: introduce 'sk' to replace 'sock->sk' in mptcp_listen()
mptcp: add statistics for mptcp socket in use
selftest: mptcp: exit from copyfd_io_poll() when receive SIGUSR1
selftest: mptcp: add test for mptcp socket in use
net/mptcp/protocol.c | 29 +++++++--- net/mptcp/token.c | 7 +++ tools/testing/selftests/net/mptcp/diag.sh | 56 +++++++++++++++++-- .../selftests/net/mptcp/mptcp_connect.c | 4 +- 4 files changed, 82 insertions(+), 14 deletions(-)
Signature · 1 line
2.37.2
PATCH v8 1/4 mptcp: introduce 'sk' to replace 'sock->sk' in mptcp_listen()
From: Menglong Dong <[email protected]>
'sock->sk' is used frequently in mptcp_listen(). Therefore, we can introduce the 'sk' and replace 'sock->sk' with it.
--- net/mptcp/protocol.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +7 -6
@@ -3656,12 +3656,13 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,static int mptcp_listen (struct socket *sock,int backlog) {struct mptcp_sock *msk =mptcp_sk (sock->sk); +struct sock *sk = sock->sk;struct socket *ssock;int err;pr_debug ("msk=%p" , msk); -lock_sock (sock->sk); +lock_sock (sk); ssock =__mptcp_nmpc_socket (msk);if (!ssock) { err = -EINVAL ;
@@ -3669,18 +3670,18 @@ static int mptcp_listen(struct socket *sock, int backlog) }mptcp_token_destroy (msk); -inet_sk_state_store (sock->sk,TCP_LISTEN ); -sock_set_flag (sock->sk,SOCK_RCU_FREE ); +inet_sk_state_store (sk,TCP_LISTEN ); +sock_set_flag (sk,SOCK_RCU_FREE ); err = ssock->ops->listen (ssock, backlog); -inet_sk_state_store (sock->sk,inet_sk_state_load (ssock->sk)); +inet_sk_state_store (sk,inet_sk_state_load (ssock->sk));if (!err) -mptcp_copy_inaddrs (sock->sk, ssock->sk); +mptcp_copy_inaddrs (sk, ssock->sk);mptcp_event_pm_listener (ssock->sk,MPTCP_EVENT_LISTENER_CREATED ); unlock: -release_sock (sock->sk); +release_sock (sk);return err; }
Signature · 1 line
2.37.2
PATCH v8 2/4 mptcp: add statistics for mptcp socket in use
In reply to [email protected]From: Menglong Dong <[email protected]>
Do the statistics of mptcp socket in use with sock_prot_inuse_add(). Therefore, we can get the count of used mptcp socket from /proc/net/protocols:
& cat /proc/net/protocols
protocol size sockets memory press maxhdr slab module cl co di ac io in de sh ss gs se re sp bi br ha uh gp em MPTCPv6 2048 0 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y n MPTCP 1896 1 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y n
---
v8:
- remove the MPTCP_INUSE flag and do the statistics according to the creation and destruction of the token
v6:
- introduce the 'MPTCP_INUSE' flag and check if msk is in use by it
v5:
- rebase to solve merge conflict
v4:
- rename MPTCP_DESTROIED to MPTCP_DESTROYED
v2:
- decrease the statistics for listening mptcp socket inuse with mptcp_listen_inuse_dec()
- add MPTCP_DESTROIED flags to store if mptcp_destroy_common() was called on the msk. For fallback case, we need to decrease the
--- net/mptcp/protocol.c | 16 +++++++++++++++- net/mptcp/token.c | 7 +++++++ 2 files changed, 22 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +15 -1
@@ -3005,6 +3005,16 @@ void mptcp_copy_inaddrs(struct sock *msk, const struct sock *ssk)inet_sk (msk)->inet_rcv_saddr =inet_sk (ssk)->inet_rcv_saddr; } +static void mptcp_listen_inuse_dec (struct sock *sk) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct socket *ssock; + + ssock =__mptcp_nmpc_socket (msk); +if (ssock &&inet_sk_state_load (ssock->sk) ==TCP_LISTEN ) +sock_prot_inuse_add (sock_net (sk), sk->sk_prot,-1 ); +} +static int mptcp_disconnect (struct sock *sk,int flags) {struct mptcp_sock *msk =mptcp_sk (sk);
@@ -3025,6 +3035,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)if (msk->token)mptcp_event (MPTCP_EVENT_CLOSED , msk,NULL ,GFP_KERNEL ); +mptcp_listen_inuse_dec (sk);/* msk->subflow is still intact, the following will not free the first * subflow */
@@ -3203,6 +3214,7 @@ static void mptcp_destroy(struct sock *sk) {struct mptcp_sock *msk =mptcp_sk (sk); +mptcp_listen_inuse_dec (sk);/* clears msk->subflow, allowing the following to close * even the initial subflow */
@@ -3675,8 +3687,10 @@ static int mptcp_listen(struct socket *sock, int backlog) err = ssock->ops->listen (ssock, backlog);inet_sk_state_store (sk,inet_sk_state_load (ssock->sk)); -if (!err) +if (!err) { +sock_prot_inuse_add (sock_net (sk), sk->sk_prot,1 );mptcp_copy_inaddrs (sk, ssock->sk); + }mptcp_event_pm_listener (ssock->sk,MPTCP_EVENT_LISTENER_CREATED );
net/mptcp/token.c +7 -0
@@ -175,6 +175,9 @@ int mptcp_token_new_connect(struct sock *sk)__sk_nulls_add_node_rcu ((struct sock *)msk, &bucket->msk_chain); bucket->chain_len++;spin_unlock_bh (&bucket->lock); +sock_prot_inuse_add (sock_net (subflow->conn), + subflow->conn->sk_prot, +1 );return 0 ; }
@@ -190,8 +193,10 @@ void mptcp_token_accept(struct mptcp_subflow_request_sock *req, struct mptcp_sock *msk) {struct mptcp_subflow_request_sock *pos; +struct sock *sk = (struct sock *)msk;struct token_bucket *bucket; +sock_prot_inuse_add (sock_net (sk), sk->sk_prot,1 ); bucket =token_bucket (req->token);spin_lock_bh (&bucket->lock);
@@ -370,12 +375,14 @@ void mptcp_token_destroy_request(struct request_sock *req)*/ void mptcp_token_destroy (struct mptcp_sock *msk) { +struct sock *sk = (struct sock *)msk;struct token_bucket *bucket;struct mptcp_sock *pos;if (sk_unhashed ((struct sock *)msk))return ; +sock_prot_inuse_add (sock_net (sk), sk->sk_prot,-1 ); bucket =token_bucket (msk->token);spin_lock_bh (&bucket->lock); pos =__token_lookup_msk (bucket, msk->token);
Signature · 1 line
2.37.2
Hi Menglong Dong,
Quoted 11 lines · On 08/12/2022 03:45, [email protected] wrote:
From: Menglong Dong <[email protected]>
Do the statistics of mptcp socket in use with
sock_prot_inuse_add(). Therefore, we can get the count of used mptcp socket from/proc/net/protocols:& cat
/proc/net/protocolsprotocol size sockets memory press maxhdr slab module cl co di ac io in de sh ss gs se re sp bi br ha uh gp em MPTCPv6 2048 0 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y n MPTCP 1896 1 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y n
Quoted 5 lines
Signed-off-by Menglong Dong <[email protected]>---
v8:
- remove theMPTCP_INUSEflag and do the statistics according to the creation and destruction of the token
Thank you for the new version!
I marked this series as "Changes Requested" on Patchwork because I guess you saw the CI was not happy with the KUnit token tests, e.g.:
- KVM Validation: normal (except selftest_mptcp_join):
- Unstable: 1 failed test(s): insmod - Critical: 3 Call Trace(s) ❌:
- Task: https://cirrus-ci.com/task/5270512411082752
- Summary:
https://api.cirrus-ci.com/v1/artifact/task/5270512411082752/summary/summary.txt
- Debug: https://cirrus-ci.com/task/4989037434372096
Do you mind looking at that please?
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net
Quoted 26 lines · Matthieu Baerts
Hi Menglong Dong,
Quoted 11 lines · On 08/12/2022 03:45, [email protected] wrote:
From: Menglong Dong <[email protected]>
Do the statistics of mptcp socket in use with
sock_prot_inuse_add(). Therefore, we can get the count of used mptcp socket from/proc/net/protocols:& cat
/proc/net/protocolsprotocol size sockets memory press maxhdr slab module cl co di ac io in de sh ss gs se re sp bi br ha uh gp em MPTCPv6 2048 0 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y n MPTCP 1896 1 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y nQuoted 5 lines
Signed-off-by Menglong Dong <[email protected]>---
v8:
- remove theMPTCP_INUSEflag and do the statistics according to the creation and destruction of the tokenThank you for the new version!
I marked this series as "Changes Requested" on Patchwork because I guess you saw the CI was not happy with the KUnit token tests, e.g.:
Quoted 9 lines
- KVM Validation: normal (except
selftest_mptcp_join):
- Unstable: 1 failed test(s): insmod - Critical: 3 Call Trace(s) ❌:
- Task: https://cirrus-ci.com/task/5270512411082752
- Summary:
https://api.cirrus-ci.com/v1/artifact/task/5270512411082752/summary/summary.txt
- Debug: https://cirrus-ci.com/task/4989037434372096Do you mind looking at that please?
Of course! I'll run all of the tests to make sure they pass.
Quoted 5 lines
Cheers,
Matt
--
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
Paolo Abeni
maintainerQuoted 41 lines · On Thu, 2022-12-08 at 10:45 +0800, [email protected] wrote:
From: Menglong Dong <[email protected]>
Do the statistics of mptcp socket in use with
sock_prot_inuse_add(). Therefore, we can get the count of used mptcp socket from/proc/net/protocols:& cat
/proc/net/protocolsprotocol size sockets memory press maxhdr slab module cl co di ac io in de sh ss gs se re sp bi br ha uh gp em MPTCPv6 2048 0 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y n MPTCP 1896 1 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y nSigned-off-by Menglong Dong <[email protected]>---
v8:
- remove theMPTCP_INUSEflag and do the statistics according to the creation and destruction of the tokenv6:
- introduce the 'MPTCP_INUSE' flag and check if msk is in use by itv5:
- rebase to solve merge conflictv4:
- renameMPTCP_DESTROIEDtoMPTCP_DESTROYEDv2:
- decrease the statistics for listening mptcp socket inuse withmptcp_listen_inuse_dec()
- addMPTCP_DESTROIEDflags to store ifmptcp_destroy_common()was called on the msk. For fallback case, we need to decrease the--- net/mptcp/protocol.c | 16 +++++++++++++++- net/mptcp/token.c | 7 +++++++ 2 files changed, 22 insertions(+), 1 deletion(-)net/mptcp/protocol.c +0
-0
net/mptcp/protocol.c void mptcp_copy_inaddrs(struct sock *msk, const struct sock *ssk) · line 3014
Quoted 10 lines
net/mptcp/protocol.c +7
-0@@ -3005,6 +3005,16 @@ void mptcp_copy_inaddrs(struct sock *msk, const struct sock *ssk)inet_sk (msk)->inet_rcv_saddr =inet_sk (ssk)->inet_rcv_saddr; } +static void mptcp_listen_inuse_dec (struct sock *sk) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct socket *ssock; + + ssock =__mptcp_nmpc_socket (msk); +if (ssock &&inet_sk_state_load (ssock->sk) ==TCP_LISTEN )
Here I think you can check directly: sk->sk_state == TCP_LISTEN, which should be both simpler and safer, since this should be called under the (m)sk socket lock.
It would be nice adding a comment describing why the state check is needed, e.g.
/* Listener sockets do not have a valid token, but we need to * account them, too. */
Other then that, LGTM.
Cheers,
Paolo
Hello,
Quoted 46 lines · Paolo Abeni
Quoted 44 lines · On Thu, 2022-12-08 at 10:45 +0800, [email protected] wrote:
From: Menglong Dong <[email protected]>
Do the statistics of mptcp socket in use with
sock_prot_inuse_add(). Therefore, we can get the count of used mptcp socket from/proc/net/protocols:& cat
/proc/net/protocolsprotocol size sockets memory press maxhdr slab module cl co di ac io in de sh ss gs se re sp bi br ha uh gp em MPTCPv6 2048 0 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y n MPTCP 1896 1 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y nSigned-off-by Menglong Dong <[email protected]>---
v8:
- remove theMPTCP_INUSEflag and do the statistics according to the creation and destruction of the tokenv6:
- introduce the 'MPTCP_INUSE' flag and check if msk is in use by itv5:
- rebase to solve merge conflictv4:
- renameMPTCP_DESTROIEDtoMPTCP_DESTROYEDv2:
- decrease the statistics for listening mptcp socket inuse withmptcp_listen_inuse_dec()
- addMPTCP_DESTROIEDflags to store ifmptcp_destroy_common()was called on the msk. For fallback case, we need to decrease the--- net/mptcp/protocol.c | 16 +++++++++++++++- net/mptcp/token.c | 7 +++++++ 2 files changed, 22 insertions(+), 1 deletion(-)net/mptcp/protocol.c +0
-0@@ -3005,6 +3005,16 @@ void mptcp_copy_inaddrs(struct sock *msk, const struct sock *ssk)inet_sk (msk)->inet_rcv_saddr =inet_sk (ssk)->inet_rcv_saddr; }
Quoted 12 lines
net/mptcp/protocol.c void mptcp_copy_inaddrs(struct sock *msk, const struct sock *ssk) · line 3014
Quoted 7 lines
net/mptcp/protocol.c +7
-0+static void mptcp_listen_inuse_dec (struct sock *sk) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct socket *ssock; + + ssock =__mptcp_nmpc_socket (msk); +if (ssock &&inet_sk_state_load (ssock->sk) ==TCP_LISTEN )Here I think you can check directly:
sk->sk_state==TCP_LISTEN, which should be both simpler and safer, since this should be called under the (m)sk socket lock.
Then, mptcp_listen_inuse_dec() needs to be called before msk enters TCP_CLOSE state, which means __mptcp_close() and mptcp_disconnect(). Do I miss any case that a listening msk enters TCP_CLOSE state?
Quoted 7 lines
It would be nice adding a comment describing why the state check is needed, e.g.
/* Listener sockets do not have a valid token, but we need to * account them, too. */
Sounds nice!
Quoted 6 lines
Other then that, LGTM.
Cheers,
Paolo
Paolo Abeni
maintainerQuoted 62 lines · Menglong Dong
Hello,
Quoted 46 lines · Paolo Abeni
Quoted 44 lines · On Thu, 2022-12-08 at 10:45 +0800, [email protected] wrote:
From: Menglong Dong <[email protected]>
Do the statistics of mptcp socket in use with
sock_prot_inuse_add(). Therefore, we can get the count of used mptcp socket from/proc/net/protocols:& cat
/proc/net/protocolsprotocol size sockets memory press maxhdr slab module cl co di ac io in de sh ss gs se re sp bi br ha uh gp em MPTCPv6 2048 0 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y n MPTCP 1896 1 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y nSigned-off-by Menglong Dong <[email protected]>---
v8:
- remove theMPTCP_INUSEflag and do the statistics according to the creation and destruction of the tokenv6:
- introduce the 'MPTCP_INUSE' flag and check if msk is in use by itv5:
- rebase to solve merge conflictv4:
- renameMPTCP_DESTROIEDtoMPTCP_DESTROYEDv2:
- decrease the statistics for listening mptcp socket inuse withmptcp_listen_inuse_dec()
- addMPTCP_DESTROIEDflags to store ifmptcp_destroy_common()was called on the msk. For fallback case, we need to decrease the--- net/mptcp/protocol.c | 16 +++++++++++++++- net/mptcp/token.c | 7 +++++++ 2 files changed, 22 insertions(+), 1 deletion(-)net/mptcp/protocol.c +0
-0@@ -3005,6 +3005,16 @@ void mptcp_copy_inaddrs(struct sock *msk, const struct sock *ssk)inet_sk (msk)->inet_rcv_saddr =inet_sk (ssk)->inet_rcv_saddr; }Quoted 12 lines
net/mptcp/protocol.c void mptcp_copy_inaddrs(struct sock *msk, const struct sock *ssk) · line 3014
Quoted 7 lines
net/mptcp/protocol.c +7
-0+static void mptcp_listen_inuse_dec (struct sock *sk) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct socket *ssock; + + ssock =__mptcp_nmpc_socket (msk); +if (ssock &&inet_sk_state_load (ssock->sk) ==TCP_LISTEN )Here I think you can check directly:
sk->sk_state==TCP_LISTEN, which should be both simpler and safer, since this should be called under the (m)sk socket lock.
Quoted 4 lines
Then,
mptcp_listen_inuse_dec()needs to be called before msk entersTCP_CLOSEstate, which means__mptcp_close()and mptcp_disconnect(). Do I miss any case that a listening msk entersTCP_CLOSEstate?
AFAIK, that is correct. Note that the number of hooks will not change compared to the current patch revision (mptcp_disconnect() + mptcp_destroy()).
Cheers,
Paolo
Hello,
Quoted 64 lines · Paolo Abeni
Quoted 62 lines · Menglong Dong
Hello,
Quoted 58 lines · Paolo Abeni
Quoted 41 lines · On Thu, 2022-12-08 at 10:45 +0800, [email protected] wrote:
From: Menglong Dong <[email protected]>
Do the statistics of mptcp socket in use with
sock_prot_inuse_add(). Therefore, we can get the count of used mptcp socket from/proc/net/protocols:& cat
/proc/net/protocolsprotocol size sockets memory press maxhdr slab module cl co di ac io in de sh ss gs se re sp bi br ha uh gp em MPTCPv6 2048 0 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y n MPTCP 1896 1 0 no 0 yes kernel y n y y y y y y y y y y n n n y y y nSigned-off-by Menglong Dong <[email protected]>---
v8:
- remove theMPTCP_INUSEflag and do the statistics according to the creation and destruction of the tokenv6:
- introduce the 'MPTCP_INUSE' flag and check if msk is in use by itv5:
- rebase to solve merge conflictv4:
- renameMPTCP_DESTROIEDtoMPTCP_DESTROYEDv2:
- decrease the statistics for listening mptcp socket inuse withmptcp_listen_inuse_dec()
- addMPTCP_DESTROIEDflags to store ifmptcp_destroy_common()was called on the msk. For fallback case, we need to decrease the--- net/mptcp/protocol.c | 16 +++++++++++++++- net/mptcp/token.c | 7 +++++++ 2 files changed, 22 insertions(+), 1 deletion(-)net/mptcp/protocol.c +0
-0net/mptcp/protocol.c void mptcp_copy_inaddrs(struct sock *msk, const struct sock *ssk) · line 3014
Quoted 10 lines
net/mptcp/protocol.c +7
-0@@ -3005,6 +3005,16 @@ void mptcp_copy_inaddrs(struct sock *msk, const struct sock *ssk)inet_sk (msk)->inet_rcv_saddr =inet_sk (ssk)->inet_rcv_saddr; } +static void mptcp_listen_inuse_dec (struct sock *sk) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct socket *ssock; + + ssock =__mptcp_nmpc_socket (msk); +if (ssock &&inet_sk_state_load (ssock->sk) ==TCP_LISTEN )Here I think you can check directly:
sk->sk_state==TCP_LISTEN, which should be both simpler and safer, since this should be called under the (m)sk socket lock.
Quoted 9 lines
Quoted 4 lines
Then,
mptcp_listen_inuse_dec()needs to be called before msk entersTCP_CLOSEstate, which means__mptcp_close()andmptcp_disconnect(). Do I miss any case that a listening msk entersTCP_CLOSEstate?AFAIK, that is correct. Note that the number of hooks will not change compared to the current patch revision (
mptcp_disconnect()+mptcp_destroy()).
With the changes you suggested, I need to the move mptcp_listen_inuse_dec() that called in mptcp_destroy() to __mptcp_close(), as msk is already in CLOSE state in mptcp_destroy(). Isn't it?
Thanks!
Menglong Dong
Quoted 5 lines
Cheers,
Paolo
Paolo Abeni
maintainernet/mptcp/token.c int mptcp_token_new_connect(struct sock *sk) · line 180
Quoted 11 lines · On Thu, 2022-12-08 at 10:45 +0800, [email protected] wrote:
net/mptcp/token.c +3
-0@@ -175,6 +175,9 @@ int mptcp_token_new_connect(struct sock *sk)__sk_nulls_add_node_rcu ((struct sock *)msk, &bucket->msk_chain); bucket->chain_len++;spin_unlock_bh (&bucket->lock); +sock_prot_inuse_add (sock_net (subflow->conn), + subflow->conn->sk_prot, +1 );
Whoops, sorry for not noticing the above earlier...
Here it would be better rename the mptcp_token_new_connect argument to 'ssk', and add a new local variable:
struct sock *sk = subflow->conn;
and replace the '(struct sock *)msk', 'subflow->conn' above with 'sk'.
Side note: the kunit crash is due to build_icsk() being too naive: it creates a completely zeroed inet_connection_sock, while after this patch mptcp_token_new_connect() requires that the sk_prot field is initialized, too.
The issue could be addresses with an addtional chunk in token_test.c. Note that for token's test sake, sk_prot could be initialized to any available/already exported proto.
---
net/mptcp/token_test.c +3 -0
@@ -36,6 +36,9 @@ static struct inet_connection_sock *build_icsk(struct kunit *test) icsk =kunit_kzalloc (test,sizeof (struct inet_connection_sock ),GFP_USER );KUNIT_EXPECT_NOT_ERR_OR_NULL (test, icsk); + +/* be sure the tocken helpers can dereference sk->sk_prot */ + icsk->icsk_inet.sk.sk_prot = &tcp_prot;return icsk; }
Quoted 18 lines · Paolo Abeni
net/mptcp/token.c int mptcp_token_new_connect(struct sock *sk) · line 180
Quoted 11 lines · On Thu, 2022-12-08 at 10:45 +0800, [email protected] wrote:
net/mptcp/token.c +3
-0@@ -175,6 +175,9 @@ int mptcp_token_new_connect(struct sock *sk)__sk_nulls_add_node_rcu ((struct sock *)msk, &bucket->msk_chain); bucket->chain_len++;spin_unlock_bh (&bucket->lock); +sock_prot_inuse_add (sock_net (subflow->conn), + subflow->conn->sk_prot, +1 );Whoops, sorry for not noticing the above earlier...
Here it would be better rename themptcp_token_new_connectargument to 'ssk', and add a new local variable:
Quoted 4 lines
struct sock *sk = subflow->conn;and replace the '(struct sock *)msk', '
subflow->conn' above with 'sk'.
Okay!
Quoted 14 lines
Side note: the kunit crash is due to
build_icsk()being too naive: it creates a completely zeroedinet_connection_sock, while after this patchmptcp_token_new_connect()requires that thesk_protfield is initialized, too.The issue could be addresses with an addtional chunk in
token_test.c. Note that for token's test sake,sk_protcould be initialized to any available/already exported proto.
---net/mptcp/token_test.c +0
-0
net/mptcp/token_test.c static struct inet_connection_sock *build_icsk(struct kunit *test) · line 44
Quoted 9 lines
net/mptcp/token_test.c +3
-0@@ -36,6 +36,9 @@ static struct inet_connection_sock *build_icsk(struct kunit *test) icsk =kunit_kzalloc (test,sizeof (struct inet_connection_sock ),GFP_USER );KUNIT_EXPECT_NOT_ERR_OR_NULL (test, icsk); + +/* be sure the tocken helpers can dereference sk->sk_prot */ + icsk->icsk_inet.sk.sk_prot = &tcp_prot;return icsk; }
Get it! Thanks~
Menglong Dong
Quoted 1 line
PATCH v8 3/4 selftest: mptcp: exit from copyfd_io_poll() when receive SIGUSR1
In reply to [email protected]From: Menglong Dong <[email protected]>
For now, mptcp_connect won't exit after receiving the 'SIGUSR1' signal if '-r' is set. Fix this by skipping poll and sleep in copyfd_io_poll() if 'quit' is set.
--- tools/testing/selftests/net/mptcp/mptcp_connect.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_connect.c +2 -2
@@ -627,7 +627,7 @@ static int copyfd_io_poll(int infd, int peerfd, int outfd,char rbuf[8192 ];ssize_t len; -if (fds.events ==0 ) +if (fds.events ==0 || quit)break ;switch (poll (&fds,1 , poll_timeout)) {
@@ -733,7 +733,7 @@ static int copyfd_io_poll(int infd, int peerfd, int outfd, }/* leave some time for late join/announce */ -if (cfg_remove) +if (cfg_remove && !quit)usleep (cfg_wait);return 0 ;
Signature · 1 line
2.37.2
PATCH v8 4/4 selftest: mptcp: add test for mptcp socket in use
In reply to [email protected]From: Menglong Dong <[email protected]>
Add the function chk_msk_inuse() to diag.sh, which is used to check the statistics of mptcp socket in use. As mptcp socket in listen state will be closed randomly after 'accept', we need to get the count of listening mptcp socket through 'ss' command.
All tests pass.
---
v7:
- check all processes exit in flush_pids()
--- tools/testing/selftests/net/mptcp/diag.sh | 56 +++++++++++++++++++++-- 1 file changed, 51 insertions(+), 5 deletions(-)
tools/testing/selftests/net/mptcp/diag.sh +51 -5
@@ -17,6 +17,11 @@ flush_pids() sleep 1.1 ip netns pids "${ns}" | xargs --no-run-if-empty kill -SIGUSR1 &>/dev/null + + for _ in $(seq 10); do + [ -z "$(ip netns pids "${ns}")" ] && break + sleep 0.1 + done } cleanup()
@@ -37,15 +42,20 @@ if [ $? -ne 0 ];then exit $ksft_skip fi +get_msk_inuse() +{ + ip netns exec $ns cat /proc/net/protocols | awk '$1~/^MPTCP$/{print $3}' +} + __chk_nr() { - local condition="$1" + local command="$1" local expected=$2 local msg nr shift 2 msg=$* - nr=$(ss -inmHMN $ns | $condition) + nr=$(eval $command) printf "%-50s" "$msg" if [ $nr != $expected ]; then
@@ -57,9 +67,17 @@ __chk_nr() test_cnt=$((test_cnt+1)) } +__chk_msk_nr() +{ + local condition=$1 + shift 1 + + __chk_nr "ss -inmHMN $ns | $condition" $* +} + chk_msk_nr() { - __chk_nr "grep -c token:" $* + __chk_msk_nr "grep -c token:" $* } wait_msk_nr()
@@ -97,12 +115,12 @@ wait_msk_nr() chk_msk_fallback_nr() { - __chk_nr "grep -c fallback" $* + __chk_msk_nr "grep -c fallback" $* } chk_msk_remote_key_nr() { - __chk_nr "grep -c remote_key" $* + __chk_msk_nr "grep -c remote_key" $* } __chk_listen()
@@ -142,6 +160,26 @@ chk_msk_listen() nr=$(ss -Ml $filter | wc -l) } +chk_msk_inuse() +{ + local expected=$1 + local listen_nr + + shift 1 + + listen_nr=$(ss -N "${ns}" -Ml | grep -c LISTEN) + expected=$((expected + listen_nr)) + + for _ in $(seq 10); do + if [ $(get_msk_inuse) -eq $expected ];then + break + fi + sleep 0.1 + done + + __chk_nr get_msk_inuse $expected $* +} + # $1: ns, $2: port wait_local_port_listen() {
@@ -195,8 +233,10 @@ wait_connected $ns 10000 chk_msk_nr 2 "after MPC handshake " chk_msk_remote_key_nr 2 "....chk remote_key" chk_msk_fallback_nr 0 "....chk no fallback" +chk_msk_inuse 2 "....chk 2 msk in use" flush_pids +chk_msk_inuse 0 "....chk 0 msk in use after flush" echo "a" | \ timeout ${timeout_test} \
@@ -211,8 +251,11 @@ echo "b" | \ 127.0.0.1 >/dev/null & wait_connected $ns 10001 chk_msk_fallback_nr 1 "check fallback" +chk_msk_inuse 1 "....chk 1 msk in use" flush_pids +chk_msk_inuse 0 "....chk 0 msk in use after flush" + NR_CLIENTS=100 for I in `seq 1 $NR_CLIENTS`; do echo "a" | \
@@ -232,6 +275,9 @@ for I in `seq 1 $NR_CLIENTS`; do done wait_msk_nr $((NR_CLIENTS*2)) "many msk socket present" +chk_msk_inuse $((NR_CLIENTS*2)) "....chk many msk in use" flush_pids +chk_msk_inuse 0 "....chk 0 msk in use after flush" + exit $ret
Signature · 1 line
2.37.2
Re: selftest: mptcp: add test for mptcp socket in use: Tests Results
Hi Menglong,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join):
- Unstable: 1 failed test(s): insmod - Critical: 3 Call Trace(s) ❌:
- Task: https://cirrus-ci.com/task/5270512411082752
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5270512411082752/summary/summary.txt
- KVM Validation: normal (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/6396412317925376
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6396412317925376/summary/summary.txt
- {"code":404,"message":
- "Can't find artifacts containing file conclusion.txt"}:
- Task: https://cirrus-ci.com/task/4989037434372096
- Summary: https://api.cirrus-ci.com/v1/artifact/task/4989037434372096/summary/summary.txt
- KVM Validation: debug (only selftest_mptcp_join):
- Unstable: 1 failed test(s): selftest_mptcp_join 🔴:
- Task: https://cirrus-ci.com/task/6114937341214720
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6114937341214720/summary/summary.txt
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/27b157db80ef
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-debugFor 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 (Tessares)