Skip to contentSkip to conversation

riscv: Fixup one-page wasting

PATCH In review [email protected] 2 participants 5 messages Nov 24, 2021

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 riscv: Fixup one-page wasting

From: Guo Ren <[email protected]>

For small memory systems(Allwinner D1s/F133), one page size memory cannot be ignored.

Cc Alexandre Ghiti <[email protected]>
Cc Anup Patel <[email protected]>
Cc Atish Patra <[email protected]>
---
 arch/riscv/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/mm/init.c +1 -1
index 24b2b8044602..097bb3bc4020 100644
@@ -241,9 +241,9 @@ unsigned long riscv_pfn_base __ro_after_init;
 EXPORT_SYMBOL(riscv_pfn_base);
 
 pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
-pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
 static pte_t fixmap_pte[PTRS_PER_PTE] __page_aligned_bss;
 
+pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
 pgd_t early_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
 static pmd_t __maybe_unused early_dtb_pmd[PTRS_PER_PMD] __initdata __aligned(PAGE_SIZE);
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 10 lines · On Wed, Nov 24, 2021 at 11:35 AM <[email protected]> wrote:

From: Guo Ren <[email protected]>

For small memory systems(Allwinner D1s/F133), one page size memory cannot be ignored.

Cc Alexandre Ghiti <[email protected]>
Cc Anup Patel <[email protected]>
Cc Atish Patra <[email protected]>

This PATCH breaks the CPU hotplug functionality.

When a CPU/HART is turned off and turned on at runtime, the low-level relocate() will be called to enable MMU on the CPU being brought-up which in-turn uses trampoline_pg_dir.

Regards,
Anup

Quoted 22 lines
---
 arch/riscv/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/mm/init.c +1 -2
index 24b2b8044602..097bb3bc4020 100644
@@ -241,9 +241,9 @@ unsigned long riscv_pfn_base __ro_after_init;
 EXPORT_SYMBOL(riscv_pfn_base);
 
 pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
-pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
 static pte_t fixmap_pte[PTRS_PER_PTE] __page_aligned_bss;
 
+pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
 pgd_t early_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
 static pmd_t __maybe_unused early_dtb_pmd[PTRS_PER_PMD] __initdata __aligned(PAGE_SIZE);
 
--

2.25.1

author maintainer
#2 lore raw
Quoted 13 lines · Anup Patel
Quoted 10 lines · On Wed, Nov 24, 2021 at 11:35 AM <[email protected]> wrote:

From: Guo Ren <[email protected]>

For small memory systems(Allwinner D1s/F133), one page size memory cannot be ignored.

Cc Alexandre Ghiti <[email protected]>
Cc Anup Patel <[email protected]>
Cc Atish Patra <[email protected]>
Quoted 5 lines

This PATCH breaks the CPU hotplug functionality.

When a CPU/HART is turned off and turned on at runtime, the low-level relocate() will be called to enable MMU on the CPU being brought-up which in-turn uses trampoline_pg_dir.

Yeah, I forgot that.

How about removing trampoline_pg_dir totally and using early_pg_dir/swapper_pg_dir for relocate directly?

Quoted 26 lines

Regards,
Anup

Quoted 22 lines
---
 arch/riscv/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/mm/init.c +1 -2
index 24b2b8044602..097bb3bc4020 100644
@@ -241,9 +241,9 @@ unsigned long riscv_pfn_base __ro_after_init;
 EXPORT_SYMBOL(riscv_pfn_base);
 
 pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
-pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
 static pte_t fixmap_pte[PTRS_PER_PTE] __page_aligned_bss;
 
+pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
 pgd_t early_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
 static pmd_t __maybe_unused early_dtb_pmd[PTRS_PER_PMD] __initdata __aligned(PAGE_SIZE);
 
--

2.25.1

Signature · 4 lines
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/
#3 lore raw
Quoted 17 lines · Guo Ren
Quoted 15 lines · Anup Patel
Quoted 10 lines · On Wed, Nov 24, 2021 at 11:35 AM <[email protected]> wrote:

From: Guo Ren <[email protected]>

For small memory systems(Allwinner D1s/F133), one page size memory cannot be ignored.

Cc Alexandre Ghiti <[email protected]>
Cc Anup Patel <[email protected]>
Cc Atish Patra <[email protected]>

This PATCH breaks the CPU hotplug functionality.

Quoted 7 lines
Quoted 3 lines

When a CPU/HART is turned off and turned on at runtime, the low-level relocate() will be called to enable MMU on the CPU being brought-up which in-turn uses trampoline_pg_dir.

Yeah, I forgot that.

How about removing trampoline_pg_dir totally and using early_pg_dir/swapper_pg_dir for relocate directly?

The trampoline_pg_dir is to handle the case when RAM is large enough such that RAM physical address range overlaps kernel virtual address range (i.e. VA >= PAGE_OFFSET). This is overlap of virtual address range and physical address range can be problematic for low-level code which is trying to enable MMU (such as the relocate() function).

Here's a old kernel thread which tries to summarize this:
https://lore.kernel.org/lkml/CAAhSdy3URWHVY_GPNb2yRBuctRELRtTTWPM2OpwUVSRFAyXyiA@mail.gmail.com/

Regards,
Anup

Quoted 35 lines
Quoted 20 lines

Regards,
Anup

Quoted 15 lines
---
 arch/riscv/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/mm/init.c +0 -1
index 24b2b8044602..097bb3bc4020 100644
@@ -241,9 +241,9 @@ unsigned long riscv_pfn_base __ro_after_init;
 EXPORT_SYMBOL(riscv_pfn_base);
 
 pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
-pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
 static pte_t fixmap_pte[PTRS_PER_PTE] __page_aligned_bss;
 
Quoted 7 lines
Quoted 7 lines
arch/riscv/mm/init.c +1 -1
+pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
 pgd_t early_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
 static pmd_t __maybe_unused early_dtb_pmd[PTRS_PER_PMD] __initdata __aligned(PAGE_SIZE);
 
--

2.25.1

--
Best Regards
Guo Ren

ML: https://lore.kernel.org/linux-csky/

author maintainer
#4 lore raw
Quoted 34 lines · Anup Patel
Quoted 17 lines · Guo Ren
Quoted 15 lines · Anup Patel
Quoted 10 lines · On Wed, Nov 24, 2021 at 11:35 AM <[email protected]> wrote:

From: Guo Ren <[email protected]>

For small memory systems(Allwinner D1s/F133), one page size memory cannot be ignored.

Cc Alexandre Ghiti <[email protected]>
Cc Anup Patel <[email protected]>
Cc Atish Patra <[email protected]>

This PATCH breaks the CPU hotplug functionality.

Quoted 7 lines
Quoted 3 lines

When a CPU/HART is turned off and turned on at runtime, the low-level relocate() will be called to enable MMU on the CPU being brought-up which in-turn uses trampoline_pg_dir.

Yeah, I forgot that.

How about removing trampoline_pg_dir totally and using early_pg_dir/swapper_pg_dir for relocate directly?

The trampoline_pg_dir is to handle the case when RAM is large enough such that RAM physical address range overlaps kernel virtual address range (i.e. VA >= PAGE_OFFSET). This is overlap of virtual address range and physical address range can be problematic for low-level code which is trying to enable MMU (such as the relocate() function).

Quoted 2 lines

Here's a old kernel thread which tries to summarize this:
https://lore.kernel.org/lkml/CAAhSdy3URWHVY_GPNb2yRBuctRELRtTTWPM2OpwUVSRFAyXyiA@mail.gmail.com/

Got it. Thank you so much for sharing.

I would use the patch as private for F133 memory saving.

Quoted 39 lines

Regards,
Anup

Quoted 35 lines
Quoted 20 lines

Regards,
Anup

Quoted 15 lines
---
 arch/riscv/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/mm/init.c +0 -1
index 24b2b8044602..097bb3bc4020 100644
@@ -241,9 +241,9 @@ unsigned long riscv_pfn_base __ro_after_init;
 EXPORT_SYMBOL(riscv_pfn_base);
 
 pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
-pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
 static pte_t fixmap_pte[PTRS_PER_PTE] __page_aligned_bss;
 
Quoted 7 lines
Quoted 7 lines
arch/riscv/mm/init.c +1 -1
+pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
 pgd_t early_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
 static pmd_t __maybe_unused early_dtb_pmd[PTRS_PER_PMD] __initdata __aligned(PAGE_SIZE);
 
--

2.25.1

--
Best Regards
Guo Ren

ML: https://lore.kernel.org/linux-csky/

Signature · 4 lines
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/