Skip to content

Commit f8e8f97

Browse files
edumazetdavem330
authored andcommitted
net: fix a race in gro_cell_poll()
Dmitry Kravkov reported packet drops for GRE packets since GRO support was added. There is a race in gro_cell_poll() because we call napi_complete() without any synchronization with a concurrent gro_cells_receive() Once bug was triggered, we queued packets but did not schedule NAPI poll. We can fix this issue using the spinlock protected the napi_skbs queue, as we have to hold it to perform skb dequeue anyway. As we open-code skb_dequeue(), we no longer need to mask IRQS, as both producer and consumer run under BH context. Bug added in commit c9e6bc6 (net: add gro_cells infrastructure) Reported-by: Dmitry Kravkov <dmitry@broadcom.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Tested-by: Dmitry Kravkov <dmitry@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d46d132 commit f8e8f97

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

‎include/net/gro_cells.h‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ struct gro_cells {
1717

1818
static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *skb)
1919
{
20-
unsigned long flags;
2120
struct gro_cell *cell = gcells->cells;
2221
struct net_device *dev = skb->dev;
2322

@@ -35,32 +34,37 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
3534
return;
3635
}
3736

38-
spin_lock_irqsave(&cell->napi_skbs.lock, flags);
37+
/* We run in BH context */
38+
spin_lock(&cell->napi_skbs.lock);
3939

4040
__skb_queue_tail(&cell->napi_skbs, skb);
4141
if (skb_queue_len(&cell->napi_skbs) == 1)
4242
napi_schedule(&cell->napi);
4343

44-
spin_unlock_irqrestore(&cell->napi_skbs.lock, flags);
44+
spin_unlock(&cell->napi_skbs.lock);
4545
}
4646

47+
/* called unser BH context */
4748
static inline int gro_cell_poll(struct napi_struct *napi, int budget)
4849
{
4950
struct gro_cell *cell = container_of(napi, struct gro_cell, napi);
5051
struct sk_buff *skb;
5152
int work_done = 0;
5253

54+
spin_lock(&cell->napi_skbs.lock);
5355
while (work_done < budget) {
54-
skb = skb_dequeue(&cell->napi_skbs);
56+
skb = __skb_dequeue(&cell->napi_skbs);
5557
if (!skb)
5658
break;
57-
59+
spin_unlock(&cell->napi_skbs.lock);
5860
napi_gro_receive(napi, skb);
5961
work_done++;
62+
spin_lock(&cell->napi_skbs.lock);
6063
}
6164

6265
if (work_done < budget)
6366
napi_complete(napi);
67+
spin_unlock(&cell->napi_skbs.lock);
6468
return work_done;
6569
}
6670

0 commit comments

Comments
 (0)