public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH for-4.2] IB/mlx4: Fix and optimize SRIOV slave init
@ 2015-07-08 22:30 Doug Ledford
       [not found] ` <23f3dca9ff4b71155bd898be1f3cbd8eeb9df27f.1436394658.git.dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Doug Ledford @ 2015-07-08 22:30 UTC (permalink / raw)
  To: linux-rdma-u79uwXL29TY76Z2rM5mHXA
  Cc: Or Gerlitz, Maninder Singh, Doug Ledford

In mlx4_main.c:do_slave_init(), the function is supposed to queue up
each work struct.  However, it checks to make sure the sriov support
isn't going down first.  When it is going down, it doesn't queue up the
work struct, which results in us leaking the work struct at the end of
the function.  As a fix, make sure that if we don't queue up the work
struct, then we kfree it instead.

The routine was also sub-optimal in its loop operations.  Instead of
taking and releasing a spin lock over and over again, let's just take it
once, and quickly loop through what needs to be done under the spin lock
and then release it.

Signed-off-by: Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 drivers/infiniband/hw/mlx4/main.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index 064454aee863..3f21a5565af2 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -2681,19 +2681,21 @@ static void do_slave_init(struct mlx4_ib_dev *ibdev, int slave, int do_init)
 				kfree(dm[i]);
 			goto out;
 		}
-	}
-	/* initialize or tear down tunnel QPs for the slave */
-	for (i = 0; i < ports; i++) {
 		INIT_WORK(&dm[i]->work, mlx4_ib_tunnels_update_work);
 		dm[i]->port = first_port + i + 1;
 		dm[i]->slave = slave;
 		dm[i]->do_init = do_init;
 		dm[i]->dev = ibdev;
-		spin_lock_irqsave(&ibdev->sriov.going_down_lock, flags);
-		if (!ibdev->sriov.is_going_down)
-			queue_work(ibdev->sriov.demux[i].ud_wq, &dm[i]->work);
-		spin_unlock_irqrestore(&ibdev->sriov.going_down_lock, flags);
 	}
+	/* initialize or tear down tunnel QPs for the slave */
+	spin_lock_irqsave(&ibdev->sriov.going_down_lock, flags);
+	if (!ibdev->sriov.is_going_down)
+		for (i = 0; i < ports; i++)
+			queue_work(ibdev->sriov.demux[i].ud_wq, &dm[i]->work);
+	else
+		for (i = 0; i < ports; i++)
+			kfree(dm[i]);
+	spin_unlock_irqrestore(&ibdev->sriov.going_down_lock, flags);
 out:
 	kfree(dm);
 	return;
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-07-09 14:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-08 22:30 [PATCH for-4.2] IB/mlx4: Fix and optimize SRIOV slave init Doug Ledford
     [not found] ` <23f3dca9ff4b71155bd898be1f3cbd8eeb9df27f.1436394658.git.dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-07-09  8:28   ` Or Gerlitz
     [not found]     ` <559E30C3.5050702-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-07-09 12:31       ` Doug Ledford
     [not found]         ` <559E69AD.9050406-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-07-09 14:02           ` Or Gerlitz
     [not found]             ` <559E7EFA.3070805-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-07-09 14:27               ` Doug Ledford

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox