Skip to contentSkip to conversation

riscv: correct pt_level name via pgtable_l5/4_enabled

PATCH Superseded Song Shuai 3 participants 4 messages Jul 11, 2023 – Jul 13, 2023 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Song Shuai

author
#0 lore raw

PATCH 1/1 riscv: correct pt_level name via pgtable_l5/4_enabled

The pt_level uses CONFIG_PGTABLE_LEVELS to display page table names. But if downgrading page mode from kernel cmdline in 64BIT, it will give a wrong name.

Like, using no4lvl for sv39, ptdump named the 1G-mapping as "PUD" that should be "PGD":

0xffffffd840000000-0xffffffd900000000 0x00000000c0000000 3G PUD D A G . . W R V

So select "P4D/PUD" or "PGD" via pgtable_l5/4_enabled to correct it.

Fixes 26e7aacb83df ("riscv: Allow to downgrade paging mode from the command line")
---
 arch/riscv/mm/ptdump.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/riscv/mm/ptdump.c +5 -0
index 20a9f991a6d7..cfdd327981ee 100644
@@ -384,6 +384,11 @@ static int __init ptdump_init(void)
 
 	kernel_ptd_info.base_addr = KERN_VIRT_START;
 
+#ifdef CONFIG_64BIT
+	pg_level[1].name = pgtable_l5_enabled ? "P4D" : "PGD";
+	pg_level[2].name = pgtable_l4_enabled ? "PUD" : "PGD";
+#endif
+
 	for (i = 0; i < ARRAY_SIZE(pg_level); i++)
 		for (j = 0; j < ARRAY_SIZE(pte_bits); j++)
 			pg_level[i].mask |= pte_bits[j].mask;
Signature · 1 line
2.20.1
reviewer Reviewed-by on v1 1/1
#1 lore raw

Hi Song,

Quoted 22 lines · Song Shuai

The pt_level uses CONFIG_PGTABLE_LEVELS to display page table names. But if downgrading page mode from kernel cmdline in 64BIT, it will give a wrong name.

Like, using no4lvl for sv39, ptdump named the 1G-mapping as "PUD" that should be "PGD":

0xffffffd840000000-0xffffffd900000000 0x00000000c0000000 3G PUD D A G . . W R V

So select "P4D/PUD" or "PGD" via pgtable_l5/4_enabled to correct it.

Fixes 26e7aacb83df ("riscv: Allow to downgrade paging mode from the command line")
---
  arch/riscv/mm/ptdump.c | 5 +++++
  1 file changed, 5 insertions(+)
arch/riscv/mm/ptdump.c +0 -0
index 20a9f991a6d7..cfdd327981ee 100644

arch/riscv/mm/ptdump.c static int __init ptdump_init(void) · line 390

Quoted 7 lines
arch/riscv/mm/ptdump.c +4 -0
@@ -384,6 +384,11 @@ static int __init ptdump_init(void)
 
  	kernel_ptd_info.base_addr = KERN_VIRT_START;
 
+#ifdef CONFIG_64BIT
+	pg_level[1].name = pgtable_l5_enabled ? "P4D" : "PGD";
+	pg_level[2].name = pgtable_l4_enabled ? "PUD" : "PGD";
+#endif

You don't need the #ifdef here as pgtable_lX_enabled are always declared.

arch/riscv/mm/ptdump.c static int __init ptdump_init(void) · line 394

Quoted 4 lines
arch/riscv/mm/ptdump.c +1 -0
+
  	for (i = 0; i < ARRAY_SIZE(pg_level); i++)
  		for (j = 0; j < ARRAY_SIZE(pte_bits); j++)
  			pg_level[i].mask |= pte_bits[j].mask;

The Fixes tag is wrong to me, if satp mode is restricted by the hardware itself (not from the command line), the same problem happens. Maybe that should be the sv48 introduction patch? Or the sv57? It will be more cumbersome to backport with the sv48 introduction though as this patch won't apply as-is.

Otherwise, you can add:

Thanks,

Alex

maintainer
#2 lore raw
Quoted 44 lines · On Tue, 11 Jul 2023 04:14:10 PDT (-0700), [email protected] wrote:

Hi Song,

Quoted 22 lines · Song Shuai

The pt_level uses CONFIG_PGTABLE_LEVELS to display page table names. But if downgrading page mode from kernel cmdline in 64BIT, it will give a wrong name.

Like, using no4lvl for sv39, ptdump named the 1G-mapping as "PUD" that should be "PGD":

0xffffffd840000000-0xffffffd900000000 0x00000000c0000000 3G PUD D A G . . W R V

So select "P4D/PUD" or "PGD" via pgtable_l5/4_enabled to correct it.

Fixes 26e7aacb83df ("riscv: Allow to downgrade paging mode from the command line")
---
  arch/riscv/mm/ptdump.c | 5 +++++
  1 file changed, 5 insertions(+)
arch/riscv/mm/ptdump.c +0 -0
index 20a9f991a6d7..cfdd327981ee 100644

arch/riscv/mm/ptdump.c static int __init ptdump_init(void) · line 390

Quoted 7 lines
arch/riscv/mm/ptdump.c +4 -0
@@ -384,6 +384,11 @@ static int __init ptdump_init(void)
 
  	kernel_ptd_info.base_addr = KERN_VIRT_START;
 
+#ifdef CONFIG_64BIT
+	pg_level[1].name = pgtable_l5_enabled ? "P4D" : "PGD";
+	pg_level[2].name = pgtable_l4_enabled ? "PUD" : "PGD";
+#endif

You don't need the #ifdef here as pgtable_lX_enabled are always declared.

arch/riscv/mm/ptdump.c static int __init ptdump_init(void) · line 394

Quoted 4 lines
arch/riscv/mm/ptdump.c +1 -0
+
  	for (i = 0; i < ARRAY_SIZE(pg_level); i++)
  		for (j = 0; j < ARRAY_SIZE(pte_bits); j++)
  			pg_level[i].mask |= pte_bits[j].mask;
Quoted 5 lines

The Fixes tag is wrong to me, if satp mode is restricted by the hardware itself (not from the command line), the same problem happens. Maybe that should be the sv48 introduction patch? Or the sv57? It will be more cumbersome to backport with the sv48 introduction though as this patch won't apply as-is.

Sometimes it's easier to base the fix on the original offending commit and then forward-port it via a merge, I haven't looked at this one to know for sure though.

Quoted 3 lines

Otherwise, you can add:

Thanks.

Song: do you have a v2 that addresses the comments?

Quoted 4 lines

Thanks,

Alex

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#3 lore raw
Quoted 53 lines · Palmer Dabbelt
Quoted 44 lines · On Tue, 11 Jul 2023 04:14:10 PDT (-0700), [email protected] wrote:

Hi Song,

Quoted 22 lines · Song Shuai

The pt_level uses CONFIG_PGTABLE_LEVELS to display page table names. But if downgrading page mode from kernel cmdline in 64BIT, it will give a wrong name.

Like, using no4lvl for sv39, ptdump named the 1G-mapping as "PUD" that should be "PGD":

0xffffffd840000000-0xffffffd900000000    0x00000000c0000000 3G PUD     D A G . . W R V

So select "P4D/PUD" or "PGD" via pgtable_l5/4_enabled to correct it.

Fixes 26e7aacb83df ("riscv: Allow to downgrade paging mode from the command line")

---
  arch/riscv/mm/ptdump.c | 5 +++++

  1 file changed, 5 insertions(+)
arch/riscv/mm/ptdump.c +0 -0
index 20a9f991a6d7..cfdd327981ee 100644

arch/riscv/mm/ptdump.c static int __init ptdump_init(void) · line 390

Quoted 7 lines
arch/riscv/mm/ptdump.c +4 -0
@@ -384,6 +384,11 @@ static int __init ptdump_init(void)
 
       kernel_ptd_info.base_addr = KERN_VIRT_START;
 
+#ifdef CONFIG_64BIT
+    pg_level[1].name = pgtable_l5_enabled ? "P4D" : "PGD";
+    pg_level[2].name = pgtable_l4_enabled ? "PUD" : "PGD";
+#endif

You don't need the #ifdef here as pgtable_lX_enabled are always declared.

arch/riscv/mm/ptdump.c static int __init ptdump_init(void) · line 394

Quoted 4 lines
arch/riscv/mm/ptdump.c +1 -0
+
       for (i = 0; i < ARRAY_SIZE(pg_level); i++)
           for (j = 0; j < ARRAY_SIZE(pte_bits); j++)
               pg_level[i].mask |= pte_bits[j].mask;
Quoted 5 lines

The Fixes tag is wrong to me, if satp mode is restricted by the hardware itself (not from the command line), the same problem happens. Maybe that should be the sv48 introduction patch? Or the sv57? It will be more cumbersome to backport with the sv48 introduction though as this patch won't apply as-is.

Sometimes it's easier to base the fix on the original offending commit and then forward-port it via a merge, I haven't looked at this one to know for sure though.

Quoted 8 lines
Quoted 3 lines

Otherwise, you can add:

Thanks.

Song: do you have a v2 that addresses the comments?

Here is V2 :

https://lore.kernel.org/linux-riscv/[email protected]/

Quoted 4 lines
Quoted 4 lines

Thanks,

Alex

Signature · 2 lines
Thanks
Song Shuai