[PATCH] riscv: add a warning when physical memory address overflows

Yunhui Cui posted 1 patch 1 year, 5 months ago
arch/riscv/mm/init.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
[PATCH] riscv: add a warning when physical memory address overflows
Posted by Yunhui Cui 1 year, 5 months ago
The part of physical memory that exceeds the size of the linear mapping
will be discarded. When the system starts up normally, a warning message
will be printed to prevent confusion caused by the mismatch between the
system memory and the actual physical memory.

Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
---
 arch/riscv/mm/init.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 52290c9bd04bd..c93164dc51658 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -236,8 +236,12 @@ static void __init setup_bootmem(void)
 	 */
 	if (IS_ENABLED(CONFIG_64BIT)) {
 		max_mapped_addr = __pa(PAGE_OFFSET) + KERN_VIRT_SIZE;
-		memblock_cap_memory_range(phys_ram_base,
-					  max_mapped_addr - phys_ram_base);
+		if (memblock_end_of_DRAM() > max_mapped_addr) {
+			memblock_cap_memory_range(phys_ram_base,
+						  max_mapped_addr - phys_ram_base);
+			pr_warn("Physical memory overflows the linear mapping size: region above 0x%llx removed",
+				max_mapped_addr);
+		}
 	}
 
 
-- 
2.39.2
Re: [PATCH] riscv: add a warning when physical memory address overflows
Posted by Alexandre Ghiti 1 year, 5 months ago
Hi Yunhui,

On 14/08/2024 08:26, Yunhui Cui wrote:
> The part of physical memory that exceeds the size of the linear mapping
> will be discarded. When the system starts up normally, a warning message
> will be printed to prevent confusion caused by the mismatch between the
> system memory and the actual physical memory.
>
> Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
> ---
>   arch/riscv/mm/init.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index 52290c9bd04bd..c93164dc51658 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -236,8 +236,12 @@ static void __init setup_bootmem(void)
>   	 */
>   	if (IS_ENABLED(CONFIG_64BIT)) {
>   		max_mapped_addr = __pa(PAGE_OFFSET) + KERN_VIRT_SIZE;
> -		memblock_cap_memory_range(phys_ram_base,
> -					  max_mapped_addr - phys_ram_base);
> +		if (memblock_end_of_DRAM() > max_mapped_addr) {
> +			memblock_cap_memory_range(phys_ram_base,
> +						  max_mapped_addr - phys_ram_base);
> +			pr_warn("Physical memory overflows the linear mapping size: region above 0x%llx removed",
> +				max_mapped_addr);
> +		}
>   	}
>   
>   


A bit weird to review and test my own patch, but here it is anyway :)

Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>

Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com>

Thanks,

Alex
Re: [External] Re: [PATCH] riscv: add a warning when physical memory address overflows
Posted by yunhui cui 1 year, 4 months ago
Hi Palmer,

A gentle ping for this patch.

On Thu, Aug 15, 2024 at 7:01 PM Alexandre Ghiti <alex@ghiti.fr> wrote:
>
> Hi Yunhui,
>
> On 14/08/2024 08:26, Yunhui Cui wrote:
> > The part of physical memory that exceeds the size of the linear mapping
> > will be discarded. When the system starts up normally, a warning message
> > will be printed to prevent confusion caused by the mismatch between the
> > system memory and the actual physical memory.
> >
> > Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
> > ---
> >   arch/riscv/mm/init.c | 8 ++++++--
> >   1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> > index 52290c9bd04bd..c93164dc51658 100644
> > --- a/arch/riscv/mm/init.c
> > +++ b/arch/riscv/mm/init.c
> > @@ -236,8 +236,12 @@ static void __init setup_bootmem(void)
> >        */
> >       if (IS_ENABLED(CONFIG_64BIT)) {
> >               max_mapped_addr = __pa(PAGE_OFFSET) + KERN_VIRT_SIZE;
> > -             memblock_cap_memory_range(phys_ram_base,
> > -                                       max_mapped_addr - phys_ram_base);
> > +             if (memblock_end_of_DRAM() > max_mapped_addr) {
> > +                     memblock_cap_memory_range(phys_ram_base,
> > +                                               max_mapped_addr - phys_ram_base);
> > +                     pr_warn("Physical memory overflows the linear mapping size: region above 0x%llx removed",
> > +                             max_mapped_addr);
> > +             }
> >       }
> >
> >
>
>
> A bit weird to review and test my own patch, but here it is anyway :)
>
> Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
>
> Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com>
>
> Thanks,
>
> Alex
>

Thanks,
Yunhui
Re: [External] Re: [PATCH] riscv: add a warning when physical memory address overflows
Posted by Punit Agrawal 1 year, 3 months ago
Hi Palmer,

[...]

>> On 14/08/2024 08:26, Yunhui Cui wrote:
>> > The part of physical memory that exceeds the size of the linear mapping
>> > will be discarded. When the system starts up normally, a warning message
>> > will be printed to prevent confusion caused by the mismatch between the
>> > system memory and the actual physical memory.
>> >
>> > Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
>> > ---
>> >   arch/riscv/mm/init.c | 8 ++++++--
>> >   1 file changed, 6 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
>> > index 52290c9bd04bd..c93164dc51658 100644
>> > --- a/arch/riscv/mm/init.c
>> > +++ b/arch/riscv/mm/init.c
>> > @@ -236,8 +236,12 @@ static void __init setup_bootmem(void)
>> >        */
>> >       if (IS_ENABLED(CONFIG_64BIT)) {
>> >               max_mapped_addr = __pa(PAGE_OFFSET) + KERN_VIRT_SIZE;
>> > -             memblock_cap_memory_range(phys_ram_base,
>> > -                                       max_mapped_addr - phys_ram_base);
>> > +             if (memblock_end_of_DRAM() > max_mapped_addr) {
>> > +                     memblock_cap_memory_range(phys_ram_base,
>> > +                                               max_mapped_addr - phys_ram_base);
>> > +                     pr_warn("Physical memory overflows the linear mapping size: region above 0x%llx removed",
>> > +                             max_mapped_addr);
>> > +             }
>> >       }
>> >
>> >
>>
>>
>> A bit weird to review and test my own patch, but here it is anyway :)
>>
>> Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
>>
>> Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com>

Looks like the patch has been ready for a while now. If there are no
further problems, can it be merged please?

[...]
Re: [External] Re: [PATCH] riscv: add a warning when physical memory address overflows
Posted by Palmer Dabbelt 1 year ago
On Wed, 23 Oct 2024 07:25:22 PDT (-0700), punit.agrawal@bytedance.com wrote:
> Hi Palmer,
>
> [...]
>
>>> On 14/08/2024 08:26, Yunhui Cui wrote:
>>> > The part of physical memory that exceeds the size of the linear mapping
>>> > will be discarded. When the system starts up normally, a warning message
>>> > will be printed to prevent confusion caused by the mismatch between the
>>> > system memory and the actual physical memory.
>>> >
>>> > Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
>>> > ---
>>> >   arch/riscv/mm/init.c | 8 ++++++--
>>> >   1 file changed, 6 insertions(+), 2 deletions(-)
>>> >
>>> > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
>>> > index 52290c9bd04bd..c93164dc51658 100644
>>> > --- a/arch/riscv/mm/init.c
>>> > +++ b/arch/riscv/mm/init.c
>>> > @@ -236,8 +236,12 @@ static void __init setup_bootmem(void)
>>> >        */
>>> >       if (IS_ENABLED(CONFIG_64BIT)) {
>>> >               max_mapped_addr = __pa(PAGE_OFFSET) + KERN_VIRT_SIZE;
>>> > -             memblock_cap_memory_range(phys_ram_base,
>>> > -                                       max_mapped_addr - phys_ram_base);
>>> > +             if (memblock_end_of_DRAM() > max_mapped_addr) {
>>> > +                     memblock_cap_memory_range(phys_ram_base,
>>> > +                                               max_mapped_addr - phys_ram_base);
>>> > +                     pr_warn("Physical memory overflows the linear mapping size: region above 0x%llx removed",
>>> > +                             max_mapped_addr);
>>> > +             }
>>> >       }
>>> >
>>> >
>>>
>>>
>>> A bit weird to review and test my own patch, but here it is anyway :)
>>>
>>> Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
>>>
>>> Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com>
>
> Looks like the patch has been ready for a while now. If there are no
> further problems, can it be merged please?

It didn't build, I squashed in a 

diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 8f8b76aaf99a..9641e4ad387f 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -259,8 +259,8 @@ static void __init setup_bootmem(void)
 		if (memblock_end_of_DRAM() > max_mapped_addr) {
 			memblock_cap_memory_range(phys_ram_base,
 						  max_mapped_addr - phys_ram_base);
-			pr_warn("Physical memory overflows the linear mapping size: region above 0x%llx removed",
-				max_mapped_addr);
+			pr_warn("Physical memory overflows the linear mapping size: region above %pa removed",
+				&max_mapped_addr);
 		}
 	}

to fix it.


>
> [...]