[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 23/34] target/arm: Update arm_mmu_idx for VHE
From: |
Richard Henderson |
Subject: |
[Qemu-devel] [PATCH v3 23/34] target/arm: Update arm_mmu_idx for VHE |
Date: |
Sat, 3 Aug 2019 11:47:49 -0700 |
Return the indexes for the EL2&0 regime when the appropriate bits
are set within HCR_EL2. This happens for initial generation in
arm_mmu_idx, and reconstruction in core_to_arm_mmu_idx.
In order to make this reliable, we also need a bit in TBFLAGS.
Reviewed-by: Alex Bennée <address@hidden>
Signed-off-by: Richard Henderson <address@hidden>
---
v5: Consistently check E2H & TGE & ELUsingAArch32(EL2).
---
target/arm/cpu.h | 2 ++
target/arm/helper.c | 51 ++++++++++++++++++++++++++++++++-------------
2 files changed, 39 insertions(+), 14 deletions(-)
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index b5300f9014..8d90a4fc4d 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -3153,6 +3153,8 @@ FIELD(TBFLAG_ANY, PSTATE_SS, 26, 1)
/* Target EL if we take a floating-point-disabled exception */
FIELD(TBFLAG_ANY, FPEXC_EL, 24, 2)
FIELD(TBFLAG_ANY, BE_DATA, 23, 1)
+/* For A profile only, if EL2 is AA64 and HCR_EL2.<E2H,TGE> == 11 */
+FIELD(TBFLAG_ANY, E2H_TGE, 22, 1)
/* Bit usage when in AArch32 state: */
FIELD(TBFLAG_A32, THUMB, 0, 1)
diff --git a/target/arm/helper.c b/target/arm/helper.c
index 5472424179..a570d43232 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -11257,21 +11257,31 @@ int fp_exception_el(CPUARMState *env, int cur_el)
ARMMMUIdx core_to_arm_mmu_idx(CPUARMState *env, int mmu_idx)
{
+ bool e2h;
+
if (arm_feature(env, ARM_FEATURE_M)) {
return mmu_idx | ARM_MMU_IDX_M;
}
mmu_idx |= ARM_MMU_IDX_A;
+ if (mmu_idx & ARM_MMU_IDX_S) {
+ return mmu_idx;
+ }
+
+ /*
+ * All remaining states are non-secure, so we can directly
+ * access hcr_el2 for these two bits.
+ */
+ e2h = (env->cp15.hcr_el2 & (HCR_E2H | HCR_TGE)) == (HCR_E2H | HCR_TGE)
+ && arm_el_is_aa64(env, 2);
+
switch (mmu_idx) {
case 0 | ARM_MMU_IDX_A:
- return ARMMMUIdx_EL10_0;
+ return e2h ? ARMMMUIdx_EL20_0 : ARMMMUIdx_EL10_0;
case 1 | ARM_MMU_IDX_A:
return ARMMMUIdx_EL10_1;
case ARMMMUIdx_E2:
- case ARMMMUIdx_SE0:
- case ARMMMUIdx_SE1:
- case ARMMMUIdx_SE3:
- return mmu_idx;
+ return e2h ? ARMMMUIdx_EL20_2 : ARMMMUIdx_E2;
default:
g_assert_not_reached();
}
@@ -11300,25 +11310,27 @@ ARMMMUIdx arm_v7m_mmu_idx_for_secstate(CPUARMState
*env, bool secstate)
ARMMMUIdx arm_mmu_idx(CPUARMState *env)
{
int el;
+ bool e2h;
if (arm_feature(env, ARM_FEATURE_M)) {
return arm_v7m_mmu_idx_for_secstate(env, env->v7m.secure);
}
el = arm_current_el(env);
+ if (el == 3 || arm_is_secure_below_el3(env)) {
+ return ARMMMUIdx_SE0 + el;
+ }
+
+ e2h = (env->cp15.hcr_el2 & (HCR_E2H | HCR_TGE)) == (HCR_E2H | HCR_TGE)
+ && arm_el_is_aa64(env, 2);
+
switch (el) {
case 0:
- /* TODO: ARMv8.1-VHE */
+ return e2h ? ARMMMUIdx_EL20_0 : ARMMMUIdx_EL10_0;
case 1:
- return (arm_is_secure_below_el3(env)
- ? ARMMMUIdx_SE0 + el
- : ARMMMUIdx_EL10_0 + el);
+ return ARMMMUIdx_EL10_1;
case 2:
- /* TODO: ARMv8.1-VHE */
- /* TODO: ARMv8.4-SecEL2 */
- return ARMMMUIdx_E2;
- case 3:
- return ARMMMUIdx_SE3;
+ return e2h ? ARMMMUIdx_EL20_2 : ARMMMUIdx_E2;
default:
g_assert_not_reached();
}
@@ -11428,6 +11440,17 @@ void cpu_get_tb_cpu_state(CPUARMState *env,
target_ulong *pc,
flags = FIELD_DP32(flags, TBFLAG_ANY, MMUIDX,
arm_to_core_mmu_idx(mmu_idx));
+ /*
+ * Include E2H in TBFLAGS so that core_to_arm_mmu_idx can
+ * reliably determine EL1&0 vs EL2&0 regimes.
+ */
+ if (arm_el_is_aa64(env, 2)) {
+ uint64_t hcr = arm_hcr_el2_eff(env);
+ if ((hcr & (HCR_E2H | HCR_TGE)) == (HCR_E2H | HCR_TGE)) {
+ flags = FIELD_DP32(flags, TBFLAG_ANY, E2H_TGE, 1);
+ }
+ }
+
/* The SS_ACTIVE and PSTATE_SS bits correspond to the state machine
* states defined in the ARM ARM for software singlestep:
* SS_ACTIVE PSTATE.SS State
--
2.17.1
- Re: [Qemu-devel] [PATCH v3 12/34] target/arm: Add VHE system register redirection and aliasing, (continued)
- [Qemu-devel] [PATCH v3 14/34] target/arm: Simplify tlb_force_broadcast alternatives, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 10/34] target/arm: Update CNTVCT_EL0 for VHE, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 09/34] target/arm: Add TTBR1_EL2, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 13/34] target/arm: Split out vae1_tlbmask, vmalle1_tlbmask, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 15/34] target/arm: Rename ARMMMUIdx*_S12NSE* to ARMMMUIdx*_E10_*, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 16/34] target/arm: Rename ARMMMUIdx_S2NS to ARMMMUIdx_Stage2, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 17/34] target/arm: Rename ARMMMUIdx_S1NSE* to ARMMMUIdx_Stage1_E*, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 19/34] target/arm: Rename ARMMMUIdx*_S1E3 to ARMMMUIdx*_SE3, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 18/34] target/arm: Rename ARMMMUIdx_S1SE* to ARMMMUIdx_SE*, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 23/34] target/arm: Update arm_mmu_idx for VHE,
Richard Henderson <=
- [Qemu-devel] [PATCH v3 20/34] target/arm: Rename ARMMMUIdx_S1E2 to ARMMMUIdx_E2, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 22/34] target/arm: Add regime_has_2_ranges, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 21/34] target/arm: Reorganize ARMMMUIdx, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 24/34] target/arm: Update arm_sctlr for VHE, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 27/34] target/arm: Install asids for E2&0 translation regime, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 25/34] target/arm: Update aa64_zva_access for EL2, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 26/34] target/arm: Update ctr_el0_access for EL2, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 28/34] target/arm: Flush tlbs for E2&0 translation regime, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 30/34] target/arm: Update regime_is_user for EL2&0, Richard Henderson, 2019/08/03
- [Qemu-devel] [PATCH v3 32/34] target/arm: Enable ARMv8.1-VHE in -cpu max, Richard Henderson, 2019/08/03