Skip to content

Commit

Permalink
Merge branch 'for-linus' of master.kernel.org:/pub/scm/linux/kernel/g…
Browse files Browse the repository at this point in the history
…it/roland/infiniband

* 'for-linus' of master.kernel.org:/pub/scm/linux/kernel/git/roland/infiniband:
  IB/cm: Improve local id allocation
  IPoIB/cm: Fix SRQ WR leak
  IB/ipoib: Fix typos in error messages
  IB/mlx4: Check if SRQ is full when posting receive
  IB/mlx4: Pass send queue sizes from userspace to kernel
  IB/mlx4: Fix check of opcode in mlx4_ib_post_send()
  mlx4_core: Fix array overrun in dump_dev_cap_flags()
  IB/mlx4: Fix RESET to RESET and RESET to ERROR transitions
  IB/mthca: Fix RESET to ERROR transition
  IB/mlx4: Set GRH:HopLimit when sending globally routed MADs
  IB/mthca: Set GRH:HopLimit when building MLX headers
  IB/mlx4: Fix check of max_qp_dest_rdma in modify QP
  IB/mthca: Fix use-after-free on device restart
  IB/ehca: Return proper error code if register_mr fails
  IPoIB: Handle P_Key table reordering
  IB/core: Use start_port() and end_port()
  IB/core: Add helpers for uncached GID and P_Key searches
  IB/ipath: Fix potential deadlock with multicast spinlocks
  IB/core: Free umem when mm is already gone
  • Loading branch information
Linus Torvalds committed May 21, 2007
2 parents 080e892 + 9f81036 commit 8aee74c
Show file tree
Hide file tree
Showing 19 changed files with 697 additions and 222 deletions.
4 changes: 3 additions & 1 deletion drivers/infiniband/core/cm.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ static int cm_alloc_id(struct cm_id_private *cm_id_priv)
do {
spin_lock_irqsave(&cm.lock, flags);
ret = idr_get_new_above(&cm.local_id_table, cm_id_priv,
next_id++, &id);
next_id, &id);
if (!ret)
next_id = ((unsigned) id + 1) & MAX_ID_MASK;
spin_unlock_irqrestore(&cm.lock, flags);
} while( (ret == -EAGAIN) && idr_pre_get(&cm.local_id_table, GFP_KERNEL) );

Expand Down
135 changes: 127 additions & 8 deletions drivers/infiniband/core/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ static int alloc_name(char *name)
return 0;
}

static int start_port(struct ib_device *device)
{
return (device->node_type == RDMA_NODE_IB_SWITCH) ? 0 : 1;
}


static int end_port(struct ib_device *device)
{
return (device->node_type == RDMA_NODE_IB_SWITCH) ?
0 : device->phys_port_cnt;
}

/**
* ib_alloc_device - allocate an IB device struct
* @size:size of structure to allocate
Expand Down Expand Up @@ -209,6 +221,45 @@ static int add_client_context(struct ib_device *device, struct ib_client *client
return 0;
}

static int read_port_table_lengths(struct ib_device *device)
{
struct ib_port_attr *tprops = NULL;
int num_ports, ret = -ENOMEM;
u8 port_index;

tprops = kmalloc(sizeof *tprops, GFP_KERNEL);
if (!tprops)
goto out;

num_ports = end_port(device) - start_port(device) + 1;

device->pkey_tbl_len = kmalloc(sizeof *device->pkey_tbl_len * num_ports,
GFP_KERNEL);
device->gid_tbl_len = kmalloc(sizeof *device->gid_tbl_len * num_ports,
GFP_KERNEL);
if (!device->pkey_tbl_len || !device->gid_tbl_len)
goto err;

for (port_index = 0; port_index < num_ports; ++port_index) {
ret = ib_query_port(device, port_index + start_port(device),
tprops);
if (ret)
goto err;
device->pkey_tbl_len[port_index] = tprops->pkey_tbl_len;
device->gid_tbl_len[port_index] = tprops->gid_tbl_len;
}

ret = 0;
goto out;

err:
kfree(device->gid_tbl_len);
kfree(device->pkey_tbl_len);
out:
kfree(tprops);
return ret;
}

/**
* ib_register_device - Register an IB device with IB core
* @device:Device to register
Expand Down Expand Up @@ -240,10 +291,19 @@ int ib_register_device(struct ib_device *device)
spin_lock_init(&device->event_handler_lock);
spin_lock_init(&device->client_data_lock);

ret = read_port_table_lengths(device);
if (ret) {
printk(KERN_WARNING "Couldn't create table lengths cache for device %s\n",
device->name);
goto out;
}

ret = ib_device_register_sysfs(device);
if (ret) {
printk(KERN_WARNING "Couldn't register device %s with driver model\n",
device->name);
kfree(device->gid_tbl_len);
kfree(device->pkey_tbl_len);
goto out;
}

Expand Down Expand Up @@ -285,6 +345,9 @@ void ib_unregister_device(struct ib_device *device)

list_del(&device->core_list);

kfree(device->gid_tbl_len);
kfree(device->pkey_tbl_len);

mutex_unlock(&device_mutex);

spin_lock_irqsave(&device->client_data_lock, flags);
Expand Down Expand Up @@ -507,10 +570,7 @@ int ib_query_port(struct ib_device *device,
u8 port_num,
struct ib_port_attr *port_attr)
{
if (device->node_type == RDMA_NODE_IB_SWITCH) {
if (port_num)
return -EINVAL;
} else if (port_num < 1 || port_num > device->phys_port_cnt)
if (port_num < start_port(device) || port_num > end_port(device))
return -EINVAL;

return device->query_port(device, port_num, port_attr);
Expand Down Expand Up @@ -582,17 +642,76 @@ int ib_modify_port(struct ib_device *device,
u8 port_num, int port_modify_mask,
struct ib_port_modify *port_modify)
{
if (device->node_type == RDMA_NODE_IB_SWITCH) {
if (port_num)
return -EINVAL;
} else if (port_num < 1 || port_num > device->phys_port_cnt)
if (port_num < start_port(device) || port_num > end_port(device))
return -EINVAL;

return device->modify_port(device, port_num, port_modify_mask,
port_modify);
}
EXPORT_SYMBOL(ib_modify_port);

/**
* ib_find_gid - Returns the port number and GID table index where
* a specified GID value occurs.
* @device: The device to query.
* @gid: The GID value to search for.
* @port_num: The port number of the device where the GID value was found.
* @index: The index into the GID table where the GID was found. This
* parameter may be NULL.
*/
int ib_find_gid(struct ib_device *device, union ib_gid *gid,
u8 *port_num, u16 *index)
{
union ib_gid tmp_gid;
int ret, port, i;

for (port = start_port(device); port <= end_port(device); ++port) {
for (i = 0; i < device->gid_tbl_len[port - start_port(device)]; ++i) {
ret = ib_query_gid(device, port, i, &tmp_gid);
if (ret)
return ret;
if (!memcmp(&tmp_gid, gid, sizeof *gid)) {
*port_num = port;
if (index)
*index = i;
return 0;
}
}
}

return -ENOENT;
}
EXPORT_SYMBOL(ib_find_gid);

/**
* ib_find_pkey - Returns the PKey table index where a specified
* PKey value occurs.
* @device: The device to query.
* @port_num: The port number of the device to search for the PKey.
* @pkey: The PKey value to search for.
* @index: The index into the PKey table where the PKey was found.
*/
int ib_find_pkey(struct ib_device *device,
u8 port_num, u16 pkey, u16 *index)
{
int ret, i;
u16 tmp_pkey;

for (i = 0; i < device->pkey_tbl_len[port_num - start_port(device)]; ++i) {
ret = ib_query_pkey(device, port_num, i, &tmp_pkey);
if (ret)
return ret;

if (pkey == tmp_pkey) {
*index = i;
return 0;
}
}

return -ENOENT;
}
EXPORT_SYMBOL(ib_find_pkey);

static int __init ib_core_init(void)
{
int ret;
Expand Down
4 changes: 3 additions & 1 deletion drivers/infiniband/core/umem.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,10 @@ void ib_umem_release(struct ib_umem *umem)
__ib_umem_release(umem->context->device, umem, 1);

mm = get_task_mm(current);
if (!mm)
if (!mm) {
kfree(umem);
return;
}

diff = PAGE_ALIGN(umem->length + umem->offset) >> PAGE_SHIFT;

Expand Down
7 changes: 2 additions & 5 deletions drivers/infiniband/hw/ehca/ehca_mrmw.c
Original file line number Diff line number Diff line change
Expand Up @@ -2050,13 +2050,10 @@ int ehca_mrmw_map_hrc_alloc(const u64 hipz_rc)
switch (hipz_rc) {
case H_SUCCESS: /* successful completion */
return 0;
case H_ADAPTER_PARM: /* invalid adapter handle */
case H_RT_PARM: /* invalid resource type */
case H_NOT_ENOUGH_RESOURCES: /* insufficient resources */
case H_MLENGTH_PARM: /* invalid memory length */
case H_MEM_ACCESS_PARM: /* invalid access controls */
case H_CONSTRAINED: /* resource constraint */
return -EINVAL;
case H_NO_MEM:
return -ENOMEM;
case H_BUSY: /* long busy */
return -EBUSY;
default:
Expand Down
16 changes: 7 additions & 9 deletions drivers/infiniband/hw/ipath/ipath_verbs_mcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,9 @@ static int ipath_mcast_add(struct ipath_ibdev *dev,
{
struct rb_node **n = &mcast_tree.rb_node;
struct rb_node *pn = NULL;
unsigned long flags;
int ret;

spin_lock_irqsave(&mcast_lock, flags);
spin_lock_irq(&mcast_lock);

while (*n) {
struct ipath_mcast *tmcast;
Expand Down Expand Up @@ -228,7 +227,7 @@ static int ipath_mcast_add(struct ipath_ibdev *dev,
ret = 0;

bail:
spin_unlock_irqrestore(&mcast_lock, flags);
spin_unlock_irq(&mcast_lock);

return ret;
}
Expand Down Expand Up @@ -289,17 +288,16 @@ int ipath_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
struct ipath_mcast *mcast = NULL;
struct ipath_mcast_qp *p, *tmp;
struct rb_node *n;
unsigned long flags;
int last = 0;
int ret;

spin_lock_irqsave(&mcast_lock, flags);
spin_lock_irq(&mcast_lock);

/* Find the GID in the mcast table. */
n = mcast_tree.rb_node;
while (1) {
if (n == NULL) {
spin_unlock_irqrestore(&mcast_lock, flags);
spin_unlock_irq(&mcast_lock);
ret = -EINVAL;
goto bail;
}
Expand Down Expand Up @@ -334,7 +332,7 @@ int ipath_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
break;
}

spin_unlock_irqrestore(&mcast_lock, flags);
spin_unlock_irq(&mcast_lock);

if (p) {
/*
Expand All @@ -348,9 +346,9 @@ int ipath_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
atomic_dec(&mcast->refcount);
wait_event(mcast->wait, !atomic_read(&mcast->refcount));
ipath_mcast_free(mcast);
spin_lock(&dev->n_mcast_grps_lock);
spin_lock_irq(&dev->n_mcast_grps_lock);
dev->n_mcast_grps_allocated--;
spin_unlock(&dev->n_mcast_grps_lock);
spin_unlock_irq(&dev->n_mcast_grps_lock);
}

ret = 0;
Expand Down
Loading

0 comments on commit 8aee74c

Please sign in to comment.