Subject: Re: [PATCH v3] skbuff: Fix a race between coalescing and releasing SKBs

From: Jakub Kicinski <[email-masked]>
Date: Wed, 12 Apr 2023 21:08:16 -0700

On Tue, 11 Apr 2023 10:26:40 +0800 Liang Chen wrote:
>  	/* In general, avoid mixing slab allocated and page_pool allocated
> -	 * pages within the same SKB. However when @to is not pp_recycle and
> -	 * @from is cloned, we can transition frag pages from page_pool to
> -	 * reference counted.
> -	 *
> -	 * On the other hand, don't allow coalescing two pp_recycle SKBs if
> -	 * @from is cloned, in case the SKB is using page_pool fragment
> -	 * references (PP_FLAG_PAGE_FRAG). Since we only take full page
> -	 * references for cloned SKBs at the moment that would result in
> -	 * inconsistent reference counts.
> +	 * pages within the same SKB. However don't allow coalescing two

The word 'however' no longer works here because there's no
contradiction, it's an additional rule.

> +	 * pp_recycle SKBs if @from is cloned, in case the SKB is using
> +	 * page_pool fragment references (PP_FLAG_PAGE_FRAG). Since we only
> +	 * take full page references for cloned SKBs at the moment that would
> +	 * result in inconsistent reference counts.
>  	 */
> -	if (to->pp_recycle != (from->pp_recycle && !skb_cloned(from)))
> +	if (to->pp_recycle != from->pp_recycle ||
> +	    (from->pp_recycle && skb_cloned(from)))

How about we change the comment to:

 	/* In general, avoid mixing page_pool and non-page_pool allocated
 	 * pages within the same SKB. Additionally avoid dealing with clones
 	 * containing page_pool pages, in case the SKB is using page_pool fragment
	 * references (PP_FLAG_PAGE_FRAG). Since we only take full page
	 * references for cloned SKBs at the moment that would result in
	 * inconsistent reference counts.
	 * In theory we could take full references if from is cloned and 
	 * !@to->pp_recycle but its tricky (due to potential race with the clone 
 	 * disappearing) and rare, so not worth dealing with.
 	 */

Please also add:

Fixes: 53e0961da1c7 ("page_pool: add frag page recycling support in page pool")

and Eric's review tag.