mm/pgmap: Use correct alignment when looking at first pfn from a region
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
@@ -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
Quoted 22 lines · Aneesh Kumar K.V
vmem_altmap_offset()adjust the section alignedbase_pfnoffset. So we need to make sure we account for the same when computingbase_pfn.ie, for
altmap_validcase, ourpfn_firstshould be:
pfn_first=altmap->base_pfn+vmem_altmap_offset(altmap);Signed-off-by Aneesh Kumar K.V <[email protected]>---
* changes from v5
* update commit subject and use linux-mm for mergemm/memremap.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)mm/memremap.c +0
-0@@ -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
Andrew Morton
maintainerQuoted 6 lines · On Tue, 17 Sep 2019 21:01:29 +0530 "Aneesh Kumar K.V"…
vmem_altmap_offset()adjust the section alignedbase_pfnoffset. So we need to make sure we account for the same when computingbase_pfn.ie, for
altmap_validcase, ourpfn_firstshould 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
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 alignedbase_pfnoffset. So we need to make sure we account for the same when computingbase_pfn.ie, for
altmap_validcase, ourpfn_firstshould 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
Andrew Morton
maintainerQuoted 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 alignedbase_pfnoffset. So we need to make sure we account for the same when computingbase_pfn.ie, for
altmap_validcase, ourpfn_firstshould 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 restatic 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)
_
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 alignedbase_pfnoffset. So we need to make sure we account for the same when computingbase_pfn.ie, for
altmap_validcase, ourpfn_firstshould 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 alignedbase_pfnoffset. So we need to make sure we account for the same when computingbase_pfn.ie, for
altmap_validcase, ourpfn_firstshould 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)[[email protected]: coding style fixes]Signed-off-by Aneesh Kumar K.V <[email protected]>Cc Ralph Campbell <[email protected]>Cc Dan Williams <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
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 restatic 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.
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 alignedbase_pfnoffset. So we need to make sure we account for the same when computingbase_pfn.ie, for
altmap_validcase, ourpfn_firstshould 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 alignedbase_pfnoffset. So we need to make sure we account for the same when computingbase_pfn.ie, for
altmap_validcase, ourpfn_firstshould 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)[[email protected]: coding style fixes]Signed-off-by Aneesh Kumar K.V <[email protected]>Cc Ralph Campbell <[email protected]>Cc Dan Williams <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
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
-2static 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->startis 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_pfnor at least assert thatPHYS_PFN(res->start)andaltmap->base_pfnare 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
Andrew Morton
maintainerQuoted 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 alignedbase_pfnoffset. So we need to make sure we account for the same when computingbase_pfn.ie, for
altmap_validcase, ourpfn_firstshould 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 alignedbase_pfnoffset. So we need to make sure we account for the same when computingbase_pfn.ie, for
altmap_validcase, ourpfn_firstshould 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)[[email protected]: coding style fixes]Signed-off-by Aneesh Kumar K.V <[email protected]>Cc Ralph Campbell <[email protected]>Cc Dan Williams <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
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 reQuoted 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
-2static 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->startis 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_pfndifferent fromres->startPHYS_PFNYes that results in other error as below with the current upstream.
[ 17.491097] memory add fail, invalid altmapQuoted 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_pfnor at least assert thatPHYS_PFN(res->start)andaltmap->base_pfnare 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->startis subsection aligned ? If so we may need the patch series
https://patchwork.kernel.org/project/linux-nvdimm/list/?series=209373And 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?