Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2396058imu; Thu, 24 Jan 2019 12:03:08 -0800 (PST) X-Google-Smtp-Source: ALg8bN5iWcKn3DluSVGHCnVIKg3go5Br32HVSs1Lts4PZ2b9xLbTyEe6QQlFijUK5qnj71UBIXq2 X-Received: by 2002:a17:902:32c3:: with SMTP id z61mr7909087plb.114.1548360188632; Thu, 24 Jan 2019 12:03:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548360188; cv=none; d=google.com; s=arc-20160816; b=sHjtREEEjdLrwSK/cHpPAxYq3zG6166hLYrJwRYQl46JUL5oJOYvecVTVJR7kM/5i+ zFISsp7JRDxiJwOXfBDLH/WKixjNXxRiG43ENdUe+IEK+YEJjEm9hLtOKpt3tDRkMCzF SDHP4RqJYicMMjxAt9zoC1xVrzkZEcwvb/ddx9AvpwsN5m4o3lNX4rneSviEpWTG2yL4 BaCIT5HX2zLYOY7GWRMTa+rbPtjhvYpZ7FCemdqVCZi+8a2gv9Rv4ImqgF6T8JdiZlr4 5tbVVLvgWP16XSJvsdYMd+6VRYMrIupdx3d2z8wpBU5g/4vYZvxpvz/zW2OswRIpRo6/ /blA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=adtjzEy13nhXrYd1tGjgTo+z3Wc5mOIgIMA6S1Q8E8I=; b=FtP5MN+74wreFzDn3MTn4yeoZSW9/bVQaDV0hy0qvAlhx02nTSRTBnwfW189r9aCiW zgrimNe6oW6Y8h9QleTIYYCkX++U9HUrRfRFHYl6pUCunuJ52Vmd9e8qb9uHj9zVOWMg 8J/35OfbMoxZCzrxmLFmPNSnkRWsBlKM4e3PO6+IhnsLtxGYNvPtKd3ZYa2VPELKFsH4 VemKo4n1fOXAO6PrPzGZxcNBDwdItazKOPSvlmz08qaF3bRQiJ2mckIlHSzqhwYzMaJv Gq9KertqjRz2QNQk4cGqYVoOjnQpwgerrXsRuiipTvu1dwAoQXWe41EYlcqh2vnAzbYF baiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=E+JK2NVE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w17si22336429pgl.6.2019.01.24.12.02.53; Thu, 24 Jan 2019 12:03:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=E+JK2NVE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731918AbfAXTc7 (ORCPT + 99 others); Thu, 24 Jan 2019 14:32:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:60810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731897AbfAXTcx (ORCPT ); Thu, 24 Jan 2019 14:32:53 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5FD7321904; Thu, 24 Jan 2019 19:32:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548358372; bh=4eM+PzNyKp6NVXhIw5WHMYPQ7Yar8g26H66oWJzdnHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E+JK2NVEZIK8pV1DVAlO7dTvcYQEYqpixPUBre1loIVmiGGL3Sl6iqxoydEw6QvI3 EhVDU9ncekKoVCfIyVrvN4VOdaC9GA86WTFynYZwX7bqQkTwBX2XHDxDO+lIUl1JEV Mpqg3RfoSP/LSePe+ZiEireS4Icro2/mGO2knNmc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Parvi Kaustubhi , Jason Gunthorpe , Sasha Levin Subject: [PATCH 4.14 50/63] IB/usnic: Fix potential deadlock Date: Thu, 24 Jan 2019 20:20:39 +0100 Message-Id: <20190124190201.365930240@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190124190155.176570028@linuxfoundation.org> References: <20190124190155.176570028@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 8036e90f92aae2784b855a0007ae2d8154d28b3c ] 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 Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- 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 3c3453d213dc..fdfa25059723 100644 --- a/drivers/infiniband/hw/usnic/usnic_ib_verbs.c +++ b/drivers/infiniband/hw/usnic/usnic_ib_verbs.c @@ -310,13 +310,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; -- 2.19.1