From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 92B6221B02822 for ; Thu, 17 Jan 2019 23:31:42 -0800 (PST) Date: Fri, 18 Jan 2019 15:31:17 +0800 From: Wei Yang Subject: Re: [PATCH] libnvdimm, pfn: not allocate nd_pfn->pfn_sb if already allocated Message-ID: <20190118073117.GA4628@richard> References: <20190118033544.3980-1-richardw.yang@linux.intel.com> <20190118050333.GA4233@richard> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Wei Yang Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" To: Dan Williams Cc: Ross Zwisler , linux-nvdimm List-ID: On Thu, Jan 17, 2019 at 09:05:54PM -0800, Dan Williams wrote: >On Thu, Jan 17, 2019 at 9:03 PM Wei Yang wrote: >> >> On Thu, Jan 17, 2019 at 08:31:56PM -0800, Dan Williams wrote: >> >On Thu, Jan 17, 2019 at 7:36 PM Wei Yang wrote: >> >> >> >> In current implementation, we might re-allocate nd_pfn->pfn_sb. >> >> >> >> For example: >> >> >> >> nd_dax_probe() >> >> nd_pfn->pfn_sb = devm_kzalloc() >> >> >> >> dax_pmem_probe() >> >> nvdimm_setup_pfn() >> >> nd_pfn_init() >> >> nd_pfn->pfn_sb = devm_kzalloc() >> >> >> >> This patch checks nd_pfn->pfn_sb before allocating it in nd_pfn_init(). >> > >> >Ugh, this patch is unfortunately uncovering a deeper problem. >> >nvdimm_setup_pfn() should not be calling nd_pfn_init(). This >> >effectively is always re-initializing the info-block, benign but >> >unnecessary. Instead it needs to be using nd_pfn_validate() followed >> >by an __nvdimm_setup_pfn() in the dax_pmem_probe() path. >> > >> >Good find! >> >> So we should fix this like: >> >> dax_pmem_probe() >> nd_pfn_validate() >> __nvdimm_setup_pfn() >> >> Is my understanding correct? > >Yes, at first glance, but it would need a deeper review and testing. >The usage of nvdimm_setup_pfn() in drivers/nvdimm/pmem.c needs a >similar fixup. I went through the code again and found I may remove the allocation in nd_pfn_init(). Below is my analysis. nvdimm_setup_pfn() is invoked in two places: * dax_pmem_probe() * pmem_attach_disk(), when it is_nd_pfn() And before these two function called, corresponding device should be allocated and created. And we can see these two corresponding places to create the devices are: * nd_dax_probe() * nd_pfn_probe() Both of them allocate pfn_sb. This means it is not necessary to allocate it again when we do the probe function. Do you think it looks good to you? -- Wei Yang Help you, Help me _______________________________________________ Linux-nvdimm mailing list Linux-nvdimm@lists.01.org https://lists.01.org/mailman/listinfo/linux-nvdimm