Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6800063imu; Mon, 21 Jan 2019 16:28:26 -0800 (PST) X-Google-Smtp-Source: ALg8bN4qGDJ5CrfLPne7flMvLL59zdW/XOCCrPyJXOLjgirU2svkvJgHnlG075q4qXD96/KfH2+n X-Received: by 2002:a17:902:a710:: with SMTP id w16mr31389569plq.95.1548116906149; Mon, 21 Jan 2019 16:28:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548116906; cv=none; d=google.com; s=arc-20160816; b=zMSgmBAuygviCovvYS0LWzZ24irI4TzmsR8IK8IHIEf/dQrsxClR+GsJ6B1ey3Gex0 LCTX9IcCy+f3IxGKN53xqfnpQeSIRZqwfQ3BXR7dByMh41ScivgK+IgbniGvHXxtxeFs 5pnITEnTJWiu/Is7u3EUJ7V9hAqfNtzbfmZd8B7tR9ZtPjuTESQl2fl3WEa8KkHFRwKm H8syGPEp1h+g50TCZtLixEFFyVF766/ZbVfNHC0p2ZZx2iO3AjRkuqAOrl6avnv3vk8m xBE9BuSyD6Y5hh6txEcPeMaT0Fj6R5iP41Eu0WkTzcqdx8TAv3jMz7VQ2DbtGbsmFHmR xKgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date; bh=ISxLrgNfifMjC9+XkqrfkpgmGrWjyVso2MdGFG+S2jY=; b=yOjhaYDHI6rjZgDRQ7tyFpcoSe6KZvkEomacWaVutX0gE2XkfrY2KoogH7KfoTq6He POvddy1vQSvdf+PkND7tG7iggyugcZAHXC4Lm2ZTkyDXX5kX2HGW28ASKA1LJFn+c7bM J/gDjOP4rvJrGDQiMKY9i6+Mgpxz7IiWlxucEN0XyuppM55teBO90yi7f03922YqXOOJ ZPD0HS6ZReiNDB2U/dXTFWFHgBM/WPe5wk9plUJVjnm9Ym12yOY+LQS4ATqZ+EPWAcY+ KSbquX0kUAr7MmxjVmJiEKjQtP6JMz/YX9ieupmKdvQN3QDXCoZABFDDZ3sApNw/NqsS fSLw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s8si13880742pgm.508.2019.01.21.16.28.10; Mon, 21 Jan 2019 16:28:26 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726630AbfAVA0q (ORCPT + 99 others); Mon, 21 Jan 2019 19:26:46 -0500 Received: from mga05.intel.com ([192.55.52.43]:16730 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726300AbfAVA0p (ORCPT ); Mon, 21 Jan 2019 19:26:45 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Jan 2019 16:26:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,504,1539673200"; d="scan'208";a="127777302" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.37]) by orsmga002.jf.intel.com with ESMTP; 21 Jan 2019 16:26:43 -0800 Date: Tue, 22 Jan 2019 08:26:15 +0800 From: Wei Yang To: Dan Williams Cc: linux-nvdimm@lists.01.org, Wei Yang , linux-kernel@vger.kernel.org Subject: Re: [PATCH] libnvdimm: Clarify nd_pfn_init() flow Message-ID: <20190122002615.GB5855@richard> Reply-To: Wei Yang References: <154785884329.2202034.3295476681016958230.stgit@dwillia2-desk3.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <154785884329.2202034.3295476681016958230.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 18, 2019 at 04:47:23PM -0800, Dan Williams wrote: >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. As you replied in following mail: 3/ If present, nd_pfn_validate() returns 0 and nd_dax_probe() registers the dax0.1 device (this is a libnvdimm 'personality device). So at this point, nd_pfn_validate() return 0 or -ENODEV? >+ * >+ * 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; -- Wei Yang Help you, Help me