[ofa-general] CM sysfs-related oops on device driver reload
Roland Dreier
rdreier at cisco.com
Fri Feb 8 20:48:13 PST 2008
OK, I think the following should make things work better:
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index 638b727..017fdcf 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -159,7 +159,7 @@ struct cm_port {
struct ib_mad_agent *mad_agent;
struct kobject port_obj;
u8 port_num;
- struct cm_counter_group counter_group[CM_COUNTER_GROUPS];
+ struct cm_counter_group *counter_group[CM_COUNTER_GROUPS];
};
struct cm_device {
@@ -1363,7 +1363,7 @@ static void cm_dup_req_handler(struct cm_work *work,
struct ib_mad_send_buf *msg = NULL;
int ret;
- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+ atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES]->
counter[CM_REQ_COUNTER]);
/* Quick state check to discard duplicate REQs. */
@@ -1741,7 +1741,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
if (!cm_id_priv)
return;
- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+ atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES]->
counter[CM_REP_COUNTER]);
ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
if (ret)
@@ -1908,7 +1908,7 @@ static int cm_rtu_handler(struct cm_work *work)
if (cm_id_priv->id.state != IB_CM_REP_SENT &&
cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
spin_unlock_irq(&cm_id_priv->lock);
- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+ atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES]->
counter[CM_RTU_COUNTER]);
goto out;
}
@@ -2087,7 +2087,7 @@ static int cm_dreq_handler(struct cm_work *work)
cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
dreq_msg->local_comm_id);
if (!cm_id_priv) {
- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+ atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES]->
counter[CM_DREQ_COUNTER]);
cm_issue_drep(work->port, work->mad_recv_wc);
return -EINVAL;
@@ -2108,7 +2108,7 @@ static int cm_dreq_handler(struct cm_work *work)
case IB_CM_MRA_REP_RCVD:
break;
case IB_CM_TIMEWAIT:
- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+ atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES]->
counter[CM_DREQ_COUNTER]);
if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
goto unlock;
@@ -2122,7 +2122,7 @@ static int cm_dreq_handler(struct cm_work *work)
cm_free_msg(msg);
goto deref;
case IB_CM_DREQ_RCVD:
- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+ atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES]->
counter[CM_DREQ_COUNTER]);
goto unlock;
default:
@@ -2479,7 +2479,7 @@ static int cm_mra_handler(struct cm_work *work)
cm_id_priv->msg, timeout)) {
if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
atomic_long_inc(&work->port->
- counter_group[CM_RECV_DUPLICATES].
+ counter_group[CM_RECV_DUPLICATES]->
counter[CM_MRA_COUNTER]);
goto out;
}
@@ -2487,7 +2487,7 @@ static int cm_mra_handler(struct cm_work *work)
break;
case IB_CM_MRA_REQ_RCVD:
case IB_CM_MRA_REP_RCVD:
- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+ atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES]->
counter[CM_MRA_COUNTER]);
/* fall through */
default:
@@ -2649,7 +2649,7 @@ static int cm_lap_handler(struct cm_work *work)
case IB_CM_LAP_IDLE:
break;
case IB_CM_MRA_LAP_SENT:
- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+ atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES]->
counter[CM_LAP_COUNTER]);
if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
goto unlock;
@@ -2665,7 +2665,7 @@ static int cm_lap_handler(struct cm_work *work)
cm_free_msg(msg);
goto deref;
case IB_CM_LAP_RCVD:
- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+ atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES]->
counter[CM_LAP_COUNTER]);
goto unlock;
default:
@@ -2949,7 +2949,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
if (cur_cm_id_priv) {
spin_unlock_irq(&cm.lock);
- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
+ atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES]->
counter[CM_SIDR_REQ_COUNTER]);
goto out; /* Duplicate message. */
}
@@ -3161,10 +3161,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
msg->retries = 1;
atomic_long_add(1 + msg->retries,
- &port->counter_group[CM_XMIT].counter[attr_index]);
+ &port->counter_group[CM_XMIT]->counter[attr_index]);
if (msg->retries)
atomic_long_add(msg->retries,
- &port->counter_group[CM_XMIT_RETRIES].
+ &port->counter_group[CM_XMIT_RETRIES]->
counter[attr_index]);
switch (mad_send_wc->status) {
@@ -3373,7 +3373,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
}
attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
- atomic_long_inc(&port->counter_group[CM_RECV].
+ atomic_long_inc(&port->counter_group[CM_RECV]->
counter[attr_id - CM_ATTR_ID_OFFSET]);
work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
@@ -3561,6 +3561,14 @@ static void cm_get_ack_delay(struct cm_device *cm_dev)
cm_dev->ack_delay = attr.local_ca_ack_delay;
}
+static void cm_release_counter_obj(struct kobject *obj)
+{
+ struct cm_counter_group *counter_group;
+
+ counter_group = container_of(obj, struct cm_counter_group, obj);
+ kfree(counter_group);
+}
+
static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
char *buf)
{
@@ -3579,6 +3587,7 @@ static struct sysfs_ops cm_counter_ops = {
};
static struct kobj_type cm_counter_obj_type = {
+ .release = cm_release_counter_obj,
.sysfs_ops = &cm_counter_ops,
.default_attrs = cm_counter_default_attrs
};
@@ -3587,8 +3596,6 @@ static void cm_release_port_obj(struct kobject *obj)
{
struct cm_port *cm_port;
- printk(KERN_ERR "free cm port\n");
-
cm_port = container_of(obj, struct cm_port, port_obj);
kfree(cm_port);
}
@@ -3601,8 +3608,6 @@ static void cm_release_dev_obj(struct kobject *obj)
{
struct cm_device *cm_dev;
- printk(KERN_ERR "free cm dev\n");
-
cm_dev = container_of(obj, struct cm_device, dev_obj);
kfree(cm_dev);
}
@@ -3616,18 +3621,12 @@ struct class cm_class = {
};
EXPORT_SYMBOL(cm_class);
-static void cm_remove_fs_obj(struct kobject *obj)
-{
- kobject_put(obj->parent);
- kobject_put(obj);
-}
-
static int cm_create_port_fs(struct cm_port *port)
{
int i, ret;
ret = kobject_init_and_add(&port->port_obj, &cm_port_obj_type,
- kobject_get(&port->cm_dev->dev_obj),
+ &port->cm_dev->dev_obj,
"%d", port->port_num);
if (ret) {
kfree(port);
@@ -3635,20 +3634,30 @@ static int cm_create_port_fs(struct cm_port *port)
}
for (i = 0; i < CM_COUNTER_GROUPS; i++) {
- ret = kobject_init_and_add(&port->counter_group[i].obj,
+ port->counter_group[i] = kzalloc(sizeof *port->counter_group[i],
+ GFP_KERNEL);
+ if (!port->counter_group[i]) {
+ ret = -ENOMEM;
+ goto error;
+ }
+
+ ret = kobject_init_and_add(&port->counter_group[i]->obj,
&cm_counter_obj_type,
- kobject_get(&port->port_obj),
+ &port->port_obj,
"%s", counter_group_names[i]);
- if (ret)
+ if (ret) {
+ kfree(port->counter_group[i]);
goto error;
+ }
}
return 0;
error:
while (i--)
- cm_remove_fs_obj(&port->counter_group[i].obj);
- cm_remove_fs_obj(&port->port_obj);
+ kobject_put(&port->counter_group[i]->obj);
+
+ kobject_put(&port->port_obj);
return ret;
}
@@ -3658,9 +3667,9 @@ static void cm_remove_port_fs(struct cm_port *port)
int i;
for (i = 0; i < CM_COUNTER_GROUPS; i++)
- cm_remove_fs_obj(&port->counter_group[i].obj);
+ kobject_put(&port->counter_group[i]->obj);
- cm_remove_fs_obj(&port->port_obj);
+ kobject_put(&port->port_obj);
}
static void cm_add_one(struct ib_device *device)
@@ -3744,7 +3753,7 @@ error1:
ib_unregister_mad_agent(port->mad_agent);
cm_remove_port_fs(port);
}
- cm_remove_fs_obj(&cm_dev->dev_obj);
+ kobject_put(&cm_dev->dev_obj);
}
static void cm_remove_one(struct ib_device *device)
@@ -3771,7 +3780,7 @@ static void cm_remove_one(struct ib_device *device)
ib_unregister_mad_agent(port->mad_agent);
cm_remove_port_fs(port);
}
- cm_remove_fs_obj(&cm_dev->dev_obj);
+ kobject_put(&cm_dev->dev_obj);
}
static int __init ib_cm_init(void)
More information about the general
mailing list