Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp73060ybp; Thu, 3 Oct 2019 10:20:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqw7Q5zn6g0bpF3GbX+0wh1wdbBYFpNT+8qwe8utVZPFYb0EPKxfcwGt3hD/XaS4D9BNUdLL X-Received: by 2002:a17:906:11c3:: with SMTP id o3mr8761935eja.297.1570123222229; Thu, 03 Oct 2019 10:20:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570123222; cv=none; d=google.com; s=arc-20160816; b=vqgSnMoGIH1DO3Pg7j5VDydpKQZFB7+JkRUdvRHomS48rbAMLQTJfPpJHo0irnosLH KgUBrBTNkI07XRcEKP2fJ8oYBzl46omNx5GuF5S2OZVQWbBalP+bcDFy8HW53HX857iX 7ecTWRveO3HtP1sdPy1A1fUuGNhk6fkdqtTCA1Y6pRyECqhvM+2qK0r9bQZ+BMCZSel/ G9TL6FJFzxrggmilqVSTnYKz/SpUFPq92M0E0yNagWY7lQYYj4Bjhxi52x3Lh1Z3TmP8 LrKSdz2dnlhDZoCWMW4SyY1BOWxgNjFrhZb+lWXNe6hdq4wGcT4KSGw66tXIGucG/xWq cGCA== 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=Ns3IxD5vrwwJ8wSYg5M5HItvdy3DDVVzpE12M5GFIKY=; b=jutqiBbzpyoje2EiBV6z84NjoddBzOtr1peJzt0q3nfPowSky9v4BYrlnkLw4kBZmz KQgMa+yLPKSVe3WiFDTOk3zIkUp47LaLGL4vcCIHNhFpWWOjimoOowUT8olZd2j3/Yp/ jW40BtvM23LWkL8x8Xq01Y7hayOuwU8cP3+ytnL16jJGaO/ldCZeJRzKFaQZK0MG+KVl Zt1pjIQNKzbZient/gfSEXvf25nsQWm1WPmah9+D5BAwRSKEqg9mZYvJ1+AMUP4ubm6O r465UVRIkTnnjYc203AWuVT1ixEz0tN1i6ILZTGyPZe/F3DmICsiFNIWr6PQ+2XekcXa rtGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HxH6VGXm; 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 b33si2014134edc.265.2019.10.03.10.19.57; Thu, 03 Oct 2019 10:20:22 -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=HxH6VGXm; 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 S2390002AbfJCQUv (ORCPT + 99 others); Thu, 3 Oct 2019 12:20:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:48714 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389992AbfJCQUs (ORCPT ); Thu, 3 Oct 2019 12:20:48 -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 162422054F; Thu, 3 Oct 2019 16:20:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119647; bh=TEG5FMLOPxC2m3iJa7OAlqaOJOc/fweVtH3XyEcLuQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HxH6VGXmPlVQexKQE1GVNdLrGH45Mq3Cjg6MySjyUg4G4SFV2elStCN5VjK5BA1SS 8tqlgEaz+jzIw8KWjkQS1eo2oWX0EzXSmUWZzN1rKIYGwpTJ+/jBaLckG/N0wtENhj 8yShK90ACDbmfppIYtfcjoJcTNo1ZE7gmc2KqWA0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anton Eidelman , James Smart , Hannes Reinecke , Christoph Hellwig , Sagi Grimberg , Sasha Levin Subject: [PATCH 4.19 114/211] nvme-multipath: fix ana log nsid lookup when nsid is not found Date: Thu, 3 Oct 2019 17:53:00 +0200 Message-Id: <20191003154513.499252504@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154447.010950442@linuxfoundation.org> References: <20191003154447.010950442@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: Anton Eidelman [ Upstream commit e01f91dff91c7b16a6e3faf2565017d497a73f83 ] ANA log parsing invokes nvme_update_ana_state() per ANA group desc. This updates the state of namespaces with nsids in desc->nsids[]. Both ctrl->namespaces list and desc->nsids[] array are sorted by nsid. Hence nvme_update_ana_state() performs a single walk over ctrl->namespaces: - if current namespace matches the current desc->nsids[n], this namespace is updated, and n is incremented. - the process stops when it encounters the end of either ctrl->namespaces end or desc->nsids[] In case desc->nsids[n] does not match any of ctrl->namespaces, the remaining nsids following desc->nsids[n] will not be updated. Such situation was considered abnormal and generated WARN_ON_ONCE. However ANA log MAY contain nsids not (yet) found in ctrl->namespaces. For example, lets consider the following scenario: - nvme0 exposes namespaces with nsids = [2, 3] to the host - a new namespace nsid = 1 is added dynamically - also, a ANA topology change is triggered - NS_CHANGED aen is generated and triggers scan_work - before scan_work discovers nsid=1 and creates a namespace, a NOTICE_ANA aen was issues and ana_work receives ANA log with nsids=[1, 2, 3] Result: ana_work fails to update ANA state on existing namespaces [2, 3] Solution: Change the way nvme_update_ana_state() namespace list walk checks the current namespace against desc->nsids[n] as follows: a) ns->head->ns_id < desc->nsids[n]: keep walking ctrl->namespaces. b) ns->head->ns_id == desc->nsids[n]: match, update the namespace c) ns->head->ns_id >= desc->nsids[n]: skip to desc->nsids[n+1] This enables correct operation in the scenario described above. This also allows ANA log to contain nsids currently invisible to the host, i.e. inactive nsids. Signed-off-by: Anton Eidelman Reviewed-by: James Smart Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Signed-off-by: Sagi Grimberg Signed-off-by: Sasha Levin --- drivers/nvme/host/multipath.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c index f57feb8fdea45..892ef52122329 100644 --- a/drivers/nvme/host/multipath.c +++ b/drivers/nvme/host/multipath.c @@ -404,14 +404,16 @@ static int nvme_update_ana_state(struct nvme_ctrl *ctrl, down_write(&ctrl->namespaces_rwsem); list_for_each_entry(ns, &ctrl->namespaces, list) { - if (ns->head->ns_id != le32_to_cpu(desc->nsids[n])) + unsigned nsid = le32_to_cpu(desc->nsids[n]); + + if (ns->head->ns_id < nsid) continue; - nvme_update_ns_ana_state(desc, ns); + if (ns->head->ns_id == nsid) + nvme_update_ns_ana_state(desc, ns); if (++n == nr_nsids) break; } up_write(&ctrl->namespaces_rwsem); - WARN_ON_ONCE(n < nr_nsids); return 0; } -- 2.20.1