Reduce the differences between TCP and MPTCP for TLS usage
Subsystems (4)
Geliang Tang
reviewerv14 cover Reduce the differences between TCP and MPTCP for TLS usage
From: Geliang Tang <[email protected]>
v14:
- v13 can no longer be applied to the export branch, so it has been rebased here with the following corrections:
- Patch 2: move locking in mptcp_inq_hint() to avoid races with ack_seq change from patch 3 to here. Update commit log.
- Patch 3: add mptcp_data_lock() in __mptcp_move_skb() around copied_seq update. Remove local delta variable in __mptcp_ofo_queue(). Initialize msk->copied_seq to 0 in mptcp_propagate_state() fallback path.
- Patch 4: add map_seq64 comparison in __mptcp_try_coalesce() for 64-bit sequence consistency.
- New patch 11: rename mptcp_check_readable() to mptcp_stream_is_readable() and align with TCP by calling sk_is_readable() for KTLS support.
v13:
- use smp_mb instead of smp_mb__before_atomic in mptcp_check_data_fin.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v12:
- Move sock_set_flag(SOCK_DONE) to after smp_mb__before_atomic() in mptcp_check_data_fin() and reuse the existing barrier rather than adding
a new smp_wmb().
- Sample SOCK_DONE before smp_rmb() in mptcp_inq_hint() and mptcp_inq(),
so the smp_rmb() only orders SOCK_DONE read relative to the subsequent ack_seq/copied_seq reads.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v11:
- __mptcp_move_skb(): gate __mptcp_sync_rcv_sequence() on test_and_clear_bit(MPTCP_SYNC_SEQ) so the dummy mapping is only re-based after ack_seq = iasn.
- a new patch to set and test SOCK_DONE.
- use SOCK_DONE in mptcp_inq_hint() and mptcp_inq().
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v10:
- Drop "mptcp: use atomic64_t for locklessly accessed u64 fields"
(v9 patch 1) and the squash to bpf_burst test (v9 patch 11).
Series reduced from 11 to 9 patches.
- Revert all atomic64_read()/atomic64_set() on msk->ack_seq back to
plain reads and WRITE_ONCE() in patches 1-4. Remove the local u64
ack_seq variables that only existed to hold atomic64_read() results.
- mptcp_inq_hint: move test_bit(MPTCP_SYNC_SEQ) inside mptcp_data_lock()
to close the race between the flag check and the ack_seq read. Revert atomic64_read() to plain msk->ack_seq under the lock.
- mptcp_inq (patch 6): use READ_ONCE() for both ack_seq and copied_seq
instead of atomic64_read(). Add comment for the FIN subtraction,
mirroring tcp_inq(). Update commit log.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v9:
- Extend atomic64_t conversion from only msk->ack_seq to all locklessly accessed u64 fields: write_seq, snd_nxt, snd_una, wnd_end,
bytes_received, bytes_consumed.
- Add mptcp_data_lock() in mptcp_inq_hint() to read ack_seq and
copied_seq atomically.
- Add read_copied field and drain it under mptcp_data_lock() in mptcp_read_complete() to fix the BH vs worker data race.
- New patches: mptcp_inq/peek_len and sendmsg_locked proto_ops.
- Squash to "selftests/bpf: Add bpf_burst scheduler & test".
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v8:
- check MPTCP_SYNC_SEQ in mptcp_inq_hint:
if (hint_val >= INT_MAX) {
if (test_bit(MPTCP_SYNC_SEQ, &msk->cb_flags))
return 0;
return INT_MAX;
} - rename mptcp_sock_rate_check_app_limited to
mptcp_rate_check_app_limited.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v7:
- Patch 1 is a new one to fix the existing issue Sashiko mentioned -
using atomic64_t for msk->ack_seq.
- Fix the map_subflow_seq setting in fallback mode in patch 4.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v6:
- Memory ordering for MPTCP_SYNC_SEQ: Add smp_wmb() before set_bit() in subflow_set_remote_key() and smp_rmb() after test_and_clear_bit() in __mptcp_move_skb() and mptcp_release_cb() to prevent data races on weakly-ordered architectures, ensuring ack_seq updates are visible
before the flag is set and readers see the updated sequence after
observing the flag.
- Lockdep nested locking: Use lock_sock_fast_nested(ssk) instead of lock_sock_fast(ssk) in mptcp_sock_rate_check_app_limited() to suppress
false positive recursive locking warnings when acquiring subflow socket
locks while holding the parent MPTCP socket lock.
- Receive window advertisement order: Swap mptcp_rcv_space_adjust() and mptcp_cleanup_rbuf() in mptcp_read_complete() to expand the receive
buffer before evaluating window updates, ensuring ACKs advertise the
new (larger) window size instead of delaying the advertisement until
the next cycle.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v5:
- only patch 3 changed.
- Fallback offset underflow: Initialize MPTCP sequence space to 0 in mptcp_propagate_state() when mp_opt == NULL, ensuring SKB's map_seq
starts from 0 to match msk->copied_seq and prevent offset calculation underflow in fallback mode.
- Stale peek_seq: Move peek_seq recomputation into the mptcp_move_skbs() continue path and add another recomputation after sk_wait_data(),
ensuring peek_seq stays synchronized with msk->copied_seq updates from MPTCP_SYNC_SEQ processing in both paths.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v4:
- mptcp_recvmsg: move the peek_seq recompute from after sk_wait_data() to before the mptcp_move_skbs() continue check. mptcp_move_skbs() -> __mptcp_move_skb() may shift the head skb's map_seq to the IASN frame via __mptcp_sync_rcv_sequence(); if 'continue' then exits the loop, the recompute is skipped, and the next __mptcp_recvmsg_mskq() computes offset with peek_seq in the old frame minus map_seq in the new frame. The underflow makes the offset test fail and the skb is skipped (and mptcp_recv_skb() actually frees the TFO skb via mptcp_eat_recv_skb()).
- Make all three MPTCP_SYNC_SEQ bit accesses atomic:
- subflow_set_remote_key: __set_bit -> set_bit - __mptcp_move_skb: __test_and_clear_bit -> test_and_clear_bit - mptcp_release_cb: __test_and_clear_bit -> test_and_clear_bit
The flag is set in BH under mptcp_data_lock() (msk slock held) and
cleared in user context under lock_sock() slow path (only owned=1,
slock not held). The non-atomic RMW on the two sides races, which can
lose the IASN sync.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v3:
- Patch 2, handle "offset" in __mptcp_sync_rcv_sequence().
- Patch 3, update __mptcp_move_skb() in response to Sashiko comments:
if (__test_and_clear_bit(MPTCP_SYNC_SEQ, &msk->cb_flags))
msk->copied_seq += mptcp_iasn(msk);
- Patch 4, replace after64() to after() in mptcp_prune_ofo_queue(). The pre-existing issue raised by Sashiko regarding changing the type of
ack_seq to atomic64_t is not addressed in this series.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v2:
- Patch 3, updated in response to Sashiko comments:
if (unlikely(msk->rcvd_dummy_seq)) {
msk->copied_seq += mptcp_iasn(msk);
__mptcp_sync_rcv_sequence(sk);
/* Release cb() would otherwise re-base copied_seq
* again.
*/
test_and_clear_bit(MPTCP_SYNC_SEQ, &msk->cb_flags);
}
/* Skip the already peeked data. */
if (offset >= skb->len) {
*last = skb;
continue;
} - Patch 5, replaced with Paolo's patch.
- Patch 6, 7, new patches addressing app-limited conditions.
- The patch "trim the duplicated skb head at receive enqueue" has been
dropped, as it is no longer needed after Paolo updated the "mptcp:
out-of-order queue pruning" series.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v1:
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
The goal of this series is to reduce the differences between TCP and MPTCP for TLS usage, in preparation for adding TLS over MPTCP support in the future.
In previous versions [1], a struct tls_prot_ops was defined to represent the interface differences between TCP and MPTCP, which contained the following callbacks:
struct sk_buff *(*recv_skb)(struct sock *sk, u32 *off); bool (*lock_is_held)(struct sock *sk); void (*read_done)(struct sock *sk, size_t len); u32 (*get_skb_seq)(struct sk_buff *skb); int (*skb_get_header)(const struct sk_buff *skb, int offset, void *to, int len); bool (*epollin_ready)(const struct sock *sk); void (*check_app_limited)(struct sock *sk);
In reality, some of these callbacks are unnecessary. This series aims to eliminate the get_skb_seq(), skb_get_header(), and lock_is_held() callbacks.
The first four patches come from Paolo's "mptcp: address stall under memory pressure" series v5 [2], with only minor cleanup from my side.
They remove the CB offset field and sync the MPTCP skb CB layout with the TCP one, so that we can obtain the TCP or MPTCP sequence number in a unified way, e.g.:
struct tls_skb_cb {
u32 seq;
};
#define TLS_SKB_CB(__skb) ((struct tls_skb_cb *)&((__skb)->cb[0]))This eliminates the need for a separate get_skb_seq() callback.
Building on the removal of the CB offset field, I also added patch 5 that trims the duplicated skb head at receive enqueue. With that in place, KTLS can retrieve the record header via skb_copy_bits() directly, so there is no longer any need for a dedicated MPTCP helper like mptcp_skb_get_header(). The skb_get_header() callback can thus be removed.
Patch 6 defers sk_data_ready to the worker, which avoids recursive locking when TLS calls back into MPTCP under mptcp_data_lock(). With this change, the lock_is_held() callback is no longer needed and can be removed.
[1]
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
[2]
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
Gang Yan (1):
mptcp: update mptcp_check_readable
Geliang Tang (5):
mptcp: align FIN handling with TCP via SOCK_DONE
mptcp: implement peek_len for proto_ops
mptcp: add sendmsg_locked to proto_ops
mptcp: track app-limited state in mptcp_sendmsg
selftests: mptcp: sockopt: check app_limited
Paolo Abeni (5):
mptcp: drop the mptcp_ooo_try_coalesce() helper
mptcp: drop the cant_coalesce CB field
mptcp: remove CB offset field
mptcp: sync mptcp skb cb layout with tcp one
mptcp: defer read_sock cleanup to mptcp_worker
include/net/tcp.h | 1 + net/ipv4/tcp.c | 9 +- net/mptcp/fastopen.c | 17 +- net/mptcp/protocol.c | 366 ++++++++++++------ net/mptcp/protocol.h | 21 +- net/mptcp/subflow.c | 20 + .../selftests/net/mptcp/mptcp_sockopt.c | 1 + 7 files changed, 310 insertions(+), 125 deletions(-)
Signature · 1 line
2.53.0
Geliang Tang
reviewerPATCH v14 1/11 mptcp: drop the mptcp_ooo_try_coalesce() helper
From: Paolo Abeni <[email protected]>
It's used to save an additional comparison for in-order skbs, but is also a barrier to remove CB offset. Remove the helper, let __mptcp_try_coalesce() always perform the sequence check and remove duplicate checks from the callers.
--- net/mptcp/protocol.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-)
net/mptcp/protocol.c +6 -15
@@ -167,7 +167,8 @@ static bool __mptcp_try_coalesce(struct sock *sk, struct sk_buff *to, {int limit =READ_ONCE (sk->sk_rcvbuf); -if (unlikely (MPTCP_SKB_CB (to)->cant_coalesce) || +if (MPTCP_SKB_CB (from)->map_seq !=MPTCP_SKB_CB (to)->end_seq || +unlikely (MPTCP_SKB_CB (to)->cant_coalesce) ||MPTCP_SKB_CB (from)->offset || ((to->len + from->len) > (limit >>3 )) || !skb_try_coalesce (to, from, fragstolen, delta))
@@ -200,15 +201,6 @@ static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,return true; } -static bool mptcp_ooo_try_coalesce (struct mptcp_sock *msk,struct sk_buff *to, -struct sk_buff *from) -{ -if (MPTCP_SKB_CB (from)->map_seq !=MPTCP_SKB_CB (to)->end_seq) -return false; - -return mptcp_try_coalesce ((struct sock *)msk, to, from); -} -/* "inspired" by tcp_rcvbuf_grow(), main difference: * - mptcp does not maintain a msk-level window clamp * - returns true when the receive buffer is actually updated
@@ -348,7 +340,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)/* with 2 subflows, adding at end of ooo queue is quite likely * Use of ooo_last_skb avoids the O(Log(N)) rbtree lookup. */ -if (mptcp_ooo_try_coalesce (msk, msk->ooo_last_skb, skb)) { +if (mptcp_try_coalesce (sk, msk->ooo_last_skb, skb)) {MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_OFOMERGE );MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_OFOQUEUETAIL );return ;
@@ -394,7 +386,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_DUPDATA ); goto merge_right; } - }else if (mptcp_ooo_try_coalesce (msk, skb1, skb)) { + }else if (mptcp_try_coalesce (sk, skb1, skb)) {MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_OFOMERGE );return ; }
@@ -777,8 +769,7 @@ static void __mptcp_add_backlog(struct sock *sk,if (!list_empty (&msk->backlog_list)) tail = list_last_entry(&msk->backlog_list, struct sk_buff, list); -if (tail &&MPTCP_SKB_CB (skb)->map_seq ==MPTCP_SKB_CB (tail)->end_seq && - ssk == tail->sk && +if (tail && ssk == tail->sk &&__mptcp_try_coalesce (sk, tail, skb, &fragstolen, &delta)) { skb->truesize -= delta;kfree_skb_partial (skb, fragstolen);
@@ -902,7 +893,7 @@ static bool __mptcp_ofo_queue(struct mptcp_sock *msk) end_seq =MPTCP_SKB_CB (skb)->end_seq; tail =skb_peek_tail (&sk->sk_receive_queue); -if (!tail || !mptcp_ooo_try_coalesce (msk, tail, skb)) { +if (!tail || !mptcp_try_coalesce (sk, tail, skb)) {int delta = msk->ack_seq -MPTCP_SKB_CB (skb)->map_seq;/* skip overlapping data, if any */
Signature · 1 line
2.53.0
Geliang Tang
reviewerPATCH v14 2/11 mptcp: drop the cant_coalesce CB field
In reply to Geliang TangFrom: Paolo Abeni <[email protected]>
Such field is used to ensure in-sequence processing in case of fastopen. Instead let's perform synchronization of the fastopen skb sequence when the IASN becomes available with the 3rd ack.
When the cant_coalesce field has been introduced, commit f03afb3aeb9d ("mptcp: drop __mptcp_fastopen_gen_msk_ackseq()") noted that updating the already queued skb for passive fastopen socket at 3rd ack time would be difficult and race prone. The main point is that such update don't need to be synchronously performed at 3rd ack time, but is sufficient to perform it before the next segment is introduced into the msk.
To such extent, add an explicit test in __mptcp_move_skb(). Performance wise this trades a conditional in the fast path - in __mptcp_try_coalesce()
- with a similar one in __mptcp_move_skb() and a couple more in slow paths.
After this change the user-space will always observe consistent sequence numbers in the receive queue, even in the TFO dummy mapping case.
Also add locking in mptcp_inq_hint() to avoid races with ack_seq updates during the fastopen sequence synchronization.
--- net/mptcp/fastopen.c | 6 +++-- net/mptcp/protocol.c | 57 ++++++++++++++++++++++++++++++++++++++++---- net/mptcp/protocol.h | 4 +++- net/mptcp/subflow.c | 10 ++++++++ 4 files changed, 69 insertions(+), 8 deletions(-)
net/mptcp/fastopen.c +4 -2
@@ -9,6 +9,7 @@void mptcp_fastopen_subflow_synack_set_params (struct mptcp_subflow_context *subflow,struct request_sock *req) { +struct mptcp_sock *msk;struct sock *sk, *ssk;struct sk_buff *skb;struct tcp_sock *tp;
@@ -49,15 +50,16 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subfMPTCP_SKB_CB (skb)->end_seq =0 ;MPTCP_SKB_CB (skb)->offset =0 ;MPTCP_SKB_CB (skb)->has_rxtstamp = has_rxtstamp; -MPTCP_SKB_CB (skb)->cant_coalesce =1 ;mptcp_data_lock (sk);DEBUG_NET_WARN_ON_ONCE (sock_owned_by_user_nocheck (sk)); + msk =mptcp_sk (sk); + msk->rcvd_dummy_seq = true;mptcp_borrow_fwdmem (sk, skb);skb_set_owner_r (skb, sk);__skb_queue_tail (&sk->sk_receive_queue, skb); -mptcp_sk (sk)->bytes_received += skb->len; + msk->bytes_received += skb->len; sk->sk_data_ready (sk);
net/mptcp/protocol.c +52 -5
106 lines not on this page · raw message
net/mptcp/protocol.h +3 -1
@@ -126,13 +126,13 @@#define MPTCP_FLUSH_JOIN_LIST 5#define MPTCP_SYNC_STATE 6#define MPTCP_SYNC_SNDBUF 7 +#define MPTCP_SYNC_SEQ 8struct mptcp_skb_cb {u64 map_seq;u64 end_seq;u32 offset;u8 has_rxtstamp; -u8 cant_coalesce; };#define MPTCP_SKB_CB (__skb) ((struct mptcp_skb_cb *)&((__skb)->cb[0]))
@@ -327,6 +327,7 @@ struct mptcp_sock {u32 token;unsigned long flags;unsigned long cb_flags; +bool rcvd_dummy_seq;bool recovery;/* closing subflow write queue reinjected */ bool can_ack;bool fully_established;
@@ -1187,6 +1188,7 @@ void mptcp_event_pm_listener(const struct sock *ssk, enum mptcp_event_type event);bool mptcp_userspace_pm_active (const struct mptcp_sock *msk); +void __mptcp_sync_rcv_sequence (struct sock *sk);void mptcp_fastopen_subflow_synack_set_params (struct mptcp_subflow_context *subflow,struct request_sock *req); int mptcp_pm_genl_fill_addr(struct sk_buff *msg,
net/mptcp/subflow.c +10 -0
@@ -480,6 +480,8 @@ static void subflow_set_remote_key(struct mptcp_sock *msk,struct mptcp_subflow_context *subflow, const struct mptcp_options_received *mp_opt) { + struct sock *sk = (struct sock *)msk; +/* active MPC subflow will reach here multiple times: * at subflow_finish_connect() time and at 4th ack time */
@@ -498,6 +500,14 @@ static void subflow_set_remote_key(struct mptcp_sock *msk,WRITE_ONCE (msk->ack_seq, subflow->iasn);WRITE_ONCE (msk->can_ack, true);atomic64_set (&msk->rcv_wnd_sent, subflow->iasn); + +if (!sock_owned_by_user (sk)) { +__mptcp_sync_rcv_sequence (sk); + }else { +/* Ensure ack_seq is visible before setting the flag */ +smp_wmb (); +set_bit (MPTCP_SYNC_SEQ , &msk->cb_flags); + } } static void mptcp_propagate_state(struct sock *sk, struct sock *ssk,
Signature · 1 line
2.53.0
Geliang Tang
reviewerPATCH v14 3/11 mptcp: remove CB offset field
In reply to Geliang TangFrom: Paolo Abeni <[email protected]>
Instead, use a new msk-level field to track the bytes already consumed inside each skb, carrying the amount of bytes already copied to user-space, alike what TCP is already doing.
The newly introduce copied_seq field is always accessed under the msk socket lock, delegating the synchronization with IASN to the msk release CB, when the socket is owned by the user-space at remote key reception time. Such synchronization preserves any partial progress (copy) made on the TFO packet.
Note that the explicit synchronization in __mptcp_move_skb() is needed to ensure that the TFO skb in the receive queue got its map_seq synched before the next skb lands into the receive queue when spooling the backlog at mptcp_release_cb() time, as the release CB synchronization will happen later.
Prior to this patch, the TFO skb dummy mapping was always ignored, now it affects the copied_seq initial update: be sure to extends the sign correctly of such mapping initialization time.
Overall this simplify a bit the __mptcp_recvmsg_mskq(), mptcp_inq_hint() and the __mptcp_move_skb() code and will also make possible the next patch.
Initialize MPTCP sequence space to 0 in mptcp_propagate_state() when mp_opt is NULL, ensuring SKB's map_seq starts from 0 to match msk->copied_seq and prevent offset calculation underflow in fallback mode.
--- net/mptcp/fastopen.c | 9 ++-- net/mptcp/protocol.c | 115 +++++++++++++++++++------------------------ net/mptcp/protocol.h | 8 ++- net/mptcp/subflow.c | 10 ++++ 4 files changed, 74 insertions(+), 68 deletions(-)
net/mptcp/fastopen.c +6 -3
@@ -45,10 +45,11 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf subflow->ssn_offset += skb->len; has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp; -/* Only the sequence delta is relevant */ -MPTCP_SKB_CB (skb)->map_seq = -skb->len; +/* The TFO segment data sits before the IASN; before receiving +* the remote key, IASN is assumed being 0. +*/ +MPTCP_SKB_CB (skb)->map_seq = -(u64 )skb->len;MPTCP_SKB_CB (skb)->end_seq =0 ; -MPTCP_SKB_CB (skb)->offset =0 ;MPTCP_SKB_CB (skb)->has_rxtstamp = has_rxtstamp;mptcp_data_lock (sk);
@@ -56,6 +57,8 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf msk =mptcp_sk (sk); msk->rcvd_dummy_seq = true; + msk->copied_seq =MPTCP_SKB_CB (skb)->map_seq; + msk->tfo_skb_len = skb->len;mptcp_borrow_fwdmem (sk, skb);skb_set_owner_r (skb, sk);__skb_queue_tail (&sk->sk_receive_queue, skb);
net/mptcp/protocol.c +51 -64
273 lines not on this page · raw message
net/mptcp/protocol.h +7 -1
@@ -131,7 +131,6 @@struct mptcp_skb_cb {u64 map_seq;u64 end_seq; -u32 offset;u8 has_rxtstamp; };
@@ -306,6 +305,7 @@ struct mptcp_sock {u64 bytes_sent;u64 snd_nxt;u64 bytes_received; +u64 copied_seq;u64 ack_seq;atomic64_t rcv_wnd_sent;u64 rcv_data_fin_seq;
@@ -325,6 +325,7 @@ struct mptcp_sock {u32 last_ack_recv;unsigned long timer_ival;u32 token; +u32 tfo_skb_len;unsigned long flags;unsigned long cb_flags;bool rcvd_dummy_seq;
@@ -880,6 +881,11 @@ struct sock *mptcp_subflow_get_retrans(struct mptcp_sock *msk);int mptcp_sched_get_send (struct mptcp_sock *msk);int mptcp_sched_get_retrans (struct mptcp_sock *msk); +static inline u64 mptcp_iasn (const struct mptcp_sock *msk) +{ +return msk->ack_seq - msk->bytes_received + msk->tfo_skb_len; +} +static inline u64 mptcp_data_avail (const struct mptcp_sock *msk) {return READ_ONCE (msk->bytes_received) -READ_ONCE (msk->bytes_consumed);
net/mptcp/subflow.c +10 -0
@@ -502,6 +502,8 @@ static void subflow_set_remote_key(struct mptcp_sock *msk,atomic64_set (&msk->rcv_wnd_sent, subflow->iasn);if (!sock_owned_by_user (sk)) { +/* User space could have already read partially the TFO skb */ + msk->copied_seq += subflow->iasn;__mptcp_sync_rcv_sequence (sk); }else {/* Ensure ack_seq is visible before setting the flag */
@@ -524,6 +526,14 @@ static void mptcp_propagate_state(struct sock *sk, struct sock *ssk,WRITE_ONCE (msk->snd_una, subflow->idsn +1 );WRITE_ONCE (msk->wnd_end, subflow->idsn +1 +tcp_sk (ssk)->snd_wnd);subflow_set_remote_key (msk, subflow, mp_opt); + }else { +/* Fallback: initialize sequence space to 0 (no remote key) */ + subflow->map_seq =0 ; +/* ensure mptcp_subflow_get_map_offset() returns 0 */ + subflow->map_subflow_seq =tcp_sk (ssk)->copied_seq - + subflow->ssn_offset; +WRITE_ONCE (msk->ack_seq,0 ); + msk->copied_seq =0 ; }if (!sock_owned_by_user (sk)) {
Signature · 1 line
2.53.0
Geliang Tang
reviewerPATCH v14 4/11 mptcp: sync mptcp skb cb layout with tcp one
In reply to Geliang TangFrom: Paolo Abeni <[email protected]>
The MPTCP protocol uses a significantly different CB layout WRT TCP, as it includes different information and use 64 bits for the sequence numbers.
As the msk-level rcvbuf buffer size is limited by the core socket code the INT_MAX; after validating the incoming skb vs the current receive window, we can safely use 32 bits for MPTCP-level sequence number. This allow updating the MPTCP CB layout so that fields with a corresponding TCP-level data use the same area inside the CB itself.
Add build time check to ensure the latter invariant.
--- net/mptcp/fastopen.c | 6 ++- net/mptcp/protocol.c | 87 +++++++++++++++++++++++++++----------------- net/mptcp/protocol.h | 7 +++- 3 files changed, 63 insertions(+), 37 deletions(-)
net/mptcp/fastopen.c +4 -2
@@ -48,8 +48,10 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf/* The TFO segment data sits before the IASN; before receiving * the remote key, IASN is assumed being 0. */ -MPTCP_SKB_CB (skb)->map_seq = -(u64 )skb->len; +MPTCP_SKB_CB (skb)->map_seq64 = -(u64 )skb->len; +MPTCP_SKB_CB (skb)->map_seq =MPTCP_SKB_CB (skb)->map_seq64;MPTCP_SKB_CB (skb)->end_seq =0 ; +MPTCP_SKB_CB (skb)->flags =0 ;MPTCP_SKB_CB (skb)->has_rxtstamp = has_rxtstamp;mptcp_data_lock (sk);
@@ -57,7 +59,7 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf msk =mptcp_sk (sk); msk->rcvd_dummy_seq = true; - msk->copied_seq =MPTCP_SKB_CB (skb)->map_seq; + msk->copied_seq =MPTCP_SKB_CB (skb)->map_seq64; msk->tfo_skb_len = skb->len;mptcp_borrow_fwdmem (sk, skb);skb_set_owner_r (skb, sk);
net/mptcp/protocol.c +54 -33
227 lines not on this page · raw message
net/mptcp/protocol.h +5 -2
@@ -129,9 +129,12 @@#define MPTCP_SYNC_SEQ 8struct mptcp_skb_cb { -u64 map_seq; -u64 end_seq; +u32 map_seq; +u32 end_seq; +u32 unused; +u16 flags;u8 has_rxtstamp; +u64 map_seq64; };#define MPTCP_SKB_CB (__skb) ((struct mptcp_skb_cb *)&((__skb)->cb[0]))
Signature · 1 line
2.53.0
Geliang Tang
reviewerPATCH v14 5/11 mptcp: defer read_sock cleanup to mptcp_worker
In reply to Geliang TangFrom: Paolo Abeni <[email protected]>
When MPTCP carries TLS, the data path runs under mptcp_data_lock(). Reaching sk->sk_data_ready(sk) synchronously ends up at tls_strp_check_rcv() -> mptcp_recv_skb() -> mptcp_move_skbs(), which calls mptcp_data_lock() on the same sk and recurses on sk_lock.slock.
The TLS path is not the only constraint: before the mptcp_recv_skb() calls, the TLS code would also reach __mptcp_read_sock(), which calls mptcp_rcv_space_adjust() and mptcp_cleanup_rbuf(). Both require holding the msk socket lock in process context, while the mptcp/TLS caller is in BH scope.
Fix this by deferring sk->sk_data_ready(sk) to mptcp_worker() via a new MPTCP_WORK_READ_COMPLETE bit, reusing the existing mptcp_schedule_work()/ mptcp_cancel_work() infrastructure. The wakeup bit is consumed after the SOCK_DEAD && TCP_CLOSE destroy branch, so a socket that reaches the destroy path drops the pending wakeup rather than running it post-free.
--- net/mptcp/protocol.c | 32 ++++++++++++++++++++++++-------- net/mptcp/protocol.h | 2 ++ 2 files changed, 26 insertions(+), 8 deletions(-)
net/mptcp/protocol.c +24 -8
@@ -3147,6 +3147,20 @@ static void mptcp_backlog_purge(struct sock *sk)sk_mem_reclaim (sk); } +static void mptcp_read_complete (struct sock *sk) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +int read_copied; + +mptcp_data_lock (sk); + read_copied = msk->read_copied; + msk->read_copied =0 ; +mptcp_data_unlock (sk); + +mptcp_rcv_space_adjust (msk, read_copied); +mptcp_cleanup_rbuf (msk, read_copied); +} +static void mptcp_do_fastclose (struct sock *sk) {struct mptcp_subflow_context *subflow, *tmp;
@@ -3222,6 +3236,9 @@ static void mptcp_worker(struct work_struct *work)if (test_and_clear_bit (MPTCP_WORK_RTX , &msk->flags))__mptcp_retrans (sk); +if (test_and_clear_bit (MPTCP_WORK_READ_COMPLETE , &msk->flags)) +mptcp_read_complete (sk); + fail_tout = msk->first ?READ_ONCE (mptcp_subflow_ctx (msk->first)->fail_tout) :0 ;if (fail_tout &&time_after (jiffies, fail_tout))mptcp_mp_fail_no_response (msk);
@@ -4608,9 +4625,6 @@ static struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off)struct sk_buff *skb;u32 offset; -if (!list_empty (&msk->backlog_list)) -mptcp_move_skbs (sk); -while ((skb =skb_peek (&sk->sk_receive_queue)) !=NULL ) { offset = (u32 )msk->copied_seq -MPTCP_SKB_CB (skb)->map_seq;if (offset < skb->len) {
@@ -4625,6 +4639,7 @@ static struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off)/* * Note: * - It is assumed that the socket was locked by the caller. +* - Can be invoked in BH scope. */ static int __mptcp_read_sock (struct sock *sk,read_descriptor_t *desc,sk_read_actor_t recv_actor,bool noack)
@@ -4634,8 +4649,6 @@ static int __mptcp_read_sock(struct sock *sk, read_descriptor_t *desc,int copied =0 ;u32 offset; -msk_owned_by_me (msk); -if (sk->sk_state ==TCP_LISTEN )return -ENOTCONN ;while ((skb =mptcp_recv_skb (sk, &offset)) !=NULL ) {
@@ -4666,11 +4679,14 @@ static int __mptcp_read_sock(struct sock *sk, read_descriptor_t *desc,if (noack) goto out; -mptcp_rcv_space_adjust (msk, copied); - +/* The backlog flushing is only needed when some data is actually +* moved and will take place in the workers's release callback. +*/ if (copied >0 ) {mptcp_recv_skb (sk, &offset); -mptcp_cleanup_rbuf (msk, copied); + msk->read_copied += copied; +set_bit (MPTCP_WORK_READ_COMPLETE , &msk->flags); +mptcp_schedule_work (sk); } out:return copied;
net/mptcp/protocol.h +2 -0
@@ -117,6 +117,7 @@#define MPTCP_FALLBACK_DONE 2#define MPTCP_WORK_CLOSE_SUBFLOW 3#define MPTCP_RTX_ENABLED 4 +#define MPTCP_WORK_READ_COMPLETE 5/* MPTCP socket release cb flags */ #define MPTCP_PUSH_PENDING 1
@@ -326,6 +327,7 @@ struct mptcp_sock {u32 last_data_sent;u32 last_data_recv;u32 last_ack_recv; +int read_copied;unsigned long timer_ival;u32 token;u32 tfo_skb_len;
Signature · 1 line
2.53.0
Geliang Tang
reviewerPATCH v14 6/11 mptcp: align FIN handling with TCP via SOCK_DONE
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
TCP uses SOCK_DONE to mark FIN reception because RCV_SHUTDOWN alone is
ambiguous: it is also set by RST (via SHUTDOWN_MASK) without an ack_seq increment. mptcp_inq_hint() used the latter as a proxy for "FIN pending", causing over-count and potentially returning 0 to peek_len() on a RST-while-data-queued socket, hanging TLS/BPF strparser consumers.
Mirror tcp_fin()/tcp_disconnect() in MPTCP:
- Set SOCK_DONE in mptcp_check_data_fin() next to RCV_SHUTDOWN, strictly tied to the ack_seq +=1 that counts the FIN byte.
- Test SOCK_DONE in mptcp_inq_hint() and mptcp_recvmsg() so the FIONREAD/ recvmsg FIN-handling only fires on a real DATA_FIN.
- Reset SOCK_DONE in mptcp_disconnect() to mirror tcp_disconnect().
Memory ordering: use smp_mb() in mptcp_check_data_fin() to order the SHUTDOWN, rcv_data_fin, and ack_seq writes before the non-atomic sock_set_flag(SOCK_DONE) and the subsequent atomic operations in mptcp_set_state()/mptcp_close_wake_up(). Pair it with smp_rmb() in mptcp_inq_hint() so a reader never sees SOCK_DONE=1 without the matching ack_seq +=1. smp_mb() is required (rather than reusing the existing smp_mb__before_atomic()) because sock_set_flag() uses __set_bit() which is non-atomic: on LoongArch smp_mb__before_atomic() is just a compiler fence and a CPU could reorder the SOCK_DONE store past it.
--- net/mptcp/protocol.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +11 -3
@@ -741,7 +741,8 @@ static void mptcp_check_data_fin(struct sock *sk)WRITE_ONCE (msk->rcv_data_fin,0 );WRITE_ONCE (sk->sk_shutdown, sk->sk_shutdown |RCV_SHUTDOWN ); -smp_mb__before_atomic ();/* SHUTDOWN must be visible first */ +smp_mb ();/* Order SHUTDOWN, ack_seq before SOCK_DONE. */ +sock_set_flag (sk,SOCK_DONE );switch (sk->sk_state) {case TCP_ESTABLISHED :
@@ -2405,8 +2406,12 @@ static bool mptcp_move_skbs(struct sock *sk)static unsigned int mptcp_inq_hint (struct sock *sk) {const struct mptcp_sock *msk =mptcp_sk (sk); +bool sock_done =sock_flag (sk,SOCK_DONE );u64 hint_val; +/* Pair with smp_mb() in mptcp_check_data_fin(). */ +smp_rmb (); +/* Avoid races vs ack_seq updates and MPTCP_SYNC_SEQ flag. */ mptcp_data_lock (sk);if (test_bit (MPTCP_SYNC_SEQ , &msk->cb_flags)) {
@@ -2419,8 +2424,7 @@ static unsigned int mptcp_inq_hint(struct sock *sk)if (hint_val >=INT_MAX )return INT_MAX ; -if (!hint_val && - (sk->sk_state ==TCP_CLOSE || (sk->sk_shutdown &RCV_SHUTDOWN ))) +if (!hint_val && sock_done)return 1 ;return (unsigned int )hint_val;
@@ -2492,6 +2496,9 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, !timeo)break ; }else { +if (sock_flag (sk,SOCK_DONE )) +break ; +if (sk->sk_err) { copied =sock_error (sk);break ;
@@ -3735,6 +3742,7 @@ static int mptcp_disconnect(struct sock *sk, int flags) msk->copied_seq =0 ;WRITE_ONCE (sk->sk_shutdown,0 ); +sock_reset_flag (sk,SOCK_DONE );sk_error_report (sk);return 0 ; }
Signature · 1 line
2.53.0
Geliang Tang
reviewerPATCH v14 7/11 mptcp: implement peek_len for proto_ops
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Add mptcp_inq() to compute the number of readable bytes at the MPTCP level. It derives the count from ack_seq - copied_seq, returns 0 while the connection is still handshaking (TCP_SYN_SENT/TCP_SYN_RECV), and subtracts 1 once a FIN has been received, mirroring tcp_inq().
The subtraction is needed because MPTCP's ack_seq is incremented by 1 in mptcp_check_data_fin() when the DATA_FIN is processed, consuming a sequence number without carrying any payload data. Without subtracting 1, peek_len would over-report by one byte, causing upper layers to wait for data that will never arrive.
READ_ONCE() is used instead of mptcp_data_lock() for the u64 reads of ack_seq and copied_seq because mptcp_inq() will be called from TLS contexts with the socket lock held - taking the spinlock would deadlock. On 32-bit systems a torn read can produce a wrapped subtraction (close to 2^64), which is caught by the INT_MAX clamp. TLS callers use mptcp_inq()
conservatively: over-reporting defers work to the next iteration, where recvmsg() provides the actual byte count.
Wire mptcp_inq() into mptcp_peek_len() and assign .peek_len in both mptcp_stream_ops and mptcp_v6_stream_ops, so upper layers get the correct in-queue byte count for MPTCP connections.
--- net/mptcp/protocol.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
net/mptcp/protocol.c +37 -0
@@ -4819,6 +4819,41 @@ static ssize_t mptcp_splice_read(struct socket *sock, loff_t *ppos,return ret; } +static int mptcp_inq (struct sock *sk) +{ +const struct mptcp_sock *msk =mptcp_sk (sk); +int answ; + +if ((1 << sk->sk_state) & (TCPF_SYN_SENT |TCPF_SYN_RECV )) { + answ =0 ; + }else if (test_bit (MPTCP_SYNC_SEQ , &msk->cb_flags)) { + answ =0 ; + }else { +bool sock_done =sock_flag (sk,SOCK_DONE ); +u64 hint_val; + +/* Pair with smp_mb() in mptcp_check_data_fin(). */ +smp_rmb (); + + hint_val =READ_ONCE (msk->ack_seq) -READ_ONCE (msk->copied_seq); +if (hint_val >=INT_MAX ) + hint_val =INT_MAX ; + + answ = (unsigned int )hint_val; + +/* Subtract 1, if FIN was received. Mirror tcp_inq() */ +if (answ && sock_done) + answ--; + } + +return answ; +} + +static int mptcp_peek_len (struct socket *sock) +{ +return mptcp_inq (sock->sk); +} +static const struct proto_ops mptcp_stream_ops = { .family =PF_INET , .owner =THIS_MODULE ,
@@ -4841,6 +4876,7 @@ static const struct proto_ops mptcp_stream_ops = { .set_rcvlowat = mptcp_set_rcvlowat, .read_sock = mptcp_read_sock, .splice_read = mptcp_splice_read, + .peek_len = mptcp_peek_len, };static struct inet_protosw mptcp_protosw = {
@@ -4965,6 +5001,7 @@ static const struct proto_ops mptcp_v6_stream_ops = { .set_rcvlowat = mptcp_set_rcvlowat, .read_sock = mptcp_read_sock, .splice_read = mptcp_splice_read, + .peek_len = mptcp_peek_len, };static struct proto mptcp_v6_prot;
Signature · 1 line
2.53.0
Geliang Tang
reviewerPATCH v14 8/11 mptcp: add sendmsg_locked to proto_ops
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
MPTCP currently provides a standard sendmsg() implementation which acquires and releases the socket lock internally. However, certain upper layers need to call the sendmsg method while the socket lock is already held.
Split the existing mptcp_sendmsg() into mptcp_sendmsg_locked() which assumes the caller holds the socket lock, and a tiny wrapper mptcp_sendmsg() that acquires the lock and calls the locked version.
Expose .sendmsg_locked in both mptcp_stream_ops and mptcp_v6_stream_ops.
--- net/mptcp/protocol.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
net/mptcp/protocol.c +14 -4
@@ -2055,7 +2055,7 @@ static void mptcp_rps_record_subflows(const struct mptcp_sock *msk) } } -static int mptcp_sendmsg (struct sock *sk,struct msghdr *msg,size_t len) +static int mptcp_sendmsg_locked (struct sock *sk,struct msghdr *msg,size_t len) {struct mptcp_sock *msk =mptcp_sk (sk);struct page_frag *pfrag;
@@ -2067,8 +2067,6 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) msg->msg_flags &=MSG_MORE |MSG_DONTWAIT |MSG_NOSIGNAL |MSG_FASTOPEN |MSG_EOR ; -lock_sock (sk); -mptcp_rps_record_subflows (msk); if (unlikely(inet_test_bit(DEFER_CONNECT, sk) ||
@@ -2184,7 +2182,6 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) } out: -release_sock (sk);return copied; do_error:
@@ -2195,6 +2192,17 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) goto out; } +static int mptcp_sendmsg (struct sock *sk,struct msghdr *msg,size_t len) +{ +int ret; + +lock_sock (sk); + ret =mptcp_sendmsg_locked (sk, msg, len); +release_sock (sk); + +return ret; +} +static void mptcp_rcv_space_adjust (struct mptcp_sock *msk,int copied);static void mptcp_eat_recv_skb (struct sock *sk,struct sk_buff *skb)
@@ -4877,6 +4885,7 @@ static const struct proto_ops mptcp_stream_ops = { .read_sock = mptcp_read_sock, .splice_read = mptcp_splice_read, .peek_len = mptcp_peek_len, + .sendmsg_locked = mptcp_sendmsg_locked, };static struct inet_protosw mptcp_protosw = {
@@ -5002,6 +5011,7 @@ static const struct proto_ops mptcp_v6_stream_ops = { .read_sock = mptcp_read_sock, .splice_read = mptcp_splice_read, .peek_len = mptcp_peek_len, + .sendmsg_locked = mptcp_sendmsg_locked, };static struct proto mptcp_v6_prot;
Signature · 1 line
2.53.0
Geliang Tang
reviewerPATCH v14 9/11 mptcp: track app-limited state in mptcp_sendmsg
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
The application-limited accounting in TCP is updated by tcp_rate_check_app_limited(), which currently takes a struct sock * and internally calls tcp_sk(). MPTCP needs to apply the same accounting to each subflow individually - every subflow is an independent TCP socket with its own tp->app_limited / delivered state - so wrapping the call as a struct sock * -> tcp_sk() helper is awkward at the call site.
Split the existing function: keep the logic as tcp_sock_rate_check_app_limited(struct tcp_sock *tp), and turn tcp_rate_check_app_limited(struct sock *) into a thin wrapper so the exported API is unchanged for other TCP users.
Then add mptcp_sock_rate_check_app_limited() that walks every subflow of the mptcp_sock and runs tcp_sock_rate_check_app_limited() under each subflow's socket lock. Invoke it from mptcp_sendmsg() right after the send-side setup, so the delivery-rate app_limited state stays in sync with what the application actually has to send across each subflow.
With this in place, TCP_INFO.tcpi_delivery_rate_app_limited is reported correctly for MPTCP connections instead of being left at 0.
--- include/net/tcp.h | 1 + net/ipv4/tcp.c | 9 +++++++-- net/mptcp/protocol.c | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-)
include/net/tcp.h +1 -0
@@ -851,6 +851,7 @@ static inline int tcp_bound_to_half_wnd(struct tcp_sock *tp, int pktsize)/* tcp.c */ void tcp_get_info (struct sock *,struct tcp_info *); +void tcp_sock_rate_check_app_limited (struct tcp_sock *tp);void tcp_rate_check_app_limited (struct sock *sk);/* Read 'sendfile()'-style from a TCP socket */
net/ipv4/tcp.c +7 -2
@@ -1099,9 +1099,9 @@ int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *copied, }/* If a gap is detected between sends, mark the socket application-limited. */ -void tcp_rate_check_app_limited (struct sock *sk) +void tcp_sock_rate_check_app_limited (struct tcp_sock *tp) { -struct tcp_sock *tp =tcp_sk (sk); +struct sock *sk = (struct sock *)tp; if (/* We have less than one packet to send. */ tp->write_seq - tp->snd_nxt < tp->mss_cache &&
@@ -1114,6 +1114,11 @@ void tcp_rate_check_app_limited(struct sock *sk) tp->app_limited = (tp->delivered +tcp_packets_in_flight (tp)) ? :1 ; } + +void tcp_rate_check_app_limited (struct sock *sk) +{ +tcp_sock_rate_check_app_limited (tcp_sk (sk)); +}EXPORT_SYMBOL_GPL (tcp_rate_check_app_limited);int tcp_sendmsg_locked (struct sock *sk,struct msghdr *msg,size_t size)
net/mptcp/protocol.c +18 -0
@@ -2055,6 +2055,21 @@ static void mptcp_rps_record_subflows(const struct mptcp_sock *msk) } } +static void mptcp_rate_check_app_limited (struct sock *sk) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct mptcp_subflow_context *subflow; + +mptcp_for_each_subflow (msk, subflow) { +struct sock *ssk =mptcp_subflow_tcp_sock (subflow); +bool slow; + + slow =lock_sock_fast_nested (ssk); +tcp_sock_rate_check_app_limited (tcp_sk (ssk)); +unlock_sock_fast (ssk, slow); + } +} +static int mptcp_sendmsg_locked (struct sock *sk,struct msghdr *msg,size_t len) {struct mptcp_sock *msk =mptcp_sk (sk);
@@ -2083,6 +2098,9 @@ static int mptcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t len) timeo =sock_sndtimeo (sk, msg->msg_flags &MSG_DONTWAIT ); +/* is sending application-limited? */ +mptcp_rate_check_app_limited (sk); +if ((1 << sk->sk_state) & ~(TCPF_ESTABLISHED |TCPF_CLOSE_WAIT )) { ret =sk_stream_wait_connect (sk, &timeo);if (ret)
Signature · 1 line
2.53.0
Geliang Tang
reviewerPATCH v14 10/11 selftests: mptcp: sockopt: check app_limited
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
connect_one_server() in mptcp_sockopt exchanges only a few packets between the client and server, then closes the socket. After such a small transfer the application has nothing further to send, so the connection is, by definition, application-limited.
Extend the TCP_INFO readback at the end of the function to assert s.tcp_info.tcpi_delivery_rate_app_limited == 1.
Without the preceding commit, mptcp_sendmsg() never updates the per-subflow app-limited state, and this field stays at 0 - the assertion would fail. With it in place, the value is forced to 1, turning this into a regression guard for the subflow-side application-limited accounting.
--- tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +1 -0
@@ -640,6 +640,7 @@ static void connect_one_server(int fd, int pipefd) total +=1 ;/* sequence advances due to FIN */ assert (s.mptcpi_rcv_delta == (uint64_t )total); +assert (s.tcp_info.tcpi_delivery_rate_app_limited ==1 );close (fd); }
Signature · 1 line
2.53.0
Geliang Tang
reviewerPATCH v14 11/11 mptcp: update mptcp_check_readable
In reply to Geliang TangFrom: Gang Yan <[email protected]>
This patch makes mptcp_check_readable() aligned with TCP, and renames it to mptcp_stream_is_readable(). It will be used in the case of KTLS, because 'prot' will be modified, tls_sw_sock_is_readable() is expected to be called from prot->sock_is_readable().
--- net/mptcp/protocol.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +6 -3
@@ -3546,9 +3546,11 @@ void __mptcp_unaccepted_force_close(struct sock *sk)__mptcp_destroy_sock (sk); } -static __poll_t mptcp_check_readable (struct sock *sk) +static bool mptcp_stream_is_readable (struct sock *sk) { -return mptcp_epollin_ready (sk) ?EPOLLIN |EPOLLRDNORM :0 ; +if (mptcp_epollin_ready (sk)) +return true; +return sk_is_readable (sk); }static void mptcp_check_listen_stop (struct sock *sk)
@@ -4633,7 +4635,8 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock, mask |=EPOLLIN |EPOLLRDNORM |EPOLLRDHUP ;if (state !=TCP_SYN_SENT && state !=TCP_SYN_RECV ) { - mask |=mptcp_check_readable (sk); +if (mptcp_stream_is_readable (sk)) + mask |=EPOLLIN |EPOLLRDNORM ;if (shutdown &SEND_SHUTDOWN ) mask |=EPOLLOUT |EPOLLWRNORM ;else
Signature · 1 line
2.53.0
Hi Gang,
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): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Perf: Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/36661539144
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/e903b8eeadde
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1176484
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-normalFor 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 (NGI0 Core)
Geliang Tang
reviewerHi Matt,
Quoted 11 lines · Geliang Tang
From: Geliang Tang <[email protected]>
v14:
- v13 can no longer be applied to the export branch, so it has been rebased here with the following corrections:
- Patch 2: move locking inmptcp_inq_hint()to avoid races withack_seq
change from patch 3 to here. Update commit log.
- Patch 3: addmptcp_data_lock()in__mptcp_move_skb()aroundcopied_seq
update. Remove local delta variable in__mptcp_ofo_queue().
Quoted 8 lines
Initialize
msk->copied_seqto 0 inmptcp_propagate_state()fallback path.
- Patch 4: addmap_seq64comparison in__mptcp_try_coalesce()for 64-bit
sequence consistency.
- New patch 11: renamemptcp_check_readable()tomptcp_stream_is_readable()
and align with TCP by callingsk_is_readable()for KTLS support.
Thanks to Paolo for reviewing the series for me on site at LPC2026 Networking Track in Prague earlier this month, and for pointing out that patch 9 should not add tcp_sock_rate_check_app_limited() - all changes should be kept on the MPTCP side. Following his comments, along with feedback from netdev-bot+sashiko, I've revised the code and will send out v15 soon.
I've changed the status of this series to "Changes Requested".
Thanks,
-Geliang
Quoted 291 lines
v13:
- usesmp_mbinstead ofsmp_mb__before_atomicinmptcp_check_data_fin.
-
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v12:
- Movesock_set_flag(SOCK_DONE)to aftersmp_mb__before_atomic()inmptcp_check_data_fin()and reuse the existing barrier rather than adding
a newsmp_wmb().
- SampleSOCK_DONEbeforesmp_rmb()inmptcp_inq_hint()andmptcp_inq(),
so thesmp_rmb()only ordersSOCK_DONEread relative to the subsequent
ack_seq/copied_seq reads.
-
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v11:
-__mptcp_move_skb(): gate__mptcp_sync_rcv_sequence()ontest_and_clear_bit(MPTCP_SYNC_SEQ)so the dummy mapping is only re-based
afterack_seq= iasn.
- a new patch to set and testSOCK_DONE.
- useSOCK_DONEinmptcp_inq_hint()andmptcp_inq().
-
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v10:
- Drop "mptcp: useatomic64_tfor locklessly accessed u64 fields" (v9 patch 1) and the squash tobpf_bursttest (v9 patch 11). Series reduced from 11 to 9 patches.
- Revert all atomic64_read()/atomic64_set() onmsk->ack_seqback to plain reads andWRITE_ONCE()in patches 1-4. Remove the local u64ack_seqvariables that only existed to holdatomic64_read()results.
-mptcp_inq_hint: movetest_bit(MPTCP_SYNC_SEQ)insidemptcp_data_lock()
to close the race between the flag check and theack_seqread. Revert
atomic64_read()to plainmsk->ack_sequnder the lock.
-mptcp_inq(patch 6): useREAD_ONCE()for bothack_seqandcopied_seq
instead ofatomic64_read(). Add comment for the FIN subtraction, mirroringtcp_inq(). Update commit log.
-
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v9:
- Extendatomic64_tconversion from onlymsk->ack_seqto all locklessly
accessed u64 fields:write_seq,snd_nxt,snd_una,wnd_end,bytes_received,bytes_consumed.
- Addmptcp_data_lock()inmptcp_inq_hint()to readack_seqandcopied_seqatomically.
- Addread_copiedfield and drain it undermptcp_data_lock()inmptcp_read_complete()to fix the BH vs worker data race.
- New patches: mptcp_inq/peek_len andsendmsg_lockedproto_ops.
- Squash to "selftests/bpf: Addbpf_burstscheduler & test". -
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v8:
- checkMPTCP_SYNC_SEQinmptcp_inq_hint:
if (hint_val>=INT_MAX) {
if (test_bit(MPTCP_SYNC_SEQ, &msk->cb_flags)) return 0;
returnINT_MAX;
}
- renamemptcp_sock_rate_check_app_limitedtomptcp_rate_check_app_limited.
-
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v7:
- Patch 1 is a new one to fix the existing issue Sashiko mentioned - usingatomic64_tformsk->ack_seq.
- Fix themap_subflow_seqsetting in fallback mode in patch 4. -
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v6:
- Memory ordering forMPTCP_SYNC_SEQ: Addsmp_wmb()beforeset_bit()in
subflow_set_remote_key()andsmp_rmb()aftertest_and_clear_bit()in
__mptcp_move_skb()andmptcp_release_cb()to prevent data races on weakly-ordered architectures, ensuringack_sequpdates are visible before the flag is set and readers see the updated sequence after observing the flag.
- Lockdep nested locking: Uselock_sock_fast_nested(ssk)instead oflock_sock_fast(ssk)inmptcp_sock_rate_check_app_limited()to suppress
false positive recursive locking warnings when acquiring subflow socket
locks while holding the parent MPTCP socket lock.
- Receive window advertisement order: Swapmptcp_rcv_space_adjust()and
mptcp_cleanup_rbuf()inmptcp_read_complete()to expand the receive
buffer before evaluating window updates, ensuring ACKs advertise the
new (larger) window size instead of delaying the advertisement until
the next cycle.
-
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v5:
- only patch 3 changed.
- Fallback offset underflow: Initialize MPTCP sequence space to 0 inmptcp_propagate_state()whenmp_opt== NULL, ensuring SKB'smap_seq
starts from 0 to matchmsk->copied_seqand prevent offset calculation
underflow in fallback mode.
- Stalepeek_seq: Movepeek_seqrecomputation into themptcp_move_skbs()
continue path and add another recomputation aftersk_wait_data(), ensuringpeek_seqstays synchronized withmsk->copied_sequpdates from
MPTCP_SYNC_SEQprocessing in both paths.
-
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v4:
-mptcp_recvmsg: move thepeek_seqrecompute from aftersk_wait_data()
to before themptcp_move_skbs()continue check.mptcp_move_skbs()->__mptcp_move_skb()may shift the head skb'smap_seqto the IASN frame via__mptcp_sync_rcv_sequence(); if 'continue' then exits the loop, the recompute is skipped, and the next__mptcp_recvmsg_mskq()computes offset withpeek_seqin the old
frame minusmap_seqin the new frame. The underflow makes the offset
test fail and the skb is skipped (andmptcp_recv_skb()actually frees
the TFO skb viamptcp_eat_recv_skb()).
- Make all threeMPTCP_SYNC_SEQbit accesses atomic:
- subflow_set_remote_key: __set_bit ->set_bit
- __mptcp_move_skb:__test_and_clear_bit->test_and_clear_bit
- mptcp_release_cb:__test_and_clear_bit->test_and_clear_bit
The flag is set in BH undermptcp_data_lock()(msk slock held) and cleared in user context underlock_sock()slow path (only owned=1, slock not held). The non-atomic RMW on the two sides races, which can
lose the IASN sync.
-
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v3:
- Patch 2, handle "offset" in__mptcp_sync_rcv_sequence().
- Patch 3, update__mptcp_move_skb()in response to Sashiko comments:if (
__test_and_clear_bit(MPTCP_SYNC_SEQ, &msk->cb_flags))msk->copied_seq += mptcp_iasn(msk);- Patch 4, replace
after64()toafter()inmptcp_prune_ofo_queue(). The
pre-existing issue raised by Sashiko regarding changing the type of
ack_seqtoatomic64_tis not addressed in this series. -
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v2:
- Patch 3, updated in response to Sashiko comments:if (
unlikely(msk->rcvd_dummy_seq)) {msk->copied_seq+=mptcp_iasn(msk);__mptcp_sync_rcv_sequence(sk);
/* Releasecb()would otherwise re-basecopied_seq
* again.
*/
test_and_clear_bit(MPTCP_SYNC_SEQ, &msk->cb_flags); }/* Skip the already peeked data. */
if (offset >=skb->len) {
*last = skb;
continue;
}
- Patch 5, replaced with Paolo's patch.
- Patch 6, 7, new patches addressing app-limited conditions.
- The patch "trim the duplicated skb head at receive enqueue" has been
dropped, as it is no longer needed after Paolo updated the "mptcp:
out-of-order queue pruning" series.
-
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v1:
-
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/The goal of this series is to reduce the differences between TCP and MPTCP
for TLS usage, in preparation for adding TLS over MPTCP support in the
future.In previous versions [1], a struct
tls_prot_opswas defined to represent
the interface differences between TCP and MPTCP, which contained the following callbacks:struct sk_buff *(*recv_skb)(struct sock *sk, u32 *off); bool (*lock_is_held)(struct sock *sk); void (*read_done)(struct sock *sk, size_t len); u32 (*get_skb_seq)(struct sk_buff *skb); int (*skb_get_header)(const struct sk_buff *skb, int offset, void *to, int len); bool (*epollin_ready)(const struct sock *sk); void (*check_app_limited)(struct sock *sk);In reality, some of these callbacks are unnecessary. This series aims to
eliminate theget_skb_seq(),skb_get_header(), andlock_is_held()callbacks.The first four patches come from Paolo's "mptcp: address stall under memory
pressure" series v5 [2], with only minor cleanup from my side.They remove the CB offset field and sync the MPTCP skb CB layout with the
TCP one, so that we can obtain the TCP or MPTCP sequence number in a unified way, e.g.:struct tls_skb_cb { u32 seq; }; #define TLS_SKB_CB(__skb) ((struct tls_skb_cb *)&((__skb)-Quoted 1 line
cb[0]))
This eliminates the need for a separate
get_skb_seq()callback.Building on the removal of the CB offset field, I also added patch 5 that
trims the duplicated skb head at receive enqueue. With that in place, KTLS
can retrieve the record header viaskb_copy_bits()directly, so there is no
longer any need for a dedicated MPTCP helper likemptcp_skb_get_header().
Theskb_get_header()callback can thus be removed.Patch 6 defers
sk_data_readyto the worker, which avoids recursive locking
when TLS calls back into MPTCP undermptcp_data_lock(). With this change,
thelock_is_held()callback is no longer needed and can be removed.[1]
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
[2]
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/Gang Yan (1):
mptcp: updatemptcp_check_readableGeliang Tang (5):
mptcp: align FIN handling with TCP viaSOCK_DONE
mptcp: implementpeek_lenforproto_ops
mptcp: addsendmsg_lockedtoproto_ops
mptcp: track app-limited state inmptcp_sendmsg
selftests: mptcp: sockopt: checkapp_limitedPaolo Abeni (5):
mptcp: drop themptcp_ooo_try_coalesce()helper
mptcp: drop thecant_coalesceCB field
mptcp: remove CB offset field
mptcp: sync mptcp skb cb layout with tcp one
mptcp: deferread_sockcleanup tomptcp_workerinclude/net/tcp.h | 1 + net/ipv4/tcp.c | 9 +- net/mptcp/fastopen.c | 17 +- net/mptcp/protocol.c | 366 ++++++++++++---- --
net/mptcp/protocol.h | 21 +- net/mptcp/subflow.c | 20 + .../selftests/net/mptcp/mptcp_sockopt.c | 1 +7 files changed, 310 insertions(+), 125 deletions(-)