Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1972238ima; Thu, 25 Oct 2018 07:46:24 -0700 (PDT) X-Google-Smtp-Source: AJdET5dbYKzen9+vq4779QLk8qKdshWkSzlEnTyq2CqhRBWbQnYR+OogzhyxvTl1WaAvmTID+8+J X-Received: by 2002:a62:32c4:: with SMTP id y187-v6mr1870051pfy.4.1540478784660; Thu, 25 Oct 2018 07:46:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540478784; cv=none; d=google.com; s=arc-20160816; b=m9SYSYM/ZH+OMwU0tC8Xjs7sIuOTY2Mz0hhkhFbxZoKtgMjngHvhfLiXKAcJHUaDZE 6aRBZsaXQKuWGUXUw7al7Vh076hTGEy7Zr/DNFQgFD9PAubsmjBmrMt6Sa/sv/1Lo424 te350Ff7Piak/LK8UmUQgJNLx9m1Kr2iv5Yms1r9GiVMWjhd1pDB02fMfbl7fmYUKpVs tOukwd9SDg2YB9vgKBHwmP8SqRWTUpQn11jQfMS+QvWVCzTqF8UMYwL5EZeAsz8lZezL GP6EgmMA1kB8nS7j0NwTUGoNdn2akyYGleXULWGzfwgmh8zZAmhxj8ipfyKH0n5WziQc 374g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=Umeh0WQFVO3FO4p8xejnqrWZvNz2C2V4AHTx2+aQeMw=; b=kaWp6DhZz7j5Fa98EuJ26UWbD9l89ilY2sL980VxgURxz+lDnXmmZZaZ0+Pvogl+Rp CZoE/nXkmoNb6jUSk8bWTzrxtnWahjPUphOLNv/Wc3sm+MHzOmGTWolunCwJNaNE5D9k u60NZFmcFF20TKlK13UblUfP/zpoyj9yEkP+2GZdx8F1VMNlcwJ1pfxg7LwZ85cOuej7 6uCkl87X8GPF0XG75Bg/F13p3XH5DUk9AmkwbRkYxVmpoPXRDlwTUBoVHc2GSncrK/DU WubAFHRn31jidJH0w+zQTvyZbAQykwdWxFuDgUMvxNRgjQXo41iGTzN4sFyJEHIhBo+8 rEXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nwKi1Zm2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8-v6si8160352pga.6.2018.10.25.07.46.05; Thu, 25 Oct 2018 07:46:24 -0700 (PDT) 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=nwKi1Zm2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727876AbeJYWoD (ORCPT + 99 others); Thu, 25 Oct 2018 18:44:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:52554 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727518AbeJYWoC (ORCPT ); Thu, 25 Oct 2018 18:44:02 -0400 Received: from sasha-vm.mshome.net (unknown [167.98.65.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F395F20840; Thu, 25 Oct 2018 14:11:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1540476667; bh=PviyBiI5cs/Wbgdh9FnHeOak49NOT3EkZg2ofT89CZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nwKi1Zm2vwF6IL3qiPPJB2RpH+K5YBcmhNqjqIgWfVI6Gzfy1DykxrnwBRfwUf+tl 2Mv6LQfJw/AFzZGWSFz4JS9dC8hz8WMYxZzGruYfmd/0lWjpsJbGrHEETsHRloEYpr +zFlMejUP32ptDdf1k8afkgG0ZTDuXpxYOS+Nx08= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Alex Vesker , Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH AUTOSEL 4.14 08/46] IB/ipoib: Fix lockdep issue found on ipoib_ib_dev_heavy_flush Date: Thu, 25 Oct 2018 10:10:15 -0400 Message-Id: <20181025141053.213330-8-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025141053.213330-1-sashal@kernel.org> References: <20181025141053.213330-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alex Vesker [ Upstream commit 1f80bd6a6cc8358b81194e1f5fc16449947396ec ] The locking order of vlan_rwsem (LOCK A) and then rtnl (LOCK B), contradicts other flows such as ipoib_open possibly causing a deadlock. To prevent this deadlock heavy flush is called with RTNL locked and only then tries to acquire vlan_rwsem. This deadlock is possible only when there are child interfaces. [ 140.941758] ====================================================== [ 140.946276] WARNING: possible circular locking dependency detected [ 140.950950] 4.15.0-rc1+ #9 Tainted: G O [ 140.954797] ------------------------------------------------------ [ 140.959424] kworker/u32:1/146 is trying to acquire lock: [ 140.963450] (rtnl_mutex){+.+.}, at: [] __ipoib_ib_dev_flush+0x2da/0x4e0 [ib_ipoib] [ 140.970006] but task is already holding lock: [ 140.975141] (&priv->vlan_rwsem){++++}, at: [] __ipoib_ib_dev_flush+0x51/0x4e0 [ib_ipoib] [ 140.982105] which lock already depends on the new lock. [ 140.990023] the existing dependency chain (in reverse order) is: [ 140.998650] -> #1 (&priv->vlan_rwsem){++++}: [ 141.005276] down_read+0x4d/0xb0 [ 141.009560] ipoib_open+0xad/0x120 [ib_ipoib] [ 141.014400] __dev_open+0xcb/0x140 [ 141.017919] __dev_change_flags+0x1a4/0x1e0 [ 141.022133] dev_change_flags+0x23/0x60 [ 141.025695] devinet_ioctl+0x704/0x7d0 [ 141.029156] sock_do_ioctl+0x20/0x50 [ 141.032526] sock_ioctl+0x221/0x300 [ 141.036079] do_vfs_ioctl+0xa6/0x6d0 [ 141.039656] SyS_ioctl+0x74/0x80 [ 141.042811] entry_SYSCALL_64_fastpath+0x1f/0x96 [ 141.046891] -> #0 (rtnl_mutex){+.+.}: [ 141.051701] lock_acquire+0xd4/0x220 [ 141.055212] __mutex_lock+0x88/0x970 [ 141.058631] __ipoib_ib_dev_flush+0x2da/0x4e0 [ib_ipoib] [ 141.063160] __ipoib_ib_dev_flush+0x71/0x4e0 [ib_ipoib] [ 141.067648] process_one_work+0x1f5/0x610 [ 141.071429] worker_thread+0x4a/0x3f0 [ 141.074890] kthread+0x141/0x180 [ 141.078085] ret_from_fork+0x24/0x30 [ 141.081559] other info that might help us debug this: [ 141.088967] Possible unsafe locking scenario: [ 141.094280] CPU0 CPU1 [ 141.097953] ---- ---- [ 141.101640] lock(&priv->vlan_rwsem); [ 141.104771] lock(rtnl_mutex); [ 141.109207] lock(&priv->vlan_rwsem); [ 141.114032] lock(rtnl_mutex); [ 141.116800] *** DEADLOCK *** Fixes: b4b678b06f6e ("IB/ipoib: Grab rtnl lock on heavy flush when calling ndo_open/stop") Signed-off-by: Alex Vesker Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/ulp/ipoib/ipoib_ib.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ib.c b/drivers/infiniband/ulp/ipoib/ipoib_ib.c index c97384c914a4..d77e8e2ae05f 100644 --- a/drivers/infiniband/ulp/ipoib/ipoib_ib.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_ib.c @@ -1203,13 +1203,10 @@ static void __ipoib_ib_dev_flush(struct ipoib_dev_priv *priv, ipoib_ib_dev_down(dev); if (level == IPOIB_FLUSH_HEAVY) { - rtnl_lock(); if (test_bit(IPOIB_FLAG_INITIALIZED, &priv->flags)) ipoib_ib_dev_stop(dev); - result = ipoib_ib_dev_open(dev); - rtnl_unlock(); - if (result) + if (ipoib_ib_dev_open(dev)) return; if (netif_queue_stopped(dev)) @@ -1249,7 +1246,9 @@ void ipoib_ib_dev_flush_heavy(struct work_struct *work) struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv, flush_heavy); + rtnl_lock(); __ipoib_ib_dev_flush(priv, IPOIB_FLUSH_HEAVY, 0); + rtnl_unlock(); } void ipoib_ib_dev_cleanup(struct net_device *dev) -- 2.17.1