Skip to contentSkip to conversation

mm/pgmap: Use correct alignment when looking at first pfn from a region

PATCH In review Aneesh Kumar K.V 4 participants 8 messages Sep 17, 2019 – Jan 31, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 mm/pgmap: Use correct alignment when looking at first pfn from a region

vmem_altmap_offset() adjust the section aligned base_pfn offset. So we need to make sure we account for the same when computing base_pfn.

ie, for altmap_valid case, our pfn_first should be:

pfn_first = altmap->base_pfn + vmem_altmap_offset(altmap);

---
* changes from v5
* update commit subject and use linux-mm for merge

 mm/memremap.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
mm/memremap.c +10 -2
index ed70c4e8e52a..233908d7df75 100644
@@ -54,8 +54,16 @@ static void pgmap_array_delete(struct resource *res)
 
 static unsigned long pfn_first(struct dev_pagemap *pgmap)
 {
-	return PHYS_PFN(pgmap->res.start) +
-		vmem_altmap_offset(pgmap_altmap(pgmap));
+	const struct resource *res = &pgmap->res;
+	struct vmem_altmap *altmap = pgmap_altmap(pgmap);
+	unsigned long pfn;
+
+	if (altmap) {
+		pfn = altmap->base_pfn + vmem_altmap_offset(altmap);
+	} else
+		pfn = PHYS_PFN(res->start);
+
+	return pfn;
 }
 
 static unsigned long pfn_end(struct dev_pagemap *pgmap)
Signature · 1 line
2.21.0
#1 lore raw
Quoted 22 lines · Aneesh Kumar K.V

vmem_altmap_offset() adjust the section aligned base_pfn offset. So we need to make sure we account for the same when computing base_pfn.

ie, for altmap_valid case, our pfn_first should be:

pfn_first = altmap->base_pfn + vmem_altmap_offset(altmap);

---
* changes from v5
* update commit subject and use linux-mm for merge

  mm/memremap.c | 12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)
mm/memremap.c +0 -0
index ed70c4e8e52a..233908d7df75 100644
@@ -54,8 +54,16 @@ static void pgmap_array_delete(struct resource *res)
 
  static unsigned long pfn_first(struct dev_pagemap *pgmap)

mm/memremap.c static void pgmap_array_delete(struct resource *res) · line 63

Quoted 10 lines
mm/memremap.c +7 -2
  {
-	return PHYS_PFN(pgmap->res.start) +
-		vmem_altmap_offset(pgmap_altmap(pgmap));
+	const struct resource *res = &pgmap->res;
+	struct vmem_altmap *altmap = pgmap_altmap(pgmap);
+	unsigned long pfn;
+
+	if (altmap) {
+		pfn = altmap->base_pfn + vmem_altmap_offset(altmap);
+	} else

A nit: you don't need the '{}'s

mm/memremap.c static void pgmap_array_delete(struct resource *res) · line 69

Quoted 7 lines
mm/memremap.c +3 -0
+		pfn = PHYS_PFN(res->start);
+
+	return pfn;
  }
 
  static unsigned long pfn_end(struct dev_pagemap *pgmap)

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer
#2 lore raw
In reply to Aneesh Kumar K.V
Quoted 6 lines · On Tue, 17 Sep 2019 21:01:29 +0530 "Aneesh Kumar K.V"…

vmem_altmap_offset() adjust the section aligned base_pfn offset. So we need to make sure we account for the same when computing base_pfn.

ie, for altmap_valid case, our pfn_first should be:

pfn_first = altmap->base_pfn + vmem_altmap_offset(altmap);

What are the user-visible runtime effects of this change?

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#3 lore raw
Quoted 10 lines · Andrew Morton
Quoted 6 lines · On Tue, 17 Sep 2019 21:01:29 +0530 "Aneesh Kumar K.V"…

vmem_altmap_offset() adjust the section aligned base_pfn offset. So we need to make sure we account for the same when computing base_pfn.

ie, for altmap_valid case, our pfn_first should be:

pfn_first = altmap->base_pfn + vmem_altmap_offset(altmap);

What are the user-visible runtime effects of this change?

This was found by code inspection. If the pmem region is not correctly section aligned we can skip pfns while iterating device pfn using
for_each_device_pfn(pfn, pgmap)

I still would want Dan to ack the change though.

-aneesh

maintainer
#4 lore raw
Quoted 11 lines · On Wed, 25 Sep 2019 09:21:02 +0530 "Aneesh Kumar K.V"…
Quoted 9 lines · Andrew Morton
Quoted 6 lines · On Tue, 17 Sep 2019 21:01:29 +0530 "Aneesh Kumar K.V"…

vmem_altmap_offset() adjust the section aligned base_pfn offset. So we need to make sure we account for the same when computing base_pfn.

ie, for altmap_valid case, our pfn_first should be:

pfn_first = altmap->base_pfn + vmem_altmap_offset(altmap);

Quoted 9 lines
Quoted 1 line

What are the user-visible runtime effects of this change?

This was found by code inspection. If the pmem region is not correctly section aligned we can skip pfns while iterating device pfn using
for_each_device_pfn(pfn, pgmap)

I still would want Dan to ack the change though.

Dan?

From: "Aneesh Kumar K.V" <[email protected]>
Subject: mm/pgmap: use correct alignment when looking at first pfn from a region

vmem_altmap_offset() adjusts the section aligned base_pfn offset. So we need to make sure we account for the same when computing base_pfn.

ie, for altmap_valid case, our pfn_first should be:

pfn_first = altmap->base_pfn + vmem_altmap_offset(altmap);

This was found by code inspection. If the pmem region is not correctly section aligned we can skip pfns while iterating device pfn using

for_each_device_pfn(pfn, pgmap)

---

 mm/memremap.c |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
mm/memremap.c renamed from mm/memremap.c~mm-pgmap-use-correct-alignment-when-looking-at-first-pfn-from-a-region +10 -2
@@ -55,8 +55,16 @@ static void pgmap_array_delete(struct re
 
 static unsigned long pfn_first(struct dev_pagemap *pgmap)
 {
-	return PHYS_PFN(pgmap->res.start) +
-		vmem_altmap_offset(pgmap_altmap(pgmap));
+	const struct resource *res = &pgmap->res;
+	struct vmem_altmap *altmap = pgmap_altmap(pgmap);
+	unsigned long pfn;
+
+	if (altmap)
+		pfn = altmap->base_pfn + vmem_altmap_offset(altmap);
+	else
+		pfn = PHYS_PFN(res->start);
+
+	return pfn;
 }
 
 static unsigned long pfn_end(struct dev_pagemap *pgmap)

_

#5 lore raw
Quoted 59 lines · Andrew Morton
Quoted 11 lines · On Wed, 25 Sep 2019 09:21:02 +0530 "Aneesh Kumar K.V"…
Quoted 9 lines · Andrew Morton
Quoted 6 lines · On Tue, 17 Sep 2019 21:01:29 +0530 "Aneesh Kumar K.V"…

vmem_altmap_offset() adjust the section aligned base_pfn offset. So we need to make sure we account for the same when computing base_pfn.

ie, for altmap_valid case, our pfn_first should be:

pfn_first = altmap->base_pfn + vmem_altmap_offset(altmap);

Quoted 9 lines
Quoted 1 line

What are the user-visible runtime effects of this change?

This was found by code inspection. If the pmem region is not correctly section aligned we can skip pfns while iterating device pfn using
for_each_device_pfn(pfn, pgmap)

I still would want Dan to ack the change though.

Dan?

From: "Aneesh Kumar K.V" <[email protected]>
Subject: mm/pgmap: use correct alignment when looking at first pfn from a region

vmem_altmap_offset() adjusts the section aligned base_pfn offset. So we need to make sure we account for the same when computing base_pfn.

ie, for altmap_valid case, our pfn_first should be:

pfn_first = altmap->base_pfn + vmem_altmap_offset(altmap);

This was found by code inspection. If the pmem region is not correctly section aligned we can skip pfns while iterating device pfn using

for_each_device_pfn(pfn, pgmap)

---

 mm/memremap.c |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
mm/memremap.c renamed from mm/memremap.c~mm-pgmap-use-correct-alignment-when-looking-at-first-pfn-from-a-region +0 -0
@@ -55,8 +55,16 @@ static void pgmap_array_delete(struct re
 
 static unsigned long pfn_first(struct dev_pagemap *pgmap)
 {

mm/memremap.c static void pgmap_array_delete(struct re · line 65

Quoted 10 lines
mm/memremap.c renamed from mm/memremap.c~mm-pgmap-use-correct-alignment-when-looking-at-first-pfn-from-a-region +8 -2
-       return PHYS_PFN(pgmap->res.start) +
-               vmem_altmap_offset(pgmap_altmap(pgmap));
+       const struct resource *res = &pgmap->res;
+       struct vmem_altmap *altmap = pgmap_altmap(pgmap);
+       unsigned long pfn;
+
+       if (altmap)
+               pfn = altmap->base_pfn + vmem_altmap_offset(altmap);
+       else
+               pfn = PHYS_PFN(res->start);

This would only be a problem if res->start is not subsection aligned. Is that bug triggering in your case, or is this just inspection. Now that the subsections can be assumed as the minimum mapping granularity I'd rather see a cleanup I'd rather cleanup the implementation to eliminate altmap->base_pfn or at least assert that PHYS_PFN(res->start) and altmap->base_pfn are always identical.

Otherwise ->base_pfn is supposed to be just a convenient way to recall the bounds of the memory hotplug operation deeper in the vmemmap setup.

#6 lore raw
Quoted 58 lines · Dan Williams
Quoted 57 lines · Andrew Morton
Quoted 11 lines · On Wed, 25 Sep 2019 09:21:02 +0530 "Aneesh Kumar K.V"…
Quoted 9 lines · Andrew Morton
Quoted 6 lines · On Tue, 17 Sep 2019 21:01:29 +0530 "Aneesh Kumar K.V"…

vmem_altmap_offset() adjust the section aligned base_pfn offset. So we need to make sure we account for the same when computing base_pfn.

ie, for altmap_valid case, our pfn_first should be:

pfn_first = altmap->base_pfn + vmem_altmap_offset(altmap);

Quoted 9 lines
Quoted 1 line

What are the user-visible runtime effects of this change?

This was found by code inspection. If the pmem region is not correctly section aligned we can skip pfns while iterating device pfn using
for_each_device_pfn(pfn, pgmap)

I still would want Dan to ack the change though.

Dan?

From: "Aneesh Kumar K.V" <[email protected]>
Subject: mm/pgmap: use correct alignment when looking at first pfn from a region

vmem_altmap_offset() adjusts the section aligned base_pfn offset. So we need to make sure we account for the same when computing base_pfn.

ie, for altmap_valid case, our pfn_first should be:

pfn_first = altmap->base_pfn + vmem_altmap_offset(altmap);

This was found by code inspection. If the pmem region is not correctly section aligned we can skip pfns while iterating device pfn using

for_each_device_pfn(pfn, pgmap)

---

  mm/memremap.c |   12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)
mm/memremap.c renamed from mm/memremap.c~mm-pgmap-use-correct-alignment-when-looking-at-first-pfn-from-a-region +0 -0
@@ -55,8 +55,16 @@ static void pgmap_array_delete(struct re
 
Quoted 14 lines

mm/memremap.c static void pgmap_array_delete(struct re · line 65

Quoted 12 lines
mm/memremap.c renamed from mm/memremap.c~mm-pgmap-use-correct-alignment-when-looking-at-first-pfn-from-a-region +8 -2
  static unsigned long pfn_first(struct dev_pagemap *pgmap)
  {
-       return PHYS_PFN(pgmap->res.start) +
-               vmem_altmap_offset(pgmap_altmap(pgmap));
+       const struct resource *res = &pgmap->res;
+       struct vmem_altmap *altmap = pgmap_altmap(pgmap);
+       unsigned long pfn;
+
+       if (altmap)
+               pfn = altmap->base_pfn + vmem_altmap_offset(altmap);
+       else
+               pfn = PHYS_PFN(res->start);

This would only be a problem if res->start is not subsection aligned.

Kernel is not enforcing this right? ie, If i create multiple namespace as below

ndctl create-namespace -s 16908288 --align 64K

I can get base_pfn different from res->start PHYS_PFN

Yes that results in other error as below with the current upstream.

[   17.491097] memory add fail, invalid altmap
Quoted 10 lines

Is that bug triggering in your case, or is this just inspection. Now that the subsections can be assumed as the minimum mapping granularity I'd rather see a cleanup I'd rather cleanup the implementation to eliminate altmap->base_pfn or at least assert that PHYS_PFN(res->start) and altmap->base_pfn are always identical.

Otherwise ->base_pfn is supposed to be just a convenient way to recall the bounds of the memory hotplug operation deeper in the vmemmap setup.

Is the right fix to ensure that we always make sure res->start is subsection aligned ? If so we may need the patch series
https://patchwork.kernel.org/project/linux-nvdimm/list/?series=209373

And enforce that to be multiple of subsection size?

-aneesh

maintainer
#7 lore raw
Quoted 98 lines · On Tue, 3 Dec 2019 15:42:28 +0530 "Aneesh Kumar K.V"…
Quoted 58 lines · Dan Williams
Quoted 57 lines · Andrew Morton
Quoted 11 lines · On Wed, 25 Sep 2019 09:21:02 +0530 "Aneesh Kumar K.V"…
Quoted 9 lines · Andrew Morton
Quoted 6 lines · On Tue, 17 Sep 2019 21:01:29 +0530 "Aneesh Kumar K.V"…

vmem_altmap_offset() adjust the section aligned base_pfn offset. So we need to make sure we account for the same when computing base_pfn.

ie, for altmap_valid case, our pfn_first should be:

pfn_first = altmap->base_pfn + vmem_altmap_offset(altmap);

Quoted 9 lines
Quoted 1 line

What are the user-visible runtime effects of this change?

This was found by code inspection. If the pmem region is not correctly section aligned we can skip pfns while iterating device pfn using
for_each_device_pfn(pfn, pgmap)

I still would want Dan to ack the change though.

Dan?

From: "Aneesh Kumar K.V" <[email protected]>
Subject: mm/pgmap: use correct alignment when looking at first pfn from a region

vmem_altmap_offset() adjusts the section aligned base_pfn offset. So we need to make sure we account for the same when computing base_pfn.

ie, for altmap_valid case, our pfn_first should be:

pfn_first = altmap->base_pfn + vmem_altmap_offset(altmap);

This was found by code inspection. If the pmem region is not correctly section aligned we can skip pfns while iterating device pfn using

for_each_device_pfn(pfn, pgmap)

---

  mm/memremap.c |   12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)
mm/memremap.c renamed from mm/memremap.c~mm-pgmap-use-correct-alignment-when-looking-at-first-pfn-from-a-region +0 -0
@@ -55,8 +55,16 @@ static void pgmap_array_delete(struct re
 
Quoted 14 lines

mm/memremap.c static void pgmap_array_delete(struct re · line 65

Quoted 12 lines
mm/memremap.c renamed from mm/memremap.c~mm-pgmap-use-correct-alignment-when-looking-at-first-pfn-from-a-region +8 -2
  static unsigned long pfn_first(struct dev_pagemap *pgmap)
  {
-       return PHYS_PFN(pgmap->res.start) +
-               vmem_altmap_offset(pgmap_altmap(pgmap));
+       const struct resource *res = &pgmap->res;
+       struct vmem_altmap *altmap = pgmap_altmap(pgmap);
+       unsigned long pfn;
+
+       if (altmap)
+               pfn = altmap->base_pfn + vmem_altmap_offset(altmap);
+       else
+               pfn = PHYS_PFN(res->start);

This would only be a problem if res->start is not subsection aligned.

Kernel is not enforcing this right? ie, If i create multiple namespace as below

ndctl create-namespace -s 16908288 --align 64K

I can get base_pfn different from res->start PHYS_PFN

Yes that results in other error as below with the current upstream.

[   17.491097] memory add fail, invalid altmap
Quoted 10 lines

Is that bug triggering in your case, or is this just inspection. Now that the subsections can be assumed as the minimum mapping granularity I'd rather see a cleanup I'd rather cleanup the implementation to eliminate altmap->base_pfn or at least assert that PHYS_PFN(res->start) and altmap->base_pfn are always identical.

Otherwise ->base_pfn is supposed to be just a convenient way to recall the bounds of the memory hotplug operation deeper in the vmemmap setup.

Quoted 5 lines

Is the right fix to ensure that we always make sure res->start is subsection aligned ? If so we may need the patch series
https://patchwork.kernel.org/project/linux-nvdimm/list/?series=209373

And enforce that to be multiple of subsection size?

No response here?

This patch has been floating around for rather a long time. I think I'll drop it for now - please resend if still interested?