diff mbox

[ndctl] ndctl, create-namespace: fix minimum alignment detection

Message ID 152011374766.14937.7017387737157056826.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Williams March 3, 2018, 9:49 p.m. UTC
Commit 0c31ce0a2875 "ndctl, create-namespace: fix --align= default..."
tried to make casual testing with nfit_test easier by auto-detecting the
alignment. However, this auto-detection always falls back to 4K
alignment on kernels that do not export the region 'resource' attribute.
Those kernels, like v4.9.4, may also be missing this fix: commit
cd755677d944 "libnvdimm, pfn: fix memmap reservation size versus 4K
alignment".

Given the chance to fail to initialize a namespace in the 4K case on
older kernels, be more conservative about falling back to 4K alignment.

Link: https://github.com/pmem/ndctl/issues/34
Reported-by: Maciej Ramotowski <maciej.ramotowski@intel.com>
Fixes: 0c31ce0a2875 ("ndctl, create-namespace: fix --align= default...")
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/namespace.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Verma, Vishal L March 6, 2018, 12:38 a.m. UTC | #1
On Sat, 2018-03-03 at 13:49 -0800, Dan Williams wrote:
> Commit 0c31ce0a2875 "ndctl, create-namespace: fix --align=
> default..."
> tried to make casual testing with nfit_test easier by auto-detecting
> the
> alignment. However, this auto-detection always falls back to 4K
> alignment on kernels that do not export the region 'resource'
> attribute.
> Those kernels, like v4.9.4, may also be missing this fix: commit
> cd755677d944 "libnvdimm, pfn: fix memmap reservation size versus 4K
> alignment".
> 
> Given the chance to fail to initialize a namespace in the 4K case on
> older kernels, be more conservative about falling back to 4K
> alignment.
> 
> Link: https://github.com/pmem/ndctl/issues/34
> Reported-by: Maciej Ramotowski <maciej.ramotowski@intel.com>
> Fixes: 0c31ce0a2875 ("ndctl, create-namespace: fix --align=
> default...")
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
>  ndctl/namespace.c |    7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 

Looks good, queued for v60.

> diff --git a/ndctl/namespace.c b/ndctl/namespace.c
> index ceb9e7a9b8af..aef356abbee1 100644
> --- a/ndctl/namespace.c
> +++ b/ndctl/namespace.c
> @@ -462,7 +462,7 @@ static int validate_namespace_options(struct
> ndctl_region *region,
>  		struct ndctl_namespace *ndns, struct
> parsed_parameters *p)
>  {
>  	const char *region_name = ndctl_region_get_devname(region);
> -	unsigned long long size_align = SZ_4K, units = 1;
> +	unsigned long long size_align = SZ_4K, units = 1, resource;
>  	unsigned int ways;
>  	int rc = 0;
>  
> @@ -563,8 +563,9 @@ static int validate_namespace_options(struct
> ndctl_region *region,
>  		 * the nfit_test use case where it is backed by
> vmalloc
>  		 * memory.
>  		 */
> -		if (param.align_default &&
> (ndctl_region_get_resource(region)
> -					& (SZ_2M - 1))) {
> +		resource = ndctl_region_get_resource(region);
> +		if (param.align_default && resource < ULLONG_MAX
> +				&& (resource & (SZ_2M - 1))) {
>  			debug("%s: falling back to a 4K
> alignment\n",
>  					region_name);
>  			p->align = SZ_4K;
> 
> _______________________________________________
> Linux-nvdimm mailing list
> Linux-nvdimm@lists.01.org
> https://lists.01.org/mailman/listinfo/linux-nvdimm
diff mbox

Patch

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index ceb9e7a9b8af..aef356abbee1 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -462,7 +462,7 @@  static int validate_namespace_options(struct ndctl_region *region,
 		struct ndctl_namespace *ndns, struct parsed_parameters *p)
 {
 	const char *region_name = ndctl_region_get_devname(region);
-	unsigned long long size_align = SZ_4K, units = 1;
+	unsigned long long size_align = SZ_4K, units = 1, resource;
 	unsigned int ways;
 	int rc = 0;
 
@@ -563,8 +563,9 @@  static int validate_namespace_options(struct ndctl_region *region,
 		 * the nfit_test use case where it is backed by vmalloc
 		 * memory.
 		 */
-		if (param.align_default && (ndctl_region_get_resource(region)
-					& (SZ_2M - 1))) {
+		resource = ndctl_region_get_resource(region);
+		if (param.align_default && resource < ULLONG_MAX
+				&& (resource & (SZ_2M - 1))) {
 			debug("%s: falling back to a 4K alignment\n",
 					region_name);
 			p->align = SZ_4K;