Skip to contentSkip to conversation

mptcp: Avoid unsequenced accesses to jiffies in mptcp_reset_tout_timer()

PATCH Applied Nathan Chancellor 4 participants 4 messages Nov 15 – Nov 18

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mptcp: Avoid unsequenced accesses to jiffies in mptcp_reset_tout_timer()

After a recent improvement in clang to warn on unsequenced accesses to volatile variables [1], an instance appears in mptcp_reset_tout_timer(), which can break the build with CONFIG_WERROR=y / W=e:

net/mptcp/protocol.c:3044:20: error: unsequenced accesses to volatile qualified 'jiffies' [-Werror,-Wunsequenced]

   3044 |                         tcp_jiffies32 + jiffies + mptcp_close_timeout(sk);
        |                         ~~~~~~~~~~~~~   ^

Per C11 5.1.2.3.2, accessing a volatile object is a side effect. Per C11 6.5.2, unsequenced side effects on the same scalar object are undefined behavior. Per C11 6.5.3, unless otherwise specified, side effects and value computations of subexpressions are unsequenced within expressions.

Add an explicit sequence point by splitting the addition expression in half, eliminating the undefined behavior and clearing up the warning.

---
 net/mptcp/protocol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +2 -1
index 8968db58083e..8a9efebf3497 100644
@@ -3041,7 +3041,8 @@ void mptcp_reset_tout_timer(struct mptcp_sock *msk, unsigned long fail_tout)
 		return;
 
 	close_timeout = (unsigned long)inet_csk(sk)->icsk_mtup.probe_timestamp -
-			tcp_jiffies32 + jiffies + mptcp_close_timeout(sk);
+			tcp_jiffies32;
+	close_timeout += jiffies + mptcp_close_timeout(sk);
 
 	/* the close timeout takes precedence on the fail one, and here at least one of
 	 * them is active

---
base-commit: aa40afa831ebfe45e40a23721711059f2ac584d4
change-id: 20261114-mptcp-wunsequenced-ccbb861b3d4c

Best regards,

Signature · 2 lines
Cheers,
Nathan
#1 lore raw

Hi Nathan,

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: Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/43678670075

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

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 Reviewed-by on v1 1/1
#2 lore raw
In reply to Nathan Chancellor

Hi Nathan,

Quoted 8 lines · Nathan Chancellor

After a recent improvement in clang to warn on unsequenced accesses to volatile variables [1], an instance appears in mptcp_reset_tout_timer(), which can break the build with CONFIG_WERROR=y / W=e:

net/mptcp/protocol.c:3044:20: error: unsequenced accesses to volatile qualified 'jiffies' [-Werror,-Wunsequenced]

   3044 |                         tcp_jiffies32 + jiffies + mptcp_close_timeout(sk);
        |                         ~~~~~~~~~~~~~   ^
Quoted 7 lines

Per C11 5.1.2.3.2, accessing a volatile object is a side effect. Per C11 6.5.2, unsequenced side effects on the same scalar object are undefined behavior. Per C11 6.5.3, unless otherwise specified, side effects and value computations of subexpressions are unsequenced within expressions.

Add an explicit sequence point by splitting the addition expression in half, eliminating the undefined behavior and clearing up the warning.

Thank you for the fix, it looks good to me:

@Net maintainers: this can be applied in net directly (simple, safe, and avoid build break with -Werror on newer version of clang).

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
#3 lore raw
In reply to Nathan Chancellor
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Sat, 14 Nov 2026 21:30:07 -0700 you wrote:

After a recent improvement in clang to warn on unsequenced accesses to volatile variables [1], an instance appears in mptcp_reset_tout_timer(), which can break the build with CONFIG_WERROR=y / W=e:

net/mptcp/protocol.c:3044:20: error: unsequenced accesses to volatile qualified 'jiffies' [-Werror,-Wunsequenced]

   3044 |                         tcp_jiffies32 + jiffies + mptcp_close_timeout(sk);
        |                         ~~~~~~~~~~~~~   ^

[...]

Here is the summary with links:
- [net] mptcp: Avoid unsequenced accesses to jiffies in mptcp_reset_tout_timer()

    https://git.kernel.org/netdev/net/c/728a2abd15a7

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html