Skip to contentSkip to conversation

mptcp: support MSG_EOR in mptcp_sendmsg

RFC In review Gang Yan 4 participants 5 messages Feb 3 – Mar 4

Subsystems (2)
lore
Share & tools
lore

Gang Yan

author
#0 lore raw

RFC v2 1/1 mptcp: support MSG_EOR in mptcp_sendmsg

From: Gang Yan <[email protected]>

This patch adds support for the MSG_EOR flag in MPTCP's sendmsg path, ensuring that data fragments marked with MSG_EOR are properly handled to prevent coalescing with subsequent data.

Key changes:
1. Added an 'eor' field to struct mptcp_data_frag to track MSG_EOR marking
2. Initialize the eor field to 0 in mptcp_carve_data_frag()
3. In mptcp_sendmsg_frag(), when sending the last chunk of a data fragment that has MSG_EOR set, mark the corresponding skb with 'TCP_SKB_CB(skb)->eor=1' to prevent coalescing with subsequent data
4. Modified mptcp_sendmsg() to:
- Preserve MSG_EOR flag in msg_flags filtering
- Mark the last pending data fragment with eor = 1 when MSG_EOR is set in the message flags

This ensures that applications using MSG_EOR to indicate record boundaries have their intent preserved across MPTCP subflows, maintaining proper message segmentation semantics.

---

Notes:
changelog:
v2:
- Fix code-style issues.
- Submitted a pull request to the mptcp_packetdrill repository:
https://github.com/multipath-tcp/packetdrill/pull/189

Hi Matt:

Thank you for your feedback on v1. I've addressed the suggestions in this updated version. Please take a look when you have a moment.

Thanks
Gang

 net/mptcp/protocol.c | 22 +++++++++++++++++++---
 net/mptcp/protocol.h |  1 +
 2 files changed, 20 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +19 -3
index c88882062c40..b8200765506f 100644
@@ -1174,6 +1174,7 @@ mptcp_carve_data_frag(const struct mptcp_sock *msk, struct page_frag *pfrag,
 	dfrag->offset = offset + sizeof(struct mptcp_data_frag);
 	dfrag->already_sent = 0;
 	dfrag->page = pfrag->page;
+	dfrag->eor = 0;
 
 	return dfrag;
 }
@@ -1434,6 +1435,13 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 		mptcp_update_infinite_map(msk, ssk, mpext);
 	trace_mptcp_sendmsg_frag(mpext);
 	mptcp_subflow_ctx(ssk)->rel_write_seq += copy;
+
+	 /* If this is the last chunk of a dfrag with MSG_EOR set
+	  * mark the skb to prevent coalescing with subsequent data
+	  */
+	if (dfrag->eor && info->sent + copy >= dfrag->data_len)
+		TCP_SKB_CB(skb)->eor = 1;
+
 	return copy;
 }
 
@@ -1894,7 +1902,8 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	long timeo;
 
 	/* silently ignore everything else */
-	msg->msg_flags &= MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL | MSG_FASTOPEN;
+	msg->msg_flags &= MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL |
+			  MSG_FASTOPEN | MSG_EOR;
 
 	lock_sock(sk);
 
@@ -2001,9 +2010,16 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 			goto do_error;
 	}
 
-	if (copied)
-		__mptcp_push_pending(sk, msg->msg_flags);
+	if (copied) {
+		/* Mark the last dfrag with EOR if MSG_EOR was set */
+		if (msg->msg_flags & MSG_EOR) {
+			struct mptcp_data_frag *dfrag = mptcp_pending_tail(sk);
 
+			if (dfrag)
+				dfrag->eor = 1;
+		}
+		__mptcp_push_pending(sk, msg->msg_flags);
+	}
 out:
 	release_sock(sk);
 	return copied;
net/mptcp/protocol.h +1 -0
index cd5266099993..8b243062009c 100644
@@ -267,6 +267,7 @@ struct mptcp_data_frag {
 	u16 overhead;
 	u16 already_sent;
 	struct page *page;
+	u8 eor;  /* Is MSG_EOR marked? Prevents coalescing with next frag */
 };
 
 /* Arbitrary compromise between as low as possible to react timely to subflow
Signature · 1 line
2.43.0
#1 lore raw

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: 2 failed test(s): packetdrill_dss packetdrill_fastopen 🔴
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/21614981304

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/68562b159b7f
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1050034

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-normal

For 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)

maintainer
#2 lore raw
In reply to Gang Yan

net/mptcp/protocol.h struct mptcp_data_frag { · line 270

Quoted 9 lines · Gang Yan
net/mptcp/protocol.h +1 -0
index cd5266099993..8b243062009c 100644
@@ -267,6 +267,7 @@ struct mptcp_data_frag {
 	u16 overhead;
 	u16 already_sent;
 	struct page *page;
+	u8 eor;  /* Is MSG_EOR marked? Prevents coalescing with next frag */

I'm sorry for the late feedback, but the above will waste quite a bit of memory due to alignment. I think you can change the 'overhead' size to u8 and place 'eor' after such field.

Such change could be paired with build time check vs 'overhead' overflow. i.e.

BUILD_BUG_ON(ALIGN(1, sizeof(long)) + sizeof(struct mptcp_data_frag) >
U8_MAX);

/P

reviewer
#3 lore raw

Hi Gang,

Quoted 17 lines · Paolo Abeni
Quoted 10 lines · Gang Yan
net/mptcp/protocol.h +1 -0
index cd5266099993..8b243062009c 100644
@@ -267,6 +267,7 @@ struct mptcp_data_frag {
  	u16 overhead;
  	u16 already_sent;
  	struct page *page;
+	u8 eor;  /* Is MSG_EOR marked? Prevents coalescing with

next frag */

I'm sorry for the late feedback, but the above will waste quite a bit of
memory due to alignment. I think you can change the 'overhead' size to
u8 and place 'eor' after such field.

I completely agree.
I think it's better not to let 'eor' use all 8 bits here; just one bit is
sufficient, leaving the other 7 bits for future use, similar to:

	u8 eor:1,
	   __unused:7;

I changed the state of this patch as "Changes Requested".

Thanks,
-Geliang

Quoted 10 lines

Such change could be paired with build time check vs 'overhead' overflow. i.e.

BUILD_BUG_ON(ALIGN(1, sizeof(long)) + sizeof(struct
mptcp_data_frag) >
U8_MAX);

/P

maintainer
#4 lore raw
Quoted 24 lines · Geliang Tang
Quoted 17 lines · Paolo Abeni
Quoted 10 lines · Gang Yan
net/mptcp/protocol.h +1 -0
index cd5266099993..8b243062009c 100644
@@ -267,6 +267,7 @@ struct mptcp_data_frag {
  	u16 overhead;
  	u16 already_sent;
  	struct page *page;
+	u8 eor;  /* Is MSG_EOR marked? Prevents coalescing with

next frag */

I'm sorry for the late feedback, but the above will waste quite a bit of
memory due to alignment. I think you can change the 'overhead' size to
u8 and place 'eor' after such field.

I completely agree.
I think it's better not to let 'eor' use all 8 bits here; just one bit is
sufficient, leaving the other 7 bits for future use, similar to:

Quoted 4 lines
	u8 eor:1,
	   __unused:7;

I changed the state of this patch as "Changes Requested".

Note that adding a trailing filed will still increases the struct mptcp_data_frag effective size by 8 bytes.

The maximum value that can land into the 'overhead' field is 'sizeof(struct mptcp_data_frag)' + 7; we can shrink such field to u8 and move the new one in the created hole. This will prevent struct mptcp_data_frag size increase.

An eventual build time check on the max 'overhead' value could be a plus, but it's probably too conservative, given that max is currently 47 and should not increase.

/P