Re: [PATCH v3 6/9] RFC: net: limit folio refcount when copying skb frag references

From: Pedro Falcato

Date: Thu Nov 12 2026 - 11:15:24 EST


On Tue, Nov 10, 2026 at 09:35:46PM +0100, David Hildenbrand (Arm) wrote:
> Various networking features copy frag references of an skb, for example
> when unsharing a cloned skb (AF_PACKET trimming a clone), when copying an
> skb (nft dup) or when building NFQUEUE messages. This is an effective
> way for multiplying folio references held by an skb, allowing for
> exceeding folio refcount limits.
>
> This is not specific to large pagecache folios, but with them it is a
> lot easier to reach the refcount limit, as page table mappings can cheaply
> create many references.
>
> Let's introduce skb_frag_try_ref() and skb_frags_try_ref(), which use
> try_get_page(), and use them in pskb_expand_head(), __pskb_copy_fclone(),
> skb_zerocopy() and pskb_carve_inside_*(). All of these can already fail,
> and their callers handle that.
>
> Fixes: 800d8c63b2e9 ("shmem: add huge pages support")
> Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
> Fixes: 793917d997df ("mm/readahead: Add large folio readahead")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

Acked-by: Pedro Falcato <pfalcato@xxxxxxx>

For what it's worth, I tried thinking up a way to avoid all of this stuff.
I know there are severe recursion limits that (should) avoid a large copy
chain, but the issue is that, say you have a copy chain limit of 8, you can
still create 2^31/8 skbs (each with their own reference), then clone each 8
times such that you get an overflow. Annoying.

--
Pedro