diff mbox series

[6/7] lib: sbi: Not use smepmp if has pmp reserved and MSECCFG.MML=1

Message ID tencent_C0BE4FC10C6D3847295C8418A91096465E07@qq.com
State Changes Requested
Headers show
Series lib: sbi: Probe PMP locked entries and adjust first usable PMP index | expand

Commit Message

Yangyu Chen Dec. 7, 2023, 10:04 p.m. UTC
If the platform already sets any locked PMPs before OpenSBI starts,
CSR.MSECCFG.MML should never change by OpenSBI to make the locked PMPs
behave as expected.

Signed-off-by: Yangyu Chen <cyy@cyyself.name>
---
 lib/sbi/sbi_hart.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Anup Patel Dec. 12, 2023, 8:39 a.m. UTC | #1
On Fri, Dec 8, 2023 at 3:34 AM Yangyu Chen <cyy@cyyself.name> wrote:
>
> If the platform already sets any locked PMPs before OpenSBI starts,
> CSR.MSECCFG.MML should never change by OpenSBI to make the locked PMPs
> behave as expected.

NACK.

For platforms with Smepmp, OpenSBI configures M-mode only regions
before setting mseccfg.MML.

In other words, it is mandatory for platforms with Smepmp to boot
OpenSBI with mseccfg.RLB = 1 and mseccfg.MML = 0.

Regards,
Anup

>
> Signed-off-by: Yangyu Chen <cyy@cyyself.name>
> ---
>  lib/sbi/sbi_hart.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
> index f836b1c..fe24e82 100644
> --- a/lib/sbi/sbi_hart.c
> +++ b/lib/sbi/sbi_hart.c
> @@ -559,7 +559,8 @@ int sbi_hart_pmp_configure(struct sbi_scratch *scratch)
>         pmp_bits = sbi_hart_pmp_addrbits(scratch) - 1;
>         pmp_addr_max = (1UL << pmp_bits) | ((1UL << pmp_bits) - 1);
>
> -       if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMEPMP))
> +       if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMEPMP) &&
> +               (csr_read(CSR_MSECCFG) & MSECCFG_MML || !sbi_hart_pmp_reserved(scratch)))
>                 rc = sbi_hart_smepmp_configure(scratch, pmp_count,
>                                                 pmp_gran_log2, pmp_addr_max);
>         else
> --
> 2.43.0
>
>
> --
> opensbi mailing list
> opensbi@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
diff mbox series

Patch

diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index f836b1c..fe24e82 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -559,7 +559,8 @@  int sbi_hart_pmp_configure(struct sbi_scratch *scratch)
 	pmp_bits = sbi_hart_pmp_addrbits(scratch) - 1;
 	pmp_addr_max = (1UL << pmp_bits) | ((1UL << pmp_bits) - 1);
 
-	if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMEPMP))
+	if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMEPMP) &&
+		(csr_read(CSR_MSECCFG) & MSECCFG_MML || !sbi_hart_pmp_reserved(scratch)))
 		rc = sbi_hart_smepmp_configure(scratch, pmp_count,
 						pmp_gran_log2, pmp_addr_max);
 	else