2007-02-06 04:12:23 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006 Mellanox Technologies. All rights reserved
|
|
|
|
*
|
|
|
|
* This software is available to you under a choice of one of two
|
|
|
|
* licenses. You may choose to be licensed under the terms of the GNU
|
|
|
|
* General Public License (GPL) Version 2, available from the file
|
|
|
|
* COPYING in the main directory of this source tree, or the
|
|
|
|
* OpenIB.org BSD license below:
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or
|
|
|
|
* without modification, are permitted provided that the following
|
|
|
|
* conditions are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials
|
|
|
|
* provided with the distribution.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rdma/ib_cm.h>
|
|
|
|
#include <net/dst.h>
|
|
|
|
#include <net/icmp.h>
|
|
|
|
#include <linux/icmpv6.h>
|
2007-05-21 20:04:59 +08:00
|
|
|
#include <linux/delay.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2008-03-12 22:51:03 +08:00
|
|
|
#include <linux/vmalloc.h>
|
2011-08-31 00:32:52 +08:00
|
|
|
#include <linux/moduleparam.h>
|
2007-02-06 04:12:23 +08:00
|
|
|
|
2008-01-26 06:15:24 +08:00
|
|
|
#include "ipoib.h"
|
|
|
|
|
|
|
|
int ipoib_max_conn_qp = 128;
|
|
|
|
|
|
|
|
module_param_named(max_nonsrq_conn_qp, ipoib_max_conn_qp, int, 0444);
|
|
|
|
MODULE_PARM_DESC(max_nonsrq_conn_qp,
|
|
|
|
"Max number of connected-mode QPs per interface "
|
|
|
|
"(applied only if shared receive queue is not available)");
|
|
|
|
|
2007-02-06 04:12:23 +08:00
|
|
|
#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
|
|
|
|
static int data_debug_level;
|
|
|
|
|
|
|
|
module_param_named(cm_data_debug_level, data_debug_level, int, 0644);
|
|
|
|
MODULE_PARM_DESC(cm_data_debug_level,
|
|
|
|
"Enable data path debug tracing for connected mode if > 0");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define IPOIB_CM_IETF_ID 0x1000000000000000ULL
|
|
|
|
|
|
|
|
#define IPOIB_CM_RX_UPDATE_TIME (256 * HZ)
|
|
|
|
#define IPOIB_CM_RX_TIMEOUT (2 * 256 * HZ)
|
|
|
|
#define IPOIB_CM_RX_DELAY (3 * 256 * HZ)
|
|
|
|
#define IPOIB_CM_RX_UPDATE_MASK (0x3)
|
|
|
|
|
2007-05-21 20:04:59 +08:00
|
|
|
static struct ib_qp_attr ipoib_cm_err_attr = {
|
|
|
|
.qp_state = IB_QPS_ERR
|
|
|
|
};
|
|
|
|
|
2007-10-27 04:44:25 +08:00
|
|
|
#define IPOIB_CM_RX_DRAIN_WRID 0xffffffff
|
2007-05-21 20:04:59 +08:00
|
|
|
|
2007-05-28 19:37:27 +08:00
|
|
|
static struct ib_send_wr ipoib_cm_rx_drain_wr = {
|
|
|
|
.opcode = IB_WR_SEND,
|
2007-05-21 20:04:59 +08:00
|
|
|
};
|
|
|
|
|
2007-02-06 04:12:23 +08:00
|
|
|
static int ipoib_cm_tx_handler(struct ib_cm_id *cm_id,
|
|
|
|
struct ib_cm_event *event);
|
|
|
|
|
2007-02-21 02:17:55 +08:00
|
|
|
static void ipoib_cm_dma_unmap_rx(struct ipoib_dev_priv *priv, int frags,
|
2007-02-06 04:12:23 +08:00
|
|
|
u64 mapping[IPOIB_CM_RX_SG])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ib_dma_unmap_single(priv->ca, mapping[0], IPOIB_CM_HEAD_SIZE, DMA_FROM_DEVICE);
|
|
|
|
|
2007-02-21 02:17:55 +08:00
|
|
|
for (i = 0; i < frags; ++i)
|
2011-10-18 21:22:14 +08:00
|
|
|
ib_dma_unmap_page(priv->ca, mapping[i + 1], PAGE_SIZE, DMA_FROM_DEVICE);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
2008-01-26 06:15:24 +08:00
|
|
|
static int ipoib_cm_post_receive_srq(struct net_device *dev, int id)
|
2007-02-06 04:12:23 +08:00
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
struct ib_recv_wr *bad_wr;
|
|
|
|
int i, ret;
|
|
|
|
|
2007-08-16 20:36:16 +08:00
|
|
|
priv->cm.rx_wr.wr_id = id | IPOIB_OP_CM | IPOIB_OP_RECV;
|
2007-02-06 04:12:23 +08:00
|
|
|
|
2007-12-22 05:08:23 +08:00
|
|
|
for (i = 0; i < priv->cm.num_frags; ++i)
|
2007-02-06 04:12:23 +08:00
|
|
|
priv->cm.rx_sge[i].addr = priv->cm.srq_ring[id].mapping[i];
|
|
|
|
|
|
|
|
ret = ib_post_srq_recv(priv->cm.srq, &priv->cm.rx_wr, &bad_wr);
|
|
|
|
if (unlikely(ret)) {
|
|
|
|
ipoib_warn(priv, "post srq failed for buf %d (%d)\n", id, ret);
|
2007-12-22 05:08:23 +08:00
|
|
|
ipoib_cm_dma_unmap_rx(priv, priv->cm.num_frags - 1,
|
2007-02-21 02:17:55 +08:00
|
|
|
priv->cm.srq_ring[id].mapping);
|
2007-02-06 04:12:23 +08:00
|
|
|
dev_kfree_skb_any(priv->cm.srq_ring[id].skb);
|
|
|
|
priv->cm.srq_ring[id].skb = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-01-26 06:15:24 +08:00
|
|
|
static int ipoib_cm_post_receive_nonsrq(struct net_device *dev,
|
2008-07-15 14:48:47 +08:00
|
|
|
struct ipoib_cm_rx *rx,
|
|
|
|
struct ib_recv_wr *wr,
|
|
|
|
struct ib_sge *sge, int id)
|
2008-01-26 06:15:24 +08:00
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
struct ib_recv_wr *bad_wr;
|
|
|
|
int i, ret;
|
|
|
|
|
2008-07-15 14:48:47 +08:00
|
|
|
wr->wr_id = id | IPOIB_OP_CM | IPOIB_OP_RECV;
|
2008-01-26 06:15:24 +08:00
|
|
|
|
|
|
|
for (i = 0; i < IPOIB_CM_RX_SG; ++i)
|
2008-07-15 14:48:47 +08:00
|
|
|
sge[i].addr = rx->rx_ring[id].mapping[i];
|
2008-01-26 06:15:24 +08:00
|
|
|
|
2008-07-15 14:48:47 +08:00
|
|
|
ret = ib_post_recv(rx->qp, wr, &bad_wr);
|
2008-01-26 06:15:24 +08:00
|
|
|
if (unlikely(ret)) {
|
|
|
|
ipoib_warn(priv, "post recv failed for buf %d (%d)\n", id, ret);
|
|
|
|
ipoib_cm_dma_unmap_rx(priv, IPOIB_CM_RX_SG - 1,
|
|
|
|
rx->rx_ring[id].mapping);
|
|
|
|
dev_kfree_skb_any(rx->rx_ring[id].skb);
|
|
|
|
rx->rx_ring[id].skb = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sk_buff *ipoib_cm_alloc_rx_skb(struct net_device *dev,
|
|
|
|
struct ipoib_cm_rx_buf *rx_ring,
|
|
|
|
int id, int frags,
|
2013-10-16 22:37:48 +08:00
|
|
|
u64 mapping[IPOIB_CM_RX_SG],
|
|
|
|
gfp_t gfp)
|
2007-02-06 04:12:23 +08:00
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
struct sk_buff *skb;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
skb = dev_alloc_skb(IPOIB_CM_HEAD_SIZE + 12);
|
|
|
|
if (unlikely(!skb))
|
2007-02-21 02:17:55 +08:00
|
|
|
return NULL;
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IPoIB adds a 4 byte header. So we need 12 more bytes to align the
|
|
|
|
* IP header to a multiple of 16.
|
|
|
|
*/
|
|
|
|
skb_reserve(skb, 12);
|
|
|
|
|
|
|
|
mapping[0] = ib_dma_map_single(priv->ca, skb->data, IPOIB_CM_HEAD_SIZE,
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
if (unlikely(ib_dma_mapping_error(priv->ca, mapping[0]))) {
|
|
|
|
dev_kfree_skb_any(skb);
|
2007-02-21 02:17:55 +08:00
|
|
|
return NULL;
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
2007-02-21 02:17:55 +08:00
|
|
|
for (i = 0; i < frags; i++) {
|
2013-10-16 22:37:48 +08:00
|
|
|
struct page *page = alloc_page(gfp);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
if (!page)
|
|
|
|
goto partial_error;
|
|
|
|
skb_fill_page_desc(skb, i, page, 0, PAGE_SIZE);
|
|
|
|
|
2011-08-25 06:28:10 +08:00
|
|
|
mapping[i + 1] = ib_dma_map_page(priv->ca, page,
|
2007-04-10 23:32:42 +08:00
|
|
|
0, PAGE_SIZE, DMA_FROM_DEVICE);
|
2007-02-06 04:12:23 +08:00
|
|
|
if (unlikely(ib_dma_mapping_error(priv->ca, mapping[i + 1])))
|
|
|
|
goto partial_error;
|
|
|
|
}
|
|
|
|
|
2008-01-26 06:15:24 +08:00
|
|
|
rx_ring[id].skb = skb;
|
2007-02-21 02:17:55 +08:00
|
|
|
return skb;
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
partial_error:
|
|
|
|
|
|
|
|
ib_dma_unmap_single(priv->ca, mapping[0], IPOIB_CM_HEAD_SIZE, DMA_FROM_DEVICE);
|
|
|
|
|
2007-06-30 02:37:56 +08:00
|
|
|
for (; i > 0; --i)
|
2011-10-18 21:22:14 +08:00
|
|
|
ib_dma_unmap_page(priv->ca, mapping[i], PAGE_SIZE, DMA_FROM_DEVICE);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
2007-02-16 06:16:13 +08:00
|
|
|
dev_kfree_skb_any(skb);
|
2007-02-21 02:17:55 +08:00
|
|
|
return NULL;
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
2008-01-26 06:15:24 +08:00
|
|
|
static void ipoib_cm_free_rx_ring(struct net_device *dev,
|
|
|
|
struct ipoib_cm_rx_buf *rx_ring)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ipoib_recvq_size; ++i)
|
|
|
|
if (rx_ring[i].skb) {
|
|
|
|
ipoib_cm_dma_unmap_rx(priv, IPOIB_CM_RX_SG - 1,
|
|
|
|
rx_ring[i].mapping);
|
|
|
|
dev_kfree_skb_any(rx_ring[i].skb);
|
|
|
|
}
|
|
|
|
|
2008-08-09 06:51:29 +08:00
|
|
|
vfree(rx_ring);
|
2008-01-26 06:15:24 +08:00
|
|
|
}
|
|
|
|
|
2007-10-24 10:57:54 +08:00
|
|
|
static void ipoib_cm_start_rx_drain(struct ipoib_dev_priv *priv)
|
2007-05-21 20:04:59 +08:00
|
|
|
{
|
2007-05-28 19:37:27 +08:00
|
|
|
struct ib_send_wr *bad_wr;
|
|
|
|
struct ipoib_cm_rx *p;
|
2007-05-21 20:04:59 +08:00
|
|
|
|
2007-05-28 19:37:27 +08:00
|
|
|
/* We only reserved 1 extra slot in CQ for drain WRs, so
|
2007-05-21 20:04:59 +08:00
|
|
|
* make sure we have at most 1 outstanding WR. */
|
|
|
|
if (list_empty(&priv->cm.rx_flush_list) ||
|
|
|
|
!list_empty(&priv->cm.rx_drain_list))
|
|
|
|
return;
|
|
|
|
|
2007-05-28 19:37:27 +08:00
|
|
|
/*
|
|
|
|
* 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);
|
2015-12-12 03:53:03 +08:00
|
|
|
ipoib_cm_rx_drain_wr.wr_id = IPOIB_CM_RX_DRAIN_WRID;
|
2007-05-28 19:37:27 +08:00
|
|
|
if (ib_post_send(p->qp, &ipoib_cm_rx_drain_wr, &bad_wr))
|
|
|
|
ipoib_warn(priv, "failed to post drain wr\n");
|
2007-05-21 20:04:59 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
struct ipoib_cm_rx *p = ctx;
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(p->dev);
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (event->event != IB_EVENT_QP_LAST_WQE_REACHED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
list_move(&p->list, &priv->cm.rx_flush_list);
|
|
|
|
p->state = IPOIB_CM_RX_FLUSH;
|
|
|
|
ipoib_cm_start_rx_drain(priv);
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
}
|
|
|
|
|
2007-02-06 04:12:23 +08:00
|
|
|
static struct ib_qp *ipoib_cm_create_rx_qp(struct net_device *dev,
|
|
|
|
struct ipoib_cm_rx *p)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
struct ib_qp_init_attr attr = {
|
2007-05-21 20:04:59 +08:00
|
|
|
.event_handler = ipoib_cm_rx_event_handler,
|
2008-04-30 04:46:53 +08:00
|
|
|
.send_cq = priv->recv_cq, /* For drain WR */
|
|
|
|
.recv_cq = priv->recv_cq,
|
2007-02-06 04:12:23 +08:00
|
|
|
.srq = priv->cm.srq,
|
2007-05-28 19:37:27 +08:00
|
|
|
.cap.max_send_wr = 1, /* For drain WR */
|
2007-02-06 04:12:23 +08:00
|
|
|
.cap.max_send_sge = 1, /* FIXME: 0 Seems not to work */
|
|
|
|
.sq_sig_type = IB_SIGNAL_ALL_WR,
|
|
|
|
.qp_type = IB_QPT_RC,
|
|
|
|
.qp_context = p,
|
|
|
|
};
|
2008-01-26 06:15:24 +08:00
|
|
|
|
|
|
|
if (!ipoib_cm_has_srq(dev)) {
|
|
|
|
attr.cap.max_recv_wr = ipoib_recvq_size;
|
|
|
|
attr.cap.max_recv_sge = IPOIB_CM_RX_SG;
|
|
|
|
}
|
|
|
|
|
2007-02-06 04:12:23 +08:00
|
|
|
return ib_create_qp(priv->pd, &attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ipoib_cm_modify_rx_qp(struct net_device *dev,
|
2008-01-26 06:15:24 +08:00
|
|
|
struct ib_cm_id *cm_id, struct ib_qp *qp,
|
|
|
|
unsigned psn)
|
2007-02-06 04:12:23 +08:00
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
struct ib_qp_attr qp_attr;
|
|
|
|
int qp_attr_mask, ret;
|
|
|
|
|
|
|
|
qp_attr.qp_state = IB_QPS_INIT;
|
|
|
|
ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &qp_attr_mask);
|
|
|
|
if (ret) {
|
|
|
|
ipoib_warn(priv, "failed to init QP attr for INIT: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = ib_modify_qp(qp, &qp_attr, qp_attr_mask);
|
|
|
|
if (ret) {
|
|
|
|
ipoib_warn(priv, "failed to modify QP to INIT: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
qp_attr.qp_state = IB_QPS_RTR;
|
|
|
|
ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &qp_attr_mask);
|
|
|
|
if (ret) {
|
|
|
|
ipoib_warn(priv, "failed to init QP attr for RTR: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
qp_attr.rq_psn = psn;
|
|
|
|
ret = ib_modify_qp(qp, &qp_attr, qp_attr_mask);
|
|
|
|
if (ret) {
|
|
|
|
ipoib_warn(priv, "failed to modify QP to RTR: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2007-05-28 19:37:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Current Mellanox HCA firmware won't generate completions
|
|
|
|
* with error for drain WRs unless the QP has been moved to
|
|
|
|
* RTS first. This work-around leaves a window where a QP has
|
|
|
|
* moved to error asynchronously, but this will eventually get
|
|
|
|
* fixed in firmware, so let's not error out if modify QP
|
|
|
|
* fails.
|
|
|
|
*/
|
|
|
|
qp_attr.qp_state = IB_QPS_RTS;
|
|
|
|
ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &qp_attr_mask);
|
|
|
|
if (ret) {
|
|
|
|
ipoib_warn(priv, "failed to init QP attr for RTS: %d\n", ret);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ret = ib_modify_qp(qp, &qp_attr, qp_attr_mask);
|
|
|
|
if (ret) {
|
|
|
|
ipoib_warn(priv, "failed to modify QP to RTS: %d\n", ret);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-06 04:12:23 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-15 14:48:47 +08:00
|
|
|
static void ipoib_cm_init_rx_wr(struct net_device *dev,
|
|
|
|
struct ib_recv_wr *wr,
|
|
|
|
struct ib_sge *sge)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < priv->cm.num_frags; ++i)
|
2015-07-31 07:22:17 +08:00
|
|
|
sge[i].lkey = priv->pd->local_dma_lkey;
|
2008-07-15 14:48:47 +08:00
|
|
|
|
|
|
|
sge[0].length = IPOIB_CM_HEAD_SIZE;
|
|
|
|
for (i = 1; i < priv->cm.num_frags; ++i)
|
|
|
|
sge[i].length = PAGE_SIZE;
|
|
|
|
|
|
|
|
wr->next = NULL;
|
2008-07-30 22:21:46 +08:00
|
|
|
wr->sg_list = sge;
|
2008-07-15 14:48:47 +08:00
|
|
|
wr->num_sge = priv->cm.num_frags;
|
|
|
|
}
|
|
|
|
|
2008-01-26 06:15:24 +08:00
|
|
|
static int ipoib_cm_nonsrq_init_rx(struct net_device *dev, struct ib_cm_id *cm_id,
|
|
|
|
struct ipoib_cm_rx *rx)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
2008-07-15 14:48:47 +08:00
|
|
|
struct {
|
|
|
|
struct ib_recv_wr wr;
|
|
|
|
struct ib_sge sge[IPOIB_CM_RX_SG];
|
|
|
|
} *t;
|
2008-01-26 06:15:24 +08:00
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
2010-11-05 11:07:36 +08:00
|
|
|
rx->rx_ring = vzalloc(ipoib_recvq_size * sizeof *rx->rx_ring);
|
2008-08-09 06:51:29 +08:00
|
|
|
if (!rx->rx_ring) {
|
|
|
|
printk(KERN_WARNING "%s: failed to allocate CM non-SRQ ring (%d entries)\n",
|
|
|
|
priv->ca->name, ipoib_recvq_size);
|
2008-01-26 06:15:24 +08:00
|
|
|
return -ENOMEM;
|
2008-08-09 06:51:29 +08:00
|
|
|
}
|
|
|
|
|
2008-07-15 14:48:47 +08:00
|
|
|
t = kmalloc(sizeof *t, GFP_KERNEL);
|
|
|
|
if (!t) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
ipoib_cm_init_rx_wr(dev, &t->wr, t->sge);
|
|
|
|
|
2008-01-26 06:15:24 +08:00
|
|
|
spin_lock_irq(&priv->lock);
|
|
|
|
|
|
|
|
if (priv->cm.nonsrq_conn_qp >= ipoib_max_conn_qp) {
|
|
|
|
spin_unlock_irq(&priv->lock);
|
|
|
|
ib_send_cm_rej(cm_id, IB_CM_REJ_NO_QP, NULL, 0, NULL, 0);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err_free;
|
|
|
|
} else
|
|
|
|
++priv->cm.nonsrq_conn_qp;
|
|
|
|
|
|
|
|
spin_unlock_irq(&priv->lock);
|
|
|
|
|
|
|
|
for (i = 0; i < ipoib_recvq_size; ++i) {
|
|
|
|
if (!ipoib_cm_alloc_rx_skb(dev, rx->rx_ring, i, IPOIB_CM_RX_SG - 1,
|
2013-10-16 22:37:48 +08:00
|
|
|
rx->rx_ring[i].mapping,
|
|
|
|
GFP_KERNEL)) {
|
2008-01-26 06:15:24 +08:00
|
|
|
ipoib_warn(priv, "failed to allocate receive buffer %d\n", i);
|
2015-05-05 19:01:39 +08:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_count;
|
2008-07-15 14:48:47 +08:00
|
|
|
}
|
|
|
|
ret = ipoib_cm_post_receive_nonsrq(dev, rx, &t->wr, t->sge, i);
|
2008-01-26 06:15:24 +08:00
|
|
|
if (ret) {
|
|
|
|
ipoib_warn(priv, "ipoib_cm_post_receive_nonsrq "
|
|
|
|
"failed for buf %d\n", i);
|
|
|
|
ret = -EIO;
|
|
|
|
goto err_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rx->recv_count = ipoib_recvq_size;
|
|
|
|
|
2008-07-15 14:48:47 +08:00
|
|
|
kfree(t);
|
|
|
|
|
2008-01-26 06:15:24 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_count:
|
|
|
|
spin_lock_irq(&priv->lock);
|
|
|
|
--priv->cm.nonsrq_conn_qp;
|
|
|
|
spin_unlock_irq(&priv->lock);
|
|
|
|
|
|
|
|
err_free:
|
2008-07-15 14:48:47 +08:00
|
|
|
kfree(t);
|
2008-01-26 06:15:24 +08:00
|
|
|
ipoib_cm_free_rx_ring(dev, rx->rx_ring);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-02-06 04:12:23 +08:00
|
|
|
static int ipoib_cm_send_rep(struct net_device *dev, struct ib_cm_id *cm_id,
|
|
|
|
struct ib_qp *qp, struct ib_cm_req_event_param *req,
|
|
|
|
unsigned psn)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
struct ipoib_cm_data data = {};
|
|
|
|
struct ib_cm_rep_param rep = {};
|
|
|
|
|
|
|
|
data.qpn = cpu_to_be32(priv->qp->qp_num);
|
|
|
|
data.mtu = cpu_to_be32(IPOIB_CM_BUF_SIZE);
|
|
|
|
|
|
|
|
rep.private_data = &data;
|
|
|
|
rep.private_data_len = sizeof data;
|
|
|
|
rep.flow_control = 0;
|
|
|
|
rep.rnr_retry_count = req->rnr_retry_count;
|
2008-01-26 06:15:24 +08:00
|
|
|
rep.srq = ipoib_cm_has_srq(dev);
|
2007-02-06 04:12:23 +08:00
|
|
|
rep.qp_num = qp->qp_num;
|
|
|
|
rep.starting_psn = psn;
|
|
|
|
return ib_send_cm_rep(cm_id, &rep);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ipoib_cm_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
|
|
|
|
{
|
|
|
|
struct net_device *dev = cm_id->context;
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
struct ipoib_cm_rx *p;
|
|
|
|
unsigned psn;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ipoib_dbg(priv, "REQ arrived\n");
|
|
|
|
p = kzalloc(sizeof *p, GFP_KERNEL);
|
|
|
|
if (!p)
|
|
|
|
return -ENOMEM;
|
|
|
|
p->dev = dev;
|
|
|
|
p->id = cm_id;
|
2007-06-19 18:40:41 +08:00
|
|
|
cm_id->context = p;
|
|
|
|
p->state = IPOIB_CM_RX_LIVE;
|
|
|
|
p->jiffies = jiffies;
|
|
|
|
INIT_LIST_HEAD(&p->list);
|
|
|
|
|
2007-02-06 04:12:23 +08:00
|
|
|
p->qp = ipoib_cm_create_rx_qp(dev, p);
|
|
|
|
if (IS_ERR(p->qp)) {
|
|
|
|
ret = PTR_ERR(p->qp);
|
|
|
|
goto err_qp;
|
|
|
|
}
|
|
|
|
|
2013-05-08 07:18:16 +08:00
|
|
|
psn = prandom_u32() & 0xffffff;
|
2007-02-06 04:12:23 +08:00
|
|
|
ret = ipoib_cm_modify_rx_qp(dev, cm_id, p->qp, psn);
|
|
|
|
if (ret)
|
|
|
|
goto err_modify;
|
|
|
|
|
2008-01-26 06:15:24 +08:00
|
|
|
if (!ipoib_cm_has_srq(dev)) {
|
|
|
|
ret = ipoib_cm_nonsrq_init_rx(dev, cm_id, p);
|
|
|
|
if (ret)
|
|
|
|
goto err_modify;
|
|
|
|
}
|
|
|
|
|
2007-06-19 18:40:41 +08:00
|
|
|
spin_lock_irq(&priv->lock);
|
IB/ipoib: Use dedicated workqueues per interface
During my recent work on the rtnl lock deadlock in the IPoIB driver, I
saw that even once I fixed the apparent races for a single device, as
soon as that device had any children, new races popped up. It turns
out that this is because no matter how well we protect against races
on a single device, the fact that all devices use the same workqueue,
and flush_workqueue() flushes *everything* from that workqueue means
that we would also have to prevent all races between different devices
(for instance, ipoib_mcast_restart_task on interface ib0 can race with
ipoib_mcast_flush_dev on interface ib0.8002, resulting in a deadlock on
the rtnl_lock).
There are several possible solutions to this problem:
Make carrier_on_task and mcast_restart_task try to take the rtnl for
some set period of time and if they fail, then bail. This runs the
real risk of dropping work on the floor, which can end up being its
own separate kind of deadlock.
Set some global flag in the driver that says some device is in the
middle of going down, letting all tasks know to bail. Again, this can
drop work on the floor.
Or the method this patch attempts to use, which is when we bring an
interface up, create a workqueue specifically for that interface, so
that when we take it back down, we are flushing only those tasks
associated with our interface. In addition, keep the global
workqueue, but now limit it to only flush tasks. In this way, the
flush tasks can always flush the device specific work queues without
having deadlock issues.
Signed-off-by: Doug Ledford <dledford@redhat.com>
2015-02-22 08:27:03 +08:00
|
|
|
queue_delayed_work(priv->wq,
|
2007-06-19 18:40:41 +08:00
|
|
|
&priv->cm.stale_task, IPOIB_CM_RX_DELAY);
|
|
|
|
/* Add this entry to passive ids list head, but do not re-add it
|
|
|
|
* if IB_EVENT_QP_LAST_WQE_REACHED has moved it to flush list. */
|
|
|
|
p->jiffies = jiffies;
|
|
|
|
if (p->state == IPOIB_CM_RX_LIVE)
|
|
|
|
list_move(&p->list, &priv->cm.passive_ids);
|
|
|
|
spin_unlock_irq(&priv->lock);
|
|
|
|
|
2007-02-06 04:12:23 +08:00
|
|
|
ret = ipoib_cm_send_rep(dev, cm_id, p->qp, &event->param.req_rcvd, psn);
|
|
|
|
if (ret) {
|
|
|
|
ipoib_warn(priv, "failed to send REP: %d\n", ret);
|
2007-06-19 18:40:41 +08:00
|
|
|
if (ib_modify_qp(p->qp, &ipoib_cm_err_attr, IB_QP_STATE))
|
|
|
|
ipoib_warn(priv, "unable to move qp to error state\n");
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_modify:
|
|
|
|
ib_destroy_qp(p->qp);
|
|
|
|
err_qp:
|
|
|
|
kfree(p);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ipoib_cm_rx_handler(struct ib_cm_id *cm_id,
|
|
|
|
struct ib_cm_event *event)
|
|
|
|
{
|
|
|
|
struct ipoib_cm_rx *p;
|
|
|
|
struct ipoib_dev_priv *priv;
|
|
|
|
|
|
|
|
switch (event->event) {
|
|
|
|
case IB_CM_REQ_RECEIVED:
|
|
|
|
return ipoib_cm_req_handler(cm_id, event);
|
|
|
|
case IB_CM_DREQ_RECEIVED:
|
|
|
|
p = cm_id->context;
|
|
|
|
ib_send_cm_drep(cm_id, NULL, 0);
|
|
|
|
/* Fall through */
|
|
|
|
case IB_CM_REJ_RECEIVED:
|
|
|
|
p = cm_id->context;
|
|
|
|
priv = netdev_priv(p->dev);
|
2007-05-21 20:04:59 +08:00
|
|
|
if (ib_modify_qp(p->qp, &ipoib_cm_err_attr, IB_QP_STATE))
|
|
|
|
ipoib_warn(priv, "unable to move qp to error state\n");
|
|
|
|
/* Fall through */
|
2007-02-06 04:12:23 +08:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Adjust length of skb with fragments to match received data */
|
|
|
|
static void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space,
|
2007-02-21 02:17:55 +08:00
|
|
|
unsigned int length, struct sk_buff *toskb)
|
2007-02-06 04:12:23 +08:00
|
|
|
{
|
|
|
|
int i, num_frags;
|
|
|
|
unsigned int size;
|
|
|
|
|
|
|
|
/* put header into skb */
|
|
|
|
size = min(length, hdr_space);
|
|
|
|
skb->tail += size;
|
|
|
|
skb->len += size;
|
|
|
|
length -= size;
|
|
|
|
|
|
|
|
num_frags = skb_shinfo(skb)->nr_frags;
|
|
|
|
for (i = 0; i < num_frags; i++) {
|
|
|
|
skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
|
|
|
|
|
|
|
|
if (length == 0) {
|
|
|
|
/* don't need this page */
|
2011-08-25 06:28:10 +08:00
|
|
|
skb_fill_page_desc(toskb, i, skb_frag_page(frag),
|
|
|
|
0, PAGE_SIZE);
|
2007-02-06 04:12:23 +08:00
|
|
|
--skb_shinfo(skb)->nr_frags;
|
|
|
|
} else {
|
|
|
|
size = min(length, (unsigned) PAGE_SIZE);
|
|
|
|
|
2011-10-19 05:00:24 +08:00
|
|
|
skb_frag_size_set(frag, size);
|
2007-02-06 04:12:23 +08:00
|
|
|
skb->data_len += size;
|
|
|
|
skb->truesize += size;
|
|
|
|
skb->len += size;
|
|
|
|
length -= size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
2008-01-26 06:15:24 +08:00
|
|
|
struct ipoib_cm_rx_buf *rx_ring;
|
2007-08-16 20:36:16 +08:00
|
|
|
unsigned int wr_id = wc->wr_id & ~(IPOIB_OP_CM | IPOIB_OP_RECV);
|
2007-02-21 02:17:55 +08:00
|
|
|
struct sk_buff *skb, *newskb;
|
2007-02-06 04:12:23 +08:00
|
|
|
struct ipoib_cm_rx *p;
|
|
|
|
unsigned long flags;
|
|
|
|
u64 mapping[IPOIB_CM_RX_SG];
|
2007-02-21 02:17:55 +08:00
|
|
|
int frags;
|
2008-01-26 06:15:24 +08:00
|
|
|
int has_srq;
|
IPoIB: Copy small received SKBs in connected mode
The connected mode implementation in the IPoIB driver has a large
overhead in the way SKBs are handled in the receive flow. It usually
allocates an SKB with as big as was used in the currently received SKB
and moves unused fragments from the old SKB to the new one. This
involves a loop on all the remaining fragments and incurs overhead on
the CPU. This patch, for small SKBs, allocates an SKB just large
enough to contain the received data and copies to it the data from the
received SKB. The newly allocated SKB is passed to the stack and the
old SKB is reposted.
When running netperf, UDP small messages, without this pach I get:
UDP UNIDIRECTIONAL SEND TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to
14.4.3.178 (14.4.3.178) port 0 AF_INET
Socket Message Elapsed Messages
Size Size Time Okay Errors Throughput
bytes bytes secs # # 10^6bits/sec
114688 128 10.00 5142034 0 526.31
114688 10.00 1130489 115.71
With this patch I get both send and receive at ~315 mbps.
The reason that send performance actually slows down is as follows:
When using this patch, the overhead of the CPU for handling RX packets
is dramatically reduced. As a result, we do not experience RNR NAK
messages from the receiver which cause the connection to be closed and
reopened again; when the patch is not used, the receiver cannot handle
the packets fast enough so there is less time to post new buffers and
hence the mentioned RNR NACKs. So what happens is that the
application *thinks* it posted a certain number of packets for
transmission but these packets are flushed and do not really get
transmitted. Since the connection gets opened and closed many times,
each time netperf gets the CPU time that otherwise would have been
given to IPoIB to actually transmit the packets. This can be verified
when looking at the port counters -- the output of ifconfig and the
oputput of netperf (this is for the case without the patch):
tx packets
==========
port counter: 1,543,996
ifconfig: 1,581,426
netperf: 5,142,034
rx packets
==========
netperf 1,1304,089
Signed-off-by: Eli Cohen <eli@mellanox.co.il>
2008-07-15 14:48:44 +08:00
|
|
|
struct sk_buff *small_skb;
|
2007-02-06 04:12:23 +08:00
|
|
|
|
2007-04-19 11:20:53 +08:00
|
|
|
ipoib_dbg_data(priv, "cm recv completion: id %d, status: %d\n",
|
|
|
|
wr_id, wc->status);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
if (unlikely(wr_id >= ipoib_recvq_size)) {
|
2007-08-16 20:36:16 +08:00
|
|
|
if (wr_id == (IPOIB_CM_RX_DRAIN_WRID & ~(IPOIB_OP_CM | IPOIB_OP_RECV))) {
|
2007-05-21 20:04:59 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
list_splice_init(&priv->cm.rx_drain_list, &priv->cm.rx_reap_list);
|
|
|
|
ipoib_cm_start_rx_drain(priv);
|
IB/ipoib: Use dedicated workqueues per interface
During my recent work on the rtnl lock deadlock in the IPoIB driver, I
saw that even once I fixed the apparent races for a single device, as
soon as that device had any children, new races popped up. It turns
out that this is because no matter how well we protect against races
on a single device, the fact that all devices use the same workqueue,
and flush_workqueue() flushes *everything* from that workqueue means
that we would also have to prevent all races between different devices
(for instance, ipoib_mcast_restart_task on interface ib0 can race with
ipoib_mcast_flush_dev on interface ib0.8002, resulting in a deadlock on
the rtnl_lock).
There are several possible solutions to this problem:
Make carrier_on_task and mcast_restart_task try to take the rtnl for
some set period of time and if they fail, then bail. This runs the
real risk of dropping work on the floor, which can end up being its
own separate kind of deadlock.
Set some global flag in the driver that says some device is in the
middle of going down, letting all tasks know to bail. Again, this can
drop work on the floor.
Or the method this patch attempts to use, which is when we bring an
interface up, create a workqueue specifically for that interface, so
that when we take it back down, we are flushing only those tasks
associated with our interface. In addition, keep the global
workqueue, but now limit it to only flush tasks. In this way, the
flush tasks can always flush the device specific work queues without
having deadlock issues.
Signed-off-by: Doug Ledford <dledford@redhat.com>
2015-02-22 08:27:03 +08:00
|
|
|
queue_work(priv->wq, &priv->cm.rx_reap_task);
|
2007-05-21 20:04:59 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
} else
|
|
|
|
ipoib_warn(priv, "cm recv completion event with wrid %d (> %d)\n",
|
|
|
|
wr_id, ipoib_recvq_size);
|
2007-02-06 04:12:23 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-26 06:15:24 +08:00
|
|
|
p = wc->qp->qp_context;
|
|
|
|
|
|
|
|
has_srq = ipoib_cm_has_srq(dev);
|
|
|
|
rx_ring = has_srq ? priv->cm.srq_ring : p->rx_ring;
|
|
|
|
|
|
|
|
skb = rx_ring[wr_id].skb;
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
if (unlikely(wc->status != IB_WC_SUCCESS)) {
|
|
|
|
ipoib_dbg(priv, "cm recv error "
|
|
|
|
"(status=%d, wrid=%d vend_err %x)\n",
|
|
|
|
wc->status, wr_id, wc->vendor_err);
|
2007-09-29 06:33:51 +08:00
|
|
|
++dev->stats.rx_dropped;
|
2008-01-26 06:15:24 +08:00
|
|
|
if (has_srq)
|
|
|
|
goto repost;
|
|
|
|
else {
|
|
|
|
if (!--p->recv_count) {
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
list_move(&p->list, &priv->cm.rx_reap_list);
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
IB/ipoib: Use dedicated workqueues per interface
During my recent work on the rtnl lock deadlock in the IPoIB driver, I
saw that even once I fixed the apparent races for a single device, as
soon as that device had any children, new races popped up. It turns
out that this is because no matter how well we protect against races
on a single device, the fact that all devices use the same workqueue,
and flush_workqueue() flushes *everything* from that workqueue means
that we would also have to prevent all races between different devices
(for instance, ipoib_mcast_restart_task on interface ib0 can race with
ipoib_mcast_flush_dev on interface ib0.8002, resulting in a deadlock on
the rtnl_lock).
There are several possible solutions to this problem:
Make carrier_on_task and mcast_restart_task try to take the rtnl for
some set period of time and if they fail, then bail. This runs the
real risk of dropping work on the floor, which can end up being its
own separate kind of deadlock.
Set some global flag in the driver that says some device is in the
middle of going down, letting all tasks know to bail. Again, this can
drop work on the floor.
Or the method this patch attempts to use, which is when we bring an
interface up, create a workqueue specifically for that interface, so
that when we take it back down, we are flushing only those tasks
associated with our interface. In addition, keep the global
workqueue, but now limit it to only flush tasks. In this way, the
flush tasks can always flush the device specific work queues without
having deadlock issues.
Signed-off-by: Doug Ledford <dledford@redhat.com>
2015-02-22 08:27:03 +08:00
|
|
|
queue_work(priv->wq, &priv->cm.rx_reap_task);
|
2008-01-26 06:15:24 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
2007-10-18 12:54:44 +08:00
|
|
|
if (unlikely(!(wr_id & IPOIB_CM_RX_UPDATE_MASK))) {
|
2007-05-02 20:31:12 +08:00
|
|
|
if (p && time_after_eq(jiffies, p->jiffies + IPOIB_CM_RX_UPDATE_TIME)) {
|
2007-02-06 04:12:23 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
p->jiffies = jiffies;
|
2007-05-21 20:04:59 +08:00
|
|
|
/* Move this entry to list head, but do not re-add it
|
|
|
|
* if it has been moved out of list. */
|
|
|
|
if (p->state == IPOIB_CM_RX_LIVE)
|
2007-02-06 04:12:23 +08:00
|
|
|
list_move(&p->list, &priv->cm.passive_ids);
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
IPoIB: Copy small received SKBs in connected mode
The connected mode implementation in the IPoIB driver has a large
overhead in the way SKBs are handled in the receive flow. It usually
allocates an SKB with as big as was used in the currently received SKB
and moves unused fragments from the old SKB to the new one. This
involves a loop on all the remaining fragments and incurs overhead on
the CPU. This patch, for small SKBs, allocates an SKB just large
enough to contain the received data and copies to it the data from the
received SKB. The newly allocated SKB is passed to the stack and the
old SKB is reposted.
When running netperf, UDP small messages, without this pach I get:
UDP UNIDIRECTIONAL SEND TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to
14.4.3.178 (14.4.3.178) port 0 AF_INET
Socket Message Elapsed Messages
Size Size Time Okay Errors Throughput
bytes bytes secs # # 10^6bits/sec
114688 128 10.00 5142034 0 526.31
114688 10.00 1130489 115.71
With this patch I get both send and receive at ~315 mbps.
The reason that send performance actually slows down is as follows:
When using this patch, the overhead of the CPU for handling RX packets
is dramatically reduced. As a result, we do not experience RNR NAK
messages from the receiver which cause the connection to be closed and
reopened again; when the patch is not used, the receiver cannot handle
the packets fast enough so there is less time to post new buffers and
hence the mentioned RNR NACKs. So what happens is that the
application *thinks* it posted a certain number of packets for
transmission but these packets are flushed and do not really get
transmitted. Since the connection gets opened and closed many times,
each time netperf gets the CPU time that otherwise would have been
given to IPoIB to actually transmit the packets. This can be verified
when looking at the port counters -- the output of ifconfig and the
oputput of netperf (this is for the case without the patch):
tx packets
==========
port counter: 1,543,996
ifconfig: 1,581,426
netperf: 5,142,034
rx packets
==========
netperf 1,1304,089
Signed-off-by: Eli Cohen <eli@mellanox.co.il>
2008-07-15 14:48:44 +08:00
|
|
|
if (wc->byte_len < IPOIB_CM_COPYBREAK) {
|
|
|
|
int dlen = wc->byte_len;
|
|
|
|
|
|
|
|
small_skb = dev_alloc_skb(dlen + 12);
|
|
|
|
if (small_skb) {
|
|
|
|
skb_reserve(small_skb, 12);
|
|
|
|
ib_dma_sync_single_for_cpu(priv->ca, rx_ring[wr_id].mapping[0],
|
|
|
|
dlen, DMA_FROM_DEVICE);
|
|
|
|
skb_copy_from_linear_data(skb, small_skb->data, dlen);
|
|
|
|
ib_dma_sync_single_for_device(priv->ca, rx_ring[wr_id].mapping[0],
|
|
|
|
dlen, DMA_FROM_DEVICE);
|
|
|
|
skb_put(small_skb, dlen);
|
|
|
|
skb = small_skb;
|
|
|
|
goto copied;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-21 02:17:55 +08:00
|
|
|
frags = PAGE_ALIGN(wc->byte_len - min(wc->byte_len,
|
|
|
|
(unsigned)IPOIB_CM_HEAD_SIZE)) / PAGE_SIZE;
|
|
|
|
|
2013-10-16 22:37:48 +08:00
|
|
|
newskb = ipoib_cm_alloc_rx_skb(dev, rx_ring, wr_id, frags,
|
|
|
|
mapping, GFP_ATOMIC);
|
2007-02-21 02:17:55 +08:00
|
|
|
if (unlikely(!newskb)) {
|
2007-02-06 04:12:23 +08:00
|
|
|
/*
|
|
|
|
* If we can't allocate a new RX buffer, dump
|
|
|
|
* this packet and reuse the old buffer.
|
|
|
|
*/
|
|
|
|
ipoib_dbg(priv, "failed to allocate receive buffer %d\n", wr_id);
|
2007-09-29 06:33:51 +08:00
|
|
|
++dev->stats.rx_dropped;
|
2007-02-06 04:12:23 +08:00
|
|
|
goto repost;
|
|
|
|
}
|
|
|
|
|
2008-01-26 06:15:24 +08:00
|
|
|
ipoib_cm_dma_unmap_rx(priv, frags, rx_ring[wr_id].mapping);
|
|
|
|
memcpy(rx_ring[wr_id].mapping, mapping, (frags + 1) * sizeof *mapping);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n",
|
|
|
|
wc->byte_len, wc->slid);
|
|
|
|
|
2007-02-21 02:17:55 +08:00
|
|
|
skb_put_frags(skb, IPOIB_CM_HEAD_SIZE, wc->byte_len, newskb);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
IPoIB: Copy small received SKBs in connected mode
The connected mode implementation in the IPoIB driver has a large
overhead in the way SKBs are handled in the receive flow. It usually
allocates an SKB with as big as was used in the currently received SKB
and moves unused fragments from the old SKB to the new one. This
involves a loop on all the remaining fragments and incurs overhead on
the CPU. This patch, for small SKBs, allocates an SKB just large
enough to contain the received data and copies to it the data from the
received SKB. The newly allocated SKB is passed to the stack and the
old SKB is reposted.
When running netperf, UDP small messages, without this pach I get:
UDP UNIDIRECTIONAL SEND TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to
14.4.3.178 (14.4.3.178) port 0 AF_INET
Socket Message Elapsed Messages
Size Size Time Okay Errors Throughput
bytes bytes secs # # 10^6bits/sec
114688 128 10.00 5142034 0 526.31
114688 10.00 1130489 115.71
With this patch I get both send and receive at ~315 mbps.
The reason that send performance actually slows down is as follows:
When using this patch, the overhead of the CPU for handling RX packets
is dramatically reduced. As a result, we do not experience RNR NAK
messages from the receiver which cause the connection to be closed and
reopened again; when the patch is not used, the receiver cannot handle
the packets fast enough so there is less time to post new buffers and
hence the mentioned RNR NACKs. So what happens is that the
application *thinks* it posted a certain number of packets for
transmission but these packets are flushed and do not really get
transmitted. Since the connection gets opened and closed many times,
each time netperf gets the CPU time that otherwise would have been
given to IPoIB to actually transmit the packets. This can be verified
when looking at the port counters -- the output of ifconfig and the
oputput of netperf (this is for the case without the patch):
tx packets
==========
port counter: 1,543,996
ifconfig: 1,581,426
netperf: 5,142,034
rx packets
==========
netperf 1,1304,089
Signed-off-by: Eli Cohen <eli@mellanox.co.il>
2008-07-15 14:48:44 +08:00
|
|
|
copied:
|
2007-02-06 04:12:23 +08:00
|
|
|
skb->protocol = ((struct ipoib_header *) skb->data)->proto;
|
2007-03-20 06:30:44 +08:00
|
|
|
skb_reset_mac_header(skb);
|
2007-02-06 04:12:23 +08:00
|
|
|
skb_pull(skb, IPOIB_ENCAP_LEN);
|
|
|
|
|
2007-09-29 06:33:51 +08:00
|
|
|
++dev->stats.rx_packets;
|
|
|
|
dev->stats.rx_bytes += skb->len;
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
skb->dev = dev;
|
|
|
|
/* XXX get correct PACKET_ type here */
|
|
|
|
skb->pkt_type = PACKET_HOST;
|
2007-05-07 12:05:32 +08:00
|
|
|
netif_receive_skb(skb);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
repost:
|
2008-01-26 06:15:24 +08:00
|
|
|
if (has_srq) {
|
|
|
|
if (unlikely(ipoib_cm_post_receive_srq(dev, wr_id)))
|
|
|
|
ipoib_warn(priv, "ipoib_cm_post_receive_srq failed "
|
|
|
|
"for buf %d\n", wr_id);
|
|
|
|
} else {
|
2008-07-15 14:48:47 +08:00
|
|
|
if (unlikely(ipoib_cm_post_receive_nonsrq(dev, p,
|
|
|
|
&priv->cm.rx_wr,
|
|
|
|
priv->cm.rx_sge,
|
|
|
|
wr_id))) {
|
2008-01-26 06:15:24 +08:00
|
|
|
--p->recv_count;
|
|
|
|
ipoib_warn(priv, "ipoib_cm_post_receive_nonsrq failed "
|
|
|
|
"for buf %d\n", wr_id);
|
|
|
|
}
|
|
|
|
}
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int post_send(struct ipoib_dev_priv *priv,
|
|
|
|
struct ipoib_cm_tx *tx,
|
|
|
|
unsigned int wr_id,
|
2015-07-12 16:24:09 +08:00
|
|
|
struct ipoib_tx_buf *tx_req)
|
2007-02-06 04:12:23 +08:00
|
|
|
{
|
|
|
|
struct ib_send_wr *bad_wr;
|
|
|
|
|
2015-07-12 16:24:09 +08:00
|
|
|
ipoib_build_sge(priv, tx_req);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
2015-10-08 16:16:33 +08:00
|
|
|
priv->tx_wr.wr.wr_id = wr_id | IPOIB_OP_CM;
|
2007-02-06 04:12:23 +08:00
|
|
|
|
2015-10-08 16:16:33 +08:00
|
|
|
return ib_post_send(tx->qp, &priv->tx_wr.wr, &bad_wr);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ipoib_cm_send(struct net_device *dev, struct sk_buff *skb, struct ipoib_cm_tx *tx)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
2015-07-12 16:24:09 +08:00
|
|
|
struct ipoib_tx_buf *tx_req;
|
2010-03-04 21:17:37 +08:00
|
|
|
int rc;
|
2016-03-02 20:44:28 +08:00
|
|
|
unsigned usable_sge = tx->max_send_sge - !!skb_headlen(skb);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
if (unlikely(skb->len > tx->mtu)) {
|
|
|
|
ipoib_warn(priv, "packet len %d (> %d) too long to send, dropping\n",
|
|
|
|
skb->len, tx->mtu);
|
2007-09-29 06:33:51 +08:00
|
|
|
++dev->stats.tx_dropped;
|
|
|
|
++dev->stats.tx_errors;
|
2007-03-21 21:45:05 +08:00
|
|
|
ipoib_cm_skb_too_long(dev, skb, tx->mtu - IPOIB_ENCAP_LEN);
|
2007-02-06 04:12:23 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-03-02 20:44:28 +08:00
|
|
|
if (skb_shinfo(skb)->nr_frags > usable_sge) {
|
|
|
|
if (skb_linearize(skb) < 0) {
|
|
|
|
ipoib_warn(priv, "skb could not be linearized\n");
|
|
|
|
++dev->stats.tx_dropped;
|
|
|
|
++dev->stats.tx_errors;
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Does skb_linearize return ok without reducing nr_frags? */
|
|
|
|
if (skb_shinfo(skb)->nr_frags > usable_sge) {
|
|
|
|
ipoib_warn(priv, "too many frags after skb linearize\n");
|
|
|
|
++dev->stats.tx_dropped;
|
|
|
|
++dev->stats.tx_errors;
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-02-06 04:12:23 +08:00
|
|
|
ipoib_dbg_data(priv, "sending packet: head 0x%x length %d connection 0x%x\n",
|
|
|
|
tx->tx_head, skb->len, tx->qp->qp_num);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We put the skb into the tx_ring _before_ we call post_send()
|
|
|
|
* because it's entirely possible that the completion handler will
|
|
|
|
* run before we execute anything after the post_send(). That
|
|
|
|
* means we have to make sure everything is properly recorded and
|
|
|
|
* our state is consistent before we call post_send().
|
|
|
|
*/
|
|
|
|
tx_req = &tx->tx_ring[tx->tx_head & (ipoib_sendq_size - 1)];
|
|
|
|
tx_req->skb = skb;
|
2015-07-12 16:24:09 +08:00
|
|
|
|
|
|
|
if (unlikely(ipoib_dma_map_tx(priv->ca, tx_req))) {
|
2007-09-29 06:33:51 +08:00
|
|
|
++dev->stats.tx_errors;
|
2007-02-06 04:12:23 +08:00
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-04 23:29:10 +08:00
|
|
|
skb_orphan(skb);
|
|
|
|
skb_dst_drop(skb);
|
|
|
|
|
2015-07-12 16:24:09 +08:00
|
|
|
rc = post_send(priv, tx, tx->tx_head & (ipoib_sendq_size - 1), tx_req);
|
2010-03-04 21:17:37 +08:00
|
|
|
if (unlikely(rc)) {
|
|
|
|
ipoib_warn(priv, "post_send failed, error %d\n", rc);
|
2007-09-29 06:33:51 +08:00
|
|
|
++dev->stats.tx_errors;
|
2015-07-12 16:24:09 +08:00
|
|
|
ipoib_dma_unmap_tx(priv, tx_req);
|
2007-02-06 04:12:23 +08:00
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
} else {
|
2016-05-03 22:33:13 +08:00
|
|
|
netif_trans_update(dev);
|
2007-02-06 04:12:23 +08:00
|
|
|
++tx->tx_head;
|
|
|
|
|
2007-08-16 20:36:16 +08:00
|
|
|
if (++priv->tx_outstanding == ipoib_sendq_size) {
|
2007-02-06 04:12:23 +08:00
|
|
|
ipoib_dbg(priv, "TX ring 0x%x full, stopping kernel net queue\n",
|
|
|
|
tx->qp->qp_num);
|
|
|
|
netif_stop_queue(dev);
|
2013-02-26 23:46:27 +08:00
|
|
|
rc = ib_req_notify_cq(priv->send_cq,
|
|
|
|
IB_CQ_NEXT_COMP | IB_CQ_REPORT_MISSED_EVENTS);
|
|
|
|
if (rc < 0)
|
|
|
|
ipoib_warn(priv, "request notify on send CQ failed\n");
|
|
|
|
else if (rc)
|
|
|
|
ipoib_send_comp_handler(priv->send_cq, dev);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-16 20:36:16 +08:00
|
|
|
void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ib_wc *wc)
|
2007-02-06 04:12:23 +08:00
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
2007-08-16 20:36:16 +08:00
|
|
|
struct ipoib_cm_tx *tx = wc->qp->qp_context;
|
|
|
|
unsigned int wr_id = wc->wr_id & ~IPOIB_OP_CM;
|
2015-07-12 16:24:09 +08:00
|
|
|
struct ipoib_tx_buf *tx_req;
|
2007-02-06 04:12:23 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2007-04-19 11:20:53 +08:00
|
|
|
ipoib_dbg_data(priv, "cm send completion: id %d, status: %d\n",
|
|
|
|
wr_id, wc->status);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
if (unlikely(wr_id >= ipoib_sendq_size)) {
|
|
|
|
ipoib_warn(priv, "cm send completion event with wrid %d (> %d)\n",
|
|
|
|
wr_id, ipoib_sendq_size);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tx_req = &tx->tx_ring[wr_id];
|
|
|
|
|
2015-07-12 16:24:09 +08:00
|
|
|
ipoib_dma_unmap_tx(priv, tx_req);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
/* FIXME: is this right? Shouldn't we only increment on success? */
|
2007-09-29 06:33:51 +08:00
|
|
|
++dev->stats.tx_packets;
|
|
|
|
dev->stats.tx_bytes += tx_req->skb->len;
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
dev_kfree_skb_any(tx_req->skb);
|
|
|
|
|
2008-10-01 01:36:21 +08:00
|
|
|
netif_tx_lock(dev);
|
|
|
|
|
2007-02-06 04:12:23 +08:00
|
|
|
++tx->tx_tail;
|
2007-08-16 20:36:16 +08:00
|
|
|
if (unlikely(--priv->tx_outstanding == ipoib_sendq_size >> 1) &&
|
|
|
|
netif_queue_stopped(dev) &&
|
|
|
|
test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
|
2007-02-06 04:12:23 +08:00
|
|
|
netif_wake_queue(dev);
|
|
|
|
|
|
|
|
if (wc->status != IB_WC_SUCCESS &&
|
|
|
|
wc->status != IB_WC_WR_FLUSH_ERR) {
|
|
|
|
struct ipoib_neigh *neigh;
|
|
|
|
|
|
|
|
ipoib_dbg(priv, "failed cm send event "
|
|
|
|
"(status=%d, wrid=%d vend_err %x)\n",
|
|
|
|
wc->status, wr_id, wc->vendor_err);
|
|
|
|
|
2008-10-01 01:36:21 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2007-02-06 04:12:23 +08:00
|
|
|
neigh = tx->neigh;
|
|
|
|
|
|
|
|
if (neigh) {
|
|
|
|
neigh->cm = NULL;
|
IPoIB: Use a private hash table for path lookup in xmit path
Dave Miller <davem@davemloft.net> provided a detailed description of
why the way IPoIB is using neighbours for its own ipoib_neigh struct
is buggy:
Any time an ipoib_neigh is changed, a sequence like the following is made:
spin_lock_irqsave(&priv->lock, flags);
/*
* It's safe to call ipoib_put_ah() inside
* priv->lock here, because we know that
* path->ah will always hold one more reference,
* so ipoib_put_ah() will never do more than
* decrement the ref count.
*/
if (neigh->ah)
ipoib_put_ah(neigh->ah);
list_del(&neigh->list);
ipoib_neigh_free(dev, neigh);
spin_unlock_irqrestore(&priv->lock, flags);
ipoib_path_lookup(skb, n, dev);
This doesn't work, because you're leaving a stale pointer to the freed up
ipoib_neigh in the special neigh->ha pointer cookie. Yes, it even fails
with all the locking done to protect _changes_ to *ipoib_neigh(n), and
with the code in ipoib_neigh_free() that NULLs out the pointer.
The core issue is that read side calls to *to_ipoib_neigh(n) are not
being synchronized at all, they are performed without any locking. So
whether we hold the lock or not when making changes to *ipoib_neigh(n)
you still can have threads see references to freed up ipoib_neigh
objects.
cpu 1 cpu 2
n = *ipoib_neigh()
*ipoib_neigh() = NULL
kfree(n)
n->foo == OOPS
[..]
Perhaps the ipoib code can have a private path database it manages
entirely itself, which holds all the necessary information and is
looked up by some generic key which is available easily at transmit
time and does not involve generic neighbour entries.
See <http://marc.info/?l=linux-rdma&m=132812793105624&w=2> and
<http://marc.info/?l=linux-rdma&w=2&r=1&s=allows+references+to+freed+memory&q=b>
for the full discussion.
This patch aims to solve the race conditions found in the IPoIB driver.
The patch removes the connection between the core networking neighbour
structure and the ipoib_neigh structure. In addition to avoiding the
race described above, it allows us to handle SKBs carrying IP packets
that don't have any associated neighbour.
We add an ipoib_neigh hash table with N buckets where the key is the
destination hardware address. The ipoib_neigh is fetched from the
hash table and instead of the stashed location in the neighbour
structure. The hash table uses both RCU and reference counting to
guarantee that no ipoib_neigh instance is ever deleted while in use.
Fetching the ipoib_neigh structure instance from the hash also makes
the special code in ipoib_start_xmit that handles remote and local
bonding failover redundant.
Aged ipoib_neigh instances are deleted by a garbage collection task
that runs every M seconds and deletes every ipoib_neigh instance that
was idle for at least 2*M seconds. The deletion is safe since the
ipoib_neigh instances are protected using RCU and reference count
mechanisms.
The number of buckets (N) and frequency of running the GC thread (M),
are taken from the exported arb_tbl.
Signed-off-by: Shlomo Pongratz <shlomop@mellanox.com>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
2012-07-25 01:05:22 +08:00
|
|
|
ipoib_neigh_free(neigh);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
tx->neigh = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test_and_clear_bit(IPOIB_FLAG_INITIALIZED, &tx->flags)) {
|
|
|
|
list_move(&tx->list, &priv->cm.reap_list);
|
IB/ipoib: Use dedicated workqueues per interface
During my recent work on the rtnl lock deadlock in the IPoIB driver, I
saw that even once I fixed the apparent races for a single device, as
soon as that device had any children, new races popped up. It turns
out that this is because no matter how well we protect against races
on a single device, the fact that all devices use the same workqueue,
and flush_workqueue() flushes *everything* from that workqueue means
that we would also have to prevent all races between different devices
(for instance, ipoib_mcast_restart_task on interface ib0 can race with
ipoib_mcast_flush_dev on interface ib0.8002, resulting in a deadlock on
the rtnl_lock).
There are several possible solutions to this problem:
Make carrier_on_task and mcast_restart_task try to take the rtnl for
some set period of time and if they fail, then bail. This runs the
real risk of dropping work on the floor, which can end up being its
own separate kind of deadlock.
Set some global flag in the driver that says some device is in the
middle of going down, letting all tasks know to bail. Again, this can
drop work on the floor.
Or the method this patch attempts to use, which is when we bring an
interface up, create a workqueue specifically for that interface, so
that when we take it back down, we are flushing only those tasks
associated with our interface. In addition, keep the global
workqueue, but now limit it to only flush tasks. In this way, the
flush tasks can always flush the device specific work queues without
having deadlock issues.
Signed-off-by: Doug Ledford <dledford@redhat.com>
2015-02-22 08:27:03 +08:00
|
|
|
queue_work(priv->wq, &priv->cm.reap_task);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
clear_bit(IPOIB_FLAG_OPER_UP, &tx->flags);
|
|
|
|
|
2008-10-01 01:36:21 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
2008-10-01 01:36:21 +08:00
|
|
|
netif_tx_unlock(dev);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int ipoib_cm_dev_open(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!IPOIB_CM_SUPPORTED(dev->dev_addr))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
priv->cm.id = ib_create_cm_id(priv->ca, ipoib_cm_rx_handler, dev);
|
|
|
|
if (IS_ERR(priv->cm.id)) {
|
|
|
|
printk(KERN_WARNING "%s: failed to create CM ID\n", priv->ca->name);
|
2007-05-01 08:30:28 +08:00
|
|
|
ret = PTR_ERR(priv->cm.id);
|
2007-05-21 20:04:59 +08:00
|
|
|
goto err_cm;
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = ib_cm_listen(priv->cm.id, cpu_to_be64(IPOIB_CM_IETF_ID | priv->qp->qp_num),
|
2015-07-30 22:50:26 +08:00
|
|
|
0);
|
2007-02-06 04:12:23 +08:00
|
|
|
if (ret) {
|
|
|
|
printk(KERN_WARNING "%s: failed to listen on ID 0x%llx\n", priv->ca->name,
|
|
|
|
IPOIB_CM_IETF_ID | priv->qp->qp_num);
|
2007-05-21 20:04:59 +08:00
|
|
|
goto err_listen;
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
2007-05-21 20:04:59 +08:00
|
|
|
|
2007-02-06 04:12:23 +08:00
|
|
|
return 0;
|
2007-05-21 20:04:59 +08:00
|
|
|
|
|
|
|
err_listen:
|
|
|
|
ib_destroy_cm_id(priv->cm.id);
|
|
|
|
err_cm:
|
|
|
|
priv->cm.id = NULL;
|
|
|
|
return ret;
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
2008-01-26 06:15:24 +08:00
|
|
|
static void ipoib_cm_free_rx_reap_list(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
struct ipoib_cm_rx *rx, *n;
|
|
|
|
LIST_HEAD(list);
|
|
|
|
|
|
|
|
spin_lock_irq(&priv->lock);
|
|
|
|
list_splice_init(&priv->cm.rx_reap_list, &list);
|
|
|
|
spin_unlock_irq(&priv->lock);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(rx, n, &list, list) {
|
|
|
|
ib_destroy_cm_id(rx->id);
|
|
|
|
ib_destroy_qp(rx->qp);
|
2008-01-26 06:15:24 +08:00
|
|
|
if (!ipoib_cm_has_srq(dev)) {
|
|
|
|
ipoib_cm_free_rx_ring(priv->dev, rx->rx_ring);
|
|
|
|
spin_lock_irq(&priv->lock);
|
|
|
|
--priv->cm.nonsrq_conn_qp;
|
|
|
|
spin_unlock_irq(&priv->lock);
|
|
|
|
}
|
2008-01-26 06:15:24 +08:00
|
|
|
kfree(rx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-06 04:12:23 +08:00
|
|
|
void ipoib_cm_dev_stop(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
2008-01-26 06:15:24 +08:00
|
|
|
struct ipoib_cm_rx *p;
|
2007-05-21 20:04:59 +08:00
|
|
|
unsigned long begin;
|
|
|
|
int ret;
|
2007-02-06 04:12:23 +08:00
|
|
|
|
2007-05-01 08:30:28 +08:00
|
|
|
if (!IPOIB_CM_SUPPORTED(dev->dev_addr) || !priv->cm.id)
|
2007-02-06 04:12:23 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
ib_destroy_cm_id(priv->cm.id);
|
2007-05-01 08:30:28 +08:00
|
|
|
priv->cm.id = NULL;
|
2007-05-21 20:04:59 +08:00
|
|
|
|
2007-04-25 12:30:37 +08:00
|
|
|
spin_lock_irq(&priv->lock);
|
2007-02-06 04:12:23 +08:00
|
|
|
while (!list_empty(&priv->cm.passive_ids)) {
|
|
|
|
p = list_entry(priv->cm.passive_ids.next, typeof(*p), list);
|
2007-05-21 20:04:59 +08:00
|
|
|
list_move(&p->list, &priv->cm.rx_error_list);
|
|
|
|
p->state = IPOIB_CM_RX_ERROR;
|
2007-04-25 12:30:37 +08:00
|
|
|
spin_unlock_irq(&priv->lock);
|
2007-05-21 20:04:59 +08:00
|
|
|
ret = ib_modify_qp(p->qp, &ipoib_cm_err_attr, IB_QP_STATE);
|
|
|
|
if (ret)
|
|
|
|
ipoib_warn(priv, "unable to move qp to error state: %d\n", ret);
|
|
|
|
spin_lock_irq(&priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for all RX to be drained */
|
|
|
|
begin = jiffies;
|
|
|
|
|
|
|
|
while (!list_empty(&priv->cm.rx_error_list) ||
|
|
|
|
!list_empty(&priv->cm.rx_flush_list) ||
|
|
|
|
!list_empty(&priv->cm.rx_drain_list)) {
|
2007-05-25 05:02:39 +08:00
|
|
|
if (time_after(jiffies, begin + 5 * HZ)) {
|
2007-05-21 20:04:59 +08:00
|
|
|
ipoib_warn(priv, "RX drain timing out\n");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* assume the HW is wedged and just free up everything.
|
|
|
|
*/
|
2008-02-13 07:00:59 +08:00
|
|
|
list_splice_init(&priv->cm.rx_flush_list,
|
|
|
|
&priv->cm.rx_reap_list);
|
|
|
|
list_splice_init(&priv->cm.rx_error_list,
|
|
|
|
&priv->cm.rx_reap_list);
|
|
|
|
list_splice_init(&priv->cm.rx_drain_list,
|
|
|
|
&priv->cm.rx_reap_list);
|
2007-05-21 20:04:59 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
spin_unlock_irq(&priv->lock);
|
|
|
|
msleep(1);
|
2007-05-24 23:32:46 +08:00
|
|
|
ipoib_drain_cq(dev);
|
2007-05-21 20:04:59 +08:00
|
|
|
spin_lock_irq(&priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irq(&priv->lock);
|
|
|
|
|
2008-01-26 06:15:24 +08:00
|
|
|
ipoib_cm_free_rx_reap_list(dev);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
cancel_delayed_work(&priv->cm.stale_task);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ipoib_cm_rep_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
|
|
|
|
{
|
|
|
|
struct ipoib_cm_tx *p = cm_id->context;
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(p->dev);
|
|
|
|
struct ipoib_cm_data *data = event->private_data;
|
|
|
|
struct sk_buff_head skqueue;
|
|
|
|
struct ib_qp_attr qp_attr;
|
|
|
|
int qp_attr_mask, ret;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
|
|
|
p->mtu = be32_to_cpu(data->mtu);
|
|
|
|
|
2007-06-21 00:22:15 +08:00
|
|
|
if (p->mtu <= IPOIB_ENCAP_LEN) {
|
|
|
|
ipoib_warn(priv, "Rejecting connection: mtu %d <= %d\n",
|
|
|
|
p->mtu, IPOIB_ENCAP_LEN);
|
2007-02-06 04:12:23 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
qp_attr.qp_state = IB_QPS_RTR;
|
|
|
|
ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &qp_attr_mask);
|
|
|
|
if (ret) {
|
|
|
|
ipoib_warn(priv, "failed to init QP attr for RTR: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
qp_attr.rq_psn = 0 /* FIXME */;
|
|
|
|
ret = ib_modify_qp(p->qp, &qp_attr, qp_attr_mask);
|
|
|
|
if (ret) {
|
|
|
|
ipoib_warn(priv, "failed to modify QP to RTR: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
qp_attr.qp_state = IB_QPS_RTS;
|
|
|
|
ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &qp_attr_mask);
|
|
|
|
if (ret) {
|
|
|
|
ipoib_warn(priv, "failed to init QP attr for RTS: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = ib_modify_qp(p->qp, &qp_attr, qp_attr_mask);
|
|
|
|
if (ret) {
|
|
|
|
ipoib_warn(priv, "failed to modify QP to RTS: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_queue_head_init(&skqueue);
|
|
|
|
|
2007-04-25 12:30:37 +08:00
|
|
|
spin_lock_irq(&priv->lock);
|
2007-02-06 04:12:23 +08:00
|
|
|
set_bit(IPOIB_FLAG_OPER_UP, &p->flags);
|
|
|
|
if (p->neigh)
|
|
|
|
while ((skb = __skb_dequeue(&p->neigh->queue)))
|
|
|
|
__skb_queue_tail(&skqueue, skb);
|
2007-04-25 12:30:37 +08:00
|
|
|
spin_unlock_irq(&priv->lock);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
while ((skb = __skb_dequeue(&skqueue))) {
|
|
|
|
skb->dev = p->dev;
|
|
|
|
if (dev_queue_xmit(skb))
|
|
|
|
ipoib_warn(priv, "dev_queue_xmit failed "
|
|
|
|
"to requeue packet\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ib_send_cm_rtu(cm_id, NULL, 0);
|
|
|
|
if (ret) {
|
|
|
|
ipoib_warn(priv, "failed to send RTU: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-16 20:36:16 +08:00
|
|
|
static struct ib_qp *ipoib_cm_create_tx_qp(struct net_device *dev, struct ipoib_cm_tx *tx)
|
2007-02-06 04:12:23 +08:00
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
2007-10-07 15:30:48 +08:00
|
|
|
struct ib_qp_init_attr attr = {
|
2008-04-30 04:46:53 +08:00
|
|
|
.send_cq = priv->recv_cq,
|
|
|
|
.recv_cq = priv->recv_cq,
|
2007-10-07 15:30:48 +08:00
|
|
|
.srq = priv->cm.srq,
|
|
|
|
.cap.max_send_wr = ipoib_sendq_size,
|
|
|
|
.cap.max_send_sge = 1,
|
|
|
|
.sq_sig_type = IB_SIGNAL_ALL_WR,
|
|
|
|
.qp_type = IB_QPT_RC,
|
2014-05-11 20:15:11 +08:00
|
|
|
.qp_context = tx,
|
|
|
|
.create_flags = IB_QP_CREATE_USE_GFP_NOIO
|
2007-10-24 10:57:54 +08:00
|
|
|
};
|
2007-10-07 15:30:48 +08:00
|
|
|
|
2014-05-11 20:15:11 +08:00
|
|
|
struct ib_qp *tx_qp;
|
|
|
|
|
2015-07-12 16:24:09 +08:00
|
|
|
if (dev->features & NETIF_F_SG)
|
2016-03-02 20:44:28 +08:00
|
|
|
attr.cap.max_send_sge =
|
|
|
|
min_t(u32, priv->ca->attrs.max_sge, MAX_SKB_FRAGS + 1);
|
2015-07-12 16:24:09 +08:00
|
|
|
|
2014-05-11 20:15:11 +08:00
|
|
|
tx_qp = ib_create_qp(priv->pd, &attr);
|
|
|
|
if (PTR_ERR(tx_qp) == -EINVAL) {
|
|
|
|
ipoib_warn(priv, "can't use GFP_NOIO for QPs on device %s, using GFP_KERNEL\n",
|
|
|
|
priv->ca->name);
|
|
|
|
attr.create_flags &= ~IB_QP_CREATE_USE_GFP_NOIO;
|
|
|
|
tx_qp = ib_create_qp(priv->pd, &attr);
|
|
|
|
}
|
2016-03-02 20:44:28 +08:00
|
|
|
tx->max_send_sge = attr.cap.max_send_sge;
|
2014-05-11 20:15:11 +08:00
|
|
|
return tx_qp;
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ipoib_cm_send_req(struct net_device *dev,
|
|
|
|
struct ib_cm_id *id, struct ib_qp *qp,
|
|
|
|
u32 qpn,
|
|
|
|
struct ib_sa_path_rec *pathrec)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
struct ipoib_cm_data data = {};
|
|
|
|
struct ib_cm_req_param req = {};
|
|
|
|
|
|
|
|
data.qpn = cpu_to_be32(priv->qp->qp_num);
|
|
|
|
data.mtu = cpu_to_be32(IPOIB_CM_BUF_SIZE);
|
|
|
|
|
2007-10-24 10:57:54 +08:00
|
|
|
req.primary_path = pathrec;
|
|
|
|
req.alternate_path = NULL;
|
|
|
|
req.service_id = cpu_to_be64(IPOIB_CM_IETF_ID | qpn);
|
|
|
|
req.qp_num = qp->qp_num;
|
|
|
|
req.qp_type = qp->qp_type;
|
|
|
|
req.private_data = &data;
|
|
|
|
req.private_data_len = sizeof data;
|
|
|
|
req.flow_control = 0;
|
2007-02-06 04:12:23 +08:00
|
|
|
|
2007-10-24 10:57:54 +08:00
|
|
|
req.starting_psn = 0; /* FIXME */
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Pick some arbitrary defaults here; we could make these
|
|
|
|
* module parameters if anyone cared about setting them.
|
|
|
|
*/
|
2007-10-24 10:57:54 +08:00
|
|
|
req.responder_resources = 4;
|
|
|
|
req.remote_cm_response_timeout = 20;
|
|
|
|
req.local_cm_response_timeout = 20;
|
|
|
|
req.retry_count = 0; /* RFC draft warns against retries */
|
|
|
|
req.rnr_retry_count = 0; /* RFC draft warns against retries */
|
|
|
|
req.max_cm_retries = 15;
|
2008-01-26 06:15:24 +08:00
|
|
|
req.srq = ipoib_cm_has_srq(dev);
|
2007-02-06 04:12:23 +08:00
|
|
|
return ib_send_cm_req(id, &req);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ipoib_cm_modify_tx_init(struct net_device *dev,
|
|
|
|
struct ib_cm_id *cm_id, struct ib_qp *qp)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
struct ib_qp_attr qp_attr;
|
|
|
|
int qp_attr_mask, ret;
|
2008-04-17 12:09:35 +08:00
|
|
|
ret = ib_find_pkey(priv->ca, priv->port, priv->pkey, &qp_attr.pkey_index);
|
2007-02-06 04:12:23 +08:00
|
|
|
if (ret) {
|
2008-04-17 12:09:35 +08:00
|
|
|
ipoib_warn(priv, "pkey 0x%x not found: %d\n", priv->pkey, ret);
|
2007-02-06 04:12:23 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
qp_attr.qp_state = IB_QPS_INIT;
|
|
|
|
qp_attr.qp_access_flags = IB_ACCESS_LOCAL_WRITE;
|
|
|
|
qp_attr.port_num = priv->port;
|
|
|
|
qp_attr_mask = IB_QP_STATE | IB_QP_ACCESS_FLAGS | IB_QP_PKEY_INDEX | IB_QP_PORT;
|
|
|
|
|
|
|
|
ret = ib_modify_qp(qp, &qp_attr, qp_attr_mask);
|
|
|
|
if (ret) {
|
|
|
|
ipoib_warn(priv, "failed to modify tx QP to INIT: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ipoib_cm_tx_init(struct ipoib_cm_tx *p, u32 qpn,
|
|
|
|
struct ib_sa_path_rec *pathrec)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(p->dev);
|
|
|
|
int ret;
|
|
|
|
|
2014-05-11 20:15:11 +08:00
|
|
|
p->tx_ring = __vmalloc(ipoib_sendq_size * sizeof *p->tx_ring,
|
|
|
|
GFP_NOIO, PAGE_KERNEL);
|
2007-02-06 04:12:23 +08:00
|
|
|
if (!p->tx_ring) {
|
|
|
|
ipoib_warn(priv, "failed to allocate tx ring\n");
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_tx;
|
|
|
|
}
|
2014-05-11 20:15:11 +08:00
|
|
|
memset(p->tx_ring, 0, ipoib_sendq_size * sizeof *p->tx_ring);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
2007-08-16 20:36:16 +08:00
|
|
|
p->qp = ipoib_cm_create_tx_qp(p->dev, p);
|
2007-02-06 04:12:23 +08:00
|
|
|
if (IS_ERR(p->qp)) {
|
|
|
|
ret = PTR_ERR(p->qp);
|
|
|
|
ipoib_warn(priv, "failed to allocate tx qp: %d\n", ret);
|
|
|
|
goto err_qp;
|
|
|
|
}
|
|
|
|
|
|
|
|
p->id = ib_create_cm_id(priv->ca, ipoib_cm_tx_handler, p);
|
|
|
|
if (IS_ERR(p->id)) {
|
|
|
|
ret = PTR_ERR(p->id);
|
|
|
|
ipoib_warn(priv, "failed to create tx cm id: %d\n", ret);
|
|
|
|
goto err_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ipoib_cm_modify_tx_init(p->dev, p->id, p->qp);
|
|
|
|
if (ret) {
|
|
|
|
ipoib_warn(priv, "failed to modify tx qp to rtr: %d\n", ret);
|
|
|
|
goto err_modify;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ipoib_cm_send_req(p->dev, p->id, p->qp, qpn, pathrec);
|
|
|
|
if (ret) {
|
|
|
|
ipoib_warn(priv, "failed to send cm req: %d\n", ret);
|
|
|
|
goto err_send_cm;
|
|
|
|
}
|
|
|
|
|
2008-10-30 03:52:50 +08:00
|
|
|
ipoib_dbg(priv, "Request connection 0x%x for gid %pI6 qpn 0x%x\n",
|
2008-10-29 13:37:22 +08:00
|
|
|
p->qp->qp_num, pathrec->dgid.raw, qpn);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_send_cm:
|
|
|
|
err_modify:
|
|
|
|
ib_destroy_cm_id(p->id);
|
|
|
|
err_id:
|
|
|
|
p->id = NULL;
|
|
|
|
ib_destroy_qp(p->qp);
|
|
|
|
err_qp:
|
|
|
|
p->qp = NULL;
|
2008-03-12 22:51:03 +08:00
|
|
|
vfree(p->tx_ring);
|
2007-02-06 04:12:23 +08:00
|
|
|
err_tx:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ipoib_cm_tx_destroy(struct ipoib_cm_tx *p)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(p->dev);
|
2015-07-12 16:24:09 +08:00
|
|
|
struct ipoib_tx_buf *tx_req;
|
2007-08-16 20:36:16 +08:00
|
|
|
unsigned long begin;
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
ipoib_dbg(priv, "Destroy active connection 0x%x head 0x%x tail 0x%x\n",
|
|
|
|
p->qp ? p->qp->qp_num : 0, p->tx_head, p->tx_tail);
|
|
|
|
|
|
|
|
if (p->id)
|
|
|
|
ib_destroy_cm_id(p->id);
|
|
|
|
|
|
|
|
if (p->tx_ring) {
|
2007-08-16 20:36:16 +08:00
|
|
|
/* Wait for all sends to complete */
|
|
|
|
begin = jiffies;
|
2007-02-06 04:12:23 +08:00
|
|
|
while ((int) p->tx_tail - (int) p->tx_head < 0) {
|
2007-08-16 20:36:16 +08:00
|
|
|
if (time_after(jiffies, begin + 5 * HZ)) {
|
|
|
|
ipoib_warn(priv, "timing out; %d sends not completed\n",
|
|
|
|
p->tx_head - p->tx_tail);
|
|
|
|
goto timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
msleep(1);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
2007-08-16 20:36:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
timeout:
|
2007-02-06 04:12:23 +08:00
|
|
|
|
2007-08-16 20:36:16 +08:00
|
|
|
while ((int) p->tx_tail - (int) p->tx_head < 0) {
|
|
|
|
tx_req = &p->tx_ring[p->tx_tail & (ipoib_sendq_size - 1)];
|
2015-07-12 16:24:09 +08:00
|
|
|
ipoib_dma_unmap_tx(priv, tx_req);
|
2007-08-16 20:36:16 +08:00
|
|
|
dev_kfree_skb_any(tx_req->skb);
|
|
|
|
++p->tx_tail;
|
2008-10-01 01:36:21 +08:00
|
|
|
netif_tx_lock_bh(p->dev);
|
2007-08-16 20:36:16 +08:00
|
|
|
if (unlikely(--priv->tx_outstanding == ipoib_sendq_size >> 1) &&
|
|
|
|
netif_queue_stopped(p->dev) &&
|
|
|
|
test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
|
|
|
|
netif_wake_queue(p->dev);
|
2008-10-01 01:36:21 +08:00
|
|
|
netif_tx_unlock_bh(p->dev);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
2007-08-16 20:36:16 +08:00
|
|
|
if (p->qp)
|
|
|
|
ib_destroy_qp(p->qp);
|
|
|
|
|
2008-03-12 22:51:03 +08:00
|
|
|
vfree(p->tx_ring);
|
2007-02-06 04:12:23 +08:00
|
|
|
kfree(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ipoib_cm_tx_handler(struct ib_cm_id *cm_id,
|
|
|
|
struct ib_cm_event *event)
|
|
|
|
{
|
|
|
|
struct ipoib_cm_tx *tx = cm_id->context;
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(tx->dev);
|
|
|
|
struct net_device *dev = priv->dev;
|
|
|
|
struct ipoib_neigh *neigh;
|
2008-10-01 01:36:21 +08:00
|
|
|
unsigned long flags;
|
2007-02-06 04:12:23 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (event->event) {
|
|
|
|
case IB_CM_DREQ_RECEIVED:
|
|
|
|
ipoib_dbg(priv, "DREQ received.\n");
|
|
|
|
ib_send_cm_drep(cm_id, NULL, 0);
|
|
|
|
break;
|
|
|
|
case IB_CM_REP_RECEIVED:
|
|
|
|
ipoib_dbg(priv, "REP received.\n");
|
|
|
|
ret = ipoib_cm_rep_handler(cm_id, event);
|
|
|
|
if (ret)
|
|
|
|
ib_send_cm_rej(cm_id, IB_CM_REJ_CONSUMER_DEFINED,
|
|
|
|
NULL, 0, NULL, 0);
|
|
|
|
break;
|
|
|
|
case IB_CM_REQ_ERROR:
|
|
|
|
case IB_CM_REJ_RECEIVED:
|
|
|
|
case IB_CM_TIMEWAIT_EXIT:
|
|
|
|
ipoib_dbg(priv, "CM error %d.\n", event->event);
|
2008-10-01 01:36:21 +08:00
|
|
|
netif_tx_lock_bh(dev);
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2007-02-06 04:12:23 +08:00
|
|
|
neigh = tx->neigh;
|
|
|
|
|
|
|
|
if (neigh) {
|
|
|
|
neigh->cm = NULL;
|
IPoIB: Use a private hash table for path lookup in xmit path
Dave Miller <davem@davemloft.net> provided a detailed description of
why the way IPoIB is using neighbours for its own ipoib_neigh struct
is buggy:
Any time an ipoib_neigh is changed, a sequence like the following is made:
spin_lock_irqsave(&priv->lock, flags);
/*
* It's safe to call ipoib_put_ah() inside
* priv->lock here, because we know that
* path->ah will always hold one more reference,
* so ipoib_put_ah() will never do more than
* decrement the ref count.
*/
if (neigh->ah)
ipoib_put_ah(neigh->ah);
list_del(&neigh->list);
ipoib_neigh_free(dev, neigh);
spin_unlock_irqrestore(&priv->lock, flags);
ipoib_path_lookup(skb, n, dev);
This doesn't work, because you're leaving a stale pointer to the freed up
ipoib_neigh in the special neigh->ha pointer cookie. Yes, it even fails
with all the locking done to protect _changes_ to *ipoib_neigh(n), and
with the code in ipoib_neigh_free() that NULLs out the pointer.
The core issue is that read side calls to *to_ipoib_neigh(n) are not
being synchronized at all, they are performed without any locking. So
whether we hold the lock or not when making changes to *ipoib_neigh(n)
you still can have threads see references to freed up ipoib_neigh
objects.
cpu 1 cpu 2
n = *ipoib_neigh()
*ipoib_neigh() = NULL
kfree(n)
n->foo == OOPS
[..]
Perhaps the ipoib code can have a private path database it manages
entirely itself, which holds all the necessary information and is
looked up by some generic key which is available easily at transmit
time and does not involve generic neighbour entries.
See <http://marc.info/?l=linux-rdma&m=132812793105624&w=2> and
<http://marc.info/?l=linux-rdma&w=2&r=1&s=allows+references+to+freed+memory&q=b>
for the full discussion.
This patch aims to solve the race conditions found in the IPoIB driver.
The patch removes the connection between the core networking neighbour
structure and the ipoib_neigh structure. In addition to avoiding the
race described above, it allows us to handle SKBs carrying IP packets
that don't have any associated neighbour.
We add an ipoib_neigh hash table with N buckets where the key is the
destination hardware address. The ipoib_neigh is fetched from the
hash table and instead of the stashed location in the neighbour
structure. The hash table uses both RCU and reference counting to
guarantee that no ipoib_neigh instance is ever deleted while in use.
Fetching the ipoib_neigh structure instance from the hash also makes
the special code in ipoib_start_xmit that handles remote and local
bonding failover redundant.
Aged ipoib_neigh instances are deleted by a garbage collection task
that runs every M seconds and deletes every ipoib_neigh instance that
was idle for at least 2*M seconds. The deletion is safe since the
ipoib_neigh instances are protected using RCU and reference count
mechanisms.
The number of buckets (N) and frequency of running the GC thread (M),
are taken from the exported arb_tbl.
Signed-off-by: Shlomo Pongratz <shlomop@mellanox.com>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
2012-07-25 01:05:22 +08:00
|
|
|
ipoib_neigh_free(neigh);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
tx->neigh = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test_and_clear_bit(IPOIB_FLAG_INITIALIZED, &tx->flags)) {
|
|
|
|
list_move(&tx->list, &priv->cm.reap_list);
|
IB/ipoib: Use dedicated workqueues per interface
During my recent work on the rtnl lock deadlock in the IPoIB driver, I
saw that even once I fixed the apparent races for a single device, as
soon as that device had any children, new races popped up. It turns
out that this is because no matter how well we protect against races
on a single device, the fact that all devices use the same workqueue,
and flush_workqueue() flushes *everything* from that workqueue means
that we would also have to prevent all races between different devices
(for instance, ipoib_mcast_restart_task on interface ib0 can race with
ipoib_mcast_flush_dev on interface ib0.8002, resulting in a deadlock on
the rtnl_lock).
There are several possible solutions to this problem:
Make carrier_on_task and mcast_restart_task try to take the rtnl for
some set period of time and if they fail, then bail. This runs the
real risk of dropping work on the floor, which can end up being its
own separate kind of deadlock.
Set some global flag in the driver that says some device is in the
middle of going down, letting all tasks know to bail. Again, this can
drop work on the floor.
Or the method this patch attempts to use, which is when we bring an
interface up, create a workqueue specifically for that interface, so
that when we take it back down, we are flushing only those tasks
associated with our interface. In addition, keep the global
workqueue, but now limit it to only flush tasks. In this way, the
flush tasks can always flush the device specific work queues without
having deadlock issues.
Signed-off-by: Doug Ledford <dledford@redhat.com>
2015-02-22 08:27:03 +08:00
|
|
|
queue_work(priv->wq, &priv->cm.reap_task);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
2008-10-01 01:36:21 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
netif_tx_unlock_bh(dev);
|
2007-02-06 04:12:23 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ipoib_cm_tx *ipoib_cm_create_tx(struct net_device *dev, struct ipoib_path *path,
|
|
|
|
struct ipoib_neigh *neigh)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
struct ipoib_cm_tx *tx;
|
|
|
|
|
|
|
|
tx = kzalloc(sizeof *tx, GFP_ATOMIC);
|
|
|
|
if (!tx)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
neigh->cm = tx;
|
|
|
|
tx->neigh = neigh;
|
|
|
|
tx->path = path;
|
|
|
|
tx->dev = dev;
|
|
|
|
list_add(&tx->list, &priv->cm.start_list);
|
|
|
|
set_bit(IPOIB_FLAG_INITIALIZED, &tx->flags);
|
IB/ipoib: Use dedicated workqueues per interface
During my recent work on the rtnl lock deadlock in the IPoIB driver, I
saw that even once I fixed the apparent races for a single device, as
soon as that device had any children, new races popped up. It turns
out that this is because no matter how well we protect against races
on a single device, the fact that all devices use the same workqueue,
and flush_workqueue() flushes *everything* from that workqueue means
that we would also have to prevent all races between different devices
(for instance, ipoib_mcast_restart_task on interface ib0 can race with
ipoib_mcast_flush_dev on interface ib0.8002, resulting in a deadlock on
the rtnl_lock).
There are several possible solutions to this problem:
Make carrier_on_task and mcast_restart_task try to take the rtnl for
some set period of time and if they fail, then bail. This runs the
real risk of dropping work on the floor, which can end up being its
own separate kind of deadlock.
Set some global flag in the driver that says some device is in the
middle of going down, letting all tasks know to bail. Again, this can
drop work on the floor.
Or the method this patch attempts to use, which is when we bring an
interface up, create a workqueue specifically for that interface, so
that when we take it back down, we are flushing only those tasks
associated with our interface. In addition, keep the global
workqueue, but now limit it to only flush tasks. In this way, the
flush tasks can always flush the device specific work queues without
having deadlock issues.
Signed-off-by: Doug Ledford <dledford@redhat.com>
2015-02-22 08:27:03 +08:00
|
|
|
queue_work(priv->wq, &priv->cm.start_task);
|
2007-02-06 04:12:23 +08:00
|
|
|
return tx;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(tx->dev);
|
2012-08-13 22:39:49 +08:00
|
|
|
unsigned long flags;
|
2007-02-06 04:12:23 +08:00
|
|
|
if (test_and_clear_bit(IPOIB_FLAG_INITIALIZED, &tx->flags)) {
|
2012-08-13 22:39:49 +08:00
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2007-02-06 04:12:23 +08:00
|
|
|
list_move(&tx->list, &priv->cm.reap_list);
|
IB/ipoib: Use dedicated workqueues per interface
During my recent work on the rtnl lock deadlock in the IPoIB driver, I
saw that even once I fixed the apparent races for a single device, as
soon as that device had any children, new races popped up. It turns
out that this is because no matter how well we protect against races
on a single device, the fact that all devices use the same workqueue,
and flush_workqueue() flushes *everything* from that workqueue means
that we would also have to prevent all races between different devices
(for instance, ipoib_mcast_restart_task on interface ib0 can race with
ipoib_mcast_flush_dev on interface ib0.8002, resulting in a deadlock on
the rtnl_lock).
There are several possible solutions to this problem:
Make carrier_on_task and mcast_restart_task try to take the rtnl for
some set period of time and if they fail, then bail. This runs the
real risk of dropping work on the floor, which can end up being its
own separate kind of deadlock.
Set some global flag in the driver that says some device is in the
middle of going down, letting all tasks know to bail. Again, this can
drop work on the floor.
Or the method this patch attempts to use, which is when we bring an
interface up, create a workqueue specifically for that interface, so
that when we take it back down, we are flushing only those tasks
associated with our interface. In addition, keep the global
workqueue, but now limit it to only flush tasks. In this way, the
flush tasks can always flush the device specific work queues without
having deadlock issues.
Signed-off-by: Doug Ledford <dledford@redhat.com>
2015-02-22 08:27:03 +08:00
|
|
|
queue_work(priv->wq, &priv->cm.reap_task);
|
2008-10-30 03:52:50 +08:00
|
|
|
ipoib_dbg(priv, "Reap connection for gid %pI6\n",
|
IPoIB: Use a private hash table for path lookup in xmit path
Dave Miller <davem@davemloft.net> provided a detailed description of
why the way IPoIB is using neighbours for its own ipoib_neigh struct
is buggy:
Any time an ipoib_neigh is changed, a sequence like the following is made:
spin_lock_irqsave(&priv->lock, flags);
/*
* It's safe to call ipoib_put_ah() inside
* priv->lock here, because we know that
* path->ah will always hold one more reference,
* so ipoib_put_ah() will never do more than
* decrement the ref count.
*/
if (neigh->ah)
ipoib_put_ah(neigh->ah);
list_del(&neigh->list);
ipoib_neigh_free(dev, neigh);
spin_unlock_irqrestore(&priv->lock, flags);
ipoib_path_lookup(skb, n, dev);
This doesn't work, because you're leaving a stale pointer to the freed up
ipoib_neigh in the special neigh->ha pointer cookie. Yes, it even fails
with all the locking done to protect _changes_ to *ipoib_neigh(n), and
with the code in ipoib_neigh_free() that NULLs out the pointer.
The core issue is that read side calls to *to_ipoib_neigh(n) are not
being synchronized at all, they are performed without any locking. So
whether we hold the lock or not when making changes to *ipoib_neigh(n)
you still can have threads see references to freed up ipoib_neigh
objects.
cpu 1 cpu 2
n = *ipoib_neigh()
*ipoib_neigh() = NULL
kfree(n)
n->foo == OOPS
[..]
Perhaps the ipoib code can have a private path database it manages
entirely itself, which holds all the necessary information and is
looked up by some generic key which is available easily at transmit
time and does not involve generic neighbour entries.
See <http://marc.info/?l=linux-rdma&m=132812793105624&w=2> and
<http://marc.info/?l=linux-rdma&w=2&r=1&s=allows+references+to+freed+memory&q=b>
for the full discussion.
This patch aims to solve the race conditions found in the IPoIB driver.
The patch removes the connection between the core networking neighbour
structure and the ipoib_neigh structure. In addition to avoiding the
race described above, it allows us to handle SKBs carrying IP packets
that don't have any associated neighbour.
We add an ipoib_neigh hash table with N buckets where the key is the
destination hardware address. The ipoib_neigh is fetched from the
hash table and instead of the stashed location in the neighbour
structure. The hash table uses both RCU and reference counting to
guarantee that no ipoib_neigh instance is ever deleted while in use.
Fetching the ipoib_neigh structure instance from the hash also makes
the special code in ipoib_start_xmit that handles remote and local
bonding failover redundant.
Aged ipoib_neigh instances are deleted by a garbage collection task
that runs every M seconds and deletes every ipoib_neigh instance that
was idle for at least 2*M seconds. The deletion is safe since the
ipoib_neigh instances are protected using RCU and reference count
mechanisms.
The number of buckets (N) and frequency of running the GC thread (M),
are taken from the exported arb_tbl.
Signed-off-by: Shlomo Pongratz <shlomop@mellanox.com>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
2012-07-25 01:05:22 +08:00
|
|
|
tx->neigh->daddr + 4);
|
2007-02-06 04:12:23 +08:00
|
|
|
tx->neigh = NULL;
|
2012-08-13 22:39:49 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ipoib_cm_tx_start(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv,
|
|
|
|
cm.start_task);
|
|
|
|
struct net_device *dev = priv->dev;
|
|
|
|
struct ipoib_neigh *neigh;
|
|
|
|
struct ipoib_cm_tx *p;
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
struct ib_sa_path_rec pathrec;
|
|
|
|
u32 qpn;
|
|
|
|
|
2008-10-01 01:36:21 +08:00
|
|
|
netif_tx_lock_bh(dev);
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
|
2007-02-06 04:12:23 +08:00
|
|
|
while (!list_empty(&priv->cm.start_list)) {
|
|
|
|
p = list_entry(priv->cm.start_list.next, typeof(*p), list);
|
|
|
|
list_del_init(&p->list);
|
|
|
|
neigh = p->neigh;
|
IPoIB: Use a private hash table for path lookup in xmit path
Dave Miller <davem@davemloft.net> provided a detailed description of
why the way IPoIB is using neighbours for its own ipoib_neigh struct
is buggy:
Any time an ipoib_neigh is changed, a sequence like the following is made:
spin_lock_irqsave(&priv->lock, flags);
/*
* It's safe to call ipoib_put_ah() inside
* priv->lock here, because we know that
* path->ah will always hold one more reference,
* so ipoib_put_ah() will never do more than
* decrement the ref count.
*/
if (neigh->ah)
ipoib_put_ah(neigh->ah);
list_del(&neigh->list);
ipoib_neigh_free(dev, neigh);
spin_unlock_irqrestore(&priv->lock, flags);
ipoib_path_lookup(skb, n, dev);
This doesn't work, because you're leaving a stale pointer to the freed up
ipoib_neigh in the special neigh->ha pointer cookie. Yes, it even fails
with all the locking done to protect _changes_ to *ipoib_neigh(n), and
with the code in ipoib_neigh_free() that NULLs out the pointer.
The core issue is that read side calls to *to_ipoib_neigh(n) are not
being synchronized at all, they are performed without any locking. So
whether we hold the lock or not when making changes to *ipoib_neigh(n)
you still can have threads see references to freed up ipoib_neigh
objects.
cpu 1 cpu 2
n = *ipoib_neigh()
*ipoib_neigh() = NULL
kfree(n)
n->foo == OOPS
[..]
Perhaps the ipoib code can have a private path database it manages
entirely itself, which holds all the necessary information and is
looked up by some generic key which is available easily at transmit
time and does not involve generic neighbour entries.
See <http://marc.info/?l=linux-rdma&m=132812793105624&w=2> and
<http://marc.info/?l=linux-rdma&w=2&r=1&s=allows+references+to+freed+memory&q=b>
for the full discussion.
This patch aims to solve the race conditions found in the IPoIB driver.
The patch removes the connection between the core networking neighbour
structure and the ipoib_neigh structure. In addition to avoiding the
race described above, it allows us to handle SKBs carrying IP packets
that don't have any associated neighbour.
We add an ipoib_neigh hash table with N buckets where the key is the
destination hardware address. The ipoib_neigh is fetched from the
hash table and instead of the stashed location in the neighbour
structure. The hash table uses both RCU and reference counting to
guarantee that no ipoib_neigh instance is ever deleted while in use.
Fetching the ipoib_neigh structure instance from the hash also makes
the special code in ipoib_start_xmit that handles remote and local
bonding failover redundant.
Aged ipoib_neigh instances are deleted by a garbage collection task
that runs every M seconds and deletes every ipoib_neigh instance that
was idle for at least 2*M seconds. The deletion is safe since the
ipoib_neigh instances are protected using RCU and reference count
mechanisms.
The number of buckets (N) and frequency of running the GC thread (M),
are taken from the exported arb_tbl.
Signed-off-by: Shlomo Pongratz <shlomop@mellanox.com>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
2012-07-25 01:05:22 +08:00
|
|
|
qpn = IPOIB_QPN(neigh->daddr);
|
2007-02-06 04:12:23 +08:00
|
|
|
memcpy(&pathrec, &p->path->pathrec, sizeof pathrec);
|
2008-10-01 01:36:21 +08:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
netif_tx_unlock_bh(dev);
|
|
|
|
|
2007-02-06 04:12:23 +08:00
|
|
|
ret = ipoib_cm_tx_init(p, qpn, &pathrec);
|
2008-10-01 01:36:21 +08:00
|
|
|
|
|
|
|
netif_tx_lock_bh(dev);
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
|
2007-02-06 04:12:23 +08:00
|
|
|
if (ret) {
|
|
|
|
neigh = p->neigh;
|
|
|
|
if (neigh) {
|
|
|
|
neigh->cm = NULL;
|
IPoIB: Use a private hash table for path lookup in xmit path
Dave Miller <davem@davemloft.net> provided a detailed description of
why the way IPoIB is using neighbours for its own ipoib_neigh struct
is buggy:
Any time an ipoib_neigh is changed, a sequence like the following is made:
spin_lock_irqsave(&priv->lock, flags);
/*
* It's safe to call ipoib_put_ah() inside
* priv->lock here, because we know that
* path->ah will always hold one more reference,
* so ipoib_put_ah() will never do more than
* decrement the ref count.
*/
if (neigh->ah)
ipoib_put_ah(neigh->ah);
list_del(&neigh->list);
ipoib_neigh_free(dev, neigh);
spin_unlock_irqrestore(&priv->lock, flags);
ipoib_path_lookup(skb, n, dev);
This doesn't work, because you're leaving a stale pointer to the freed up
ipoib_neigh in the special neigh->ha pointer cookie. Yes, it even fails
with all the locking done to protect _changes_ to *ipoib_neigh(n), and
with the code in ipoib_neigh_free() that NULLs out the pointer.
The core issue is that read side calls to *to_ipoib_neigh(n) are not
being synchronized at all, they are performed without any locking. So
whether we hold the lock or not when making changes to *ipoib_neigh(n)
you still can have threads see references to freed up ipoib_neigh
objects.
cpu 1 cpu 2
n = *ipoib_neigh()
*ipoib_neigh() = NULL
kfree(n)
n->foo == OOPS
[..]
Perhaps the ipoib code can have a private path database it manages
entirely itself, which holds all the necessary information and is
looked up by some generic key which is available easily at transmit
time and does not involve generic neighbour entries.
See <http://marc.info/?l=linux-rdma&m=132812793105624&w=2> and
<http://marc.info/?l=linux-rdma&w=2&r=1&s=allows+references+to+freed+memory&q=b>
for the full discussion.
This patch aims to solve the race conditions found in the IPoIB driver.
The patch removes the connection between the core networking neighbour
structure and the ipoib_neigh structure. In addition to avoiding the
race described above, it allows us to handle SKBs carrying IP packets
that don't have any associated neighbour.
We add an ipoib_neigh hash table with N buckets where the key is the
destination hardware address. The ipoib_neigh is fetched from the
hash table and instead of the stashed location in the neighbour
structure. The hash table uses both RCU and reference counting to
guarantee that no ipoib_neigh instance is ever deleted while in use.
Fetching the ipoib_neigh structure instance from the hash also makes
the special code in ipoib_start_xmit that handles remote and local
bonding failover redundant.
Aged ipoib_neigh instances are deleted by a garbage collection task
that runs every M seconds and deletes every ipoib_neigh instance that
was idle for at least 2*M seconds. The deletion is safe since the
ipoib_neigh instances are protected using RCU and reference count
mechanisms.
The number of buckets (N) and frequency of running the GC thread (M),
are taken from the exported arb_tbl.
Signed-off-by: Shlomo Pongratz <shlomop@mellanox.com>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
2012-07-25 01:05:22 +08:00
|
|
|
ipoib_neigh_free(neigh);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
list_del(&p->list);
|
|
|
|
kfree(p);
|
|
|
|
}
|
|
|
|
}
|
2008-10-01 01:36:21 +08:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
netif_tx_unlock_bh(dev);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ipoib_cm_tx_reap(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv,
|
|
|
|
cm.reap_task);
|
2008-10-01 01:36:21 +08:00
|
|
|
struct net_device *dev = priv->dev;
|
2007-02-06 04:12:23 +08:00
|
|
|
struct ipoib_cm_tx *p;
|
2008-10-01 01:36:21 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
netif_tx_lock_bh(dev);
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
while (!list_empty(&priv->cm.reap_list)) {
|
|
|
|
p = list_entry(priv->cm.reap_list.next, typeof(*p), list);
|
|
|
|
list_del(&p->list);
|
2008-10-01 01:36:21 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
netif_tx_unlock_bh(dev);
|
2007-02-06 04:12:23 +08:00
|
|
|
ipoib_cm_tx_destroy(p);
|
2008-10-01 01:36:21 +08:00
|
|
|
netif_tx_lock_bh(dev);
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
2008-10-01 01:36:21 +08:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
netif_tx_unlock_bh(dev);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ipoib_cm_skb_reap(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv,
|
|
|
|
cm.skb_task);
|
2008-10-01 01:36:21 +08:00
|
|
|
struct net_device *dev = priv->dev;
|
2007-02-06 04:12:23 +08:00
|
|
|
struct sk_buff *skb;
|
2008-10-01 01:36:21 +08:00
|
|
|
unsigned long flags;
|
2007-02-06 04:12:23 +08:00
|
|
|
unsigned mtu = priv->mcast_mtu;
|
|
|
|
|
2008-10-01 01:36:21 +08:00
|
|
|
netif_tx_lock_bh(dev);
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
|
2007-02-06 04:12:23 +08:00
|
|
|
while ((skb = skb_dequeue(&priv->cm.skb_queue))) {
|
2008-10-01 01:36:21 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
netif_tx_unlock_bh(dev);
|
|
|
|
|
2007-02-06 04:12:23 +08:00
|
|
|
if (skb->protocol == htons(ETH_P_IP))
|
|
|
|
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
|
2012-07-06 13:39:34 +08:00
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
2007-02-06 04:12:23 +08:00
|
|
|
else if (skb->protocol == htons(ETH_P_IPV6))
|
2010-02-18 16:25:24 +08:00
|
|
|
icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
|
2007-02-06 04:12:23 +08:00
|
|
|
#endif
|
|
|
|
dev_kfree_skb_any(skb);
|
2008-10-01 01:36:21 +08:00
|
|
|
|
|
|
|
netif_tx_lock_bh(dev);
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
2008-10-01 01:36:21 +08:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
netif_tx_unlock_bh(dev);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
2007-10-24 10:57:54 +08:00
|
|
|
void ipoib_cm_skb_too_long(struct net_device *dev, struct sk_buff *skb,
|
2007-02-06 04:12:23 +08:00
|
|
|
unsigned int mtu)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
int e = skb_queue_empty(&priv->cm.skb_queue);
|
|
|
|
|
2009-06-02 13:19:30 +08:00
|
|
|
if (skb_dst(skb))
|
2012-07-17 18:29:28 +08:00
|
|
|
skb_dst(skb)->ops->update_pmtu(skb_dst(skb), NULL, skb, mtu);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
skb_queue_tail(&priv->cm.skb_queue, skb);
|
|
|
|
if (e)
|
IB/ipoib: Use dedicated workqueues per interface
During my recent work on the rtnl lock deadlock in the IPoIB driver, I
saw that even once I fixed the apparent races for a single device, as
soon as that device had any children, new races popped up. It turns
out that this is because no matter how well we protect against races
on a single device, the fact that all devices use the same workqueue,
and flush_workqueue() flushes *everything* from that workqueue means
that we would also have to prevent all races between different devices
(for instance, ipoib_mcast_restart_task on interface ib0 can race with
ipoib_mcast_flush_dev on interface ib0.8002, resulting in a deadlock on
the rtnl_lock).
There are several possible solutions to this problem:
Make carrier_on_task and mcast_restart_task try to take the rtnl for
some set period of time and if they fail, then bail. This runs the
real risk of dropping work on the floor, which can end up being its
own separate kind of deadlock.
Set some global flag in the driver that says some device is in the
middle of going down, letting all tasks know to bail. Again, this can
drop work on the floor.
Or the method this patch attempts to use, which is when we bring an
interface up, create a workqueue specifically for that interface, so
that when we take it back down, we are flushing only those tasks
associated with our interface. In addition, keep the global
workqueue, but now limit it to only flush tasks. In this way, the
flush tasks can always flush the device specific work queues without
having deadlock issues.
Signed-off-by: Doug Ledford <dledford@redhat.com>
2015-02-22 08:27:03 +08:00
|
|
|
queue_work(priv->wq, &priv->cm.skb_task);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
2007-05-21 20:04:59 +08:00
|
|
|
static void ipoib_cm_rx_reap(struct work_struct *work)
|
|
|
|
{
|
2008-01-26 06:15:24 +08:00
|
|
|
ipoib_cm_free_rx_reap_list(container_of(work, struct ipoib_dev_priv,
|
|
|
|
cm.rx_reap_task)->dev);
|
2007-05-21 20:04:59 +08:00
|
|
|
}
|
|
|
|
|
2007-02-06 04:12:23 +08:00
|
|
|
static void ipoib_cm_stale_task(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv,
|
|
|
|
cm.stale_task.work);
|
|
|
|
struct ipoib_cm_rx *p;
|
2007-05-21 20:04:59 +08:00
|
|
|
int ret;
|
2007-02-06 04:12:23 +08:00
|
|
|
|
2007-04-25 12:30:37 +08:00
|
|
|
spin_lock_irq(&priv->lock);
|
2007-02-06 04:12:23 +08:00
|
|
|
while (!list_empty(&priv->cm.passive_ids)) {
|
2007-05-21 20:04:59 +08:00
|
|
|
/* List is sorted by LRU, start from tail,
|
2007-02-06 04:12:23 +08:00
|
|
|
* stop when we see a recently used entry */
|
|
|
|
p = list_entry(priv->cm.passive_ids.prev, typeof(*p), list);
|
2007-03-23 05:32:09 +08:00
|
|
|
if (time_before_eq(jiffies, p->jiffies + IPOIB_CM_RX_TIMEOUT))
|
2007-02-06 04:12:23 +08:00
|
|
|
break;
|
2007-05-21 20:04:59 +08:00
|
|
|
list_move(&p->list, &priv->cm.rx_error_list);
|
|
|
|
p->state = IPOIB_CM_RX_ERROR;
|
2007-04-25 12:30:37 +08:00
|
|
|
spin_unlock_irq(&priv->lock);
|
2007-05-21 20:04:59 +08:00
|
|
|
ret = ib_modify_qp(p->qp, &ipoib_cm_err_attr, IB_QP_STATE);
|
|
|
|
if (ret)
|
|
|
|
ipoib_warn(priv, "unable to move qp to error state: %d\n", ret);
|
2007-04-25 12:30:37 +08:00
|
|
|
spin_lock_irq(&priv->lock);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
2007-05-14 12:26:51 +08:00
|
|
|
|
|
|
|
if (!list_empty(&priv->cm.passive_ids))
|
IB/ipoib: Use dedicated workqueues per interface
During my recent work on the rtnl lock deadlock in the IPoIB driver, I
saw that even once I fixed the apparent races for a single device, as
soon as that device had any children, new races popped up. It turns
out that this is because no matter how well we protect against races
on a single device, the fact that all devices use the same workqueue,
and flush_workqueue() flushes *everything* from that workqueue means
that we would also have to prevent all races between different devices
(for instance, ipoib_mcast_restart_task on interface ib0 can race with
ipoib_mcast_flush_dev on interface ib0.8002, resulting in a deadlock on
the rtnl_lock).
There are several possible solutions to this problem:
Make carrier_on_task and mcast_restart_task try to take the rtnl for
some set period of time and if they fail, then bail. This runs the
real risk of dropping work on the floor, which can end up being its
own separate kind of deadlock.
Set some global flag in the driver that says some device is in the
middle of going down, letting all tasks know to bail. Again, this can
drop work on the floor.
Or the method this patch attempts to use, which is when we bring an
interface up, create a workqueue specifically for that interface, so
that when we take it back down, we are flushing only those tasks
associated with our interface. In addition, keep the global
workqueue, but now limit it to only flush tasks. In this way, the
flush tasks can always flush the device specific work queues without
having deadlock issues.
Signed-off-by: Doug Ledford <dledford@redhat.com>
2015-02-22 08:27:03 +08:00
|
|
|
queue_delayed_work(priv->wq,
|
2007-05-14 12:26:51 +08:00
|
|
|
&priv->cm.stale_task, IPOIB_CM_RX_DELAY);
|
2007-04-25 12:30:37 +08:00
|
|
|
spin_unlock_irq(&priv->lock);
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
|
2007-10-24 10:57:54 +08:00
|
|
|
static ssize_t show_mode(struct device *d, struct device_attribute *attr,
|
2007-02-06 04:12:23 +08:00
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(d));
|
|
|
|
|
|
|
|
if (test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags))
|
|
|
|
return sprintf(buf, "connected\n");
|
|
|
|
else
|
|
|
|
return sprintf(buf, "datagram\n");
|
|
|
|
}
|
|
|
|
|
2012-09-27 20:06:02 +08:00
|
|
|
static ssize_t set_mode(struct device *d, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct net_device *dev = to_net_dev(d);
|
|
|
|
int ret;
|
2016-06-04 20:15:20 +08:00
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
|
|
|
|
if (test_bit(IPOIB_FLAG_GOING_DOWN, &priv->flags))
|
|
|
|
return -EPERM;
|
2012-09-27 20:06:02 +08:00
|
|
|
|
|
|
|
if (!rtnl_trylock())
|
|
|
|
return restart_syscall();
|
|
|
|
|
|
|
|
ret = ipoib_set_mode(dev, buf);
|
|
|
|
|
|
|
|
rtnl_unlock();
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return count;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-02-17 05:57:33 +08:00
|
|
|
static DEVICE_ATTR(mode, S_IWUSR | S_IRUGO, show_mode, set_mode);
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
int ipoib_cm_add_mode_attr(struct net_device *dev)
|
|
|
|
{
|
|
|
|
return device_create_file(&dev->dev, &dev_attr_mode);
|
|
|
|
}
|
|
|
|
|
2007-12-22 05:08:23 +08:00
|
|
|
static void ipoib_cm_create_srq(struct net_device *dev, int max_sge)
|
2007-02-06 04:12:23 +08:00
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
|
|
|
struct ib_srq_init_attr srq_init_attr = {
|
2011-05-24 07:31:36 +08:00
|
|
|
.srq_type = IB_SRQT_BASIC,
|
2007-02-06 04:12:23 +08:00
|
|
|
.attr = {
|
|
|
|
.max_wr = ipoib_recvq_size,
|
2007-12-22 05:08:23 +08:00
|
|
|
.max_sge = max_sge
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
};
|
2008-01-26 06:15:24 +08:00
|
|
|
|
|
|
|
priv->cm.srq = ib_create_srq(priv->pd, &srq_init_attr);
|
|
|
|
if (IS_ERR(priv->cm.srq)) {
|
2008-01-26 06:15:24 +08:00
|
|
|
if (PTR_ERR(priv->cm.srq) != -ENOSYS)
|
|
|
|
printk(KERN_WARNING "%s: failed to allocate SRQ, error %ld\n",
|
|
|
|
priv->ca->name, PTR_ERR(priv->cm.srq));
|
2008-01-26 06:15:24 +08:00
|
|
|
priv->cm.srq = NULL;
|
2008-01-26 06:15:24 +08:00
|
|
|
return;
|
2008-01-26 06:15:24 +08:00
|
|
|
}
|
|
|
|
|
2010-11-05 11:07:36 +08:00
|
|
|
priv->cm.srq_ring = vzalloc(ipoib_recvq_size * sizeof *priv->cm.srq_ring);
|
2008-01-26 06:15:24 +08:00
|
|
|
if (!priv->cm.srq_ring) {
|
2008-01-26 06:15:24 +08:00
|
|
|
printk(KERN_WARNING "%s: failed to allocate CM SRQ ring (%d entries)\n",
|
2008-01-26 06:15:24 +08:00
|
|
|
priv->ca->name, ipoib_recvq_size);
|
|
|
|
ib_destroy_srq(priv->cm.srq);
|
|
|
|
priv->cm.srq = NULL;
|
2008-08-09 06:51:29 +08:00
|
|
|
return;
|
2008-01-26 06:15:24 +08:00
|
|
|
}
|
2008-08-09 06:51:29 +08:00
|
|
|
|
2008-01-26 06:15:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int ipoib_cm_dev_init(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
2015-12-18 16:59:46 +08:00
|
|
|
int max_srq_sge, i;
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
INIT_LIST_HEAD(&priv->cm.passive_ids);
|
|
|
|
INIT_LIST_HEAD(&priv->cm.reap_list);
|
|
|
|
INIT_LIST_HEAD(&priv->cm.start_list);
|
2007-05-21 20:04:59 +08:00
|
|
|
INIT_LIST_HEAD(&priv->cm.rx_error_list);
|
|
|
|
INIT_LIST_HEAD(&priv->cm.rx_flush_list);
|
|
|
|
INIT_LIST_HEAD(&priv->cm.rx_drain_list);
|
|
|
|
INIT_LIST_HEAD(&priv->cm.rx_reap_list);
|
2007-02-06 04:12:23 +08:00
|
|
|
INIT_WORK(&priv->cm.start_task, ipoib_cm_tx_start);
|
|
|
|
INIT_WORK(&priv->cm.reap_task, ipoib_cm_tx_reap);
|
|
|
|
INIT_WORK(&priv->cm.skb_task, ipoib_cm_skb_reap);
|
2007-05-21 20:04:59 +08:00
|
|
|
INIT_WORK(&priv->cm.rx_reap_task, ipoib_cm_rx_reap);
|
2007-02-06 04:12:23 +08:00
|
|
|
INIT_DELAYED_WORK(&priv->cm.stale_task, ipoib_cm_stale_task);
|
|
|
|
|
|
|
|
skb_queue_head_init(&priv->cm.skb_queue);
|
|
|
|
|
2015-12-18 16:59:46 +08:00
|
|
|
ipoib_dbg(priv, "max_srq_sge=%d\n", priv->ca->attrs.max_srq_sge);
|
2007-12-22 05:08:23 +08:00
|
|
|
|
2015-12-18 16:59:46 +08:00
|
|
|
max_srq_sge = min_t(int, IPOIB_CM_RX_SG, priv->ca->attrs.max_srq_sge);
|
|
|
|
ipoib_cm_create_srq(dev, max_srq_sge);
|
2007-12-22 05:08:23 +08:00
|
|
|
if (ipoib_cm_has_srq(dev)) {
|
2015-12-18 16:59:46 +08:00
|
|
|
priv->cm.max_cm_mtu = max_srq_sge * PAGE_SIZE - 0x10;
|
|
|
|
priv->cm.num_frags = max_srq_sge;
|
2007-12-22 05:08:23 +08:00
|
|
|
ipoib_dbg(priv, "max_cm_mtu = 0x%x, num_frags=%d\n",
|
|
|
|
priv->cm.max_cm_mtu, priv->cm.num_frags);
|
|
|
|
} else {
|
|
|
|
priv->cm.max_cm_mtu = IPOIB_CM_MTU;
|
|
|
|
priv->cm.num_frags = IPOIB_CM_RX_SG;
|
|
|
|
}
|
|
|
|
|
2008-07-15 14:48:47 +08:00
|
|
|
ipoib_cm_init_rx_wr(dev, &priv->cm.rx_wr, priv->cm.rx_sge);
|
2008-01-26 06:15:24 +08:00
|
|
|
|
|
|
|
if (ipoib_cm_has_srq(dev)) {
|
|
|
|
for (i = 0; i < ipoib_recvq_size; ++i) {
|
|
|
|
if (!ipoib_cm_alloc_rx_skb(dev, priv->cm.srq_ring, i,
|
2007-12-22 05:08:23 +08:00
|
|
|
priv->cm.num_frags - 1,
|
2013-10-16 22:37:48 +08:00
|
|
|
priv->cm.srq_ring[i].mapping,
|
|
|
|
GFP_KERNEL)) {
|
2008-01-26 06:15:24 +08:00
|
|
|
ipoib_warn(priv, "failed to allocate "
|
|
|
|
"receive buffer %d\n", i);
|
|
|
|
ipoib_cm_dev_cleanup(dev);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2008-01-26 06:15:24 +08:00
|
|
|
|
2008-01-26 06:15:24 +08:00
|
|
|
if (ipoib_cm_post_receive_srq(dev, i)) {
|
|
|
|
ipoib_warn(priv, "ipoib_cm_post_receive_srq "
|
|
|
|
"failed for buf %d\n", i);
|
|
|
|
ipoib_cm_dev_cleanup(dev);
|
|
|
|
return -EIO;
|
|
|
|
}
|
2007-02-06 04:12:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->dev->dev_addr[0] = IPOIB_FLAGS_RC;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ipoib_cm_dev_cleanup(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct ipoib_dev_priv *priv = netdev_priv(dev);
|
2008-01-26 06:15:24 +08:00
|
|
|
int ret;
|
2007-02-06 04:12:23 +08:00
|
|
|
|
|
|
|
if (!priv->cm.srq)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ipoib_dbg(priv, "Cleanup ipoib connected mode.\n");
|
|
|
|
|
|
|
|
ret = ib_destroy_srq(priv->cm.srq);
|
|
|
|
if (ret)
|
|
|
|
ipoib_warn(priv, "ib_destroy_srq failed: %d\n", ret);
|
|
|
|
|
|
|
|
priv->cm.srq = NULL;
|
|
|
|
if (!priv->cm.srq_ring)
|
|
|
|
return;
|
2008-01-26 06:15:24 +08:00
|
|
|
|
|
|
|
ipoib_cm_free_rx_ring(dev, priv->cm.srq_ring);
|
2007-02-06 04:12:23 +08:00
|
|
|
priv->cm.srq_ring = NULL;
|
|
|
|
}
|