From nobody Sun Feb 8 07:57:50 2026 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:ab0:590e:0:0:0:0:0 with SMTP id n14csp1071737uad; Fri, 29 Jul 2022 11:14:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1urkRpVb24WBLxtocOjdDo4IFKIQ9POAb7bQils3gqVROb7ub8o68pfSYcZbH1W1CBh2c4H X-Received: by 2002:a05:620a:2491:b0:6b5:e53d:25dc with SMTP id i17-20020a05620a249100b006b5e53d25dcmr3665427qkn.540.1659118496680; Fri, 29 Jul 2022 11:14:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659118496; cv=none; d=google.com; s=arc-20160816; b=jhqq9SgG0uJVkct3rc8XiJg1sr1z8gdXbphBpTPiyX4bG5wrpwx1/obggf9u3EgCSo QiZBMaqvIj85ra7skrooYaL/lEwNXBISHTFRbtNBG+axJurOAJj1kKAkgfopvb6H40Rq 8CMWQsjYTLHNOm/AykUQVlqniCkbb8DDg8ap/tt3ajEjaHlenlBlQePW4rsY/KtIc1ng 3gJQviGvDY3yvRINvjdi7+RYB2XcRPh0IZmj4qaFoEGpHzPM/dinbW1m+Xe1sRNG25XB YASxMdsUy4YqUxCg6L1S3GgrFlspgH7NoKWWsuNK11NW8sZAMBWxPyzAMY9aTuvzhPby 8eeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=0cgJGv6YYOKjInMCrAks3Onl/Q3rxx/NYNKZdjKTGbI=; b=gpBRh3QS+pSvjXOdwdHjen0TlPvxw/9kzZrvSvU+N6RxFdBScQmSAV2FTA95WOntSY flTg/ewFIhpUjb5SI0KGq9Yq12QbrEdj2qjS+BAPs5r+12xlEW5dop9Ymx4agnUsRHIB LIu80WDjc70o40NCB9LwNyViccuan3u2O80/gZEGsC0C+MTgFP4WQL3/E/ewIvXcdb2H 3MDf4IOGleJxgtK2TOmhpeAD2Rr1W+V2Y2yeTBaafVKqT5jG5VeltEKGFNCXZsNDBD3E ka+u2gq+b57q+znD2RMb59q4mNoG+XIUjXy4aYa8vCMZMigFotea5hMha5kSbi4V14Ko Shsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JFu9lN5q; spf=pass (google.com: domain of mptcp+bounces-6078-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="mptcp+bounces-6078-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id u13-20020a05620a0c4d00b006b5fe583195si2921681qki.708.2022.07.29.11.14.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Jul 2022 11:14:56 -0700 (PDT) Received-SPF: pass (google.com: domain of mptcp+bounces-6078-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JFu9lN5q; spf=pass (google.com: domain of mptcp+bounces-6078-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="mptcp+bounces-6078-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8289D1C2093E for ; Fri, 29 Jul 2022 18:14:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 937684C77; Fri, 29 Jul 2022 18:14:54 +0000 (UTC) X-Original-To: mptcp@lists.linux.dev Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 592EA4C87 for ; Fri, 29 Jul 2022 18:14:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659118491; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0cgJGv6YYOKjInMCrAks3Onl/Q3rxx/NYNKZdjKTGbI=; b=JFu9lN5qttApv8YrD0DX1brbGbHNzGZ6gqcF/UqIm//BjnmXbUqLqD9QEqCXxlHu7jXhwA tPi3/SSqEDOW2PFVxCnv4JVF0xWZ0eQJBhwyYQhRXpIQgvsGFVkNQFAEcjqqQ8KpX84eIf ADUJW8J8Ynnjo5Bih9th2LAJGuAsDUg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-611-9j-fXJcNPaiOzJ0QlT8vEg-1; Fri, 29 Jul 2022 14:14:50 -0400 X-MC-Unique: 9j-fXJcNPaiOzJ0QlT8vEg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C0864800124 for ; Fri, 29 Jul 2022 18:14:49 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.39.192.205]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51B251121314 for ; Fri, 29 Jul 2022 18:14:49 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH v2 mptcp-next 2/4] mptcp: more accurate receive buffer updates Date: Fri, 29 Jul 2022 20:14:39 +0200 Message-Id: <1da024c8ed9da4fcf78aa2d73e00c1f9e4d3e98f.1659117128.git.pabeni@redhat.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pabeni@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8"; x-default="true" Currently mptcp_cleanup_rbuf() makes a significant effort to avoid acquiring the subflow socket lock, estimating if the tcp level cleanup could actually send an ack. Such estimate is a bit rough when accounting for receive window change, as it consider the msk available buffer space instead of the announced mptcp-level window. Let's consider the announced window instead, mirroring closely the plain TCP implementation. We need to lockless access a bunch of additional, tcp fields. Signed-off-by: Paolo Abeni --- include/net/mptcp.h | 2 ++ net/ipv4/tcp.c | 3 +++ net/mptcp/options.c | 1 - net/mptcp/protocol.c | 14 +++++++++++--- net/mptcp/protocol.h | 6 +++++- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 7af7fd48acc7..4b6c66b73bf4 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -136,6 +136,7 @@ static inline bool rsk_drop_req(const struct request_so= ck *req) return tcp_rsk(req)->is_mptcp && tcp_rsk(req)->drop_req; } =20 +void mptcp_receive_window(const struct sock *ssk, int *rwnd); void mptcp_space(const struct sock *ssk, int *space, int *full_space); bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb, unsigned int *size, struct mptcp_out_options *opts); @@ -284,6 +285,7 @@ static inline bool mptcp_skb_can_collapse(const struct = sk_buff *to, return true; } =20 +static inline void mptcp_receive_window(const struct sock *ssk, int *rwnd)= { } static inline void mptcp_space(const struct sock *ssk, int *s, int *fs) { } static inline void mptcp_seq_show(struct seq_file *seq) { } =20 diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 970e9a2cca4a..d0c0100f74f3 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1606,6 +1606,9 @@ void tcp_cleanup_rbuf(struct sock *sk, int copied) if (copied > 0 && !time_to_ack && !(sk->sk_shutdown & RCV_SHUTDOWN)) { __u32 rcv_window_now =3D tcp_receive_window(tp); =20 + if (sk_is_mptcp(sk)) + mptcp_receive_window(sk, &rcv_window_now); + /* Optimize, __tcp_select_window() is not cheap. */ if (2*rcv_window_now <=3D tp->window_clamp) { __u32 new_window =3D __tcp_select_window(sk); diff --git a/net/mptcp/options.c b/net/mptcp/options.c index 30d289044e71..563ef8fe5a85 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -604,7 +604,6 @@ static bool mptcp_established_options_dss(struct sock *= sk, struct sk_buff *skb, } opts->ext_copy.use_ack =3D 1; opts->suboptions =3D OPTION_MPTCP_DSS; - WRITE_ONCE(msk->old_wspace, __mptcp_space((struct sock *)msk)); =20 /* Add kind/length/subtype/flag overhead if mapping is not populated */ if (dss_size =3D=3D 0) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 5af3d591a20b..17e2dbe43639 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -535,6 +535,14 @@ static void mptcp_subflow_cleanup_rbuf(struct sock *ss= k) unlock_sock_fast(ssk, slow); } =20 +void mptcp_receive_window(const struct sock *ssk, int *rwnd) +{ + const struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(ssk); + const struct sock *sk =3D subflow->conn; + + *rwnd =3D __mptcp_receive_window(mptcp_sk(sk)); +} + static bool mptcp_subflow_could_cleanup(const struct sock *ssk, bool rx_em= pty) { const struct inet_connection_sock *icsk =3D inet_csk(ssk); @@ -550,13 +558,13 @@ static bool mptcp_subflow_could_cleanup(const struct = sock *ssk, bool rx_empty) =20 static void mptcp_cleanup_rbuf(struct mptcp_sock *msk) { - int old_space =3D READ_ONCE(msk->old_wspace); + int cur_window =3D __mptcp_receive_window(msk); struct mptcp_subflow_context *subflow; struct sock *sk =3D (struct sock *)msk; - int space =3D __mptcp_space(sk); + int new_window =3D __mptcp_space(sk); bool cleanup, rx_empty; =20 - cleanup =3D (space > 0) && (space >=3D (old_space << 1)); + cleanup =3D new_window > 0 && new_window >=3D (cur_window << 1); rx_empty =3D !__mptcp_rmem(sk); =20 mptcp_for_each_subflow(msk, subflow) { diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 1bc9f6e77ddd..1e603f28f1db 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -260,7 +260,6 @@ struct mptcp_sock { int rmem_fwd_alloc; struct sock *last_snd; int snd_burst; - int old_wspace; u64 recovery_snd_nxt; /* in recovery mode accept up to this seq; * recovery related fields are under data_lock * protection @@ -336,6 +335,11 @@ static inline int __mptcp_rmem(const struct sock *sk) return atomic_read(&sk->sk_rmem_alloc) - READ_ONCE(mptcp_sk(sk)->rmem_rel= eased); } =20 +static inline int __mptcp_receive_window(const struct mptcp_sock *msk) +{ + return atomic64_read(&msk->rcv_wnd_sent) - READ_ONCE(msk->ack_seq); +} + static inline int __mptcp_space(const struct sock *sk) { return tcp_win_from_space(sk, READ_ONCE(sk->sk_rcvbuf) - __mptcp_rmem(sk)= ); --=20 2.35.3