From patchwork Mon Sep 10 06:21:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ocean He X-Patchwork-Id: 10593585 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3BD4E14E0 for ; Mon, 10 Sep 2018 06:24:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29C0B28C91 for ; Mon, 10 Sep 2018 06:24:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E18328E82; Mon, 10 Sep 2018 06:24:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C8B8728C91 for ; Mon, 10 Sep 2018 06:24:11 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C1EA821122932; Sun, 9 Sep 2018 23:24:11 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::643; helo=mail-pl1-x643.google.com; envelope-from=oceanhehy@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C82FF2112292A for ; Sun, 9 Sep 2018 23:24:10 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id f6-v6so9254615plo.1 for ; Sun, 09 Sep 2018 23:24:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3MmFh5VYNhBbWAgBarErsEIFlbjZvJPeEdHR7yalks8=; b=jXSLJXlot2IR2g7En6xCzJouoS5MAIcvPjxxGHeNhNdxkewv0TeRiuJkK58S6mGHdv CnEfwzqUoPNVTh6snNhv1eUfc7WMDg5fcA1NH+x0binvxbJJ1r+RUGWH1+aoWblULpmM HO6sAjz+7dz1Cd1PKEaFKE0PU+ztrm4eWWF/nOQxa49FVsPEIqXGvr70HVep1A5NcOBx MZrAftjohhWoxPtwHpYzOnLY61y6huNIPdULZf/3WfDJs1s6A2+wzXxBsC2GwrmPU3KM lepmp6NQcphykNAK4Bo/dDmOTkiray0cV8rf879Q73zdoTFSipVcmsZpWTGXXLf786NB lXfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3MmFh5VYNhBbWAgBarErsEIFlbjZvJPeEdHR7yalks8=; b=LXaTXcP7OdEJa0JG/3RZsmJZteqHTT6U0k7hs5yGeS4AgD6iZfbUDe5au9lD3jdfyp KCjEM4Ytt7PQRV/pOU3UCENjokPiU/k7ALVtJAe0zSWSLw3el+GywplRovfbMqqB/sF4 BjWPwmjXt0J6cZYCfZ3XDF8jE1ZbNr0utHlcJlP4L5QHd1pKs9HJRFDbdQIRZXPow74W BMI5F1yoA6gciTB35iCMex2kFy1MM9qH+JGcJSLVBj8A/IZsDG77rx9p59x073zlX0Hf yxyU6vKx51ZguP7gJMRiC7O3jKj+AzwyKE/XwTgrrRBii9rZVcM7e1I7QG1UwzrV7/NH DWeQ== X-Gm-Message-State: APzg51B6rmfywOjpzoHOUoShKjLBiFIGTQND3cso5Im0XpEVtmh0HXzG X/X8t+Or/yoGiXNRPqHTEYQ= X-Google-Smtp-Source: ANB0VdYwY1BEVzHUSZwG2PauzFQWzUu+hfuHu+/oMhmB2V8nB8hDeIBDfWFERedxly7NycDgbhFr5w== X-Received: by 2002:a17:902:b089:: with SMTP id p9-v6mr20108057plr.254.1536560650554; Sun, 09 Sep 2018 23:24:10 -0700 (PDT) Received: from localhost.localdomain ([104.237.86.186]) by smtp.gmail.com with ESMTPSA id e190-v6sm29884955pfc.81.2018.09.09.23.24.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Sep 2018 23:24:10 -0700 (PDT) From: Ocean He To: dan.j.williams@intel.com, zwisler@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com Subject: [PATCH 3/3] libnvdimm, region_devs: reset related seeds when fail to create namespace Date: Mon, 10 Sep 2018 02:21:48 -0400 Message-Id: <1536560508-24564-4-git-send-email-oceanhehy@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1536560508-24564-1-git-send-email-oceanhehy@gmail.com> References: <1536560508-24564-1-git-send-email-oceanhehy@gmail.com> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ocean He , linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP From: Ocean He During runtime, namespace creation may fail if blocked by commit 15d36fecd0bdc7510b70 ("mm: disallow mappings that conflict for devm_memremap_pages()"). To ensure pfn_seed/dax_seed and namespace_seed are ready for next namespace creation, here to do detach and reset. Signed-off-by: Ocean He --- drivers/nvdimm/region_devs.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c index fa37afc..4c46fb6 100644 --- a/drivers/nvdimm/region_devs.c +++ b/drivers/nvdimm/region_devs.c @@ -703,7 +703,27 @@ void nd_mapping_free_labels(struct nd_mapping *nd_mapping) kfree(label_ent); } } +/* + * To ensure pfn_seed/dax_seed and namespace_seed are ready for + * next namespace creation, here to do detach and reset. + */ +void nd_region_detach_and_reset(struct device *dev, + struct nd_region *nd_region) +{ + /* Only nd_pmem has been verified, fix me for other dev type. */ + if (!is_nd_pmem(&nd_region->dev)) + return; + if (is_nd_pfn(dev) || is_nd_dax(dev)) { + struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); + struct nd_namespace_common *ndns = to_ndns(nd_region->ns_seed); + + if (nd_pfn->ndns == ndns && ndns->claim == dev) { + nd_detach_and_reset(dev, &nd_pfn->ndns); + nd_region_reset_ns_seed(nd_region); + } + } +} /* * Upon successful probe/remove, take/release a reference on the * associated interleave set (if present), and plant new btt + namespace @@ -774,6 +794,20 @@ static void nd_region_notify_driver_action(struct nvdimm_bus *nvdimm_bus, nd_region_create_ns_seed(nd_region); nvdimm_bus_unlock(dev); } + if (is_nd_pfn(dev) && !probe) { + nd_region = to_nd_region(dev->parent); + nvdimm_bus_lock(dev); + if (nd_region->pfn_seed == dev) + nd_region_detach_and_reset(dev, nd_region); + nvdimm_bus_unlock(dev); + } + if (is_nd_dax(dev) && !probe) { + nd_region = to_nd_region(dev->parent); + nvdimm_bus_lock(dev); + if (nd_region->dax_seed == dev) + nd_region_detach_and_reset(dev, nd_region); + nvdimm_bus_unlock(dev); + } } void nd_region_probe_success(struct nvdimm_bus *nvdimm_bus, struct device *dev)