From: Paolo Abeni <pabeni@redhat.com>
To: Matthieu Baerts <matthieu.baerts@tessares.net>,
Dmytro Shytyi <dmytro@shytyi.net>,
mptcp@lists.linux.dev
Subject: Re: [RFC PATCH mptcp-next v8 3/7] reuse tcp_sendmsg_fastopen()
Date: Tue, 20 Sep 2022 17:12:15 +0200 [thread overview]
Message-ID: <9010c984f0d7a238087df9ede5e3a5d36b2ca96b.camel@redhat.com> (raw)
In-Reply-To: <9f63a04a-7213-0757-2475-d09e74cdc54f@tessares.net>
On Tue, 2022-09-20 at 17:02 +0200, Matthieu Baerts wrote:
> Hi Paolo, Dmytro,
>
> On 20/09/2022 16:36, Paolo Abeni wrote:
> > On Tue, 2022-09-20 at 14:52 +0200, Dmytro Shytyi wrote:
> > > In the following patches we will reuse modified tcp_sendmsg_fastopen().
> > > We call it from mptcp_sendmsg().
> > >
> > > Signed-off-by: Dmytro Shytyi <dmytro@shytyi.net>
> > > ---
> > > include/net/tcp.h | 3 +++
> > > net/ipv4/tcp.c | 18 +++++++++++++-----
> > > net/mptcp/protocol.c | 11 +++++++++--
> > > 3 files changed, 25 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/include/net/tcp.h b/include/net/tcp.h
> > > index 735e957f7f4b..a7d49e42470a 100644
> > > --- a/include/net/tcp.h
> > > +++ b/include/net/tcp.h
> > > @@ -1754,6 +1754,9 @@ struct sock *tcp_try_fastopen(struct sock *sk, struct sk_buff *skb,
> > > struct request_sock *req,
> > > struct tcp_fastopen_cookie *foc,
> > > const struct dst_entry *dst);
> > > +int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
> > > + int *copied, size_t size,
> > > + struct ubuf_info *uarg);
> > > void tcp_fastopen_init_key_once(struct net *net);
> > > bool tcp_fastopen_cookie_check(struct sock *sk, u16 *mss,
> > > struct tcp_fastopen_cookie *cookie);
> > > diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> > > index 9251c99d3cfd..d10a3cdae220 100644
> > > --- a/net/ipv4/tcp.c
> > > +++ b/net/ipv4/tcp.c
> > > @@ -280,6 +280,9 @@
> > > #include <asm/ioctls.h>
> > > #include <net/busy_poll.h>
> > >
> > > +#include <net/mptcp.h>
> > > +#include "../mptcp/protocol.h"
> > > +
> > > /* Track pending CMSGs. */
> > > enum {
> > > TCP_CMSG_INQ = 1,
> > > @@ -1162,9 +1165,9 @@ void tcp_free_fastopen_req(struct tcp_sock *tp)
> > > }
> > > }
> > >
> > > -static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
> > > - int *copied, size_t size,
> > > - struct ubuf_info *uarg)
> > > +int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
> > > + int *copied, size_t size,
> > > + struct ubuf_info *uarg)
> > > {
> > > struct tcp_sock *tp = tcp_sk(sk);
> > > struct inet_sock *inet = inet_sk(sk);
> > > @@ -1197,8 +1200,13 @@ static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
> > > }
> > > }
> > > flags = (msg->msg_flags & MSG_DONTWAIT) ? O_NONBLOCK : 0;
> > > - err = __inet_stream_connect(sk->sk_socket, uaddr,
> > > - msg->msg_namelen, flags, 1);
> > > + if (!sk_is_mptcp(sk))
> > > + err = __inet_stream_connect(sk->sk_socket, uaddr,
> > > + msg->msg_namelen, flags, 1);
> > > + else
> > > + err = mptcp_stream_connect(sk->sk_socket, uaddr,
> > > + msg->msg_namelen, msg->msg_flags);
> >
> >
> > I guess the goal of the above change is let mptcp_stream_connect()
> > update the msk socket status, is that correct?
> >
> > However there are a few problems with lock: you must acquite the
> > subflow socket lock before calling tcp_sendmsg_fastopen() - or will see
> > subflow state corruption - but that in turn will cause a deadlock as
> > mptcp_stream_connect() acquires the msk socket lock and then the
> > subflow socket lock.
> >
> > I think it's better leave the tcp_sendmsg_fastopen() body unchanged...
> >
> > > +
> > > /* fastopen_req could already be freed in __inet_stream_connect
> > > * if the connection times out or gets rst
> > > */
> > > diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> > > index 470045793181..8cf307e4e59c 100644
> > > --- a/net/mptcp/protocol.c
> > > +++ b/net/mptcp/protocol.c
> > > @@ -1673,9 +1673,16 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
> > > long timeo;
> > >
> > > /* we don't support FASTOPEN yet */
> > > - if (msg->msg_flags & MSG_FASTOPEN)
> > > - return -EOPNOTSUPP;
> > > + if (msg->msg_flags & MSG_FASTOPEN) {
> > > + struct socket *ssock = __mptcp_nmpc_socket(msk);
> >
> > ... acquire the subflow socket lock here...
> >
> > >
> > > + if (ssock) {
> > > + int copied_syn_fastopen = 0;
> > > +
> > > + ret = tcp_sendmsg_fastopen(ssock->sk, msg, &copied_syn_fastopen, len, NULL);
> > > + copied += copied_syn_fastopen;
> > > + }
> >
> > ... and additionally handle the sock state update here. Possibly you
> > can encapsulate all the fastopen code in a new function - say
> > __mptcp_sendmsg_fastopen(), as it will be called under the msk socket
> > lock.
> >
> >
> > Side note: you should enter the fastopen branch even when
> > inet_sk(ssock->sk)->defer_connect is set
>
> I think we should better discuss about that at the next meeting because
> all items you are asking here is what Benjamin did in [1]:
>
> https://patchwork.kernel.org/project/mptcp/patch/20220908133829.3410092-4-benjamin.hesmans@tessares.net/
Almost. The above lacks the msk socket state update.
Cheers,
Paolo
next prev parent reply other threads:[~2022-09-20 15:12 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-20 12:52 [RFC PATCH mptcp-next v8 0/7] mptcp: Fast Open Mechanism Dmytro Shytyi
2022-09-20 12:52 ` [RFC PATCH mptcp-next v8 1/7] add mptcp_stream_connect to protocol.h Dmytro Shytyi
2022-09-20 12:52 ` [RFC PATCH mptcp-next v8 2/7] add mptcp_setsockopt_fastopen Dmytro Shytyi
2022-09-20 12:52 ` [RFC PATCH mptcp-next v8 3/7] reuse tcp_sendmsg_fastopen() Dmytro Shytyi
2022-09-20 14:36 ` Paolo Abeni
2022-09-20 15:02 ` Matthieu Baerts
2022-09-20 15:10 ` Dmytro Shytyi
2022-09-20 15:12 ` Paolo Abeni [this message]
2022-09-21 4:20 ` Dmytro Shytyi
2022-09-20 12:52 ` [RFC PATCH mptcp-next v8 4/7] mptfo variables for msk, options. Fix loop retrans Dmytro Shytyi
2022-09-20 14:56 ` Paolo Abeni
2022-09-21 4:15 ` Dmytro Shytyi
2022-09-20 12:52 ` [RFC PATCH mptcp-next v8 5/7] Fix unxpctd val of subflow->map_seq(dscrd packet) Dmytro Shytyi
2022-09-20 16:04 ` Paolo Abeni
2022-09-21 4:12 ` Dmytro Shytyi
2022-09-20 12:52 ` [RFC PATCH mptcp-next v8 6/7] add skb to mskq in tcp_fastopen_add_skb() Dmytro Shytyi
2022-09-20 16:02 ` Paolo Abeni
2022-09-21 4:09 ` Dmytro Shytyi
2022-09-20 12:52 ` [RFC PATCH mptcp-next v8 7/7] selftests: mptfo initiator/listener Dmytro Shytyi
2022-09-20 13:17 ` selftests: mptfo initiator/listener: Build Failure MPTCP CI
2022-09-20 14:40 ` selftests: mptfo initiator/listener: Tests Results MPTCP CI
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9010c984f0d7a238087df9ede5e3a5d36b2ca96b.camel@redhat.com \
--to=pabeni@redhat.com \
--cc=dmytro@shytyi.net \
--cc=matthieu.baerts@tessares.net \
--cc=mptcp@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).