From patchwork Wed Jul 8 22:30:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Ledford X-Patchwork-Id: 6751671 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DCB679F380 for ; Wed, 8 Jul 2015 22:31:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 151882054A for ; Wed, 8 Jul 2015 22:31:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2493D20549 for ; Wed, 8 Jul 2015 22:31:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751234AbbGHWbR (ORCPT ); Wed, 8 Jul 2015 18:31:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40857 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750908AbbGHWbR (ORCPT ); Wed, 8 Jul 2015 18:31:17 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 285F13D0058; Wed, 8 Jul 2015 22:31:17 +0000 (UTC) Received: from linux-ws.xsintricity.com ([10.10.116.25]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t68MVF0r022406; Wed, 8 Jul 2015 18:31:15 -0400 From: Doug Ledford To: linux-rdma@vger.kernel.org Cc: Or Gerlitz , Maninder Singh , Doug Ledford Subject: [PATCH for-4.2] IB/mlx4: Fix and optimize SRIOV slave init Date: Wed, 8 Jul 2015 18:30:58 -0400 Message-Id: <23f3dca9ff4b71155bd898be1f3cbd8eeb9df27f.1436394658.git.dledford@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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;