@@ -5282,9 +5282,11 @@ static void __napi_gro_flush_chain(struct napi_struct *napi, u32 index,
52825282 list_del (& skb -> list );
52835283 skb -> next = NULL ;
52845284 napi_gro_complete (skb );
5285- napi -> gro_count -- ;
52865285 napi -> gro_hash [index ].count -- ;
52875286 }
5287+
5288+ if (!napi -> gro_hash [index ].count )
5289+ __clear_bit (index , & napi -> gro_bitmask );
52885290}
52895291
52905292/* napi->gro_hash[].list contains packets ordered by age.
@@ -5295,8 +5297,10 @@ void napi_gro_flush(struct napi_struct *napi, bool flush_old)
52955297{
52965298 u32 i ;
52975299
5298- for (i = 0 ; i < GRO_HASH_BUCKETS ; i ++ )
5299- __napi_gro_flush_chain (napi , i , flush_old );
5300+ for (i = 0 ; i < GRO_HASH_BUCKETS ; i ++ ) {
5301+ if (test_bit (i , & napi -> gro_bitmask ))
5302+ __napi_gro_flush_chain (napi , i , flush_old );
5303+ }
53005304}
53015305EXPORT_SYMBOL (napi_gro_flush );
53025306
@@ -5388,8 +5392,8 @@ static void gro_flush_oldest(struct list_head *head)
53885392 if (WARN_ON_ONCE (!oldest ))
53895393 return ;
53905394
5391- /* Do not adjust napi->gro_count , caller is adding a new SKB to
5392- * the chain.
5395+ /* Do not adjust napi->gro_hash[].count , caller is adding a new
5396+ * SKB to the chain.
53935397 */
53945398 list_del (& oldest -> list );
53955399 napi_gro_complete (oldest );
@@ -5464,7 +5468,6 @@ static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff
54645468 list_del (& pp -> list );
54655469 pp -> next = NULL ;
54665470 napi_gro_complete (pp );
5467- napi -> gro_count -- ;
54685471 napi -> gro_hash [hash ].count -- ;
54695472 }
54705473
@@ -5477,7 +5480,6 @@ static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff
54775480 if (unlikely (napi -> gro_hash [hash ].count >= MAX_GRO_SKBS )) {
54785481 gro_flush_oldest (gro_head );
54795482 } else {
5480- napi -> gro_count ++ ;
54815483 napi -> gro_hash [hash ].count ++ ;
54825484 }
54835485 NAPI_GRO_CB (skb )-> count = 1 ;
@@ -5492,6 +5494,13 @@ static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff
54925494 if (grow > 0 )
54935495 gro_pull_from_frag0 (skb , grow );
54945496ok :
5497+ if (napi -> gro_hash [hash ].count ) {
5498+ if (!test_bit (hash , & napi -> gro_bitmask ))
5499+ __set_bit (hash , & napi -> gro_bitmask );
5500+ } else if (test_bit (hash , & napi -> gro_bitmask )) {
5501+ __clear_bit (hash , & napi -> gro_bitmask );
5502+ }
5503+
54955504 return ret ;
54965505
54975506normal :
@@ -5890,7 +5899,7 @@ bool napi_complete_done(struct napi_struct *n, int work_done)
58905899 NAPIF_STATE_IN_BUSY_POLL )))
58915900 return false;
58925901
5893- if (n -> gro_count ) {
5902+ if (n -> gro_bitmask ) {
58945903 unsigned long timeout = 0 ;
58955904
58965905 if (work_done )
@@ -6099,7 +6108,7 @@ static enum hrtimer_restart napi_watchdog(struct hrtimer *timer)
60996108 /* Note : we use a relaxed variant of napi_schedule_prep() not setting
61006109 * NAPI_STATE_MISSED, since we do not react to a device IRQ.
61016110 */
6102- if (napi -> gro_count && !napi_disable_pending (napi ) &&
6111+ if (napi -> gro_bitmask && !napi_disable_pending (napi ) &&
61036112 !test_and_set_bit (NAPI_STATE_SCHED , & napi -> state ))
61046113 __napi_schedule_irqoff (napi );
61056114
@@ -6114,7 +6123,7 @@ void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
61146123 INIT_LIST_HEAD (& napi -> poll_list );
61156124 hrtimer_init (& napi -> timer , CLOCK_MONOTONIC , HRTIMER_MODE_REL_PINNED );
61166125 napi -> timer .function = napi_watchdog ;
6117- napi -> gro_count = 0 ;
6126+ napi -> gro_bitmask = 0 ;
61186127 for (i = 0 ; i < GRO_HASH_BUCKETS ; i ++ ) {
61196128 INIT_LIST_HEAD (& napi -> gro_hash [i ].list );
61206129 napi -> gro_hash [i ].count = 0 ;
@@ -6174,7 +6183,7 @@ void netif_napi_del(struct napi_struct *napi)
61746183 napi_free_frags (napi );
61756184
61766185 flush_gro_hash (napi );
6177- napi -> gro_count = 0 ;
6186+ napi -> gro_bitmask = 0 ;
61786187}
61796188EXPORT_SYMBOL (netif_napi_del );
61806189
@@ -6216,7 +6225,7 @@ static int napi_poll(struct napi_struct *n, struct list_head *repoll)
62166225 goto out_unlock ;
62176226 }
62186227
6219- if (n -> gro_count ) {
6228+ if (n -> gro_bitmask ) {
62206229 /* flush too old packets
62216230 * If HZ < 1000, flush all packets.
62226231 */
@@ -9272,6 +9281,9 @@ static struct hlist_head * __net_init netdev_create_hash(void)
92729281/* Initialize per network namespace state */
92739282static int __net_init netdev_init (struct net * net )
92749283{
9284+ BUILD_BUG_ON (GRO_HASH_BUCKETS >
9285+ FIELD_SIZEOF (struct napi_struct , gro_bitmask ));
9286+
92759287 if (net != & init_net )
92769288 INIT_LIST_HEAD (& net -> dev_base_head );
92779289
0 commit comments