Skip to contentSkip to conversation

IB/ipoib: fix dangling pointer references to ipoib_neigh and ipoib_path

PATCH Superseded Ralph Campbell 2 participants 7 messages Aug 17, 2010 – Oct 1, 2010 4 messages not in the archive InfiniBand

lore
Share & tools
lore
#0 lore raw

v5 cover IB/ipoib: fix dangling pointer references to ipoib_neigh and ipoib_path

Hopefully, this is the last update needed to this patch and it can be applied. It has been in use within QLogic for several months without problems.

Changes from v4 to v5:

Removed the "break;" in ipoib_cm_flush_path() so now the function comment matches the code.

Updated the error case code in ipoib_cm_tx_start() so the address handle and cached GID are reset so the next call to ipoib_start_xmit() will create a new CM connection.

Added netif_tx_lock_bh() in ipoib_neigh_cleanup()
in order to call ipoib_cm_destroy_tx().
I don't think it is strictly needed, I'm just being paranoid and I don't think it is a performance path when deleting struct neighbour.

=================
These are my notes on the IPoIB locking and what I figured out in the process of creating the patch that follows.

IPoIB connected mode uses a separate QP for transmit and receive. I will only talk about the transmit side although the some of the data structures are used by both.

The executive summary for locking is that most things are protected by the struct ipoib_dev_priv.lock. The network device lock, netif_tx_lock(), netif_tx_lock_bh(), or stopping network output via netif_stop_queue() is used to prevent ipoib_start_xmit() and ipoib_cm_send() from being called which can access struct ipoib_neigh and struct ipoib_cm_tx without holding locks.

struct sk_buff {
// This pointer may hold a reference (see SKB_DST_NOREF).
// IPoIB doesn't change this pointer so the locking rules aren't important. unsigned long _skb_refdst;
}

struct dst_entry {
// The neighbour pointer holds a reference.
// IPoIB doesn't change this pointer so the locking rules aren't important. struct neighbour *neighbour;

atomic_t refcnt;
}

struct neighbour {
// stores the IPoIB "hardware" address:
// (control flags (one byte), QPN (3 bytes), destination GID (16 bytes), // padding (0 or 4 bytes), and a pointer to struct ipoib_neigh (4 or 8 bytes) // which is not reference counted.
// It is protected by calling netif_tx_lock(dev) or netif_stop_queue(dev). // The Linux network stack can free the ipoib_neigh pointer by calling // ipoib_neigh_cleanup()
uchar ha[];

struct neigh_ops *ops;
atomic_t refcnt;
}

struct ipoib_neigh {
// This is protected by priv->lock and *does not* hold a reference struct neighbour *neighbour; // back pointer to containing struct

// This is protected by priv->lock although it is accessed w/o // holding the priv->lock in ipoib_start_xmit() which means that // to clear the pointer, ipoib_start_xmit() has to be prevented from // being called if there is a chance that
// "to_ipoib_neigh(skb_dst(skb)->neighbour)" could point to this struct. struct ipoib_cm_tx *cm;

// This is protected by priv->lock and holds a reference struct ipoib_ah *ah;

// Link for path->neigh_list or mcast->neigh_list. // This is protected by priv->lock.
struct list_head list;
}

struct ipoib_cm_tx {
// This is protected by priv->lock.
struct ipoib_neigh *neigh;
}

struct ipoib_path {
struct ib_sa_query *query; // non-NULL if SA path record query is pending

// This is protected by priv->lock and holds a reference struct ipoib_ah *ah;

struct completion done; // True if query is finished

// list of all struct ipoib_neigh.list with the same ah pointer struct list_head neigh_list;
}

struct ipoib_dev_priv {
// This lock protects a number of things associated with this // IPoIB network device.
spinlock_t lock;

// Contains the struct ipoib_mcast nodes indexed by MGID. // It is protected by priv->lock.
struct rb_root multicast_tree;
}

Before any nodes can send IPoIB packets, the SA creates the "all HCA multicast group GID" which encodes <flag>, <scope>, <IPv4/IPv6>, <pkey>. For example, transient, link local scope, IPv4, pkey of 0x8001, limited broadcast address we have:
FF12:401B:8001::FFFF:FFFF, in compressed format.
The group also has a P_Key, Q_Key, and MTU associated with it in the SA path record.
This multicast group is used for IPv4 address resolution (ARP). The group is joined when the IPoIB device is brought up and the details saved in priv->broadcast.

The transmit process starts with the Linux networking code calling netif_tx_lock(dev) and then calling:

ipoib_hard_header()
// This prepends the "hardware address" onto the sk_buff header if // the neighbor address hasn't been set in the sk_buff.

ipoib_start_xmit(skb, dev)
// The first time through, skb_dst(skb)->neighbour won't be set and // ipoib_hard_header() will have prepended the IPv4 broadcast // "hardware address" which we strip off and call the following. ipoib_mcast_send(dev, mgid, skb)

    spin_lock_irqsave(&priv->lock, flags)
    // Search for the mgid and create an entry if not found.
    mcast = __ipoib_mcast_find(dev, mgid)
    // Since mgid is probably the "all HCA multicast group GID" which
    // was initialized when the network interface was started, we call:
    spin_unlock_irqrestore(&priv->lock, flags)
    // XXX bug? using mcast->ah after unlock w/o incref on ah?
    ipoib_send(dev, skb, mcast->ah, IB_MULTICAST_QPN)

// Eventually, we get an ARP reply, the struct neighbour.ha[] is filled // in with the destination's "hardware address" and ipoib_start_xmit() // is called again:
ipoib_start_xmit(skb, dev)
// This time, if (likely(skb_dst(skb) && skb_dst(skb)->neighbour)) is true neigh = *to_ipoib_neigh(skb_dst(skb)->neighbour)
// neigh is NULL so we allocate a struct ipoib_neigh:
neigh = neigh_alloc(skb_dst(skb)->neighbour, skb->dev) path_lookup(skb, dev, neigh)

    // Assume it is a unicast address
    neigh_add_path(skb, dev, neigh)
      spin_lock_irqsave(&priv->lock, flags)
      // Find or allocate a path record entry
      path = __path_find(dev, n->ha + 4)
      if (!path)
        path = path_rec_create(dev, n->ha + 4)
      // path->ah will be NULL the first time through so:
      path_rec_start(dev, path)
        // Start the path record lookup process.
        // When it is finished, path_rec_completion() will be called.
      spin_unlock_irqrestore(&priv->lock, flags)

// Eventually, path_rec_completion() will be called when the SA replies. path_rec_completion()
// Create address handle from the reply
ah = ipoib_create_ah()
spin_lock_irqsave(&priv->lock, flags)
// for each ipoib_neigh in path->neigh_list

    // set neigh->ah
    // create connected mode QP if enabled
    ipoib_cm_set(neigh, ipoib_cm_create_tx())
      // Allocate a struct ipoib_cm_tx.
      tx = kzalloc()
      // Add it to the list of structs waiting to be processed.
      list_add(&tx->list, &priv->cm.start_list)
      // At this point, tx->neigh != NULL so ipoib_cm_destroy_tx(tx)
      // will have an effect.
      // Schedule ipoib_cm_tx_start() to be called by work thread
      queue_work(ipoib_workqueue, &priv->cm.start_task)

// Mark path as "done" doing the SA path record query process path->query = NULL
complete(&path->done) spin_unlock_irqrestore(&priv->lock, flags)
// Requeue waiting skbs if any
while ((skb = __skb_dequeue(&skqueue)))
dev_queue_xmit(skb)

// Some time later, ipoib_cm_tx_start() is called from the workqueue thread ipoib_cm_tx_start()
// netif_tx_lock_bh() is needed because we may set neigh->cm = NULL netif_tx_lock_bh(dev)
spin_lock_irqsave(&priv->lock, flags)
while (!list_empty(&priv->cm.start_list))

    // Remove tx from priv->cm.start_list
    list_del_init(&p->list)
    // Save the QPN and path record (destination address)
    spin_unlock_irqrestore(&priv->lock, flags)
    netif_tx_unlock_bh(dev)
    ipoib_cm_tx_init()
      // Create and initialize QP
      p->qp = ipoib_cm_create_tx_qp()
      // Create CM state
      ib_create_cm_id(ipoib_cm_tx_handler)
      // Call CM to start the process of establishing the RC QP connection
      ipoib_cm_send_req()
    netif_tx_lock_bh(dev)
    spin_lock_irqsave(&priv->lock, flags)
    // We need the lock to check p->neigh in case ipoib_cm_destroy_tx()
    // was called but can't call ipoib_cm_tx_destroy() w/ the lock held so
    // put it on the priv->reap_list if there was an error.

spin_unlock_irqrestore(&priv->lock, flags)
netif_tx_unlock_bh(dev)

// Eventually, CM calls ipoib_cm_tx_handler to say what parameters to // use to modify the QP to RTS
ipoib_cm_tx_handler()
ipoib_cm_rep_handler()

    // Use CM parameters to complete RC QP initialization
    ib_modify_qp()
    // This allows ipoib_start_xmit() to call ipoib_cm_send()
    set_bit(IPOIB_FLAG_OPER_UP, &p->flags)
    // XXX Hmm, race between ipoib_start_xmit() setting UP flag and
    // then getting the priv lock to queue the skb if UP wasn't set.

// Requeued skb will call:
ipoib_start_xmit(skb, dev)
// This time all the checks pass so we call:
ipoib_cm_send()

    post_send()
      ib_post_send()

// Some time later, we get a send completion ipoib_cm_handle_tx_wc()
// Note that the completion contains a pointer to the QP
// which contains a pointer to the struct ipoib_cm_tx.
// This means that when destroying a RC QP, we need to wait for completions // to drain before calling kfree(tx). See ipoib_cm_tx_destroy(). struct ipoib_cm_tx *tx = wc->qp->qp_context; ib_dma_unmap_single()
dev_kfree_skb_any()
// We lock the network device transmit since ipoib_cm_destroy_tx() // might be called and change neigh->cm = NULL.
// Also, it protects tx->tx_tail, tx->tx_head, and ipoib_cm_send(). netif_tx_lock(dev)
if wc error

    spin_lock_irqsave(&priv->lock, flags)
    // This prevents ipoib_cm_send(tx) from being called.
    // XXX not really needed since we hold the netif_tx_lock() and
    // will clear neigh->cm.
    clear_bit(IPOIB_FLAG_OPER_UP, &tx->flags)
    ipoib_cm_destroy_tx(tx)
      // Since there can be many error completions queued,
      // tx->neigh != NULL means this is the first time this tx is being
      // destroyed
      struct ipoib_neigh *neigh = tx->neigh
      if (!neigh) return;
      neigh->cm = NULL;
      tx->neigh = NULL;
      // if ipoib_cm_tx_start() is not actively using this tx,
      // put on tx reap list
    spin_unlock_irqrestore(&priv->lock, flags)

netif_tx_unlock(dev)

// This is called by the workqueue to reap struct ipoib_cm_tx ipoib_cm_tx_reap()
// This protects struct ipoib_cm_tx netif_tx_lock_bh(dev); spin_lock_irqsave(&priv->lock, flags);
while (!list_empty(&priv->cm.reap_list))

    // remove from list, unlock
    ipoib_cm_tx_destroy(p)
      if (p->id) ib_destroy_cm_id(p->id);
      // wait for all competions
      if (p->qp) ib_destroy_qp(p->qp);
      vfree(p->tx_ring);
      kfree(p);
    // lock

spin_unlock_irqrestore(&priv->lock, flags);
netif_tx_unlock_bh(dev);

// ipoib_flush_paths() is called when bringing the network interface down, // or when changing between connected<->datagram modes. ipoib_flush_paths()
// This protects priv->path_tree from ipoib_start_xmit() netif_tx_lock_bh(dev);
spin_lock_irqsave(&priv->lock, flags);
// remove path from lookup table, add to remove_list list_for_each_entry_safe(path, tp, &remove_list, list)

    // Cancel any outstanding SA path query for this path
    // unlock and wait for SA query completion
    wait_for_completion(&path->done)
    path_free(path)
      foreach neigh in path->neigh_list
        ipoib_neigh_flush(neigh)
          // lock to protect against ipoib_start_xmit()
          // return struct ipoib_neigh back to initial state
          // unlock
      kfree(path)
    // lock

spin_unlock_irqrestore(&priv->lock, flags); netif_tx_unlock_bh(dev);
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

PATCH v5 1/1 IB/ipoib: fix dangling pointer references to ipoib_neigh and ipoib_path

In reply to a message not in the archive

Basically, a struct sk_buff has a pointer to a struct dst_entry which has a pointer to a struct neighbour. IPoIB uses
struct neighbour.ha to store the IB "hardware address" and a pointer to a struct ipoib_neigh. When using connected mode, struct ipoib_neigh has a pointer to struct ipoib_cm_tx which contains pointers back to struct ipoib_neigh and ipoib_path. The core network code will call ipoib_neigh_cleanup() when it is destroying struct neighbour and IPoIB should guarantee that the struct ipoib_neigh and all the memory it points to are destroyed. Also, the connected mode RC QP contains a pointer back to the struct ipoib_cm_tx which can be dereferenced in the CQ completion handler.
The problem is that there are several places where the struct ipoib_cm_tx can be used after it has been freed. The easiest way to reproduce this bug is to run a UDP bandwidth test while loading/unloading the IPoIB module or ifup/ifdown the interface.
The fix is rather complex since the RC QP connection setup, tear down, and CQ completion draining are asynchronous processes. The struct ipoib_cm_tx goes through four "states":
1) Newly created by ipoib_cm_create_tx()
neigh!=NULL, flags==0, and linked on priv->cm.start_list.
2) Being used by ipoib_cm_tx_start()
neigh!=NULL, not on priv->cm.start_list, flags==0, and in the process of starting CM.
3) Being used by CM or sending data on the RC QP
neigh!=NULL, not on priv->cm.start_list, flags & IPOIB_FLAG_INITIALIZED.
4) Being destroyed
tx->neigh==NULL and on priv->cm.reap_task list or being destroyed by ipoib_cm_tx_reap().

---

 drivers/infiniband/ulp/ipoib/ipoib.h           |   14 +
 drivers/infiniband/ulp/ipoib/ipoib_cm.c        |  108 ++++++----
 drivers/infiniband/ulp/ipoib/ipoib_main.c      |  266 ++++++++++++------------
 drivers/infiniband/ulp/ipoib/ipoib_multicast.c |   76 ++-----
 4 files changed, 223 insertions(+), 241 deletions(-)
drivers/infiniband/ulp/ipoib/ipoib.h +10 -4
index 753a983..5a842d7 100644
@@ -415,9 +415,7 @@ static inline struct ipoib_neigh **to_ipoib_neigh(struct neighbour *neigh)
 				     INFINIBAND_ALEN, sizeof(void *));
 }
 
-struct ipoib_neigh *ipoib_neigh_alloc(struct neighbour *neigh,
-				      struct net_device *dev);
-void ipoib_neigh_free(struct net_device *dev, struct ipoib_neigh *neigh);
+void ipoib_neigh_flush(struct ipoib_neigh *neigh);
 
 extern struct workqueue_struct *ipoib_workqueue;
 
@@ -464,7 +462,8 @@ void ipoib_dev_cleanup(struct net_device *dev);
 
 void ipoib_mcast_join_task(struct work_struct *work);
 void ipoib_mcast_carrier_on_task(struct work_struct *work);
-void ipoib_mcast_send(struct net_device *dev, void *mgid, struct sk_buff *skb);
+void ipoib_mcast_send(struct net_device *dev, void *mgid, struct sk_buff *skb,
+		      struct ipoib_neigh *neigh);
 
 void ipoib_mcast_restart_task(struct work_struct *work);
 int ipoib_mcast_start_thread(struct net_device *dev);
@@ -570,6 +569,7 @@ void ipoib_cm_dev_cleanup(struct net_device *dev);
 struct ipoib_cm_tx *ipoib_cm_create_tx(struct net_device *dev, struct ipoib_path *path,
 				    struct ipoib_neigh *neigh);
 void ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx);
+void ipoib_cm_flush_path(struct net_device *dev, struct ipoib_path *path);
 void ipoib_cm_skb_too_long(struct net_device *dev, struct sk_buff *skb,
 			   unsigned int mtu);
 void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc);
@@ -659,6 +659,12 @@ void ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx)
 }
 
 static inline
+void ipoib_cm_flush_path(struct net_device *dev, struct ipoib_path *path)
+{
+	return;
+}
+
+static inline
 int ipoib_cm_add_mode_attr(struct net_device *dev)
 {
 	return 0;
drivers/infiniband/ulp/ipoib/ipoib_cm.c +62 -46

166 lines not on this page · raw message

drivers/infiniband/ulp/ipoib/ipoib_main.c +129 -137

452 lines not on this page · raw message

drivers/infiniband/ulp/ipoib/ipoib_multicast.c +22 -54

124 lines not on this page · raw message

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to a message not in the archive

Ralph,

I see the following crash sporadically (only under stress) with a Sles11SP1 (which is 2.6.32 kernel). I saw this crash with V4 of your patch and have not yet had a chance to try V5. Have you seen this in your testing? If this not the crash stack can you please share what your patch fixes?

<4>ib0: RX drain timing out
<4>idr_remove called for id=11491974 which is not allocated.
<4>Call Trace:
<4>[c000000749fe33b0] [c0000000000129e4] .show_stack+0x6c/0x198 (unreliable) <4>[c000000749fe3460] [c0000000002ea594] .sub_remove+0x1ec/0x1f8 <4>[c000000749fe3520] [c0000000002ea5e0] .idr_remove+0x40/0xf8 <4>[c000000749fe35b0] [d000000012d84d70] .cm_destroy_id+0xa0/0x520 [ib_cm] <4>[c000000749fe3680] [d00000001b7fb644] .ipoib_cm_free_rx_reap_list+0xd4/0x190 [ib_ipoib] <4>[c000000749fe3740] [d00000001b7fe404] .ipoib_cm_dev_stop+0x23c/0x360 [ib_ipoib] <4>[c000000749fe3800] [d00000001b7f4dbc] .ipoib_ib_dev_stop+0xe4/0x4b0 [ib_ipoib] <4>[c000000749fe3960] [d00000001b7f0f30] .ipoib_stop+0x88/0x178 [ib_ipoib] <4>[c000000749fe39f0] [c0000000004eacf4] .dev_close+0xdc/0x148 <4>[c000000749fe3a80] [c0000000004ea2b8] .dev_change_flags+0x1f0/0x288 <4>[c000000749fe3b20] [d00000001b7f11b8] .ipoib_remove_one+0xb8/0x140 [ib_ipoib] <4>[c000000749fe3bc0] [d00000001210425c] .ib_unregister_client+0xb4/0x1b8 [ib_core] <4>[c000000749fe3c90] [d00000001b7ffde8] .ipoib_cleanup_module+0x20/0x60 [ib_ipoib] <4>[c000000749fe3d20] [c0000000000ec408] .SyS_delete_module+0x238/0x320 <4>[c000000749fe3e30] [c0000000000085b4] syscall_exit+0x0/0x40
<1>Unable to handle kernel paging request for data at address 0x45000027228d1ffb <1>Faulting instruction address: 0xc0000000005a8e88
12:mon> e
cpu 0x12: Vector: 300 (Data Access) at [c000000749fe3250]

    pc: c0000000005a8e88: .wait_for_common+0xb8/0x268
    lr: c0000000005a8e20: .wait_for_common+0x50/0x268
    sp: c000000749fe34d0
   msr: 8000000000009032
   dar: 45000027228d1ffb
 dsisr: 42000000
  current = 0xc00000074b4ce0e0
  paca    = 0xc000000000f64a00
    pid   = 13605, comm = modprobe

12:mon>

Thanks
Pradeep

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
In reply to a message not in the archive

I haven't seen this stack trace before. Since it involves the RX
QP connection and my patch changes the TX QP connection,
I doubt my patch has any effect on this case. When I get some
time, I will look to see if I can find similar races in the RX connection
set up & tear down that might exist.
________________________________________
From: Pradeep Satyanarayana [[email protected]]
Sent: Thursday, September 02, 2010 8:41 PM
To: Ralph Campbell
Cc: Roland Dreier; [email protected]
Subject: Re: [PATCH v5] IB/ipoib: fix dangling pointer references to ipoib_neigh and ipoib_path

Ralph,

I see the following crash sporadically (only under stress) with a Sles11SP1 (which is 2.6.32 kernel). I saw this crash with V4 of your patch and have not yet had a chance to try V5. Have you seen this in your testing? If this not the crash stack can you please share what your patch fixes?

<4>ib0: RX drain timing out
<4>idr_remove called for id=11491974 which is not allocated.
<4>Call Trace:
<4>[c000000749fe33b0] [c0000000000129e4] .show_stack+0x6c/0x198 (unreliable) <4>[c000000749fe3460] [c0000000002ea594] .sub_remove+0x1ec/0x1f8 <4>[c000000749fe3520] [c0000000002ea5e0] .idr_remove+0x40/0xf8 <4>[c000000749fe35b0] [d000000012d84d70] .cm_destroy_id+0xa0/0x520 [ib_cm] <4>[c000000749fe3680] [d00000001b7fb644] .ipoib_cm_free_rx_reap_list+0xd4/0x190 [ib_ipoib] <4>[c000000749fe3740] [d00000001b7fe404] .ipoib_cm_dev_stop+0x23c/0x360 [ib_ipoib] <4>[c000000749fe3800] [d00000001b7f4dbc] .ipoib_ib_dev_stop+0xe4/0x4b0 [ib_ipoib] <4>[c000000749fe3960] [d00000001b7f0f30] .ipoib_stop+0x88/0x178 [ib_ipoib] <4>[c000000749fe39f0] [c0000000004eacf4] .dev_close+0xdc/0x148 <4>[c000000749fe3a80] [c0000000004ea2b8] .dev_change_flags+0x1f0/0x288 <4>[c000000749fe3b20] [d00000001b7f11b8] .ipoib_remove_one+0xb8/0x140 [ib_ipoib] <4>[c000000749fe3bc0] [d00000001210425c] .ib_unregister_client+0xb4/0x1b8 [ib_core] <4>[c000000749fe3c90] [d00000001b7ffde8] .ipoib_cleanup_module+0x20/0x60 [ib_ipoib] <4>[c000000749fe3d20] [c0000000000ec408] .SyS_delete_module+0x238/0x320 <4>[c000000749fe3e30] [c0000000000085b4] syscall_exit+0x0/0x40
<1>Unable to handle kernel paging request for data at address 0x45000027228d1ffb <1>Faulting instruction address: 0xc0000000005a8e88
12:mon> e
cpu 0x12: Vector: 300 (Data Access) at [c000000749fe3250]

    pc: c0000000005a8e88: .wait_for_common+0xb8/0x268
    lr: c0000000005a8e20: .wait_for_common+0x50/0x268
    sp: c000000749fe34d0
   msr: 8000000000009032
   dar: 45000027228d1ffb
 dsisr: 42000000
  current = 0xc00000074b4ce0e0
  paca    = 0xc000000000f64a00
    pid   = 13605, comm = modprobe

12:mon>

Thanks
Pradeep

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw
In reply to a message not in the archive

I was looking at the Rx connection tear down and found a bug. I don't know if it would cause this panic but you might try it. I haven't stress tested it but it compiles and basic network connections work.

I also don't like the call to cancel_delayed_work(&priv->cm.stale_task) at the end of ipoib_cm_dev_stop(). I think it should be called after ib_destroy_cm_id() and priv->cm.id = NULL.

Quoted 37 lines · Pradeep Satyanarayana

Ralph,

I see the following crash sporadically (only under stress) with a Sles11SP1 (which is 2.6.32 kernel). I saw this crash with V4 of your patch and have not yet had a chance to try V5. Have you seen this in your testing? If this not the crash stack can you please share what your patch fixes?

<4>ib0: RX drain timing out
<4>idr_remove called for id=11491974 which is not allocated.
<4>Call Trace:
<4>[c000000749fe33b0] [c0000000000129e4] .show_stack+0x6c/0x198 (unreliable) <4>[c000000749fe3460] [c0000000002ea594] .sub_remove+0x1ec/0x1f8 <4>[c000000749fe3520] [c0000000002ea5e0] .idr_remove+0x40/0xf8 <4>[c000000749fe35b0] [d000000012d84d70] .cm_destroy_id+0xa0/0x520 [ib_cm] <4>[c000000749fe3680] [d00000001b7fb644] .ipoib_cm_free_rx_reap_list+0xd4/0x190 [ib_ipoib] <4>[c000000749fe3740] [d00000001b7fe404] .ipoib_cm_dev_stop+0x23c/0x360 [ib_ipoib] <4>[c000000749fe3800] [d00000001b7f4dbc] .ipoib_ib_dev_stop+0xe4/0x4b0 [ib_ipoib] <4>[c000000749fe3960] [d00000001b7f0f30] .ipoib_stop+0x88/0x178 [ib_ipoib] <4>[c000000749fe39f0] [c0000000004eacf4] .dev_close+0xdc/0x148 <4>[c000000749fe3a80] [c0000000004ea2b8] .dev_change_flags+0x1f0/0x288 <4>[c000000749fe3b20] [d00000001b7f11b8] .ipoib_remove_one+0xb8/0x140 [ib_ipoib] <4>[c000000749fe3bc0] [d00000001210425c] .ib_unregister_client+0xb4/0x1b8 [ib_core] <4>[c000000749fe3c90] [d00000001b7ffde8] .ipoib_cleanup_module+0x20/0x60 [ib_ipoib] <4>[c000000749fe3d20] [c0000000000ec408] .SyS_delete_module+0x238/0x320 <4>[c000000749fe3e30] [c0000000000085b4] syscall_exit+0x0/0x40
<1>Unable to handle kernel paging request for data at address 0x45000027228d1ffb <1>Faulting instruction address: 0xc0000000005a8e88
12:mon> e
cpu 0x12: Vector: 300 (Data Access) at [c000000749fe3250]

    pc: c0000000005a8e88: .wait_for_common+0xb8/0x268
    lr: c0000000005a8e20: .wait_for_common+0x50/0x268
    sp: c000000749fe34d0
   msr: 8000000000009032
   dar: 45000027228d1ffb
 dsisr: 42000000
  current = 0xc00000074b4ce0e0
  paca    = 0xc000000000f64a00
    pid   = 13605, comm = modprobe
Quoted 4 lines

12:mon>

Thanks
Pradeep

IB/ipoib: fix race when handling IPOIB_CM_RX_DRAIN_WRID

From: Ralph Campbell <[email protected]>

ipoib_cm_start_rx_drain() calls ib_post_send() and *then* moves the struct ipoib_cm_rx onto the rx_drain_list. The ib_post_send() will trigger a completion callback to ipoib_cm_handle_rx_wc() which tries to move the rx_drain_list to the rx_reap_list but if the callback happens before ipoib_cm_start_rx_drain() has moved the structure, it is left in limbo. The fix is to change ipoib_cm_start_rx_drain() to put the struct on the rx_drain_list and then call ib_post_send().
Also, only move one struct from rx_flush_list to rx_drain_list since concurrent IPOIB_CM_RX_DRAIN_WRID events on different QPs could put multiple ipoib_cm_rx structs on rx_flush_list.

---

 drivers/infiniband/ulp/ipoib/ipoib_cm.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
drivers/infiniband/ulp/ipoib/ipoib_cm.c +9 -3
index bb10041..dfff159 100644
@@ -216,15 +216,21 @@ static void ipoib_cm_start_rx_drain(struct ipoib_dev_priv *priv)
 	    !list_empty(&priv->cm.rx_drain_list))
 		return;
 
+	p = list_entry(priv->cm.rx_flush_list.next, typeof(*p), list);
+
+	/*
+	 * Put p on rx_drain_list before calling ib_post_send() or there
+	 * is a race with the ipoib_cm_handle_rx_wc() completion handler
+	 * trying to remove it from rx_drain_list.
+	 */
+	list_move(&p->list, &priv->cm.rx_drain_list);
+
 	/*
 	 * QPs on flush list are error state.  This way, a "flush
 	 * error" WC will be immediately generated for each WR we post.
 	 */
-	p = list_entry(priv->cm.rx_flush_list.next, typeof(*p), list);
 	if (ib_post_send(p->qp, &ipoib_cm_rx_drain_wr, &bad_wr))
 		ipoib_warn(priv, "failed to post drain wr\n");
-
-	list_splice_init(&priv->cm.rx_flush_list, &priv->cm.rx_drain_list);
 }
 
 static void ipoib_cm_rx_event_handler(struct ib_event *event, void *ctx)
#9 lore raw
In reply to a message not in the archive
Quoted 9 lines · Ralph Campbell

I was looking at the Rx connection tear down and found a bug. I don't know if it would cause this panic but you might try it. I haven't stress tested it but it compiles and basic network connections work.

I also don't like the call to cancel_delayed_work(&priv->cm.stale_task) at the end of ipoib_cm_dev_stop(). I think it should be called after ib_destroy_cm_id() and priv->cm.id = NULL.

Ralph,

I have managed to recreate this crash a few times under stress. I expect to be able to try your patch some time next week, and will let you know. Thanks for taking time to look into this.

Thanks
Pradeep

Quoted 40 lines · Pradeep Satyanarayana
Quoted 39 lines

Ralph,

I see the following crash sporadically (only under stress) with a Sles11SP1 (which is 2.6.32 kernel). I saw this crash with V4 of your patch and have not yet had a chance to try V5. Have you seen this in your testing? If this not the crash stack can you please share what your patch fixes?

<4>ib0: RX drain timing out
<4>idr_remove called for id=11491974 which is not allocated.
<4>Call Trace:
<4>[c000000749fe33b0] [c0000000000129e4] .show_stack+0x6c/0x198 (unreliable) <4>[c000000749fe3460] [c0000000002ea594] .sub_remove+0x1ec/0x1f8 <4>[c000000749fe3520] [c0000000002ea5e0] .idr_remove+0x40/0xf8 <4>[c000000749fe35b0] [d000000012d84d70] .cm_destroy_id+0xa0/0x520 [ib_cm] <4>[c000000749fe3680] [d00000001b7fb644] .ipoib_cm_free_rx_reap_list+0xd4/0x190 [ib_ipoib] <4>[c000000749fe3740] [d00000001b7fe404] .ipoib_cm_dev_stop+0x23c/0x360 [ib_ipoib] <4>[c000000749fe3800] [d00000001b7f4dbc] .ipoib_ib_dev_stop+0xe4/0x4b0 [ib_ipoib] <4>[c000000749fe3960] [d00000001b7f0f30] .ipoib_stop+0x88/0x178 [ib_ipoib] <4>[c000000749fe39f0] [c0000000004eacf4] .dev_close+0xdc/0x148 <4>[c000000749fe3a80] [c0000000004ea2b8] .dev_change_flags+0x1f0/0x288 <4>[c000000749fe3b20] [d00000001b7f11b8] .ipoib_remove_one+0xb8/0x140 [ib_ipoib] <4>[c000000749fe3bc0] [d00000001210425c] .ib_unregister_client+0xb4/0x1b8 [ib_core] <4>[c000000749fe3c90] [d00000001b7ffde8] .ipoib_cleanup_module+0x20/0x60 [ib_ipoib] <4>[c000000749fe3d20] [c0000000000ec408] .SyS_delete_module+0x238/0x320 <4>[c000000749fe3e30] [c0000000000085b4] syscall_exit+0x0/0x40
<1>Unable to handle kernel paging request for data at address 0x45000027228d1ffb <1>Faulting instruction address: 0xc0000000005a8e88
12:mon> e
cpu 0x12: Vector: 300 (Data Access) at [c000000749fe3250]

    pc: c0000000005a8e88: .wait_for_common+0xb8/0x268
    lr: c0000000005a8e20: .wait_for_common+0x50/0x268
    sp: c000000749fe34d0
   msr: 8000000000009032
   dar: 45000027228d1ffb
 dsisr: 42000000
  current = 0xc00000074b4ce0e0
  paca    = 0xc000000000f64a00
    pid   = 13605, comm = modprobe

12:mon>

Quoted 3 lines
Quoted 2 lines

Thanks
Pradeep

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html