From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751920AbcCAC4w (ORCPT ); Mon, 29 Feb 2016 21:56:52 -0500 Received: from mga03.intel.com ([134.134.136.65]:23914 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751877AbcCAC4u (ORCPT ); Mon, 29 Feb 2016 21:56:50 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,521,1449561600"; d="scan'208";a="898067141" Subject: [PATCH 1/2] libnvdimm, pmem: fix 'pfn' support for section-misaligned namespaces From: Dan Williams To: linux-nvdimm@ml01.01.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org Date: Mon, 29 Feb 2016 18:56:26 -0800 Message-ID: <20160301025626.12812.4840.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <20160301025620.12812.87268.stgit@dwillia2-desk3.amr.corp.intel.com> References: <20160301025620.12812.87268.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The altmap for a section-misaligned namespace needs to arrange for the base_pfn to be section-aligned. As a result the 'reserve' region (pfns from base that do not have a struct page) must be increased. Otherwise we trip the altmap validation check in __add_pages: if (altmap->base_pfn != phys_start_pfn || vmem_altmap_offset(altmap) > nr_pages) { pr_warn_once("memory add fail, invalid altmap\n"); return -EINVAL; } Signed-off-by: Dan Williams --- drivers/nvdimm/pmem.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index efc2a5e671c6..6a6283ab974c 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -356,6 +356,31 @@ static int nvdimm_namespace_detach_pfn(struct nd_namespace_common *ndns) return 0; } +/* + * We hotplug memory at section granularity, pad the reserved area from + * the previous section base to the namespace base address. + */ +static unsigned long init_altmap_base(resource_size_t base) +{ + unsigned long base_pfn = __phys_to_pfn(base); + +#ifdef CONFIG_SPARSEMEM + base_pfn = SECTION_ALIGN_DOWN(base_pfn); +#endif + return base_pfn; +} + +static unsigned long init_altmap_reserve(resource_size_t base) +{ + unsigned long base_pfn = __phys_to_pfn(base); + unsigned long reserve = __phys_to_pfn(SZ_8K); + +#ifdef CONFIG_SPARSEMEM + reserve += base_pfn - SECTION_ALIGN_DOWN(base_pfn); +#endif + return reserve; +} + static int nvdimm_namespace_attach_pfn(struct nd_namespace_common *ndns) { struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev); @@ -369,8 +394,8 @@ static int nvdimm_namespace_attach_pfn(struct nd_namespace_common *ndns) phys_addr_t offset; int rc; struct vmem_altmap __altmap = { - .base_pfn = __phys_to_pfn(nsio->res.start), - .reserve = __phys_to_pfn(SZ_8K), + .base_pfn = init_altmap_base(nsio->res.start), + .reserve = init_altmap_reserve(nsio->res.start), }; if (!nd_pfn->uuid || !nd_pfn->ndns)