prepare interfaces for kTLS and sockmap support
Subsystems (3)
Geliang Tang
reviewerv7 cover prepare interfaces for kTLS and sockmap support
From: Geliang Tang <[email protected]>
v7:
- patch 1: add 1 to hint_val when RCV_SHUTDOWN is set to include the FIN byte, matching the previous ack_seq - map_seq behavior. Simplify the EOF condition accordingly.
- patch 2: replace poll()-based check with a wait_for_remote_key() helper that polls MPTCP_INFO until MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED is set, ensuring the third ACK has been processed before checking SIOCINQ. Add SOL_MPTCP fallback definition and handle ENOPROTOOPT/EOPNOTSUPP for TCP or fallback sockets.
- patches 3-7: no changes.
v6:
- patch 2: add Fixes tag, and use '-net' prefix.
- patch 3: remove poll() call, check SIOCINQ directly after accept().
- patch 6: add READ_ONCE() for msk->flags and msk->cb_flags reads in mptcp_rate_check_app_limited() to annotate intentionally racy accesses.
- update commit logs.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v5:
- patch 2: new patch - rewrite mptcp_inq_hint() to use mptcp_data_avail() instead of ack_seq - map_seq, completely avoiding TFO overflow issues.
- patch 3: new patch - add TFO SIOCINQ overflow detection in
mptcp_connect test to catch INT_MAX returns on TFO connections.
- patch 4: mptcp_inq() now returns INT_MAX instead of 0 when avail >=
INT_MAX. Removed mptcp_inq_hint() changes (moved to patch 2).
- patch 6: replace mptcp_rtx_head() check with MPTCP_WORK_RTX and MPTCP_RETRANSMIT flag checks in mptcp_rate_check_app_limited() to
properly detect pending retransmissions without data race issues.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v4:
- patch 2: fix mptcp_inq_hint() to return 0 instead of INT_MAX on
passive TFO overflow (ack_seq - map_seq >= INT_MAX).
- patch 4: add mptcp_rtx_head(sk) to the early-return check in mptcp_rate_check_app_limited() so pending retransmissions also
prevent false app-limited marking.
- patch 5: update comment message.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v3:
- patch 2: drop DATA_FIN subtraction in mptcp_inq(), remove the
intermediate 'answ' variable and return (unsigned int)avail
directly. Update commit message accordingly.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v2:
- drop the patch "prevent dummy DATA_FIN on RST in fallback mode".
- keep mptcp_inq_hint in mptcp_ioctl unchanged.
- use mptcp_data_avail in mptcp_inq.
- add msk_owned_by_me check in mptcp_sendmsg_locked.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v1:
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
This series was previously posted as part of "Reduce the differences between TCP and MPTCP for TLS usage" v15. It creates the mptcp_inq() and mptcp_sendmsg_locked() interfaces that are required for the upcoming MPTCP kTLS and MPTCP sockmap implementations.
The series has been rebased and no longer depends on Paolo's CB layout refactoring patches (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). Those patches are more complex and will be sent in a separate series.
Patch overview:
1. mptcp: update mptcp_check_readable
- Align with TCP's sock_is_readable for better TLS compatibility
2. mptcp: prevent dummy DATA_FIN on RST in fallback mode
- Fix semantic issue where RST on fallback connections would create dummy DATA_FIN, causing unnecessary state transitions
- Add sk_err check to subflow_is_done() to distinguish abortive closes (RST) from clean closes (FIN)
3. mptcp: implement peek_len for proto_ops
- Add mptcp_inq() to report readable bytes at MPTCP level
- Wire into .peek_len proto_ops for both IPv4 and IPv6
- Handle 32-bit torn reads by returning 0 instead of INT_MAX
- Prepare for TLS strparser integration
4. mptcp: add sendmsg_locked to proto_ops
- Split mptcp_sendmsg() into locked/unlocked variants
- Expose .sendmsg_locked in proto_ops for TLS send path
5. mptcp: track app-limited state in mptcp_sendmsg
- Add mptcp_rate_check_app_limited() to mark subflows as app-limited
- Bail out when MPTCP has unsent data (write_seq != snd_nxt or mptcp_send_head() != NULL) to avoid false app-limited marking
- Enable accurate delivery rate estimation for BBR
6. selftests: mptcp: sockopt: check app_limited
- Add regression test for app-limited accounting
- Verify tcpi_delivery_rate_app_limited == 1 after small transfers
Gang Yan (1):
mptcp: update mptcp_check_readable
Geliang Tang (6):
mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
selftests: mptcp: connect: check TFO SIOCINQ overflow
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
net/mptcp/protocol.c | 96 +++++++++++++++---- .../selftests/net/mptcp/mptcp_connect.c | 44 +++++++++ .../selftests/net/mptcp/mptcp_sockopt.c | 5 + 3 files changed, 127 insertions(+), 18 deletions(-)
Signature · 1 line
2.55.0
Geliang Tang
reviewerPATCH v7 1/7 mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
From: Geliang Tang <[email protected]>
Fix mptcp_inq_hint() to compute available bytes using mptcp_data_avail() (bytes_received - bytes_consumed) instead of ack_seq minus the head skb's map_seq.
On passive TFO connections, the TFO skb has map_seq set to -skb->len. Without the removed __mptcp_fastopen_gen_msk_ackseq() to adjust the TFO skb's map_seq, mptcp_inq_hint() computes "ack_seq - map_seq = iasn + len", almost always >= INT_MAX, causing SIOCINQ/FIONREAD and TCP_CM_INQ to report INT_MAX.
Using mptcp_data_avail() avoids this by tracking bytes directly. When RCV_SHUTDOWN is set (DATA_FIN received), add 1 to include the FIN byte, matching the previous ack_seq - map_seq behavior.
--- net/mptcp/protocol.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
net/mptcp/protocol.c +7 -11
@@ -2402,22 +2402,18 @@ static bool mptcp_move_skbs(struct sock *sk)static unsigned int mptcp_inq_hint (const struct sock *sk) {const struct mptcp_sock *msk =mptcp_sk (sk); -const struct sk_buff *skb; +u64 hint_val =mptcp_data_avail (msk); - skb =skb_peek (&sk->sk_receive_queue); -if (skb) { -u64 hint_val =READ_ONCE (msk->ack_seq) -MPTCP_SKB_CB (skb)->map_seq; +if (hint_val >=INT_MAX ) +return INT_MAX ; -if (hint_val >=INT_MAX ) -return INT_MAX ; +if (sk->sk_shutdown &RCV_SHUTDOWN ) + hint_val++; -return (unsigned int )hint_val; - } - -if (sk->sk_state ==TCP_CLOSE || (sk->sk_shutdown &RCV_SHUTDOWN )) +if (!hint_val && sk->sk_state ==TCP_CLOSE )return 1 ; -return 0 ; +return (unsigned int )hint_val; } static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH mptcp-net v7 1/7] mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] In net/mptcp/protocol.c, mptcp_inq_hint() now adds 1 whenever RCV_SHUTDOWN is set (`if (sk->sk_shutdown & RCV_SHUTDOWN)…
- [Low] The commit author is Geliang Tang <[email protected]>, but the only Signed-off-by is Geliang Tang <[email protected]>.
--
mptcp: fix TFO SIOCINQ overflow in mptcp_inq_hint
This commit changes mptcp_inq_hint() to compute the available bytes with mptcp_data_avail() instead of ack_seq minus the head skb's map_seq. The goal is to stop reporting INT_MAX on passive TFO connections. It also adds 1 to the result when RCV_SHUTDOWN is set, to account for the DATA_FIN byte.
Quoted 2 lines
Fixes f03afb3aeb9d ("mptcp: drop __mptcp_fastopen_gen_msk_ackseq()")Signed-off-by Geliang Tang <[email protected]>
[Severity: Low]
This isn't a bug, but the Author: line is Geliang Tang <[email protected]> while the only Signed-off-by is Geliang Tang <[email protected]>. checkpatch reports this as FROM_SIGN_OFF_MISMATCH.
Could the author and Signed-off-by identities be made to match?
Quoted 11 lines
net/mptcp/protocol.c +1
-1@@ -2402,22 +2402,18 @@ static bool mptcp_move_skbs(struct sock *sk)static unsigned int mptcp_inq_hint (const struct sock *sk) {const struct mptcp_sock *msk =mptcp_sk (sk); -const struct sk_buff *skb; +u64 hint_val =mptcp_data_avail (msk);
net/mptcp/protocol.c static bool mptcp_move_skbs(struct sock *sk) · line 2411
Quoted 10 lines
net/mptcp/protocol.c +4
-5- skb =skb_peek (&sk->sk_receive_queue); -if (skb) { -u64 hint_val =READ_ONCE (msk->ack_seq) -MPTCP_SKB_CB (skb)->map_seq; +if (hint_val >=INT_MAX ) +return INT_MAX ; -if (hint_val >=INT_MAX ) -return INT_MAX ; +if (sk->sk_shutdown &RCV_SHUTDOWN ) + hint_val++;
[Severity: Medium]
Can RCV_SHUTDOWN be relied on here to mean that a DATA_FIN was received?
The commit message says:
When RCV_SHUTDOWN is set (DATA_FIN received), add 1 to include the FIN byte, matching the previous ack_seq - map_seq behavior.
As far as I can tell, mptcp_check_data_fin() is the only path that sets RCV_SHUTDOWN and also bumps ack_seq for the FIN byte:
net/mptcp/protocol.c:mptcp_check_data_fin() {
...
if (mptcp_pending_data_fin(sk, &rcv_data_fin_seq)) {
WRITE_ONCE(msk->ack_seq, msk->ack_seq + 1);
...
WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | RCV_SHUTDOWN);
...
}At least two other paths seem to set RCV_SHUTDOWN without a DATA_FIN, while unread data is still sitting in sk_receive_queue.
The first is a local shutdown(fd, SHUT_RD). mptcp_stream_ops.shutdown is inet_shutdown(), which does sk->sk_shutdown |= how. mptcp_shutdown() only acts on SEND_SHUTDOWN.
The second is a peer MP_FASTCLOSE, through
mptcp_worker()->mptcp_check_fastclose():
net/mptcp/protocol.c:mptcp_check_fastclose() {
...
mptcp_set_state(sk, TCP_CLOSE);
WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
...
}This path does not purge the msk receive queue.
Suppose N bytes are unread in either case. The old code returned ack_seq - map_seq = N, because ack_seq was never bumped for a FIN. Won't the new code return bytes_received - bytes_consumed + 1 = N + 1?
That value reaches userspace through mptcp_ioctl() for SIOCINQ/FIONREAD and through the TCP_CM_INQ cmsg in mptcp_recvmsg(). It is also subtracted from rcvq_space.copied in mptcp_rcv_space_adjust().
For comparison, plain TCP bases its FIN adjustment on SOCK_DONE, not on RCV_SHUTDOWN:
include/net/tcp.h:tcp_inq() {
...
/* Subtract 1, if FIN was received */
if (answ && sock_flag(sk, SOCK_DONE))
answ--;
...
}So TCP still reports N after SHUT_RD.
Would it be better to base the +1 on the DATA_FIN actually having been received, rather than on RCV_SHUTDOWN?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794053683.git.tanggeliang%40kylinos.cn
Geliang Tang
reviewerPATCH v7 2/7 selftests: mptcp: connect: check TFO SIOCINQ overflow
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Add a SIOCINQ check in mptcp_connect's server mode when the MPTFO socket option is enabled to detect TFO SIOCINQ overflow regressions.
When a TFO connection is accepted, the test polls MPTCP_INFO until the MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED flag is set (with 100ms timeout), ensuring the third ACK has been processed. It then checks if SIOCINQ returns INT_MAX, which would indicate the regression where mptcp_inq_hint() incorrectly returns INT_MAX for passive TFO connections.
Add SOL_MPTCP fallback definition for compatibility with older libc headers. Handle ENOPROTOOPT and EOPNOTSUPP errors from getsockopt() to skip the wait for TCP sockets or MPTCP sockets that fell back to TCP.
--- .../selftests/net/mptcp/mptcp_connect.c | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_connect.c +44 -0
@@ -34,6 +34,7 @@#include <linux/time_types.h> #include <linux/sockios.h> #include <linux/compiler.h> +#include <linux/mptcp.h> extern int optind;
@@ -43,6 +44,9 @@ extern int optind;#ifndef TCP_ULP #define TCP_ULP 31#endif +#ifndef SOL_MPTCP +#define SOL_MPTCP 284 +#endif static int poll_timeout =10 *1000 ;static bool listen_mode;
@@ -1176,6 +1180,28 @@ static void maybe_close(int fd)close (fd); } +static bool wait_for_remote_key (int fd) +{ +struct mptcp_info info; +int retries =10 ; +socklen_t olen; + +while (retries >0 ) { + olen =sizeof (info); +if (getsockopt (fd,SOL_MPTCP ,MPTCP_INFO , &info, &olen) <0 ) { +/* Not an MPTCP socket (TCP or fallback), skip wait */ +if (errno ==ENOPROTOOPT || errno ==EOPNOTSUPP ) +return true; +return false; + } +if (info.mptcpi_flags &MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED ) +return true; +usleep (10000 ); + retries--; + } +return false; +} +int main_loop_s (int listensock) {struct sockaddr_storage ss;
@@ -1207,6 +1233,24 @@ int main_loop_s(int listensock)check_sockaddr (pf, &ss, salen);check_getpeername (remotesock, &ss, salen); +if (cfg_sockopt_types.mptfo) { +int avail; + +if (!wait_for_remote_key (remotesock)) { +fprintf (stderr, +"TFO: timeout waiting for third ACK\n" ); +close (remotesock); +return 1 ; + } + +if (ioctl (remotesock,SIOCINQ , &avail) ==0 && + avail ==INT_MAX ) { +fprintf (stderr,"TFO SIOCINQ overflow\n" ); +close (remotesock); +return 1 ; + } + } +if (cfg_input) { fd =open (cfg_input,O_RDONLY );if (fd <0 )
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH mptcp-next v7 2/7] selftests: mptcp: connect: check TFO SIOCINQ overflow
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The new MPTFO SIOCINQ check in tools/testing/selftests/net/mptcp/mptcp_connect.c only waits 100 ms…
--
selftests: mptcp: connect: check TFO SIOCINQ overflow
This adds a SIOCINQ check to mptcp_connect's server mode when the MPTFO socket option is enabled. After accept(), the server polls MPTCP_INFO for MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED for up to 100ms. It then fails the test if SIOCINQ returns INT_MAX.
Quoted 4 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c +0
-0
[ ... ]
Quoted 15 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c +11
-0@@ -1176,6 +1180,28 @@ static void maybe_close(int fd)close (fd); } +static bool wait_for_remote_key (int fd) +{ +struct mptcp_info info; +int retries =10 ; +socklen_t olen; + +while (retries >0 ) { + olen =sizeof (info); +if (getsockopt (fd,SOL_MPTCP ,MPTCP_INFO , &info, &olen) <0 ) { +/* Not an MPTCP socket (TCP or fallback), skip wait */ +if (errno ==ENOPROTOOPT || errno ==EOPNOTSUPP )
tools/testing/selftests/net/mptcp/mptcp_connect.c static void maybe_close(int fd) · line 1203
Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c +10
-0+return true; +return false; + } +if (info.mptcpi_flags &MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED ) +return true; +usleep (10000 ); + retries--; + } +return false; +}
[Severity: Medium]
Can this fixed budget of 10 x 10ms cause false MPTFO failures on slow machines?
On a passive TFO connection, accept() returns once the SYN with data has been processed. That is before the client's third ACK arrives.
The flag polled here comes from msk->can_ack in mptcp_diag_fill_info(). The only place can_ack gets set is subflow_set_remote_key():
net/mptcp/subflow.c:subflow_set_remote_key() {
...
WRITE_ONCE(msk->can_ack, true);
...
}That code runs only when the client's MPC third ACK, or its first MPC+DSS data segment, goes through __mptcp_subflow_fully_established().
Nothing synchronizes the server-side wait with the peer's ACK except elapsed time. The SYN-ACK -> third ACK round trip in ns2 can take more than 100ms, for example on debug kernels with KASAN, lockdep or kmemleak, in nested VMs, or on loaded CI hosts. The key can also arrive only with a later segment or a retransmit. In those cases this helper returns false, and main_loop_s() does:
fprintf(stderr, "TFO: timeout waiting for third ACK\n"); close(remotesock); return 1;
As a result, the MPTFO group in mptcp_connect.sh would be marked failed on a kernel that does not have the SIOCINQ overflow.
Any getsockopt() error other than ENOPROTOOPT or EOPNOTSUPP also returns false here, and that gets reported as the same timeout.
The harness sets timeout_poll=30 and passes "-t ${timeout_poll}" to the listener (poll_timeout), but this wait does not use that value.
Could the wait be based on poll_timeout instead? Another option is to skip the SIOCINQ check with a notice, rather than returning 1, when the key does not arrive in time.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794053683.git.tanggeliang%40kylinos.cn
Geliang Tang
reviewerPATCH v7 3/7 mptcp: implement peek_len for proto_ops
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Add mptcp_inq() to compute readable bytes at the MPTCP level using mptcp_data_avail() (bytes_received - bytes_consumed). It returns 0 during handshake (TCPF_SYN_SENT/TCPF_SYN_RECV), INT_MAX when avail >= INT_MAX, otherwise 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.
Unlike mptcp_inq_hint() (used by SIOCINQ), mptcp_inq() does not include the EOF hint (returning 1 when socket is closed with no data) because peek_len is used by strparser to check whether the whole message is already queued, not to report connection state to userspace. It also does not drain the backlog before reading counters; the caller mptcp_ioctl() handles that for SIOCINQ, while strparser only needs a heuristic value.
This prepares for upcoming kTLS and sockmap support.
--- net/mptcp/protocol.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
net/mptcp/protocol.c +22 -0
@@ -4790,6 +4790,26 @@ 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); +u64 avail; + +if ((1 << sk->sk_state) & (TCPF_SYN_SENT |TCPF_SYN_RECV )) +return 0 ; + + avail =mptcp_data_avail (msk); +if (avail >=INT_MAX ) +return INT_MAX ; + +return (unsigned int )avail; +} + +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 ,
@@ -4812,6 +4832,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 = {
@@ -4924,6 +4945,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.55.0
Geliang Tang
reviewerPATCH v7 4/7 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. Add msk_owned_by_me() assertion to enforce the locking requirement. Expose .sendmsg_locked in both mptcp_stream_ops and mptcp_v6_stream_ops.
Unlike tcp_sendmsg_locked(), mptcp_sendmsg_locked() drops the MSG_SPLICE_PAGES flag from the mask. Future kTLS and sockmap support will require additional changes to call through proto_ops->sendmsg_locked instead of tcp_sendmsg_locked() directly.
--- net/mptcp/protocol.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
net/mptcp/protocol.c +16 -4
@@ -2038,7 +2038,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;
@@ -2046,12 +2046,12 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)int ret =0 ;long timeo; +msk_owned_by_me (msk); +/* silently ignore everything else */ 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) ||
@@ -2167,7 +2167,6 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) } out: -release_sock (sk);return copied; do_error:
@@ -2180,6 +2179,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)
@@ -4833,6 +4843,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 = {
@@ -4946,6 +4957,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.55.0
[email protected]
AI reviewRe: [PATCH mptcp-next v7 4/7] mptcp: add sendmsg_locked to proto_ops
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The patch adds .sendmsg_locked = mptcp_sendmsg_locked to mptcp_stream_ops (net/mptcp/protocol.c:4846) and…
--
mptcp: add sendmsg_locked to proto_ops
This splits mptcp_sendmsg() into mptcp_sendmsg_locked(), which expects the caller to already hold the msk socket lock and asserts this with msk_owned_by_me(), and a small wrapper that takes and releases the lock. The locked variant is then exposed as .sendmsg_locked in both mptcp_stream_ops and mptcp_v6_stream_ops.
Quoted 4 lines
net/mptcp/protocol.c +0
-0
[ ... ]
net/mptcp/protocol.c static const struct proto_ops mptcp_stream_ops = { · line 4847
Quoted 6 lines
net/mptcp/protocol.c +1
-0@@ -4833,6 +4843,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, };
[Severity: Low]
Is there an in-tree path that can reach this op on an MPTCP socket?
The only code that dispatches proto_ops->sendmsg_locked seems to be the static helper in net/core/skbuff.c. Only skb_send_sock_locked() and skb_send_sock_locked_with_flags() use it:
net/core/skbuff.c:sendmsg_locked() {
...
if (!sock->ops->sendmsg_locked)
return sock_no_sendmsg_locked(sk, msg, size);
return sock->ops->sendmsg_locked(sk, msg, size);
}Neither of the two in-tree users of those helpers looks like it can be attached to an msk.
espintcp in net/xfrm/espintcp.c is a TCP ULP, andmptcp_setsockopt_sol_tcp() rejects TCP_ULP:
case TCP_ULP: return -EOPNOTSUPP;
ovpn_socket_attach() in drivers/net/ovpn/socket.c only accepts UDP and TCP sockets:
if (sock->sk->sk_protocol == IPPROTO_UDP) return ovpn_udp_socket_attach(ovpn_sock, sock, peer->ovpn); else if (sock->sk->sk_protocol == IPPROTO_TCP) return ovpn_tcp_socket_attach(ovpn_sock, peer); return -EOPNOTSUPP;
The commit message also says that kTLS (net/tls/tls_main.c) and sockmap (net/ipv4/tcp_bpf.c) call tcp_sendmsg_locked() directly and need "additional changes". As far as I can tell, no patch up to and including "mptcp: update mptcp_check_readable" makes those changes or adds another caller.
So mptcp_sendmsg_locked() cannot currently be reached through proto_ops. That leaves its semantics without a user or a test to check them against. One example is masking out MSG_SPLICE_PAGES, even though __skb_send_sock() always sets that flag for frag pages.
Could the .sendmsg_locked registration move to the patch that adds its first caller?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794053683.git.tanggeliang%40kylinos.cn
Geliang Tang
reviewerPATCH v7 5/7 mptcp: track app-limited state in mptcp_sendmsg
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Add mptcp_rate_check_app_limited() that walks every subflow and runs tcp_rate_check_app_limited() under each subflow's socket lock. The helper bails out early when MPTCP still has data to send: unsent data (write_seq != snd_nxt), pending dfrags (mptcp_send_head), or pending retransmission (MPTCP_WORK_RTX or MPTCP_RETRANSMIT flags). In these cases marking subflows app-limited would mislead congestion controllers.
Invoke from mptcp_sendmsg_locked() after send-side setup so BBR and similar controllers can ignore rate samples taken while the connection is genuinely application-limited. The per-subflow locking only occurs when the MPTCP send queue is empty, which is the correct scenario to mark the connection as application-limited.
--- net/mptcp/protocol.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
net/mptcp/protocol.c +27 -0
@@ -2038,6 +2038,30 @@ 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; +unsigned long flags, cb_flags; + + flags =READ_ONCE (msk->flags); + cb_flags =READ_ONCE (msk->cb_flags); + +if (msk->write_seq != msk->snd_nxt ||mptcp_send_head (sk) || +test_bit (MPTCP_WORK_RTX , &flags) || +test_bit (MPTCP_RETRANSMIT , &cb_flags)) +return ; + +mptcp_for_each_subflow (msk, subflow) { +struct sock *ssk =mptcp_subflow_tcp_sock (subflow); +bool slow; + + slow =lock_sock_fast_nested (ssk); +tcp_rate_check_app_limited (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);
@@ -2068,6 +2092,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.55.0
[email protected]
AI reviewRe: [PATCH mptcp-next v7 5/7] mptcp: track app-limited state in mptcp_sendmsg
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The From: address and the Signed-off-by address of commit "mptcp:
track app-limited state in mptcp_sendmsg" do not match.
--
mptcp: track app-limited state in mptcp_sendmsg
This commit adds mptcp_rate_check_app_limited(), which walks the subflows and calls tcp_rate_check_app_limited() on each one when the MPTCP send queue is empty and no retransmission is pending. It is called from mptcp_sendmsg_locked(), so BBR and similar congestion controllers can ignore rate samples taken while the connection is application-limited.
Quoted 1 line
Signed-off-by Geliang Tang <[email protected]>
[Severity: Low]
This isn't a bug, but the From: and Signed-off-by: addresses don't match.
The author is recorded as:
Author: Geliang Tang <[email protected]>
but the only trailer is:
checkpatch.pl reports this as FROM_SIGN_OFF_MISMATCH. The last patch in this series, "mptcp: update mptcp_check_readable", uses the kernel.org address in its Signed-off-by.
Could this be resent with a matching From:, or with an extra
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794053683.git.tanggeliang%40kylinos.cn
Geliang Tang
reviewerPATCH v7 6/7 selftests: mptcp: sockopt: check app_limited
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
After a small data exchange, assert tcpi_delivery_rate_app_limited == 1 when expect_all_features() is enabled.
rate_app_limited starts at 1 (tcp_init_sock) and is cleared only by non-app-limited rate samples. The preceding commit makes mptcp_rate_check_app_limited() set tp->app_limited on subflows when MPTCP has no pending data, marking outgoing skbs as app-limited so rate samples don't clear rate_app_limited.
This guards against regressions where subflows are never marked app-limited. The test covers the empty-queue path only; the early return in mptcp_rate_check_app_limited() (when MPTCP has pending data or retransmissions) is not exercised by this test.
--- tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 5 +++++ 1 file changed, 5 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +5 -0
@@ -635,6 +635,11 @@ static void connect_one_server(int fd, int pipefd)do_getsockopts (&s, fd, total, total);assert (s.mptcpi_rcv_delta == (uint64_t )total); + +/* app-limited accounting only checked under EXPECT_ALL_FEATURES */ +if (expect_all_features ()) +assert (s.tcp_info.tcpi_delivery_rate_app_limited ==1 ); +close (fd); }
Signature · 1 line
2.55.0
Geliang Tang
reviewerPATCH v7 7/7 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
@@ -3509,9 +3509,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)
@@ -4613,7 +4615,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.55.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): Unstable: 1 failed test(s): selftest_diag ⚠️
- 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: Unstable: 1 failed test(s): validation:sched-bbr ⚠️
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/42373664681
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/50d98c10d06e
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1204872
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)