From nobody Tue May 14 00:24:52 2024 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 A72E37C0A8 for ; Mon, 22 Jan 2024 15:08:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705936136; cv=none; b=FDY7LIimK5YjC8cSxjX3QyjNy1JLc95ugw1nGgJZDwZQVhhU2fyVgGhdzIVnKi4MmJ/m178kNGRWhJm4LNOVibGlRbV0V6b34C6uFCRjf2acJn8Lh3AwLjpEJ4PUK6ePexuVJmE35EzCLsy1m1JMJ2iVRNGznOz+7WzyCoFtcsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705936136; c=relaxed/simple; bh=d+8CI2uMCsgL1BPzno67QAdv0HRtvXP4YoJamTPQCDE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pXdXqU0tB070KYhY6VYPL2uZuH/8BwfN7u89sJ/AzNzNE0hOOYXNzGC2c5niUrPDUobuxtPwv7PuP6oHcW8smYeA2u9ah2CgOIt77cAr3HLbt9tg8NvrO88Az0H/mlCZbrwQT9W1gDoG5SKD4HyQ6X66/L3fMjafZkAF30zERxQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=dCL/Tf31; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dCL/Tf31" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705936133; 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=IUsbV3x6gstmuw+xD6xLceLMmB9XZwsqFdjfq/0Oi8o=; b=dCL/Tf31wr2QGK+hbR3VZnDOw7H/rlR0iOHuqwoTTeTzKWLx/AcU5Qh2j4jp4yaHP9kZYN RWJ4i3Fm+m1Y34tJuqc0CiBKXisTHveLA0IioaOsPqD2XuIpgqNE5NSJiXJjwAh4oUWS5A /b/MIk6dNMaXOJyWEkql7p0V7BriRmk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-311-9osGyCUJOHiAvFRkIULs4Q-1; Mon, 22 Jan 2024 10:08:52 -0500 X-MC-Unique: 9osGyCUJOHiAvFRkIULs4Q-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 32FC5870828 for ; Mon, 22 Jan 2024 15:08:51 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.45.226.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id B66221C060AF for ; Mon, 22 Jan 2024 15:08:50 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next 1/7] mptcp: push ad DSS boundaries Date: Mon, 22 Jan 2024 16:08:38 +0100 Message-ID: <59d94e4297902d25829276df006615bbdd5f717f.1705836321.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 3.4.1 on 10.11.54.7 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" when inserting/creating skbs on the subflow write queue, if the to-be-appended data don't is not contiguous to the tail data, the protocol creates a new skb and prevent the TCP stack from merging it later by setting the EOR marker. Still no push flag is explicitly set at the end of previous GSO packet, making the aggregation on the receiver side sub-optimal - and packetdrill self-tests less predictable. Explicitly mark the end of not contiguous DSS with the push flag. Fixes: 6d0060f600ad ("mptcp: Write MPTCP DSS headers to outgoing data packe= ts") Signed-off-by: Paolo Abeni --- This could also land on next, as needed, dropping the fixes tag --- net/mptcp/protocol.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 744b4d6f15f4..4d7131f96ebf 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1264,6 +1264,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct= sock *ssk, mpext =3D mptcp_get_ext(skb); if (!mptcp_skb_can_collapse_to(data_seq, skb, mpext)) { TCP_SKB_CB(skb)->eor =3D 1; + tcp_mark_push(tcp_sk(ssk), skb); goto alloc_skb; } =20 --=20 2.43.0 From nobody Tue May 14 00:24:52 2024 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 621D27C09E for ; Mon, 22 Jan 2024 15:08:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705936136; cv=none; b=DuAGVVlconH5SsW+hACz5Obd8Ymqcy5p0nV20EHGGlIeNGVcCB6a/Lk0vtxYUbqnIy3hICoCkhst5jmdNF8ibAo3l91Btl+Krsd+FFUF/s17GnLflhIYvdIDcGPzHLQs12LGiWvJyLEtbLhHdAK+Ehb6UFeadiafv8rffvx+CNE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705936136; c=relaxed/simple; bh=cfSWfF26bkzGFut5qdlu5ktfWfKBGxtCCrelM2Kxmq4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MAStqmIgDALA1XCiF1L2gt003tHM3hMHf8exFUbtUHWrfvek06K0oGzP3cV0z7zk6jXBZohYlBj3Rjc9tj4nXN1Enp5Fwe9t2F/OFEbnL9hRkiNxElOtmu55n9jLsi48VwKUUaPrHI3IwCEETNZF9b1FAFp0nfxG1MW5zLlO+W0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=EE1VAgBs; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EE1VAgBs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705936133; 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=J6UEF+Ej27BnwaNlYKPVRxmeAbOwB/OBF4lFqGVZ+Fg=; b=EE1VAgBsFX+3kWXZJIxpEF1hxYgxnslEf+n5Y86pPwDpc9QjHw9eSY/JtVuW0hdKBhPY2F Au/qaCK4I+ZvK7tgL+YeIIxR2sy98prtLyFfUtKLebvFNLh/ofW+JPtqEomJiZZnZtA76p 5//UCR1sqcuZI9pKpkg8a//fOQAlwwg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-646-JjyMShYlPWO0KPJJJuZaTA-1; Mon, 22 Jan 2024 10:08:52 -0500 X-MC-Unique: JjyMShYlPWO0KPJJJuZaTA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ED44D85A596 for ; Mon, 22 Jan 2024 15:08:51 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.45.226.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7CB5C1C060AF for ; Mon, 22 Jan 2024 15:08:51 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next 2/7] mptcp: fix snd_wnd initialization for passive socket Date: Mon, 22 Jan 2024 16:08:39 +0100 Message-ID: <14ed71656159324df35d706466b6da75a60d114a.1705836321.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 3.4.1 on 10.11.54.7 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" Such value should be inherited from the first subflow, but passive sockets always used 'rsk_rcv_wnd'. Fixes: 6f8a612a33e4 ("mptcp: keep track of advertised windows right edge") Signed-off-by: Paolo Abeni --- net/mptcp/protocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 4d7131f96ebf..7a47834bf6ac 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3218,7 +3218,7 @@ struct sock *mptcp_sk_clone_init(const struct sock *s= k, WRITE_ONCE(msk->write_seq, subflow_req->idsn + 1); WRITE_ONCE(msk->snd_nxt, msk->write_seq); WRITE_ONCE(msk->snd_una, msk->write_seq); - WRITE_ONCE(msk->wnd_end, msk->snd_nxt + req->rsk_rcv_wnd); + WRITE_ONCE(msk->wnd_end, msk->snd_nxt + tcp_sk(ssk)->snd_wnd); msk->setsockopt_seq =3D mptcp_sk(sk)->setsockopt_seq; mptcp_init_sched(msk, mptcp_sk(sk)->sched); =20 --=20 2.43.0 From nobody Tue May 14 00:24:52 2024 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 72A1E7C0BA for ; Mon, 22 Jan 2024 15:08:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705936136; cv=none; b=iDsj/SlSMGk+jnTVvGMiuBvdTWQqaC0Ay9pdWsC1iYPjszzU71Y9LySeEjYyFWxcOeFiW9BWROEhFjIkeI/q16hebt6eElk+KsrRi6PDOMHShuiiEJLCGOo9oMDPUs2w0XaB1E5YmFRg53ej+4xtwn/cgjFlsRN5FKLFYTmUoHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705936136; c=relaxed/simple; bh=Jm483eD7XCTYbTstZzMYLKIB3V+3PFzZD9vFTDmnOVs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HMBwD9E+f0mh3D0+D0HqwUk21bC2mLHRGmAyHT4yOPXdK0JV5wKKhygSGg4coXNHicEN6W7uIUri1vF8YujIu2L/WvF7yuJdsOqZXjH8IPNoaLbEHOU0P9SxV0ratjqQ2/vOilHi+wDGapZJUF2gik7iv/zqcabjh++i7KRzoNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=GqJslBfy; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GqJslBfy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705936134; 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=lTGB/FaQW48FTChQHYDDz35Uy2tB9OJ40H8G7HEtVEs=; b=GqJslBfygSSGK0VEQTClq+TnJzqt6xucY8QUS2lPz7PV9l8+MIONkp9YK5FY66oIBE+R6Q VR+kaOwehacjpwk+2GbWtfLGxKKZB7yI8SJaQtBbZfAKy8OwMRYUSgYTkOCwzjuKYVY7Dw rifj597HsFfxkVn9sZbP8g4xNw5vMQc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-568-K5vgEjh9Ou-nks34Sr1iwg-1; Mon, 22 Jan 2024 10:08:52 -0500 X-MC-Unique: K5vgEjh9Ou-nks34Sr1iwg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ADE81884346 for ; Mon, 22 Jan 2024 15:08:52 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.45.226.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D8C41C060AF for ; Mon, 22 Jan 2024 15:08:52 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next 3/7] mptcp: fix potential wake-up event loss Date: Mon, 22 Jan 2024 16:08:40 +0100 Message-ID: <27f976d6a8f1a88ed5ad3822af43d0fc648ab9f8.1705836321.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 3.4.1 on 10.11.54.7 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" After the blamed commit below, the send buffer auto-tuning can happen after that the mptcp_propagate_sndbuf() completes - via the delegated action infrastructure. We must check for write space even after such change or we risk missing the wake-up event. Fixes: 8005184fd1ca ("mptcp: refactor sndbuf auto-tuning") Signed-off-by: Paolo Abeni --- net/mptcp/protocol.h | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index d05ec76dd7c2..bbc490f36273 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -797,6 +797,16 @@ static inline bool mptcp_data_fin_enabled(const struct= mptcp_sock *msk) READ_ONCE(msk->write_seq) =3D=3D READ_ONCE(msk->snd_nxt); } =20 +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); + } +} + static inline void __mptcp_sync_sndbuf(struct sock *sk) { struct mptcp_subflow_context *subflow; @@ -815,6 +825,7 @@ static inline void __mptcp_sync_sndbuf(struct sock *sk) =20 /* the msk max wmem limit is * tcp wmem[2] */ WRITE_ONCE(sk->sk_sndbuf, new_sndbuf); + mptcp_write_space(sk); } =20 /* The called held both the msk socket and the subflow socket locks, @@ -845,14 +856,16 @@ static inline void mptcp_propagate_sndbuf(struct sock= *sk, struct sock *ssk) local_bh_enable(); } =20 -static inline void mptcp_write_space(struct sock *sk) +static inline void __mptcp_sync_sndnxt(struct sock *sk, u64 new_snd_nxt) { - 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); - } + struct mptcp_sock *msk =3D mptcp_sk(sk); + + if (!after64(new_snd_nxt, msk->snd_nxt)) + return; + + msk->bytes_sent +=3D new_snd_nxt - msk->snd_nxt; + WRITE_ONCE(msk->snd_nxt, new_snd_nxt); + mptcp_write_space(sk); } =20 void mptcp_destroy_common(struct mptcp_sock *msk, unsigned int flags); --=20 2.43.0 From nobody Tue May 14 00:24:52 2024 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 790BC7CF04 for ; Mon, 22 Jan 2024 15:08:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705936138; cv=none; b=Qcwnv2veptkYMcnI4tk+iyOrNcEztWJHD8uriLzhEq+onP1CXzgn7Y/Xe72N6i//D0CskyixcUIfTe5/pntC8bq0rkrauetcJpMK4Sb3aUHqfv1LPLENyTD+0rxi1Wt5um7oBpovjr7+/dANRFedBHM0czbSqZaDmhPtkgd+joE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705936138; c=relaxed/simple; bh=7rJJHWX04kPETA0xp0m1Ecfw5MqH/nJCYUOrFnnW5mo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=H8H3WTaswz6/3rrgBRbqDIB4DsEHfnl+OFbcqDYHSdykvVANLe9iDb9CeMqrZK7vd8RoTm0MxDOyPgbsJ/Ms2LzcNSRYQ3ZQSk6fhJngg8tA7uxikb2N8KGDOimCDk0DyDUwVjCE4s4WbOqx+3PnDpw+HF5Mh0L+TBQAJQcGnvc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WkLbdRp+; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WkLbdRp+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705936135; 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=8UOWoEQIZeXgatx7N24f9kg+TH790lVe6zdf0engFQ4=; b=WkLbdRp+F25zLXfapJb1oOqoWiAjUS7HHvs0dqTIhYfIYc/LklQEyuThQCTO8yOSDgBhPo igp4OOMD17OqvQB0yprLZ4uPWgX1+HATzNd+ByaXWHgpcm+m++u3viSeXpXyKNJe0XxFxD ioPJ2dMvDFIX4Q/tiBohH/66WWe40lA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-588-Twr2dRBePaeksLGYurhOHA-1; Mon, 22 Jan 2024 10:08:53 -0500 X-MC-Unique: Twr2dRBePaeksLGYurhOHA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 70BF985A58E for ; Mon, 22 Jan 2024 15:08:53 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.45.226.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id F29931C060B1 for ; Mon, 22 Jan 2024 15:08:52 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next 4/7] mptcp: cleanup writer wake-up Date: Mon, 22 Jan 2024 16:08:41 +0100 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 3.4.1 on 10.11.54.7 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" 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 --- 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 7a47834bf6ac..3599205fdceb 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1691,15 +1691,6 @@ static void __mptcp_subflow_push_pending(struct sock= *sk, struct sock *ssk, bool } } =20 -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); =20 static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, @@ -1873,7 +1864,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msgh= dr *msg, size_t len) continue; =20 wait_for_memory: - mptcp_set_nospace(sk); + set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); __mptcp_push_pending(sk, msg->msg_flags); ret =3D sk_stream_wait_memory(sk, &timeo); if (ret) @@ -3898,8 +3889,8 @@ static __poll_t mptcp_check_writeable(struct mptcp_so= ck *msk) if (sk_stream_is_writeable(sk)) return EPOLLOUT | EPOLLWRNORM; =20 - 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; =20 diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index bbc490f36273..3069d5c072b0 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -113,10 +113,9 @@ #define MPTCP_RST_TRANSIENT BIT(0) =20 /* 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 =20 /* MPTCP socket release cb flags */ #define MPTCP_PUSH_PENDING 1 @@ -799,12 +798,9 @@ static inline bool mptcp_data_fin_enabled(const struct= mptcp_sock *msk) =20 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); } =20 static inline void __mptcp_sync_sndbuf(struct sock *sk) --=20 2.43.0 From nobody Tue May 14 00:24:52 2024 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 C9DC97CF06 for ; Mon, 22 Jan 2024 15:08:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705936138; cv=none; b=fdvXdnfET0eOnTYszGXml7Lx3fSzJNfb8M5uIffMSCDZHZaSW3F02N74Plct4JW6Cr7Kji+FYpjhzFV5EyMeDjNMo3zFZTAQUDsAOwxFxIDm+GAadLkLmsKd3OImfqWIw0D2h0U3n433QzBL5MK1zb3/fpzzo9t0y2YkkYKPnH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705936138; c=relaxed/simple; bh=x+d6eSiGhT2Nlyf5X80Xa2HjBowEIhTNrTNaIs9pyBY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V/s8ztWxinRKlYXUIz3iBodtWx4BS4WsvynZGVpNGwDKvg04kYQkDaeOT63wLjut0kKH6ZMf9jaoWwPcfJ9MuDhYnkciXF8ZyxKsA41bTadH93bqT8yPSW2k6EwgF7HvUJzLFryfL9TZEBxd7dWWkL0rBaIo+heCSRWBnm2BEJk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FXtaPwQ8; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FXtaPwQ8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705936135; 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=3dBwYBZm8KULJpa+g8Lf6eL61n5tLMWELiidRcbUT0Y=; b=FXtaPwQ810LS/Iu5nlSL622zO5wSAol1mNLyjD/IaJkI6RTpvLb0n6GJ474RuRO5dmFoX/ KTYG9A7qtK5Lk4rGdK8OHYFlpRGbECOK0DcIkYFgvR1Q0H4LCPYjpX82E9ICkCh8KDuoUc FVJxcC/4LnRjgYk5dHvYo456YvaZfEU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-118-n_0_BYLmNaWWKdmhmqy0UQ-1; Mon, 22 Jan 2024 10:08:54 -0500 X-MC-Unique: n_0_BYLmNaWWKdmhmqy0UQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 351B2185A788 for ; Mon, 22 Jan 2024 15:08:54 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.45.226.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id B98E41C060AF for ; Mon, 22 Jan 2024 15:08:53 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next 5/7] mptcp: avoid some duplicate code in socket option handling Date: Mon, 22 Jan 2024 16:08:42 +0100 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 3.4.1 on 10.11.54.7 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" 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 --- 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 =3D (struct sock *)msk; - int val; - - if (optlen < sizeof(int)) - return -EINVAL; + int val, ret; =20 - if (copy_from_sockptr(&val, optval, sizeof(val))) - return -EFAULT; + ret =3D mptcp_get_int_option(msk, optval, optlen, &val); + if (ret) + return ret; =20 lock_sock(sk); sockopt_seq_inc(msk); @@ -659,13 +657,11 @@ static int mptcp_setsockopt_sol_tcp_nodelay(struct mp= tcp_sock *msk, sockptr_t op { struct mptcp_subflow_context *subflow; struct sock *sk =3D (struct sock *)msk; - int val; - - if (optlen < sizeof(int)) - return -EINVAL; + int val, ret; =20 - if (copy_from_sockptr(&val, optval, sizeof(val))) - return -EFAULT; + ret =3D mptcp_get_int_option(msk, optval, optlen, &val); + if (ret) + return ret; =20 lock_sock(sk); sockopt_seq_inc(msk); --=20 2.43.0 From nobody Tue May 14 00:24:52 2024 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 93C1A3E46A for ; Mon, 22 Jan 2024 15:08:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705936139; cv=none; b=pieOJCdhjG0OwgGGLTDhpZAgWeOwP212aTgY16Bg0Eiptrj9QK7LM9+05XkALNPzIeui6XqrtVAafF4mrR82wDtkYONBpD/g6aq4O/PUs1Z8DjcOvwirHBzxdd1bIgFuevFAi19OjFl2uv1BIK5oidMYYdia3qmLu95UtYqgMfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705936139; c=relaxed/simple; bh=uoS9gJEJd7vI9ca4Qi7umtcT99gv6NDEchTJ6/qcbOg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gVJ2BWu7SehIREbLZ77DRFEX3t40ARde7ser13kW8Qra4lurCh008kruqLEfzYc+PdNvN2tZHnB6x2zDhIXjXYRlvV5oaVpTQSTyj2BMpeN3WN7BtrWHhOACCj4UizJDJy59KO29UQqmQm63trqaSWBozXGkHK0NnSnacj6rvkM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XDPwGLd2; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XDPwGLd2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705936136; 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=SQhGXBrQocmrcorCcRWZu+qKNBqHrYUygfdg6pBb1RM=; b=XDPwGLd2m7GoMOUmwCkTjbQKN1BFlU+fW4xExr66muWHFZgEsIfBwRP5XRz5TIymIZpYWc WbY2sNawUeOB5ZqLzkfTtV1dLvxYnqJsB10CltvvdLrQRkhJK6BdPYCaaGBY0n5JH8mQbu r0KSDCW8ZY0cZfinUQBCsfg9OaxII/I= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-112-09NT16EMMya-FcuQj1rlzQ-1; Mon, 22 Jan 2024 10:08:55 -0500 X-MC-Unique: 09NT16EMMya-FcuQj1rlzQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EAED438143A0 for ; Mon, 22 Jan 2024 15:08:54 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.45.226.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79B8E1C060AF for ; Mon, 22 Jan 2024 15:08:54 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next 6/7] mptcp: implement TCP_NOTSENT_LOWAT support. Date: Mon, 22 Jan 2024 16:08:43 +0100 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 3.4.1 on 10.11.54.7 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" 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, instead of hooking the new helper via the sk_stream_memory_free sock cb, add the directly calls where needed. Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/464 Signed-off-by: Paolo Abeni --- net/mptcp/protocol.c | 33 ++++++++++++++++++++++++++++----- net/mptcp/protocol.h | 28 +++++++++++++++++++++++++++- net/mptcp/sockopt.c | 12 ++++++++++++ 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 3599205fdceb..53d6c5544900 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1761,6 +1761,25 @@ static int do_copy_data_nocache(struct sock *sk, int= copy, return 0; } =20 +static u32 mptcp_send_limit(const struct sock *sk) +{ + const struct mptcp_sock *msk =3D mptcp_sk(sk); + u32 limit, not_sent; + + if (!sk_stream_memory_free(sk)) + return 0; + + limit =3D mptcp_notsent_lowat(sk); + if (limit =3D=3D UINT_MAX) + return UINT_MAX; + + not_sent =3D msk->write_seq - msk->snd_nxt; + if (not_sent >=3D limit) + return 0; + + return limit - not_sent; +} + static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) { struct mptcp_sock *msk =3D mptcp_sk(sk); @@ -1805,6 +1824,12 @@ static int mptcp_sendmsg(struct sock *sk, struct msg= hdr *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 =3D mptcp_send_limit(sk); + if (!copy_limit) + goto wait_for_memory; =20 /* reuse tail pfrag, if possible, or carve a new one from the * page allocator @@ -1812,9 +1837,6 @@ static int mptcp_sendmsg(struct sock *sk, struct msgh= dr *msg, size_t len) dfrag =3D mptcp_pending_tail(sk); dfrag_collapsed =3D 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; =20 @@ -1829,6 +1851,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msgh= dr *msg, size_t len) offset =3D dfrag->offset + dfrag->data_len; psize =3D pfrag->size - offset; psize =3D min_t(size_t, psize, msg_data_left(msg)); + psize =3D min_t(size_t, psize, copy_limit); total_ts =3D psize + frag_truesize; =20 if (!sk_wmem_schedule(sk, total_ts)) @@ -3886,12 +3909,12 @@ static __poll_t mptcp_check_writeable(struct mptcp_= sock *msk) { struct sock *sk =3D (struct sock *)msk; =20 - if (sk_stream_is_writeable(sk)) + if (__mptcp_stream_is_writeable(sk, 1)) return EPOLLOUT | EPOLLWRNORM; =20 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; =20 return 0; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 3069d5c072b0..4a32d3d11fb6 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; @@ -796,11 +797,36 @@ static inline bool mptcp_data_fin_enabled(const struc= t mptcp_sock *msk) READ_ONCE(msk->write_seq) =3D=3D READ_ONCE(msk->snd_nxt); } =20 +static inline u32 mptcp_notsent_lowat(const struct sock *sk) +{ + struct net *net =3D sock_net(sk); + u32 val; + + val =3D 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 w= ake) +{ + const struct mptcp_sock *msk =3D mptcp_sk(sk); + u32 notsent_bytes; + + notsent_bytes =3D 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); } =20 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 =3D 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; } --=20 2.43.0 From nobody Tue May 14 00:24:52 2024 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 5AB257CF04 for ; Mon, 22 Jan 2024 15:08:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705936139; cv=none; b=YOyN8uJ5/Hs7B/xxmmZTQ7+qPYbkUh5ascgRSQZw4Mb6YRO99cUM0qBD0PxDEU8SeI+hdwoHVKEI9S7AAviGt4Pe6AmrlJDROFmAyBij1bYfDReU5KSy7YsnLPNGuqsEPgghK7GLZ10rt/a2qRynXUT47iQ+mcgjhN6KiAqHFII= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705936139; c=relaxed/simple; bh=EzLZH6aFXRumUkGJpI3oeD+oymNoJs7Iq/Y89m+Rsdk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MvrQIQ7gX6xRMPD8nY0YL5ssl5TZ6R/n9gcOkuO0kzUdj6F/vmsvbObdkfYNrafv0lJnKy5mjYbzb+CHfvd822G6IdM5g2VZs+PglK94YJxsgUftYLPtkqmHyTIhnhWvORih7SkZP8mKVQUoQ56u0+k9fkEapmgJsEVmc7QLrpc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=E146FcDD; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="E146FcDD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705936137; 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=+akTRa9mFQqVNm211wS2m5ZkUgSgoHSuHL1fIi9cQyo=; b=E146FcDDwv09E5bSpXUZJCndZMV81xcL56XOZ5X7IJ8WqyUPm1V8CnJummm4mX3BhNRhbF 3TOUlgkhJurGiuYOktijv43obyzb+Xa3D0/f5rSNqlN5UBJf97I1TKHkUkIvUEpE3OPnsu eQWugJuNWt8ezvDsUwE7olki7cSMZrQ= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-136-qf6UftvuPXyynEed3k5K6A-1; Mon, 22 Jan 2024 10:08:56 -0500 X-MC-Unique: qf6UftvuPXyynEed3k5K6A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B07C53C0008A for ; Mon, 22 Jan 2024 15:08:55 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.45.226.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 401C31C060AF for ; Mon, 22 Jan 2024 15:08:55 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next 7/7] mptcp: cleanup SOL_TCP handling Date: Mon, 22 Jan 2024 16:08:44 +0100 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 3.4.1 on 10.11.54.7 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" 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 --- 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; } =20 -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 =3D (struct sock *)msk; - int val, ret; =20 - ret =3D mptcp_get_int_option(msk, optval, optlen, &val); - if (ret) - return ret; - - lock_sock(sk); sockopt_seq_inc(msk); msk->cork =3D !!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); =20 return 0; } =20 -static int mptcp_setsockopt_sol_tcp_nodelay(struct mptcp_sock *msk, sockpt= r_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 =3D (struct sock *)msk; - int val, ret; =20 - ret =3D mptcp_get_int_option(msk, optval, optlen, &val); - if (ret) - return ret; - - lock_sock(sk); sockopt_seq_inc(msk); msk->nodelay =3D !!val; mptcp_for_each_subflow(msk, subflow) { @@ -675,8 +660,6 @@ static int mptcp_setsockopt_sol_tcp_nodelay(struct mptc= p_sock *msk, sockptr_t op } if (val) mptcp_check_and_set_pending(sk); - release_sock(sk); - return 0; } =20 @@ -799,35 +782,10 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock= *msk, int optname, int ret, val; =20 switch (optname) { - case TCP_INQ: - ret =3D 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 =3D !!val; - release_sock(sk); - return 0; case TCP_ULP: return -EOPNOTSUPP; - case TCP_NOTSENT_LOWAT: - ret =3D 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); } =20 - return -EOPNOTSUPP; + ret =3D 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 =3D -EINVAL; + else + msk->recvmsg_inq =3D !!val; + break; + case TCP_NOTSENT_LOWAT: + WRITE_ONCE(msk->notsent_lowat, val); + mptcp_write_space(sk); + break; + case TCP_CORK: + ret =3D __mptcp_setsockopt_sol_tcp_cork(msk, val); + break; + case TCP_NODELAY: + ret =3D __mptcp_setsockopt_sol_tcp_nodelay(msk, val); + break; + default: + ret =3D -ENOPROTOOPT; + } + + release_sock(sk); + return ret; } =20 int mptcp_setsockopt(struct sock *sk, int level, int optname, --=20 2.43.0