* [PATCH] riscv: Start of DRAM should at least be aligned on PMD size for the direct mapping
@ 2023-07-04 12:18 Alexandre Ghiti
2023-07-04 12:26 ` Conor Dooley
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Alexandre Ghiti @ 2023-07-04 12:18 UTC (permalink / raw)
To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Song Shuai, linux-riscv,
linux-kernel
Cc: Alexandre Ghiti
So that we do not end up mapping the whole linear mapping using 4K
pages, which is slow at boot time, and also very likely at runtime.
So make sure we align the start of DRAM on a PMD boundary.
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
---
arch/riscv/mm/init.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 4fa420faa780..4a43ec275c6d 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -214,8 +214,13 @@ static void __init setup_bootmem(void)
memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
phys_ram_end = memblock_end_of_DRAM();
+
+ /*
+ * Make sure we align the start of the memory on a PMD boundary so that
+ * at worst, we map the linear mapping with PMD mappings.
+ */
if (!IS_ENABLED(CONFIG_XIP_KERNEL))
- phys_ram_base = memblock_start_of_DRAM();
+ phys_ram_base = memblock_start_of_DRAM() & PMD_MASK;
/*
* In 64-bit, any use of __va/__pa before this point is wrong as we
--
2.39.2
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] riscv: Start of DRAM should at least be aligned on PMD size for the direct mapping
2023-07-04 12:18 [PATCH] riscv: Start of DRAM should at least be aligned on PMD size for the direct mapping Alexandre Ghiti
@ 2023-07-04 12:26 ` Conor Dooley
2023-07-04 13:16 ` Alexandre Ghiti
2023-07-06 17:05 ` Palmer Dabbelt
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Conor Dooley @ 2023-07-04 12:26 UTC (permalink / raw)
To: Alexandre Ghiti
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Song Shuai, linux-riscv,
linux-kernel
[-- Attachment #1.1: Type: text/plain, Size: 1404 bytes --]
Hey Alex,
On Tue, Jul 04, 2023 at 02:18:37PM +0200, Alexandre Ghiti wrote:
> So that we do not end up mapping the whole linear mapping using 4K
> pages, which is slow at boot time, and also very likely at runtime.
>
> So make sure we align the start of DRAM on a PMD boundary.
>
> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Obviously correct me if I am wrong here, but was this not reported by
Song Shuai as a regression?
Accordingly, should this not have Reported-by, Closes/Link & Fixes tags?
Cheers,
Conor.
> ---
> arch/riscv/mm/init.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index 4fa420faa780..4a43ec275c6d 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -214,8 +214,13 @@ static void __init setup_bootmem(void)
> memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
>
> phys_ram_end = memblock_end_of_DRAM();
> +
> + /*
> + * Make sure we align the start of the memory on a PMD boundary so that
> + * at worst, we map the linear mapping with PMD mappings.
> + */
> if (!IS_ENABLED(CONFIG_XIP_KERNEL))
> - phys_ram_base = memblock_start_of_DRAM();
> + phys_ram_base = memblock_start_of_DRAM() & PMD_MASK;
>
> /*
> * In 64-bit, any use of __va/__pa before this point is wrong as we
> --
> 2.39.2
>
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
[-- Attachment #2: Type: text/plain, Size: 161 bytes --]
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] riscv: Start of DRAM should at least be aligned on PMD size for the direct mapping
2023-07-04 12:26 ` Conor Dooley
@ 2023-07-04 13:16 ` Alexandre Ghiti
2023-07-05 10:19 ` Song Shuai
0 siblings, 1 reply; 8+ messages in thread
From: Alexandre Ghiti @ 2023-07-04 13:16 UTC (permalink / raw)
To: Conor Dooley
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Song Shuai, linux-riscv,
linux-kernel
On Tue, Jul 4, 2023 at 2:26 PM Conor Dooley <conor.dooley@microchip.com> wrote:
>
> Hey Alex,
>
> On Tue, Jul 04, 2023 at 02:18:37PM +0200, Alexandre Ghiti wrote:
> > So that we do not end up mapping the whole linear mapping using 4K
> > pages, which is slow at boot time, and also very likely at runtime.
> >
> > So make sure we align the start of DRAM on a PMD boundary.
> >
> > Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
>
> Obviously correct me if I am wrong here, but was this not reported by
> Song Shuai as a regression?
> Accordingly, should this not have Reported-by, Closes/Link & Fixes tags?
Sure we should add the reported by from Song as he did the proper report :)
Reported-by: Song Shuai <suagrfillet@gmail.com>
Closes: https://lore.kernel.org/linux-riscv/20230625140931.1266216-1-songshuaishuai@tinylab.org/
And yes sorry, I thought it was there before, but it was actually when
I retrieved the first 2MB that the problem appeared, so:
Fixes: 3335068f8721 ("riscv: Use PUD/P4D/PGD pages for the linear mapping")
Thanks!
>
> Cheers,
> Conor.
>
> > ---
> > arch/riscv/mm/init.c | 7 ++++++-
> > 1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> > index 4fa420faa780..4a43ec275c6d 100644
> > --- a/arch/riscv/mm/init.c
> > +++ b/arch/riscv/mm/init.c
> > @@ -214,8 +214,13 @@ static void __init setup_bootmem(void)
> > memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
> >
> > phys_ram_end = memblock_end_of_DRAM();
> > +
> > + /*
> > + * Make sure we align the start of the memory on a PMD boundary so that
> > + * at worst, we map the linear mapping with PMD mappings.
> > + */
> > if (!IS_ENABLED(CONFIG_XIP_KERNEL))
> > - phys_ram_base = memblock_start_of_DRAM();
> > + phys_ram_base = memblock_start_of_DRAM() & PMD_MASK;
> >
> > /*
> > * In 64-bit, any use of __va/__pa before this point is wrong as we
> > --
> > 2.39.2
> >
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] riscv: Start of DRAM should at least be aligned on PMD size for the direct mapping
2023-07-04 13:16 ` Alexandre Ghiti
@ 2023-07-05 10:19 ` Song Shuai
0 siblings, 0 replies; 8+ messages in thread
From: Song Shuai @ 2023-07-05 10:19 UTC (permalink / raw)
To: Alexandre Ghiti, Conor Dooley
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, linux-riscv,
linux-kernel
在 2023/7/4 21:16, Alexandre Ghiti 写道:
> On Tue, Jul 4, 2023 at 2:26 PM Conor Dooley <conor.dooley@microchip.com> wrote:
>>
>> Hey Alex,
>>
>> On Tue, Jul 04, 2023 at 02:18:37PM +0200, Alexandre Ghiti wrote:
>>> So that we do not end up mapping the whole linear mapping using 4K
>>> pages, which is slow at boot time, and also very likely at runtime.
>>>
>>> So make sure we align the start of DRAM on a PMD boundary.
>>>
>>> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
>>
>> Obviously correct me if I am wrong here, but was this not reported by
>> Song Shuai as a regression?
>> Accordingly, should this not have Reported-by, Closes/Link & Fixes tags?
>
> Sure we should add the reported by from Song as he did the proper report :)
>
> Reported-by: Song Shuai <suagrfillet@gmail.com>
> Closes: https://lore.kernel.org/linux-riscv/20230625140931.1266216-1-songshuaishuai@tinylab.org/
>
> And yes sorry, I thought it was there before, but it was actually when
> I retrieved the first 2MB that the problem appeared, so:
>
> Fixes: 3335068f8721 ("riscv: Use PUD/P4D/PGD pages for the linear mapping")
>
> Thanks!
And you can add my tested-by:
Tested-by: Song Shuai <suagrfillet@gmail.com>
>
>>
>> Cheers,
>> Conor.
>>
>>> ---
>>> arch/riscv/mm/init.c | 7 ++++++-
>>> 1 file changed, 6 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
>>> index 4fa420faa780..4a43ec275c6d 100644
>>> --- a/arch/riscv/mm/init.c
>>> +++ b/arch/riscv/mm/init.c
>>> @@ -214,8 +214,13 @@ static void __init setup_bootmem(void)
>>> memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
>>>
>>> phys_ram_end = memblock_end_of_DRAM();
>>> +
>>> + /*
>>> + * Make sure we align the start of the memory on a PMD boundary so that
>>> + * at worst, we map the linear mapping with PMD mappings.
>>> + */
>>> if (!IS_ENABLED(CONFIG_XIP_KERNEL))
>>> - phys_ram_base = memblock_start_of_DRAM();
>>> + phys_ram_base = memblock_start_of_DRAM() & PMD_MASK;
>>>
>>> /*
>>> * In 64-bit, any use of __va/__pa before this point is wrong as we
>>> --
>>> 2.39.2
>>>
--
Thanks
Song Shuai
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] riscv: Start of DRAM should at least be aligned on PMD size for the direct mapping
2023-07-04 12:18 [PATCH] riscv: Start of DRAM should at least be aligned on PMD size for the direct mapping Alexandre Ghiti
2023-07-04 12:26 ` Conor Dooley
@ 2023-07-06 17:05 ` Palmer Dabbelt
2023-07-11 10:51 ` Alexandre Ghiti
2023-08-03 14:45 ` Palmer Dabbelt
2023-08-03 15:10 ` patchwork-bot+linux-riscv
3 siblings, 1 reply; 8+ messages in thread
From: Palmer Dabbelt @ 2023-07-06 17:05 UTC (permalink / raw)
To: alexghiti
Cc: Paul Walmsley, aou, suagrfillet, linux-riscv, linux-kernel,
alexghiti
On Tue, 04 Jul 2023 05:18:37 PDT (-0700), alexghiti@rivosinc.com wrote:
> So that we do not end up mapping the whole linear mapping using 4K
> pages, which is slow at boot time, and also very likely at runtime.
>
> So make sure we align the start of DRAM on a PMD boundary.
>
> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> ---
> arch/riscv/mm/init.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index 4fa420faa780..4a43ec275c6d 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -214,8 +214,13 @@ static void __init setup_bootmem(void)
> memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
>
> phys_ram_end = memblock_end_of_DRAM();
> +
> + /*
> + * Make sure we align the start of the memory on a PMD boundary so that
> + * at worst, we map the linear mapping with PMD mappings.
> + */
> if (!IS_ENABLED(CONFIG_XIP_KERNEL))
> - phys_ram_base = memblock_start_of_DRAM();
> + phys_ram_base = memblock_start_of_DRAM() & PMD_MASK;
This rounds down, which IIUC will result in mappings outside what
memblock detected as the start af DRAM. I'd expect that to cause bad
behavior somewhere.
Shouldn't we be rounding up?
>
> /*
> * In 64-bit, any use of __va/__pa before this point is wrong as we
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] riscv: Start of DRAM should at least be aligned on PMD size for the direct mapping
2023-07-06 17:05 ` Palmer Dabbelt
@ 2023-07-11 10:51 ` Alexandre Ghiti
0 siblings, 0 replies; 8+ messages in thread
From: Alexandre Ghiti @ 2023-07-11 10:51 UTC (permalink / raw)
To: Palmer Dabbelt; +Cc: Paul Walmsley, aou, suagrfillet, linux-riscv, linux-kernel
(sorry for the delay!)
On Thu, Jul 6, 2023 at 7:05 PM Palmer Dabbelt <palmer@dabbelt.com> wrote:
>
> On Tue, 04 Jul 2023 05:18:37 PDT (-0700), alexghiti@rivosinc.com wrote:
> > So that we do not end up mapping the whole linear mapping using 4K
> > pages, which is slow at boot time, and also very likely at runtime.
> >
> > So make sure we align the start of DRAM on a PMD boundary.
> >
> > Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> > ---
> > arch/riscv/mm/init.c | 7 ++++++-
> > 1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> > index 4fa420faa780..4a43ec275c6d 100644
> > --- a/arch/riscv/mm/init.c
> > +++ b/arch/riscv/mm/init.c
> > @@ -214,8 +214,13 @@ static void __init setup_bootmem(void)
> > memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
> >
> > phys_ram_end = memblock_end_of_DRAM();
> > +
> > + /*
> > + * Make sure we align the start of the memory on a PMD boundary so that
> > + * at worst, we map the linear mapping with PMD mappings.
> > + */
> > if (!IS_ENABLED(CONFIG_XIP_KERNEL))
> > - phys_ram_base = memblock_start_of_DRAM();
> > + phys_ram_base = memblock_start_of_DRAM() & PMD_MASK;
>
> This rounds down, which IIUC will result in mappings outside what
> memblock detected as the start af DRAM. I'd expect that to cause bad
> behavior somewhere.
Actually we are not mapping this new region as it is not present in
the memblock regions, we are just re-aligning the virtual and physical
address: phys_ram_base is only used for the virtual to physical
translations.
>
> Shouldn't we be rounding up?
Doing so would remove memory from the memory map, but I'm not sure
this is correct, we could remove memory that contains "something" that
needs to be accessed using the linear mapping (ACPI tables? DT?).
More testing is welcome as I can be wrong of course.
Thanks,
Alex
>
> >
> > /*
> > * In 64-bit, any use of __va/__pa before this point is wrong as we
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] riscv: Start of DRAM should at least be aligned on PMD size for the direct mapping
2023-07-04 12:18 [PATCH] riscv: Start of DRAM should at least be aligned on PMD size for the direct mapping Alexandre Ghiti
2023-07-04 12:26 ` Conor Dooley
2023-07-06 17:05 ` Palmer Dabbelt
@ 2023-08-03 14:45 ` Palmer Dabbelt
2023-08-03 15:10 ` patchwork-bot+linux-riscv
3 siblings, 0 replies; 8+ messages in thread
From: Palmer Dabbelt @ 2023-08-03 14:45 UTC (permalink / raw)
To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Song Shuai, linux-riscv,
linux-kernel, Alexandre Ghiti
On Tue, 04 Jul 2023 14:18:37 +0200, Alexandre Ghiti wrote:
> So that we do not end up mapping the whole linear mapping using 4K
> pages, which is slow at boot time, and also very likely at runtime.
>
> So make sure we align the start of DRAM on a PMD boundary.
>
>
Applied, thanks!
[1/1] riscv: Start of DRAM should at least be aligned on PMD size for the direct mapping
https://git.kernel.org/palmer/c/9d3e8e1ff0d8
Best regards,
--
Palmer Dabbelt <palmer@rivosinc.com>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] riscv: Start of DRAM should at least be aligned on PMD size for the direct mapping
2023-07-04 12:18 [PATCH] riscv: Start of DRAM should at least be aligned on PMD size for the direct mapping Alexandre Ghiti
` (2 preceding siblings ...)
2023-08-03 14:45 ` Palmer Dabbelt
@ 2023-08-03 15:10 ` patchwork-bot+linux-riscv
3 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+linux-riscv @ 2023-08-03 15:10 UTC (permalink / raw)
To: Alexandre Ghiti
Cc: linux-riscv, paul.walmsley, palmer, aou, suagrfillet,
linux-kernel
Hello:
This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:
On Tue, 4 Jul 2023 14:18:37 +0200 you wrote:
> So that we do not end up mapping the whole linear mapping using 4K
> pages, which is slow at boot time, and also very likely at runtime.
>
> So make sure we align the start of DRAM on a PMD boundary.
>
> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
>
> [...]
Here is the summary with links:
- riscv: Start of DRAM should at least be aligned on PMD size for the direct mapping
https://git.kernel.org/riscv/c/9d3e8e1ff0d8
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-08-03 15:14 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-04 12:18 [PATCH] riscv: Start of DRAM should at least be aligned on PMD size for the direct mapping Alexandre Ghiti
2023-07-04 12:26 ` Conor Dooley
2023-07-04 13:16 ` Alexandre Ghiti
2023-07-05 10:19 ` Song Shuai
2023-07-06 17:05 ` Palmer Dabbelt
2023-07-11 10:51 ` Alexandre Ghiti
2023-08-03 14:45 ` Palmer Dabbelt
2023-08-03 15:10 ` patchwork-bot+linux-riscv
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox