From patchwork Sat Jan 19 00:47:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10771875 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 C6F5B13BF for ; Sat, 19 Jan 2019 01:00:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA6BE2EEBC for ; Sat, 19 Jan 2019 01:00:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E8D02F24F; Sat, 19 Jan 2019 01:00:03 +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.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE 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 9E4AE2F35F for ; Sat, 19 Jan 2019 01:00:02 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 41B21211BA44C; Fri, 18 Jan 2019 17:00:02 -0800 (PST) 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=134.134.136.126; helo=mga18.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4718D211B1FAF for ; Fri, 18 Jan 2019 17:00:00 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jan 2019 17:00:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,493,1539673200"; d="scan'208";a="119662427" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga003.jf.intel.com with ESMTP; 18 Jan 2019 17:00:00 -0800 Subject: [PATCH] libnvdimm: Clarify nd_pfn_init() flow From: Dan Williams To: linux-nvdimm@lists.01.org Date: Fri, 18 Jan 2019 16:47:23 -0800 Message-ID: <154785884329.2202034.3295476681016958230.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 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: linux-kernel@vger.kernel.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP In recent days, 2 engineers, including the original author of nd_pfn_init(), overlooked the internal call to nd_pfn_validate() and the implications to memory allocation. Clarify this situation to help anyone that reads through this code in the future. Reported-by: Wei Yang Signed-off-by: Dan Williams --- drivers/nvdimm/btt_devs.c | 5 +++++ drivers/nvdimm/dax_devs.c | 5 +++++ drivers/nvdimm/pfn_devs.c | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c index 795ad4ff35ca..e0a6f2491e57 100644 --- a/drivers/nvdimm/btt_devs.c +++ b/drivers/nvdimm/btt_devs.c @@ -354,6 +354,11 @@ int nd_btt_probe(struct device *dev, struct nd_namespace_common *ndns) put_device(btt_dev); } + /* + * Successful probe indicates to the caller that an nd_btt + * personality device has been registered and the caller can + * fail the probe of the baseline namespace device. + */ return rc; } EXPORT_SYMBOL(nd_btt_probe); diff --git a/drivers/nvdimm/dax_devs.c b/drivers/nvdimm/dax_devs.c index 0453f49dc708..65010d955fa7 100644 --- a/drivers/nvdimm/dax_devs.c +++ b/drivers/nvdimm/dax_devs.c @@ -136,6 +136,11 @@ int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns) } else __nd_device_register(dax_dev); + /* + * Successful probe indicates to the caller that a device-dax + * personality device has been registered and the caller can + * fail the probe of the baseline namespace device. + */ return rc; } EXPORT_SYMBOL(nd_dax_probe); diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c index 6f22272e8d80..a8783b5a76ba 100644 --- a/drivers/nvdimm/pfn_devs.c +++ b/drivers/nvdimm/pfn_devs.c @@ -576,6 +576,11 @@ int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns) } else __nd_device_register(pfn_dev); + /* + * Successful probe indicates to the caller that an nd_pfn + * personality device has been registered and the caller can + * fail the probe of the baseline namespace device. + */ return rc; } EXPORT_SYMBOL(nd_pfn_probe); @@ -706,6 +711,22 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn) sig = DAX_SIG; else sig = PFN_SIG; + + /* + * Check for an existing 'pfn' superblock before writing a new + * one. The intended flow is that on the first probe of an + * nd_{pfn,dax} device the superblock is calculated and written + * to the namespace. In this case nd_pfn_validate() returns + * -ENODEV because no valid superblock exists currently. + * + * On subsequent probes nd_pfn_validate() will find a valid + * superblock and return 0. + * + * If an assumption of the superblock has been violated, like a + * change to the physical alignment of the namespace, + * nd_pfn_validate() will return an error other than -ENODEV to + * fail probing. + */ rc = nd_pfn_validate(nd_pfn, sig); if (rc != -ENODEV) return rc;