mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	net: add napi_get_frags_check() helper
This is a follow up of commit 3226b158e6
("net: avoid 32 x truesize under-estimation for tiny skbs")
When/if we increase MAX_SKB_FRAGS, we better make sure
the old bug will not come back.
Adding a check in napi_get_frags() would be costly,
even if using DEBUG_NET_WARN_ON_ONCE().
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
			
			
This commit is contained in:
		
							parent
							
								
									ee2640df23
								
							
						
					
					
						commit
						fd9ea57f4e
					
				
					 1 changed files with 18 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -6351,6 +6351,23 @@ int dev_set_threaded(struct net_device *dev, bool threaded)
 | 
			
		|||
}
 | 
			
		||||
EXPORT_SYMBOL(dev_set_threaded);
 | 
			
		||||
 | 
			
		||||
/* Double check that napi_get_frags() allocates skbs with
 | 
			
		||||
 * skb->head being backed by slab, not a page fragment.
 | 
			
		||||
 * This is to make sure bug fixed in 3226b158e67c
 | 
			
		||||
 * ("net: avoid 32 x truesize under-estimation for tiny skbs")
 | 
			
		||||
 * does not accidentally come back.
 | 
			
		||||
 */
 | 
			
		||||
static void napi_get_frags_check(struct napi_struct *napi)
 | 
			
		||||
{
 | 
			
		||||
	struct sk_buff *skb;
 | 
			
		||||
 | 
			
		||||
	local_bh_disable();
 | 
			
		||||
	skb = napi_get_frags(napi);
 | 
			
		||||
	WARN_ON_ONCE(skb && skb->head_frag);
 | 
			
		||||
	napi_free_frags(napi);
 | 
			
		||||
	local_bh_enable();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi,
 | 
			
		||||
			   int (*poll)(struct napi_struct *, int), int weight)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -6378,6 +6395,7 @@ void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi,
 | 
			
		|||
	set_bit(NAPI_STATE_NPSVC, &napi->state);
 | 
			
		||||
	list_add_rcu(&napi->dev_list, &dev->napi_list);
 | 
			
		||||
	napi_hash_add(napi);
 | 
			
		||||
	napi_get_frags_check(napi);
 | 
			
		||||
	/* Create kthread for this napi if dev->threaded is set.
 | 
			
		||||
	 * Clear dev->threaded if kthread creation failed so that
 | 
			
		||||
	 * threaded mode will not be enabled in napi_enable().
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue