arm64: mm: update max_pfn after memory hotplug
Subsystems (2)
On arm64 we set max_pfn at boot in arch/arm64/mm/init.c. If you hotplug in memory after booting up, max_pfn is not updated. This breaks diagnostic functions executed from user space like read_page_owner():
https://elixir.bootlin.com/linux/v5.14.7/source/mm/page_owner.c#L472
or kpageflags_read() (see how get_max_dump_pfn() is used):
https://elixir.bootlin.com/linux/v5.14.7/source/fs/proc/page.c#L47
Thus, this patch updates max_pfn and max_low_pfn in arm64's arch_add_memory() function, mirroring what is updatated during boot:
https://elixir.bootlin.com/linux/v5.14.7/source/arch/arm64/mm/init.c#L448
We would appreciate feedback on any other variables that should be updated when hotplugging in memory - note that we're mirroring x86, in that max_pfn is only ever incremented when calling arch_add_memory():
https://elixir.bootlin.com/linux/v5.14.7/source/arch/x86/mm/init_64.c#L958
Sudarshan Rajagopalan (1):
arm64: mm: update max_pfn after memory hotplug
arch/arm64/mm/mmu.c | 5 +++++ 1 file changed, 5 insertions(+)
Signature · 1 line
2.7.4
RFC 1/1 arm64: mm: update max_pfn after memory hotplug
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged, max_pfn and max_low_pfn needs updating to reflect on new PFNs being hot added to system.
--- arch/arm64/mm/mmu.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm64/mm/mmu.c +5 -0
@@ -1499,6 +1499,11 @@ int arch_add_memory(int nid, u64 start, u64 size,if (ret)__remove_pgd_mapping (swapper_pg_dir,__phys_to_virt (start), size); +else { + max_pfn =PFN_UP (start + size); + max_low_pfn = max_pfn; + } +return ret; }
Signature · 1 line
2.7.4
Quoted 16 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>--- arch/arm64/mm/mmu.c | 5 +++++ 1 file changed, 5 insertions(+)arch/arm64/mm/mmu.c +0
-0
arch/arm64/mm/mmu.c int arch_add_memory(int nid, u64 start, u64 size, · line 1505
Quoted 7 lines
arch/arm64/mm/mmu.c +4
-0@@ -1499,6 +1499,11 @@ int arch_add_memory(int nid, u64 start, u64 size,if (ret)__remove_pgd_mapping (swapper_pg_dir,__phys_to_virt (start), size); +else { + max_pfn =PFN_UP (start + size); + max_low_pfn = max_pfn; + }
This is a drive by review, but it got me thinking about your changes a bit:
- if you raise max_pfn when you hotplug memory, don't you need to lower it when you hot unplug memory as well?
- suppose that you have a platform which maps physical memory into the CPU's address space at 0x00_4000_0000 (1GB offset) and the kernel boots with 2GB of DRAM plugged by default. At that point we have not registered a swiotlb because we have less than 4GB of addressable physical memory, there is no IOMMU in that system, it's a happy world. Now assume that we plug an additional 2GB of DRAM into that system adjacent to the previous 2GB, from 0x00_C0000_0000 through 0x14_0000_0000, now we have physical addresses above 4GB, but we still don't have a swiotlb, some of our DMA_BIT_MASK(32) peripherals are going to be unable to DMA from that hot plugged memory, but they could if we had a swiotlb.
- now let's go even further but this is very contrived. Assume that the firmware has somewhat created a reserved memory region with a 'no-map' attribute thus indicating it does not want a struct page to be created for a specific PFN range, is it valid to "blindly" raise max_pfn if that region were to be at the end of the just hot-plugged memory?
Signature · 1 line
Florian
Quoted 29 lines · Florian Fainelli
Quoted 16 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>--- arch/arm64/mm/mmu.c | 5 +++++ 1 file changed, 5 insertions(+)arch/arm64/mm/mmu.c +0
-0arch/arm64/mm/mmu.c int arch_add_memory(int nid, u64 start, u64 size, · line 1505
Quoted 7 lines
arch/arm64/mm/mmu.c +4
-0@@ -1499,6 +1499,11 @@ int arch_add_memory(int nid, u64 start, u64 size,if (ret)__remove_pgd_mapping (swapper_pg_dir,__phys_to_virt (start), size); +else { + max_pfn =PFN_UP (start + size); + max_low_pfn = max_pfn; + }This is a drive by review, but it got me thinking about your changes a bit:
Quoted 2 lines
- if you raise
max_pfnwhen you hotplug memory, don't you need to lower it when you hot unplug memory as well?
The issue with lowering is that you actually have to do some search to figure out the actual value -- and it's not really worth the trouble. Raising the limit is easy.
With memory hotunplug, anybody wanting to take a look at a "struct page" via a pfn has to do a pfn_to_online_page() either way. That will fail if there isn't actually a memmap anymore because the memory has been unplugged. So "max_pfn" is actually rather a hint what maximum pfn to look at, and it can be bigger than it actually is.
The a look at the example usage in fs/proc/page.c:kpageflags_read()
pfn_to_online_page() will simply fail and stable_page_flags() will indicate a KPF_NOPAGE.
Just like we would have a big memory hole now at the end of memory.
Quoted 12 lines
- suppose that you have a platform which maps physical memory into the CPU's address space at 0x00_4000_0000 (1GB offset) and the kernel boots with 2GB of DRAM plugged by default. At that point we have not registered a swiotlb because we have less than 4GB of addressable physical memory, there is no IOMMU in that system, it's a happy world. Now assume that we plug an additional 2GB of DRAM into that system adjacent to the previous 2GB, from 0x00_C0000_0000 through 0x14_0000_0000, now we have physical addresses above 4GB, but we still don't have a swiotlb, some of our
DMA_BIT_MASK(32)peripherals are going to be unable to DMA from that hot plugged memory, but they could if we had a swiotlb.
That's why platforms that hotplug memory should indicate the maximum possible PFN via some mechanism during boot. On x86-64 (and IIRC also arm64 now), this is done via the ACPI SRAT.
And that's where "max_possible_pfn" and "max_pfn" differ. See drivers/acpi/numa/srat.c:acpi_numa_memory_affinity_init():
max_possible_pfn = max(max_possible_pfn, PFN_UP(end - 1));$
Using max_possible_pfn, the OS can properly setup the swiotlb, even thought it wouldn't currently be required when just looking at max_pfn.
I documented that for virtio-mem in
https://virtio-mem.gitlab.io/user-guide/user-guide-linux.html
"swiotlb and DMA memory".
Quoted 6 lines
- now let's go even further but this is very contrived. Assume that the firmware has somewhat created a reserved memory region with a 'no-map' attribute thus indicating it does not want a struct page to be created for a specific PFN range, is it valid to "blindly" raise
max_pfnif that region were to be at the end of the just hot-plugged memory?
no-map means that no direct mapping is to be created, right? We would still have a memmap IIRC, and the pages are PG_reserved.
Again, I think this is very similar to just having no-map regions like random memory holes within the existing memory layout.
What Chris proposes here is very similar to arch/x86/mm/init_64.c:update_end_of_memory_vars() called during arch_add_memory()->add_pages() on x86-64.
Signature · 3 lines
Thanks, David / dhildenb
Thanks for the response David.
Quoted 5 lines · David Hildenbrand
no-map means that no direct mapping is to be created, right? We would still have a memmap IIRC, and the pages are
PG_reserved.Again, I think this is very similar to just having no-map regions like random memory holes within the existing memory layout.
For those curious, see __reserved_mem_alloc_size() > early_init_dt_alloc_reserved_memory_arch() > memblock_mark_nomap() - the 'no-map' attribute is read in __reserved_mem_alloc_size() and the pre-requisite steps need to have the relevant struct pages marked as PG_reserved are taken in memblock_mark_nomap().
Quoted 4 lines
What Chris proposes here is very similar to arch/x86/mm/init_64.c:update_end_of_memory_vars() called during arch_add_memory()->add_pages() on x86-64.
For other's reference, the patch was derived from what x86 is doing with max_pfn (such that we also set max_low_pfn as is done in arm64's mm/init.c.
+Anshuman
Thanks for the responses. Do we see any issues with having this patch go for merge? I agree with David that 'max_pfn' is just a hint about maximum possible PFN that can go. So it doesn't need updating when memory is hotunplugged out.
Also regarding comment about possible reserved memory region with "no-map" attribute - I'm not sure if we such reserved memory allocations are allowed post early init when memory blocks are hot added later on after arm64_memblock_init is done? These are all done during setup_arch right?
We found this issue/bug where kernel inits with limited boot memory using 'mem=' and a driver hot-adds memory blocks during module init using add_memory_driver_managed and owns it. This makes 'max_pfn' out of sync and breaks /proc/kpageXXX kpageflags_read() functionality where any processes using pages beyond this outdated 'max_pfn', stable_page_flags() would simply return KPF_NOPAGE.
I think this is generic bug that exists with arm64 memory hotplug where any consumers of 'max_pfn' would break its functionality after memory blocks are hotplugged in after init. If this patch looks OK and be ACKed, we can have it in GKI. Other suggestions on proper fix or feedback are also welcome.
Quoted 84 lines · David Hildenbrand
Quoted 30 lines · Florian Fainelli
Quoted 16 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>---
arch/arm64/mm/mmu.c| 5 +++++1 file changed, 5 insertions(+)arch/arm64/mm/mmu.c +0
-0arch/arm64/mm/mmu.c int arch_add_memory(int nid, u64 start, u64 · line 1506
Quoted 8 lines
arch/arm64/mm/mmu.c +4
-0@@ -1499,6 +1499,11 @@ int arch_add_memory(int nid, u64 start, u64 size, if (ret) __remove_pgd_mapping(swapper_pg_dir, __phys_to_virt(start), size); + else { + max_pfn = PFN_UP(start + size); + max_low_pfn = max_pfn; + }This is a drive by review, but it got me thinking about your changes a bit:
Quoted 2 lines
- if you raise
max_pfnwhen you hotplug memory, don't you need to lower it when you hot unplug memory as well?The issue with lowering is that you actually have to do some search to figure out the actual value -- and it's not really worth the trouble. Raising the limit is easy.
With memory hotunplug, anybody wanting to take a look at a "struct page" via a pfn has to do a
pfn_to_online_page()either way. That will fail if there isn't actually a memmap anymore because the memory has been unplugged. So "max_pfn" is actually rather a hint what maximum pfn to look at, and it can be bigger than it actually is.The a look at the example usage in fs/proc/page.c:kpageflags_read()
pfn_to_online_page()will simply fail andstable_page_flags()will indicate aKPF_NOPAGE.Just like we would have a big memory hole now at the end of memory.
Quoted 12 lines
- suppose that you have a platform which maps physical memory into the CPU's address space at 0x00_4000_0000 (1GB offset) and the kernel boots with 2GB of DRAM plugged by default. At that point we have not registered a swiotlb because we have less than 4GB of addressable physical memory, there is no IOMMU in that system, it's a happy world. Now assume that we plug an additional 2GB of DRAM into that system adjacent to the previous 2GB, from 0x00_C0000_0000 through 0x14_0000_0000, now we have physical addresses above 4GB, but we still don't have a swiotlb, some of our
DMA_BIT_MASK(32)peripherals are going to be unable to DMA from that hot plugged memory, but they could if we had a swiotlb.That's why platforms that hotplug memory should indicate the maximum possible PFN via some mechanism during boot. On x86-64 (and IIRC also arm64 now), this is done via the ACPI SRAT.
And that's where "
max_possible_pfn" and "max_pfn" differ. See drivers/acpi/numa/srat.c:acpi_numa_memory_affinity_init():max_possible_pfn =
max(max_possible_pfn, PFN_UP(end - 1));$Using
max_possible_pfn, the OS can properly setup the swiotlb, even thought it wouldn't currently be required when just looking atmax_pfn.I documented that for virtio-mem in
https://virtio-mem.gitlab.io/user-guide/user-guide-linux.html
"swiotlb and DMA memory".Quoted 6 lines
- now let's go even further but this is very contrived. Assume that the firmware has somewhat created a reserved memory region with a 'no-map' attribute thus indicating it does not want a struct page to be created for a specific PFN range, is it valid to "blindly" raise
max_pfnif that region were to be at the end of the just hot-plugged memory?no-map means that no direct mapping is to be created, right? We would still have a memmap IIRC, and the pages are
PG_reserved.Again, I think this is very similar to just having no-map regions like random memory holes within the existing memory layout.
What Chris proposes here is very similar to arch/x86/mm/init_64.c:update_end_of_memory_vars() called during arch_add_memory()->add_pages() on x86-64.
Quoted 16 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>--- arch/arm64/mm/mmu.c | 5 +++++ 1 file changed, 5 insertions(+)arch/arm64/mm/mmu.c +0
-0
arch/arm64/mm/mmu.c int arch_add_memory(int nid, u64 start, u64 size, · line 1507
Quoted 9 lines
arch/arm64/mm/mmu.c +5
-0@@ -1499,6 +1499,11 @@ int arch_add_memory(int nid, u64 start, u64 size,if (ret)__remove_pgd_mapping (swapper_pg_dir,__phys_to_virt (start), size); +else { + max_pfn =PFN_UP (start + size); + max_low_pfn = max_pfn; + } +return ret;
Note: didn't verify if updating max_low_pfn is correct here.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 12 lines · David Hildenbrand
Quoted 11 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>---
arch/arm64/mm/mmu.c| 5 +++++1 file changed, 5 insertions(+)
Quoted 16 lines
Quoted 5 lines
arch/arm64/mm/mmu.c +0
-0arch/arm64/mm/mmu.c int arch_add_memory(int nid, u64 start, u64 size, · line 1507
Quoted 9 lines
arch/arm64/mm/mmu.c +5
-0@@ -1499,6 +1499,11 @@ int arch_add_memory(int nid, u64 start, u64 size, if (ret) __remove_pgd_mapping(swapper_pg_dir, __phys_to_virt(start), size); + else { + max_pfn = PFN_UP(start + size); + max_low_pfn = max_pfn; + } + return ret;Note: didn't verify if updating
max_low_pfnis correct here.
My understanding is that max_low_pfn defines the low/high memory boundary and it should be also updated.
Thanks,
Georgi
Quoted 30 lines · Georgi Djakov
Quoted 12 lines · David Hildenbrand
Quoted 11 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>---
arch/arm64/mm/mmu.c| 5 +++++1 file changed, 5 insertions(+)Quoted 16 lines
Quoted 5 lines
arch/arm64/mm/mmu.c +0
-0arch/arm64/mm/mmu.c int arch_add_memory(int nid, u64 start, u64 size, · line 1507
Quoted 9 lines
arch/arm64/mm/mmu.c +5
-0@@ -1499,6 +1499,11 @@ int arch_add_memory(int nid, u64 start, u64 size, if (ret) __remove_pgd_mapping(swapper_pg_dir, __phys_to_virt(start), size); + else { + max_pfn = PFN_UP(start + size); + max_low_pfn = max_pfn; + } + return ret;Note: didn't verify if updating
max_low_pfnis correct here.
Quoted 5 lines
My understanding is that
max_low_pfndefines the low/high memory boundary and it should be also updated.Thanks,
Georgi
To build more on Georgi's response, our assumption here after an offline discussion is that max_low_pfn would not be equal to max_pfn only if there is high memory - another assumption is that arm64 kernels will not need high memory due to their large logical mappings. Under these two assumptions, the patch is correct. Perhaps Catalin can ack or critique this, as he initially set max_pfn = max_low_pfn in the first arm64 mm initialization code:
Quoted 37 lines · Chris Goldsworthy
Quoted 30 lines · Georgi Djakov
Quoted 12 lines · David Hildenbrand
Quoted 11 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>--- arch/arm64/mm/mmu.c | 5 +++++ 1 file changed, 5 insertions(+)Quoted 16 lines
Quoted 5 lines
arch/arm64/mm/mmu.c +0
-0arch/arm64/mm/mmu.c int arch_add_memory(int nid, u64 start, u64 size, · line 1507
Quoted 9 lines
arch/arm64/mm/mmu.c +5
-0@@ -1499,6 +1499,11 @@ int arch_add_memory(int nid, u64 start, u64 size, if (ret) __remove_pgd_mapping(swapper_pg_dir, __phys_to_virt(start), size); + else { + max_pfn = PFN_UP(start + size); + max_low_pfn = max_pfn; + } + return ret;Note: didn't verify if updating
max_low_pfnis correct here.Quoted 5 lines
My understanding is that
max_low_pfndefines the low/high memory boundary and it should be also updated.Thanks,
Georgi
Quoted 6 lines
To build more on Georgi's response, our assumption here after an offline discussion is that
max_low_pfnwould not be equal tomax_pfnonly if there is high memory - another assumption is that arm64 kernels will not need high memory due to their large logical mappings. Under these two assumptions, the patch is correct. Perhaps Catalin can ack or critique this, as he initially setmax_pfn=max_low_pfnin the first arm64 mm initialization code:
Makes sense to me, thanks.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 7 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>
Thanks for the patch, Chris!
With this patch, the data in /proc/kpageflags appears to be correct and memory tools like procrank work again on arm64 platforms.
Maybe we should add fixes tag, as it has been broken since the following commit:
Thanks,
Georgi
Quoted 21 lines
--- arch/arm64/mm/mmu.c | 5 +++++ 1 file changed, 5 insertions(+)arch/arm64/mm/mmu.c +5
-0@@ -1499,6 +1499,11 @@ int arch_add_memory(int nid, u64 start, u64 size,if (ret)__remove_pgd_mapping (swapper_pg_dir,__phys_to_virt (start), size); +else { + max_pfn =PFN_UP (start + size); + max_low_pfn = max_pfn; + } +return ret; }
Quoted 14 lines · Georgi Djakov
Quoted 7 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>Thanks for the patch, Chris!
With this patch, the data in
/proc/kpageflagsappears to be correct and memory tools like procrank work again on arm64 platforms.
Quoted 6 lines
Tested-by Georgi Djakov <[email protected]>Maybe we should add fixes tag, as it has been broken since the following commit:
Fixes abec749facff ("fs/proc/page.c: allow inspection of last sectionand fix end detection")
Are you sure that that commit broke it?
I recall that we would naturally run into the limit, because
count = min_t(size_t, count, (max_pfn * KPMSIZE) - src);
wouldn't really do what you would expect either. But you could force-read beyond max_pfn, yes, because the count computation was just weird.
I think the real issue is not properly adjusting max_pfn in the first place when we introduced memoruy hotplug on arm64.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 15 lines · David Hildenbrand
Quoted 14 lines · Georgi Djakov
Quoted 7 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>Thanks for the patch, Chris!
With this patch, the data in
/proc/kpageflagsappears to be correct and memory tools like procrank work again on arm64 platforms.
Quoted 8 lines
Quoted 6 lines
Tested-by Georgi Djakov <[email protected]>Maybe we should add fixes tag, as it has been broken since the following commit:
Fixes abec749facff ("fs/proc/page.c: allow inspection of last sectionand fix end detection")
Are you sure that that commit broke it?
Reverting the above commit also "fixes" kpageflags, otherwise kpageflags_read() returns 0 in the following check:
if (src >= max_dump_pfn * KPMSIZE) return 0;
Quoted 3 lines
I recall that we would naturally run into the limit, because
count =
min_t(size_t, count, (max_pfn * KPMSIZE) - src);
The function returns before we reach this line.
Thanks,
Georgi
Quoted 4 lines
wouldn't really do what you would expect either. But you could force-read beyond
max_pfn, yes, because the count computation was just weird.I think the real issue is not properly adjusting
max_pfnin the first place when we introduced memoruy hotplug on arm64
Quoted 27 lines · Georgi Djakov
Quoted 15 lines · David Hildenbrand
Quoted 14 lines · Georgi Djakov
Quoted 7 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>Thanks for the patch, Chris!
With this patch, the data in
/proc/kpageflagsappears to be correct and memory tools like procrank work again on arm64 platforms.Quoted 8 lines
Quoted 6 lines
Tested-by Georgi Djakov <[email protected]>Maybe we should add fixes tag, as it has been broken since the following commit:
Fixes abec749facff ("fs/proc/page.c: allow inspection of last sectionand fix end detection")
Are you sure that that commit broke it?
Reverting the above commit also "fixes" kpageflags, otherwise
kpageflags_read()returns 0 in the following check:
Quoted 8 lines
if (src >= max_dump_pfn * KPMSIZE) return 0;Quoted 3 lines
I recall that we would naturally run into the limit, because
count =
min_t(size_t, count, (max_pfn * KPMSIZE) - src);The function returns before we reach this line.
That is the old code. I don't see how the behavior of the old code with wrong max_pfn was doing what it's supposed to do.
page_idle and page_owner also rely on max_pfn. The root issue is that max_pfn wasn't updated properly.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 33 lines · David Hildenbrand
Quoted 32 lines · Georgi Djakov
Quoted 15 lines · David Hildenbrand
Quoted 14 lines · Georgi Djakov
Quoted 7 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>Thanks for the patch, Chris!
With this patch, the data in
/proc/kpageflagsappears to be correct and memory tools like procrank work again on arm64 platforms.Quoted 8 lines
Quoted 6 lines
Tested-by Georgi Djakov <[email protected]>Maybe we should add fixes tag, as it has been broken since the following commit:
Fixes abec749facff ("fs/proc/page.c: allow inspection of last sectionand fix end detection")
Are you sure that that commit broke it?
Reverting the above commit also "fixes" kpageflags, otherwise
kpageflags_read()returns 0 in the following check:
if (src >=max_dump_pfn* KPMSIZE)
return 0;Quoted 2 lines
I recall that we would naturally run into the limit, because
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
count =
min_t(size_t, count, (max_pfn * KPMSIZE) - src);The function returns before we reach this line.
That is the old code. I don't see how the behavior of the old code with wrong
max_pfnwas doing what it's supposed to do.
page_idleandpage_owneralso rely onmax_pfn. The root issue is thatmax_pfnwasn't updated properly.
Ok, i agree that this is not really fixing abec749facff, as it only reveals the real issue, so then the fixes tag should be even further back to:
Thanks,
Georgi
Will Deacon
maintainerQuoted 16 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>--- arch/arm64/mm/mmu.c | 5 +++++ 1 file changed, 5 insertions(+)arch/arm64/mm/mmu.c +0
-0
arch/arm64/mm/mmu.c int arch_add_memory(int nid, u64 start, u64 size, · line 1505
Quoted 7 lines
arch/arm64/mm/mmu.c +4
-0@@ -1499,6 +1499,11 @@ int arch_add_memory(int nid, u64 start, u64 size,if (ret)__remove_pgd_mapping (swapper_pg_dir,__phys_to_virt (start), size); +else { + max_pfn =PFN_UP (start + size); + max_low_pfn = max_pfn; + }
We use 'max_pfn' as part of the argument to set_max_mapnr(). Does that need updating as well?
Do we have sufficient locking to ensure nobody is looking at max_pfn or max_low_pfn while we update them?
Will
Quoted 28 lines · Will Deacon
Quoted 16 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>--- arch/arm64/mm/mmu.c | 5 +++++ 1 file changed, 5 insertions(+)arch/arm64/mm/mmu.c +0
-0arch/arm64/mm/mmu.c int arch_add_memory(int nid, u64 start, u64 size, · line 1505
Quoted 7 lines
arch/arm64/mm/mmu.c +4
-0@@ -1499,6 +1499,11 @@ int arch_add_memory(int nid, u64 start, u64 size,if (ret)__remove_pgd_mapping (swapper_pg_dir,__phys_to_virt (start), size); +else { + max_pfn =PFN_UP (start + size); + max_low_pfn = max_pfn; + }We use '
max_pfn' as part of the argument toset_max_mapnr(). Does that need updating as well?
Quoted 2 lines
Do we have sufficient locking to ensure nobody is looking at
max_pfnormax_low_pfnwhile we update them?
Only the write side is protected by memory hotplug locking. The read side is lockless -- just like all of the other pfn_to_online_page() machinery.
Quoted 3 lines
Will
Signature · 3 lines
Thanks, David / dhildenb
Will Deacon
maintainerQuoted 29 lines · David Hildenbrand
Quoted 28 lines · Will Deacon
Quoted 16 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>--- arch/arm64/mm/mmu.c | 5 +++++ 1 file changed, 5 insertions(+)arch/arm64/mm/mmu.c +0
-0arch/arm64/mm/mmu.c int arch_add_memory(int nid, u64 start, u64 size, · line 1505
Quoted 7 lines
arch/arm64/mm/mmu.c +4
-0@@ -1499,6 +1499,11 @@ int arch_add_memory(int nid, u64 start, u64 size,if (ret)__remove_pgd_mapping (swapper_pg_dir,__phys_to_virt (start), size); +else { + max_pfn =PFN_UP (start + size); + max_low_pfn = max_pfn; + }We use '
max_pfn' as part of the argument toset_max_mapnr(). Does that need updating as well?
Quoted 5 lines
Quoted 2 lines
Do we have sufficient locking to ensure nobody is looking at
max_pfnormax_low_pfnwhile we update them?Only the write side is protected by memory hotplug locking. The read side is lockless -- just like all of the other
pfn_to_online_page()machinery.
Hmm. So the readers can see one of the variables updated but the other one stale?
Will
Quoted 30 lines · Will Deacon
Quoted 29 lines · David Hildenbrand
Quoted 28 lines · Will Deacon
Quoted 16 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>--- arch/arm64/mm/mmu.c | 5 +++++ 1 file changed, 5 insertions(+)arch/arm64/mm/mmu.c +0
-0arch/arm64/mm/mmu.c int arch_add_memory(int nid, u64 start, u64 size, · line 1505
Quoted 7 lines
arch/arm64/mm/mmu.c +4
-0@@ -1499,6 +1499,11 @@ int arch_add_memory(int nid, u64 start, u64 size,if (ret)__remove_pgd_mapping (swapper_pg_dir,__phys_to_virt (start), size); +else { + max_pfn =PFN_UP (start + size); + max_low_pfn = max_pfn; + }We use '
max_pfn' as part of the argument toset_max_mapnr(). Does that need updating as well?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Do we have sufficient locking to ensure nobody is looking at
max_pfnormax_low_pfnwhile we update them?Only the write side is protected by memory hotplug locking. The read side is lockless -- just like all of the other
pfn_to_online_page()machinery.Hmm. So the readers can see one of the variables updated but the other one stale?
Yes, just like it has been on x86-64 for a long time:
arch/x86/mm/init_64.c:update_end_of_memory_vars()
Not sure if anyone really cares about slightly delayed updates while memory is getting hotplugged. The users that I am aware of don't care.
Signature · 3 lines
Thanks, David / dhildenb
Will Deacon
maintainerQuoted 40 lines · David Hildenbrand
Quoted 30 lines · Will Deacon
Quoted 29 lines · David Hildenbrand
Quoted 28 lines · Will Deacon
Quoted 16 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>--- arch/arm64/mm/mmu.c | 5 +++++ 1 file changed, 5 insertions(+)arch/arm64/mm/mmu.c +0
-0arch/arm64/mm/mmu.c int arch_add_memory(int nid, u64 start, u64 size, · line 1505
Quoted 7 lines
arch/arm64/mm/mmu.c +4
-0@@ -1499,6 +1499,11 @@ int arch_add_memory(int nid, u64 start, u64 size,if (ret)__remove_pgd_mapping (swapper_pg_dir,__phys_to_virt (start), size); +else { + max_pfn =PFN_UP (start + size); + max_low_pfn = max_pfn; + }We use '
max_pfn' as part of the argument toset_max_mapnr(). Does that need updating as well?Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Do we have sufficient locking to ensure nobody is looking at
max_pfnormax_low_pfnwhile we update them?Only the write side is protected by memory hotplug locking. The read side is lockless -- just like all of the other
pfn_to_online_page()machinery.Hmm. So the readers can see one of the variables updated but the other one stale?
Quoted 6 lines
Yes, just like it has been on x86-64 for a long time:
arch/x86/mm/init_64.c:update_end_of_memory_vars()
Not sure if anyone really cares about slightly delayed updates while memory is getting hotplugged. The users that I am aware of don't care.
Thanks, I'd missed that x86 also updates max_low_pfn. So at least we're not worse off in that respect.
Looking at set_max_mapnr(), I'm wondering why we need to call that at all on arm64 as 'max_mapnr' only seems to be used for nommu.
Will
Quoted 45 lines · Will Deacon
Quoted 44 lines · David Hildenbrand
Quoted 30 lines · Will Deacon
Quoted 29 lines · David Hildenbrand
Quoted 28 lines · Will Deacon
Quoted 16 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>--- arch/arm64/mm/mmu.c | 5 +++++ 1 file changed, 5 insertions(+)arch/arm64/mm/mmu.c +0
-0arch/arm64/mm/mmu.c int arch_add_memory(int nid, u64 start, u64 size, · line 1505
Quoted 7 lines
arch/arm64/mm/mmu.c +4
-0@@ -1499,6 +1499,11 @@ int arch_add_memory(int nid, u64 start, u64 size,if (ret)__remove_pgd_mapping (swapper_pg_dir,__phys_to_virt (start), size); +else { + max_pfn =PFN_UP (start + size); + max_low_pfn = max_pfn; + }We use '
max_pfn' as part of the argument toset_max_mapnr(). Does that need updating as well?Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Do we have sufficient locking to ensure nobody is looking at
max_pfnormax_low_pfnwhile we update them?Only the write side is protected by memory hotplug locking. The read side is lockless -- just like all of the other
pfn_to_online_page()machinery.Hmm. So the readers can see one of the variables updated but the other one stale?
Yes, just like it has been on x86-64 for a long time:
arch/x86/mm/init_64.c:update_end_of_memory_vars()
Quoted 8 lines
Quoted 2 lines
Not sure if anyone really cares about slightly delayed updates while memory is getting hotplugged. The users that I am aware of don't care.
Thanks, I'd missed that x86 also updates
max_low_pfn. So at least we're not worse off in that respect.Looking at
set_max_mapnr(), I'm wondering why we need to call that at all on arm64 as 'max_mapnr' only seems to be used for nommu.
I think max_mapnr is only helpful without SPARSE, I can spot the most prominent consumer being simplistic pfn_valid() implementation.
MEMORY_HOTPLUG on arm64 implies SPARSE. ... and I recall that FLATMEM is no longer possible on arm64. So most probably the arm64 call of set_max_mapnr() can just be dropped.
Signature · 3 lines
Thanks, David / dhildenb
Will Deacon
maintainerQuoted 49 lines · David Hildenbrand
Quoted 48 lines · Will Deacon
Quoted 46 lines · David Hildenbrand
Quoted 30 lines · Will Deacon
Quoted 29 lines · David Hildenbrand
Quoted 28 lines · Will Deacon
Quoted 16 lines · Chris Goldsworthy
From: Sudarshan Rajagopalan <[email protected]>
After new memory blocks have been hotplugged,
max_pfnandmax_low_pfnneeds updating to reflect on new PFNs being hot added to system.Signed-off-by Sudarshan Rajagopalan <[email protected]>Signed-off-by Chris Goldsworthy <[email protected]>--- arch/arm64/mm/mmu.c | 5 +++++ 1 file changed, 5 insertions(+)arch/arm64/mm/mmu.c +0
-0arch/arm64/mm/mmu.c int arch_add_memory(int nid, u64 start, u64 size, · line 1505
Quoted 7 lines
arch/arm64/mm/mmu.c +4
-0@@ -1499,6 +1499,11 @@ int arch_add_memory(int nid, u64 start, u64 size,if (ret)__remove_pgd_mapping (swapper_pg_dir,__phys_to_virt (start), size); +else { + max_pfn =PFN_UP (start + size); + max_low_pfn = max_pfn; + }We use '
max_pfn' as part of the argument toset_max_mapnr(). Does that need updating as well?Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Do we have sufficient locking to ensure nobody is looking at
max_pfnormax_low_pfnwhile we update them?Only the write side is protected by memory hotplug locking. The read side is lockless -- just like all of the other
pfn_to_online_page()machinery.Hmm. So the readers can see one of the variables updated but the other one stale?
Yes, just like it has been on x86-64 for a long time:
arch/x86/mm/init_64.c:update_end_of_memory_vars()
Not sure if anyone really cares about slightly delayed updates while memory is getting hotplugged. The users that I am aware of don't care.
Quoted 8 lines
Quoted 5 lines
Thanks, I'd missed that x86 also updates
max_low_pfn. So at least we're not worse off in that respect.Looking at
set_max_mapnr(), I'm wondering why we need to call that at all on arm64 as 'max_mapnr' only seems to be used for nommu.I think
max_mapnris only helpful without SPARSE, I can spot the most prominent consumer being simplisticpfn_valid()implementation.
Yeah, and that's only used #ifndef CONFIG_MMU (there's a #error otherwise at the top of the file).
Quoted 3 lines
MEMORY_HOTPLUGon arm64 implies SPARSE. ... and I recall that FLATMEM is no longer possible on arm64. So most probably the arm64 call ofset_max_mapnr()can just be dropped.
I'll do that and see if anything catches fire.
Will