Skip to contentSkip to conversation

RISC-V: mm: Fix set_satp_mode() for platform not having Sv57

PATCH In review Anup Patel 4 participants 7 messages Apr 12, 2022 – Apr 21, 2022 RISC-V

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

PATCH 1/1 RISC-V: mm: Fix set_satp_mode() for platform not having Sv57

When Sv57 is not available the satp.MODE test in set_satp_mode() will fail and lead to pgdir re-programming for Sv48. The pgdir re-programming will fail as well due to pre-existing pgdir entry used for Sv57 and as a result kernel fails to boot on RISC-V platform not having Sv57.

To fix above issue, we should clear the pgdir memory in set_satp_mode() before re-programming.

Fixes 011f09d12052 ("riscv: mm: Set sv57 on defaultly")
---
 arch/riscv/mm/init.c | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/mm/init.c +1 -0
index 9535bea8688c..b0793dc0c291 100644
@@ -718,6 +718,7 @@ static __init void set_satp_mode(void)
 		if (!check_l4) {
 			disable_pgtable_l5();
 			check_l4 = true;
+			memset(early_pg_dir, 0, PAGE_SIZE);
 			goto retry;
 		}
 		disable_pgtable_l4();
Signature · 1 line
2.25.1
#1 lore raw

Hi Anup,

>
> When Sv57 is not available the satp.MODE test in set_satp_mode() will > fail and lead to pgdir re-programming for Sv48. The pgdir re-programming > will fail as well due to pre-existing pgdir entry used for Sv57 and as > a result kernel fails to boot on RISC-V platform not having Sv57. >
> To fix above issue, we should clear the pgdir memory in set_satp_mode() > before re-programming.
>
&gt; Fixes: 011f09d12052 ("riscv: mm: Set sv57 on defaultly") &gt; Reported-by: Mayuresh Chitale <[email protected]> &gt; Signed-off-by: Anup Patel <[email protected]>
&gt; ---
&gt; arch/riscv/mm/init.c | 1 +
&gt; 1 file changed, 1 insertion(+)
&gt;
&gt; diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c &gt; index 9535bea8688c..b0793dc0c291 100644
&gt; --- a/arch/riscv/mm/init.c
&gt; +++ b/arch/riscv/mm/init.c
&gt; @@ -718,6 +718,7 @@ static __init void set_satp_mode(void)

&gt;  		if (!check_l4) {
&gt;  			disable_pgtable_l5();
&gt;  			check_l4 = true;
&gt; +			memset(early_pg_dir, 0, PAGE_SIZE);
&gt;  			goto retry;
&gt;  		}
&gt;  		disable_pgtable_l4();

&gt; --

I find it that the set_satp_mode function is in .init.text section which begins at 0x80800000. And its pgd_index in both Sv48 and Sv57 will be 0. So it may not be necessary to clear the early_pg_dir when the kernel find Sv57 is not supported? And may I get the steps of reproduction from you?

Yours,
Qinglin </[email protected]></[email protected]>
_______________________________________________
linux-riscv mailing list [email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#2 lore raw
Quoted 34 lines · 潘庆霖

Hi Anup,

&gt;
&gt; When Sv57 is not available the satp.MODE test in set_satp_mode() will &gt; fail and lead to pgdir re-programming for Sv48. The pgdir re-programming &gt; will fail as well due to pre-existing pgdir entry used for Sv57 and as &gt; a result kernel fails to boot on RISC-V platform not having Sv57. &gt;
&gt; To fix above issue, we should clear the pgdir memory in set_satp_mode() &gt; before re-programming.
&gt;
&gt; Fixes: 011f09d12052 ("riscv: mm: Set sv57 on defaultly") &gt; Reported-by: Mayuresh Chitale <[email protected]> &gt; Signed-off-by: Anup Patel <[email protected]>
&gt; ---
&gt; arch/riscv/mm/init.c | 1 +
&gt; 1 file changed, 1 insertion(+)
&gt;
&gt; diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c &gt; index 9535bea8688c..b0793dc0c291 100644
&gt; --- a/arch/riscv/mm/init.c
&gt; +++ b/arch/riscv/mm/init.c
&gt; @@ -718,6 +718,7 @@ static __init void set_satp_mode(void)
&gt; if (!check_l4) {

&gt;                    disable_pgtable_l5();
&gt;                    check_l4 = true;
&gt; +                  memset(early_pg_dir, 0, PAGE_SIZE);
&gt;                    goto retry;

&gt; }
&gt; disable_pgtable_l4();
&gt; --

Quoted 4 lines

I find it that the set_satp_mode function is in .init.text section which begins at 0x80800000. And its pgd_index in both Sv48 and Sv57 will be 0. So it may not be necessary to clear the early_pg_dir when the kernel find Sv57 is not supported? And may I get the steps of reproduction from you?

We can't assume that it will be the same pgd_index for Sv48 and Sv57.

For example, some hypothetical SoC might have RAM starting after 1TB space.

We should ensure that early_pg_dir is cleaned entirely for detecting the next mode.

Regards,
Anup

Quoted 4 lines

Yours,
Qinglin </[email protected]></[email protected]>

#3 lore raw

Hi Anup,

&gt;
&gt; We can't assume that it will be the same pgd_index for Sv48 and Sv57. &gt;
&gt; For example, some hypothetical SoC might have RAM starting after 1TB space. &gt;
&gt; We should ensure that early_pg_dir is cleaned entirely for detecting the next &gt; mode.
&gt;

Got it. Your idea is really more stable. Thank you for pointing out that!

Yours,
Qinglin

Reviewed-by on v1 1/1
#4 lore raw
In reply to Anup Patel
Quoted 29 lines · Anup Patel

When Sv57 is not available the satp.MODE test in set_satp_mode() will fail and lead to pgdir re-programming for Sv48. The pgdir re-programming will fail as well due to pre-existing pgdir entry used for Sv57 and as a result kernel fails to boot on RISC-V platform not having Sv57.

To fix above issue, we should clear the pgdir memory in set_satp_mode() before re-programming.

Fixes 011f09d12052 ("riscv: mm: Set sv57 on defaultly")
---
 arch/riscv/mm/init.c | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/mm/init.c +1 -1
index 9535bea8688c..b0793dc0c291 100644
@@ -718,6 +718,7 @@ static __init void set_satp_mode(void)
                if (!check_l4) {
                        disable_pgtable_l5();
                        check_l4 = true;
+                       memset(early_pg_dir, 0, PAGE_SIZE);
                        goto retry;
                }
                disable_pgtable_l4();
--
Quoted 2 lines

2.25.1

Signature · 2 lines
Regards,
Atish
author
#5 lore raw
In reply to Anup Patel

Hi Palmer,

Quoted 6 lines · Anup Patel

When Sv57 is not available the satp.MODE test in set_satp_mode() will fail and lead to pgdir re-programming for Sv48. The pgdir re-programming will fail as well due to pre-existing pgdir entry used for Sv57 and as a result kernel fails to boot on RISC-V platform not having Sv57.

Quoted 6 lines

To fix above issue, we should clear the pgdir memory in set_satp_mode() before re-programming.

Fixes 011f09d12052 ("riscv: mm: Set sv57 on defaultly")

Can this be considered for 5.18-rcX ?

Regards,
Anup

Quoted 19 lines
---
 arch/riscv/mm/init.c | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/mm/init.c +1 -1
index 9535bea8688c..b0793dc0c291 100644
@@ -718,6 +718,7 @@ static __init void set_satp_mode(void)
                if (!check_l4) {
                        disable_pgtable_l5();
                        check_l4 = true;
+                       memset(early_pg_dir, 0, PAGE_SIZE);
                        goto retry;
                }
                disable_pgtable_l4();
--

2.25.1

maintainer
#6 lore raw
Quoted 9 lines · On Thu, 21 Apr 2022 02:30:05 PDT (-0700), [email protected] wrote:

Hi Palmer,

Quoted 6 lines · Anup Patel

When Sv57 is not available the satp.MODE test in set_satp_mode() will fail and lead to pgdir re-programming for Sv48. The pgdir re-programming will fail as well due to pre-existing pgdir entry used for Sv57 and as a result kernel fails to boot on RISC-V platform not having Sv57.

Quoted 8 lines
Quoted 6 lines

To fix above issue, we should clear the pgdir memory in set_satp_mode() before re-programming.

Fixes 011f09d12052 ("riscv: mm: Set sv57 on defaultly")

Can this be considered for 5.18-rcX ?

Sorry, there's a queue but I just say this one at the top and it's super simple so I'm going to take it now -- IRC is good to ping this sort of stuff.

It's in fixes.

Thanks!

Quoted 23 lines

Regards,
Anup

Quoted 19 lines
---
 arch/riscv/mm/init.c | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/mm/init.c +1 -1
index 9535bea8688c..b0793dc0c291 100644
@@ -718,6 +718,7 @@ static __init void set_satp_mode(void)
                if (!check_l4) {
                        disable_pgtable_l5();
                        check_l4 = true;
+                       memset(early_pg_dir, 0, PAGE_SIZE);
                        goto retry;
                }
                disable_pgtable_l4();
--

2.25.1