From: sashiko-bot@kernel.org
To: "Kuniyuki Iwashima" <kuniyu@google.com>
Cc: mptcp@lists.linux.dev
Subject: Re: [PATCH v2 net-next 4/7] tcp: Skip collapsing if collapsed skb is less-dense.
Date: Tue, 17 Nov 2026 23:06:08 +0000 [thread overview]
Message-ID: <sashiko-outbox-219780@kernel.org> (raw)
In-Reply-To: <20261116230555.2305867-5-kuniyu@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] tcp: rbtree order corruption in tcp_collapse() on skipped
overlapping skb
- [Low] net: skbuff: duplicate kmalloc_size_roundup() call in
kmalloc_reserve()
--
commit a3eb35002975ecc31de00e85abdd6d7c9480540e
Author: Kuniyuki Iwashima <kuniyu@google.com>
tcp: Skip collapsing if collapsed skb is less-dense.
This commit introduces compute_skb_truesize() and uses it in tcp_collapse()
to skip collapsing a range of SKBs when the resulting truesize would not
decrease.
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index 2e81aacc998b6..a89eaadc729f4 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -589,6 +589,17 @@ struct sk_buff *napi_build_skb(void *data, unsigned int frag_size)
> }
> EXPORT_SYMBOL(napi_build_skb);
>
> +static __always_inline size_t kmalloc_reserve_size(unsigned int size, gfp_t flags)
> +{
> + size_t obj_size = SKB_HEAD_ALIGN(size);
> +
> + if (obj_size <= SKB_SMALL_HEAD_CACHE_SIZE &&
> + !(flags & KMALLOC_NOT_NORMAL_BITS))
> + return 0;
> +
> + return kmalloc_size_roundup(obj_size);
> +}
> +
> static void *kmalloc_pfmemalloc(size_t obj_size, gfp_t flags, int node)
> {
> if (!gfp_pfmemalloc_allowed(flags))
> @@ -612,9 +623,8 @@ static void *kmalloc_reserve(unsigned int *size, gfp_t flags, int node,
> size_t obj_size;
> void *obj;
>
> - obj_size = SKB_HEAD_ALIGN(*size);
> - if (obj_size <= SKB_SMALL_HEAD_CACHE_SIZE &&
> - !(flags & KMALLOC_NOT_NORMAL_BITS)) {
> + obj_size = kmalloc_reserve_size(*size, flags);
> + if (!obj_size) {
> obj = kmem_cache_alloc_node(net_hotdata.skb_small_head_cache,
> flags | __GFP_NOMEMALLOC | __GFP_NOWARN,
> node);
[Severity: Low]
Does kmalloc_reserve() now call kmalloc_size_roundup() twice for allocations
that do not use skb_small_head_cache?
kmalloc_reserve_size() already returns kmalloc_size_roundup(obj_size), but
kmalloc_reserve() still calls kmalloc_size_roundup(obj_size) again right
after the if (!obj_size) block. Since kmalloc_size_roundup() is an
out-of-line function in mm/slab_common.c without const or pure attributes,
non-small SKB allocations make a redundant call on the hotpath.
[ ... ]
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index 5bd42a74c6f58..0815e1891fba0 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
[ ... ]
> @@ -5908,6 +5913,23 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,
> break;
>
> sub_end = TCP_SKB_CB(n)->end_seq;
> + old_truesize += n->truesize;
> + }
> +
> + /* Third, check if the new skbs have high density. */
> + nskbs = (sub_end - start) / TCP_COLLAPSE_MAX_SIZE;
> + new_truesize = nskbs * SKB_TRUESIZE(TCP_COLLAPSE_MAX_SIZE);
> +
> + remainder = (sub_end - start) % TCP_COLLAPSE_MAX_SIZE;
> + if (remainder) {
> + nskbs++;
> + new_truesize += compute_skb_truesize(remainder, GFP_ATOMIC);
> + }
> +
> + if (old_truesize <= new_truesize) {
> + start = sub_end;
> + skb = n;
> + goto restart;
> }
[Severity: Medium]
Can skipping a sub-range on the out-of-order rbtree (list == NULL) break the
monotonic seq and end_seq ordering of tp->out_of_order_queue when skb
partially overlaps the previously collapsed range?
Suppose tp->out_of_order_queue holds skb_1 [1000, 5000] (truesize 8448) and
an overlapping skb_2 [4500, 5100] (truesize 896 from skbuff_small_head) where
!tcp_skb_can_collapse_rx(skb_1, skb_2) is true (for example, due to differing
MPTCP DSS extensions or decrypted state). The first pass collapses skb_1 into
nskb_1 [1000, 4776] and nskb_2 [4776, 5000] on the deferred tmp queue, erases
skb_1 from root, and advances start to 5000 and skb to skb_2.
On the next pass at restart, the unread 100 bytes of skb_2 [4500, 5100] are
bloated, but compute_skb_truesize(100, GFP_ATOMIC) is 896, so
old_truesize <= new_truesize holds and skb_2 is left in root with seq 4500
and end_seq 5100. At the end label, tcp_rbtree_insert() orders by seq and
inserts nskb_2 [4776, 5000] to the right of skb_2 [4500, 5100]:
net/ipv4/tcp_input.c:tcp_collapse() {
...
end:
skb_queue_walk_safe(&tmp, skb, n)
tcp_rbtree_insert(root, skb);
}
tcp_collapse_ofo_queue() then sets tp->ooo_last_skb = skb_rb_last() to nskb_2
(end_seq 5000) instead of skb_2 (end_seq 5100), causing later
tcp_data_queue_ofo() fastpath checks to misbehave and tcp_ofo_queue() to drop
nskb_2 as out-of-order after skb_2 advances tp->rcv_nxt to 5100.
Checking (list || !before(TCP_SKB_CB(skb)->seq, start)) before taking the
old_truesize <= new_truesize skip path would ensure overlapping OOO SKBs are
still trimmed and re-keyed at start.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116230555.2305867-1-kuniyu@google.com?part=4
next prev parent reply other threads:[~2026-11-17 23:06 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 23:05 [PATCH v2 net-next 0/7] tcp: Prevent tcp_collapse() from bloating queue Kuniyuki Iwashima
2026-11-16 23:05 ` [PATCH v2 net-next 1/7] tcp: Refactor the first loop in tcp_collapse() Kuniyuki Iwashima
2026-11-16 23:05 ` [PATCH v2 net-next 2/7] tcp: Don't collapse high density skb Kuniyuki Iwashima
2026-11-17 23:13 ` netdev-bot+sashiko
2026-11-16 23:05 ` [PATCH v2 net-next 3/7] tcp: Stop collapsing if not bloated Kuniyuki Iwashima
2026-11-17 23:13 ` netdev-bot+sashiko
2026-11-16 23:05 ` [PATCH v2 net-next 4/7] tcp: Skip collapsing if collapsed skb is less-dense Kuniyuki Iwashima
2026-11-17 23:06 ` sashiko-bot [this message]
2026-11-17 23:13 ` netdev-bot+sashiko
2026-11-16 23:05 ` [PATCH v2 net-next 5/7] tcp: Allocate all new skb before collapsing Kuniyuki Iwashima
2026-11-17 23:13 ` netdev-bot+sashiko
2026-11-16 23:05 ` [PATCH v2 net-next 6/7] tcp: Batch memory accounting in tcp_collapse() Kuniyuki Iwashima
2026-11-16 23:05 ` [PATCH v2 net-next 7/7] selftest: packetdrill: Add test for tcp_collapse() Kuniyuki Iwashima
2026-11-17 23:13 ` netdev-bot+sashiko
2026-11-17 1:37 ` [PATCH v2 net-next 0/7] tcp: Prevent tcp_collapse() from bloating queue MPTCP CI
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-219780@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kuniyu@google.com \
--cc=mptcp@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.