Skip to contentSkip to conversation

target/ppc/mmu_common: Fix SRR1/MSR error code on Book-E

PATCH In review Vitaly Cheptsov 2 participants 2 messages Jan 21, 2022 – Jan 25, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/ppc/mmu_common: Fix SRR1/MSR error code on Book-E

Book-E architecture does not set the error code in 31:27 bits of SRR1, but instead uses these bits for custom fields such as GS (Guest Supervisor).

Wrongly setting these fields will result in QEMU crashes when attempting to execute not executable code due to the attempts to use Guest Supervisor mode.

Cc "Cédric Le Goater" <[email protected]>
Cc Daniel Henrique Barboza <[email protected]>
Cc David Gibson <[email protected]>
Cc Greg Kurz <[email protected]>
---
 target/ppc/mmu_common.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
target/ppc/mmu_common.c +15 -3
index 91270c1f17..6512ee031c 100644
@@ -1367,22 +1367,34 @@ static bool ppc_jumbo_xlate(PowerPCCPU *cpu, vaddr eaddr,
             case -2:
                 /* Access rights violation */
                 cs->exception_index = POWERPC_EXCP_ISI;
-                env->error_code = 0x08000000;
+                if ((env->mmu_model == POWERPC_MMU_BOOKE) ||
+                    (env->mmu_model == POWERPC_MMU_BOOKE206)) {
+                    env->error_code = 0;
+                } else {
+                    env->error_code = 0x08000000;
+                }
                 break;
             case -3:
                 /* No execute protection violation */
                 if ((env->mmu_model == POWERPC_MMU_BOOKE) ||
                     (env->mmu_model == POWERPC_MMU_BOOKE206)) {
                     env->spr[SPR_BOOKE_ESR] = 0x00000000;
+                    env->error_code = 0;
+                } else {
+                    env->error_code = 0x10000000;
                 }
                 cs->exception_index = POWERPC_EXCP_ISI;
-                env->error_code = 0x10000000;
                 break;
             case -4:
                 /* Direct store exception */
                 /* No code fetch is allowed in direct-store areas */
                 cs->exception_index = POWERPC_EXCP_ISI;
-                env->error_code = 0x10000000;
+                if ((env->mmu_model == POWERPC_MMU_BOOKE) ||
+                    (env->mmu_model == POWERPC_MMU_BOOKE206)) {
+                    env->error_code = 0;
+                } else {
+                    env->error_code = 0x10000000;
+                }
                 break;
             }
         } else {
Signature · 1 line
2.32.0 (Apple Git-132)
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Vitaly Cheptsov

Book-E architecture does not set the error code in 31:27 bits of SRR1, but instead uses these bits for custom fields such as GS (Guest Supervisor).

Wrongly setting these fields will result in QEMU crashes when attempting to execute not executable code due to the attempts to use Guest Supervisor mode.

Quoted 8 lines
Cc "Cédric Le Goater" <[email protected]>
Cc Daniel Henrique Barboza <[email protected]>
Cc David Gibson <[email protected]>
Cc Greg Kurz <[email protected]>

Thanks,

C.

Quoted 47 lines
---
  target/ppc/mmu_common.c | 18 +++++++++++++++---
  1 file changed, 15 insertions(+), 3 deletions(-)
target/ppc/mmu_common.c +15 -3
index 91270c1f17..6512ee031c 100644
@@ -1367,22 +1367,34 @@ static bool ppc_jumbo_xlate(PowerPCCPU *cpu, vaddr eaddr,
              case -2:
                  /* Access rights violation */
                  cs->exception_index = POWERPC_EXCP_ISI;
-                env->error_code = 0x08000000;
+                if ((env->mmu_model == POWERPC_MMU_BOOKE) ||
+                    (env->mmu_model == POWERPC_MMU_BOOKE206)) {
+                    env->error_code = 0;
+                } else {
+                    env->error_code = 0x08000000;
+                }
                  break;
              case -3:
                  /* No execute protection violation */
                  if ((env->mmu_model == POWERPC_MMU_BOOKE) ||
                      (env->mmu_model == POWERPC_MMU_BOOKE206)) {
                      env->spr[SPR_BOOKE_ESR] = 0x00000000;
+                    env->error_code = 0;
+                } else {
+                    env->error_code = 0x10000000;
                  }
                  cs->exception_index = POWERPC_EXCP_ISI;
-                env->error_code = 0x10000000;
                  break;
              case -4:
                  /* Direct store exception */
                  /* No code fetch is allowed in direct-store areas */
                  cs->exception_index = POWERPC_EXCP_ISI;
-                env->error_code = 0x10000000;
+                if ((env->mmu_model == POWERPC_MMU_BOOKE) ||
+                    (env->mmu_model == POWERPC_MMU_BOOKE206)) {
+                    env->error_code = 0;
+                } else {
+                    env->error_code = 0x10000000;
+                }
                  break;
              }
          } else {