Received: by 10.213.65.68 with SMTP id h4csp1728495imn; Mon, 19 Mar 2018 11:36:34 -0700 (PDT) X-Google-Smtp-Source: AG47ELtfr3xyLiTNOcTkBux3iKLK5UBUGn3xFR2AqxTTK210+Cl3VF1zzEEgClV+UZ+wIv93tXbp X-Received: by 10.98.198.92 with SMTP id m89mr11094106pfg.73.1521484594370; Mon, 19 Mar 2018 11:36:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521484594; cv=none; d=google.com; s=arc-20160816; b=0sF/RF4rC2HZkS8i+Ib54/2awzJJexJEDiOWZ6L3C3gsJrVgfcyRUDpHzoVjZqYdQZ y+kLtrycfpO0tycQXYXVzdtam7+OIUNkLky2GCN9uALJyAMxB16lZ/C1Ktvx9IeFynff amq3D3gLWFNOgOApJ1b8Ta8OYJUe5lANDQV8A7CGeb5WnpgI0gPfNf8P03VpFiQ5zBMh JQa4wrYw3ijyHVsxAo0AIQbRLYkVIAn4jO2WPokaN+gYdXU/czoJTNPP4UQEPNI0DZId AjvfHx6xziOf93SuTMbh/PGBWOUXF+P70ae3cqs9gHxGbHSl5idgM7luosoFntBDTc9J 87Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=8si3MwNYefvv6HAh/VXXhjibX7E/kTKry1rBNlUMJms=; b=0vIS0NCDZF7+P1EKPVC3lyubI5Pr4A6RMcn6ha2IB0bODuNwrjNbBAFN+QOk64ZOci PDeD9KQhUR2+L9CaZsnukq9PWy08GYZLLzy+hXAMlZiyYto9rfFc2Pw0UdhDfCauqSl4 C6zJ79IqY/3ZyiEhxYzrjJbdDM3DfYjC7aJM1YDKD9fQEB/ohQmR1bjSfWHpGYzqO87v IIHhYwGXk1ty/CGRdVQFX6hfMTXS7E9h874ldxaAEBPhdSNgg1DzVZvx4hPKvf5evE7l AQpbkFoXwOZXTytnrSon/5bVnJYv1pL6bqLrF6agdzHLWvI1COL+fGpG8AkJOQkQOhH4 DzDw== ARC-Authentication-Results: i=1; mx.google.com; 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 61-v6si442282plr.136.2018.03.19.11.36.20; Mon, 19 Mar 2018 11:36:34 -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; 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 S1032264AbeCSSez (ORCPT + 99 others); Mon, 19 Mar 2018 14:34:55 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:54198 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032187AbeCSSdQ (ORCPT ); Mon, 19 Mar 2018 14:33:16 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 3228312BC; Mon, 19 Mar 2018 18:33:15 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Max Gurtovoy , Israel Rukshin , Christoph Hellwig , Keith Busch Subject: [PATCH 4.15 30/52] nvme: fix subsystem multiple controllers support check Date: Mon, 19 Mar 2018 19:08:28 +0100 Message-Id: <20180319180736.736965575@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180734.976730813@linuxfoundation.org> References: <20180319180734.976730813@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Israel Rukshin commit b837b28394fb76993c28bb242db7061ee0417da6 upstream. There is a problem when another module (e.g. nvmet) takes a reference on the nvme block device and the physical nvme drive is removed. In that case nvme_free_ctrl() will not be called and the controller state will be "deleting" or "dead" unless nvmet module releases the block device. Later on, the same nvme drive probes back and nvme_init_subsystem() will be called and fail due to duplicate subnqn (if the nvme device doesn't support subsystem with multiple controllers). This will cause a probe failure. This commit changes the check of multiple controllers support at nvme_init_subsystem() by not counting all the controllers at "dead" or "deleting" state (this is safe because controllers at this state will never be active again). Fixes: ab9e00cc72fa ("nvme: track subsystems") Reviewed-by: Max Gurtovoy Signed-off-by: Israel Rukshin Signed-off-by: Christoph Hellwig Signed-off-by: Keith Busch Signed-off-by: Greg Kroah-Hartman --- drivers/nvme/host/core.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2052,6 +2052,22 @@ static const struct attribute_group *nvm NULL, }; +static int nvme_active_ctrls(struct nvme_subsystem *subsys) +{ + int count = 0; + struct nvme_ctrl *ctrl; + + mutex_lock(&subsys->lock); + list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { + if (ctrl->state != NVME_CTRL_DELETING && + ctrl->state != NVME_CTRL_DEAD) + count++; + } + mutex_unlock(&subsys->lock); + + return count; +} + static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) { struct nvme_subsystem *subsys, *found; @@ -2090,7 +2106,7 @@ static int nvme_init_subsystem(struct nv * Verify that the subsystem actually supports multiple * controllers, else bail out. */ - if (!(id->cmic & (1 << 1))) { + if (nvme_active_ctrls(found) && !(id->cmic & (1 << 1))) { dev_err(ctrl->device, "ignoring ctrl due to duplicate subnqn (%s).\n", found->subnqn);