linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] arm64: mm: update max_pfn after memory hotplug
@ 2021-09-23 22:54 Chris Goldsworthy
  2021-09-23 22:54 ` Chris Goldsworthy
  0 siblings, 1 reply; 20+ messages in thread
From: Chris Goldsworthy @ 2021-09-23 22:54 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Andrew Morton
  Cc: David Hildenbrand, linux-arm-kernel, linux-kernel, linux-mm,
	Chris Goldsworthy

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(+)

-- 
2.7.4


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-23 22:54 [RFC] arm64: mm: update max_pfn after memory hotplug Chris Goldsworthy
@ 2021-09-23 22:54 ` Chris Goldsworthy
  2021-09-24  2:47   ` Florian Fainelli
                     ` (3 more replies)
  0 siblings, 4 replies; 20+ messages in thread
From: Chris Goldsworthy @ 2021-09-23 22:54 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Andrew Morton
  Cc: David Hildenbrand, linux-arm-kernel, linux-kernel, linux-mm,
	Sudarshan Rajagopalan, Chris Goldsworthy

From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>

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.

Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>
---
 arch/arm64/mm/mmu.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index cfd9deb..fd85b51 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -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;
 }
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-23 22:54 ` Chris Goldsworthy
@ 2021-09-24  2:47   ` Florian Fainelli
  2021-09-24  8:17     ` David Hildenbrand
  2021-09-27 15:51   ` David Hildenbrand
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 20+ messages in thread
From: Florian Fainelli @ 2021-09-24  2:47 UTC (permalink / raw)
  To: Chris Goldsworthy, Catalin Marinas, Will Deacon, Andrew Morton
  Cc: David Hildenbrand, linux-arm-kernel, linux-kernel, linux-mm,
	Sudarshan Rajagopalan, Doug Berger



On 9/23/2021 3:54 PM, Chris Goldsworthy wrote:
> From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
> 
> 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.
> 
> Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
> Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>
> ---
>   arch/arm64/mm/mmu.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> index cfd9deb..fd85b51 100644
> --- a/arch/arm64/mm/mmu.c
> +++ b/arch/arm64/mm/mmu.c
> @@ -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?
-- 
Florian

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-24  2:47   ` Florian Fainelli
@ 2021-09-24  8:17     ` David Hildenbrand
  2021-09-24 20:52       ` Chris Goldsworthy
  0 siblings, 1 reply; 20+ messages in thread
From: David Hildenbrand @ 2021-09-24  8:17 UTC (permalink / raw)
  To: Florian Fainelli, Chris Goldsworthy, Catalin Marinas,
	Will Deacon, Andrew Morton
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Sudarshan Rajagopalan,
	Doug Berger

On 24.09.21 04:47, Florian Fainelli wrote:
> 
> 
> On 9/23/2021 3:54 PM, Chris Goldsworthy wrote:
>> From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>>
>> 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.
>>
>> Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>> Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>
>> ---
>>    arch/arm64/mm/mmu.c | 5 +++++
>>    1 file changed, 5 insertions(+)
>>
>> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
>> index cfd9deb..fd85b51 100644
>> --- a/arch/arm64/mm/mmu.c
>> +++ b/arch/arm64/mm/mmu.c
>> @@ -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?

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.

> 
> - 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".

> 
> - 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?

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.

-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-24  8:17     ` David Hildenbrand
@ 2021-09-24 20:52       ` Chris Goldsworthy
  0 siblings, 0 replies; 20+ messages in thread
From: Chris Goldsworthy @ 2021-09-24 20:52 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Florian Fainelli, Chris Goldsworthy, Catalin Marinas,
	Will Deacon, Andrew Morton, linux-arm-kernel, linux-kernel,
	linux-mm, Sudarshan Rajagopalan, Doug Berger


Thanks for the response David.

On Fri, Sep 24, 2021 at 10:17:46AM +0200, David Hildenbrand wrote:
> 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().

> 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.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-23 22:54 ` Chris Goldsworthy
  2021-09-24  2:47   ` Florian Fainelli
@ 2021-09-27 15:51   ` David Hildenbrand
  2021-09-27 23:22     ` Georgi Djakov
  2021-09-27 17:22   ` Georgi Djakov
  2021-09-29 10:10   ` Will Deacon
  3 siblings, 1 reply; 20+ messages in thread
From: David Hildenbrand @ 2021-09-27 15:51 UTC (permalink / raw)
  To: Chris Goldsworthy, Catalin Marinas, Will Deacon, Andrew Morton
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Sudarshan Rajagopalan

On 24.09.21 00:54, Chris Goldsworthy wrote:
> From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
> 
> 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.
> 
> Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
> Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>
> ---
>   arch/arm64/mm/mmu.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> index cfd9deb..fd85b51 100644
> --- a/arch/arm64/mm/mmu.c
> +++ b/arch/arm64/mm/mmu.c
> @@ -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.

Acked-by: David Hildenbrand <david@redhat.com>


-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-23 22:54 ` Chris Goldsworthy
  2021-09-24  2:47   ` Florian Fainelli
  2021-09-27 15:51   ` David Hildenbrand
@ 2021-09-27 17:22   ` Georgi Djakov
  2021-09-27 17:34     ` David Hildenbrand
  2021-09-29 10:10   ` Will Deacon
  3 siblings, 1 reply; 20+ messages in thread
From: Georgi Djakov @ 2021-09-27 17:22 UTC (permalink / raw)
  To: Chris Goldsworthy, Catalin Marinas, Will Deacon, Andrew Morton
  Cc: David Hildenbrand, linux-arm-kernel, linux-kernel, linux-mm,
	Sudarshan Rajagopalan

On 9/24/2021 1:54 AM, Chris Goldsworthy wrote:
> From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
> 
> 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.
> 
> Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
> Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>

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.

Tested-by: Georgi Djakov <quic_c_gdjako@quicinc.com>

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 section 
and fix end detection")

Thanks,
Georgi

> ---
>   arch/arm64/mm/mmu.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> index cfd9deb..fd85b51 100644
> --- a/arch/arm64/mm/mmu.c
> +++ b/arch/arm64/mm/mmu.c
> @@ -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;
>   }
>   
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-27 17:22   ` Georgi Djakov
@ 2021-09-27 17:34     ` David Hildenbrand
  2021-09-27 20:00       ` Georgi Djakov
  0 siblings, 1 reply; 20+ messages in thread
From: David Hildenbrand @ 2021-09-27 17:34 UTC (permalink / raw)
  To: Georgi Djakov, Chris Goldsworthy, Catalin Marinas, Will Deacon,
	Andrew Morton
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Sudarshan Rajagopalan

On 27.09.21 19:22, Georgi Djakov wrote:
> On 9/24/2021 1:54 AM, Chris Goldsworthy wrote:
>> From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>>
>> 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.
>>
>> Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>> Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>
> 
> 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.
> 
> Tested-by: Georgi Djakov <quic_c_gdjako@quicinc.com>
> 
> 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 section
> and 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.

-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-27 17:34     ` David Hildenbrand
@ 2021-09-27 20:00       ` Georgi Djakov
  2021-09-27 20:14         ` David Hildenbrand
  0 siblings, 1 reply; 20+ messages in thread
From: Georgi Djakov @ 2021-09-27 20:00 UTC (permalink / raw)
  To: David Hildenbrand, Chris Goldsworthy, Catalin Marinas,
	Will Deacon, Andrew Morton
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Sudarshan Rajagopalan

On 9/27/2021 8:34 PM, David Hildenbrand wrote:
> On 27.09.21 19:22, Georgi Djakov wrote:
>> On 9/24/2021 1:54 AM, Chris Goldsworthy wrote:
>>> From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>>>
>>> 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.
>>>
>>> Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>>> Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>
>>
>> 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.
>>
>> Tested-by: Georgi Djakov <quic_c_gdjako@quicinc.com>
>>
>> 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 section
>> and 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;

> 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

> 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

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-27 20:00       ` Georgi Djakov
@ 2021-09-27 20:14         ` David Hildenbrand
  0 siblings, 0 replies; 20+ messages in thread
From: David Hildenbrand @ 2021-09-27 20:14 UTC (permalink / raw)
  To: Georgi Djakov, Chris Goldsworthy, Catalin Marinas, Will Deacon,
	Andrew Morton
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Sudarshan Rajagopalan

On 27.09.21 22:00, Georgi Djakov wrote:
> On 9/27/2021 8:34 PM, David Hildenbrand wrote:
>> On 27.09.21 19:22, Georgi Djakov wrote:
>>> On 9/24/2021 1:54 AM, Chris Goldsworthy wrote:
>>>> From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>>>>
>>>> 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.
>>>>
>>>> Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>>>> Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>
>>>
>>> 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.
>>>
>>> Tested-by: Georgi Djakov <quic_c_gdjako@quicinc.com>
>>>
>>> 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 section
>>> and 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;
> 
>> 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.

-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-27 15:51   ` David Hildenbrand
@ 2021-09-27 23:22     ` Georgi Djakov
  2021-09-28  6:12       ` Chris Goldsworthy
  0 siblings, 1 reply; 20+ messages in thread
From: Georgi Djakov @ 2021-09-27 23:22 UTC (permalink / raw)
  To: David Hildenbrand, Chris Goldsworthy, Catalin Marinas,
	Will Deacon, Andrew Morton
  Cc: linux-arm-kernel, linux-kernel, linux-mm, Sudarshan Rajagopalan

On 9/27/2021 6:51 PM, David Hildenbrand wrote:
> On 24.09.21 00:54, Chris Goldsworthy wrote:
>> From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>>
>> 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.
>>
>> Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>> Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>
>> ---
>>   arch/arm64/mm/mmu.c | 5 +++++
>>   1 file changed, 5 insertions(+)
>>
>> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
>> index cfd9deb..fd85b51 100644
>> --- a/arch/arm64/mm/mmu.c
>> +++ b/arch/arm64/mm/mmu.c
>> @@ -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.

My understanding is that max_low_pfn defines the low/high memory
boundary and it should be also updated.

Thanks,
Georgi

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-27 23:22     ` Georgi Djakov
@ 2021-09-28  6:12       ` Chris Goldsworthy
  2021-09-28  7:33         ` David Hildenbrand
  0 siblings, 1 reply; 20+ messages in thread
From: Chris Goldsworthy @ 2021-09-28  6:12 UTC (permalink / raw)
  To: Georgi Djakov
  Cc: David Hildenbrand, Chris Goldsworthy, Catalin Marinas,
	Will Deacon, Andrew Morton, linux-arm-kernel, linux-kernel,
	linux-mm, Sudarshan Rajagopalan

On Tue, Sep 28, 2021 at 02:22:59AM +0300, Georgi Djakov wrote:
> On 9/27/2021 6:51 PM, David Hildenbrand wrote:
> >On 24.09.21 00:54, Chris Goldsworthy wrote:
> >>From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
> >>
> >>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.
> >>
> >>Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
> >>Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>
> >>---
> >>  arch/arm64/mm/mmu.c | 5 +++++
> >>  1 file changed, 5 insertions(+)
> >>
> >>diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> >>index cfd9deb..fd85b51 100644
> >>--- a/arch/arm64/mm/mmu.c
> >>+++ b/arch/arm64/mm/mmu.c
> >>@@ -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.
> 
> My understanding is that max_low_pfn defines 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:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c1cc1552616d0f354d040823151e61634e7ad01f

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-28  6:12       ` Chris Goldsworthy
@ 2021-09-28  7:33         ` David Hildenbrand
  0 siblings, 0 replies; 20+ messages in thread
From: David Hildenbrand @ 2021-09-28  7:33 UTC (permalink / raw)
  To: Chris Goldsworthy, Georgi Djakov
  Cc: Catalin Marinas, Will Deacon, Andrew Morton, linux-arm-kernel,
	linux-kernel, linux-mm, Sudarshan Rajagopalan

On 28.09.21 08:12, Chris Goldsworthy wrote:
> On Tue, Sep 28, 2021 at 02:22:59AM +0300, Georgi Djakov wrote:
>> On 9/27/2021 6:51 PM, David Hildenbrand wrote:
>>> On 24.09.21 00:54, Chris Goldsworthy wrote:
>>>> From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>>>>
>>>> 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.
>>>>
>>>> Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>>>> Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>
>>>> ---
>>>>    arch/arm64/mm/mmu.c | 5 +++++
>>>>    1 file changed, 5 insertions(+)
>>>>
>>>> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
>>>> index cfd9deb..fd85b51 100644
>>>> --- a/arch/arm64/mm/mmu.c
>>>> +++ b/arch/arm64/mm/mmu.c
>>>> @@ -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.
>>
>> My understanding is that max_low_pfn defines 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:

Makes sense to me, thanks.


-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-23 22:54 ` Chris Goldsworthy
                     ` (2 preceding siblings ...)
  2021-09-27 17:22   ` Georgi Djakov
@ 2021-09-29 10:10   ` Will Deacon
  2021-09-29 10:29     ` David Hildenbrand
  3 siblings, 1 reply; 20+ messages in thread
From: Will Deacon @ 2021-09-29 10:10 UTC (permalink / raw)
  To: Chris Goldsworthy
  Cc: Catalin Marinas, Andrew Morton, David Hildenbrand,
	linux-arm-kernel, linux-kernel, linux-mm, Sudarshan Rajagopalan

On Thu, Sep 23, 2021 at 03:54:48PM -0700, Chris Goldsworthy wrote:
> From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
> 
> 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.
> 
> Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
> Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>
> ---
>  arch/arm64/mm/mmu.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> index cfd9deb..fd85b51 100644
> --- a/arch/arm64/mm/mmu.c
> +++ b/arch/arm64/mm/mmu.c
> @@ -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

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-29 10:10   ` Will Deacon
@ 2021-09-29 10:29     ` David Hildenbrand
  2021-09-29 10:42       ` Will Deacon
  0 siblings, 1 reply; 20+ messages in thread
From: David Hildenbrand @ 2021-09-29 10:29 UTC (permalink / raw)
  To: Will Deacon, Chris Goldsworthy
  Cc: Catalin Marinas, Andrew Morton, linux-arm-kernel, linux-kernel,
	linux-mm, Sudarshan Rajagopalan

On 29.09.21 12:10, Will Deacon wrote:
> On Thu, Sep 23, 2021 at 03:54:48PM -0700, Chris Goldsworthy wrote:
>> From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>>
>> 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.
>>
>> Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>> Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>
>> ---
>>   arch/arm64/mm/mmu.c | 5 +++++
>>   1 file changed, 5 insertions(+)
>>
>> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
>> index cfd9deb..fd85b51 100644
>> --- a/arch/arm64/mm/mmu.c
>> +++ b/arch/arm64/mm/mmu.c
>> @@ -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?

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.

> 
> Will
> 


-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-29 10:29     ` David Hildenbrand
@ 2021-09-29 10:42       ` Will Deacon
  2021-09-29 10:49         ` David Hildenbrand
  0 siblings, 1 reply; 20+ messages in thread
From: Will Deacon @ 2021-09-29 10:42 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Chris Goldsworthy, Catalin Marinas, Andrew Morton,
	linux-arm-kernel, linux-kernel, linux-mm, Sudarshan Rajagopalan

On Wed, Sep 29, 2021 at 12:29:32PM +0200, David Hildenbrand wrote:
> On 29.09.21 12:10, Will Deacon wrote:
> > On Thu, Sep 23, 2021 at 03:54:48PM -0700, Chris Goldsworthy wrote:
> > > From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
> > > 
> > > 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.
> > > 
> > > Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
> > > Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>
> > > ---
> > >   arch/arm64/mm/mmu.c | 5 +++++
> > >   1 file changed, 5 insertions(+)
> > > 
> > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> > > index cfd9deb..fd85b51 100644
> > > --- a/arch/arm64/mm/mmu.c
> > > +++ b/arch/arm64/mm/mmu.c
> > > @@ -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?
> 
> 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

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-29 10:42       ` Will Deacon
@ 2021-09-29 10:49         ` David Hildenbrand
  2021-09-29 11:03           ` Will Deacon
  0 siblings, 1 reply; 20+ messages in thread
From: David Hildenbrand @ 2021-09-29 10:49 UTC (permalink / raw)
  To: Will Deacon
  Cc: Chris Goldsworthy, Catalin Marinas, Andrew Morton,
	linux-arm-kernel, linux-kernel, linux-mm, Sudarshan Rajagopalan

On 29.09.21 12:42, Will Deacon wrote:
> On Wed, Sep 29, 2021 at 12:29:32PM +0200, David Hildenbrand wrote:
>> On 29.09.21 12:10, Will Deacon wrote:
>>> On Thu, Sep 23, 2021 at 03:54:48PM -0700, Chris Goldsworthy wrote:
>>>> From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>>>>
>>>> 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.
>>>>
>>>> Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>>>> Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>
>>>> ---
>>>>    arch/arm64/mm/mmu.c | 5 +++++
>>>>    1 file changed, 5 insertions(+)
>>>>
>>>> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
>>>> index cfd9deb..fd85b51 100644
>>>> --- a/arch/arm64/mm/mmu.c
>>>> +++ b/arch/arm64/mm/mmu.c
>>>> @@ -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?
>>
>> 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.

-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-29 10:49         ` David Hildenbrand
@ 2021-09-29 11:03           ` Will Deacon
  2021-09-29 12:09             ` David Hildenbrand
  0 siblings, 1 reply; 20+ messages in thread
From: Will Deacon @ 2021-09-29 11:03 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Chris Goldsworthy, Catalin Marinas, Andrew Morton,
	linux-arm-kernel, linux-kernel, linux-mm, Sudarshan Rajagopalan

On Wed, Sep 29, 2021 at 12:49:58PM +0200, David Hildenbrand wrote:
> On 29.09.21 12:42, Will Deacon wrote:
> > On Wed, Sep 29, 2021 at 12:29:32PM +0200, David Hildenbrand wrote:
> > > On 29.09.21 12:10, Will Deacon wrote:
> > > > On Thu, Sep 23, 2021 at 03:54:48PM -0700, Chris Goldsworthy wrote:
> > > > > From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
> > > > > 
> > > > > 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.
> > > > > 
> > > > > Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
> > > > > Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>
> > > > > ---
> > > > >    arch/arm64/mm/mmu.c | 5 +++++
> > > > >    1 file changed, 5 insertions(+)
> > > > > 
> > > > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> > > > > index cfd9deb..fd85b51 100644
> > > > > --- a/arch/arm64/mm/mmu.c
> > > > > +++ b/arch/arm64/mm/mmu.c
> > > > > @@ -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?
> > > 
> > > 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.

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

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-29 11:03           ` Will Deacon
@ 2021-09-29 12:09             ` David Hildenbrand
  2021-09-29 12:51               ` Will Deacon
  0 siblings, 1 reply; 20+ messages in thread
From: David Hildenbrand @ 2021-09-29 12:09 UTC (permalink / raw)
  To: Will Deacon
  Cc: Chris Goldsworthy, Catalin Marinas, Andrew Morton,
	linux-arm-kernel, linux-kernel, linux-mm, Sudarshan Rajagopalan

On 29.09.21 13:03, Will Deacon wrote:
> On Wed, Sep 29, 2021 at 12:49:58PM +0200, David Hildenbrand wrote:
>> On 29.09.21 12:42, Will Deacon wrote:
>>> On Wed, Sep 29, 2021 at 12:29:32PM +0200, David Hildenbrand wrote:
>>>> On 29.09.21 12:10, Will Deacon wrote:
>>>>> On Thu, Sep 23, 2021 at 03:54:48PM -0700, Chris Goldsworthy wrote:
>>>>>> From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>>>>>>
>>>>>> 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.
>>>>>>
>>>>>> Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
>>>>>> Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>
>>>>>> ---
>>>>>>     arch/arm64/mm/mmu.c | 5 +++++
>>>>>>     1 file changed, 5 insertions(+)
>>>>>>
>>>>>> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
>>>>>> index cfd9deb..fd85b51 100644
>>>>>> --- a/arch/arm64/mm/mmu.c
>>>>>> +++ b/arch/arm64/mm/mmu.c
>>>>>> @@ -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?
>>>>
>>>> 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.
> 
> 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.

-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] arm64: mm: update max_pfn after memory hotplug
  2021-09-29 12:09             ` David Hildenbrand
@ 2021-09-29 12:51               ` Will Deacon
  0 siblings, 0 replies; 20+ messages in thread
From: Will Deacon @ 2021-09-29 12:51 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Chris Goldsworthy, Catalin Marinas, Andrew Morton,
	linux-arm-kernel, linux-kernel, linux-mm, Sudarshan Rajagopalan

On Wed, Sep 29, 2021 at 02:09:35PM +0200, David Hildenbrand wrote:
> On 29.09.21 13:03, Will Deacon wrote:
> > On Wed, Sep 29, 2021 at 12:49:58PM +0200, David Hildenbrand wrote:
> > > On 29.09.21 12:42, Will Deacon wrote:
> > > > On Wed, Sep 29, 2021 at 12:29:32PM +0200, David Hildenbrand wrote:
> > > > > On 29.09.21 12:10, Will Deacon wrote:
> > > > > > On Thu, Sep 23, 2021 at 03:54:48PM -0700, Chris Goldsworthy wrote:
> > > > > > > From: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
> > > > > > > 
> > > > > > > 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.
> > > > > > > 
> > > > > > > Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
> > > > > > > Signed-off-by: Chris Goldsworthy <quic_cgoldswo@quicinc.com>
> > > > > > > ---
> > > > > > >     arch/arm64/mm/mmu.c | 5 +++++
> > > > > > >     1 file changed, 5 insertions(+)
> > > > > > > 
> > > > > > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> > > > > > > index cfd9deb..fd85b51 100644
> > > > > > > --- a/arch/arm64/mm/mmu.c
> > > > > > > +++ b/arch/arm64/mm/mmu.c
> > > > > > > @@ -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?
> > > > > 
> > > > > 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.
> > 
> > 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.

Yeah, and that's only used #ifndef CONFIG_MMU (there's a #error otherwise at
the top of the file).

> 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.

I'll do that and see if anything catches fire.

Will

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2021-09-29 12:51 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-23 22:54 [RFC] arm64: mm: update max_pfn after memory hotplug Chris Goldsworthy
2021-09-23 22:54 ` Chris Goldsworthy
2021-09-24  2:47   ` Florian Fainelli
2021-09-24  8:17     ` David Hildenbrand
2021-09-24 20:52       ` Chris Goldsworthy
2021-09-27 15:51   ` David Hildenbrand
2021-09-27 23:22     ` Georgi Djakov
2021-09-28  6:12       ` Chris Goldsworthy
2021-09-28  7:33         ` David Hildenbrand
2021-09-27 17:22   ` Georgi Djakov
2021-09-27 17:34     ` David Hildenbrand
2021-09-27 20:00       ` Georgi Djakov
2021-09-27 20:14         ` David Hildenbrand
2021-09-29 10:10   ` Will Deacon
2021-09-29 10:29     ` David Hildenbrand
2021-09-29 10:42       ` Will Deacon
2021-09-29 10:49         ` David Hildenbrand
2021-09-29 11:03           ` Will Deacon
2021-09-29 12:09             ` David Hildenbrand
2021-09-29 12:51               ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).