From patchwork Tue Dec 11 22:15:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Parvi Kaustubhi (pkaustub)" X-Patchwork-Id: 10724931 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AC3DD1869 for ; Tue, 11 Dec 2018 22:25:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 985F32AA69 for ; Tue, 11 Dec 2018 22:25:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 898792AAF5; Tue, 11 Dec 2018 22:25:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 392752AA69 for ; Tue, 11 Dec 2018 22:25:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726314AbeLKWZF (ORCPT ); Tue, 11 Dec 2018 17:25:05 -0500 Received: from alln-iport-3.cisco.com ([173.37.142.90]:30078 "EHLO alln-iport-3.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726183AbeLKWZF (ORCPT ); Tue, 11 Dec 2018 17:25:05 -0500 X-Greylist: delayed 557 seconds by postgrey-1.27 at vger.kernel.org; Tue, 11 Dec 2018 17:25:04 EST DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=1649; q=dns/txt; s=iport; t=1544567104; x=1545776704; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=QB/pe2R2yy5XuCpnaM8kOsCkqLAcoNa4j4jceXQC6wU=; b=BYyG0iCvkbdnC3mHwGac2BDovS/ljyQ/xTvz+l4RjJFtOlqMA4ddRQ+U UoFXAnt/sGGtH00NngbCpIqKABS/A0Oi5kvi3LSxU3IXq4DQkeoHQzqdU 4hRsBaWW9OOjh4lw7/UMJLYpw3OaD5rXFwVK5tEGlktPiCq9ZD17JI8ba E=; X-IronPort-AV: E=Sophos;i="5.56,343,1539648000"; d="scan'208";a="211960244" Received: from rcdn-core-6.cisco.com ([173.37.93.157]) by alln-iport-3.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2018 22:15:48 +0000 Received: from cisco.com (savbu-usnic-a.cisco.com [10.193.184.48]) by rcdn-core-6.cisco.com (8.15.2/8.15.2) with ESMTP id wBBMFlXe004112; Tue, 11 Dec 2018 22:15:47 GMT Received: by cisco.com (Postfix, from userid 478433) id 8638720F2001; Tue, 11 Dec 2018 14:15:47 -0800 (PST) From: Parvi Kaustubhi To: linux-rdma@vger.kernel.org Cc: pkaustub@cisco.com, benve@cisco.com, gvaradar@cisco.com, tinamdar@cisco.com, neescoba@cisco.com, ravianan@cisco.com, jsquyres@cisco.com Subject: [PATCH for-next 2/3] IB/usnic: fix potential deadlock Date: Tue, 11 Dec 2018 14:15:42 -0800 Message-Id: <1544566543-3395-3-git-send-email-pkaustub@cisco.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1544566543-3395-1-git-send-email-pkaustub@cisco.com> References: <1544566543-3395-1-git-send-email-pkaustub@cisco.com> X-Outbound-SMTP-Client: 10.193.184.48, savbu-usnic-a.cisco.com X-Outbound-Node: rcdn-core-6.cisco.com Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Acquiring the rtnl lock while holding usdev_lock could result in a deadlock. For example: usnic_ib_query_port() | mutex_lock(&us_ibdev->usdev_lock) | ib_get_eth_speed() | rtnl_lock() rtnl_lock() | usnic_ib_netdevice_event() | mutex_lock(&us_ibdev->usdev_lock) This commit moves the usdev_lock acquisition after the rtnl lock has been released. This is safe to do because usdev_lock is not protecting anything being accessed in ib_get_eth_speed(). Hence, the correct order of holding locks (rtnl -> usdev_lock) is not violated. Signed-off-by: Parvi Kaustubhi --- drivers/infiniband/hw/usnic/usnic_ib_verbs.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/hw/usnic/usnic_ib_verbs.c b/drivers/infiniband/hw/usnic/usnic_ib_verbs.c index 0b91ff3..598e23c 100644 --- a/drivers/infiniband/hw/usnic/usnic_ib_verbs.c +++ b/drivers/infiniband/hw/usnic/usnic_ib_verbs.c @@ -336,13 +336,16 @@ int usnic_ib_query_port(struct ib_device *ibdev, u8 port, usnic_dbg("\n"); - mutex_lock(&us_ibdev->usdev_lock); if (ib_get_eth_speed(ibdev, port, &props->active_speed, - &props->active_width)) { - mutex_unlock(&us_ibdev->usdev_lock); + &props->active_width)) return -EINVAL; - } + /* + * usdev_lock is acquired after (and not before) ib_get_eth_speed call + * because acquiring rtnl_lock in ib_get_eth_speed, while holding + * usdev_lock could lead to a deadlock. + */ + mutex_lock(&us_ibdev->usdev_lock); /* props being zeroed by the caller, avoid zeroing it here */ props->lid = 0;