mptcp: more token follow-up
Subsystems (3)
Paolo Abeni
cover mptcp: more token follow-up
The patch 1 addesses a race on close which may possibly fix issues/36 && issues/29, the 2nd patch is a follow-up cleanup.
Patch 2 should be inserted just after "mptcp: refactor token container."
Note: I'm observing frequent (1 every a few runs) self-tests failure on top of export branch due to timeout, but looks unrelated from series (happens on unpatched tree)
Paolo Abeni (2):
mptcp: do nonce initialization at subflow creation time dbg
net/core/sock.c | 16 +------------ net/mptcp/protocol.c | 23 +++++++++++++++++++ net/mptcp/protocol.h | 7 ++++++ net/mptcp/subflow.c | 54 ++++++++++++++++---------------------------- net/mptcp/token.c | 3 +++ 5 files changed, 54 insertions(+), 49 deletions(-)
Signature · 1 line
2.21.3
Paolo Abeni
PATCH 1/2 mptcp: do nonce initialization at subflow creation time
This clean-up the code a bit, reduces the number of used hooks and indirect call requested, and allow better error reporting from __mptcp_subflow_connect()
--- net/mptcp/subflow.c | 54 +++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 34 deletions(-)
net/mptcp/subflow.c +20 -34
@@ -29,34 +29,6 @@ static void SUBFLOW_REQ_INC_STATS(struct request_sock *req,MPTCP_INC_STATS (sock_net (req_to_sk (req)), field); } -static int subflow_rebuild_header (struct sock *sk) -{ -struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (sk); -int local_id; - -if (subflow->request_join && !subflow->local_nonce) { -struct mptcp_sock *msk = (struct mptcp_sock *)subflow->conn; - -pr_debug ("subflow=%p" , sk); - -do { -get_random_bytes (&subflow->local_nonce,sizeof (u32)); - }while (!subflow->local_nonce); - -if (subflow->local_id) - goto out; - - local_id =mptcp_pm_get_local_id (msk, (struct sock_common *)sk); -if (local_id <0 ) -return -EINVAL ; - - subflow->local_id = local_id; - } - -out: -return subflow->icsk_af_ops->rebuild_header (sk); -} -static void subflow_req_destructor (struct request_sock *req) {struct mptcp_subflow_request_sock *subflow_req =mptcp_subflow_rsk (req);
@@ -972,7 +944,9 @@ int __mptcp_subflow_connect(struct sock *sk, int ifindex,struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_subflow_context *subflow;struct sockaddr_storage addr; +int local_id = loc->id;struct socket *sf; +struct sock *ssk;u32 remote_token;int addrlen;int err;
@@ -984,7 +958,20 @@ int __mptcp_subflow_connect(struct sock *sk, int ifindex,if (err)return err; - subflow =mptcp_subflow_ctx (sf->sk); + ssk = sf->sk; + subflow =mptcp_subflow_ctx (ssk); +do { +get_random_bytes (&subflow->local_nonce,sizeof (u32)); + }while (!subflow->local_nonce); + +if (!local_id) { + err =mptcp_pm_get_local_id (msk, (struct sock_common *)ssk); +if (err <0 ) + goto failed; + + local_id = err; + } + subflow->remote_key = msk->remote_key; subflow->local_key = msk->local_key; subflow->token = msk->token;
@@ -995,15 +982,16 @@ int __mptcp_subflow_connect(struct sock *sk, int ifindex,if (loc->family ==AF_INET6 ) addrlen =sizeof (struct sockaddr_in6 );#endif - sf->sk->sk_bound_dev_if = ifindex; + ssk->sk_bound_dev_if = ifindex; err =kernel_bind (sf, (struct sockaddr *)&addr, addrlen);if (err) goto failed;mptcp_crypto_key_sha (subflow->remote_key, &remote_token,NULL ); -pr_debug ("msk=%p remote_token=%u" , msk, remote_token); +pr_debug ("msk=%p remote_token=%u local_id=%d" , msk, remote_token, + local_id); subflow->remote_token = remote_token; - subflow->local_id = loc->id; + subflow->local_id = local_id; subflow->request_join =1 ; subflow->request_bkup =1 ;mptcp_info2sockaddr (remote, &addr);
@@ -1264,7 +1252,6 @@ void __init mptcp_subflow_init(void) subflow_specific.conn_request = subflow_v4_conn_request; subflow_specific.syn_recv_sock = subflow_syn_recv_sock; subflow_specific.sk_rx_dst_set = subflow_finish_connect; - subflow_specific.rebuild_header = subflow_rebuild_header;#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) subflow_request_sock_ipv6_ops = tcp_request_sock_ipv6_ops;
@@ -1274,7 +1261,6 @@ void __init mptcp_subflow_init(void) subflow_v6_specific.conn_request = subflow_v6_conn_request; subflow_v6_specific.syn_recv_sock = subflow_syn_recv_sock; subflow_v6_specific.sk_rx_dst_set = subflow_finish_connect; - subflow_v6_specific.rebuild_header = subflow_rebuild_header; subflow_v6m_specific = subflow_v6_specific; subflow_v6m_specific.queue_xmit = ipv4_specific.queue_xmit;
Signature · 1 line
2.21.3
Paolo Abeni
PATCH 2/2 dbg
In reply to Paolo Abeni--- net/core/sock.c | 16 +--------------- net/mptcp/protocol.c | 23 +++++++++++++++++++++++ net/mptcp/protocol.h | 7 +++++++ net/mptcp/token.c | 3 +++ 4 files changed, 34 insertions(+), 15 deletions(-)
net/core/sock.c +1 -15
@@ -1776,7 +1776,7 @@ EXPORT_SYMBOL(sk_alloc);/* Sockets having SOCK_RCU_FREE will call this function after one RCU * grace period. This is the case for UDP sockets and TCP listeners. */ -static void __sk_destruct (struct rcu_head *head) +void __sk_destruct (struct rcu_head *head) { struct sock *sk = container_of(head, struct sock, sk_rcu);struct sk_filter *filter;
@@ -1814,20 +1814,6 @@ static void __sk_destruct(struct rcu_head *head)sk_prot_free (sk->sk_prot_creator, sk); } -void sk_destruct (struct sock *sk) -{ -bool use_call_rcu =sock_flag (sk,SOCK_RCU_FREE ); - -if (rcu_access_pointer (sk->sk_reuseport_cb)) { -reuseport_detach_sock (sk); - use_call_rcu = true; - } - -if (use_call_rcu) -call_rcu (&sk->sk_rcu, __sk_destruct); -else -__sk_destruct (&sk->sk_rcu); -}static void __sk_free (struct sock *sk) {
net/mptcp/protocol.c +23 -0
@@ -2088,6 +2088,29 @@ static struct inet_protosw mptcp_protosw = { .flags = INET_PROTOSW_ICSK, }; +void __sk_destruct (struct rcu_head *head); + +void sk_destruct (struct sock *sk) +{ +bool use_call_rcu =sock_flag (sk,SOCK_RCU_FREE ); + +if (rcu_access_pointer (sk->sk_reuseport_cb)) { +reuseport_detach_sock (sk); + use_call_rcu = true; + } + +if (sk->sk_prot == &mptcp_prot) { +struct mptcp_sock *msk =mptcp_sk (sk); + + msk->add_nr =stack_trace_save (msk->add_store,STORE_LEN ,1 ); + } + +if (use_call_rcu) +call_rcu (&sk->sk_rcu, __sk_destruct); +else +__sk_destruct (&sk->sk_rcu); +} +#if IS_ENABLED (CONFIG_KASAN )#define MPTCP_USE_SLAB 0#else
net/mptcp/protocol.h +7 -0
@@ -210,6 +210,13 @@ struct mptcp_sock {struct socket *subflow;/* outgoing connect/listener/!mp_capable */ struct sock *first;struct mptcp_pm_data pm; + +#define STORE_LEN 16 +long add_store[STORE_LEN ]; +int add_nr; +bool connect; +bool accept; +int del_nr; };#define mptcp_for_each_subflow (__msk, __subflow) \
net/mptcp/token.c +3 -0
@@ -167,6 +167,7 @@ int mptcp_token_new_connect(struct sock *sk)WRITE_ONCE (msk->token, subflow->token);__sk_nulls_add_node_rcu ((struct sock *)msk, &bucket->msk_chain); bucket->chain_len++; + msk->connect = true;spin_unlock_bh (&bucket->lock);return 0 ; }
@@ -193,6 +194,7 @@ void mptcp_token_accept(struct mptcp_subflow_request_sock *req,if (!WARN_ON_ONCE (pos != req))hlist_nulls_del_init_rcu (&req->token_node);__sk_nulls_add_node_rcu ((struct sock *)msk, &bucket->msk_chain); + msk->accept = true;spin_unlock_bh (&bucket->lock); }
@@ -285,6 +287,7 @@ void mptcp_token_destroy(struct mptcp_sock *msk)__sk_nulls_del_node_init_rcu ((struct sock *)pos); bucket->chain_len--; } + msk->del_nr++;spin_unlock_bh (&bucket->lock); }
Signature · 1 line
2.21.3
Paolo Abeni
[MPTCP] Re: [PATCH net-next 2/2] dbg
Quoted 114 lines · Paolo Abeni
--- net/core/sock.c | 16 +--------------- net/mptcp/protocol.c | 23 +++++++++++++++++++++++ net/mptcp/protocol.h | 7 +++++++ net/mptcp/token.c | 3 +++ 4 files changed, 34 insertions(+), 15 deletions(-)net/core/sock.c +1
-15@@ -1776,7 +1776,7 @@ EXPORT_SYMBOL(sk_alloc);/* Sockets having SOCK_RCU_FREE will call this function after one RCU * grace period. This is the case for UDP sockets and TCP listeners. */ -static void __sk_destruct (struct rcu_head *head) +void __sk_destruct (struct rcu_head *head) { struct sock *sk = container_of(head, struct sock, sk_rcu);struct sk_filter *filter;@@ -1814,20 +1814,6 @@ static void __sk_destruct(struct rcu_head *head)sk_prot_free (sk->sk_prot_creator, sk); } -void sk_destruct (struct sock *sk) -{ -bool use_call_rcu =sock_flag (sk,SOCK_RCU_FREE ); - -if (rcu_access_pointer (sk->sk_reuseport_cb)) { -reuseport_detach_sock (sk); - use_call_rcu = true; - } - -if (use_call_rcu) -call_rcu (&sk->sk_rcu, __sk_destruct); -else -__sk_destruct (&sk->sk_rcu); -}static void __sk_free (struct sock *sk) {net/mptcp/protocol.c +23
-0@@ -2088,6 +2088,29 @@ static struct inet_protosw mptcp_protosw = { .flags = INET_PROTOSW_ICSK, }; +void __sk_destruct (struct rcu_head *head); + +void sk_destruct (struct sock *sk) +{ +bool use_call_rcu =sock_flag (sk,SOCK_RCU_FREE ); + +if (rcu_access_pointer (sk->sk_reuseport_cb)) { +reuseport_detach_sock (sk); + use_call_rcu = true; + } + +if (sk->sk_prot == &mptcp_prot) { +struct mptcp_sock *msk =mptcp_sk (sk); + + msk->add_nr =stack_trace_save (msk->add_store,STORE_LEN ,1 ); + } + +if (use_call_rcu) +call_rcu (&sk->sk_rcu, __sk_destruct); +else +__sk_destruct (&sk->sk_rcu); +} +#if IS_ENABLED (CONFIG_KASAN )#define MPTCP_USE_SLAB 0#else net/mptcp/protocol.h +7
-0@@ -210,6 +210,13 @@ struct mptcp_sock {struct socket *subflow;/* outgoing connect/listener/!mp_capable */ struct sock *first;struct mptcp_pm_data pm; + +#define STORE_LEN 16 +long add_store[STORE_LEN ]; +int add_nr; +bool connect; +bool accept; +int del_nr; };#define mptcp_for_each_subflow (__msk, __subflow) \net/mptcp/token.c +2
-0@@ -167,6 +167,7 @@ int mptcp_token_new_connect(struct sock *sk)WRITE_ONCE (msk->token, subflow->token);__sk_nulls_add_node_rcu ((struct sock *)msk, &bucket->msk_chain); bucket->chain_len++; + msk->connect = true;spin_unlock_bh (&bucket->lock);return 0 ; }@@ -193,6 +194,7 @@ void mptcp_token_accept(struct mptcp_subflow_request_sock *req,if (!WARN_ON_ONCE (pos != req))hlist_nulls_del_init_rcu (&req->token_node);__sk_nulls_add_node_rcu ((struct sock *)msk, &bucket->msk_chain); + msk->accept = true;spin_unlock_bh (&bucket->lock); }
net/mptcp/token.c void mptcp_token_destroy(struct mptcp_sock *msk) · line 293
Quoted 7 lines
net/mptcp/token.c +1
-0@@ -285,6 +287,7 @@ void mptcp_token_destroy(struct mptcp_sock *msk)__sk_nulls_del_node_init_rcu ((struct sock *)pos); bucket->chain_len--; } + msk->del_nr++;spin_unlock_bh (&bucket->lock); }
For the records: this horrible crap was not supposed to be here. -ENOCOFFEE :(
Will send a v2 hopefully comprising the correct code.
Sorry for the noise.
/P