Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4478651ybx; Mon, 4 Nov 2019 14:06:22 -0800 (PST) X-Google-Smtp-Source: APXvYqxSH4jwkjI+O921jRtsaut0PygtF9zqGfiOb2sR2y3ou6BfO+ljvPaF5BdKJqPJBEhA3/wz X-Received: by 2002:a17:906:7e41:: with SMTP id z1mr19054129ejr.63.1572905182055; Mon, 04 Nov 2019 14:06:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905182; cv=none; d=google.com; s=arc-20160816; b=Ef1UmDc9g9Sdio23T+MuUrJxopWzleQNzedJcvEjLi9D6VQNNpip3eFqeb20W4FfSR eA5YPP7xVLlFkMS4Nclc5y3m/n2ViqjMmM4NnIQL8Sw1UoAIYuOhMVie+xdT27eCzcTf ZmHbta1Y3+GnKrtgn6T1wiFnHtGyhDMErEc7OK9SvN/iurvSkfQD+NEgALmEmLG2AdAk uJnyComqDVe7TpcEQ4xe+RPA1Y6iVbe6mIpSXyIJvLinj7fEd1+jMeOJk0I5pjBQMvaF aDU4XPU4/kcqbjNG0EO+iyccT9U2XOUZ2hDUCHpRZqNGlYj9KdH2jQ1rmF1oRpMIJq8Y OOxQ== 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=2gjUDWCDIjXApZ7c00yMIoZh+OBLg0nXZ9QWfxjECKk=; b=aX5pmkl5x6adUWhWPTbpWv/wosk7BOpZbgD6vbxvevciFoAHMZOoohgiWawh0EWikg vUxZQBEvgWaq1BxyCQd3UOQm3Hjal48YpLzTvSvMDw3+A/aoEbIWyG/coKZAAYXW9jnT WJIOrrlq7q8x7USAhGSqhzuIfIVthQ0ibz0qc/QfnEoIfpasxW8FU7c3HebejCff7qVh ujtr++xZ7rN5T0v1wqCA2zHZI1CKgs4iYof9PCYsagXdWXMq1ioVmQBZgodqLQAwlPJA xkF5ioEd2JNokRacGX4hDbLiBulykn2AObqZt3erccWie+75E/7n9euJkmcYCOTrIQvP dUnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0YdradfU; 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 j12si8405662eda.406.2019.11.04.14.05.58; Mon, 04 Nov 2019 14:06:22 -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=0YdradfU; 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 S2389083AbfKDWEs (ORCPT + 99 others); Mon, 4 Nov 2019 17:04:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:35564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388145AbfKDWEq (ORCPT ); Mon, 4 Nov 2019 17:04:46 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (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 5D0EE2084D; Mon, 4 Nov 2019 22:04:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572905084; bh=Z8kNSpZKICsj64i1BK953BmpbaZEYmjCSvxuGKfVnTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0YdradfUxygHo1KbUa5/GZkgBbMm2jFpLqExPBEy/2ZjZKwDsSx97cHclN8lA8Vyj yl+RwzLpr7Hb49NCfjC7vQT1r2Mp5A0xSBt8hR472sO8DKXXOH55nLyO90mouqk/3s vVZjW6wy5HH+2gtHggCkBdhjRZu0JgbqTgOGuwwg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.3 024/163] RDMA/iwcm: Fix a lock inversion issue Date: Mon, 4 Nov 2019 22:43:34 +0100 Message-Id: <20191104212142.110758784@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212140.046021995@linuxfoundation.org> References: <20191104212140.046021995@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Bart Van Assche [ Upstream commit b66f31efbdad95ec274345721d99d1d835e6de01 ] This patch fixes the lock inversion complaint: ============================================ WARNING: possible recursive locking detected 5.3.0-rc7-dbg+ #1 Not tainted -------------------------------------------- kworker/u16:6/171 is trying to acquire lock: 00000000035c6e6c (&id_priv->handler_mutex){+.+.}, at: rdma_destroy_id+0x78/0x4a0 [rdma_cm] but task is already holding lock: 00000000bc7c307d (&id_priv->handler_mutex){+.+.}, at: iw_conn_req_handler+0x151/0x680 [rdma_cm] other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&id_priv->handler_mutex); lock(&id_priv->handler_mutex); *** DEADLOCK *** May be due to missing lock nesting notation 3 locks held by kworker/u16:6/171: #0: 00000000e2eaa773 ((wq_completion)iw_cm_wq){+.+.}, at: process_one_work+0x472/0xac0 #1: 000000001efd357b ((work_completion)(&work->work)#3){+.+.}, at: process_one_work+0x476/0xac0 #2: 00000000bc7c307d (&id_priv->handler_mutex){+.+.}, at: iw_conn_req_handler+0x151/0x680 [rdma_cm] stack backtrace: CPU: 3 PID: 171 Comm: kworker/u16:6 Not tainted 5.3.0-rc7-dbg+ #1 Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011 Workqueue: iw_cm_wq cm_work_handler [iw_cm] Call Trace: dump_stack+0x8a/0xd6 __lock_acquire.cold+0xe1/0x24d lock_acquire+0x106/0x240 __mutex_lock+0x12e/0xcb0 mutex_lock_nested+0x1f/0x30 rdma_destroy_id+0x78/0x4a0 [rdma_cm] iw_conn_req_handler+0x5c9/0x680 [rdma_cm] cm_work_handler+0xe62/0x1100 [iw_cm] process_one_work+0x56d/0xac0 worker_thread+0x7a/0x5d0 kthread+0x1bc/0x210 ret_from_fork+0x24/0x30 This is not a bug as there are actually two lock classes here. Link: https://lore.kernel.org/r/20190930231707.48259-3-bvanassche@acm.org Fixes: de910bd92137 ("RDMA/cma: Simplify locking needed for serialization of callbacks") Signed-off-by: Bart Van Assche Reviewed-by: Jason Gunthorpe Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/core/cma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c index a68d0ccf67a43..2e48b59926c19 100644 --- a/drivers/infiniband/core/cma.c +++ b/drivers/infiniband/core/cma.c @@ -2396,9 +2396,10 @@ static int iw_conn_req_handler(struct iw_cm_id *cm_id, conn_id->cm_id.iw = NULL; cma_exch(conn_id, RDMA_CM_DESTROYING); mutex_unlock(&conn_id->handler_mutex); + mutex_unlock(&listen_id->handler_mutex); cma_deref_id(conn_id); rdma_destroy_id(&conn_id->id); - goto out; + return ret; } mutex_unlock(&conn_id->handler_mutex); -- 2.20.1