Commit e3aa31c5 authored by Michael S. Tsirkin's avatar Michael S. Tsirkin Committed by Roland Dreier

IB/mthca: Don't cancel commands on a signal

We have run into the following problem: if a task receives a signal
while in the process of e.g. destroying a resource (which could be
because the relevant file was closed) mthca could bail out from trying
to take a command interface semaphore without performing the
appropriate command to tell hardware that the resource is being
destroyed.

As a result we see messages like
 ib_mthca 0000:04:00.0: HW2SW_CQ failed (-4)

In this case, hardware could access the resource after the memory has
been freed, possibly causing memory corruption.

A simple solution is to replace down_interruptible() by down() in
command interface activation.
Signed-off-by: default avatarMichael S. Tsirkin <mst@mellanox.co.il>
[ It's also not safe to bail out on multicast table operations, since
  they may be invoked on the cleanup path too.  So use down() for
  mcg_table.sem too. ]
Signed-off-by: default avatarRoland Dreier <rolandd@cisco.com>
parent 8e9e5f4f
...@@ -199,8 +199,7 @@ static int mthca_cmd_post(struct mthca_dev *dev, ...@@ -199,8 +199,7 @@ static int mthca_cmd_post(struct mthca_dev *dev,
{ {
int err = 0; int err = 0;
if (down_interruptible(&dev->cmd.hcr_sem)) down(&dev->cmd.hcr_sem);
return -EINTR;
if (event) { if (event) {
unsigned long end = jiffies + GO_BIT_TIMEOUT; unsigned long end = jiffies + GO_BIT_TIMEOUT;
...@@ -255,8 +254,7 @@ static int mthca_cmd_poll(struct mthca_dev *dev, ...@@ -255,8 +254,7 @@ static int mthca_cmd_poll(struct mthca_dev *dev,
int err = 0; int err = 0;
unsigned long end; unsigned long end;
if (down_interruptible(&dev->cmd.poll_sem)) down(&dev->cmd.poll_sem);
return -EINTR;
err = mthca_cmd_post(dev, in_param, err = mthca_cmd_post(dev, in_param,
out_param ? *out_param : 0, out_param ? *out_param : 0,
...@@ -333,8 +331,7 @@ static int mthca_cmd_wait(struct mthca_dev *dev, ...@@ -333,8 +331,7 @@ static int mthca_cmd_wait(struct mthca_dev *dev,
int err = 0; int err = 0;
struct mthca_cmd_context *context; struct mthca_cmd_context *context;
if (down_interruptible(&dev->cmd.event_sem)) down(&dev->cmd.event_sem);
return -EINTR;
spin_lock(&dev->cmd.context_lock); spin_lock(&dev->cmd.context_lock);
BUG_ON(dev->cmd.free_head < 0); BUG_ON(dev->cmd.free_head < 0);
......
...@@ -154,10 +154,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) ...@@ -154,10 +154,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
return PTR_ERR(mailbox); return PTR_ERR(mailbox);
mgm = mailbox->buf; mgm = mailbox->buf;
if (down_interruptible(&dev->mcg_table.sem)) { down(&dev->mcg_table.sem);
err = -EINTR;
goto err_sem;
}
err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index); err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index);
if (err) if (err)
...@@ -242,7 +239,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) ...@@ -242,7 +239,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
mthca_free(&dev->mcg_table.alloc, index); mthca_free(&dev->mcg_table.alloc, index);
} }
up(&dev->mcg_table.sem); up(&dev->mcg_table.sem);
err_sem:
mthca_free_mailbox(dev, mailbox); mthca_free_mailbox(dev, mailbox);
return err; return err;
} }
...@@ -263,10 +260,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) ...@@ -263,10 +260,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
return PTR_ERR(mailbox); return PTR_ERR(mailbox);
mgm = mailbox->buf; mgm = mailbox->buf;
if (down_interruptible(&dev->mcg_table.sem)) { down(&dev->mcg_table.sem);
err = -EINTR;
goto err_sem;
}
err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index); err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index);
if (err) if (err)
...@@ -372,7 +366,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) ...@@ -372,7 +366,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
out: out:
up(&dev->mcg_table.sem); up(&dev->mcg_table.sem);
err_sem:
mthca_free_mailbox(dev, mailbox); mthca_free_mailbox(dev, mailbox);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment