]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.9.129/ib-ipoib-avoid-a-race-condition-between-start_xmit-and-cm_rep_handler.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.9.129 / ib-ipoib-avoid-a-race-condition-between-start_xmit-and-cm_rep_handler.patch
CommitLineData
69a513a2
GKH
1From 816e846c2eb9129a3e0afa5f920c8bbc71efecaa Mon Sep 17 00:00:00 2001
2From: Aaron Knister <aaron.s.knister@nasa.gov>
3Date: Fri, 24 Aug 2018 08:42:46 -0400
4Subject: IB/ipoib: Avoid a race condition between start_xmit and cm_rep_handler
5
6From: Aaron Knister <aaron.s.knister@nasa.gov>
7
8commit 816e846c2eb9129a3e0afa5f920c8bbc71efecaa upstream.
9
10Inside of start_xmit() the call to check if the connection is up and the
11queueing of the packets for later transmission is not atomic which leaves
12a window where cm_rep_handler can run, set the connection up, dequeue
13pending packets and leave the subsequently queued packets by start_xmit()
14sitting on neigh->queue until they're dropped when the connection is torn
15down. This only applies to connected mode. These dropped packets can
16really upset TCP, for example, and cause multi-minute delays in
17transmission for open connections.
18
19Here's the code in start_xmit where we check to see if the connection is
20up:
21
22 if (ipoib_cm_get(neigh)) {
23 if (ipoib_cm_up(neigh)) {
24 ipoib_cm_send(dev, skb, ipoib_cm_get(neigh));
25 goto unref;
26 }
27 }
28
29The race occurs if cm_rep_handler execution occurs after the above
30connection check (specifically if it gets to the point where it acquires
31priv->lock to dequeue pending skb's) but before the below code snippet in
32start_xmit where packets are queued.
33
34 if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) {
35 push_pseudo_header(skb, phdr->hwaddr);
36 spin_lock_irqsave(&priv->lock, flags);
37 __skb_queue_tail(&neigh->queue, skb);
38 spin_unlock_irqrestore(&priv->lock, flags);
39 } else {
40 ++dev->stats.tx_dropped;
41 dev_kfree_skb_any(skb);
42 }
43
44The patch acquires the netif tx lock in cm_rep_handler for the section
45where it sets the connection up and dequeues and retransmits deferred
46skb's.
47
48Fixes: 839fcaba355a ("IPoIB: Connected mode experimental support")
49Cc: stable@vger.kernel.org
50Signed-off-by: Aaron Knister <aaron.s.knister@nasa.gov>
51Tested-by: Ira Weiny <ira.weiny@intel.com>
52Reviewed-by: Ira Weiny <ira.weiny@intel.com>
53Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
54Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
55
56---
57 drivers/infiniband/ulp/ipoib/ipoib_cm.c | 2 ++
58 1 file changed, 2 insertions(+)
59
60--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
61+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
62@@ -1009,12 +1009,14 @@ static int ipoib_cm_rep_handler(struct i
63
64 skb_queue_head_init(&skqueue);
65
66+ netif_tx_lock_bh(p->dev);
67 spin_lock_irq(&priv->lock);
68 set_bit(IPOIB_FLAG_OPER_UP, &p->flags);
69 if (p->neigh)
70 while ((skb = __skb_dequeue(&p->neigh->queue)))
71 __skb_queue_tail(&skqueue, skb);
72 spin_unlock_irq(&priv->lock);
73+ netif_tx_unlock_bh(p->dev);
74
75 while ((skb = __skb_dequeue(&skqueue))) {
76 skb->dev = p->dev;