Skip to contentSkip to conversation

target/arm: Use correct mmu_idx for exception-return unstacking

PATCH In review Peter Maydell 2 participants 3 messages Jul 9, 2018 – Jul 10, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/arm: Use correct mmu_idx for exception-return unstacking

For M-profile exception returns, the mmu index to use for exception return unstacking is supposed to be that of wherever we are returning to:
* if returning to handler mode, privileged
* if returning to thread mode, privileged or unprivileged depending on CONTROL.nPRIV for the destination security state

We were passing the wrong thing as the 'priv' argument to arm_v7m_mmu_idx_for_secstate_and_priv(). The effect was that guests which programmed the MPU to behave differently for privileged and unprivileged code could get spurious MemManage Unstack exceptions.

---
 target/arm/helper.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
target/arm/helper.c +3 -1
index a2ac96084e7..0604a0efbe2 100644
@@ -7171,9 +7171,11 @@ static void do_v7m_exception_exit(ARMCPU *cpu)
         uint32_t frameptr = *frame_sp_p;
         bool pop_ok = true;
         ARMMMUIdx mmu_idx;
+        bool return_to_priv = return_to_handler ||
+            !(env->v7m.control[return_to_secure] & R_V7M_CONTROL_NPRIV_MASK);
 
         mmu_idx = arm_v7m_mmu_idx_for_secstate_and_priv(env, return_to_secure,
-                                                        !return_to_handler);
+                                                        return_to_priv);
 
         if (!QEMU_IS_ALIGNED(frameptr, 8) &&
             arm_feature(env, ARM_FEATURE_V8)) {
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Peter Maydell

For M-profile exception returns, the mmu index to use for exception return unstacking is supposed to be that of wherever we are returning to:
* if returning to handler mode, privileged
* if returning to thread mode, privileged or unprivileged depending on CONTROL.nPRIV for the destination security state

We were passing the wrong thing as the 'priv' argument to arm_v7m_mmu_idx_for_secstate_and_priv(). The effect was that guests which programmed the MPU to behave differently for privileged and unprivileged code could get spurious MemManage Unstack exceptions.

Quoted 5 lines
---
 target/arm/helper.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

r~

#2 lore raw
Quoted 12 lines · Richard Henderson
Quoted 11 lines · Peter Maydell

For M-profile exception returns, the mmu index to use for exception return unstacking is supposed to be that of wherever we are returning to:
* if returning to handler mode, privileged
* if returning to thread mode, privileged or unprivileged depending on CONTROL.nPRIV for the destination security state

We were passing the wrong thing as the 'priv' argument to arm_v7m_mmu_idx_for_secstate_and_priv(). The effect was that guests which programmed the MPU to behave differently for privileged and unprivileged code could get spurious MemManage Unstack exceptions.

Quoted 7 lines
Quoted 5 lines
---
 target/arm/helper.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Thanks; applied to master for 3.0-rc0.

-- PMM