mptcp: fallback socket cleanup
Subsystems (2)
Paolo Abeni
v2 cover mptcp: fallback socket cleanup
This addresses feedback from Mat on v1
From the original cover letter:
---
After all the above, performance for connection fallen back to plain TCP should be almost the same of TCP connection on unpacked kernel.
Addittionally 'nc' and 'netperf' now run successfully when forced to MPTCP. The latter still report a non fatal error at connection closing time as it performs:
getsockopt(4, SOL_TCP, TCP_MAXSEG, //...);getsockopt(4, SOL_TCP, TCP_INFO, //...);
which is still unsupported after that the mp capable handshake is started.
For the records on the debug build I'm using netperf scores better result with MPTCP that with plain TCP ;) [agreed, completely irrelevant, still nice]
The series applies at selftests and is unsquashed - will require quite a bit of work there and more work to rebase/adjust the patches after kselftest. I'll start that after the pending patches are in.
_Any_ feedback _very_ welcome!
Paolo Abeni (4):
mptcp: clear 'is_tcp' socket flag when the MP_CAPABLE handshake fails
mptcp: cleanup fallback handling
mptcp: add subflow to conn_list early
mptcp: avoid acquiring the msk lock in mptcp_finisch_connect()
net/mptcp/options.c | 3 + net/mptcp/protocol.c | 353 ++++++++++++++++++++----------------------- net/mptcp/subflow.c | 2 + 3 files changed, 169 insertions(+), 189 deletions(-)
Signature · 1 line
2.21.0
Paolo Abeni
PATCH v2 1/4 mptcp: clear 'is_tcp' socket flag when the MP_CAPABLE handshake fails
Currently we don't have a single flag for 'mp capable handshake failed', but we can clear the is_tcp flag to record such info.
This will make also processing for fallback socket almost as fast as native ones, and will help cleaning 'fallback' fields usage in later patches.
--- net/mptcp/options.c | 3 +++ net/mptcp/subflow.c | 2 ++ 2 files changed, 5 insertions(+)
net/mptcp/options.c +3 -0
@@ -306,6 +306,8 @@ void mptcp_rcv_synsent(struct sock *sk) subflow->mp_capable =1 ; subflow->can_ack =1 ; subflow->remote_key = tp->rx_opt.mptcp.sndr_key; + }else { +tcp_sk (sk)->is_mptcp =0 ; } }
@@ -508,6 +510,7 @@ static bool check_fourth_ack(struct mptcp_subflow_context *subflow,*/ if (!mp_opt->mp_capable) { subflow->mp_capable =0 ; +tcp_sk (mptcp_subflow_tcp_sock (subflow))->is_mptcp =0 ;return false; } subflow->remote_key = mp_opt->sndr_key;
net/mptcp/subflow.c +2 -0
@@ -745,6 +745,8 @@ static void subflow_ulp_clone(const struct request_sock *req, new_ctx->token = subflow_req->token; new_ctx->ssn_offset = subflow_req->ssn_offset; new_ctx->idsn = subflow_req->idsn; + }else { +tcp_sk (newsk)->is_mptcp =0 ; } }
Signature · 1 line
2.21.0
Paolo Abeni
PATCH v2 2/4 mptcp: cleanup fallback handling
In reply to Paolo AbeniThe 'fallback' field has many different meanings:
tcp fallback socket, first subflow, listening socket. Enforcing the correct usage is not easy - currently we have several problems:
1) this will fail, but it should not:
fd = socket(AF_INET{,6}, SOCK_STREAM, MPTCP_PROTO); setsockopt(fd, SOL_IP{,V6}, //...) = -1 EOPNOTSUPP (Operation not supported)
2) this will report success, but it should not:
fd = socket(AF_INET{,6}, SOCK_STREAM, MPTCP_PROTO); connect(fd, //)bind(fd, //) = 0
3) this will report success, but it should not:
fd = socket(AF_INET{,6}, SOCK_STREAM, MPTCP_PROTO); listen(fd, // )
s = accept(fd, )bind(s, ...) = 0
This patch:
- explicitly handle the msk socket status in some missing places
- wrap msk->subflow access with helpers describing the expected semantic
- use the above to enforce correct syscall behavior
- create on demand the subflow socket for setsockopt(), if possible
v1 -> v2:
- use MPTCP_SAME_STATE macro (Mat)
- drop dumb comment (Mat)
RFC -> v1:
- drop __mptcp_first_socket() helper, always use __mptcp_nmpc_socket() instead
--- net/mptcp/protocol.c | 178 +++++++++++++++++++++++++++---------------- 1 file changed, 111 insertions(+), 67 deletions(-)
net/mptcp/protocol.c +111 -67
@@ -22,25 +22,35 @@#include <net/mptcp.h> #include "protocol.h" -static struct socket *__mptcp_fallback_get_ref (const struct mptcp_sock *msk) -{ -sock_owned_by_me ((const struct sock *)msk); +#define MPTCP_SAME_STATE TCP_MAX_STATES +/* if msk has a single subflow socket, and the mp_capable handshake is not +* completed yet or has failed - that is, the socket is Not MP Capable, +* returns it. +* Otherwise returns NULL +*/ +static struct socket *__mptcp_nmpc_socket (const struct mptcp_sock *msk) +{if (!msk->subflow)return NULL ; -sock_hold (msk->subflow->sk);return msk->subflow; } -static struct socket *mptcp_fallback_get_ref (const struct mptcp_sock *msk) +/* if msk has a single subflow, and the mp_capable handshake is failed, +* get a reference and return it. +* Otherwise returns NULL +*/ +static struct socket *__mptcp_tcp_fallback_get (const struct mptcp_sock *msk) { -struct socket *ssock; +struct socket *ssock =__mptcp_nmpc_socket (msk); -lock_sock ((struct sock *)msk); - ssock =__mptcp_fallback_get_ref (msk); -release_sock ((struct sock *)msk); +sock_owned_by_me ((const struct sock *)msk); +if (!ssock ||tcp_sk (ssock->sk)->is_mptcp) +return NULL ; + +sock_hold (ssock->sk);return ssock; }
@@ -57,6 +67,49 @@ static struct sock *mptcp_subflow_get(const struct mptcp_sock *msk)return NULL ; } +static bool __mptcp_can_create_subflow (const struct mptcp_sock *msk) +{ +return ((struct sock *)msk)->sk_state ==TCP_CLOSE ; +} + +static struct socket *mptcp_socket_create_get (struct mptcp_sock *msk,int state) +{ +struct mptcp_subflow_context *subflow; +struct sock *sk = (struct sock *)msk; +struct socket *ssock; +int err; + +lock_sock (sk); + ssock =__mptcp_nmpc_socket (msk); +if (ssock) + goto set_state; + +if (!__mptcp_can_create_subflow (msk)) { + ssock =ERR_PTR (-EINVAL ); + goto release; + } + + err =mptcp_subflow_create_socket (sk, &ssock); +if (err) { + ssock =ERR_PTR (err); + goto release; + } + + msk->subflow = ssock; + subflow =mptcp_subflow_ctx (msk->subflow->sk); + subflow->request_mptcp =1 ;/* @@ if MPTCP enabled */ + subflow->request_version =1 ;/* only v1 supported */ + +set_state: +sock_hold (ssock->sk); +if (state !=MPTCP_SAME_STATE ) +inet_sk_state_store (sk, state); + +release: +release_sock (sk); +return ssock; +} +static bool mptcp_ext_cache_refill (struct mptcp_sock *msk) {if (!msk->cached_ext)
@@ -221,7 +274,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)return -EOPNOTSUPP ;lock_sock (sk); - ssock =__mptcp_fallback_get_ref (msk); + ssock =__mptcp_tcp_fallback_get (msk);if (ssock) {release_sock (sk);pr_debug ("fallback passthrough" );
@@ -324,7 +377,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,long timeo;lock_sock (sk); - ssock =__mptcp_fallback_get_ref (msk); + ssock =__mptcp_tcp_fallback_get (msk);if (ssock) {release_sock (sk); pr_debug("fallback-read subflow=%p",
@@ -579,7 +632,11 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,struct socket *listener;struct sock *newsk; - listener = msk->subflow; + listener =__mptcp_nmpc_socket (msk); +if (WARN_ON_ONCE (!listener)) { + *err = -EINVAL ; +return NULL ; + }pr_debug ("msk=%p, listener=%p" , msk,mptcp_subflow_ctx (listener->sk)); newsk =inet_csk_accept (listener->sk, flags, err, kern);
@@ -665,8 +722,8 @@ static int mptcp_setsockopt(struct sock *sk, int level, int optname, optval = (char __kernel __force *)uoptval;pr_debug ("msk=%p" , msk); - ssock =mptcp_fallback_get_ref (msk); -if (ssock) { + ssock =mptcp_socket_create_get (msk,MPTCP_SAME_STATE ); +if (!IS_ERR (ssock)) {pr_debug ("subflow=%p" , ssock->sk); ret =kernel_setsockopt (ssock, level, optname, optval, optlen);sock_put (ssock->sk);
@@ -693,8 +750,8 @@ static int mptcp_getsockopt(struct sock *sk, int level, int optname, option = (int __kernel __force *)uoption;pr_debug ("msk=%p" , msk); - ssock =mptcp_fallback_get_ref (msk); -if (ssock) { + ssock =mptcp_socket_create_get (msk,MPTCP_SAME_STATE ); +if (!IS_ERR (ssock)) {pr_debug ("subflow=%p" , ssock->sk); ret =kernel_getsockopt (ssock, level, optname, optval, option);sock_put (ssock->sk);
@@ -710,11 +767,14 @@ static int mptcp_getsockopt(struct sock *sk, int level, int optname,static int mptcp_get_port (struct sock *sk,unsigned short snum) {struct mptcp_sock *msk =mptcp_sk (sk); +struct socket *ssock; -pr_debug ("msk=%p, subflow=%p" , msk, -mptcp_subflow_ctx (msk->subflow->sk)); + ssock =__mptcp_nmpc_socket (msk); +pr_debug ("msk=%p, subflow=%p" , msk, ssock); +if (WARN_ON_ONCE (!ssock)) +return -EINVAL ; -return inet_csk_get_port (msk->subflow->sk, snum); +return inet_csk_get_port (ssock->sk, snum); }void mptcp_finish_connect (struct sock *ssk)
@@ -811,43 +871,13 @@ static struct proto mptcp_prot = { .no_autobind = true, }; -static struct socket *mptcp_socket_create_get (struct mptcp_sock *msk) -{ -struct mptcp_subflow_context *subflow; -struct sock *sk = (struct sock *)msk; -struct socket *ssock; -int err; - -lock_sock (sk); - ssock =__mptcp_fallback_get_ref (msk); -if (ssock) - goto release; - - err =mptcp_subflow_create_socket (sk, &ssock); -if (err) { - ssock =ERR_PTR (err); - goto release; - } - - msk->subflow = ssock; - subflow =mptcp_subflow_ctx (msk->subflow->sk); - subflow->request_mptcp =1 ;/* @@ if MPTCP enabled */ - subflow->request_version =1 ;/* only v1 supported */ - -sock_hold (ssock->sk); - -release: -release_sock (sk); -return ssock; -} -static int mptcp_bind (struct socket *sock,struct sockaddr *uaddr,int addr_len) {struct mptcp_sock *msk =mptcp_sk (sock->sk);struct socket *ssock;int err; - ssock =mptcp_socket_create_get (msk); + ssock =mptcp_socket_create_get (msk,MPTCP_SAME_STATE );if (IS_ERR (ssock))return PTR_ERR (ssock);
@@ -863,7 +893,7 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,struct socket *ssock;int err; - ssock =mptcp_socket_create_get (msk); + ssock =mptcp_socket_create_get (msk,TCP_SYN_SENT );if (IS_ERR (ssock))return PTR_ERR (ssock);
@@ -876,6 +906,7 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,#endif err = ssock->ops->connect (ssock, uaddr, addr_len, flags); +inet_sk_state_store (sock->sk,inet_sk_state_load (ssock->sk));sock_put (ssock->sk);return err; }
@@ -887,16 +918,16 @@ static int mptcp_getname(struct socket *sock, struct sockaddr *uaddr,struct socket *ssock;int ret; -if (msk->subflow) { -lock_sock (sock->sk); - ssock =__mptcp_fallback_get_ref (msk); -release_sock (sock->sk); -if (ssock) { -pr_debug ("subflow=%p" , ssock->sk); - ret = ssock->ops->getname (ssock, uaddr, peer); -sock_put (ssock->sk); -return ret; - } +lock_sock (sock->sk); + ssock =__mptcp_nmpc_socket (msk); +if (ssock) +sock_hold (ssock->sk); +release_sock (sock->sk); +if (ssock) { +pr_debug ("subflow=%p" , ssock->sk); + ret = ssock->ops->getname (ssock, uaddr, peer); +sock_put (ssock->sk); +return ret; }switch (af) {
@@ -962,11 +993,12 @@ static int mptcp_listen(struct socket *sock, int backlog)pr_debug ("msk=%p" , msk); - ssock =mptcp_socket_create_get (msk); + ssock =mptcp_socket_create_get (msk,TCP_LISTEN );if (IS_ERR (ssock))return PTR_ERR (ssock); err = ssock->ops->listen (ssock, backlog); +inet_sk_state_store (sock->sk,inet_sk_state_load (ssock->sk));sock_put (ssock->sk);return err; }
@@ -985,13 +1017,20 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock, {struct mptcp_sock *msk =mptcp_sk (sock->sk);struct socket *ssock; -int err; +int err = -EINVAL ;pr_debug ("msk=%p" , msk); - ssock =mptcp_fallback_get_ref (msk); +lock_sock (sock->sk); +if (sock->sk->sk_state !=TCP_LISTEN ) + goto unlock_fail; + + ssock =__mptcp_nmpc_socket (msk);if (!ssock) -return -EINVAL ; + goto unlock_fail; + +sock_hold (ssock->sk); +release_sock (sock->sk); err = ssock->ops->accept (sock, newsock, flags, kern);if (err ==0 && !is_tcp_proto (newsock->sk->sk_prot)) {
@@ -1011,6 +1050,10 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,sock_put (ssock->sk);return err; + +unlock_fail: +release_sock (sock->sk); +return -EINVAL ; } static __poll_t mptcp_poll(struct file *file, struct socket *sock,
@@ -1023,8 +1066,9 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock, msk =mptcp_sk (sk);lock_sock (sk); - ssock =__mptcp_fallback_get_ref (msk); + ssock =__mptcp_nmpc_socket (msk);if (ssock) { +sock_hold (ssock->sk);release_sock (sk); mask = ssock->ops->poll (file, ssock, wait);sock_put (ssock->sk);
@@ -1061,7 +1105,7 @@ static int mptcp_shutdown(struct socket *sock, int how)if (how ==SHUT_WR || how ==SHUT_RDWR )inet_sk_state_store (sock->sk,TCP_FIN_WAIT1 ); - ssock =__mptcp_fallback_get_ref (msk); + ssock =__mptcp_tcp_fallback_get (msk);if (ssock) {release_sock (sock->sk);pr_debug ("subflow=%p" , ssock->sk);
Signature · 1 line
2.21.0
Paolo Abeni
PATCH v2 3/4 mptcp: add subflow to conn_list early
In reply to Paolo AbeniAfter the previous commit we can move the subflow into conn_list at creation time, using the msk 'can_ack' field to track the fallaback status of such subflow.
Note that we still need to keep the subflow field around, as we can't easily access the non MP capable socket otherwise.
RFC -> v1:
- keep 'subflow' field around, after mptcp_subflow_tcp_sock() conversion we need some way to track such socket around
--- net/mptcp/protocol.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
net/mptcp/protocol.c +3 -10
@@ -31,7 +31,7 @@*/ static struct socket *__mptcp_nmpc_socket (const struct mptcp_sock *msk) { -if (!msk->subflow) +if (!msk->subflow ||READ_ONCE (msk->can_ack))return NULL ;return msk->subflow;
@@ -96,7 +96,8 @@ static struct socket *mptcp_socket_create_get(struct mptcp_sock *msk, int state) } msk->subflow = ssock; - subflow =mptcp_subflow_ctx (msk->subflow->sk); + subflow =mptcp_subflow_ctx (ssock->sk); +list_add (&subflow->node, &msk->conn_list); subflow->request_mptcp =1 ;/* @@ if MPTCP enabled */ subflow->request_version =1 ;/* only v1 supported */
@@ -584,11 +585,6 @@ static void mptcp_close(struct sock *sk, long timeout)lock_sock (sk); -if (msk->subflow) { -sock_release (msk->subflow); - msk->subflow =NULL ; - } -list_for_each_entry_safe (subflow, tmp, &msk->conn_list, node) {struct sock *ssk =mptcp_subflow_tcp_sock (subflow);
@@ -671,7 +667,6 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err, msk->token = subflow->token;mptcp_token_update_accept (newsk, new_mptcp_sock); - msk->subflow =NULL ; msk->write_seq = subflow->idsn +1 ;if (subflow->can_ack) {
@@ -827,8 +822,6 @@ void mptcp_finish_connect(struct sock *ssk) subflow->map_seq = ack_seq; subflow->map_subflow_seq =1 ; subflow->rel_write_seq =1 ; -list_add (&subflow->node, &msk->conn_list); - msk->subflow =NULL ;bh_unlock_sock (sk);local_bh_enable (); }
Signature · 1 line
2.21.0
Paolo Abeni
PATCH v2 4/4 mptcp: avoid acquiring the msk lock in mptcp_finisch_connect()
In reply to Paolo AbeniMove the mptcp_copy_inaddrs() into mptcp_finish_connect(), so that the mks lock is no longer required. Just document the unlocked access with WRITE_ONCE().
Since we now always acquire msk -> ssk lock in order, we can also avoid the msk lock/subflow lookup()/get()/ msk unlock()/ subflow op/ subflow put dance in most ops - simply keep the msk lock held the whole time.
Additionally we can simplify mptcp_getname(), as now the address information are always available in the msk.
v1 -> v2:
- moved status change to the end of mptcp_stream_accept() - Florian
RFC -> v1:
- move mptcp_copy_inaddrs() into finish_connect()
--- net/mptcp/protocol.c | 234 ++++++++++++++++--------------------------- 1 file changed, 86 insertions(+), 148 deletions(-)
net/mptcp/protocol.c +86 -148
@@ -38,10 +38,10 @@ static struct socket *__mptcp_nmpc_socket(const struct mptcp_sock *msk) }/* if msk has a single subflow, and the mp_capable handshake is failed, -* get a reference and return it. +* return it. * Otherwise returns NULL */ -static struct socket *__mptcp_tcp_fallback_get (const struct mptcp_sock *msk) +static struct socket *__mptcp_tcp_fallback (const struct mptcp_sock *msk) {struct socket *ssock =__mptcp_nmpc_socket (msk);
@@ -50,7 +50,6 @@ static struct socket *__mptcp_tcp_fallback_get(const struct mptcp_sock *msk)if (!ssock ||tcp_sk (ssock->sk)->is_mptcp)return NULL ; -sock_hold (ssock->sk);return ssock; }
@@ -72,28 +71,23 @@ static bool __mptcp_can_create_subflow(const struct mptcp_sock *msk)return ((struct sock *)msk)->sk_state ==TCP_CLOSE ; } -static struct socket *mptcp_socket_create_get (struct mptcp_sock *msk,int state) +static struct socket *__mptcp_socket_create (struct mptcp_sock *msk,int state) {struct mptcp_subflow_context *subflow;struct sock *sk = (struct sock *)msk;struct socket *ssock;int err; -lock_sock (sk); ssock =__mptcp_nmpc_socket (msk);if (ssock) goto set_state; -if (!__mptcp_can_create_subflow (msk)) { - ssock =ERR_PTR (-EINVAL ); - goto release; - } +if (!__mptcp_can_create_subflow (msk)) +return ERR_PTR (-EINVAL ); err =mptcp_subflow_create_socket (sk, &ssock); -if (err) { - ssock =ERR_PTR (err); - goto release; - } +if (err) +return ERR_PTR (err); msk->subflow = ssock; subflow =mptcp_subflow_ctx (ssock->sk);
@@ -102,12 +96,8 @@ static struct socket *mptcp_socket_create_get(struct mptcp_sock *msk, int state) subflow->request_version =1 ;/* only v1 supported */ set_state: -sock_hold (ssock->sk);if (state !=MPTCP_SAME_STATE )inet_sk_state_store (sk, state); - -release: -release_sock (sk);return ssock; }
@@ -275,12 +265,11 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)return -EOPNOTSUPP ;lock_sock (sk); - ssock =__mptcp_tcp_fallback_get (msk); + ssock =__mptcp_tcp_fallback (msk);if (ssock) { -release_sock (sk);pr_debug ("fallback passthrough" ); ret =sock_sendmsg (ssock, msg); -sock_put (ssock->sk); +release_sock (sk);return ret; }
@@ -378,13 +367,12 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,long timeo;lock_sock (sk); - ssock =__mptcp_tcp_fallback_get (msk); + ssock =__mptcp_tcp_fallback (msk);if (ssock) { -release_sock (sk);pr_debug ("fallback-read subflow=%p" ,mptcp_subflow_ctx (ssock->sk)); copied =sock_recvmsg (ssock, msg, flags); -sock_put (ssock->sk); +release_sock (sk);return copied; }
@@ -681,7 +669,6 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,list_add (&subflow->node, &msk->conn_list);bh_unlock_sock (new_mptcp_sock);local_bh_enable (); -inet_sk_state_store (newsk,TCP_ESTABLISHED );release_sock (sk);/* the subflow can already receive packet, avoid racing with
@@ -710,25 +697,26 @@ static int mptcp_setsockopt(struct sock *sk, int level, int optname, {struct mptcp_sock *msk =mptcp_sk (sk);char __kernel *optval; +int ret = -EOPNOTSUPP ;struct socket *ssock; -int ret;/* will be treated as __user in tcp_setsockopt */ optval = (char __kernel __force *)uoptval;pr_debug ("msk=%p" , msk); - ssock =mptcp_socket_create_get (msk,MPTCP_SAME_STATE ); + +/* @@ the meaning of setsockopt() when the socket is connected and +* there are multiple subflows is not defined. +*/ +lock_sock (sk); + ssock =__mptcp_socket_create (msk,MPTCP_SAME_STATE );if (!IS_ERR (ssock)) {pr_debug ("subflow=%p" , ssock->sk); ret =kernel_setsockopt (ssock, level, optname, optval, optlen); -sock_put (ssock->sk); -return ret; } +release_sock (sk); -/* @@ the meaning of setsockopt() when the socket is connected and -* there are multiple subflows is not defined. -*/ -return -EOPNOTSUPP ; +return ret; } static int mptcp_getsockopt(struct sock *sk, int level, int optname,
@@ -736,27 +724,28 @@ static int mptcp_getsockopt(struct sock *sk, int level, int optname, {struct mptcp_sock *msk =mptcp_sk (sk);char __kernel *optval; +int ret = -EOPNOTSUPP ;int __kernel *option;struct socket *ssock; -int ret;/* will be treated as __user in tcp_getsockopt */ optval = (char __kernel __force *)uoptval; option = (int __kernel __force *)uoption;pr_debug ("msk=%p" , msk); - ssock =mptcp_socket_create_get (msk,MPTCP_SAME_STATE ); + +/* @@ the meaning of getsockopt() when the socket is connected and +* there are multiple subflows is not defined. +*/ +lock_sock (sk); + ssock =__mptcp_socket_create (msk,MPTCP_SAME_STATE );if (!IS_ERR (ssock)) {pr_debug ("subflow=%p" , ssock->sk); ret =kernel_getsockopt (ssock, level, optname, optval, option); -sock_put (ssock->sk); -return ret; } +release_sock (sk); -/* @@ the meaning of getsockopt() when the socket is connected and -* there are multiple subflows is not defined. -*/ -return -EOPNOTSUPP ; +return ret; }static int mptcp_get_port (struct sock *sk,unsigned short snum)
@@ -775,57 +764,34 @@ static int mptcp_get_port(struct sock *sk, unsigned short snum)void mptcp_finish_connect (struct sock *ssk) {struct mptcp_subflow_context *subflow; +struct mptcp_sock *msk;struct sock *sk; +u64 ack_seq; subflow =mptcp_subflow_ctx (ssk); - sk = subflow->conn; - -if (subflow->mp_capable) { -struct mptcp_sock *msk =mptcp_sk (sk); -u64 ack_seq; +if (!subflow->mp_capable) +return ; -/* sk (new subflow socket) is already locked, but we need -* to lock the parent (mptcp) socket now to add the tcp socket -* to the subflow list. -* -* From lockdep point of view, this creates an ABBA type -* deadlock: Normally (sendmsg, recvmsg, ..), we lock the mptcp -* socket, then acquire a subflow lock. -* Here we do the reverse: "subflow lock, then mptcp lock". -* -* Its alright to do this here, because this subflow is not yet -* on the mptcp sockets subflow list. -* -* IOW, if another CPU has this mptcp socket locked, it cannot -* acquire this particular subflow, because subflow->sk isn't -* on msk->conn_list. -* -* This function can be called either from backlog processing -* (BH will be enabled) or from softirq, so we need to use BH -* locking scheme. -*/ -local_bh_disable (); -bh_lock_sock_nested (sk); + sk = subflow->conn; + msk =mptcp_sk (sk); - msk->remote_key = subflow->remote_key; - msk->local_key = subflow->local_key; - msk->token = subflow->token; -mptcp_copy_inaddrs (sk, ssk); +pr_debug ("msk=%p, token=%u" , sk, subflow->token); -pr_debug ("msk=%p, token=%u" , msk, msk->token); +mptcp_crypto_key_sha (subflow->remote_key,NULL , &ack_seq); + ack_seq++; + subflow->map_seq = ack_seq; + subflow->map_subflow_seq =1 ; + subflow->rel_write_seq =1 ; -mptcp_crypto_key_sha (msk->remote_key,NULL , &ack_seq); - msk->write_seq = subflow->idsn +1 ; - ack_seq++; - msk->ack_seq = ack_seq; - msk->can_ack =1 ; - subflow->map_seq = ack_seq; - subflow->map_subflow_seq =1 ; - subflow->rel_write_seq =1 ; -bh_unlock_sock (sk); -local_bh_enable (); - } -inet_sk_state_store (sk,TCP_ESTABLISHED ); +/* the socket is not connected yet, no msk/subflow ops can access/race +* accessing the field below +*/ +WRITE_ONCE (msk->remote_key, subflow->remote_key); +WRITE_ONCE (msk->local_key, subflow->local_key); +WRITE_ONCE (msk->token, subflow->token); +WRITE_ONCE (msk->write_seq, subflow->idsn +1 ); +WRITE_ONCE (msk->ack_seq, ack_seq); +WRITE_ONCE (msk->can_ack,1 ); }static void mptcp_sock_graft (struct sock *sk,struct socket *parent)
@@ -870,12 +836,19 @@ static int mptcp_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)struct socket *ssock;int err; - ssock =mptcp_socket_create_get (msk,MPTCP_SAME_STATE ); -if (IS_ERR (ssock)) -return PTR_ERR (ssock); +lock_sock (sock->sk); + ssock =__mptcp_socket_create (msk,MPTCP_SAME_STATE ); +if (IS_ERR (ssock)) { + err =PTR_ERR (ssock); + goto unlock; + } err = ssock->ops->bind (ssock, uaddr, addr_len); -sock_put (ssock->sk); +if (!err) +mptcp_copy_inaddrs (sock->sk, ssock->sk); + +unlock: +release_sock (sock->sk);return err; }
@@ -886,9 +859,12 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,struct socket *ssock;int err; - ssock =mptcp_socket_create_get (msk,TCP_SYN_SENT ); -if (IS_ERR (ssock)) -return PTR_ERR (ssock); +lock_sock (sock->sk); + ssock =__mptcp_socket_create (msk,TCP_SYN_SENT ); +if (IS_ERR (ssock)) { + err =PTR_ERR (ssock); + goto unlock; + }#ifdef CONFIG_TCP_MD5SIG /* no MPTCP if MD5SIG is enabled on this socket or we may run out of
@@ -900,44 +876,11 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr, err = ssock->ops->connect (ssock, uaddr, addr_len, flags);inet_sk_state_store (sock->sk,inet_sk_state_load (ssock->sk)); -sock_put (ssock->sk); -return err; -} - -static int mptcp_getname (struct socket *sock,struct sockaddr *uaddr, -int peer,int af) -{ -struct mptcp_sock *msk =mptcp_sk (sock->sk); -struct socket *ssock; -int ret; +mptcp_copy_inaddrs (sock->sk, ssock->sk); -lock_sock (sock->sk); - ssock =__mptcp_nmpc_socket (msk); -if (ssock) -sock_hold (ssock->sk); +unlock:release_sock (sock->sk); -if (ssock) { -pr_debug ("subflow=%p" , ssock->sk); - ret = ssock->ops->getname (ssock, uaddr, peer); -sock_put (ssock->sk); -return ret; - } - -switch (af) { -case AF_INET : - ret =inet_getname (sock, uaddr, peer); -break ; -#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) -case AF_INET6 : - ret =inet6_getname (sock, uaddr, peer); -break ; -#endif -default : - ret = -ENOPROTOOPT ; -WARN_ON_ONCE (1 ); - } - -return ret; +return err; } static int mptcp_v4_getname(struct socket *sock, struct sockaddr *uaddr,
@@ -952,10 +895,9 @@ static int mptcp_v4_getname(struct socket *sock, struct sockaddr *uaddr,* bypass mptcp. */ sock->ops = &inet_stream_ops; -return sock->ops->getname (sock, uaddr, peer); } -return mptcp_getname (sock, uaddr, peer,AF_INET ); +return inet_getname (sock, uaddr, peer); }#if IS_ENABLED (CONFIG_MPTCP_IPV6 )
@@ -971,10 +913,9 @@ static int mptcp_v6_getname(struct socket *sock, struct sockaddr *uaddr,* socket ops bypass mptcp. */ sock->ops = &inet6_stream_ops; - return sock->ops->getname(sock, uaddr, peer); } -return mptcp_getname (sock, uaddr, peer,AF_INET6 ); +return inet6_getname (sock, uaddr, peer); }#endif
@@ -986,13 +927,20 @@ static int mptcp_listen(struct socket *sock, int backlog)pr_debug ("msk=%p" , msk); - ssock =mptcp_socket_create_get (msk,TCP_LISTEN ); -if (IS_ERR (ssock)) -return PTR_ERR (ssock); +lock_sock (sock->sk); + ssock =__mptcp_socket_create (msk,TCP_LISTEN ); +if (IS_ERR (ssock)) { + err =PTR_ERR (ssock); + goto unlock; + } err = ssock->ops->listen (ssock, backlog);inet_sk_state_store (sock->sk,inet_sk_state_load (ssock->sk)); -sock_put (ssock->sk); +if (!err) +mptcp_copy_inaddrs (sock->sk, ssock->sk); + +unlock: +release_sock (sock->sk);return err; }
@@ -1039,6 +987,8 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,if (!ssk->sk_socket)mptcp_sock_graft (ssk, newsock); } + +inet_sk_state_store (newsock->sk,TCP_ESTABLISHED ); }sock_put (ssock->sk);
@@ -1061,10 +1011,8 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock,lock_sock (sk); ssock =__mptcp_nmpc_socket (msk);if (ssock) { -sock_hold (ssock->sk); -release_sock (sk); mask = ssock->ops->poll (file, ssock, wait); -sock_put (ssock->sk); +release_sock (sk);return mask; }
@@ -1088,7 +1036,6 @@ static int mptcp_shutdown(struct socket *sock, int how) {struct mptcp_sock *msk =mptcp_sk (sock->sk);struct mptcp_subflow_context *subflow; -struct socket *ssock;int ret =0 ;pr_debug ("sk=%p, how=%d" , msk, how);
@@ -1098,15 +1045,6 @@ static int mptcp_shutdown(struct socket *sock, int how)if (how ==SHUT_WR || how ==SHUT_RDWR )inet_sk_state_store (sock->sk,TCP_FIN_WAIT1 ); - ssock =__mptcp_tcp_fallback_get (msk); -if (ssock) { -release_sock (sock->sk); -pr_debug ("subflow=%p" , ssock->sk); - ret =kernel_sock_shutdown (ssock, how); -sock_put (ssock->sk); -return ret; - } - how++;if ((how & ~SHUTDOWN_MASK ) || !how) {
Signature · 1 line
2.21.0
Paolo Abeni
PATCH v3 4/4 mptcp: avoid acquiring the msk lock in mptcp_finisch_connect()
Move the mptcp_copy_inaddrs() into mptcp_finish_connect(), so that the mks lock is no longer required. Just document the unlocked access with WRITE_ONCE().
Since we now always acquire msk -> ssk lock in order, we can also avoid the msk lock/subflow lookup()/get()/ msk unlock()/ subflow op/ subflow put dance in most ops - simply keep the msk lock held the whole time.
Additionally we can simplify mptcp_getname(), as now the address information are always available in the msk.
v2 -> v3:
- on accept, set transiently the status to TCP_SYN_RECV, to avoid inet_accept() warnings
v1 -> v2:
- moved status change to the end of mptcp_stream_accept() - Florian
RFC -> v1:
- move mptcp_copy_inaddrs() into finish_connect()
---
sorry for the high-frequency span, v2 of this patch introduces an ugly warn on accept, fixed here
--- net/mptcp/protocol.c | 239 ++++++++++++++++--------------------------- 1 file changed, 91 insertions(+), 148 deletions(-)
net/mptcp/protocol.c +91 -148
@@ -38,10 +38,10 @@ static struct socket *__mptcp_nmpc_socket(const struct mptcp_sock *msk) }/* if msk has a single subflow, and the mp_capable handshake is failed, -* get a reference and return it. +* return it. * Otherwise returns NULL */ -static struct socket *__mptcp_tcp_fallback_get (const struct mptcp_sock *msk) +static struct socket *__mptcp_tcp_fallback (const struct mptcp_sock *msk) {struct socket *ssock =__mptcp_nmpc_socket (msk);
@@ -50,7 +50,6 @@ static struct socket *__mptcp_tcp_fallback_get(const struct mptcp_sock *msk)if (!ssock ||tcp_sk (ssock->sk)->is_mptcp)return NULL ; -sock_hold (ssock->sk);return ssock; }
@@ -72,28 +71,23 @@ static bool __mptcp_can_create_subflow(const struct mptcp_sock *msk)return ((struct sock *)msk)->sk_state ==TCP_CLOSE ; } -static struct socket *mptcp_socket_create_get (struct mptcp_sock *msk,int state) +static struct socket *__mptcp_socket_create (struct mptcp_sock *msk,int state) {struct mptcp_subflow_context *subflow;struct sock *sk = (struct sock *)msk;struct socket *ssock;int err; -lock_sock (sk); ssock =__mptcp_nmpc_socket (msk);if (ssock) goto set_state; -if (!__mptcp_can_create_subflow (msk)) { - ssock =ERR_PTR (-EINVAL ); - goto release; - } +if (!__mptcp_can_create_subflow (msk)) +return ERR_PTR (-EINVAL ); err =mptcp_subflow_create_socket (sk, &ssock); -if (err) { - ssock =ERR_PTR (err); - goto release; - } +if (err) +return ERR_PTR (err); msk->subflow = ssock; subflow =mptcp_subflow_ctx (ssock->sk);
@@ -102,12 +96,8 @@ static struct socket *mptcp_socket_create_get(struct mptcp_sock *msk, int state) subflow->request_version =1 ;/* only v1 supported */ set_state: -sock_hold (ssock->sk);if (state !=MPTCP_SAME_STATE )inet_sk_state_store (sk, state); - -release: -release_sock (sk);return ssock; }
@@ -275,12 +265,11 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)return -EOPNOTSUPP ;lock_sock (sk); - ssock =__mptcp_tcp_fallback_get (msk); + ssock =__mptcp_tcp_fallback (msk);if (ssock) { -release_sock (sk);pr_debug ("fallback passthrough" ); ret =sock_sendmsg (ssock, msg); -sock_put (ssock->sk); +release_sock (sk);return ret; }
@@ -378,13 +367,12 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,long timeo;lock_sock (sk); - ssock =__mptcp_tcp_fallback_get (msk); + ssock =__mptcp_tcp_fallback (msk);if (ssock) { -release_sock (sk);pr_debug ("fallback-read subflow=%p" ,mptcp_subflow_ctx (ssock->sk)); copied =sock_recvmsg (ssock, msg, flags); -sock_put (ssock->sk); +release_sock (sk);return copied; }
@@ -679,9 +667,13 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err, newsk = new_mptcp_sock;mptcp_copy_inaddrs (newsk, ssk);list_add (&subflow->node, &msk->conn_list); + +/* will be fully established when at mptcp_stream_accept() +* completion. +*/ +inet_sk_state_store (new_mptcp_sock,TCP_SYN_RECV );bh_unlock_sock (new_mptcp_sock);local_bh_enable (); -inet_sk_state_store (newsk,TCP_ESTABLISHED );release_sock (sk);/* the subflow can already receive packet, avoid racing with
@@ -710,25 +702,26 @@ static int mptcp_setsockopt(struct sock *sk, int level, int optname, {struct mptcp_sock *msk =mptcp_sk (sk);char __kernel *optval; +int ret = -EOPNOTSUPP ;struct socket *ssock; -int ret;/* will be treated as __user in tcp_setsockopt */ optval = (char __kernel __force *)uoptval;pr_debug ("msk=%p" , msk); - ssock =mptcp_socket_create_get (msk,MPTCP_SAME_STATE ); + +/* @@ the meaning of setsockopt() when the socket is connected and +* there are multiple subflows is not defined. +*/ +lock_sock (sk); + ssock =__mptcp_socket_create (msk,MPTCP_SAME_STATE );if (!IS_ERR (ssock)) {pr_debug ("subflow=%p" , ssock->sk); ret =kernel_setsockopt (ssock, level, optname, optval, optlen); -sock_put (ssock->sk); -return ret; } +release_sock (sk); -/* @@ the meaning of setsockopt() when the socket is connected and -* there are multiple subflows is not defined. -*/ -return -EOPNOTSUPP ; +return ret; } static int mptcp_getsockopt(struct sock *sk, int level, int optname,
@@ -736,27 +729,28 @@ static int mptcp_getsockopt(struct sock *sk, int level, int optname, {struct mptcp_sock *msk =mptcp_sk (sk);char __kernel *optval; +int ret = -EOPNOTSUPP ;int __kernel *option;struct socket *ssock; -int ret;/* will be treated as __user in tcp_getsockopt */ optval = (char __kernel __force *)uoptval; option = (int __kernel __force *)uoption;pr_debug ("msk=%p" , msk); - ssock =mptcp_socket_create_get (msk,MPTCP_SAME_STATE ); + +/* @@ the meaning of getsockopt() when the socket is connected and +* there are multiple subflows is not defined. +*/ +lock_sock (sk); + ssock =__mptcp_socket_create (msk,MPTCP_SAME_STATE );if (!IS_ERR (ssock)) {pr_debug ("subflow=%p" , ssock->sk); ret =kernel_getsockopt (ssock, level, optname, optval, option); -sock_put (ssock->sk); -return ret; } +release_sock (sk); -/* @@ the meaning of getsockopt() when the socket is connected and -* there are multiple subflows is not defined. -*/ -return -EOPNOTSUPP ; +return ret; }static int mptcp_get_port (struct sock *sk,unsigned short snum)
@@ -775,57 +769,34 @@ static int mptcp_get_port(struct sock *sk, unsigned short snum)void mptcp_finish_connect (struct sock *ssk) {struct mptcp_subflow_context *subflow; +struct mptcp_sock *msk;struct sock *sk; +u64 ack_seq; subflow =mptcp_subflow_ctx (ssk); - sk = subflow->conn; - -if (subflow->mp_capable) { -struct mptcp_sock *msk =mptcp_sk (sk); -u64 ack_seq; +if (!subflow->mp_capable) +return ; -/* sk (new subflow socket) is already locked, but we need -* to lock the parent (mptcp) socket now to add the tcp socket -* to the subflow list. -* -* From lockdep point of view, this creates an ABBA type -* deadlock: Normally (sendmsg, recvmsg, ..), we lock the mptcp -* socket, then acquire a subflow lock. -* Here we do the reverse: "subflow lock, then mptcp lock". -* -* Its alright to do this here, because this subflow is not yet -* on the mptcp sockets subflow list. -* -* IOW, if another CPU has this mptcp socket locked, it cannot -* acquire this particular subflow, because subflow->sk isn't -* on msk->conn_list. -* -* This function can be called either from backlog processing -* (BH will be enabled) or from softirq, so we need to use BH -* locking scheme. -*/ -local_bh_disable (); -bh_lock_sock_nested (sk); + sk = subflow->conn; + msk =mptcp_sk (sk); - msk->remote_key = subflow->remote_key; - msk->local_key = subflow->local_key; - msk->token = subflow->token; -mptcp_copy_inaddrs (sk, ssk); +pr_debug ("msk=%p, token=%u" , sk, subflow->token); -pr_debug ("msk=%p, token=%u" , msk, msk->token); +mptcp_crypto_key_sha (subflow->remote_key,NULL , &ack_seq); + ack_seq++; + subflow->map_seq = ack_seq; + subflow->map_subflow_seq =1 ; + subflow->rel_write_seq =1 ; -mptcp_crypto_key_sha (msk->remote_key,NULL , &ack_seq); - msk->write_seq = subflow->idsn +1 ; - ack_seq++; - msk->ack_seq = ack_seq; - msk->can_ack =1 ; - subflow->map_seq = ack_seq; - subflow->map_subflow_seq =1 ; - subflow->rel_write_seq =1 ; -bh_unlock_sock (sk); -local_bh_enable (); - } -inet_sk_state_store (sk,TCP_ESTABLISHED ); +/* the socket is not connected yet, no msk/subflow ops can access/race +* accessing the field below +*/ +WRITE_ONCE (msk->remote_key, subflow->remote_key); +WRITE_ONCE (msk->local_key, subflow->local_key); +WRITE_ONCE (msk->token, subflow->token); +WRITE_ONCE (msk->write_seq, subflow->idsn +1 ); +WRITE_ONCE (msk->ack_seq, ack_seq); +WRITE_ONCE (msk->can_ack,1 ); }static void mptcp_sock_graft (struct sock *sk,struct socket *parent)
@@ -870,12 +841,19 @@ static int mptcp_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)struct socket *ssock;int err; - ssock =mptcp_socket_create_get (msk,MPTCP_SAME_STATE ); -if (IS_ERR (ssock)) -return PTR_ERR (ssock); +lock_sock (sock->sk); + ssock =__mptcp_socket_create (msk,MPTCP_SAME_STATE ); +if (IS_ERR (ssock)) { + err =PTR_ERR (ssock); + goto unlock; + } err = ssock->ops->bind (ssock, uaddr, addr_len); -sock_put (ssock->sk); +if (!err) +mptcp_copy_inaddrs (sock->sk, ssock->sk); + +unlock: +release_sock (sock->sk);return err; }
@@ -886,9 +864,12 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,struct socket *ssock;int err; - ssock =mptcp_socket_create_get (msk,TCP_SYN_SENT ); -if (IS_ERR (ssock)) -return PTR_ERR (ssock); +lock_sock (sock->sk); + ssock =__mptcp_socket_create (msk,TCP_SYN_SENT ); +if (IS_ERR (ssock)) { + err =PTR_ERR (ssock); + goto unlock; + }#ifdef CONFIG_TCP_MD5SIG /* no MPTCP if MD5SIG is enabled on this socket or we may run out of
@@ -900,44 +881,11 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr, err = ssock->ops->connect (ssock, uaddr, addr_len, flags);inet_sk_state_store (sock->sk,inet_sk_state_load (ssock->sk)); -sock_put (ssock->sk); -return err; -} - -static int mptcp_getname (struct socket *sock,struct sockaddr *uaddr, -int peer,int af) -{ -struct mptcp_sock *msk =mptcp_sk (sock->sk); -struct socket *ssock; -int ret; +mptcp_copy_inaddrs (sock->sk, ssock->sk); -lock_sock (sock->sk); - ssock =__mptcp_nmpc_socket (msk); -if (ssock) -sock_hold (ssock->sk); +unlock:release_sock (sock->sk); -if (ssock) { -pr_debug ("subflow=%p" , ssock->sk); - ret = ssock->ops->getname (ssock, uaddr, peer); -sock_put (ssock->sk); -return ret; - } - -switch (af) { -case AF_INET : - ret =inet_getname (sock, uaddr, peer); -break ; -#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) -case AF_INET6 : - ret =inet6_getname (sock, uaddr, peer); -break ; -#endif -default : - ret = -ENOPROTOOPT ; -WARN_ON_ONCE (1 ); - } - -return ret; +return err; } static int mptcp_v4_getname(struct socket *sock, struct sockaddr *uaddr,
@@ -952,10 +900,9 @@ static int mptcp_v4_getname(struct socket *sock, struct sockaddr *uaddr,* bypass mptcp. */ sock->ops = &inet_stream_ops; -return sock->ops->getname (sock, uaddr, peer); } -return mptcp_getname (sock, uaddr, peer,AF_INET ); +return inet_getname (sock, uaddr, peer); }#if IS_ENABLED (CONFIG_MPTCP_IPV6 )
@@ -971,10 +918,9 @@ static int mptcp_v6_getname(struct socket *sock, struct sockaddr *uaddr,* socket ops bypass mptcp. */ sock->ops = &inet6_stream_ops; - return sock->ops->getname(sock, uaddr, peer); } -return mptcp_getname (sock, uaddr, peer,AF_INET6 ); +return inet6_getname (sock, uaddr, peer); }#endif
@@ -986,13 +932,20 @@ static int mptcp_listen(struct socket *sock, int backlog)pr_debug ("msk=%p" , msk); - ssock =mptcp_socket_create_get (msk,TCP_LISTEN ); -if (IS_ERR (ssock)) -return PTR_ERR (ssock); +lock_sock (sock->sk); + ssock =__mptcp_socket_create (msk,TCP_LISTEN ); +if (IS_ERR (ssock)) { + err =PTR_ERR (ssock); + goto unlock; + } err = ssock->ops->listen (ssock, backlog);inet_sk_state_store (sock->sk,inet_sk_state_load (ssock->sk)); -sock_put (ssock->sk); +if (!err) +mptcp_copy_inaddrs (sock->sk, ssock->sk); + +unlock: +release_sock (sock->sk);return err; }
@@ -1039,6 +992,8 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,if (!ssk->sk_socket)mptcp_sock_graft (ssk, newsock); } + +inet_sk_state_store (newsock->sk,TCP_ESTABLISHED ); }sock_put (ssock->sk);
@@ -1061,10 +1016,8 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock,lock_sock (sk); ssock =__mptcp_nmpc_socket (msk);if (ssock) { -sock_hold (ssock->sk); -release_sock (sk); mask = ssock->ops->poll (file, ssock, wait); -sock_put (ssock->sk); +release_sock (sk);return mask; }
@@ -1088,7 +1041,6 @@ static int mptcp_shutdown(struct socket *sock, int how) {struct mptcp_sock *msk =mptcp_sk (sock->sk);struct mptcp_subflow_context *subflow; -struct socket *ssock;int ret =0 ;pr_debug ("sk=%p, how=%d" , msk, how);
@@ -1098,15 +1050,6 @@ static int mptcp_shutdown(struct socket *sock, int how)if (how ==SHUT_WR || how ==SHUT_RDWR )inet_sk_state_store (sock->sk,TCP_FIN_WAIT1 ); - ssock =__mptcp_tcp_fallback_get (msk); -if (ssock) { -release_sock (sock->sk); -pr_debug ("subflow=%p" , ssock->sk); - ret =kernel_sock_shutdown (ssock, how); -sock_put (ssock->sk); -return ret; - } - how++;if ((how & ~SHUTDOWN_MASK ) || !how) {
Signature · 1 line
2.21.0
Mat Martineau
[MPTCP] Re: [PATCH v2 2/4] mptcp: cleanup fallback handling
In reply to Paolo AbeniQuoted 14 lines · Paolo Abeni
The 'fallback' field has many different meanings:
tcp fallback socket, first subflow, listening socket. Enforcing the correct usage is not easy - currently we have several problems:1) this will fail, but it should not:
fd =socket(AF_INET{,6}, SOCK_STREAM, MPTCP_PROTO);setsockopt(fd, SOL_IP{,V6}, //...)= -1 EOPNOTSUPP (Operation not supported)2) this will report success, but it should not:
fd =socket(AF_INET{,6}, SOCK_STREAM, MPTCP_PROTO);connect(fd, //)bind(fd, //)= 0
Quoted 6 lines
3) this will report success, but it should not:
fd =socket(AF_INET{,6}, SOCK_STREAM, MPTCP_PROTO);listen(fd, // )
s =accept(fd, )bind(s, ...)= 0
It would be good to add these problems to the self tests! Not considering that a blocker for merging this patch, though.
Patch otherwise looks good, thanks for the readability fixes.
Mat
Quoted 12 lines
This patch:
- explicitly handle the msk socket status in some missing places
- wrapmsk->subflowaccess with helpers describing the expected semantic
- use the above to enforce correct syscall behavior
- create on demand the subflow socket forsetsockopt(), if possiblev1 -> v2:
- useMPTCP_SAME_STATEmacro (Mat)
- drop dumb comment (Mat)
Quoted 9 lines
RFC -> v1:
- drop__mptcp_first_socket()helper, always use__mptcp_nmpc_socket()insteadSigned-off-by Paolo Abeni <pabeni(a)redhat.com>---
net/mptcp/protocol.c| 178 +++++++++++++++++++++++++++----------------1 file changed, 111 insertions(+), 67 deletions(-)
--
Mat Martineau
Intel
Mat Martineau
Quoted 12 lines · Paolo Abeni
This addresses feedback from Mat on v1
From the original cover letter:
---After all the above, performance for connection fallen back to plain TCP should be almost the same of TCP connection on unpacked kernel.
Addittionally 'nc' and 'netperf' now run successfully when forced to MPTCP. The latter still report a non fatal error at connection closing time as it performs:
Quoted 8 lines
getsockopt(4, SOL_TCP, TCP_MAXSEG, //...);getsockopt(4, SOL_TCP, TCP_INFO, //...);which is still unsupported after that the mp capable handshake is started.
For the records on the debug build I'm using netperf scores better result with MPTCP that with plain TCP ;) [agreed, completely irrelevant, still nice]
Hi Paolo -
The series looks good to me, and tests out ok on my side too when applied to today's export branch. Given the locking changes I think it would be helpful to have more than one reviewer.
Quoted 3 lines
The series applies at selftests and is unsquashed - will require quite a bit of work there and more work to rebase/adjust the patches after kselftest. I'll start that after the pending patches are in.
That was going to be my next question! Thanks for starting on that.
Mat
Quoted 9 lines
_Any_ feedback _very_ welcome!
Paolo Abeni (4):
mptcp: clear 'is_tcp' socket flag when theMP_CAPABLEhandshake fails
mptcp: cleanup fallback handling
mptcp: add subflow toconn_listearly
mptcp: avoid acquiring the msk lock inmptcp_finisch_connect()
Quoted 4 lines
net/mptcp/options.c | 3 + net/mptcp/protocol.c | 353 ++++++++++++++++++++----------------------- net/mptcp/subflow.c | 2 + 3 files changed, 169 insertions(+), 189 deletions(-)
--
Mat Martineau
Intel