ARM: NOMMU: Fix exc_ret for stack frame type
PATCH 1/1 ARM: NOMMU: Fix exc_ret for stack frame type
commit 72cd4064fcca ("ARM: 8830/1: NOMMU: Toggle only bits in EXC_RETURN we are really care of") only sets BIT[3] for Thread mode and BIT[2] for PSP, it leaves BIT[4] untouched. But there's such a
case: the pre-linux env makes use of FPU then the BIT[4] in 'lr' is cleared, this brings an umatch issue since the NOMMU kernel doesn't support FPU yet. Before the above commit, we hardcode the exc_ret as 0xfffffffd, so the flow works fine.
Fix this issue by explicitly set BIT[4] which means using standard stack frame.
--- arch/arm/include/asm/v7m.h | 1 + arch/arm/mm/proc-v7m.S | 1 + 2 files changed, 2 insertions(+)
arch/arm/include/asm/v7m.h +1 -0
@@ -51,6 +51,7 @@*/ #define EXC_RET_STACK_MASK 0x00000004#define EXC_RET_THREADMODE_PROCESSSTACK (3 << 2) +#define EXC_RET_FTYPE (1 << 4)/* Cache related definitions */
arch/arm/mm/proc-v7m.S +1 -0
@@ -138,6 +138,7 @@ __v7m_setup_cont: 1: cpsid i /* Calculate exc_ret */ orr r10, lr, #EXC_RET_THREADMODE_PROCESSSTACK + orr r10, #EXC_RET_FTYPE ldmia sp, {r0-r3, r12} str r5, [r12, #11 * 4] @ restore the original SVC vector entry mov lr, r6 @ restore LR
Signature · 1 line
2.45.2
Quoted 5 lines · Jisheng Zhang
commit
72cd4064fcca("ARM: 8830/1: NOMMU: Toggle only bits inEXC_RETURNwe are really care of") only sets BIT[3] for Thread mode and BIT[2] for PSP, it leaves BIT[4] untouched. But there's such a
case: the pre-linux env makes use of FPU then the BIT[4] in 'lr' is cleared, this brings an umatch issue since the NOMMU kernel doesn't
Can pre-linux env disable FPU before passing control to kernel (which is, as correctly pointed, doesn't know how to use FPU)?
Cheers
Vladimir
Quoted 9 lines · Vladimir Murzin
Quoted 5 lines · Jisheng Zhang
commit
72cd4064fcca("ARM: 8830/1: NOMMU: Toggle only bits inEXC_RETURNwe are really care of") only sets BIT[3] for Thread mode and BIT[2] for PSP, it leaves BIT[4] untouched. But there's such a
case: the pre-linux env makes use of FPU then the BIT[4] in 'lr' is cleared, this brings an umatch issue since the NOMMU kernel doesn'tCan pre-linux env disable FPU before passing control to kernel (which is, as correctly pointed, doesn't know how to use FPU)?
IIRC, I did a experiment like this by clearing the SCB CPACR related bits, but the stack frame type is still not correct. I searched in the armv8m arm or cortex-mN's TRM I didn't find the relation between the returned "lr" and the pre FPU usage.
What's more, IMHO, kernel needs to use the correct exc_ret no matter the pre-linux env does, I.E if kernel/userspace supports FPU, then clear BIT[4]; if no, set BIT[4].
PS: this is a regression: before the commit, the have-used-fpu pre-linux env + linux nommu combination works; after the commit, it fails to execute the init due to wrong stack frame type.
Thanks
Vladimir Murzin
Reviewed-byQuoted 18 lines · Jisheng Zhang
Quoted 8 lines · Vladimir Murzin
Quoted 5 lines · Jisheng Zhang
commit
72cd4064fcca("ARM: 8830/1: NOMMU: Toggle only bits inEXC_RETURNwe are really care of") only sets BIT[3] for Thread mode and BIT[2] for PSP, it leaves BIT[4] untouched. But there's such a
case: the pre-linux env makes use of FPU then the BIT[4] in 'lr' is cleared, this brings an umatch issue since the NOMMU kernel doesn'tCan pre-linux env disable FPU before passing control to kernel (which is, as correctly pointed, doesn't know how to use FPU)?
IIRC, I did a experiment like this by clearing the SCB CPACR related bits, but the stack frame type is still not correct. I searched in the armv8m arm or cortex-mN's TRM I didn't find the relation between the returned "lr" and the pre FPU usage.
What's more, IMHO, kernel needs to use the correct
exc_retno matter the pre-linux env does, I.E if kernel/userspace supports FPU, then clear BIT[4]; if no, set BIT[4].
Quoted 6 lines
PS: this is a regression: before the commit, the have-used-fpu pre-linux env + linux nommu combination works; after the commit, it fails to execute the init due to wrong stack frame type.
Thanks
Fair enough.
Please, upload the patch in RMK's patch system [1]
[1] https://www.arm.linux.org.uk/developer/patches/
Vladimir