All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH mptcp-next v2 1/2] tcp: define initial scaling factor value as a macro
@ 2023-10-02  9:13 Paolo Abeni
  2023-10-02  9:13 ` [PATCH mptcp-next v2 2/2] Squash-to: "mptcp: give rcvlowat some love" Paolo Abeni
  2023-10-03 16:45 ` [PATCH mptcp-next v2 1/2] tcp: define initial scaling factor value as a macro Matthieu Baerts
  0 siblings, 2 replies; 4+ messages in thread
From: Paolo Abeni @ 2023-10-02  9:13 UTC (permalink / raw)
  To: mptcp; +Cc: Christoph Paasch

So that other users could access it. Notably MPTCP will use
it in the next patch.

No functional change intended.

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
 include/net/tcp.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/include/net/tcp.h b/include/net/tcp.h
index 91688d0dadcd..8b0364b44dd9 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1453,13 +1453,15 @@ static inline int tcp_space_from_win(const struct sock *sk, int win)
 	return __tcp_space_from_win(tcp_sk(sk)->scaling_ratio, win);
 }
 
+/* Assume a conservative default of 1200 bytes of payload per 4K page.
+ * This may be adjusted later in tcp_measure_rcv_mss().
+ */
+#define TCP_DEFAULT_SCALING_RATIO ((1200 << TCP_RMEM_TO_WIN_SCALE) / \
+				   SKB_TRUESIZE(4096))
+
 static inline void tcp_scaling_ratio_init(struct sock *sk)
 {
-	/* Assume a conservative default of 1200 bytes of payload per 4K page.
-	 * This may be adjusted later in tcp_measure_rcv_mss().
-	 */
-	tcp_sk(sk)->scaling_ratio = (1200 << TCP_RMEM_TO_WIN_SCALE) /
-				    SKB_TRUESIZE(4096);
+	tcp_sk(sk)->scaling_ratio = TCP_DEFAULT_SCALING_RATIO;
 }
 
 /* Note: caller must be prepared to deal with negative returns */
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH mptcp-next v2 2/2] Squash-to: "mptcp: give rcvlowat some love"
  2023-10-02  9:13 [PATCH mptcp-next v2 1/2] tcp: define initial scaling factor value as a macro Paolo Abeni
@ 2023-10-02  9:13 ` Paolo Abeni
  2023-10-03 16:59   ` Matthieu Baerts
  2023-10-03 16:45 ` [PATCH mptcp-next v2 1/2] tcp: define initial scaling factor value as a macro Matthieu Baerts
  1 sibling, 1 reply; 4+ messages in thread
From: Paolo Abeni @ 2023-10-02  9:13 UTC (permalink / raw)
  To: mptcp; +Cc: Christoph Paasch

Christoph reported a couple of serious splat caused by
the mentioned patch.

mptcp_set_rcvlowat() can use msk->scaling_ratio, before
such field is initialized, causing a divide by zero: we
need to init it in the sock constructor.

Additionally the same function bogusly cast an msk to a
tcp_sock, causing memory corruption. The reproducer likely
clears the sk refcount for the next msk allocated into the
same slab.

The intent was to properly propagate the rcvbuf changes to
the subflows. Let's do that explicitly.

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
--
Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/442
Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/443

since the above issues are introduced by the squash-to patch, I think
we can't have the tag in the final patch.

v1 -> v2:
 - use scaling_ratio define (Mat)
---
 net/mptcp/protocol.c |  1 +
 net/mptcp/sockopt.c  | 17 ++++++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 6f9e116598ed..990fcf53074a 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2758,6 +2758,7 @@ static void __mptcp_init_sock(struct sock *sk)
 	msk->rmem_fwd_alloc = 0;
 	WRITE_ONCE(msk->rmem_released, 0);
 	msk->timer_ival = TCP_RTO_MIN;
+	msk->scaling_ratio = TCP_DEFAULT_SCALING_RATIO;
 
 	WRITE_ONCE(msk->first, NULL);
 	inet_csk(sk)->icsk_sync_mss = mptcp_sync_mss;
diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
index 340e87195a27..6b37946b5c52 100644
--- a/net/mptcp/sockopt.c
+++ b/net/mptcp/sockopt.c
@@ -1473,6 +1473,7 @@ void mptcp_sockopt_sync_locked(struct mptcp_sock *msk, struct sock *ssk)
  */
 int mptcp_set_rcvlowat(struct sock *sk, int val)
 {
+	struct mptcp_subflow_context *subflow;
 	int space, cap;
 
 	if (sk->sk_userlocks & SOCK_RCVBUF_LOCK)
@@ -1490,9 +1491,19 @@ int mptcp_set_rcvlowat(struct sock *sk, int val)
 		return 0;
 
 	space = __tcp_space_from_win(mptcp_sk(sk)->scaling_ratio, val);
-	if (space > sk->sk_rcvbuf) {
-		WRITE_ONCE(sk->sk_rcvbuf, space);
-		tcp_sk(sk)->window_clamp = val;
+	if (space <= sk->sk_rcvbuf)
+		return 0;
+
+	/* propagate the rcvbuf changes to all the subflows */
+	WRITE_ONCE(sk->sk_rcvbuf, space);
+	mptcp_for_each_subflow(mptcp_sk(sk), subflow) {
+		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+		bool slow;
+
+		slow = lock_sock_fast(ssk);
+		WRITE_ONCE(ssk->sk_rcvbuf, space);
+		tcp_sk(ssk)->window_clamp = val;
+		unlock_sock_fast(ssk, slow);
 	}
 	return 0;
 }
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH mptcp-next v2 1/2] tcp: define initial scaling factor value as a macro
  2023-10-02  9:13 [PATCH mptcp-next v2 1/2] tcp: define initial scaling factor value as a macro Paolo Abeni
  2023-10-02  9:13 ` [PATCH mptcp-next v2 2/2] Squash-to: "mptcp: give rcvlowat some love" Paolo Abeni
@ 2023-10-03 16:45 ` Matthieu Baerts
  1 sibling, 0 replies; 4+ messages in thread
From: Matthieu Baerts @ 2023-10-03 16:45 UTC (permalink / raw)
  To: Paolo Abeni, mptcp; +Cc: Christoph Paasch

Hi Paolo,

On 02/10/2023 11:13, Paolo Abeni wrote:
> So that other users could access it. Notably MPTCP will use
> it in the next patch.
> 
> No functional change intended.

Thank you for the new version, it looks good to me!

Acked-by: Matthieu Baerts <matttbe@kernel.org>

Cheers,
Matt

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH mptcp-next v2 2/2] Squash-to: "mptcp: give rcvlowat some love"
  2023-10-02  9:13 ` [PATCH mptcp-next v2 2/2] Squash-to: "mptcp: give rcvlowat some love" Paolo Abeni
@ 2023-10-03 16:59   ` Matthieu Baerts
  0 siblings, 0 replies; 4+ messages in thread
From: Matthieu Baerts @ 2023-10-03 16:59 UTC (permalink / raw)
  To: Paolo Abeni, mptcp; +Cc: Christoph Paasch

Hi Paolo,

On 02/10/2023 11:13, Paolo Abeni wrote:
> Christoph reported a couple of serious splat caused by
> the mentioned patch.
> 
> mptcp_set_rcvlowat() can use msk->scaling_ratio, before
> such field is initialized, causing a divide by zero: we
> need to init it in the sock constructor.
> 
> Additionally the same function bogusly cast an msk to a
> tcp_sock, causing memory corruption. The reproducer likely
> clears the sk refcount for the next msk allocated into the
> same slab.
> 
> The intent was to properly propagate the rcvbuf changes to
> the subflows. Let's do that explicitly.
> 
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> --
> Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/442
> Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/443

Thank you for the patches!

Now in our tree (I added patch 1/2 just before "mptcp: give rcvlowat
some love")

New patches for t/upstream:
- 3a6e7c602676: tcp: define initial scaling factor value as a macro
- 4b8e173a713a: "squashed" patch 2/2 in "mptcp: give rcvlowat some love"
- Results: 3cbb19268039..ad8e597b726a (export)

Tests are now in progress:

https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20231003T165758

Cheers,
Matt

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-03 16:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-02  9:13 [PATCH mptcp-next v2 1/2] tcp: define initial scaling factor value as a macro Paolo Abeni
2023-10-02  9:13 ` [PATCH mptcp-next v2 2/2] Squash-to: "mptcp: give rcvlowat some love" Paolo Abeni
2023-10-03 16:59   ` Matthieu Baerts
2023-10-03 16:45 ` [PATCH mptcp-next v2 1/2] tcp: define initial scaling factor value as a macro Matthieu Baerts

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.