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: 13578885 X-Patchwork-Delegate: kuba@kernel.org 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AJHcs2kG" 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: netdev@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-Patchwork-Delegate: kuba@kernel.org 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: 13578886 X-Patchwork-Delegate: kuba@kernel.org 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="g6irTJYs" 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: netdev@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-Patchwork-Delegate: kuba@kernel.org 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: 13578887 X-Patchwork-Delegate: kuba@kernel.org 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gTX5kZtM" 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: netdev@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-Patchwork-Delegate: kuba@kernel.org 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: 13578888 X-Patchwork-Delegate: kuba@kernel.org 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="U+0SQCYO" 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: netdev@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-Patchwork-Delegate: kuba@kernel.org 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,