diff mbox series

[v3,08/10] lib: sbi: Change the order of PMP initialization

Message ID 20230712043436.100548-9-hchauhan@ventanamicro.com
State Accepted
Headers show
Series Add support for Smepmp | expand

Commit Message

Himanshu Chauhan July 12, 2023, 4:34 a.m. UTC
Configure PMP at last when all other initializations have been done.
Because if SMEPMP is detected, M-mode access to the S/U space will be
rescinded.

Signed-off-by: Himanshu Chauhan <hchauhan@ventanamicro.com>
---
 lib/sbi/sbi_init.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

Comments

Anup Patel July 12, 2023, 6:24 a.m. UTC | #1
On Wed, Jul 12, 2023 at 10:05 AM Himanshu Chauhan
<hchauhan@ventanamicro.com> wrote:
>
> Configure PMP at last when all other initializations have been done.
> Because if SMEPMP is detected, M-mode access to the S/U space will be
> rescinded.
>
> Signed-off-by: Himanshu Chauhan <hchauhan@ventanamicro.com>

Looks good to me.

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

Thanks,
Anup

> ---
>  lib/sbi/sbi_init.c | 26 +++++++++++++++++---------
>  1 file changed, 17 insertions(+), 9 deletions(-)
>
> diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
> index 423e6d8..35e6633 100644
> --- a/lib/sbi/sbi_init.c
> +++ b/lib/sbi/sbi_init.c
> @@ -356,13 +356,6 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
>                 sbi_hart_hang();
>         }
>
> -       rc = sbi_hart_pmp_configure(scratch);
> -       if (rc) {
> -               sbi_printf("%s: PMP configure failed (error %d)\n",
> -                          __func__, rc);
> -               sbi_hart_hang();
> -       }
> -
>         /*
>          * Note: Platform final initialization should be after finalizing
>          * domains so that it sees correct domain assignment and PMP
> @@ -392,6 +385,17 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
>
>         sbi_boot_print_hart(scratch, hartid);
>
> +       /*
> +        * Configure PMP at last because if SMEPMP is detected,
> +        * M-mode access to the S/U space will be rescinded.
> +        */
> +       rc = sbi_hart_pmp_configure(scratch);
> +       if (rc) {
> +               sbi_printf("%s: PMP configure failed (error %d)\n",
> +                          __func__, rc);
> +               sbi_hart_hang();
> +       }
> +
>         wake_coldboot_harts(scratch, hartid);
>
>         count = sbi_scratch_offset_ptr(scratch, init_count_offset);
> @@ -445,11 +449,15 @@ static void __noreturn init_warm_startup(struct sbi_scratch *scratch,
>         if (rc)
>                 sbi_hart_hang();
>
> -       rc = sbi_hart_pmp_configure(scratch);
> +       rc = sbi_platform_final_init(plat, false);
>         if (rc)
>                 sbi_hart_hang();
>
> -       rc = sbi_platform_final_init(plat, false);
> +       /*
> +        * Configure PMP at last because if SMEPMP is detected,
> +        * M-mode access to the S/U space will be rescinded.
> +        */
> +       rc = sbi_hart_pmp_configure(scratch);
>         if (rc)
>                 sbi_hart_hang();
>
> --
> 2.34.1
>
>
> --
> opensbi mailing list
> opensbi@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
diff mbox series

Patch

diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
index 423e6d8..35e6633 100644
--- a/lib/sbi/sbi_init.c
+++ b/lib/sbi/sbi_init.c
@@ -356,13 +356,6 @@  static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
 		sbi_hart_hang();
 	}
 
-	rc = sbi_hart_pmp_configure(scratch);
-	if (rc) {
-		sbi_printf("%s: PMP configure failed (error %d)\n",
-			   __func__, rc);
-		sbi_hart_hang();
-	}
-
 	/*
 	 * Note: Platform final initialization should be after finalizing
 	 * domains so that it sees correct domain assignment and PMP
@@ -392,6 +385,17 @@  static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
 
 	sbi_boot_print_hart(scratch, hartid);
 
+	/*
+	 * Configure PMP at last because if SMEPMP is detected,
+	 * M-mode access to the S/U space will be rescinded.
+	 */
+	rc = sbi_hart_pmp_configure(scratch);
+	if (rc) {
+		sbi_printf("%s: PMP configure failed (error %d)\n",
+			   __func__, rc);
+		sbi_hart_hang();
+	}
+
 	wake_coldboot_harts(scratch, hartid);
 
 	count = sbi_scratch_offset_ptr(scratch, init_count_offset);
@@ -445,11 +449,15 @@  static void __noreturn init_warm_startup(struct sbi_scratch *scratch,
 	if (rc)
 		sbi_hart_hang();
 
-	rc = sbi_hart_pmp_configure(scratch);
+	rc = sbi_platform_final_init(plat, false);
 	if (rc)
 		sbi_hart_hang();
 
-	rc = sbi_platform_final_init(plat, false);
+	/*
+	 * Configure PMP at last because if SMEPMP is detected,
+	 * M-mode access to the S/U space will be rescinded.
+	 */
+	rc = sbi_hart_pmp_configure(scratch);
 	if (rc)
 		sbi_hart_hang();