Skip to contentSkip to conversation

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

PATCH Superseded Aneesh Kumar K.V 2 participants 4 messages May 14, 2019 – May 27, 2019

Subsystems (2)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

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

We already add the start_pad to the resource->start but fails to section align the start. This make sure with altmap we compute the right first pfn when start_pad is zero and we are doing an align down of start address.

---
 kernel/memremap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/memremap.c +2 -2
index a856cb5ff192..23d77b60e728 100644
@@ -59,9 +59,9 @@ static unsigned long pfn_first(struct dev_pagemap *pgmap)
 {
 	const struct resource *res = &pgmap->res;
 	struct vmem_altmap *altmap = &pgmap->altmap;
-	unsigned long pfn;
+	unsigned long pfn = PHYS_PFN(res->start);
 
-	pfn = res->start >> PAGE_SHIFT;
+	pfn = SECTION_ALIGN_DOWN(pfn);
 	if (pgmap->altmap_valid)
 		pfn += vmem_altmap_offset(altmap);
 	return pfn;
Signature · 6 lines
2.21.0

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#1 lore raw
Quoted 15 lines · Aneesh Kumar K.V

We already add the start_pad to the resource->start but fails to section align the start. This make sure with altmap we compute the right first pfn when start_pad is zero and we are doing an align down of start address.

---
 kernel/memremap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/memremap.c +0 -0
index a856cb5ff192..23d77b60e728 100644

kernel/memremap.c static unsigned long pfn_first(struct dev_pagemap *pgmap) · line 64

Quoted 8 lines
kernel/memremap.c +2 -2
@@ -59,9 +59,9 @@ static unsigned long pfn_first(struct dev_pagemap *pgmap)
 {
        const struct resource *res = &pgmap->res;
        struct vmem_altmap *altmap = &pgmap->altmap;
-       unsigned long pfn;
+       unsigned long pfn = PHYS_PFN(res->start);
 
-       pfn = res->start >> PAGE_SHIFT;
+       pfn = SECTION_ALIGN_DOWN(pfn);

This does not seem right to me it breaks the assumptions of where the first expected valid pfn occurs in the passed in range.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#2 lore raw
Quoted 23 lines · Dan Williams
Quoted 21 lines · Aneesh Kumar K.V

We already add the start_pad to the resource->start but fails to section align the start. This make sure with altmap we compute the right first pfn when start_pad is zero and we are doing an align down of start address.

---
  kernel/memremap.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
kernel/memremap.c +1 -1
index a856cb5ff192..23d77b60e728 100644
@@ -59,9 +59,9 @@ static unsigned long pfn_first(struct dev_pagemap *pgmap)
  {
         const struct resource *res = &pgmap->res;
         struct vmem_altmap *altmap = &pgmap->altmap;
-       unsigned long pfn;
+       unsigned long pfn = PHYS_PFN(res->start);
 
Quoted 6 lines

kernel/memremap.c static unsigned long pfn_first(struct dev_pagemap *pgmap) · line 64

Quoted 2 lines
kernel/memremap.c +1 -1
-       pfn = res->start >> PAGE_SHIFT;
+       pfn = SECTION_ALIGN_DOWN(pfn);

This does not seem right to me it breaks the assumptions of where the first expected valid pfn occurs in the passed in range.

How do we define the first valid pfn? Isn't that at pfn_sb->dataoff ?

-aneesh

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

#3 lore raw
Quoted 24 lines · Aneesh Kumar K.V
Quoted 23 lines · Dan Williams
Quoted 21 lines · Aneesh Kumar K.V

We already add the start_pad to the resource->start but fails to section align the start. This make sure with altmap we compute the right first pfn when start_pad is zero and we are doing an align down of start address.

---
  kernel/memremap.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
kernel/memremap.c +1 -1
index a856cb5ff192..23d77b60e728 100644
@@ -59,9 +59,9 @@ static unsigned long pfn_first(struct dev_pagemap *pgmap)
  {
         const struct resource *res = &pgmap->res;
         struct vmem_altmap *altmap = &pgmap->altmap;
-       unsigned long pfn;
+       unsigned long pfn = PHYS_PFN(res->start);
 
Quoted 8 lines
Quoted 6 lines

kernel/memremap.c static unsigned long pfn_first(struct dev_pagemap *pgmap) · line 64

Quoted 2 lines
kernel/memremap.c +1 -1
-       pfn = res->start >> PAGE_SHIFT;
+       pfn = SECTION_ALIGN_DOWN(pfn);

This does not seem right to me it breaks the assumptions of where the first expected valid pfn occurs in the passed in range.

How do we define the first valid pfn? Isn't that at pfn_sb->dataoff ?

for altmap the pfn_first should be

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

?

-aneesh

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