[PATCH 1/7] lib: sbi: Probe pmp_count in read-only

Anup Patel anup at brainfault.org
Mon Dec 11 23:37:10 PST 2023


On Fri, Dec 8, 2023 at 3:34 AM Yangyu Chen <cyy at cyyself.name> wrote:
>
> Some CPU implementations such as T-Head C908 will raise illegal
> instruction exception when writing a different value to some pmpaddr
> which is locked.
>
> To avoid this, a solution is to probe pmp_count in read-only. This will
> not affect the existing CPU implementation as RISC-V Privileged
> Architecture specified that access to a non-existent CSR raises an
> illegal instruction exception.
>
> Signed-off-by: Yangyu Chen <cyy at cyyself.name>

Looks good to me.

Reviewed-by: Anup Patel <anup at brainfault.org>

Regards,
Anup

> ---
>  lib/sbi/sbi_hart.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
> index c948373..49d1454 100644
> --- a/lib/sbi/sbi_hart.c
> +++ b/lib/sbi/sbi_hart.c
> @@ -877,7 +877,7 @@ static int hart_detect_features(struct sbi_scratch *scratch)
>                 hfeatures->pmp_gran =  1 << (sbi_ffs(val) + 2);
>                 hfeatures->pmp_addr_bits = sbi_fls(val) + 1;
>                 /* Detect number of PMP regions. At least PMPADDR0 should be implemented*/
> -               __check_csr_64(CSR_PMPADDR0, 0, val, pmp_count, __pmp_skip);
> +               __check_csr_64(CSR_PMPADDR0, true, 0, pmp_count, __pmp_skip);
>         }
>  __pmp_skip:
>         /* Detect number of MHPM counters */
> --
> 2.43.0
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi



More information about the opensbi mailing list