From nobody Tue May 7 07:56:19 2024 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:ab0:590e:0:0:0:0:0 with SMTP id n14csp995379uad; Fri, 29 Jul 2022 08:34:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR72Qsg6iLqSNsIWLqM7WJZe+xyO4CIZH7b1tHqeVFcMlXLMiCh0afcQjGGP5lacHZpmJ7AN X-Received: by 2002:a17:903:1111:b0:16a:acf4:e951 with SMTP id n17-20020a170903111100b0016aacf4e951mr4355205plh.72.1659108840725; Fri, 29 Jul 2022 08:34:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659108840; cv=none; d=google.com; s=arc-20160816; b=RVUSEbPDUC87bHfjpIZnqFSFbqLJoW/xkDZPZTFjLueUYXfKHScNX58UunzX6WLidm vZkopnFt0/IIBSuo2qtQMTJjahE6knapbmE3sxshuJOaf0S7mPbFvydb1whhwWeOr6TT 896UK4N6Y7QCOaj2fEm9eFfrTbHqyEI/nlhYvO4n6KRQ3DgyaKG0aMsHrnwtvski5ua1 sDlSrvvr3Ud09rLSAhZr4mxjHvbSTZNyAz4YtpZso8C2FMvcIQCDGEhky9jrUr8ETYLL pVz45DgwL7nIRFPFv3xyoREph0gIMhNBd1/Cr1LQXUIeC9+Y4ggopCnRgg8XwnVwDMF/ RncQ== 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=bOxjCT/a5P87RNatFo2lM2GkXg3NSBmm+aMpbukibtQ=; b=OUoMVGsPz07xD/rE6/ugoCzlHlwheV6pQfpAqgXS4HenAR/TfewzUjBK5Q7Q93xjae DddUuCGI0GbEDscPL4CrOaielQfhRi1DC0bGUowqEFSPNaQlAfz9Rgb3SimrE6svgxUc ifb4ewfu2ZZm8XBe3S5Yv4TF0AJGBbCv6MKfxH7LWUOw6D5LPTpEGxj3lfBR6fYAwzvM aSRmxzqxrtbIUbYWA8kszhL7bVT6X+VLPFeX9YbThX36pk3qrk6fBqmPQzwCht1Jf3bU rxJqMxkgFvRbpMCjaCOuCtqohY7u3V+xoI+yn3E4veL1BrTxGJXz7gCFTU/uG1gzzsHm +8Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fnCt1ad3; spf=pass (google.com: domain of mptcp+bounces-6067-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="mptcp+bounces-6067-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k13-20020a636f0d000000b0041a4f693412si4667313pgc.134.2022.07.29.08.34.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Jul 2022 08:34:00 -0700 (PDT) Received-SPF: pass (google.com: domain of mptcp+bounces-6067-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fnCt1ad3; spf=pass (google.com: domain of mptcp+bounces-6067-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="mptcp+bounces-6067-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 398B5280E31 for ; Fri, 29 Jul 2022 15:34:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F8324C6C; Fri, 29 Jul 2022 15:33:59 +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 146C34A23 for ; Fri, 29 Jul 2022 15:33:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659108835; 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=bOxjCT/a5P87RNatFo2lM2GkXg3NSBmm+aMpbukibtQ=; b=fnCt1ad34yhqTsL//opqkz/EJK0s1WbprzW6AMC+f1xjj3qK3YOqEve3krd8aT3qzINkuC F0UCAlKZLI/e5hLBweFKmygIhxjTQBsDGC4InGqHgu3CGzhuqoDAvOa5Cfc02ui7Nod7n6 i0tlnzY94cjbMsrwzclIoQnpRxznJLM= 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-635-K-Gdf8SPPlqbakLZ3R-crw-1; Fri, 29 Jul 2022 11:33:53 -0400 X-MC-Unique: K-Gdf8SPPlqbakLZ3R-crw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 38F9185A581 for ; Fri, 29 Jul 2022 15:33:53 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.39.192.205]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD80418ECB for ; Fri, 29 Jul 2022 15:33:52 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next 1/4] mptcp: move RCVPRUNE event later Date: Fri, 29 Jul 2022 17:33:01 +0200 Message-Id: <81be75dff29adfdc136035168f5bcd6d1378b0b4.1659107989.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.79 on 10.11.54.5 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" This clean the code a bit, and avoid skipping msk receive buffer update on some weird corner case. Signed-off-by: Paolo Abeni --- net/mptcp/protocol.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 970da88cd04f..5af3d591a20b 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -642,6 +642,10 @@ static bool __mptcp_move_skbs_from_subflow(struct mptc= p_sock *msk, } } =20 + /* over limit? can't append more skbs to msk */ + if (__mptcp_rmem(sk) > sk_rbuf) + return true; + pr_debug("msk=3D%p ssk=3D%p", msk, ssk); tp =3D tcp_sk(ssk); do { @@ -786,8 +790,6 @@ static bool move_skbs_to_msk(struct mptcp_sock *msk, st= ruct sock *ssk) void mptcp_data_ready(struct sock *sk, struct sock *ssk) { struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(ssk); - struct mptcp_sock *msk =3D mptcp_sk(sk); - int sk_rbuf, ssk_rbuf; =20 /* The peer can send data while we are shutting down this * subflow at msk destruction time, but we must avoid enqueuing @@ -796,20 +798,9 @@ void mptcp_data_ready(struct sock *sk, struct sock *ss= k) if (unlikely(subflow->disposable)) return; =20 - ssk_rbuf =3D READ_ONCE(ssk->sk_rcvbuf); - sk_rbuf =3D READ_ONCE(sk->sk_rcvbuf); - if (unlikely(ssk_rbuf > sk_rbuf)) - sk_rbuf =3D ssk_rbuf; - - /* over limit? can't append more skbs to msk, Also, no need to wake-up*/ - if (__mptcp_rmem(sk) > sk_rbuf) { - MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RCVPRUNED); - return; - } - /* Wake-up the reader only for in-sequence data */ mptcp_data_lock(sk); - if (move_skbs_to_msk(msk, ssk)) + if (move_skbs_to_msk(mptcp_sk(sk), ssk)) sk->sk_data_ready(sk); =20 mptcp_data_unlock(sk); --=20 2.35.3 From nobody Tue May 7 07:56:19 2024 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:ab0:590e:0:0:0:0:0 with SMTP id n14csp995364uad; Fri, 29 Jul 2022 08:33:59 -0700 (PDT) X-Google-Smtp-Source: AA6agR4eCVxB73lqJbyy7gIZW8LxL7OGbjlOiJW5kO1GhZnd2lKH4BaBOMhMqP42Fim/MHkX5Hv6 X-Received: by 2002:ad4:5dee:0:b0:474:56:2d0c with SMTP id jn14-20020ad45dee000000b0047400562d0cmr4065029qvb.50.1659108839547; Fri, 29 Jul 2022 08:33:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659108839; cv=none; d=google.com; s=arc-20160816; b=ZT3EZbbYtpjXAmyf9i3YZ3l/jISWTG0IMePJjjHvtSIZz7P8Tkjp3HXGc8s1J6YCk1 crkbp7Zq47JD5N+rTzRx5DW8CcmGuMxJU1YWTZTvixTFBCFapl/XpPo9T8lwaD73GWdF kQSzQ+SbVtqtglLKkSgzoYCeSdnsVqwR8yAxFfj0ghKT6EOmWmzvmtkewbKb7Oz1Fwpz mnELgri3yGoKsrV+eXB4n+6lOuW0/8GY09/IgZi9bKi1oyyZgPPWrr1dOJVqcAPjan84 NB0qPd947AAf21A0kJtLhG6P+yCLTedsV2dW74o0q06pbln3CjOb4Joja5vk2Tbgfnja YDxQ== 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=bNLfFuFWLjtQN+kAi5MaO4NDu794mtg+Vhw0dqUf3/c=; b=GR8ChQq1xissLgDFWSxupBXCSRpUDDyTEC940FwNgP8aWczOsoSmic8DKxIchVa+02 ShSKsYfSQqdvDqsImBPZf/J3IWN2O1mlacZSRTlJacHixYI8R6VUiYywqCswTZVqPSD+ +mr1a9mAHo71E7H8doSbuxCmSWjqqFwAnhOqm45qHg7FRxE/34T1xuJ1F1DaAGb/KuV1 jc3FI9oY1hOSfirQ4iAo2xC5te7EEsLFCiKyyPxgbhEXHWtSFisym9Ao9TdXH2CP3AO9 9e1vnQNAM9nJn2MFfZTnKWHDWzEgdyb2jqV8U1nYirokaAHSaI0jDlNzTA6l6TUBmSIH sbhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Cayvd+Ar; spf=pass (google.com: domain of mptcp+bounces-6066-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="mptcp+bounces-6066-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 e22-20020ac80116000000b0031ef6d577cdsi2576766qtg.190.2022.07.29.08.33.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Jul 2022 08:33:59 -0700 (PDT) Received-SPF: pass (google.com: domain of mptcp+bounces-6066-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=Cayvd+Ar; spf=pass (google.com: domain of mptcp+bounces-6066-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="mptcp+bounces-6066-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 64C6D1C20A6A for ; Fri, 29 Jul 2022 15:33:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D3B74C6A; Fri, 29 Jul 2022 15:33:58 +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 BB92C4A28 for ; Fri, 29 Jul 2022 15:33:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659108835; 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=bNLfFuFWLjtQN+kAi5MaO4NDu794mtg+Vhw0dqUf3/c=; b=Cayvd+ArHAtCTUOa2UGuS8ZI9qPRkfvMaKO0+g9Xn4oeLscwhMRcA4sRG0hjBc2TGxT2uq sQU/NBGCwKNNDWtJJpqFcAWR0Zh7wdfUpj2hZvXh+PhxnlyBoOpdizEd6TgoVgOfFpFHA6 ddLy8YcWwShy4UAqR9gkrqrca4kpb7E= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-153-TKZESC_eM9m1JxROww0MMw-1; Fri, 29 Jul 2022 11:33:54 -0400 X-MC-Unique: TKZESC_eM9m1JxROww0MMw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EFA4C299E741 for ; Fri, 29 Jul 2022 15:33:53 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.39.192.205]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F95318ECB for ; Fri, 29 Jul 2022 15:33:53 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next 2/4] mptcp: more accurate receive buffer updates Date: Fri, 29 Jul 2022 17:33:02 +0200 Message-Id: <63def511912bf79d6af065dccb155e9304932640.1659107989.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.79 on 10.11.54.5 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 Reported-by: kernel test robot --- 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..9e2df51c0558 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 (is_tcpsk(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..a54f42462a71 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) - 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 From nobody Tue May 7 07:56:19 2024 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:ab0:590e:0:0:0:0:0 with SMTP id n14csp995394uad; Fri, 29 Jul 2022 08:34:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR5nzk2yBnM73S6QMyaMrut9pAHxlzm3E/Qg5cF2f3+sizgq16rv38LE8Si3RMpekm54AzUe X-Received: by 2002:a17:90b:4ac1:b0:1ef:c1ba:e717 with SMTP id mh1-20020a17090b4ac100b001efc1bae717mr4682358pjb.92.1659108842938; Fri, 29 Jul 2022 08:34:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659108842; cv=none; d=google.com; s=arc-20160816; b=bJt5s46JbOTfA/GXlf+Ug1RIC28o4vQFTyYLtTJJ13AzhAGgAMtx3wkUg+qqaxLOBX 2Knv+i4gEV13MjwQeEUCr5CI0kep/jSD3BOs8QNAFzp/E8VoQzmNtPRzL//zC3QUBNJB 1sVRLWuyInWsf5bpZYPFohWHQPJ7+6sN4nXe0089Yzru5w29CAklCVmmcZE8VpJMDb3n ZLg6F0dNrtP0IljreSVEHoBoXMnwnPTbhTlNWwNtTofFZ5EUeFJXCPx31gHf3KfTgILm a69Vvp4dD/fn6xVOEt9ihp3Ou//OxeB1uudxE/5WAx9w0u1LMp7YzOFrOEpBs8S36U3I v4uA== 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=di1M1iI/C4rvUB+B/Yb9KszVmeyN1pzBSPraUBr5na0=; b=gjeJkXiXmZKnjuAshIYkl150GnLjEOYBXW7oA9fbgYKsyF1ZyEn5W7v8pgamGslKEm l7bOVig+xgxFY7jYMHLNvAtyYdj3ypO5KfewWoudzcqaLpP/lFsV3KGotGnGeHXB9Ikz vbc4fmXd8oIMVKBn6nQN//6VHotqmH0Smh7u7Ocqc9695NSoze+sG9Qn9N82pZHxRmXm MtoDzO4F0Oh5NjbxzRzcKhj5Bl/zLW26GxCPx/8FCHfiEvdcLuwMoVwv1xhTlKocDFRN 0djk9OJGDuYG5+NVwxTwc9ruJhMQj01Z138QPIp3hDrMMl4iIALhKhCLXWWePnSeHcbu i9nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QOG15R1l; spf=pass (google.com: domain of mptcp+bounces-6069-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="mptcp+bounces-6069-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id f3-20020a17090a4a8300b001f11257549fsi3865980pjh.84.2022.07.29.08.34.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Jul 2022 08:34:02 -0700 (PDT) Received-SPF: pass (google.com: domain of mptcp+bounces-6069-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QOG15R1l; spf=pass (google.com: domain of mptcp+bounces-6069-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="mptcp+bounces-6069-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 703D5280E34 for ; Fri, 29 Jul 2022 15:34:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C8AE04C67; Fri, 29 Jul 2022 15:34:01 +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.133.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 5949A4A29 for ; Fri, 29 Jul 2022 15:33:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659108836; 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=di1M1iI/C4rvUB+B/Yb9KszVmeyN1pzBSPraUBr5na0=; b=QOG15R1lcpJSXs6oVhrVb5dDCx6zJNqIw9KD/pKI8RhPGrVr5bU81j9A31mJ54foYeJzRi 3sUhmGLlz+PtEni3vj/7ZnEQOz8n4lA0TsTt/gebX8lHXELLrdbjun2Nv77Kp2uVjHfMYR oH/Zpo1p/HJNiyxHtTi1PXEwi9Q1iOI= 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-460-2KXdJmfdNBqGFig2Sg9m3A-1; Fri, 29 Jul 2022 11:33:54 -0400 X-MC-Unique: 2KXdJmfdNBqGFig2Sg9m3A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B1D738032F0 for ; Fri, 29 Jul 2022 15:33:54 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.39.192.205]) by smtp.corp.redhat.com (Postfix) with ESMTP id 41C0790A11 for ; Fri, 29 Jul 2022 15:33:54 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next 3/4] mptcp: move msk input path under full msk socket lock Date: Fri, 29 Jul 2022 17:33:03 +0200 Message-Id: <3fdd375269bc0bad45ccadfca268dcb3ac3389c1.1659107989.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.79 on 10.11.54.5 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" Signed-off-by: Paolo Abeni Reported-by: kernel test robot --- net/mptcp/protocol.c | 79 ++++++++++++++++++++------------------------ net/mptcp/protocol.h | 2 +- 2 files changed, 36 insertions(+), 45 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 17e2dbe43639..b9402a13a69d 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -795,7 +795,7 @@ static bool move_skbs_to_msk(struct mptcp_sock *msk, st= ruct sock *ssk) return moved > 0; } =20 -void mptcp_data_ready(struct sock *sk, struct sock *ssk) +void __mptcp_data_ready(struct sock *sk, struct sock *ssk) { struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(ssk); =20 @@ -807,10 +807,17 @@ void mptcp_data_ready(struct sock *sk, struct sock *s= sk) return; =20 /* Wake-up the reader only for in-sequence data */ - mptcp_data_lock(sk); if (move_skbs_to_msk(mptcp_sk(sk), ssk)) sk->sk_data_ready(sk); +} =20 +void mptcp_data_ready(struct sock *sk, struct sock *ssk) +{ + mptcp_data_lock(sk); + if (!sock_owned_by_user(sk)) + __mptcp_data_ready(sk, ssk); + else + __set_bit(MPTCP_DEQUEUE, &mptcp_sk(sk)->cb_flags); mptcp_data_unlock(sk); } =20 @@ -1059,6 +1066,7 @@ static void mptcp_clean_una_wakeup(struct sock *sk) mptcp_data_unlock(sk); } =20 + static void mptcp_enter_memory_pressure(struct sock *sk) { struct mptcp_subflow_context *subflow; @@ -1768,16 +1776,22 @@ static int mptcp_sendmsg(struct sock *sk, struct ms= ghdr *msg, size_t len) return copied ? : ret; } =20 -static int __mptcp_recvmsg_mskq(struct mptcp_sock *msk, +static bool __mptcp_move_skbs(struct sock *sk); + +static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg, size_t len, int flags, struct scm_timestamping_internal *tss, int *cmsg_flags) { + struct mptcp_sock *msk =3D mptcp_sk(sk); struct sk_buff *skb, *tmp; int copied =3D 0; =20 - skb_queue_walk_safe(&msk->receive_queue, skb, tmp) { + if (skb_queue_empty(&sk->sk_receive_queue) && !__mptcp_move_skbs(sk)) + return 0; + + skb_queue_walk_safe(&sk->sk_receive_queue, skb, tmp) { u32 offset =3D MPTCP_SKB_CB(skb)->offset; u32 data_len =3D skb->len - offset; u32 count =3D min_t(size_t, len - copied, data_len); @@ -1811,7 +1825,7 @@ static int __mptcp_recvmsg_mskq(struct mptcp_sock *ms= k, /* we will bulk release the skb memory later */ skb->destructor =3D NULL; WRITE_ONCE(msk->rmem_released, msk->rmem_released + skb->truesize); - __skb_unlink(skb, &msk->receive_queue); + __skb_unlink(skb, &sk->sk_receive_queue); __kfree_skb(skb); } =20 @@ -1932,16 +1946,9 @@ static void __mptcp_update_rmem(struct sock *sk) WRITE_ONCE(msk->rmem_released, 0); } =20 -static void __mptcp_splice_receive_queue(struct sock *sk) +static bool __mptcp_move_skbs(struct sock *sk) { struct mptcp_sock *msk =3D mptcp_sk(sk); - - skb_queue_splice_tail_init(&sk->sk_receive_queue, &msk->receive_queue); -} - -static bool __mptcp_move_skbs(struct mptcp_sock *msk) -{ - struct sock *sk =3D (struct sock *)msk; unsigned int moved =3D 0; bool ret, done; =20 @@ -1949,37 +1956,29 @@ static bool __mptcp_move_skbs(struct mptcp_sock *ms= k) struct sock *ssk =3D mptcp_subflow_recv_lookup(msk); bool slowpath; =20 - /* we can have data pending in the subflows only if the msk - * receive buffer was full at subflow_data_ready() time, - * that is an unlikely slow path. - */ - if (likely(!ssk)) + if (unlikely(!ssk)) break; =20 slowpath =3D lock_sock_fast(ssk); - mptcp_data_lock(sk); __mptcp_update_rmem(sk); done =3D __mptcp_move_skbs_from_subflow(msk, ssk, &moved); - mptcp_data_unlock(sk); =20 if (unlikely(ssk->sk_err)) __mptcp_error_report(sk); unlock_sock_fast(ssk, slowpath); } while (!done); =20 - /* acquire the data lock only if some input data is pending */ ret =3D moved > 0; if (!RB_EMPTY_ROOT(&msk->out_of_order_queue) || - !skb_queue_empty_lockless(&sk->sk_receive_queue)) { - mptcp_data_lock(sk); + !skb_queue_empty(&sk->sk_receive_queue)) { __mptcp_update_rmem(sk); ret |=3D __mptcp_ofo_queue(msk); - __mptcp_splice_receive_queue(sk); - mptcp_data_unlock(sk); } - if (ret) + if (ret) { + mptcp_cleanup_rbuf(msk); mptcp_check_data_fin((struct sock *)msk); - return !skb_queue_empty(&msk->receive_queue); + } + return ret; } =20 static unsigned int mptcp_inq_hint(const struct sock *sk) @@ -1987,7 +1986,7 @@ static unsigned int mptcp_inq_hint(const struct sock = *sk) const struct mptcp_sock *msk =3D mptcp_sk(sk); const struct sk_buff *skb; =20 - skb =3D skb_peek(&msk->receive_queue); + skb =3D skb_peek(&sk->sk_receive_queue); if (skb) { u64 hint_val =3D msk->ack_seq - MPTCP_SKB_CB(skb)->map_seq; =20 @@ -2033,7 +2032,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msgh= dr *msg, size_t len, while (copied < len) { int bytes_read; =20 - bytes_read =3D __mptcp_recvmsg_mskq(msk, msg, len - copied, flags, &tss,= &cmsg_flags); + bytes_read =3D __mptcp_recvmsg_mskq(sk, msg, len - copied, flags, &tss, = &cmsg_flags); if (unlikely(bytes_read < 0)) { if (!copied) copied =3D bytes_read; @@ -2045,9 +2044,6 @@ static int mptcp_recvmsg(struct sock *sk, struct msgh= dr *msg, size_t len, /* be sure to advertise window change */ mptcp_cleanup_rbuf(msk); =20 - if (skb_queue_empty(&msk->receive_queue) && __mptcp_move_skbs(msk)) - continue; - /* only the master socket status is relevant here. The exit * conditions mirror closely tcp_recvmsg() */ @@ -2074,7 +2070,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msgh= dr *msg, size_t len, /* race breaker: the shutdown could be after the * previous receive queue check */ - if (__mptcp_move_skbs(msk)) + if (__mptcp_move_skbs(sk)) continue; break; } @@ -2111,9 +2107,8 @@ static int mptcp_recvmsg(struct sock *sk, struct msgh= dr *msg, size_t len, } } =20 - pr_debug("msk=3D%p rx queue empty=3D%d:%d copied=3D%d", - msk, skb_queue_empty_lockless(&sk->sk_receive_queue), - skb_queue_empty(&msk->receive_queue), copied); + pr_debug("msk=3D%p rx queue empty=3D%d copied=3D%d", + msk, skb_queue_empty(&sk->sk_receive_queue), copied); if (!(flags & MSG_PEEK)) mptcp_rcv_space_adjust(msk, copied); =20 @@ -2566,7 +2561,6 @@ static int __mptcp_init_sock(struct sock *sk) INIT_LIST_HEAD(&msk->join_list); INIT_LIST_HEAD(&msk->rtx_queue); INIT_WORK(&msk->work, mptcp_worker); - __skb_queue_head_init(&msk->receive_queue); msk->out_of_order_queue =3D RB_ROOT; msk->first_pending =3D NULL; msk->rmem_fwd_alloc =3D 0; @@ -3048,12 +3042,8 @@ void mptcp_destroy_common(struct mptcp_sock *msk, un= signed int flags) mptcp_for_each_subflow_safe(msk, subflow, tmp) __mptcp_close_ssk(sk, mptcp_subflow_tcp_sock(subflow), subflow, flags); =20 - /* move to sk_receive_queue, sk_stream_kill_queues will purge it */ - mptcp_data_lock(sk); - skb_queue_splice_tail_init(&msk->receive_queue, &sk->sk_receive_queue); __skb_queue_purge(&sk->sk_receive_queue); skb_rbtree_purge(&msk->out_of_order_queue); - mptcp_data_unlock(sk); =20 /* move all the rx fwd alloc into the sk_mem_reclaim_final in * inet_sock_destruct() will dispose it @@ -3135,6 +3125,8 @@ static void mptcp_release_cb(struct sock *sk) __mptcp_flush_join_list(sk); if (flags & BIT(MPTCP_PUSH_PENDING)) __mptcp_push_pending(sk, 0); + if ((flags & BIT(MPTCP_DEQUEUE)) && __mptcp_move_skbs(sk)) + sk->sk_data_ready(sk); if (flags & BIT(MPTCP_RETRANSMIT)) __mptcp_retrans(sk); =20 @@ -3383,7 +3375,7 @@ static int mptcp_ioctl(struct sock *sk, int cmd, unsi= gned long arg) return -EINVAL; =20 lock_sock(sk); - __mptcp_move_skbs(msk); + __mptcp_move_skbs(sk); answ =3D mptcp_inq_hint(sk); release_sock(sk); break; @@ -3619,8 +3611,7 @@ static __poll_t mptcp_check_readable(struct mptcp_soc= k *msk) /* Concurrent splices from sk_receive_queue into receive_queue will * always show at least one non-empty queue when checked in this order. */ - if (skb_queue_empty_lockless(&((struct sock *)msk)->sk_receive_queue) && - skb_queue_empty_lockless(&msk->receive_queue)) + if (skb_queue_empty_lockless(&((struct sock *)msk)->sk_receive_queue)) return 0; =20 return EPOLLIN | EPOLLRDNORM; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index a54f42462a71..99c710e1ff5c 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -125,6 +125,7 @@ #define MPTCP_FLUSH_JOIN_LIST 5 #define MPTCP_CONNECTED 6 #define MPTCP_RESET_SCHEDULER 7 +#define MPTCP_DEQUEUE 8 =20 static inline bool before64(__u64 seq1, __u64 seq2) { @@ -288,7 +289,6 @@ struct mptcp_sock { struct work_struct work; struct sk_buff *ooo_last_skb; struct rb_root out_of_order_queue; - struct sk_buff_head receive_queue; struct list_head conn_list; struct list_head rtx_queue; struct mptcp_data_frag *first_pending; --=20 2.35.3 From nobody Tue May 7 07:56:19 2024 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:ab0:590e:0:0:0:0:0 with SMTP id n14csp995385uad; Fri, 29 Jul 2022 08:34:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR6XTHXPTOeDcNdmMXAkMg/SWnC1sy7HOseZ/qkc2jyt55oGeysK3+vloaUMs4CZ8jsJ5tRw X-Received: by 2002:a0c:8170:0:b0:473:af82:9a77 with SMTP id 103-20020a0c8170000000b00473af829a77mr3918765qvc.87.1659108841765; Fri, 29 Jul 2022 08:34:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659108841; cv=none; d=google.com; s=arc-20160816; b=yOpSOSxu7Ogq/u6Y9Vn6OkE9gCcaaJjoHvro3b9+88FY9EPsP8rayUtGphYUFhQ1hc RZeU68QMz3/vE1eRMB9MoeDvsW8ZmlHiLf4FMLbyLB0pe7i/fp5/TXCf7UModmE/z6cj RrNxsnyAnOqhMNZoJnOJWyJHIsDItZDjxs8t69mnHLnZ8sbHJWu8VGdlIc4vXdMQCMl0 4qp6/K+nZmGLW12dj7KHaSpBo2bADtJG5tWIh4wyCqXOcnmrWKRDBU8QViYaOnECC/ES PNZHnpolzK6/oz2svdmoQ+m3frjDLl9bBgSDftAsrnEQj72tdkYEezLmckdQRTcHkghS AxJA== 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=RcD0XgS5CQtJH05z28AzMNQ3avH8pEU8s6cv8rKq/v8=; b=sogxBKNl/Z/3++w2CJpzL1hO+XoSZj02xr/0Bzr8U83FxzKdqwFHsBSkiazoq1y9Un O1WQCeZM68Zm+xW8/BBA3lFoOTK16tQeApMKPV25b7ZAnBy+hVFz32qzGKqEwLbHLks+ jYdnBwOWEpPEJLzONg0TO0bpj/LVgvJbNqiQFqAVwk6Oiua1t3X+O95odDLCKAtIO14u ZZy0uZbuj9RGyYu+Hc/NtdeCjvapFZS4woBFr7ShzHijX4RxGhIeD5lz8g14iLhHUDh2 5J8+Uhsue3LzWPB1MquIoy4Z45O+CYXRhVnkIFj0+8TfmOLnWSHaH2czi81uH2cJwVPQ D2bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RAv2dT6m; spf=pass (google.com: domain of mptcp+bounces-6068-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 147.75.199.223 as permitted sender) smtp.mailfrom="mptcp+bounces-6068-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. [147.75.199.223]) by mx.google.com with ESMTPS id hu11-20020a056214234b00b00474479acbf7si2054788qvb.480.2022.07.29.08.34.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Jul 2022 08:34:01 -0700 (PDT) Received-SPF: pass (google.com: domain of mptcp+bounces-6068-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RAv2dT6m; spf=pass (google.com: domain of mptcp+bounces-6068-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 147.75.199.223 as permitted sender) smtp.mailfrom="mptcp+bounces-6068-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 997C41C20A76 for ; Fri, 29 Jul 2022 15:34:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 541644C6A; Fri, 29 Jul 2022 15:34:00 +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 81B754C67 for ; Fri, 29 Jul 2022 15:33:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659108837; 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=RcD0XgS5CQtJH05z28AzMNQ3avH8pEU8s6cv8rKq/v8=; b=RAv2dT6m1Og8di+PRBGO41c8ZbLvuSEsPniQSdpjplVgq37V6SBVod0MIr6w4E1pExB9S6 tOlL67xNR45foMUBspD6m8XNtycUA1OEYAb5OiVcgJ0vHXS3hki6WKl8URAAAUwbY6mIV5 OkaOjElUpu5WRrCP2/DZhGSkfmoIVMI= 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-661-oqqT7AVoPTqNet3IpM13Hw-1; Fri, 29 Jul 2022 11:33:55 -0400 X-MC-Unique: oqqT7AVoPTqNet3IpM13Hw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 75F3E811E7A for ; Fri, 29 Jul 2022 15:33:55 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.39.192.205]) by smtp.corp.redhat.com (Postfix) with ESMTP id 041F490A00 for ; Fri, 29 Jul 2022 15:33:54 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next 4/4] mptcp: use common helper for rmem memory accounting Date: Fri, 29 Jul 2022 17:33:04 +0200 Message-Id: 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.79 on 10.11.54.5 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" Signed-off-by: Paolo Abeni --- net/mptcp/protocol.c | 112 ++++--------------------------------------- net/mptcp/protocol.h | 4 +- 2 files changed, 9 insertions(+), 107 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index b9402a13a69d..130afd239ecf 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -131,11 +131,6 @@ static void mptcp_drop(struct sock *sk, struct sk_buff= *skb) __kfree_skb(skb); } =20 -static void mptcp_rmem_charge(struct sock *sk, int size) -{ - mptcp_sk(sk)->rmem_fwd_alloc -=3D size; -} - static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to, struct sk_buff *from) { @@ -152,7 +147,7 @@ static bool mptcp_try_coalesce(struct sock *sk, struct = sk_buff *to, MPTCP_SKB_CB(to)->end_seq =3D MPTCP_SKB_CB(from)->end_seq; kfree_skb_partial(from, fragstolen); atomic_add(delta, &sk->sk_rmem_alloc); - mptcp_rmem_charge(sk, delta); + sk->sk_forward_alloc -=3D delta; return true; } =20 @@ -165,44 +160,6 @@ static bool mptcp_ooo_try_coalesce(struct mptcp_sock *= msk, struct sk_buff *to, return mptcp_try_coalesce((struct sock *)msk, to, from); } =20 -static void __mptcp_rmem_reclaim(struct sock *sk, int amount) -{ - amount >>=3D PAGE_SHIFT; - mptcp_sk(sk)->rmem_fwd_alloc -=3D amount << PAGE_SHIFT; - __sk_mem_reduce_allocated(sk, amount); -} - -static void mptcp_rmem_uncharge(struct sock *sk, int size) -{ - struct mptcp_sock *msk =3D mptcp_sk(sk); - int reclaimable; - - msk->rmem_fwd_alloc +=3D size; - reclaimable =3D msk->rmem_fwd_alloc - sk_unused_reserved_mem(sk); - - /* see sk_mem_uncharge() for the rationale behind the following schema */ - if (unlikely(reclaimable >=3D PAGE_SIZE)) - __mptcp_rmem_reclaim(sk, reclaimable); -} - -static void mptcp_rfree(struct sk_buff *skb) -{ - unsigned int len =3D skb->truesize; - struct sock *sk =3D skb->sk; - - atomic_sub(len, &sk->sk_rmem_alloc); - mptcp_rmem_uncharge(sk, len); -} - -static void mptcp_set_owner_r(struct sk_buff *skb, struct sock *sk) -{ - skb_orphan(skb); - skb->sk =3D sk; - skb->destructor =3D mptcp_rfree; - atomic_add(skb->truesize, &sk->sk_rmem_alloc); - mptcp_rmem_charge(sk, skb->truesize); -} - /* "inspired" by tcp_data_queue_ofo(), main differences: * - use mptcp seqs * - don't cope with sacks @@ -315,25 +272,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *ms= k, struct sk_buff *skb) =20 end: skb_condense(skb); - mptcp_set_owner_r(skb, sk); -} - -static bool mptcp_rmem_schedule(struct sock *sk, struct sock *ssk, int siz= e) -{ - struct mptcp_sock *msk =3D mptcp_sk(sk); - int amt, amount; - - if (size <=3D msk->rmem_fwd_alloc) - return true; - - size -=3D msk->rmem_fwd_alloc; - amt =3D sk_mem_pages(size); - amount =3D amt << PAGE_SHIFT; - if (!__sk_mem_raise_allocated(sk, size, amt, SK_MEM_RECV)) - return false; - - msk->rmem_fwd_alloc +=3D amount; - return true; + skb_set_owner_r(skb, sk); } =20 static bool __mptcp_move_skb(struct mptcp_sock *msk, struct sock *ssk, @@ -350,8 +289,7 @@ static bool __mptcp_move_skb(struct mptcp_sock *msk, st= ruct sock *ssk, skb_ext_reset(skb); skb_orphan(skb); =20 - /* try to fetch required memory from subflow */ - if (!mptcp_rmem_schedule(sk, ssk, skb->truesize)) + if (!sk_rmem_schedule(sk, skb, skb->truesize)) goto drop; =20 has_rxtstamp =3D TCP_SKB_CB(skb)->has_rxtstamp; @@ -372,7 +310,7 @@ static bool __mptcp_move_skb(struct mptcp_sock *msk, st= ruct sock *ssk, if (tail && mptcp_try_coalesce(sk, tail, skb)) return true; =20 - mptcp_set_owner_r(skb, sk); + skb_set_owner_r(skb, sk); __skb_queue_tail(&sk->sk_receive_queue, skb); return true; } else if (after64(MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq)) { @@ -1784,7 +1722,6 @@ static int __mptcp_recvmsg_mskq(struct sock *sk, struct scm_timestamping_internal *tss, int *cmsg_flags) { - struct mptcp_sock *msk =3D mptcp_sk(sk); struct sk_buff *skb, *tmp; int copied =3D 0; =20 @@ -1822,9 +1759,10 @@ static int __mptcp_recvmsg_mskq(struct sock *sk, } =20 if (!(flags & MSG_PEEK)) { - /* we will bulk release the skb memory later */ + /* avoid the indirect call, we know the destructor is sock_wfree */ skb->destructor =3D NULL; - WRITE_ONCE(msk->rmem_released, msk->rmem_released + skb->truesize); + atomic_sub(skb->truesize, &sk->sk_rmem_alloc); + sk_mem_uncharge(sk, skb->truesize); __skb_unlink(skb, &sk->sk_receive_queue); __kfree_skb(skb); } @@ -1934,18 +1872,6 @@ static void mptcp_rcv_space_adjust(struct mptcp_sock= *msk, int copied) msk->rcvq_space.time =3D mstamp; } =20 -static void __mptcp_update_rmem(struct sock *sk) -{ - struct mptcp_sock *msk =3D mptcp_sk(sk); - - if (!msk->rmem_released) - return; - - atomic_sub(msk->rmem_released, &sk->sk_rmem_alloc); - mptcp_rmem_uncharge(sk, msk->rmem_released); - WRITE_ONCE(msk->rmem_released, 0); -} - static bool __mptcp_move_skbs(struct sock *sk) { struct mptcp_sock *msk =3D mptcp_sk(sk); @@ -1960,7 +1886,6 @@ static bool __mptcp_move_skbs(struct sock *sk) break; =20 slowpath =3D lock_sock_fast(ssk); - __mptcp_update_rmem(sk); done =3D __mptcp_move_skbs_from_subflow(msk, ssk, &moved); =20 if (unlikely(ssk->sk_err)) @@ -1969,11 +1894,7 @@ static bool __mptcp_move_skbs(struct sock *sk) } while (!done); =20 ret =3D moved > 0; - if (!RB_EMPTY_ROOT(&msk->out_of_order_queue) || - !skb_queue_empty(&sk->sk_receive_queue)) { - __mptcp_update_rmem(sk); - ret |=3D __mptcp_ofo_queue(msk); - } + ret |=3D __mptcp_ofo_queue(msk); if (ret) { mptcp_cleanup_rbuf(msk); mptcp_check_data_fin((struct sock *)msk); @@ -2563,8 +2484,6 @@ static int __mptcp_init_sock(struct sock *sk) INIT_WORK(&msk->work, mptcp_worker); msk->out_of_order_queue =3D RB_ROOT; msk->first_pending =3D NULL; - msk->rmem_fwd_alloc =3D 0; - WRITE_ONCE(msk->rmem_released, 0); msk->timer_ival =3D TCP_RTO_MIN; =20 msk->first =3D NULL; @@ -2776,8 +2695,6 @@ static void __mptcp_destroy_sock(struct sock *sk) =20 sk->sk_prot->destroy(sk); =20 - WARN_ON_ONCE(msk->rmem_fwd_alloc); - WARN_ON_ONCE(msk->rmem_released); sk_stream_kill_queues(sk); xfrm_sk_free_policy(sk); =20 @@ -3045,11 +2962,6 @@ void mptcp_destroy_common(struct mptcp_sock *msk, un= signed int flags) __skb_queue_purge(&sk->sk_receive_queue); skb_rbtree_purge(&msk->out_of_order_queue); =20 - /* move all the rx fwd alloc into the sk_mem_reclaim_final in - * inet_sock_destruct() will dispose it - */ - sk->sk_forward_alloc +=3D msk->rmem_fwd_alloc; - msk->rmem_fwd_alloc =3D 0; mptcp_token_destroy(msk); mptcp_pm_free_anno_list(msk); mptcp_free_local_addr_list(msk); @@ -3147,8 +3059,6 @@ static void mptcp_release_cb(struct sock *sk) if (__test_and_clear_bit(MPTCP_RESET_SCHEDULER, &msk->cb_flags)) msk->last_snd =3D NULL; } - - __mptcp_update_rmem(sk); } =20 /* MP_JOIN client subflow must wait for 4th ack before sending any data: @@ -3329,11 +3239,6 @@ static void mptcp_shutdown(struct sock *sk, int how) __mptcp_wr_shutdown(sk); } =20 -static int mptcp_forward_alloc_get(const struct sock *sk) -{ - return sk->sk_forward_alloc + mptcp_sk(sk)->rmem_fwd_alloc; -} - static int mptcp_ioctl_outq(const struct mptcp_sock *msk, u64 v) { const struct sock *sk =3D (void *)msk; @@ -3414,7 +3319,6 @@ static struct proto mptcp_prot =3D { .hash =3D mptcp_hash, .unhash =3D mptcp_unhash, .get_port =3D mptcp_get_port, - .forward_alloc_get =3D mptcp_forward_alloc_get, .sockets_allocated =3D &mptcp_sockets_allocated, =20 .memory_allocated =3D &tcp_memory_allocated, diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 99c710e1ff5c..9ddee7eac00d 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -258,7 +258,6 @@ struct mptcp_sock { u64 ack_seq; atomic64_t rcv_wnd_sent; u64 rcv_data_fin_seq; - int rmem_fwd_alloc; struct sock *last_snd; int snd_burst; u64 recovery_snd_nxt; /* in recovery mode accept up to this seq; @@ -269,7 +268,6 @@ struct mptcp_sock { u64 wnd_end; unsigned long timer_ival; u32 token; - int rmem_released; unsigned long flags; unsigned long cb_flags; unsigned long push_pending; @@ -332,7 +330,7 @@ static inline struct mptcp_sock *mptcp_sk(const struct = sock *sk) */ static inline int __mptcp_rmem(const struct sock *sk) { - return atomic_read(&sk->sk_rmem_alloc) - READ_ONCE(mptcp_sk(sk)->rmem_rel= eased); + return atomic_read(&sk->sk_rmem_alloc); } =20 static inline int __mptcp_receive_window(const struct mptcp_sock *msk) --=20 2.35.3