questions about mptcp-level locking
Paolo Abeni
Hi all,
I just gave a better look at the current locking schema implemented in the mptcp code, and found some things I could not explain/look like bugs to me.
1) in mptcp_recvmsg(), just before the function return, both ssk and sk socket lock are released. It looks like the named function can complete even without not acquiring such locks. PROVE_LOCKING does not splat because release_sock() is a no-op if the lock is not owned - thanks Florian for noticing that. I'm unsure it the above is intentional, but looks confusing.
2) msk->ack_seq is updated via atomic_read/_set(), AFAICS without any serialization. Multiple concurrent threads can race while updating the sequence number, currupting the msk status. Florian suggested we could use cmpxchg instead of set(), but we agree that acquiring the socket lock would be simpler and safer - unless we missed something ;)
3) Reading http://multipath-tcp.org/data/MultipathTCP-netsys.pdf
slide 64, and the MTPCP RFC it looks like windows size must be shared for all subflows, but AFACS, the current code does not allow that. To such extend we would need to read/update an MPTCP-level status while reading/updating the subflow's window size.
With the current lock nesting, as imposed by mptcp_sendmsg() (msk lock -> ssk lock), we can't do that, as window size computation happens in the TCP core code, with ssk lock already held and no notion about msk lock.
Managing the MPTCP pending xmit data - to implement level data retransmission - will pose similar issues as we would probably need to remove elements from the MPTCP pending data queue at TCP ack processing time.
I *think* that inverting the locks order in mptcp_sendmsg() (and in _recvmsg() - assuming we move to socket lock even there) should address the above - allowing MPTCP hooks in the core TCP code to acquire the msk lock.
Any comments welcome!
Thanks,
Paolo
Mat Martineau
Quoted 6 lines · Paolo Abeni
Hi all,
I just gave a better look at the current locking schema implemented in the mptcp code, and found some things I could not explain/look like bugs to me.
Quoted 7 lines
1) in
mptcp_recvmsg(), just before the function return, both ssk and sk socket lock are released. It looks like the named function can complete even without not acquiring such locks.PROVE_LOCKINGdoes not splat becauserelease_sock()is a no-op if the lock is not owned - thanks Florian for noticing that. I'm unsure it the above is intentional, but looks confusing.
Definitely not intentional. The lock_sock() calls were near the beginning of mptcp_recvmsg() in RFCv2 and then apparently deleted accidentally. I'll fix that.
Quoted 5 lines
2)
msk->ack_seqis updated via atomic_read/_set(), AFAICS without any serialization. Multiple concurrent threads can race while updating the sequence number, currupting the msk status. Florian suggested we could use cmpxchg instead ofset(), but we agree that acquiring the socket lock would be simpler and safer - unless we missed something ;)
Apparently RFCv2 had a lot going for it, because I used atomic64_try_cmpxchg() there. With the (intended) locking at the beginning of mptcp_recvmsg(), I thought all of the writes to msk->ack_seq were under the mptcp-level socket lock, so I took out the cmpxchg. Are there any concerns if the mptcp_recvmsg() locking problem (from question #1) is fixed?
Quoted 7 lines
3) Reading http://multipath-tcp.org/data/MultipathTCP-netsys.pdf
slide 64, and the MTPCP RFC it looks like windows size must be shared for all subflows, but AFACS, the current code does not allow that. To such extend we would need to read/update an MPTCP-level status while reading/updating the subflow's window size.
Yes, the current code doesn't implement this - I have been referring to it as "coupled receive windows" in
https://github.com/multipath-tcp/mptcp_net-next/wiki/Status#future-work
Quoted 10 lines
With the current lock nesting, as imposed by
mptcp_sendmsg()(msk lock -> ssk lock), we can't do that, as window size computation happens in the TCP core code, with ssk lock already held and no notion about msk lock.Managing the MPTCP pending xmit data - to implement level data retransmission - will pose similar issues as we would probably need to remove elements from the MPTCP pending data queue at TCP ack processing time.
Quoted 5 lines
I *think* that inverting the locks order in
mptcp_sendmsg()(and in_recvmsg()- assuming we move to socket lock even there) should address the above - allowing MPTCP hooks in the core TCP code to acquire the msk lock.
Right now, the mptcp-level socket lock is taken first when called from userspace for sendmsg/recvmsg because the MPTCP-level socket will need to be locked first to determine which subflow socket to work with, and then lock the subflow it needs to use.
I had been thinking that calling "up" from the subflow to the MPTCP-level socket would involve scheduling a worker that would be able to lock in the same order as sendmsg/recvmsg. That does introduce some latency, but I don't think MPTCP-level resends are as time-sensitive as TCP retransmission (but maybe others on the list have more data or experience on that topic).
As for the window size computation, I've been trying to think of ways to handle that without needing the msk lock but haven't found the right idea yet.
--
Mat Martineau
Intel
Florian Westphal
Quoted 11 lines · Mat Martineau
Quoted 5 lines
2)
msk->ack_seqis updated via atomic_read/_set(), AFAICS without any serialization. Multiple concurrent threads can race while updating the sequence number, currupting the msk status. Florian suggested we could use cmpxchg instead ofset(), but we agree that acquiring the socket lock would be simpler and safer - unless we missed something ;)Apparently RFCv2 had a lot going for it, because I used
atomic64_try_cmpxchg()there. With the (intended) locking at the beginning ofmptcp_recvmsg(), I thought all of the writes tomsk->ack_seqwere under the mptcp-level socket lock, so I took out the cmpxchg. Are there any concerns if themptcp_recvmsg()locking problem (from question #1) is fixed?
Not from my or Paolos side, we discussed this earlier today and we both would prefer simpler lock/release over cmpxchg tricks.
Paolo Abeni
Quoted 7 lines · Florian Westphal
Quoted 6 lines · Mat Martineau
Quoted 5 lines
2)
msk->ack_seqis updated via atomic_read/_set(), AFAICS without any serialization. Multiple concurrent threads can race while updating the sequence number, currupting the msk status. Florian suggested we could use cmpxchg instead ofset(), but we agree that acquiring the socket lock would be simpler and safer - unless we missed something ;)
Quoted 8 lines
Quoted 5 lines
Apparently RFCv2 had a lot going for it, because I used
atomic64_try_cmpxchg()there. With the (intended) locking at the beginning ofmptcp_recvmsg(), I thought all of the writes tomsk->ack_seqwere under the mptcp-level socket lock, so I took out the cmpxchg. Are there any concerns if themptcp_recvmsg()locking problem (from question #1) is fixed?Not from my or Paolos side, we discussed this earlier today and we both would prefer simpler lock/release over cmpxchg tricks.
On top of the above, mptcp_recvmsg() calls to tcp_read_sock() - currently without any lock held. The latter function carries the following comment:
* Note:
* - It is assumed that the socket was locked by the caller.
So acquiring the sockete lock in mptcp_recvmsg() is apparently mandatory.
Cheers,
Paolo