From patchwork Fri Mar 1 17:43:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthieu Baerts (NGI0)" X-Patchwork-Id: 208980 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp39695dyc; Fri, 1 Mar 2024 09:44:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW9JmFnaboDp+371l9zUmp1fLSjPr/MbiUpmyZ9xwEYclb6r4YLnhUeNv8fd/k7sG+udXoMG1zEjcQi1KjyRRNbGa+llA== X-Google-Smtp-Source: AGHT+IF36+2lP5u/hKyKLe8nBAMRZeoePcg6/+YAotEob37nAze9feaq9PMscHPPdhfUgPAWr8HY X-Received: by 2002:a17:906:1950:b0:a43:af8c:ef35 with SMTP id b16-20020a170906195000b00a43af8cef35mr1721042eje.75.1709315091666; Fri, 01 Mar 2024 09:44:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709315091; cv=pass; d=google.com; s=arc-20160816; b=Qq6PhQvzaz423j1xRVEFl3H4jfIRApuUzzS/qpXTDJ26jIZR9hszc+o1p7/Gd5Xyew Vy0ZU5+YotLBB4uMY8MhI9+PNSh5541Vcj3W03RUloMOQyfzHuToHoXjo22mD+oKH5kk zLEc0K+FMo/mTN+pqKmCe24elME3nT+luy2Ur+cEQT59L4uI7Z0EBKrbd+lyJkFZ5W7U CzyjH3BfYAg5CU0Hjce2nBMvDzxcbAQ6ScjvfjH+49Kt+Ll1u4fyEW2U+GJezNaqfzCu 5sXy9JFWgKzZ6Mqb3rSoc9NY9na5AF7ghOq2ldGg8AUsOMkojbic9WroYFL8m/hOgoXZ OPfg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=KYjNKY+x/l72JFUHA4dKe4cNOUUYT7tZvOGqN+FyNAs=; fh=dtfL7SHUWpoNkavaEIKFixF3/eMo8TZTrybXzF4g82Y=; b=P7I3lnNZRkXXTwLnu+QxQFIVetohfqh5ErOA+h1SS14SePkScU9X1MT5pR4maa9e43 fK2kEddSlJSQgX4iXqwF1Ctl0M2DloXFnD4rb01Azww4UkuveMRgYA9GD87fDPL36Hrt 48ndaz7Vemg8RrXMWF/l/4+abQKjDt3SdWz8/6q6t9+k3HB8T8FaTihyTdkctr98O+xc 7LHBSMqn6RnZC2tGQ31PpK/rJPE5V9x1DNIMOmTHcWruUn2MGlvy3Mlq7G4F2T1CRDPf c+Q4FDd/WJpl5SphEaciOz8pI2oj+ltqi216y86zHa5dZRUPaSMFNbv/7TE6pp42mWuh yqjA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AJHcs2kG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-88852-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88852-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id j24-20020a170906411800b00a448d9a8138si627742ejk.142.2024.03.01.09.44.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 09:44:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88852-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AJHcs2kG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-88852-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88852-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 21D241F23E9D for ; Fri, 1 Mar 2024 17:44:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5857A286AE; Fri, 1 Mar 2024 17:44:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AJHcs2kG" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8C59B1B7FD; Fri, 1 Mar 2024 17:44:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709315050; cv=none; b=RmA0M6ttFBUbm1PbD7uB+HmBOjBcFv+ciDg0lm2xoRb6EyR6XKeWgRH1QgXUnnl1/oDZDMFtUowtkiMFA4IJ6sVU90lnTADutgvA+57H+q1faMGjdxxxmBLRPklnCDWt6q+KSEeHTteals/+Bs2RBvvnh8CFMW2hy/vfonB/CLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709315050; c=relaxed/simple; bh=qWKkPNajfUVsea21RCifCjJMui1+CQjLYDkjVsEM5Tw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=npIUcyeO5Mqu/FyOa5NUATEfw3VxTcodro9hUGOeM3TWtn+wGzSx7uawEODSi6sSHbJVHSZg7dQB4wcBfCF7IAPc04N6P7r5Fv/StKkI6GyXLtDPro7NfQ4QziScf/jm6PYW/h8ChFbwyF4PHsoLG2Xi9a7onIbmaAg/WyqmmGc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AJHcs2kG; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C8B3C43601; Fri, 1 Mar 2024 17:44:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709315050; bh=qWKkPNajfUVsea21RCifCjJMui1+CQjLYDkjVsEM5Tw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=AJHcs2kGBucd9FOxyzi6CAEHp5/R8Qxhdp5GWFeo2fushkL8CTNe/7FTyCB6zXgNX jJU87Ge1bkClZRbvqde8IA0iW7WvM6XeVd+TBwK98lwMGIgkTR9ytfyFmexhuvVF9x XQr0DJBKmRIgy48txqvNZlKtmX8KgDsmRGGFPybPgnd4/L9LcRTJ/hR/wZQ/Rn8ftv PUWJPAy2uyw3I3EHzHSxbcjfmcmtTLD/vWYk4M1dcQ8FgfvJ0G/EbEE8r37FpbctOP 2vPKFP7nE8sh8JYOJ8k0yaEs/sTIOOea/uRpGb9XtdcWHmR+qapLEVjmqnlr8QWEur L5SGiGv4geMcQ== From: "Matthieu Baerts (NGI0)" Date: Fri, 01 Mar 2024 18:43:44 +0100 Subject: [PATCH net-next 1/4] mptcp: cleanup writer wake-up Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240301-upstream-net-next-20240301-mptcp-tcp_notsent_lowat-v1-1-415f0e8ed0e1@kernel.org> References: <20240301-upstream-net-next-20240301-mptcp-tcp_notsent_lowat-v1-0-415f0e8ed0e1@kernel.org> In-Reply-To: <20240301-upstream-net-next-20240301-mptcp-tcp_notsent_lowat-v1-0-415f0e8ed0e1@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3037; i=matttbe@kernel.org; h=from:subject:message-id; bh=QqGEqOJP/LnJu/Zld7Jkp0utf6EsUkW4CSldq5xKHBk=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBl4hPlDtIoxjQZIKgof6OZ1T4DqpNhnK6w+HQHC f4aEcIGgbaJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZeIT5QAKCRD2t4JPQmmg c51EEADPqtNb0PTe6S2cEYvynnC0p5AHi5D6EBeQIqgMkaInJyEvhSof7Spdqzhv4vJlgw+M/P5 OLZTgZ4G9WOprnKT3h/bwEXkfx9l0s/HcLond6cLdHdhnWRAnCvUZocYT1yNFbxXF2dDVWrAqRE lK/UmIsU1PO9fg3xf59vyKa+Uwn/prbO7QpBnFYpO0D+hduXP+U78+r8jTxKHHoUjZf1G04Hd9b wZMyx6jLIX45gH9I4Gvq0nln8OMGIfIhuQGBHDNB7+uYQ1FPdb4Qc7LK6A35fb5h2DzgrZnYESx eULfofIQ3mlYVVNbcqkDgcTNojGhfJmdPH9GWPQgOXOALuH+Ei8v3ga0TSA/IlQl3/IJk0WavOI XvsYp+bjjgtIe4Fza4trZM8GCQK8ecuAEY964dZTuNjCBOaUuXxCEWYDXEWkGUdQ0+nfvwbxDOC oq/CNSUwO6+7bPjLzN3S1z+YRWP1PMEICvoTpM/gPqyp9HXuwQmvrqyEISden6VhWgZJA8m8tjo ybDdgxrxtREzVpmWQ2qCQbCPBQmRf0uUsgs0HKSA+RmaEpu33ox3W1N6vsy4QBcZCUvr1/HC448 uiWu2cN+21A2hsByxz/6w7LX8BcgrDDeW+lGtL9QweadNUU6HeZSH90xhBYGdueksDnIrhLyqnL v0PRx8oXNjhrr6g== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792346781787915798 X-GMAIL-MSGID: 1792346781787915798 From: Paolo Abeni After commit 5cf92bbadc58 ("mptcp: re-enable sndbuf autotune"), the MPTCP_NOSPACE bit is redundant: it is always set and cleared together with SOCK_NOSPACE. Let's drop the first and always relay on the latter, dropping a bunch of useless code. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 15 +++------------ net/mptcp/protocol.h | 16 ++++++---------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 76c8861a852b..a3d79e9d0694 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1692,15 +1692,6 @@ static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk, bool } } -static void mptcp_set_nospace(struct sock *sk) -{ - /* enable autotune */ - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); - - /* will be cleared on avail space */ - set_bit(MPTCP_NOSPACE, &mptcp_sk(sk)->flags); -} - static int mptcp_disconnect(struct sock *sk, int flags); static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, @@ -1874,7 +1865,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) continue; wait_for_memory: - mptcp_set_nospace(sk); + set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); __mptcp_push_pending(sk, msg->msg_flags); ret = sk_stream_wait_memory(sk, &timeo); if (ret) @@ -3945,8 +3936,8 @@ static __poll_t mptcp_check_writeable(struct mptcp_sock *msk) if (sk_stream_is_writeable(sk)) return EPOLLOUT | EPOLLWRNORM; - mptcp_set_nospace(sk); - smp_mb__after_atomic(); /* msk->flags is changed by write_space cb */ + set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + smp_mb__after_atomic(); /* NOSPACE is changed by mptcp_write_space() */ if (sk_stream_is_writeable(sk)) return EPOLLOUT | EPOLLWRNORM; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index d0a7955b96c4..f0c634e843e6 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -113,10 +113,9 @@ #define MPTCP_RST_TRANSIENT BIT(0) /* MPTCP socket atomic flags */ -#define MPTCP_NOSPACE 1 -#define MPTCP_WORK_RTX 2 -#define MPTCP_FALLBACK_DONE 4 -#define MPTCP_WORK_CLOSE_SUBFLOW 5 +#define MPTCP_WORK_RTX 1 +#define MPTCP_FALLBACK_DONE 2 +#define MPTCP_WORK_CLOSE_SUBFLOW 3 /* MPTCP socket release cb flags */ #define MPTCP_PUSH_PENDING 1 @@ -810,12 +809,9 @@ static inline bool mptcp_data_fin_enabled(const struct mptcp_sock *msk) static inline void mptcp_write_space(struct sock *sk) { - if (sk_stream_is_writeable(sk)) { - /* pairs with memory barrier in mptcp_poll */ - smp_mb(); - if (test_and_clear_bit(MPTCP_NOSPACE, &mptcp_sk(sk)->flags)) - sk_stream_write_space(sk); - } + /* pairs with memory barrier in mptcp_poll */ + smp_mb(); + sk_stream_write_space(sk); } static inline void __mptcp_sync_sndbuf(struct sock *sk) From patchwork Fri Mar 1 17:43:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthieu Baerts (NGI0)" X-Patchwork-Id: 208981 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp39844dyc; Fri, 1 Mar 2024 09:45:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWCqJuHr8HITg+s8ihZcZemZtEmZJ+mnyAmGHK3FMZkQFLtd43guundQWu9YRgCXtqqO+J9XkzLefCoM565zExiLuv6hg== X-Google-Smtp-Source: AGHT+IFbmamE2q7kqWF8PrmAVrJomJFN7qPseCEAYIieqhsnLKIPxO2hXMnSm6WrpyVAmt4PHJHe X-Received: by 2002:a05:6402:b86:b0:566:806a:6f9e with SMTP id cf6-20020a0564020b8600b00566806a6f9emr1684091edb.28.1709315110859; Fri, 01 Mar 2024 09:45:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709315110; cv=pass; d=google.com; s=arc-20160816; b=hMArvWYGgj6YNaHe7pEuewUYWczswewkzVlKroFLN6JPW8EslBJKV8YnMJ3q+cIH0b yMS9KCKUN3Jrg3wgKYd8OyaY3tKkaBTxmQX6xk8Zy3MYHyFdlLruODoFFfyPUSIx1IJD bj+py4qchR0eZeBYEjEiFTSHUy1Ro4LvBgqRvbXmMyuhMYOSKvLGClyBxEwAyF1Kb1Gd Mj0+eN6ijNx0UV8JUUv/NxKs95pquWSufiMdk/uJfYCQHpnOcXGh2Cj/Z08zrlFEHr/e Lcq7HBc5YFUWgz405wl9VnYScUKG7dL9X30bp6VwvdFpa3dpguLZNARqgoIHw6eRZxmH Z8rw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=gCc12B07E2gZBfMhSlPti6S/kMb6am8w7H7jjle8Ji4=; fh=dtfL7SHUWpoNkavaEIKFixF3/eMo8TZTrybXzF4g82Y=; b=NqWPBxhqxrZXSIZ1w6nxcvohl9BhvORIIjoW8WTYaFyUFcUXJ0Vl7+gUOOakL/Dsu6 8Ko2+XmPiY4RtFtfakTpsUsk3DI4VQKYiPDQYQV4Hl3beX1I/Bwk7dk3yvCNhePGtauF 2ammHmDokvt8WvrwGqeNmIbJcLI05Rj6uBIQywYRkUFpmHEsPfnrKf8OgefFIANxpQKN DeniY7WexzKHtt6DsQCOg9nHI3YnONaJ30pvN4CnpyOw0pmHNfKAJ0A5CM9LYoCAKgWV fgcl2v9o0035M30nnVWUofK90Zo6coiuWBE3BqyQc+MYRBZhHU8ur9CaVE3E1cDCWmRa g4gQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=g6irTJYs; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-88853-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88853-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id s20-20020a508d14000000b00565ac6ebb29si1560376eds.653.2024.03.01.09.45.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 09:45:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88853-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=g6irTJYs; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-88853-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88853-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 795671F27E52 for ; Fri, 1 Mar 2024 17:45:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F11B738DFA; Fri, 1 Mar 2024 17:44:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="g6irTJYs" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 4DDCD28389; Fri, 1 Mar 2024 17:44:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709315053; cv=none; b=WlSKbMgsitMqILxFUuW8Zv1qGoPWx9K8+sERxK7XAUkj/TJYYDpVzgiThuplQxJBsRv0hr4yESoHRhN4w8cUGqQZqZzXL47yKACjeT4NG6Yn+kWXDJW8NHIZK8xxHZlJhBV41SaiYys0E5swNLf7jc9v+qeoOCcnJf4fo1Er49g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709315053; c=relaxed/simple; bh=G4kAB8OZ4MXCOBDWMFPMABLVdbV5Sbsejmq3eie/oIU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IZiaFzzhaaN/qKC/lFgEKcZgtDOxsyc8J3UGvL6+XNEmMXrHXubz8X7um4KGFJCgwYinobJ028GzUrU5t827aY9yqCMATGeAG24lNwNDtdsR6LzvdD7mZmkfGOiEgCTc0IROLJQ3EhW2tmkNTFqvz2bkGrwTdhjkyNVrFXxsJZw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g6irTJYs; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0946C433F1; Fri, 1 Mar 2024 17:44:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709315052; bh=G4kAB8OZ4MXCOBDWMFPMABLVdbV5Sbsejmq3eie/oIU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=g6irTJYsG0b1tftibIKmtpbKQSaVOC6edt9F0Gh4EBRb6L61mta5ykc3wHFcSJHOt /zFXXm1SwL2xfZrjY3V0mQI2BNlHkJ02WgEJAHSS8yVholtMCZ2DMcnvfEtodYemUF zAMmf0l2VkSsSoIuhslQxpr7D8uq1h6T10eCT+hHPpCajn3Y04eoq83blnhFVW2NGh oPaL+BDGQUi06hi1SdNCtZGP6x8lWzVM79s0oL3/suf7Z5jOSgcwXpN2RzG0cEedk7 6c6zV1r41RWO4/5EBu7qCCnt/ZWFIScA+HWgV7tLh/zEr9uKEP+bJbhqkzRHx9YVRx 1Zqby5PaxjRqA== From: "Matthieu Baerts (NGI0)" Date: Fri, 01 Mar 2024 18:43:45 +0100 Subject: [PATCH net-next 2/4] mptcp: avoid some duplicate code in socket option handling Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240301-upstream-net-next-20240301-mptcp-tcp_notsent_lowat-v1-2-415f0e8ed0e1@kernel.org> References: <20240301-upstream-net-next-20240301-mptcp-tcp_notsent_lowat-v1-0-415f0e8ed0e1@kernel.org> In-Reply-To: <20240301-upstream-net-next-20240301-mptcp-tcp_notsent_lowat-v1-0-415f0e8ed0e1@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1525; i=matttbe@kernel.org; h=from:subject:message-id; bh=IwTtMaxyL6SadOk3ggccjuN2dObjnXMFlizaf9po/Wg=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBl4hPlUHL6w2XO8GVf5jqnDctIoZ1udQhRC431z Tk1U6TC1P+JAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZeIT5QAKCRD2t4JPQmmg c32uD/9zGka6Yv9dpXPEI6gmxJNd1lT7LUCuHuISOAwZPPtRx5ducsTozslymNZpaD37awTOQf4 0H9nybMJgpk3L8pKWXOxarezbtaDtpkU5iRqCAJGyTqxEzZy6aT2quD0OK5PaZpLVvTe0pNIrpY L+Abifgo+I9pSoKXLXGUqZahC87khx871/a3CgemfsA+CaXNsUTGDlJqsm9f8U7khQn4MUYLHrA mbQDANMoZnRhRbLolqMlE3ctTTMM1SMygwsnCge/cfBzEjSHzf1/i8Vd5E8gZTAvcFazFXs+GI1 CaVRgmevHH/idjnCrvmK27wqw0eevbEvqaE5UPooXbkkAHcUq2MVS6+JxrUN6kf/DEIBd/FXNa7 nnf6zCVb4Jgq4QS/yq42u1bMbFc6xPwWmbj7Jbf5Vtq/pN0+PikB5avJBr6L4IqB2yYymINoFKx QLTyEpSpEbWP238mHxnwAa4A5y6xCE4C8o2dQA7tYHwFZSUIA0l+Wmu620ITU8+dMOwgMsu1dit tBWzLV9w1JjM8x+MOmmMNiajYDG+11iSwlJb1XWaRqNlrNfMaBPMjZBiVJKwES8UjtFT6CKMI6m cZNF6WVXZBwO3Ld6aqNAEnlzTRSDe+akEMYlcCdm4UwtDJdWzkaxcWeuRwWoD7lyQdOelCUHJDJ AizY525FFU8ZRQA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792346801582092340 X-GMAIL-MSGID: 1792346801582092340 From: Paolo Abeni The mptcp_get_int_option() helper is needless open-coded in a couple of places, replace the duplicate code with the helper call. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/sockopt.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c index da37e4541a5d..ac37f6c5e2ed 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -629,13 +629,11 @@ static int mptcp_setsockopt_sol_tcp_cork(struct mptcp_sock *msk, sockptr_t optva { struct mptcp_subflow_context *subflow; struct sock *sk = (struct sock *)msk; - int val; + int val, ret; - if (optlen < sizeof(int)) - return -EINVAL; - - if (copy_from_sockptr(&val, optval, sizeof(val))) - return -EFAULT; + ret = mptcp_get_int_option(msk, optval, optlen, &val); + if (ret) + return ret; lock_sock(sk); sockopt_seq_inc(msk); @@ -659,13 +657,11 @@ static int mptcp_setsockopt_sol_tcp_nodelay(struct mptcp_sock *msk, sockptr_t op { struct mptcp_subflow_context *subflow; struct sock *sk = (struct sock *)msk; - int val; + int val, ret; - if (optlen < sizeof(int)) - return -EINVAL; - - if (copy_from_sockptr(&val, optval, sizeof(val))) - return -EFAULT; + ret = mptcp_get_int_option(msk, optval, optlen, &val); + if (ret) + return ret; lock_sock(sk); sockopt_seq_inc(msk); From patchwork Fri Mar 1 17:43:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthieu Baerts (NGI0)" X-Patchwork-Id: 208982 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp40083dyc; Fri, 1 Mar 2024 09:45:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXRNCLlm8uEBXOeMwYi+zJ8JCuu3tIc42TQeSVej6oBtRL/XZviz3OcNgX9n8UsZoYhVQDELQNNmMj6vXK5J65V2GUSww== X-Google-Smtp-Source: AGHT+IGMrqQe2svbORaWNGa6JZJR95qYn5+NEV1kxCReE9gGMStVZndPXRUuoNMT/ohPasjPG5s5 X-Received: by 2002:a17:906:6d4e:b0:a3e:6f98:c69d with SMTP id a14-20020a1709066d4e00b00a3e6f98c69dmr1618383ejt.63.1709315140950; Fri, 01 Mar 2024 09:45:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709315140; cv=pass; d=google.com; s=arc-20160816; b=EYMopIYD3CK9Zd7KH0xlz0Lfk/nKkh9kB7D8dHIombASFWhKhffXttQ0JfE9Opk/oC 36ui+/u76wtK7SCKkrgZtxID2+vRzZOaLNaGyuNL0U3ZQGJNsWWmRIXtoC64WMksl26o g6GIWRpMJD0b8/maZAwxPwp4eRTdvVAasnv1OFEIXZYUd13qkujsOk/YmbUuRKa8GhSz 5hr4Vsn86t506pWWPVW79IZLVFLIDRiuJzYSY/VWYFwjZTXFnnjRrusJY4nrHYqvvTvs 9AOTgmv0SK9kGZWVdkTGV5yVES8d1DoyaP0u4bf5QtuaEW6EZEd8wxlcqCP6xdqGTgXg 5vRQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=lKjudTmtBX1zdvYxZHSxIIQxOvvOj/Yj1v2wDgtx5Ws=; fh=dtfL7SHUWpoNkavaEIKFixF3/eMo8TZTrybXzF4g82Y=; b=ASvHek2+2LShsJfwJWM3VnHErfv8LqXoGbzLaspUogXC7yzNUSAqQvU3ev0t9PWRKL bOy9OkptFr77W5XI0oWWS26ScGTkxKenvDdUxdCEgImtJkRbT3vopiFZXqwpjBfT3yND b+YR2brWDlJQSInkCE6VdyZGpDmyyRWk1spxQV8skQYvm5NsyBscDboVnYK3I6dAPaw5 hUZ1yH6oFppVD6yykekHJLzjJTxr7K+5cjgvjajVvdjwntH1y272sQi4Lj8m54ayR4Sw KVOZeWzmGEkhFsReAKQmL5d5eNZK90zEemduyKeAA0ZwQMVaJtsqA9KbrOJDqMtgJCYt 8K5g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gTX5kZtM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-88854-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88854-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id fx13-20020a170906b74d00b00a44039da735si1594560ejb.201.2024.03.01.09.45.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 09:45:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88854-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gTX5kZtM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-88854-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88854-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 5EA871F279B7 for ; Fri, 1 Mar 2024 17:45:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5301739FFD; Fri, 1 Mar 2024 17:44:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gTX5kZtM" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C314938DE0; Fri, 1 Mar 2024 17:44:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709315055; cv=none; b=DkTlEscEBho3UBexnB2LxDxi06goGBO9j4mq9d3hmU7qGGJImBKBrga1FgkvZVgslOR6qZ9roJlfXWwgtgcpQvbrDHmVnWHNOzpptPIuA0cGdOJPXnXXJ0KjMznDMGTuJsNiM/yds+vtk9fP/4gDezKBXmHMAUuEiOxJ5NdRKng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709315055; c=relaxed/simple; bh=On3LuyuchIv+6vUp+3/v6/8Liy7MCKBeHemzKMyJi28=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LUMhA5g2YjDHRQMgk4Ao2clnAWWzXxAFY6fnJUKQ/H/hpuwemgm5cjwkFh6zgMEyptU66cMkENCn3zy7UR9YK84EFiCK64fQgbTL/nUpJCKMB1xfSXcW3pB8D2re7VUvsa3rsBmDwAQPjMFh+1pSl/IYhxvRlkQ1iM6YeGjMHMY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gTX5kZtM; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DE67C433C7; Fri, 1 Mar 2024 17:44:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709315055; bh=On3LuyuchIv+6vUp+3/v6/8Liy7MCKBeHemzKMyJi28=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gTX5kZtMwC4VVSieEoF7mir9xtf+ndqZvp/yHAaX6z15w5mfVk1ik37QX1YVSR3ob nM/KM2Uja89196F+3ShlBYkRZTBo2JkyEFAtiWxKWbyoWfjRbgml0p5OMAXWS7LK3b ATkhs5G/85kSr3drOz+uzPmQ3Fh+huT4KpYto8d/pcyASkGo6xpP26YwWShGRyM6oi TEk1AdExOfvcDVikLS2VXcqTndpPc5j6KXfnp6dRneoOfNwCDKnCi3zia+JTw8pQRr moKxqRAqS3OhLnVv7V8hTldoLqhIfX2YmSHutlIgIWHshmE2F6a2Y8r7R8FOKlcdFy 1YJDzLzVZO8/A== From: "Matthieu Baerts (NGI0)" Date: Fri, 01 Mar 2024 18:43:46 +0100 Subject: [PATCH net-next 3/4] mptcp: implement TCP_NOTSENT_LOWAT support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240301-upstream-net-next-20240301-mptcp-tcp_notsent_lowat-v1-3-415f0e8ed0e1@kernel.org> References: <20240301-upstream-net-next-20240301-mptcp-tcp_notsent_lowat-v1-0-415f0e8ed0e1@kernel.org> In-Reply-To: <20240301-upstream-net-next-20240301-mptcp-tcp_notsent_lowat-v1-0-415f0e8ed0e1@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6452; i=matttbe@kernel.org; h=from:subject:message-id; bh=DylowcMwFWhiJDHcbv67N/3PhLtYSLe2QauXhTfybI0=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBl4hPlCVJjrsvPQRsqK81MfJXtMx2+zrnm9c51K BLZyx1pvvOJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZeIT5QAKCRD2t4JPQmmg c+0oD/90WrTHgoFAFhzSgNrxFEi70XeSvnQmlhuwtqV0jKUuPuofY7zNyyjRxQOQafbYgGk/M1F C/gi8sEfh6klQx16tbi+ptK+YX/UWnUk4cYa4bES/BWITCnF2pg74Z4hVwzka3I3E6AJmTjD064 cNQIde751qMJaW1QPp/QngoyS5TtnqtbAvsG927RxMwrbEuEXkTSUJfI56yvMksbtc7CAfIMpc1 QwlHeeLHlSObT4OQHMepe3QkX3HAFF9VuLL/f55yBcCYD7GEFiMQlkRAg36DGMjKZanUAkMxp4k AGNP7CDI2eOJXCwHSJZc0dsc2sWFDi4aTaHwK4x6eSirHXX6m1b/1oVHNxHUGC1pTAWDyhTvjtL uy4D71Hhy/bBdXMu5pPmraUGj7Qu0PJ++wiQGLj93L8t3+n+RrC3YCG7Rb/8cdIa/bnNdsFBomD XSlJI+aQXvno/b1Rs1mTN310+KxKlT6IX9K6OCxTb78T9N68R/Zq6vrOqFE4XfHUoAYJxz8g9qO 3WAAFCLmWPDcudLvpwrZx1nLfvN77NsLE2bnX7LCx5MMlD3NIgbbHYkTVrfF6nArXds/ErSuGnV FHZj0MKss7czv2sX+2BECdMaLfjVgcVtueVwmHplYFQzX2lL97eFql8BNlXbrM+2emk4Dl1xQNh YKmQalWTOWFcyFQ== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792346832975694637 X-GMAIL-MSGID: 1792346832975694637 From: Paolo Abeni Add support for such socket option storing the user-space provided value in a new msk field, and using such data to implement the _mptcp_stream_memory_free() helper, similar to the TCP one. To avoid adding more indirect calls in the fast path, open-code a variant of sk_stream_memory_free() in mptcp_sendmsg() and add direct calls to the mptcp stream memory free helper where possible. Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/464 Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 39 ++++++++++++++++++++++++++++++++++----- net/mptcp/protocol.h | 28 +++++++++++++++++++++++++++- net/mptcp/sockopt.c | 12 ++++++++++++ 3 files changed, 73 insertions(+), 6 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index a3d79e9d0694..99367c40de0d 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1762,6 +1762,30 @@ static int do_copy_data_nocache(struct sock *sk, int copy, return 0; } +/* open-code sk_stream_memory_free() plus sent limit computation to + * avoid indirect calls in fast-path. + * Called under the msk socket lock, so we can avoid a bunch of ONCE + * annotations. + */ +static u32 mptcp_send_limit(const struct sock *sk) +{ + const struct mptcp_sock *msk = mptcp_sk(sk); + u32 limit, not_sent; + + if (sk->sk_wmem_queued >= READ_ONCE(sk->sk_sndbuf)) + return 0; + + limit = mptcp_notsent_lowat(sk); + if (limit == UINT_MAX) + return UINT_MAX; + + not_sent = msk->write_seq - msk->snd_nxt; + if (not_sent >= limit) + return 0; + + return limit - not_sent; +} + static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) { struct mptcp_sock *msk = mptcp_sk(sk); @@ -1806,6 +1830,12 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) struct mptcp_data_frag *dfrag; bool dfrag_collapsed; size_t psize, offset; + u32 copy_limit; + + /* ensure fitting the notsent_lowat() constraint */ + copy_limit = mptcp_send_limit(sk); + if (!copy_limit) + goto wait_for_memory; /* reuse tail pfrag, if possible, or carve a new one from the * page allocator @@ -1813,9 +1843,6 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) dfrag = mptcp_pending_tail(sk); dfrag_collapsed = mptcp_frag_can_collapse_to(msk, pfrag, dfrag); if (!dfrag_collapsed) { - if (!sk_stream_memory_free(sk)) - goto wait_for_memory; - if (!mptcp_page_frag_refill(sk, pfrag)) goto wait_for_memory; @@ -1830,6 +1857,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) offset = dfrag->offset + dfrag->data_len; psize = pfrag->size - offset; psize = min_t(size_t, psize, msg_data_left(msg)); + psize = min_t(size_t, psize, copy_limit); total_ts = psize + frag_truesize; if (!sk_wmem_schedule(sk, total_ts)) @@ -3760,6 +3788,7 @@ static struct proto mptcp_prot = { .unhash = mptcp_unhash, .get_port = mptcp_get_port, .forward_alloc_get = mptcp_forward_alloc_get, + .stream_memory_free = mptcp_stream_memory_free, .sockets_allocated = &mptcp_sockets_allocated, .memory_allocated = &tcp_memory_allocated, @@ -3933,12 +3962,12 @@ static __poll_t mptcp_check_writeable(struct mptcp_sock *msk) { struct sock *sk = (struct sock *)msk; - if (sk_stream_is_writeable(sk)) + if (__mptcp_stream_is_writeable(sk, 1)) return EPOLLOUT | EPOLLWRNORM; set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); smp_mb__after_atomic(); /* NOSPACE is changed by mptcp_write_space() */ - if (sk_stream_is_writeable(sk)) + if (__mptcp_stream_is_writeable(sk, 1)) return EPOLLOUT | EPOLLWRNORM; return 0; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index f0c634e843e6..7cb502260dea 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -307,6 +307,7 @@ struct mptcp_sock { in_accept_queue:1, free_first:1, rcvspace_init:1; + u32 notsent_lowat; struct work_struct work; struct sk_buff *ooo_last_skb; struct rb_root out_of_order_queue; @@ -807,11 +808,36 @@ static inline bool mptcp_data_fin_enabled(const struct mptcp_sock *msk) READ_ONCE(msk->write_seq) == READ_ONCE(msk->snd_nxt); } +static inline u32 mptcp_notsent_lowat(const struct sock *sk) +{ + struct net *net = sock_net(sk); + u32 val; + + val = READ_ONCE(mptcp_sk(sk)->notsent_lowat); + return val ?: READ_ONCE(net->ipv4.sysctl_tcp_notsent_lowat); +} + +static inline bool mptcp_stream_memory_free(const struct sock *sk, int wake) +{ + const struct mptcp_sock *msk = mptcp_sk(sk); + u32 notsent_bytes; + + notsent_bytes = READ_ONCE(msk->write_seq) - READ_ONCE(msk->snd_nxt); + return (notsent_bytes << wake) < mptcp_notsent_lowat(sk); +} + +static inline bool __mptcp_stream_is_writeable(const struct sock *sk, int wake) +{ + return mptcp_stream_memory_free(sk, wake) && + __sk_stream_is_writeable(sk, wake); +} + static inline void mptcp_write_space(struct sock *sk) { /* pairs with memory barrier in mptcp_poll */ smp_mb(); - sk_stream_write_space(sk); + if (mptcp_stream_memory_free(sk, 1)) + sk_stream_write_space(sk); } static inline void __mptcp_sync_sndbuf(struct sock *sk) diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c index ac37f6c5e2ed..1b38dac70719 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -812,6 +812,16 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname, return 0; case TCP_ULP: return -EOPNOTSUPP; + case TCP_NOTSENT_LOWAT: + ret = mptcp_get_int_option(msk, optval, optlen, &val); + if (ret) + return ret; + + lock_sock(sk); + WRITE_ONCE(msk->notsent_lowat, val); + mptcp_write_space(sk); + release_sock(sk); + return 0; case TCP_CONGESTION: return mptcp_setsockopt_sol_tcp_congestion(msk, optval, optlen); case TCP_CORK: @@ -1345,6 +1355,8 @@ static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname, return mptcp_put_int_option(msk, optval, optlen, msk->cork); case TCP_NODELAY: return mptcp_put_int_option(msk, optval, optlen, msk->nodelay); + case TCP_NOTSENT_LOWAT: + return mptcp_put_int_option(msk, optval, optlen, msk->notsent_lowat); } return -EOPNOTSUPP; } From patchwork Fri Mar 1 17:43:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthieu Baerts (NGI0)" X-Patchwork-Id: 208983 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp40216dyc; Fri, 1 Mar 2024 09:45:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV4ORCnQxGDjilhqjcU3bCWJFJZ0JrhYTVOjKGrzcYWWvdKi71ssKoBHqtxznau+qFLb1giT7HJ/Uwl+1D3083E4/Fd9A== X-Google-Smtp-Source: AGHT+IEEZET0/bN+6Fu74TBWUcurwYFNPgPR3hrfKdW7e5u7Y+I9Pp1M0rcJ26BsRTyZZNVVUp6t X-Received: by 2002:a17:907:20d9:b0:a44:1b98:1829 with SMTP id qq25-20020a17090720d900b00a441b981829mr1789570ejb.57.1709315152297; Fri, 01 Mar 2024 09:45:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709315152; cv=pass; d=google.com; s=arc-20160816; b=bFVkEv2pBdgsTu7uyV+RNaIJk8zz+4jD3bbhu4Qmkobj5wcYQT5naE+Gm4WmE3jw1o vGD/cBeH6bmrM326KXdc7YwSTkzvGskeqB4Av14LG82qbMJdWGjvtBoWf9ps6s7yia3+ 5938V5oJUXaqmLRT0vbB/bGhSPGeDR42GdBOtjeciVu9TCkPTActj+eYYaihYeQ1oZE6 cdX5WY2susfC9+Z/aGuKzfXq6OoNP23KiRuol68umMhgpssJC0dHQ7Ccy9SYW+FsUB5H jxSN+meMDw408jmrpvkVcbiqQhvThipWGGMrpy+dOXbyi/hPTpKoxR4SKRly1dcQmUhz 4GmA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=SN0MsHEc8v2Q+6IVsGuqtlfdtMv81DUqr7ZBrZAbcZ8=; fh=dtfL7SHUWpoNkavaEIKFixF3/eMo8TZTrybXzF4g82Y=; b=f1vJ04bElBdRr0vPIY1aDLN0+qNlfiLPxXP689evJWXcWAmsnYVkWL8ZqTSwTvRHxX glG0U23F/vZafEwcC/7u/2/xPiVJ3JLePGdU7eQY+demPwBJivBdAyCYvyEsrWZrp52z UYREuJfgqwabThauMn2fzrSgBsoMf5EFDi6wKvYhLr0LtgA6jNCAX2zPilFj5D5u7Hem jyProq2btgP8COZK0THsUPSZ5AlK2VrB1mW3dZozRbPWOUTQWZLHStRX9+ZVh36YNB5A umBMteoq27UZG3Y9AS5FMvxHPHf5YRt8l6vcGd3lnCepQaAyypfNmdFfLgyO4CW+AeYu bROA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U+0SQCYO; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-88855-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88855-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id bx5-20020a170906a1c500b00a3f9609739fsi1715168ejb.551.2024.03.01.09.45.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 09:45:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88855-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U+0SQCYO; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-88855-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88855-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 636F71F27E52 for ; Fri, 1 Mar 2024 17:45:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41CD23A1D8; Fri, 1 Mar 2024 17:44:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="U+0SQCYO" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3B3F339AF8; Fri, 1 Mar 2024 17:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709315058; cv=none; b=u3Wr4B8CwQWAwsmHsCRr2mNsMaN4NxjHDaBXvIoKI5jY2rLMgbohhLEBIB1Pimj10ioORApwsQ68wAvDk8hMM8binm3tKH8W915f7iZJ06z7wXE+NWIZ9fi3B7pNZHV48cY+RtCnZ0j1ZVt6EEvtlWrBRXSIe1oUOmj/tITwaWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709315058; c=relaxed/simple; bh=EdDtedg5CZVRBqB3FVjkepFcu7D4qjE49o9Ec5jvrkM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LLsVxBeSGitQsh2ktqPa3m+GJ49gVvcLFiMiRiwAfBk8YqBp6zRrm/qqobIkna25tBY26KlOs3EWT+IXmgtoYVl0ldnmCrqeXSK75c5dMwJwC2B5MkJ1HNXsfPtDbXa7pQKR7X+WyQAMhCuhN+Sjl/u4m+NWNM4EmLOc4WpHOkw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U+0SQCYO; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1945C43394; Fri, 1 Mar 2024 17:44:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709315057; bh=EdDtedg5CZVRBqB3FVjkepFcu7D4qjE49o9Ec5jvrkM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=U+0SQCYOW2Fqxz64HPq0sjdCWZEYhrkEWIt0/Agtsr3QHKLuV2FyeXzaLLONCXssw yAAeF3r1yKAX+THjQHy4AKoWO2/8zApeGkDaWcS2C2T2PEoj61bkUin3iGBGG/bkVP fRdAL44UnSYX6fiIxgCZMu1Rk9gmL9BRl6mCWsu4Ci62R8pw6SL7aXaqPQxHScVAn3 U7PRtfOI/oDQ0jzRjcWCL9tVnKPpxcv7svaAKtZpQM2Yo7LHY016LEYulr36peBHyn Kbz0xuFHXuwANR5J62blx4x1rGhtI2FhpHkKoemjpkD8pv88FruM/EgdYCIKnRhzUs kOuY8l2mUMN/w== From: "Matthieu Baerts (NGI0)" Date: Fri, 01 Mar 2024 18:43:47 +0100 Subject: [PATCH net-next 4/4] mptcp: cleanup SOL_TCP handling Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240301-upstream-net-next-20240301-mptcp-tcp_notsent_lowat-v1-4-415f0e8ed0e1@kernel.org> References: <20240301-upstream-net-next-20240301-mptcp-tcp_notsent_lowat-v1-0-415f0e8ed0e1@kernel.org> In-Reply-To: <20240301-upstream-net-next-20240301-mptcp-tcp_notsent_lowat-v1-0-415f0e8ed0e1@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4108; i=matttbe@kernel.org; h=from:subject:message-id; bh=JOhIkA1LLYA8cGzrNasgxXO6BcQPIlXJLYVTAJAF5uE=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBl4hPlZzS9ixLKjsUkekt8wgU9lZeee8d4BgCjg GS/R9Hs8uaJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZeIT5QAKCRD2t4JPQmmg c5lmD/9sHqCD959Q30Wnmmxl/tk4DCC/yXJjSphpIt4NGK/jNXVeS9Xy3sXR3Rxv77l/oGa8AX+ 6cBZ61OYVCfZyBGG8C23TEKje189vY6geqp6A1Bv3qAaq7spQ80rNEUdtfOOFJlIDZ8EbiRZqw+ zWE9hGuEwNLZqEVvAR4pgPFDj7dG9NMVtILgi+T0rR539uYwp/1UFjGB2bqKertAY4D3riqKmjh JGLdU23eDtl2jZsPXZQcGvU/kodiO5ovABWY3D7nBvIcK+azJ/qx9eIxD0Cj2Mlx9bEtWpOj5WQ GVck/w/syaJjkUfCEYK4eW+HAHtnptyLv8/BGf/epFLd4ezAZ9QTFN5DZoe7Wufq6CV1lhAhJLt BY/YmiMVQ/s90SodCGibd8mqalo8iVxmqu9+fuGaH9ucgHct76DYTNYKy0r1UjsrBdfIxQSkes+ CBvrmXJHx/eMQP1LIKTPKloX99ND95FiAZQPeUEhsfZTpXB7TaJnDbgDbPmXzpsuCEyK/jZ4QQG lt0XTy5s4YJ1RWY0+ch5fib8PhDItjoUf8CGo1/mRQ+tiuMCMSoCgAgIv3KM7l9jD+gO41OthVY FLSWOGqysrrY8hvueESkPfVNDzFoOD5d5wm5A+FCE6eYWhguWsdunrjT1VBBj6sNuNcCU5I0946 x1jxsFrGCJyh5Qw== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792346845223983068 X-GMAIL-MSGID: 1792346845223983068 From: Paolo Abeni Most TCP-level socket options get an integer from user space, and set the corresponding field under the msk-level socket lock. Reduce the code duplication moving such operations in the common code. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/sockopt.c | 75 +++++++++++++++++++++-------------------------------- 1 file changed, 30 insertions(+), 45 deletions(-) diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c index 1b38dac70719..dcd1c76d2a3b 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -624,18 +624,11 @@ static int mptcp_setsockopt_sol_tcp_congestion(struct mptcp_sock *msk, sockptr_t return ret; } -static int mptcp_setsockopt_sol_tcp_cork(struct mptcp_sock *msk, sockptr_t optval, - unsigned int optlen) +static int __mptcp_setsockopt_sol_tcp_cork(struct mptcp_sock *msk, int val) { struct mptcp_subflow_context *subflow; struct sock *sk = (struct sock *)msk; - int val, ret; - ret = mptcp_get_int_option(msk, optval, optlen, &val); - if (ret) - return ret; - - lock_sock(sk); sockopt_seq_inc(msk); msk->cork = !!val; mptcp_for_each_subflow(msk, subflow) { @@ -647,23 +640,15 @@ static int mptcp_setsockopt_sol_tcp_cork(struct mptcp_sock *msk, sockptr_t optva } if (!val) mptcp_check_and_set_pending(sk); - release_sock(sk); return 0; } -static int mptcp_setsockopt_sol_tcp_nodelay(struct mptcp_sock *msk, sockptr_t optval, - unsigned int optlen) +static int __mptcp_setsockopt_sol_tcp_nodelay(struct mptcp_sock *msk, int val) { struct mptcp_subflow_context *subflow; struct sock *sk = (struct sock *)msk; - int val, ret; - ret = mptcp_get_int_option(msk, optval, optlen, &val); - if (ret) - return ret; - - lock_sock(sk); sockopt_seq_inc(msk); msk->nodelay = !!val; mptcp_for_each_subflow(msk, subflow) { @@ -675,8 +660,6 @@ static int mptcp_setsockopt_sol_tcp_nodelay(struct mptcp_sock *msk, sockptr_t op } if (val) mptcp_check_and_set_pending(sk); - release_sock(sk); - return 0; } @@ -799,35 +782,10 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname, int ret, val; switch (optname) { - case TCP_INQ: - ret = mptcp_get_int_option(msk, optval, optlen, &val); - if (ret) - return ret; - if (val < 0 || val > 1) - return -EINVAL; - - lock_sock(sk); - msk->recvmsg_inq = !!val; - release_sock(sk); - return 0; case TCP_ULP: return -EOPNOTSUPP; - case TCP_NOTSENT_LOWAT: - ret = mptcp_get_int_option(msk, optval, optlen, &val); - if (ret) - return ret; - - lock_sock(sk); - WRITE_ONCE(msk->notsent_lowat, val); - mptcp_write_space(sk); - release_sock(sk); - return 0; case TCP_CONGESTION: return mptcp_setsockopt_sol_tcp_congestion(msk, optval, optlen); - case TCP_CORK: - return mptcp_setsockopt_sol_tcp_cork(msk, optval, optlen); - case TCP_NODELAY: - return mptcp_setsockopt_sol_tcp_nodelay(msk, optval, optlen); case TCP_DEFER_ACCEPT: /* See tcp.c: TCP_DEFER_ACCEPT does not fail */ mptcp_setsockopt_first_sf_only(msk, SOL_TCP, optname, optval, optlen); @@ -840,7 +798,34 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname, optval, optlen); } - return -EOPNOTSUPP; + ret = mptcp_get_int_option(msk, optval, optlen, &val); + if (ret) + return ret; + + lock_sock(sk); + switch (optname) { + case TCP_INQ: + if (val < 0 || val > 1) + ret = -EINVAL; + else + msk->recvmsg_inq = !!val; + break; + case TCP_NOTSENT_LOWAT: + WRITE_ONCE(msk->notsent_lowat, val); + mptcp_write_space(sk); + break; + case TCP_CORK: + ret = __mptcp_setsockopt_sol_tcp_cork(msk, val); + break; + case TCP_NODELAY: + ret = __mptcp_setsockopt_sol_tcp_nodelay(msk, val); + break; + default: + ret = -ENOPROTOOPT; + } + + release_sock(sk); + return ret; } int mptcp_setsockopt(struct sock *sk, int level, int optname,