LoongArch: numa: Fix high_memory calculation

Message ID 20230926121031.1901760-1-chenhuacai@loongson.cn
State New
Headers
Series LoongArch: numa: Fix high_memory calculation |

Commit Message

Huacai Chen Sept. 26, 2023, 12:10 p.m. UTC
  high_memory is the virtual address of the 'highest physical address' in
the system. But __va(get_num_physpages() << PAGE_SHIFT) is not what we
want because there may be holes in the physical address space. On the
other hand, max_low_pfn is calculated from memblock_end_of_DRAM(), which
is exactly corresponding to the highest physical address, so use it for
high_memory calculation.

Cc: <stable@vger.kernel.org>
Signed-off-by: Chong Qiao <qiaochong@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
---
 arch/loongarch/kernel/numa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

WANG Xuerui Sept. 26, 2023, 3:26 p.m. UTC | #1
On 9/26/23 20:10, Huacai Chen wrote:
> high_memory is the virtual address of the 'highest physical address' in
> the system. But __va(get_num_physpages() << PAGE_SHIFT) is not what we
> want because there may be holes in the physical address space. On the
> other hand, max_low_pfn is calculated from memblock_end_of_DRAM(), which
> is exactly corresponding to the highest physical address, so use it for
> high_memory calculation.
>
> Cc: <stable@vger.kernel.org>
Which commit is this patch intended to amend? A "Fixes:" tag may be 
helpful for stable backporting.
> Signed-off-by: Chong Qiao <qiaochong@loongson.cn>
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
>   arch/loongarch/kernel/numa.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/loongarch/kernel/numa.c b/arch/loongarch/kernel/numa.c
> index c7d33c489e04..6e65ff12d5c7 100644
> --- a/arch/loongarch/kernel/numa.c
> +++ b/arch/loongarch/kernel/numa.c
> @@ -436,7 +436,7 @@ void __init paging_init(void)
>   
>   void __init mem_init(void)
>   {
> -	high_memory = (void *) __va(get_num_physpages() << PAGE_SHIFT);
> +	high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
>   	memblock_free_all();
>   }
>
  
Huacai Chen Sept. 27, 2023, 12:45 a.m. UTC | #2
On Tue, Sep 26, 2023 at 11:26 PM WANG Xuerui <kernel@xen0n.name> wrote:
>
> On 9/26/23 20:10, Huacai Chen wrote:
> > high_memory is the virtual address of the 'highest physical address' in
> > the system. But __va(get_num_physpages() << PAGE_SHIFT) is not what we
> > want because there may be holes in the physical address space. On the
> > other hand, max_low_pfn is calculated from memblock_end_of_DRAM(), which
> > is exactly corresponding to the highest physical address, so use it for
> > high_memory calculation.
> >
> > Cc: <stable@vger.kernel.org>
> Which commit is this patch intended to amend? A "Fixes:" tag may be
> helpful for stable backporting.
OK, I will add a Fixes: tag.

Huacai

> > Signed-off-by: Chong Qiao <qiaochong@loongson.cn>
> > Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> > ---
> >   arch/loongarch/kernel/numa.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/loongarch/kernel/numa.c b/arch/loongarch/kernel/numa.c
> > index c7d33c489e04..6e65ff12d5c7 100644
> > --- a/arch/loongarch/kernel/numa.c
> > +++ b/arch/loongarch/kernel/numa.c
> > @@ -436,7 +436,7 @@ void __init paging_init(void)
> >
> >   void __init mem_init(void)
> >   {
> > -     high_memory = (void *) __va(get_num_physpages() << PAGE_SHIFT);
> > +     high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
> >       memblock_free_all();
> >   }
> >
>
> --
> WANG "xen0n" Xuerui
>
> Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
>
  

Patch

diff --git a/arch/loongarch/kernel/numa.c b/arch/loongarch/kernel/numa.c
index c7d33c489e04..6e65ff12d5c7 100644
--- a/arch/loongarch/kernel/numa.c
+++ b/arch/loongarch/kernel/numa.c
@@ -436,7 +436,7 @@  void __init paging_init(void)
 
 void __init mem_init(void)
 {
-	high_memory = (void *) __va(get_num_physpages() << PAGE_SHIFT);
+	high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
 	memblock_free_all();
 }