Skip to contentSkip to conversation

target/arm: honor HCR_E2H for AT S1E2R and AT S1E2W address translation

PATCH In review Ake Koomsin 3 participants 4 messages Oct 17, 2022 – Oct 26, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/arm: honor HCR_E2H for AT S1E2R and AT S1E2W address translation

When HCR_E2H is set, AT S1E2R and AT S1E2W should translate an address based on both TTBR0_EL2 and TTBR1_EL2.

---
 target/arm/helper.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
target/arm/helper.c +6 -1
index dde64a487a..147f96e752 100644
@@ -3486,7 +3486,12 @@ static void ats_write64(CPUARMState *env, const ARMCPRegInfo *ri,
             }
             break;
         case 4: /* AT S1E2R, AT S1E2W */
-            mmu_idx = ARMMMUIdx_E2;
+            if (arm_hcr_el2_eff(env) & HCR_E2H) {
+                mmu_idx = env->pstate & PSTATE_PAN ?
+                    ARMMMUIdx_E20_2_PAN : ARMMMUIdx_E20_2;
+            } else {
+                mmu_idx = ARMMMUIdx_E2;
+            }
             break;
         case 6: /* AT S1E3R, AT S1E3W */
             mmu_idx = ARMMMUIdx_E3;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 15 lines · Ake Koomsin

When HCR_E2H is set, AT S1E2R and AT S1E2W should translate an address based on both TTBR0_EL2 and TTBR1_EL2.

---
 target/arm/helper.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
target/arm/helper.c +0 -0
index dde64a487a..147f96e752 100644
@@ -3486,7 +3486,12 @@ static void ats_write64(CPUARMState *env, const ARMCPRegInfo *ri,
             }

target/arm/helper.c static void ats_write64(CPUARMState *env, const ARMCPRegInfo *ri, · line 3495

Quoted 10 lines
target/arm/helper.c +6 -1
             break;
         case 4: /* AT S1E2R, AT S1E2W */
-            mmu_idx = ARMMMUIdx_E2;
+            if (arm_hcr_el2_eff(env) & HCR_E2H) {
+                mmu_idx = env->pstate & PSTATE_PAN ?
+                    ARMMMUIdx_E20_2_PAN : ARMMMUIdx_E20_2;
+            } else {
+                mmu_idx = ARMMMUIdx_E2;
+            }
             break;

I agree that the AT insns should be handling E2H, but I'm not sure this is the right fix, and with Richard's recent refactorings I've kind of lost track of what all our MMUIdxes do.

In the pseudocode, E2H is handled by changing the behaviour not just of the S1E2 ops, but also of the S1E1 ops. If E2H is set:
* the S1E2 ops use the EL2&0 regime, but continue to ignore PSTATE.PAN
* the S1E1 ops also use the EL2&0 regime, with the S1E1RP and S1E1WP ops looking at PSTATE.PAN and the others not

Richard -- do we want to just do the same thing, or do our MMUIdx uses differ from the architectural translation regimes in a way that means we need to do something else?

thanks
-- PMM

#2 lore raw
Quoted 10 lines · Peter Maydell

In the pseudocode, E2H is handled by changing the behaviour not just of the S1E2 ops, but also of the S1E1 ops. If E2H is set:
* the S1E2 ops use the EL2&0 regime, but continue to ignore PSTATE.PAN
* the S1E1 ops also use the EL2&0 regime, with the S1E1RP and S1E1WP ops looking at PSTATE.PAN and the others not

Richard -- do we want to just do the same thing, or do our MMUIdx uses differ from the architectural translation regimes in a way that means we need to do something else?

We want to do the same thing. The *_PAN MMUIdx are intended to be exactly like the architecture, when PAN is enabled and not ignored.

r~

author
#3 lore raw
In reply to Peter Maydell
Quoted 38 lines · On Tue, 25 Oct 2022 13:25:22 +0100 Peter Maydell <[email protected]>…
Quoted 15 lines · Ake Koomsin

When HCR_E2H is set, AT S1E2R and AT S1E2W should translate an address based on both TTBR0_EL2 and TTBR1_EL2.

---
 target/arm/helper.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
target/arm/helper.c +0 -0
index dde64a487a..147f96e752 100644
@@ -3486,7 +3486,12 @@ static void ats_write64(CPUARMState *env,
 const ARMCPRegInfo *ri, }

target/arm/helper.c static void ats_write64(CPUARMState *env, · line 3495

Quoted 10 lines
target/arm/helper.c +6 -1
             break;
         case 4: /* AT S1E2R, AT S1E2W */
-            mmu_idx = ARMMMUIdx_E2;
+            if (arm_hcr_el2_eff(env) & HCR_E2H) {
+                mmu_idx = env->pstate & PSTATE_PAN ?
+                    ARMMMUIdx_E20_2_PAN : ARMMMUIdx_E20_2;
+            } else {
+                mmu_idx = ARMMMUIdx_E2;
+            }
             break;

I agree that the AT insns should be handling E2H, but I'm not sure this is the right fix, and with Richard's recent refactorings I've kind of lost track of what all our MMUIdxes do.

In the pseudocode, E2H is handled by changing the behaviour not just of the S1E2 ops, but also of the S1E1 ops. If E2H is set:
* the S1E2 ops use the EL2&0 regime, but continue to ignore PSTATE.PAN
* the S1E1 ops also use the EL2&0 regime, with the S1E1RP and S1E1WP ops looking at PSTATE.PAN and the others not

Quoted 6 lines

Richard -- do we want to just do the same thing, or do our MMUIdx uses differ from the architectural translation regimes in a way that means we need to do something else?

thanks
-- PMM

I will re-read the AT instruction pseudocode and will come back with a better fix. It might take a while as I am not familiar with the code base. Thank you very much for comments.

---
Ake Koomsin