Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1965405ima; Thu, 25 Oct 2018 07:40:39 -0700 (PDT) X-Google-Smtp-Source: AJdET5cU7+rnFuM68xE9a4EhcpDrpjUfheTR+0Iq9Pb5DHdBy3WZWDg4DGa1jMnJQxO9zxksyzEF X-Received: by 2002:a63:1411:: with SMTP id u17-v6mr1682192pgl.247.1540478439307; Thu, 25 Oct 2018 07:40:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540478439; cv=none; d=google.com; s=arc-20160816; b=MOJYzHzz5Fh7v+Ld2F3NHvYY4rlif8o+3FKCW7K/7L7JGDk8KsQakyH+p8ndLTmU0E 5ZeuNoHr50y2JF3AGJnJgLhnCmw6tnXHjVVb8uhzveVOnHYTQbWQAtnN6RWEiUEsqrBN G/vL2G+tBrH31O7oERKfqsD4VCzdHIAR7t/4FG2UeYJuvHCyTsC6OHo15PnGsvCBfzuC 5ihtgkwjnXYaPZPFXds3tCVV9z7XQ48PxPoZpzSZwe3GdE2+JYbvBZGKixQotVfwJqFW TtVN2wZzdPR+FCglRdB2ydj/0abEEnvJDGVFZqz1OZRiCrpYamOIG2PfhQddXBcFfD5y 4AWg== 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=huRJvGZOqChjplI/yuVWYFNcacVmS2Y7ClXbvaW/uHU=; b=s6pda+jfTMlEFKIGIy0gwTdaUCml28wsN+1MlhJ3X7sZE7hCi8Txi2/lhGPGDrr+VL kZuHpS+5g8SNKchusy5DZLiFMnGnHcwqa4DWLfSI5tK719nxwdHrveAojCy1Yk/NjaA7 tZtaBrkECIwIoxJS+BXV/LcWIXPLGLHFJWmT00hXZKaQKVpCQ4SkKNSKFPXjvKOaFXF0 9GSPyOgdSdjlQgus2QssM7+6Wb8kmNj15jLamvypGWzmQSJWTTczXWKIs5vyvrX4RSja apu7pP+jWgx4foyzm3pqGcv1tEk1sHSwpiZXCOcjpJf8cDMmeCcSKVNSdxvSKXCkY62c 4aZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YA9yK2jD; 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 f1-v6si7900045pgv.468.2018.10.25.07.40.22; Thu, 25 Oct 2018 07:40:39 -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=YA9yK2jD; 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 S1729208AbeJYWs5 (ORCPT + 99 others); Thu, 25 Oct 2018 18:48:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:57842 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729199AbeJYWs5 (ORCPT ); Thu, 25 Oct 2018 18:48:57 -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 D29CA2085B; Thu, 25 Oct 2018 14:15:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1540476960; bh=/KliAhdLhstVlNIk/n02+ifXRuZ2/fSGwMYtLjmr7xo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YA9yK2jDSbE/e5uq2FCTSR61zhjRkcxaiZjc8iuzTSILredOMcMpQ6Zrl3mS4q0s9 toNkS9ACETh3Y6QXsP96lkf4XxgKQcIHv58XMtmLPx13R9em+/Q20j9JE7SyPEVXLy VayDOYR3E9wBsAGOJQfqk3bZ6hpwI8tTKXdWYiVg= 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.9 65/98] IB/ipoib: Fix lockdep issue found on ipoib_ib_dev_heavy_flush Date: Thu, 25 Oct 2018 10:13:50 -0400 Message-Id: <20181025141423.213774-65-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025141423.213774-1-sashal@kernel.org> References: <20181025141423.213774-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 34122c96522b..3dd5bf6c6c7a 100644 --- a/drivers/infiniband/ulp/ipoib/ipoib_ib.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_ib.c @@ -1190,13 +1190,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)) @@ -1236,7 +1233,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