lib: sbi: Change the order of PMP initialization
authorHimanshu Chauhan <hchauhan@ventanamicro.com>
Wed, 12 Jul 2023 04:34:34 +0000 (10:04 +0530)
committerAnup Patel <anup@brainfault.org>
Thu, 13 Jul 2023 07:12:06 +0000 (12:42 +0530)
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>
Reviewed-by: Anup Patel <anup@brainfault.org>
lib/sbi/sbi_init.c

index 423e6d83650f98becd39b22ab22820704e21d6b9..35e6633350105daf887bfbe97898f7342f03b07b 100644 (file)
@@ -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();