Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10440669ybi; Wed, 24 Jul 2019 23:16:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmoLDuhFZQWptZKxlSMQ2YeX16Kjzl5N48qK5vHbelIW7E5pnXcZtneEwSCOmqS5kZISsJ X-Received: by 2002:a17:90a:25af:: with SMTP id k44mr89505156pje.122.1564035360240; Wed, 24 Jul 2019 23:16:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564035360; cv=none; d=google.com; s=arc-20160816; b=Jar6Xh5TcXwJsT8Pp2Rsa1n2Vg66Jv19+JFfyQ1FqCger+qT4sYKxBmK82+tAGyRUk j3sR/TOUs4Llu8iUgQNLlslx+MLpe2FPp/d+vuEQYuFneDSHnGAhg271XJO/YmsJrhdy pt6+pWhWfn5FxAsO6C7rsYQHqFjkknHAVrVgvYAmPTICGVdOvHrBCP5SXOm/vF1sMGtH sILfIJSw7yiaHzwXGGJig1/NPnvHS2p0Y5LxarIEEqOXgvXaeRSDCPopa8z40ijJzYyv 9mBXaFo9oRg+P5ufPVnilSYOGz0zx3LBmuaLe21hCd31QrqxMAwhoxBxQ59TJQkHo+5O jc/w== 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=32tjtLB7jYCejdLtUJ16WrWDYFRuFhxdZuKsgQWu0jo=; b=iCAbGzsi2f6XGTOt0H/jWud1iGrFuqv98aH0jDe+gVDrw5mFY+TqBAbAdLYXxmd7Rr pCQDVX+6mC7IDConUIXcJt9CP9ZY7Q1gOSwNAw7YI0Hd4WbJlR6If9JQ2kugRH4Ns1WK HbCeIY8PWimg087akvjofVXSBMnI1/ZixFz4i0rNlKP6UTduK6N58j5r5/wfATNdNBCX 4HC6/Sv9DD+kE0UKIe5G+64rR+v85s/bWwL3zRr7+XMuzW778dTst4lwTtiow+waYE/D mBxuo6jARHbKhikUpEVjFNiS//etyNt09gL5FuFKvYHXgyecOOfmOLA/bejZc/HXjFkg C5Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LFr24DmC; 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 h189si15796207pgc.236.2019.07.24.23.15.45; Wed, 24 Jul 2019 23:16:00 -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=LFr24DmC; 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 S2404265AbfGYFkD (ORCPT + 99 others); Thu, 25 Jul 2019 01:40:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:54412 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404214AbfGYFkC (ORCPT ); Thu, 25 Jul 2019 01:40:02 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 6150A22BF3; Thu, 25 Jul 2019 05:40:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564033201; bh=+pnUn9iysnMItf6jUtf0I4u2VkbFirwYM/E2bJ9s8g8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LFr24DmCheTikzuh5sGfO6tsLioCYhdl3egvIFPykxsuL83coyVTZ4fedSkSlUdFX 0Jq4gdDa49kNIRp83vluPpl3mxRdrUBYIoTAJYaVROmKVVgloMRnLY+qSl6sFemPFh 7cKQxhZFZhCxSkvyfoMaNHqGj6YdbDT93u24KVRQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anton Eidelman , Sagi Grimberg , Christoph Hellwig , Sasha Levin Subject: [PATCH 4.19 087/271] nvme: fix possible io failures when removing multipathed ns Date: Wed, 24 Jul 2019 21:19:16 +0200 Message-Id: <20190724191702.666019747@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191655.268628197@linuxfoundation.org> References: <20190724191655.268628197@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 [ Upstream commit 2181e455612a8db2761eabbf126640552a451e96 ] When a shared namespace is removed, we call blk_cleanup_queue() when the device can still be accessed as the current path and this can result in submission to a dying queue. Hence, direct_make_request() called by our mpath device may fail (propagating the failure to userspace). Instead, we want to failover this I/O to a different path if one exists. Thus, before we cleanup the request queue, we make sure that the device is cleared from the current path nor it can be selected again as such. Fix this by: - clear the ns from the head->list and synchronize rcu to make sure there is no concurrent path search that restores it as the current path - clear the mpath current path in order to trigger a subsequent path search and sync srcu to wait for any ongoing request submissions - safely continue to namespace removal and blk_cleanup_queue Signed-off-by: Anton Eidelman Signed-off-by: Sagi Grimberg Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/host/core.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index d8869d978c34..e26d1191c5ad 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -3168,6 +3168,14 @@ static void nvme_ns_remove(struct nvme_ns *ns) return; nvme_fault_inject_fini(ns); + + mutex_lock(&ns->ctrl->subsys->lock); + list_del_rcu(&ns->siblings); + mutex_unlock(&ns->ctrl->subsys->lock); + synchronize_rcu(); /* guarantee not available in head->list */ + nvme_mpath_clear_current_path(ns); + synchronize_srcu(&ns->head->srcu); /* wait for concurrent submissions */ + if (ns->disk && ns->disk->flags & GENHD_FL_UP) { sysfs_remove_group(&disk_to_dev(ns->disk)->kobj, &nvme_ns_id_attr_group); @@ -3179,16 +3187,10 @@ static void nvme_ns_remove(struct nvme_ns *ns) blk_integrity_unregister(ns->disk); } - mutex_lock(&ns->ctrl->subsys->lock); - list_del_rcu(&ns->siblings); - nvme_mpath_clear_current_path(ns); - mutex_unlock(&ns->ctrl->subsys->lock); - down_write(&ns->ctrl->namespaces_rwsem); list_del_init(&ns->list); up_write(&ns->ctrl->namespaces_rwsem); - synchronize_srcu(&ns->head->srcu); nvme_mpath_check_last_path(ns); nvme_put_ns(ns); } -- 2.20.1