Received: by 10.223.185.116 with SMTP id b49csp2203844wrg; Mon, 12 Feb 2018 06:08:33 -0800 (PST) X-Google-Smtp-Source: AH8x224u1WzeXWJHmA6H6GVG4NWx31/v3CKmWLshhBSENXj4q2aVJzj8GMEIy+jQ4Kb7YGQp+tki X-Received: by 10.99.96.18 with SMTP id u18mr8356788pgb.124.1518444513692; Mon, 12 Feb 2018 06:08:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518444513; cv=none; d=google.com; s=arc-20160816; b=t1t1E3cwcJtN0S2v2qBjbM6yLnjaiA0HaqTWs0DphPzpmdZMS1bUV4vHcDB4R29qGA cHojws11hHKzdxcxBcmSnGNxuehe6VNFu9kFQ8j4Gjt5p5/jbaDWZh5S5ZtnXnxAG9XL n0z3pnfUg68WJ1iRcyguZ7QPaiNjZ35W03MJuVtqG/9w1yvXKyNH+0+/+di4JehqAlpX jY/meL8ctocxHad40qie7WwGoSc4bpWFOmN/f1TDKUcTz0sj83l/7GUN/ElEFtcm9/iL 6PHD+JkhNTQBM7NzZQOwQv76F7drPuiVOg7/ger3z1Ub4iUhBsxVSpRpCn09UeOQY8PP FAng== 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:arc-authentication-results; bh=bt5P/ZKwUPLcBwjIFfefD55JI7HJ5Cop2/OE8BJbess=; b=H1CibM8xZlMK4GOs8TrNdUZ4bip0B2e4CKmjvU+hrSUpS9OUePcG+ejOpHzeUjoK6k WxltntD7UIL8QgbgcRtdYmOzkE1o3q5d5u+UYBhsD9WFn9izLAp0uHN8I6jKJrZzxBWK gxW5XcnzTV0BRzo0TH+6B45mGAb2iqQizXbHvCXSAVDsYqYRhN7ZPfm4i16SFjB/xK6x iOkhiA+XOVQxZZS9xrcz95qqXdHNbycVnfzntnHqBiTV6pbCHiN+NEhvTAoRkfbXPVwR MZrU5Yi4TkkLiTifv08Ert/skNtNVhW3tRzXCiFGPq9c2qEQ6IdoaYYSFbDq4cMPYX5t faoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=jWo9od4J; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p189si6363268pfg.297.2018.02.12.06.08.17; Mon, 12 Feb 2018 06:08:33 -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=@oracle.com header.s=corp-2017-10-26 header.b=jWo9od4J; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935009AbeBLMz3 (ORCPT + 99 others); Mon, 12 Feb 2018 07:55:29 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:56580 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933341AbeBLMzY (ORCPT ); Mon, 12 Feb 2018 07:55:24 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w1CCqNmV084781; Mon, 12 Feb 2018 12:54:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=bt5P/ZKwUPLcBwjIFfefD55JI7HJ5Cop2/OE8BJbess=; b=jWo9od4JaKjuKzZx0PngWn7w6ycNX8m0kQ0xKxubYPjScfW6E0CCAmqdAT2PsWvqE40C ssgkUNfqVWJf8ZYmnkHKEx9xQ6fzctR3jLOJ3q4H5fDAd9RiKa+7X7IJRDIB8HhcAeYT tMYGQzqUpyxnoSs0SRKVk30qvcRFKGGs38F7eUwCGSV4baDvgCDq/aoIt4hvMrRrfq/x ZJmW/bb/GJf4Q746rtPDEpc5vJMVO8hSWGkyoGwjDp8/8IUSKWnTrVQPr+5TLJTCghfY /S2eVM0Pcl0hYNx+q/AuLahNVmeomjPMubFXMdEp5Mpk0cX03J18LQcF7eT7TNH8pIB4 qw== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2g3ad909q3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 Feb 2018 12:54:46 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w1CCsjnC022692 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 12 Feb 2018 12:54:46 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w1CCsjgA012950; Mon, 12 Feb 2018 12:54:45 GMT Received: from will-ThinkCentre-M910s.cn.oracle.com (/10.182.70.254) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 12 Feb 2018 04:54:45 -0800 From: Jianchao Wang To: keith.busch@intel.com, axboe@fb.com, hch@lst.de, sagi@grimberg.me Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] nvme: fix the deadlock in nvme_update_formats Date: Mon, 12 Feb 2018 20:54:45 +0800 Message-Id: <1518440086-583-2-git-send-email-jianchao.w.wang@oracle.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518440086-583-1-git-send-email-jianchao.w.wang@oracle.com> References: <1518440086-583-1-git-send-email-jianchao.w.wang@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8802 signatures=668668 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=681 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1802120167 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org nvme_update_formats will invoke nvme_ns_remove under namespaces_mutext. The will cause deadlock because nvme_ns_remove will also require the namespaces_mutext. Fix it by getting the ns entries which should be removed under namespaces_mutext and invoke nvme_ns_remove out of namespaces_mutext. Signed-off-by: Jianchao Wang --- drivers/nvme/host/core.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index d05855b..a051c2f 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1119,14 +1119,19 @@ static u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, static void nvme_update_formats(struct nvme_ctrl *ctrl) { - struct nvme_ns *ns; + struct nvme_ns *ns, *next; + LIST_HEAD(rm_list); mutex_lock(&ctrl->namespaces_mutex); list_for_each_entry(ns, &ctrl->namespaces, list) { - if (ns->disk && nvme_revalidate_disk(ns->disk)) - nvme_ns_remove(ns); + if (ns->disk && nvme_revalidate_disk(ns->disk)) { + list_move_tail(&ns->list, &rm_list); + } } mutex_unlock(&ctrl->namespaces_mutex); + + list_for_each_entry_safe(ns, next, &rm_list, list) + nvme_ns_remove(ns); } static void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects) -- 2.7.4