Skip to contentSkip to conversation

target/arm: cpu: add HCR_E2H on reset for EL2 + !E2H0

PATCH In review Mohamed Mediouni 3 participants 4 messages Apr 1 – Apr 3

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/arm: cpu: add HCR_E2H on reset for EL2 + !E2H0

---
 target/arm/cpu.c | 4 ++++
 1 file changed, 4 insertions(+)
target/arm/cpu.c +4 -0
index ccc47c8a9a..5ffb1e3096 100644
@@ -685,6 +685,10 @@ void arm_emulate_firmware_reset(CPUState *cpustate, int target_el)
         }
     }
 
+    if (have_el2 && !cpu_isar_feature(aa64_e2h0, cpu)) {
+        env->cp15.hcr_el2 |= HCR_E2H;
+    }
+
     /* Set the CPU to the desired state */
     if (env->aarch64) {
         env->pstate = aarch64_pstate_mode(target_el, true);
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw
Quoted 2 lines · Mohamed Mediouni

This could use some rationale in the commit message:
why do we need it, what goes wrong, etc.

Quoted 20 lines
---
 target/arm/cpu.c | 4 ++++
 1 file changed, 4 insertions(+)
target/arm/cpu.c +4 -1
index ccc47c8a9a..5ffb1e3096 100644
@@ -685,6 +685,10 @@ void arm_emulate_firmware_reset(CPUState *cpustate, int target_el)
         }
     }
 
+    if (have_el2 && !cpu_isar_feature(aa64_e2h0, cpu)) {
+        env->cp15.hcr_el2 |= HCR_E2H;
+    }
+
     /* Set the CPU to the desired state */
     if (env->aarch64) {
         env->pstate = aarch64_pstate_mode(target_el, true);
--
Quoted 1 line

2.50.1 (Apple Git-155)

thanks
-- PMM

#2 lore raw
Quoted 6 lines · Peter Maydell
Quoted 2 lines · Mohamed Mediouni

This could use some rationale in the commit message:
why do we need it, what goes wrong, etc.

Indeed. I would expect this to be handled via hcr_reset and a2834b853d9 ("target/arm: implement FEAT_E2H0")

Specifically,

+ /* Strictly E2H is RES1 unless FEAT_E2H0 relaxes the requirement */
+ if (!cpu_isar_feature(aa64_e2h0, cpu)) {
+ value |= HCR_E2H;
+ }

r~

Quoted 26 lines
Quoted 21 lines
---
  target/arm/cpu.c | 4 ++++
  1 file changed, 4 insertions(+)
target/arm/cpu.c +4 -1
index ccc47c8a9a..5ffb1e3096 100644
@@ -685,6 +685,10 @@ void arm_emulate_firmware_reset(CPUState *cpustate, int target_el)
          }
      }
 
+    if (have_el2 && !cpu_isar_feature(aa64_e2h0, cpu)) {
+        env->cp15.hcr_el2 |= HCR_E2H;
+    }
+
      /* Set the CPU to the desired state */
      if (env->aarch64) {
          env->pstate = aarch64_pstate_mode(target_el, true);
--
Quoted 1 line

2.50.1 (Apple Git-155)

thanks
-- PMM

#3 lore raw
Quoted 22 lines · Richard Henderson
Quoted 5 lines · Peter Maydell
Quoted 2 lines · Mohamed Mediouni

This could use some rationale in the commit message:
why do we need it, what goes wrong, etc.

Indeed. I would expect this to be handled via hcr_reset and a2834b853d9 ("target/arm: implement FEAT_E2H0")

Specifically,

(quoted diff) +4 -0
+        /* Strictly E2H is RES1 unless FEAT_E2H0 relaxes the requirement */
+        if (!cpu_isar_feature(aa64_e2h0, cpu)) {
+            value |= HCR_E2H;
+        }
Quoted 3 lines

r~

Hello,

That’s indeed the case, missed that commit.

Some context: the issue is an edge case around nested virt on hardware without FEAT_NV2p2 where the guest cannot flip between VHE and nVHE at runtime - but the OS supports both nested virt impls.

While KVM handles HCR_EL2.E2H’s effective value via a KVM cap, that’s not the only option around. An HV tries to be clever and sets the state depending on what HCR_EL2 is read as.