From nobody Sat Apr 20 06:31:20 2024 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:a05:6638:d02:0:0:0:0 with SMTP id q2csp99981jaj; Thu, 2 Sep 2021 07:20:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuixv+2EEllKUMLx5hDL5Sm1pU1pED4FYR1c6X2JsRCmrsmX4tftPB38eustqspVG/bzeH X-Received: by 2002:a67:cb11:: with SMTP id b17mr1877841vsl.6.1630592450473; Thu, 02 Sep 2021 07:20:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630592450; cv=none; d=google.com; s=arc-20160816; b=SBZpR1DcKD1tAEEuG6vqFlTzZxcaZM4+U5DxJQKBfVVpJ6wPCPpagkQCd7RiZwlaev YO8sZxsD6BWm0pkir7vwS8ybEyHVw5b+dITEFbndwAwO3Ox9+z9vpYIboLDd/rBgmcvT gI36AbmRWZJW3dRbfXKyhLam4cQFqQve7TDeatS9SGO+xdhKdKCsRFLgQ2cP3Bbr1Kc+ h90cpf8ELg/plkf02WZng14PczM1uIUX1pVzGUTCPN/SFykTzDKw13l06lZ3rN9YhTEr O7JuC45zr2RzwyukLes/YquW/SEJ0Vtz0QMAmUoQkNtyBwT8FOUXrB9Lh6Kb3HWvf3HU WutQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=5mDJU6NE9VaROPqiItmVTwgDB2WVu7JPOayM+M/8Tak=; b=bg4qTcCqdn/DaO2QvlSFEkLm8qEh/ACPtkuYxZ/7GMJAqyuMgsKU/ObH09ba7b5luI oXT+5dYKhnV3j+2cYDqB3I/z6QihnS5ezmJ2vjPfH46rbUwbhnYPmrR5DyiOC/Gl0nNT OCe0/jjGPdZvD5kt2xBaazEm2HTOCyA93LsF+mgGVLqQ2YTQhwO8Hnxb4SGqQ0EqZW9C TcH13tp9gXC2YpUFH8BT7lFrUpgf+iMRthDP335K2BCqHq78WUv69fnNlZE3KnNHGKxj BMoISQyUsfoDhrXKvtSbYnKHNTWA7nIkk/qO6GCQhX1fyspdFDaaNrd/2qii64MISxo9 lMUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ivPMN3cR; spf=pass (google.com: domain of mptcp+bounces-1811-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) smtp.mailfrom="mptcp+bounces-1811-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sjc.edge.kernel.org (sjc.edge.kernel.org. [2604:1380:1000:8100::1]) by mx.google.com with ESMTPS id l1si689656vsj.297.2021.09.02.07.20.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Sep 2021 07:20:50 -0700 (PDT) Received-SPF: pass (google.com: domain of mptcp+bounces-1811-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) client-ip=2604:1380:1000:8100::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ivPMN3cR; spf=pass (google.com: domain of mptcp+bounces-1811-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) smtp.mailfrom="mptcp+bounces-1811-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sjc.edge.kernel.org (Postfix) with ESMTPS id 2D0973E0F33 for ; Thu, 2 Sep 2021 14:20:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 713B52FB3; Thu, 2 Sep 2021 14:20:48 +0000 (UTC) X-Original-To: mptcp@lists.linux.dev Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.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 56D4E29CA for ; Thu, 2 Sep 2021 14:20:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630592446; 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=5mDJU6NE9VaROPqiItmVTwgDB2WVu7JPOayM+M/8Tak=; b=ivPMN3cR5nMp6I5sl2LSSeVDLwzXwn2vL7LKLVs6oSXpIloXpime7++6KniCtIlrzfnz1Y e2CknR4jdSXGv8cWNk8vbUvrmtSsKVLCDxSqZaJSJyZ4y8URp2SCxpao0ObBE3mGjoi8sM AZuY7TrC105Wf7Br/mLe58cRgedajvQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-283-KMqgrBw1MNiwz8i9PTCxNw-1; Thu, 02 Sep 2021 10:20:45 -0400 X-MC-Unique: KMqgrBw1MNiwz8i9PTCxNw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 760D0DF8A3 for ; Thu, 2 Sep 2021 14:20:44 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.39.194.237]) by smtp.corp.redhat.com (Postfix) with ESMTP id E06C21042A40 for ; Thu, 2 Sep 2021 14:20:43 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next 1/4] tcp: expose the tcp_mark_push() and skb_entail() helpers Date: Thu, 2 Sep 2021 16:20:29 +0200 Message-Id: <1c29a0077ea95b4429a3dd82a4ea3ec826b3ae99.1630591985.git.pabeni@redhat.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pabeni@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" They will be used by the next patch. Signed-off-by: Paolo Abeni --- include/net/tcp.h | 2 ++ net/ipv4/tcp.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 3166dc15d7d6..dc52ea8adfc7 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -581,6 +581,8 @@ __u32 cookie_v6_init_sequence(const struct sk_buff *skb= , __u16 *mss); #endif /* tcp_output.c */ =20 +void skb_entail(struct sock *sk, struct sk_buff *skb); +void tcp_mark_push(struct tcp_sock *tp, struct sk_buff *skb); void __tcp_push_pending_frames(struct sock *sk, unsigned int cur_mss, int nonagle); int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs); diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index e8b48df73c85..7a3e632b0048 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -647,7 +647,7 @@ int tcp_ioctl(struct sock *sk, int cmd, unsigned long a= rg) } EXPORT_SYMBOL(tcp_ioctl); =20 -static inline void tcp_mark_push(struct tcp_sock *tp, struct sk_buff *skb) +void tcp_mark_push(struct tcp_sock *tp, struct sk_buff *skb) { TCP_SKB_CB(skb)->tcp_flags |=3D TCPHDR_PSH; tp->pushed_seq =3D tp->write_seq; @@ -658,7 +658,7 @@ static inline bool forced_push(const struct tcp_sock *t= p) return after(tp->write_seq, tp->pushed_seq + (tp->max_window >> 1)); } =20 -static void skb_entail(struct sock *sk, struct sk_buff *skb) +void skb_entail(struct sock *sk, struct sk_buff *skb) { struct tcp_sock *tp =3D tcp_sk(sk); struct tcp_skb_cb *tcb =3D TCP_SKB_CB(skb); --=20 2.26.3 From nobody Sat Apr 20 06:31:20 2024 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:a05:6638:d02:0:0:0:0 with SMTP id q2csp100018jaj; Thu, 2 Sep 2021 07:20:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCbKVJ1nfbLVJieJcil0ewv7W/xVj+FVHwioKhRcY0BsgTglfGzo+4p4S62q2sL25mqnix X-Received: by 2002:a05:6e02:b48:: with SMTP id f8mr2642719ilu.25.1630592452192; Thu, 02 Sep 2021 07:20:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630592452; cv=none; d=google.com; s=arc-20160816; b=KbfVtpJXDOxqhVi+h54+41slMs1gVZ1A0Llb15H4dnls2+FZQ6zX6E1bDYFCP2tqLd DGGIEDFJOQKVg0JVdfejtpliwtJ2/b8N+yjKCR2sgmK3q20DxyIv7XQWo9Nx5yqLz5g/ dGKNOnjsOVFDBTLEgrJ/CMRJbAuvDyr+rq3TuPdhYDmf+plKZf2xRj9kxA25oXXCmd9s SvYiPhlZSPKaD7b/kBwGAN4sOPFP/+CiaG+wul/3YOsMEi2dBiTox2he0VMejmUJOXxC gBNfGbTJiFyY1BTmgHjtl/9j2Sm+gFgHc4YPcld/i57+zFkTCAiuwAlJ/dyGoJ2sEYdi x5Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=L3zioryc0vCi647cm8LzE15jr6n7M4l98puvnid3800=; b=hpuC2H9X0YKBLwKMeoDCr+ITakV5WrvqF7cmTkHG+KXHpPukevs2Xc9+Thc86uEGjS GR1wAU4mIrLj6Xxyrx/BuxDWMzQTrA/n4+azsT+c9DRZBEYDRFwlR8SG85fYdn7VOKNM 1wSUGMBD8NguEy224hKpHBMWl9GYzPLKa6XumgmyDr5cFx2NFUpxw+oqZlLqdGwMY7cW UW8L1zRIRBOdcNTe9Kwa4mzoNlbQJhmQA0dj87T2W2U/7uvUzJI8V5GAeJCCxm5O/ktU 14iH8IDcQe0pAwMYnWOPItlL8MEzVBIxwJk9OtNXsMw7s9P0Al+JWXkI0StuSGZFLTTP AqfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=B8eTpLkI; spf=pass (google.com: domain of mptcp+bounces-1812-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1:3600::1 as permitted sender) smtp.mailfrom="mptcp+bounces-1812-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ewr.edge.kernel.org (ewr.edge.kernel.org. [2604:1380:1:3600::1]) by mx.google.com with ESMTPS id h12si1161881qtu.101.2021.09.02.07.20.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Sep 2021 07:20:52 -0700 (PDT) Received-SPF: pass (google.com: domain of mptcp+bounces-1812-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1:3600::1 as permitted sender) client-ip=2604:1380:1:3600::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=B8eTpLkI; spf=pass (google.com: domain of mptcp+bounces-1812-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1:3600::1 as permitted sender) smtp.mailfrom="mptcp+bounces-1812-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ewr.edge.kernel.org (Postfix) with ESMTPS id DE88C1C0A4A for ; Thu, 2 Sep 2021 14:20:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C14533FD3; Thu, 2 Sep 2021 14:20:49 +0000 (UTC) X-Original-To: mptcp@lists.linux.dev Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 710B72FB2 for ; Thu, 2 Sep 2021 14:20:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630592447; 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=L3zioryc0vCi647cm8LzE15jr6n7M4l98puvnid3800=; b=B8eTpLkIlEOFOL46wrueqTQeXpmgLoTAod8sUExYUUlbN/euTbMHbPpp2KtQT4cMtAXttm FDOfYNIOuh4UGGM2z3RuY1sGdGWSj7YElNc+SWYoyM8tokZ6FiukvNITLQxWxVnHvc11Ch eg79Jmm938n4Nzxn0CHUuA2KOLes8tY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-398-6Ykbc789N9C1mwhvmoKXWw-1; Thu, 02 Sep 2021 10:20:46 -0400 X-MC-Unique: 6Ykbc789N9C1mwhvmoKXWw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 612D084A5E1 for ; Thu, 2 Sep 2021 14:20:45 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.39.194.237]) by smtp.corp.redhat.com (Postfix) with ESMTP id CADB21042A40 for ; Thu, 2 Sep 2021 14:20:44 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next 2/4] mptcp: stop relaying on tcp_tx_skb_cache. Date: Thu, 2 Sep 2021 16:20:30 +0200 Message-Id: <77a77e43a30e0338a1b7a0c811b8e6451862eb02.1630591985.git.pabeni@redhat.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pabeni@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We want to revert the skb TX cache, but MPTCP is currently using it unconditionally. Rework the MPTCP tx code, so that tcp_tx_skb_cache is not needed anymore: do the whole coalescing check, skb allocation skb initialization/update inside mptcp_sendmsg_frag(), quite alike the current TCP code. Signed-off-by: Paolo Abeni --- net/mptcp/protocol.c | 131 +++++++++++++++++++++++++------------------ 1 file changed, 76 insertions(+), 55 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index faf6e7000d18..98fdb0ebd68d 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1224,6 +1224,7 @@ static struct sk_buff *__mptcp_do_alloc_tx_skb(struct= sock *sk, gfp_t gfp) if (likely(__mptcp_add_ext(skb, gfp))) { skb_reserve(skb, MAX_TCP_HEADER); skb->reserved_tailroom =3D skb->end - skb->tail; + INIT_LIST_HEAD(&skb->tcp_tsorted_anchor); return skb; } __kfree_skb(skb); @@ -1233,31 +1234,23 @@ static struct sk_buff *__mptcp_do_alloc_tx_skb(stru= ct sock *sk, gfp_t gfp) return NULL; } =20 -static bool __mptcp_alloc_tx_skb(struct sock *sk, struct sock *ssk, gfp_t = gfp) +static struct sk_buff *__mptcp_alloc_tx_skb(struct sock *sk, struct sock *= ssk, gfp_t gfp) { struct sk_buff *skb; =20 - if (ssk->sk_tx_skb_cache) { - skb =3D ssk->sk_tx_skb_cache; - if (unlikely(!skb_ext_find(skb, SKB_EXT_MPTCP) && - !__mptcp_add_ext(skb, gfp))) - return false; - return true; - } - skb =3D __mptcp_do_alloc_tx_skb(sk, gfp); if (!skb) - return false; + return NULL; =20 if (likely(sk_wmem_schedule(ssk, skb->truesize))) { - ssk->sk_tx_skb_cache =3D skb; - return true; + skb_entail(ssk, skb); + return skb; } kfree_skb(skb); - return false; + return NULL; } =20 -static bool mptcp_alloc_tx_skb(struct sock *sk, struct sock *ssk, bool dat= a_lock_held) +static struct sk_buff *mptcp_alloc_tx_skb(struct sock *sk, struct sock *ss= k, bool data_lock_held) { gfp_t gfp =3D data_lock_held ? GFP_ATOMIC : sk->sk_allocation; =20 @@ -1287,23 +1280,29 @@ static int mptcp_sendmsg_frag(struct sock *sk, stru= ct sock *ssk, struct mptcp_sendmsg_info *info) { u64 data_seq =3D dfrag->data_seq + info->sent; + int offset =3D dfrag->offset + info->sent; struct mptcp_sock *msk =3D mptcp_sk(sk); bool zero_window_probe =3D false; struct mptcp_ext *mpext =3D NULL; - struct sk_buff *skb, *tail; - bool must_collapse =3D false; - int size_bias =3D 0; - int avail_size; - size_t ret =3D 0; + bool can_coalesce =3D false; + bool reuse_skb =3D true; + struct sk_buff *skb; + size_t copy; + int i =3D 0; =20 pr_debug("msk=3D%p ssk=3D%p sending dfrag at seq=3D%llu len=3D%u already = sent=3D%u", msk, ssk, dfrag->data_seq, dfrag->data_len, info->sent); =20 + if (WARN_ON_ONCE(info->sent > info->limit || + info->limit > dfrag->data_len)) + return 0; + /* compute send limit */ info->mss_now =3D tcp_send_mss(ssk, &info->size_goal, info->flags); - avail_size =3D info->size_goal; + copy =3D info->size_goal; + skb =3D tcp_write_queue_tail(ssk); - if (skb) { + if (skb && (copy > skb->len)) { /* Limit the write to the size available in the * current skb, if any, so that we create at most a new skb. * Explicitly tells TCP internals to avoid collapsing on later @@ -1316,53 +1315,75 @@ static int mptcp_sendmsg_frag(struct sock *sk, stru= ct sock *ssk, goto alloc_skb; } =20 - must_collapse =3D (info->size_goal - skb->len > 0) && - (skb_shinfo(skb)->nr_frags < sysctl_max_skb_frags); - if (must_collapse) { - size_bias =3D skb->len; - avail_size =3D info->size_goal - skb->len; + i =3D skb_shinfo(skb)->nr_frags; + can_coalesce =3D skb_can_coalesce(skb, i, dfrag->page, offset); + if (!can_coalesce && i >=3D sysctl_max_skb_frags) { + tcp_mark_push(tcp_sk(ssk), skb); + goto alloc_skb; } - } =20 + copy -=3D skb->len; + } else { alloc_skb: - if (!must_collapse && !ssk->sk_tx_skb_cache && - !mptcp_alloc_tx_skb(sk, ssk, info->data_lock_held)) - return 0; + skb =3D mptcp_alloc_tx_skb(sk, ssk, info->data_lock_held); + if (!skb) + return -ENOMEM; + + reuse_skb =3D false; + mpext =3D skb_ext_find(skb, SKB_EXT_MPTCP); + } =20 /* Zero window and all data acked? Probe. */ - avail_size =3D mptcp_check_allowed_size(msk, data_seq, avail_size); - if (avail_size =3D=3D 0) { + copy =3D mptcp_check_allowed_size(msk, data_seq, copy); + if (copy =3D=3D 0) { u64 snd_una =3D READ_ONCE(msk->snd_una); =20 - if (skb || snd_una !=3D msk->snd_nxt) + if (skb || snd_una !=3D msk->snd_nxt) { + tcp_remove_empty_skb(ssk, tcp_write_queue_tail(ssk)); return 0; + } + zero_window_probe =3D true; data_seq =3D snd_una - 1; - avail_size =3D 1; - } + copy =3D 1; =20 - if (WARN_ON_ONCE(info->sent > info->limit || - info->limit > dfrag->data_len)) - return 0; + /* all mptcp-level data is acked, no skbs should be present into the + * ssk write queue + */ + WARN_ON_ONCE(reuse_skb); + } =20 - ret =3D info->limit - info->sent; - tail =3D tcp_build_frag(ssk, avail_size + size_bias, info->flags, - dfrag->page, dfrag->offset + info->sent, &ret); - if (!tail) { - tcp_remove_empty_skb(sk, tcp_write_queue_tail(ssk)); + copy =3D min_t(size_t, copy, info->limit - info->sent); + if (!sk_wmem_schedule(ssk, copy)) { + tcp_remove_empty_skb(ssk, tcp_write_queue_tail(ssk)); return -ENOMEM; } =20 - /* if the tail skb is still the cached one, collapsing really happened. - */ - if (skb =3D=3D tail) { - TCP_SKB_CB(tail)->tcp_flags &=3D ~TCPHDR_PSH; - mpext->data_len +=3D ret; + if (can_coalesce) { + skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy); + } else { + get_page(dfrag->page); + skb_fill_page_desc(skb, i, dfrag->page, offset, copy); + } + + skb->len +=3D copy; + skb->data_len +=3D copy; + skb->truesize +=3D copy; + sk_wmem_queued_add(ssk, copy); + sk_mem_charge(ssk, copy); + skb->ip_summed =3D CHECKSUM_PARTIAL; + WRITE_ONCE(tcp_sk(ssk)->write_seq, tcp_sk(ssk)->write_seq + copy); + TCP_SKB_CB(skb)->end_seq +=3D copy; + tcp_skb_pcount_set(skb, 0); + + /* on skb reuse we just need to update the DSS len */ + if (reuse_skb) { + TCP_SKB_CB(skb)->tcp_flags &=3D ~TCPHDR_PSH; + mpext->data_len +=3D copy; WARN_ON_ONCE(zero_window_probe); goto out; } =20 - mpext =3D skb_ext_find(tail, SKB_EXT_MPTCP); if (WARN_ON_ONCE(!mpext)) { /* should never reach here, stream corrupted */ return -EINVAL; @@ -1371,7 +1392,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct= sock *ssk, memset(mpext, 0, sizeof(*mpext)); mpext->data_seq =3D data_seq; mpext->subflow_seq =3D mptcp_subflow_ctx(ssk)->rel_write_seq; - mpext->data_len =3D ret; + mpext->data_len =3D copy; mpext->use_map =3D 1; mpext->dsn64 =3D 1; =20 @@ -1380,18 +1401,18 @@ static int mptcp_sendmsg_frag(struct sock *sk, stru= ct sock *ssk, mpext->dsn64); =20 if (zero_window_probe) { - mptcp_subflow_ctx(ssk)->rel_write_seq +=3D ret; + mptcp_subflow_ctx(ssk)->rel_write_seq +=3D copy; mpext->frozen =3D 1; if (READ_ONCE(msk->csum_enabled)) - mptcp_update_data_checksum(tail, ret); + mptcp_update_data_checksum(skb, copy); tcp_push_pending_frames(ssk); return 0; } out: if (READ_ONCE(msk->csum_enabled)) - mptcp_update_data_checksum(tail, ret); - mptcp_subflow_ctx(ssk)->rel_write_seq +=3D ret; - return ret; + mptcp_update_data_checksum(skb, copy); + mptcp_subflow_ctx(ssk)->rel_write_seq +=3D copy; + return copy; } =20 #define MPTCP_SEND_BURST_SIZE ((1 << 16) - \ --=20 2.26.3 From nobody Sat Apr 20 06:31:20 2024 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:a05:6638:d02:0:0:0:0 with SMTP id q2csp100045jaj; Thu, 2 Sep 2021 07:20:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznw/fFEeekfYdT1c6f085DZeehclI54UF5AaF+inic7nMO2juEE1sTS7a+vWA5HW3GJIzn X-Received: by 2002:aa7:80d1:0:b029:399:ce3a:d617 with SMTP id a17-20020aa780d10000b0290399ce3ad617mr3725635pfn.16.1630592453392; Thu, 02 Sep 2021 07:20:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630592453; cv=none; d=google.com; s=arc-20160816; b=tGAt5BZUMDuQk6jECmpJsLL7H/jqdxKWoqoLjsscoZ3ShpaQrFgxbvK+bjQZ87kvJT UGQB1LGwbG/QWbGUdKtIOtss4Dd1YgONiSSJ1+dAzeYwEc72KgzfmnQoLZ674u7UWjQo 2OD7PK2waxMRMkCcV8FM3t+24FBEoT5FAnHPBAMSay6j2w/O3tQpceGdxRz7Hf9qMqf/ XPuzTW62glcqsyZKjA5QfurYvQfIlZv7OHkF5+TYRBkFDHQtd3L97s62mi6gC2ERdiEI Pe0bAhyRF+DvqFLA1ijWJkqjOfX90Tj+wlvRtp3QL+g3j2LwXWN5Is7FrhZ1qtDookX9 CSpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=Lvgijn04rkBbFuXU24CIyP2H68wXwzmEnNA1gqXKzi8=; b=fKBejjpuFXsU087zfV0auMSIyrk54hUVAdjNhUMgUPxkRGE4VJbmHPsPCaHOD3fQFP hX/54+XL/S5A7zSe2sU5V8WQtRg77FIgAME2ruEPUzobEnfJglpbqzf5zjCFUaTWhF10 DZazIY0gEHY7I3uS2tTwr5OXcUw1pnuqwIGo/rgzmsX850K6aGGX3wyylLHS1XfirYI2 gIxfgCQi29/TsO1kM8GQGrEest46XD2RIL1pwQcadwliZEOBZgnz+5JEXJ4Ds+UzkdxZ OWBbPkEZa9pjSux6JmuRWiVl3W9lsLXAU9skX3tW7fUvccN6Wu3VoozF6ClPmGQTAb+a ysAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DJVq4Cpd; spf=pass (google.com: domain of mptcp+bounces-1813-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) smtp.mailfrom="mptcp+bounces-1813-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sjc.edge.kernel.org (sjc.edge.kernel.org. [2604:1380:1000:8100::1]) by mx.google.com with ESMTPS id 35si2447687pgp.515.2021.09.02.07.20.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Sep 2021 07:20:53 -0700 (PDT) Received-SPF: pass (google.com: domain of mptcp+bounces-1813-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) client-ip=2604:1380:1000:8100::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DJVq4Cpd; spf=pass (google.com: domain of mptcp+bounces-1813-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) smtp.mailfrom="mptcp+bounces-1813-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sjc.edge.kernel.org (Postfix) with ESMTPS id B2CCA3E0F63 for ; Thu, 2 Sep 2021 14:20:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 075823FD5; Thu, 2 Sep 2021 14:20:50 +0000 (UTC) X-Original-To: mptcp@lists.linux.dev Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F30902FB6 for ; Thu, 2 Sep 2021 14:20:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630592448; 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=Lvgijn04rkBbFuXU24CIyP2H68wXwzmEnNA1gqXKzi8=; b=DJVq4CpdgDQStDBmvZgjIDwpjFd5VUzU6kVwiFrNf/QYZ9k4GTvY/yrH7Q98pkYbwZQGxH IMGCFOmEpY2iZR0Hzb5s4dmo/KZZg7miqK4NUGg0Pku4PS/EiMgGaWDFAT2CFjx2O2uL3r 2btEY1rRZrroAVtge/9YUSL0DkyfD7Y= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-124-rHrimlZaOMGdUTg2p4QnyQ-1; Thu, 02 Sep 2021 10:20:47 -0400 X-MC-Unique: rHrimlZaOMGdUTg2p4QnyQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 49B18107ACE3 for ; Thu, 2 Sep 2021 14:20:46 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.39.194.237]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5CCA1042A40 for ; Thu, 2 Sep 2021 14:20:45 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next 3/4] Partially revert "tcp: factor out tcp_build_frag()" Date: Thu, 2 Sep 2021 16:20:31 +0200 Message-Id: <7c32ec5b55da2d18b2461549ce0c0b5d4b8d0d93.1630591985.git.pabeni@redhat.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pabeni@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is a partial revert for commit b796d04bd014 ("tcp: factor out tcp_build_frag()"). MPTCP was the only user of the tcp_build_frag helper, and after the previous patch MPTCP does not use the mentioned helper anymore. Let's avoid exposing TCP internals. The revert is partial, as tcp_remove_empty_skb(), exposed by the same commit is still required. Signed-off-by: Paolo Abeni --- include/net/tcp.h | 2 - net/ipv4/tcp.c | 117 ++++++++++++++++++++-------------------------- 2 files changed, 51 insertions(+), 68 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index dc52ea8adfc7..91f4397c4c08 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -330,8 +330,6 @@ int tcp_sendpage(struct sock *sk, struct page *page, in= t offset, size_t size, int flags); int tcp_sendpage_locked(struct sock *sk, struct page *page, int offset, size_t size, int flags); -struct sk_buff *tcp_build_frag(struct sock *sk, int size_goal, int flags, - struct page *page, int offset, size_t *size); ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset, size_t size, int flags); int tcp_send_mss(struct sock *sk, int *size_goal, int flags); diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 7a3e632b0048..caf0c50d86bc 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -963,68 +963,6 @@ void tcp_remove_empty_skb(struct sock *sk, struct sk_b= uff *skb) } } =20 -struct sk_buff *tcp_build_frag(struct sock *sk, int size_goal, int flags, - struct page *page, int offset, size_t *size) -{ - struct sk_buff *skb =3D tcp_write_queue_tail(sk); - struct tcp_sock *tp =3D tcp_sk(sk); - bool can_coalesce; - int copy, i; - - if (!skb || (copy =3D size_goal - skb->len) <=3D 0 || - !tcp_skb_can_collapse_to(skb)) { -new_segment: - if (!sk_stream_memory_free(sk)) - return NULL; - - skb =3D sk_stream_alloc_skb(sk, 0, sk->sk_allocation, - tcp_rtx_and_write_queues_empty(sk)); - if (!skb) - return NULL; - -#ifdef CONFIG_TLS_DEVICE - skb->decrypted =3D !!(flags & MSG_SENDPAGE_DECRYPTED); -#endif - skb_entail(sk, skb); - copy =3D size_goal; - } - - if (copy > *size) - copy =3D *size; - - i =3D skb_shinfo(skb)->nr_frags; - can_coalesce =3D skb_can_coalesce(skb, i, page, offset); - if (!can_coalesce && i >=3D sysctl_max_skb_frags) { - tcp_mark_push(tp, skb); - goto new_segment; - } - if (!sk_wmem_schedule(sk, copy)) - return NULL; - - if (can_coalesce) { - skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy); - } else { - get_page(page); - skb_fill_page_desc(skb, i, page, offset, copy); - } - - if (!(flags & MSG_NO_SHARED_FRAGS)) - skb_shinfo(skb)->flags |=3D SKBFL_SHARED_FRAG; - - skb->len +=3D copy; - skb->data_len +=3D copy; - skb->truesize +=3D copy; - sk_wmem_queued_add(sk, copy); - sk_mem_charge(sk, copy); - skb->ip_summed =3D CHECKSUM_PARTIAL; - WRITE_ONCE(tp->write_seq, tp->write_seq + copy); - TCP_SKB_CB(skb)->end_seq +=3D copy; - tcp_skb_pcount_set(skb, 0); - - *size =3D copy; - return skb; -} - ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset, size_t size, int flags) { @@ -1060,13 +998,60 @@ ssize_t do_tcp_sendpages(struct sock *sk, struct pag= e *page, int offset, goto out_err; =20 while (size > 0) { - struct sk_buff *skb; - size_t copy =3D size; + struct sk_buff *skb =3D tcp_write_queue_tail(sk); + int copy, i; + bool can_coalesce; =20 - skb =3D tcp_build_frag(sk, size_goal, flags, page, offset, ©); - if (!skb) + if (!skb || (copy =3D size_goal - skb->len) <=3D 0 || + !tcp_skb_can_collapse_to(skb)) { +new_segment: + if (!sk_stream_memory_free(sk)) + goto wait_for_space; + + skb =3D sk_stream_alloc_skb(sk, 0, sk->sk_allocation, + tcp_rtx_and_write_queues_empty(sk)); + if (!skb) + goto wait_for_space; + +#ifdef CONFIG_TLS_DEVICE + skb->decrypted =3D !!(flags & MSG_SENDPAGE_DECRYPTED); +#endif + skb_entail(sk, skb); + copy =3D size_goal; + } + + if (copy > size) + copy =3D size; + + i =3D skb_shinfo(skb)->nr_frags; + can_coalesce =3D skb_can_coalesce(skb, i, page, offset); + if (!can_coalesce && i >=3D sysctl_max_skb_frags) { + tcp_mark_push(tp, skb); + goto new_segment; + } + if (!sk_wmem_schedule(sk, copy)) goto wait_for_space; =20 + if (can_coalesce) { + skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy); + } else { + get_page(page); + skb_fill_page_desc(skb, i, page, offset, copy); + } + + if (!(flags & MSG_NO_SHARED_FRAGS)) + skb_shinfo(skb)->flags |=3D SKBFL_SHARED_FRAG; + + skb->len +=3D copy; + skb->data_len +=3D copy; + skb->truesize +=3D copy; + sk_wmem_queued_add(sk, copy); + sk_mem_charge(sk, copy); + skb->ip_summed =3D CHECKSUM_PARTIAL; + WRITE_ONCE(tp->write_seq, tp->write_seq + copy); + TCP_SKB_CB(skb)->end_seq +=3D copy; + tcp_skb_pcount_set(skb, 0); + if (!copied) TCP_SKB_CB(skb)->tcp_flags &=3D ~TCPHDR_PSH; =20 --=20 2.26.3 From nobody Sat Apr 20 06:31:20 2024 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:a05:6638:d02:0:0:0:0 with SMTP id q2csp100886jaj; Thu, 2 Sep 2021 07:21:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTDbNrOKcsKE6+DiQHfbVxelXDInuDlsbxtJrVbxN9s4AN8R01ap/eJhJ+stZnlb9nAzoB X-Received: by 2002:a9f:3e4c:: with SMTP id c12mr1933765uaj.75.1630592509533; Thu, 02 Sep 2021 07:21:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630592509; cv=none; d=google.com; s=arc-20160816; b=eMLeM3/MkpF5ctyLUd9l1fZ3Hwa6UAaTITPimI5npa8Sfi0UXqGlu20FLblAlVZssd SCLHwozTdSroFsvqpn9jgR6/TjSmz2jptCirJkUV1HWq2QXenney5bQPbcppjC3ooVqo E780Kl1Kw6pZ99bQwwnmFef0KxSDJJsfyK8IkSCGW1MeaCSFTGJNR+q3rP6G+wMW8xF2 pmE8E9jWvuH/UrES0iV6mF+72kyjPC6zO2j5U6BPi6HSs06tBHOLymBpDv5sjHur16VJ s0KwZdTJwKZIyTC7xC/w7x9jOepOTixv85StcTDkJVl85Jj575+pFeGIklb98vS7bXQ5 bRvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=0sXuSGNUZPcTS2HU99UWlUvle8o+zTUPolerURfGs60=; b=RixvjaNGgf1GJ8sQSQd6uRMwusLvXF9IzcbNoOyKZJhBFKTfWL0k2PNjXAIGu0ZIua i+5Lm87rhHYkQMd+EpRzORDuY+cc2XV5UZGorIns6Wdsk/ztZDrFBc28R1c0PmqlQrn3 6fpthcDTigj+4+iI4NOvwOZXEJhrVMgWuZ+IHE/LsLUYVlNM+plujxbFIprMrk1cQQnz HDUHmZVa61PSOz1/K6Mo4EsVHyKJWVCWvYfzXNKmhc+0LGUYuw0C4MHLJUQ8mLSe+2dT L8u95Ej5gcgm6M3uKkjy8hNOB5uN+Iaoelz0bOMbhALiPMjsVvU2kSRLMY0Qf1I+/r3d X4bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d3U8y5w6; spf=pass (google.com: domain of mptcp+bounces-1814-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) smtp.mailfrom="mptcp+bounces-1814-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sjc.edge.kernel.org (sjc.edge.kernel.org. [2604:1380:1000:8100::1]) by mx.google.com with ESMTPS id k7si687923uad.52.2021.09.02.07.21.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Sep 2021 07:21:49 -0700 (PDT) Received-SPF: pass (google.com: domain of mptcp+bounces-1814-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) client-ip=2604:1380:1000:8100::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d3U8y5w6; spf=pass (google.com: domain of mptcp+bounces-1814-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) smtp.mailfrom="mptcp+bounces-1814-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sjc.edge.kernel.org (Postfix) with ESMTPS id 9E0833E0E38 for ; Thu, 2 Sep 2021 14:21:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6F6813FD5; Thu, 2 Sep 2021 14:21:47 +0000 (UTC) X-Original-To: mptcp@lists.linux.dev Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.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 295E93FD3 for ; Thu, 2 Sep 2021 14:21:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630592502; 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=0sXuSGNUZPcTS2HU99UWlUvle8o+zTUPolerURfGs60=; b=d3U8y5w6gkz2QHRJ5+vvttrl0TSz8i6xiSZuD5FxBgboGVp7l1wnoQ9Rzap+3GG74b4ruK 0EpRq5NuWMJbuWGmLWZhTeR2tVm9rKkk1u+9lEs6Y+k4eIDtlp1okMf57etjz/7MkaWem7 GuE41tQ/Po9g1BDC8UcGWfN9zMwUpYk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-447-j28Li_q0PwG8ltVVQz9uvA-1; Thu, 02 Sep 2021 10:21:32 -0400 X-MC-Unique: j28Li_q0PwG8ltVVQz9uvA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 30DCBDF8AE for ; Thu, 2 Sep 2021 14:20:47 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.39.194.237]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E6661042A40 for ; Thu, 2 Sep 2021 14:20:46 +0000 (UTC) From: Paolo Abeni To: mptcp@lists.linux.dev Subject: [PATCH mptcp-next 4/4] tcp: remove sk_{tr}x_skb_cache Date: Thu, 2 Sep 2021 16:20:32 +0200 Message-Id: <481fab3d20248bb78d959c8e9445c091c1c14e6b.1630591985.git.pabeni@redhat.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pabeni@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Eric Dumazet This reverts the following patches : 2e05fcae83c41eb2df10558338dc600dc783af47 ("tcp: fix compile error if !CONFI= G_SYSCTL") 4f661542a40217713f2cee0bb6678fbb30d9d367 ("tcp: fix zerocopy and notsent_lo= wat issues") 472c2e07eef045145bc1493cc94a01c87140780a ("tcp: add one skb cache for tx") 8b27dae5a2e89a61c46c6dbc76c040c0e6d0ed4c ("tcp: add one skb cache for rx") Having a cache of one skb (in each direction) per TCP socket is fragile, since it can cause a significant increase of memory needs, and not good enough for high speed flows anyway where more than one skb is needed. We want instead to add a generic infrastructure, with more flexible per-cpu caches, for alien NUMA nodes. Signed-off-by: Eric Dumazet --- Documentation/networking/ip-sysctl.rst | 8 -------- include/net/sock.h | 19 ------------------- net/ipv4/af_inet.c | 4 ---- net/ipv4/sysctl_net_ipv4.c | 12 ------------ net/ipv4/tcp.c | 26 -------------------------- net/ipv4/tcp_ipv4.c | 6 ------ net/ipv6/tcp_ipv6.c | 6 ------ 7 files changed, 81 deletions(-) diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/network= ing/ip-sysctl.rst index d91ab28718d4..16b8bf72feaf 100644 --- a/Documentation/networking/ip-sysctl.rst +++ b/Documentation/networking/ip-sysctl.rst @@ -989,14 +989,6 @@ tcp_challenge_ack_limit - INTEGER in RFC 5961 (Improving TCP's Robustness to Blind In-Window Attacks) Default: 1000 =20 -tcp_rx_skb_cache - BOOLEAN - Controls a per TCP socket cache of one skb, that might help - performance of some workloads. This might be dangerous - on systems with a lot of TCP sockets, since it increases - memory usage. - - Default: 0 (disabled) - UDP variables =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/include/net/sock.h b/include/net/sock.h index 66a9a90f9558..708b9de3cdbb 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -262,7 +262,6 @@ struct bpf_local_storage; * @sk_dst_cache: destination cache * @sk_dst_pending_confirm: need to confirm neighbour * @sk_policy: flow policy - * @sk_rx_skb_cache: cache copy of recently accessed RX skb * @sk_receive_queue: incoming packets * @sk_wmem_alloc: transmit queue bytes committed * @sk_tsq_flags: TCP Small Queues flags @@ -328,7 +327,6 @@ struct bpf_local_storage; * @sk_peek_off: current peek_offset value * @sk_send_head: front of stuff to transmit * @tcp_rtx_queue: TCP re-transmit queue [union with @sk_send_head] - * @sk_tx_skb_cache: cache copy of recently accessed TX skb * @sk_security: used by security modules * @sk_mark: generic packet mark * @sk_cgrp_data: cgroup data for this cgroup @@ -393,7 +391,6 @@ struct sock { atomic_t sk_drops; int sk_rcvlowat; struct sk_buff_head sk_error_queue; - struct sk_buff *sk_rx_skb_cache; struct sk_buff_head sk_receive_queue; /* * The backlog queue is special, it is always used with @@ -442,7 +439,6 @@ struct sock { struct sk_buff *sk_send_head; struct rb_root tcp_rtx_queue; }; - struct sk_buff *sk_tx_skb_cache; struct sk_buff_head sk_write_queue; __s32 sk_peek_off; int sk_write_pending; @@ -1555,18 +1551,10 @@ static inline void sk_mem_uncharge(struct sock *sk,= int size) __sk_mem_reclaim(sk, 1 << 20); } =20 -DECLARE_STATIC_KEY_FALSE(tcp_tx_skb_cache_key); static inline void sk_wmem_free_skb(struct sock *sk, struct sk_buff *skb) { sk_wmem_queued_add(sk, -skb->truesize); sk_mem_uncharge(sk, skb->truesize); - if (static_branch_unlikely(&tcp_tx_skb_cache_key) && - !sk->sk_tx_skb_cache && !skb_cloned(skb)) { - skb_ext_reset(skb); - skb_zcopy_clear(skb, true); - sk->sk_tx_skb_cache =3D skb; - return; - } __kfree_skb(skb); } =20 @@ -2575,7 +2563,6 @@ static inline void skb_setup_tx_timestamp(struct sk_b= uff *skb, __u16 tsflags) &skb_shinfo(skb)->tskey); } =20 -DECLARE_STATIC_KEY_FALSE(tcp_rx_skb_cache_key); /** * sk_eat_skb - Release a skb if it is no longer needed * @sk: socket to eat this skb from @@ -2587,12 +2574,6 @@ DECLARE_STATIC_KEY_FALSE(tcp_rx_skb_cache_key); static inline void sk_eat_skb(struct sock *sk, struct sk_buff *skb) { __skb_unlink(skb, &sk->sk_receive_queue); - if (static_branch_unlikely(&tcp_rx_skb_cache_key) && - !sk->sk_rx_skb_cache) { - sk->sk_rx_skb_cache =3D skb; - skb_orphan(skb); - return; - } __kfree_skb(skb); } =20 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 9dc7613e589d..63eda8cb0d26 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -133,10 +133,6 @@ void inet_sock_destruct(struct sock *sk) struct inet_sock *inet =3D inet_sk(sk); =20 __skb_queue_purge(&sk->sk_receive_queue); - if (sk->sk_rx_skb_cache) { - __kfree_skb(sk->sk_rx_skb_cache); - sk->sk_rx_skb_cache =3D NULL; - } __skb_queue_purge(&sk->sk_error_queue); =20 sk_mem_reclaim(sk); diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index 6f1e64d49232..6eb43dc91218 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -594,18 +594,6 @@ static struct ctl_table ipv4_table[] =3D { .extra1 =3D &sysctl_fib_sync_mem_min, .extra2 =3D &sysctl_fib_sync_mem_max, }, - { - .procname =3D "tcp_rx_skb_cache", - .data =3D &tcp_rx_skb_cache_key.key, - .mode =3D 0644, - .proc_handler =3D proc_do_static_key, - }, - { - .procname =3D "tcp_tx_skb_cache", - .data =3D &tcp_tx_skb_cache_key.key, - .mode =3D 0644, - .proc_handler =3D proc_do_static_key, - }, { } }; =20 diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index caf0c50d86bc..cbb0f807be46 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -325,11 +325,6 @@ struct tcp_splice_state { unsigned long tcp_memory_pressure __read_mostly; EXPORT_SYMBOL_GPL(tcp_memory_pressure); =20 -DEFINE_STATIC_KEY_FALSE(tcp_rx_skb_cache_key); -EXPORT_SYMBOL(tcp_rx_skb_cache_key); - -DEFINE_STATIC_KEY_FALSE(tcp_tx_skb_cache_key); - void tcp_enter_memory_pressure(struct sock *sk) { unsigned long val; @@ -866,18 +861,6 @@ struct sk_buff *sk_stream_alloc_skb(struct sock *sk, i= nt size, gfp_t gfp, { struct sk_buff *skb; =20 - if (likely(!size)) { - skb =3D sk->sk_tx_skb_cache; - if (skb) { - skb->truesize =3D SKB_TRUESIZE(skb_end_offset(skb)); - sk->sk_tx_skb_cache =3D NULL; - pskb_trim(skb, 0); - INIT_LIST_HEAD(&skb->tcp_tsorted_anchor); - skb_shinfo(skb)->tx_flags =3D 0; - memset(TCP_SKB_CB(skb), 0, sizeof(struct tcp_skb_cb)); - return skb; - } - } /* The TCP header must be at least 32-bit aligned. */ size =3D ALIGN(size, 4); =20 @@ -2905,11 +2888,6 @@ void tcp_write_queue_purge(struct sock *sk) sk_wmem_free_skb(sk, skb); } tcp_rtx_queue_purge(sk); - skb =3D sk->sk_tx_skb_cache; - if (skb) { - __kfree_skb(skb); - sk->sk_tx_skb_cache =3D NULL; - } INIT_LIST_HEAD(&tcp_sk(sk)->tsorted_sent_queue); sk_mem_reclaim(sk); tcp_clear_all_retrans_hints(tcp_sk(sk)); @@ -2946,10 +2924,6 @@ int tcp_disconnect(struct sock *sk, int flags) =20 tcp_clear_xmit_timers(sk); __skb_queue_purge(&sk->sk_receive_queue); - if (sk->sk_rx_skb_cache) { - __kfree_skb(sk->sk_rx_skb_cache); - sk->sk_rx_skb_cache =3D NULL; - } WRITE_ONCE(tp->copied_seq, tp->rcv_nxt); tp->urg_data =3D 0; tcp_write_queue_purge(sk); diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 2e62e0d6373a..29a57bd159f0 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1941,7 +1941,6 @@ static void tcp_v4_fill_cb(struct sk_buff *skb, const= struct iphdr *iph, int tcp_v4_rcv(struct sk_buff *skb) { struct net *net =3D dev_net(skb->dev); - struct sk_buff *skb_to_free; int sdif =3D inet_sdif(skb); int dif =3D inet_iif(skb); const struct iphdr *iph; @@ -2082,17 +2081,12 @@ int tcp_v4_rcv(struct sk_buff *skb) tcp_segs_in(tcp_sk(sk), skb); ret =3D 0; if (!sock_owned_by_user(sk)) { - skb_to_free =3D sk->sk_rx_skb_cache; - sk->sk_rx_skb_cache =3D NULL; ret =3D tcp_v4_do_rcv(sk, skb); } else { if (tcp_add_backlog(sk, skb)) goto discard_and_relse; - skb_to_free =3D NULL; } bh_unlock_sock(sk); - if (skb_to_free) - __kfree_skb(skb_to_free); =20 put_and_return: if (refcounted) diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 0ce52d46e4f8..8cf5ff2e9504 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1618,7 +1618,6 @@ static void tcp_v6_fill_cb(struct sk_buff *skb, const= struct ipv6hdr *hdr, =20 INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) { - struct sk_buff *skb_to_free; int sdif =3D inet6_sdif(skb); int dif =3D inet6_iif(skb); const struct tcphdr *th; @@ -1754,17 +1753,12 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_bu= ff *skb) tcp_segs_in(tcp_sk(sk), skb); ret =3D 0; if (!sock_owned_by_user(sk)) { - skb_to_free =3D sk->sk_rx_skb_cache; - sk->sk_rx_skb_cache =3D NULL; ret =3D tcp_v6_do_rcv(sk, skb); } else { if (tcp_add_backlog(sk, skb)) goto discard_and_relse; - skb_to_free =3D NULL; } bh_unlock_sock(sk); - if (skb_to_free) - __kfree_skb(skb_to_free); put_and_return: if (refcounted) sock_put(sk); --=20 2.26.3