[PULL 17/24] target/arm: Catch illegal-exception-return from EL3 with bad NSE/NS

2023-08-31 Thread Peter Maydell
The architecture requires (R_TYTWB) that an attempt to return from EL3 when SCR_EL3.{NSE,NS} are {1,0} is an illegal exception return. (This enforces that the CPU can't ever be executing below EL3 with the NSE,NS bits indicating an invalid security state.) We were missing this check; a

Re: [PATCH] target/arm: Catch illegal-exception-return from EL3 with bad NSE/NS

2023-08-07 Thread Richard Henderson
On 8/7/23 08:06, Peter Maydell wrote: The architecture requires (R_TYTWB) that an attempt to return from EL3 when SCR_EL3.{NSE,NS} are {1,0} is an illegal exception return. (This enforces that the CPU can't ever be executing below EL3 with the NSE,NS bits indicating an invalid security

[PATCH] target/arm: Catch illegal-exception-return from EL3 with bad NSE/NS

2023-08-07 Thread Peter Maydell
The architecture requires (R_TYTWB) that an attempt to return from EL3 when SCR_EL3.{NSE,NS} are {1,0} is an illegal exception return. (This enforces that the CPU can't ever be executing below EL3 with the NSE,NS bits indicating an invalid security state.) We were missing this check; a

[PULL 40/61] target/riscv: Don't save pc when exception return

2022-01-21 Thread Alistair Francis
From: LIU Zhiwei As pc will be written by the xepc in exception return, just ignore pc in translation. Signed-off-by: LIU Zhiwei Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis Message-id: 20220120122050.41546-3-zhiwei_...@c-sky.com Signed-off-by: Alistair Francis --- target

[PATCH v8 02/23] target/riscv: Don't save pc when exception return

2022-01-20 Thread LIU Zhiwei
As pc will be written by the xepc in exception return, just ignore pc in translation. Signed-off-by: LIU Zhiwei Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/helper.h | 4 ++-- target/riscv/insn_trans/trans_privileged.c.inc | 7

[PATCH v7 02/22] target/riscv: Don't save pc when exception return

2022-01-18 Thread LIU Zhiwei
As pc will be written by the xepc in exception return, just ignore pc in translation. Signed-off-by: LIU Zhiwei Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/helper.h | 4 ++-- target/riscv/insn_trans/trans_privileged.c.inc | 7

[PATCH v6 02/22] target/riscv: Don't save pc when exception return

2022-01-13 Thread LIU Zhiwei
As pc will be written by the xepc in exception return, just ignore pc in translation. Signed-off-by: LIU Zhiwei Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/helper.h | 4 ++-- target/riscv/insn_trans/trans_privileged.c.inc | 7

Re: Exception return

2021-12-16 Thread abhijeet inamdar
38d R01= R02=7004938c R03= >> > > R04=7005e410 R05=10020000 R06=e000eda0 R07= >> > > R08=0010 R09=1003f8e0 R10=e000ed94 R11= >> > > R12= R13=1003dbe0 R14=fff9 R15=7004e794 >> > > XPSR=0103 --

Re: Exception return

2021-12-16 Thread abhijeet inamdar
: 0x7f4faa471100 [/7004e794/0x312000c1] Hal_MemFault > > > R00=7004938d R01= R02=7004938c R03= > > > R04=7005e410 R05=1002 R06=e000eda0 R07= > > > R08=0010 R09=1003f8e0 R10=e000ed94 R11= > > > R12=ffff R13=1003dbe

Re: Exception return

2021-12-16 Thread Peter Maydell
On Thu, 16 Dec 2021 at 20:07, abhijeet inamdar wrote: > > If I won't make that change it gives me immediate error as follows: > > Taking exception 18 [v7M INVSTATE UsageFault] > ...BusFault with BFSR.STKERR > ...taking pending nonsecure exception 3 > qemu: fatal: Lockup: can't take terminal derive

Re: Exception return

2021-12-16 Thread Peter Maydell
4=7005e410 R05=1002 R06=e000eda0 R07= > > R08=0010 R09=1003f8e0 R10=e000ed94 R11= > > R12= R13=1003dbe0 R14=fff9 R15=7004e794 > > XPSR=0103 T handler > > Taking exception 8 [QEMU v7M exception exit] > > Exception return: magi

Re: Exception return

2021-12-16 Thread Philippe Mathieu-Daudé
e0 R14=fff9 R15=7004e794 > XPSR=0103 T handler > Taking exception 8 [QEMU v7M exception exit] > Exception return: magic PC fff9 previous exception 3 > M profile return from interrupt with misaligned PC is UNPREDICTABLE on v7M > ...successful exception return

[PATCH v5 02/22] target/riscv: Don't save pc when exception return

2021-11-24 Thread LIU Zhiwei
As pc will be written by the xepc in exception return, just ignore pc in translation. Signed-off-by: LIU Zhiwei Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/helper.h | 4 ++-- target/riscv/insn_trans/trans_privileged.c.inc | 7

Re: [PATCH v4 01/20] target/riscv: Don't save pc when exception return

2021-11-14 Thread Alistair Francis
On Fri, Nov 12, 2021 at 1:54 AM LIU Zhiwei wrote: > > As pc will be written by the xepc in exception return, just ignore > pc in translation. > > Signed-off-by: LIU Zhiwei > Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis Alistair > --- >

[PATCH v4 01/20] target/riscv: Don't save pc when exception return

2021-11-11 Thread LIU Zhiwei
As pc will be written by the xepc in exception return, just ignore pc in translation. Signed-off-by: LIU Zhiwei Reviewed-by: Richard Henderson --- target/riscv/helper.h | 4 ++-- target/riscv/insn_trans/trans_privileged.c.inc | 7 ++- target/riscv/op_helper.c

[PATCH v3 01/20] target/riscv: Don't save pc when exception return

2021-11-10 Thread LIU Zhiwei
As pc will be written by the xepc in exception return, just ignore pc in translation. Signed-off-by: LIU Zhiwei Reviewed-by: Richard Henderson --- target/riscv/helper.h | 4 ++-- target/riscv/insn_trans/trans_privileged.c.inc | 7 ++- target/riscv/op_helper.c

Re: [PATCH v2 13/14] target/riscv: Don't save pc when exception return

2021-11-10 Thread Richard Henderson
On 11/10/21 8:04 AM, LIU Zhiwei wrote: As pc will be written by the xepc in exception return, just ignore pc in translation. Signed-off-by: LIU Zhiwei Reviewed-by: Richard Henderson --- target/riscv/helper.h | 4 ++-- target/riscv/insn_trans/trans_privileged.c.inc

[PATCH v2 13/14] target/riscv: Don't save pc when exception return

2021-11-09 Thread LIU Zhiwei
As pc will be written by the xepc in exception return, just ignore pc in translation. Signed-off-by: LIU Zhiwei Reviewed-by: Richard Henderson --- target/riscv/helper.h | 4 ++-- target/riscv/insn_trans/trans_privileged.c.inc | 7 ++- target/riscv/op_helper.c

Re: [PATCH 11/13] target/riscv: Switch context in exception return

2021-11-08 Thread LIU Zhiwei
We only have to process the special CSRs(like vtype/misa) when xlen changes,  according to the explicitly  specified behavior about the CSR width change behavior. For normal CSRs, the default behavior in section 2.4 , CSR Width Modulation, is enough. And if we split the vill out, we will never

Re: [PATCH 11/13] target/riscv: Switch context in exception return

2021-11-08 Thread LIU Zhiwei
We only have to process the special CSRs(like vtype/misa) when xlen changes,  according to the explicitly  specified behavior about the CSR width change behavior. For normal CSRs, the default behavior in section 2.4 , CSR Width Modulation, is enough. And if we split the vill out, we will never

Re: [PATCH 11/13] target/riscv: Switch context in exception return

2021-11-08 Thread LIU Zhiwei
On 2021/11/2 上午12:43, Richard Henderson wrote: On 11/1/21 6:01 AM, LIU Zhiwei wrote: After excpetion return, we should give a xlen view of context in new priveledge, including the general registers, pc, and CSRs. Signed-off-by: LIU Zhiwei ---   target/riscv/helper.h |

Re: [PATCH 12/13] target/riscv: Don't save pc when exception return

2021-11-01 Thread Richard Henderson
On 11/1/21 6:01 AM, LIU Zhiwei wrote: As pc will be written by the xepc in exception return, just ignore pc in translation. Signed-off-by: LIU Zhiwei --- target/riscv/helper.h | 4 ++-- target/riscv/insn_trans/trans_privileged.c.inc | 7 ++- target/riscv

Re: [PATCH 11/13] target/riscv: Switch context in exception return

2021-11-01 Thread Richard Henderson
On 11/1/21 6:01 AM, LIU Zhiwei wrote: After excpetion return, we should give a xlen view of context in new priveledge, including the general registers, pc, and CSRs. Signed-off-by: LIU Zhiwei --- target/riscv/helper.h | 1 + .../riscv/insn_trans/trans_privileged.c.in

[PATCH 12/13] target/riscv: Don't save pc when exception return

2021-11-01 Thread LIU Zhiwei
As pc will be written by the xepc in exception return, just ignore pc in translation. Signed-off-by: LIU Zhiwei --- target/riscv/helper.h | 4 ++-- target/riscv/insn_trans/trans_privileged.c.inc | 7 ++- target/riscv/op_helper.c | 4 ++-- 3

[PATCH 11/13] target/riscv: Switch context in exception return

2021-11-01 Thread LIU Zhiwei
After excpetion return, we should give a xlen view of context in new priveledge, including the general registers, pc, and CSRs. Signed-off-by: LIU Zhiwei --- target/riscv/helper.h | 1 + .../riscv/insn_trans/trans_privileged.c.inc | 2 ++ target/riscv/op_helper.c

[PULL 009/114] target/arm: Use correct SP in M-profile exception return

2021-05-25 Thread Peter Maydell
When an M-profile CPU is restoring registers from the stack on exception return, the stack pointer to use is determined based on bits in the magic exception return type value. We were not getting this logic entirely correct. Whether we use one of the Secure stack pointers or one of the Non

Re: [PATCH] target/arm: Use correct SP in M-profile exception return

2021-05-24 Thread Richard Henderson
On 5/20/21 6:09 AM, Peter Maydell wrote: When an M-profile CPU is restoring registers from the stack on exception return, the stack pointer to use is determined based on bits in the magic exception return type value. We were not getting this logic entirely correct. Whether we use one of the

[PATCH] target/arm: Use correct SP in M-profile exception return

2021-05-20 Thread Peter Maydell
When an M-profile CPU is restoring registers from the stack on exception return, the stack pointer to use is determined based on bits in the magic exception return type value. We were not getting this logic entirely correct. Whether we use one of the Secure stack pointers or one of the Non

[PULL 29/36] target/arm: Implement new v8.1M NOCP check for exception return

2020-12-10 Thread Peter Maydell
In v8.1M a new exception return check is added which may cause a NOCP UsageFault (see rule R_XLTP): before we clear s0..s15 and the FPSCR we must check whether access to CP10 from the Security state of the returning exception is disabled; if it is then we must take a fault. (Note that for our

Re: [PATCH v2 19/28] target/arm: Implement new v8.1M NOCP check for exception return

2020-12-01 Thread Richard Henderson
On 11/19/20 3:56 PM, Peter Maydell wrote: > In v8.1M a new exception return check is added which may cause a NOCP > UsageFault (see rule R_XLTP): before we clear s0..s15 and the FPSCR > we must check whether access to CP10 from the Security state of the > returning exception is disabl

[PATCH v2 19/28] target/arm: Implement new v8.1M NOCP check for exception return

2020-11-19 Thread Peter Maydell
In v8.1M a new exception return check is added which may cause a NOCP UsageFault (see rule R_XLTP): before we clear s0..s15 and the FPSCR we must check whether access to CP10 from the Security state of the returning exception is disabled; if it is then we must take a fault. (Note that for our

[PATCH 19/55] target/arm: Don't abort on M-profile exception return in linux-user mode

2019-11-05 Thread Michael Roth
From: Peter Maydell An attempt to do an exception-return (branch to one of the magic addresses) in linux-user mode for M-profile should behave like a normal branch, because linux-user mode is always going to be in 'handler' mode. This used to work, but we broke it when we added support

[PATCH 73/97] target/arm: Don't abort on M-profile exception return in linux-user mode

2019-10-01 Thread Michael Roth
From: Peter Maydell An attempt to do an exception-return (branch to one of the magic addresses) in linux-user mode for M-profile should behave like a normal branch, because linux-user mode is always going to be in 'handler' mode. This used to work, but we broke it when we added support

[Qemu-devel] [PULL 21/21] target/arm: Don't abort on M-profile exception return in linux-user mode

2019-09-03 Thread Peter Maydell
An attempt to do an exception-return (branch to one of the magic addresses) in linux-user mode for M-profile should behave like a normal branch, because linux-user mode is always going to be in 'handler' mode. This used to work, but we broke it when we added support for the M-profil

Re: [Qemu-devel] [PATCH] target/arm: Don't abort on M-profile exception return in linux-user mode

2019-08-22 Thread Richard Henderson
On 8/22/19 6:15 AM, Peter Maydell wrote: > The upshot of all this is that for linux-user mode we should never > do any of the bx_excret magic, so the code change is simple. > > This ought to be a weird corner case that only affects broken guest > code (because Linux user processes should never be

[Qemu-devel] [PATCH] target/arm: Don't abort on M-profile exception return in linux-user mode

2019-08-22 Thread Peter Maydell
An attempt to do an exception-return (branch to one of the magic addresses) in linux-user mode for M-profile should behave like a normal branch, because linux-user mode is always going to be in 'handler' mode. This used to work, but we broke it when we added support for the M-profil

[Qemu-devel] [PULL 18/42] target/arm: Handle floating point registers in exception return

2019-04-29 Thread Peter Maydell
Handle floating point registers in exception return. This corresponds to pseudocode functions ValidateExceptionReturn(), ExceptionReturn(), PopStack() and ConsumeExcStackFrame(). Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20190416125744.27770-16-peter.mayd

Re: [Qemu-devel] [PATCH 15/26] target/arm: Handle floating point registers in exception return

2019-04-23 Thread Richard Henderson
On 4/16/19 5:57 AM, Peter Maydell wrote: > Handle floating point registers in exception return. > This corresponds to pseudocode functions ValidateExceptionReturn(), > ExceptionReturn(), PopStack() and ConsumeExcStackFrame(). > > Signed-off-by: Peter Maydell > --- > targ

[Qemu-devel] [PATCH 15/26] target/arm: Handle floating point registers in exception return

2019-04-16 Thread Peter Maydell
Handle floating point registers in exception return. This corresponds to pseudocode functions ValidateExceptionReturn(), ExceptionReturn(), PopStack() and ConsumeExcStackFrame(). Signed-off-by: Peter Maydell --- target/arm/helper.c | 142 +++- 1 file

[Qemu-devel] [PULL 01/22] target/arm: Fix PC test for LDM (exception return)

2019-03-05 Thread Peter Maydell
From: Richard Henderson Found by inspection: Rn is the base register against which the load began; I is the register within the mask being processed. The exception return should of course be processed from the loaded PC. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé

Re: [Qemu-devel] [PATCH] target/arm: Fix PC test for LDM (exception return)

2019-03-04 Thread Peter Maydell
On Sat, 2 Mar 2019 at 19:10, Philippe Mathieu-Daudé wrote: > > On 3/1/19 9:29 PM, Richard Henderson wrote: > > Found by inspection: Rn is the base register against which the > > load began; I is the register within the mask being processed. > > The exception return shou

Re: [Qemu-devel] [PATCH] target/arm: Fix PC test for LDM (exception return)

2019-03-02 Thread Philippe Mathieu-Daudé
On 3/1/19 9:29 PM, Richard Henderson wrote: > Found by inspection: Rn is the base register against which the > load began; I is the register within the mask being processed. > The exception return should of course be procesed from the loaded PC. "processed" > > Signed-

[Qemu-devel] [PATCH] target/arm: Fix PC test for LDM (exception return)

2019-03-01 Thread Richard Henderson
Found by inspection: Rn is the base register against which the load began; I is the register within the mask being processed. The exception return should of course be procesed from the loaded PC. Signed-off-by: Richard Henderson --- target/arm/translate.c | 2 +- 1 file changed, 1 insertion

[Qemu-devel] [PULL 03/49] target/arm: Allow Aarch32 exception return to switch from Mon->Hyp

2019-01-18 Thread Peter Maydell
From: Alexander Graf In U-boot, we switch from S-SVC -> Mon -> Hyp mode when we want to enter Hyp mode. The change into Hyp mode is done by doing an exception return from Mon. This doesn't work with current QEMU. The problem is that in bad_mode_switch() we refuse to allow the cha

[Qemu-devel] [PULL 11/45] target/arm: Improve debug logging of AArch32 exception return

2018-10-19 Thread Peter Maydell
For AArch32, exception return happens through certain kinds of CPSR write. We don't currently have any CPU_LOG_INT logging of these events (unlike AArch64, where we log in the ERET instruction). Add some suitable logging. This will log exception returns like this: Exception return from AA

Re: [Qemu-devel] [PATCH 01/10] target/arm: Improve debug logging of AArch32 exception return

2018-10-14 Thread Richard Henderson
On 10/12/18 7:42 AM, Peter Maydell wrote: > For AArch32, exception return happens through certain kinds > of CPSR write. We don't currently have any CPU_LOG_INT logging > of these events (unlike AArch64, where we log in the ERET > instruction). Add some suitable logging. &

[Qemu-devel] [PATCH 01/10] target/arm: Improve debug logging of AArch32 exception return

2018-10-12 Thread Peter Maydell
For AArch32, exception return happens through certain kinds of CPSR write. We don't currently have any CPU_LOG_INT logging of these events (unlike AArch64, where we log in the ERET instruction). Add some suitable logging. This will log exception returns like this: Exception return from AA

Re: [Qemu-devel] [PATCH for-3.0] target/arm: Use correct mmu_idx for exception-return unstacking

2018-07-10 Thread Peter Maydell
On 9 July 2018 at 15:30, Richard Henderson wrote: > On 07/09/2018 05:45 AM, Peter Maydell wrote: >> 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 han

Re: [Qemu-devel] [PATCH for-3.0] target/arm: Use correct mmu_idx for exception-return unstacking

2018-07-09 Thread Richard Henderson
On 07/09/2018 05:45 AM, Peter Maydell wrote: > 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

[Qemu-devel] [PATCH for-3.0] target/arm: Use correct mmu_idx for exception-return unstacking

2018-07-09 Thread 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

[Qemu-devel] [PULL 05/20] target/arm: Don't switch to target stack early in v7M exception return

2017-10-06 Thread Peter Maydell
Currently our M profile exception return code switches to the target stack pointer relatively early in the process, before it tries to pop the exception frame off the stack. This is awkward for v8M for two reasons: * in v8M the process vs main stack pointer is not selected purely by the value

[Qemu-devel] [PULL 07/20] target/arm: Restore security state on exception return

2017-10-06 Thread Peter Maydell
Now that we can handle the CONTROL.SPSEL bit not necessarily being in sync with the current stack pointer, we can restore the correct security state on exception return. This happens before we start to read registers off the stack frame, but after we have taken possible usage faults for bad

[Qemu-devel] [PULL 11/20] target/arm: Don't warn about exception return with PC low bit set for v8M

2017-10-06 Thread Peter Maydell
In the v8M architecture, return from an exception to a PC which has bit 0 set is not UNPREDICTABLE; it is defined that bit 0 is discarded [R_HRJH]. Restrict our complaint about this to v7M. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Message-i

[Qemu-devel] [PULL 08/20] target/arm: Restore SPSEL to correct CONTROL register on exception return

2017-10-06 Thread Peter Maydell
On exception return for v8M, the SPSEL bit in the EXC_RETURN magic value should be restored to the SPSEL bit in the CONTROL register banked specified by the EXC_RETURN.ES bit. Add write_v7m_control_spsel_for_secstate() which behaves like write_v7m_control_spsel() but allows the caller to specify

Re: [Qemu-devel] [PATCH 02/20] target/arm: Don't switch to target stack early in v7M exception return

2017-10-06 Thread Richard Henderson
; this is because we also use this > * function in handling of pushing of the callee-saves registers > * part of the v8M stack frame (pseudocode PushCalleeStack()), > * and in the tailchain codepath the SPSEL bit comes from the exception > * return magic LR value fro

Re: [Qemu-devel] [PATCH 02/20] target/arm: Don't switch to target stack early in v7M exception return

2017-10-06 Thread Peter Maydell
n the >>> + * SPSEL control bit value; this is because we also use this >>> + * function in handling of pushing of the callee-saves registers >>> + * part of the v8M stack frame, and in that case the SPSEL bit >>> + * comes from the exception return

Re: [Qemu-devel] [PATCH 08/20] target/arm: Don't warn about exception return with PC low bit set for v8M

2017-10-05 Thread Richard Henderson
On 10/05/2017 12:32 PM, Richard Henderson wrote: > if (env->regs[15] & 1) { > if (!arm_feature(env, ARM_FEATURE_V8)) { > qemu_log_mask(...); > } > env->regs[15] &= ~1U; > } Bah. Even better to move the bit clear statement before the feature check. The t

Re: [Qemu-devel] [PATCH 08/20] target/arm: Don't warn about exception return with PC low bit set for v8M

2017-10-05 Thread Richard Henderson
On 09/22/2017 10:59 AM, Peter Maydell wrote: > +if ((env->regs[15] & 1) && !arm_feature(env, ARM_FEATURE_V8)) { > qemu_log_mask(LOG_GUEST_ERROR, >"M profile return from interrupt with misaligned " > - "PC is UNPREDICTABLE\n")

Re: [Qemu-devel] [PATCH 02/20] target/arm: Don't switch to target stack early in v7M exception return

2017-10-05 Thread Peter Maydell
On 5 October 2017 at 17:04, Richard Henderson wrote: > On 09/22/2017 10:59 AM, Peter Maydell wrote: >> Currently our M profile exception return code switches to the >> target stack pointer relatively early in the process, before >> it tries to pop the exception frame o

Re: [Qemu-devel] [PATCH 05/20] target/arm: Restore SPSEL to correct CONTROL register on exception return

2017-10-05 Thread Richard Henderson
On 09/22/2017 10:59 AM, Peter Maydell wrote: > On exception return for v8M, the SPSEL bit in the EXC_RETURN magic > value should be restored to the SPSEL bit in the CONTROL register > banked specified by the EXC_RETURN.ES bit. > > Add write_v7m_control_spsel_for_secstate() whi

Re: [Qemu-devel] [PATCH 04/20] target/arm: Restore security state on exception return

2017-10-05 Thread Richard Henderson
On 09/22/2017 10:59 AM, Peter Maydell wrote: > Now that we can handle the CONTROL.SPSEL bit not necessarily being > in sync with the current stack pointer, we can restore the correct > security state on exception return. This happens before we start > to read registers off the stac

Re: [Qemu-devel] [PATCH 02/20] target/arm: Don't switch to target stack early in v7M exception return

2017-10-05 Thread Richard Henderson
On 09/22/2017 10:59 AM, Peter Maydell wrote: > Currently our M profile exception return code switches to the > target stack pointer relatively early in the process, before > it tries to pop the exception frame off the stack. This is > awkward for v8M for two reasons: > * in v8M

Re: [Qemu-devel] [PATCH 02/20] target/arm: Don't switch to target stack early in v7M exception return

2017-10-04 Thread Philippe Mathieu-Daudé
On 09/22/2017 11:59 AM, Peter Maydell wrote: > Currently our M profile exception return code switches to the > target stack pointer relatively early in the process, before > it tries to pop the exception frame off the stack. This is > awkward for v8M for two reasons: > * in v8M

[Qemu-devel] [PATCH 05/20] target/arm: Restore SPSEL to correct CONTROL register on exception return

2017-09-22 Thread Peter Maydell
On exception return for v8M, the SPSEL bit in the EXC_RETURN magic value should be restored to the SPSEL bit in the CONTROL register banked specified by the EXC_RETURN.ES bit. Add write_v7m_control_spsel_for_secstate() which behaves like write_v7m_control_spsel() but allows the caller to specify

[Qemu-devel] [PATCH 02/20] target/arm: Don't switch to target stack early in v7M exception return

2017-09-22 Thread Peter Maydell
Currently our M profile exception return code switches to the target stack pointer relatively early in the process, before it tries to pop the exception frame off the stack. This is awkward for v8M for two reasons: * in v8M the process vs main stack pointer is not selected purely by the value

[Qemu-devel] [PATCH 04/20] target/arm: Restore security state on exception return

2017-09-22 Thread Peter Maydell
Now that we can handle the CONTROL.SPSEL bit not necessarily being in sync with the current stack pointer, we can restore the correct security state on exception return. This happens before we start to read registers off the stack frame, but after we have taken possible usage faults for bad

[Qemu-devel] [PATCH 08/20] target/arm: Don't warn about exception return with PC low bit set for v8M

2017-09-22 Thread Peter Maydell
In the v8M architecture, return from an exception to a PC which has bit 0 set is not UNPREDICTABLE; it is defined that bit 0 is discarded [R_HRJH]. Restrict our complaint about this to v7M. Signed-off-by: Peter Maydell --- target/arm/helper.c | 20 +--- 1 file changed, 13 inserti

Re: [Qemu-devel] target/arm: Fix abort on exception return from AArch64 to AArch32

2017-07-12 Thread Alex Bennée
.c b/target/arm/op_helper.c >> index 2a85666..8222c19 100644 >> --- a/target/arm/op_helper.c >> +++ b/target/arm/op_helper.c >> @@ -1027,6 +1027,9 @@ void HELPER(exception_return)(CPUARMState *env) >> } else { >> env->regs[15] = env->

Re: [Qemu-devel] target/arm: Fix abort on exception return from AArch64 to AArch32

2017-07-12 Thread Peter Maydell
1027,9 @@ void HELPER(exception_return)(CPUARMState *env) > } else { > env->regs[15] = env->elr_el[cur_el] & ~0x3; > } > + > +env->pc = env->regs[15]; > + > qemu_log_mask(CPU_LOG_INT, "Exception return from AArch64

[Qemu-devel] target/arm: Fix abort on exception return from AArch64 to AArch32

2017-07-12 Thread Jaroslaw Pelczar
..8222c19 100644 --- a/target/arm/op_helper.c +++ b/target/arm/op_helper.c @@ -1027,6 +1027,9 @@ void HELPER(exception_return)(CPUARMState *env) } else { env->regs[15] = env->elr_el[cur_el] & ~0x3; } + +env->pc = env->regs[15]; + qemu_log_ma

[Qemu-devel] [PULL 23/24] arm: Implement M profile exception return properly

2017-04-20 Thread Peter Maydell
specially but then catching the attempt to execute from the magic address value. This is not ideal, because: * there are guest visible differences from the architecturally specified behaviour (for instance jumping to 0xFFxx via a different instruction should not cause an exception return but

[Qemu-devel] [PULL 24/24] arm: Remove workarounds for old M-profile exception return implementation

2017-04-20 Thread Peter Maydell
Now that we've rewritten M-profile exception return so that the magic PC values are not visible to other parts of QEMU, we can delete the special casing of them elsewhere. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Message-id: 14918

Re: [Qemu-devel] [PATCH v2 0/9] arm: Implement M profile exception return properly

2017-04-20 Thread Peter Maydell
arm: Track M profile handler mode state in TB flags >> arm: Implement M profile exception return properly >> arm: Remove workarounds for old M-profile exception return >> implementation >> >> target/arm/cpu.h | 9 +++ &g

Re: [Qemu-devel] [PATCH v2 0/9] arm: Implement M profile exception return properly

2017-04-15 Thread Richard Henderson
t_pc_im() up in the file arm: Move condition-failed codepath generation out of if() arm: Abstract out "are we singlestepping" test to utility function arm: Track M profile handler mode state in TB flags arm: Implement M profile exception return properly arm: Remove workarounds fo

[Qemu-devel] [PATCH v2 9/9] arm: Remove workarounds for old M-profile exception return implementation

2017-04-10 Thread Peter Maydell
Now that we've rewritten M-profile exception return so that the magic PC values are not visible to other parts of QEMU, we can delete the special casing of them elsewhere. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- target/arm/cpu.c

[Qemu-devel] [PATCH v2 8/9] arm: Implement M profile exception return properly

2017-04-10 Thread Peter Maydell
specially but then catching the attempt to execute from the magic address value. This is not ideal, because: * there are guest visible differences from the architecturally specified behaviour (for instance jumping to 0xFFxx via a different instruction should not cause an exception return but

[Qemu-devel] [PATCH v2 0/9] arm: Implement M profile exception return properly

2017-04-10 Thread Peter Maydell
exception return but it will in the QEMU implementation) * we have to account for it in various places (like refusing to take an interrupt if the PC is at a magic value, and making sure that the MPU doesn't deny execution at the magic value addresses) Drop these hacks, and in

Re: [Qemu-devel] [Qemu-arm] [PATCH 6/7] arm: Implement M profile exception return properly

2017-04-10 Thread Peter Maydell
ception != 0) in the TB flags and test that here rather than testing IS_USER. (Otherwise if you have code which executes the same 'bx' instruction both as a legitimate exception return and as a fake exception return while in privileged thread mode then we assert() in do_v7m_exception_exit.

Re: [Qemu-devel] [Qemu-arm] [PATCH 6/7] arm: Implement M profile exception return properly

2017-04-10 Thread Peter Maydell
On 10 April 2017 at 14:52, Philippe Mathieu-Daudé wrote: > On 04/10/2017 07:39 AM, Peter Maydell wrote: >> +/* Is the new PC value in the magic range indicating exception >> return? */ >> +tcg_gen_brcondi_i32(TCG_COND_GEU, cpu_R[15], 0xff00, >> excret_la

Re: [Qemu-devel] [Qemu-arm] [PATCH 7/7] arm: Remove workarounds for old M-profile exception return implementation

2017-04-10 Thread Philippe Mathieu-Daudé
On 04/10/2017 07:39 AM, Peter Maydell wrote: Now that we've rewritten M-profile exception return so that the magic PC values are not visible to other parts of QEMU, we can delete the special casing of them elsewhere. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-

Re: [Qemu-devel] [Qemu-arm] [PATCH 6/7] arm: Implement M profile exception return properly

2017-04-10 Thread Philippe Mathieu-Daudé
instruction should not cause an exception return but it will in the QEMU implementation) * we have to account for it in various places (like refusing to take an interrupt if the PC is at a magic value, and making sure that the MPU doesn't deny execution at the magic value addresses) Drop

[Qemu-devel] [PATCH 6/7] arm: Implement M profile exception return properly

2017-04-10 Thread Peter Maydell
but then catching the attempt to execute from the magic address value. This is not ideal, because: * there are guest visible differences from the architecturally specified behaviour (for instance jumping to 0xFFxx via a different instruction should not cause an exception return but it

[Qemu-devel] [PATCH 0/7] arm: Implement M profile exception return properly

2017-04-10 Thread Peter Maydell
ement exception return the way the architecture specifies -- by having the relevant instructions check for the magic value and raise the 'do an exception return' QEMU internal exception immediately. I realised when I was looking at the MPU patches that the current mechanism was a bit awk

[Qemu-devel] [PATCH 7/7] arm: Remove workarounds for old M-profile exception return implementation

2017-04-10 Thread Peter Maydell
Now that we've rewritten M-profile exception return so that the magic PC values are not visible to other parts of QEMU, we can delete the special casing of them elsewhere. Signed-off-by: Peter Maydell --- target/arm/cpu.c | 43 ++- targe

[Qemu-devel] [PULL 22/30] armv7m: Check exception return consistency

2017-02-27 Thread Peter Maydell
Implement the exception return consistency checks described in the v7M pseudocode ExceptionReturn(). Inspired by a patch from Michael Davidsaver's series, but this is a reimplementation from scratch based on the ARM ARM pseudocode. Signed-off-by: Peter Maydell Reviewed-by: Alex B

Re: [Qemu-devel] [PATCH v2 11/13] armv7m: Check exception return consistency

2017-02-24 Thread Alex Bennée
Peter Maydell writes: > Implement the exception return consistency checks > described in the v7M pseudocode ExceptionReturn(). > > Inspired by a patch from Michael Davidsaver's series, but > this is a reimplementation from scratch based on the > ARM ARM pseudocode. &

[Qemu-devel] [PATCH v2 11/13] armv7m: Check exception return consistency

2017-02-16 Thread Peter Maydell
Implement the exception return consistency checks described in the v7M pseudocode ExceptionReturn(). Inspired by a patch from Michael Davidsaver's series, but this is a reimplementation from scratch based on the ARM ARM pseudocode. Signed-off-by: Peter Maydell --- target/arm/cpu.h

Re: [Qemu-devel] [PATCH] target-arm/translate.c: fix movs pc, lr exception return on ARMv7

2016-10-15 Thread Alex Bennée
Peter Maydell writes: > On 14 October 2016 at 16:13, Alex Bennée wrote: >> This was broken by the fix for 9b6a3ea7a699594162ed3d11e4e04b98568dc5c0. >> Specifically a movs pc,lr in the kernels ret_fast_syscall returning to >> some thumb mode user space code but store_reg unconditionally aligned

Re: [Qemu-devel] [PATCH] target-arm/translate.c: fix movs pc, lr exception return on ARMv7

2016-10-14 Thread Peter Maydell
On 14 October 2016 at 16:13, Alex Bennée wrote: > I suspect we need to audit all calls to store_reg that might involve the > PC to ensure "interworking" branches are correctly handled. Also I'm not > quite sure how the code worked before 9b6a3e as the store_reg path > wouldn't have triggered the s

Re: [Qemu-devel] [PATCH] target-arm/translate.c: fix movs pc, lr exception return on ARMv7

2016-10-14 Thread Peter Maydell
On 14 October 2016 at 16:13, Alex Bennée wrote: > This was broken by the fix for 9b6a3ea7a699594162ed3d11e4e04b98568dc5c0. > Specifically a movs pc,lr in the kernels ret_fast_syscall returning to > some thumb mode user space code but store_reg unconditionally aligned > the return PC instead of tre

[Qemu-devel] [PATCH] target-arm/translate.c: fix movs pc, lr exception return on ARMv7

2016-10-14 Thread Alex Bennée
This was broken by the fix for 9b6a3ea7a699594162ed3d11e4e04b98568dc5c0. Specifically a movs pc,lr in the kernels ret_fast_syscall returning to some thumb mode user space code but store_reg unconditionally aligned the return PC instead of treating the return as an "interworking" branch. I suspect

Re: [Qemu-devel] [PATCH 2/2] target-arm: Fix an exception return on AArch32 instruction ADDS

2016-05-04 Thread Peter Maydell
On 19 April 2016 at 19:07, Sergey Sorokin wrote: > In AArch32 instruction ADDS r15, ... is used for exception return. > > Signed-off-by: Sergey Sorokin > --- > target-arm/translate.c | 15 --- > 1 file changed, 12 insertions(+), 3 deletions(-) > > diff --git

Re: [Qemu-devel] [PATCH 1/2] target-arm: Unify AArch32 exception return generating functions

2016-05-04 Thread Peter Maydell
On 19 April 2016 at 19:07, Sergey Sorokin wrote: > There is a duplicating code in AArch32 exception return implementation. > The patch rearranges the code to avoid this. > > Signed-off-by: Sergey Sorokin > --- > target-arm/translate.c | 36 +---

[Qemu-devel] [PATCH 1/2] target-arm: Unify AArch32 exception return generating functions

2016-04-19 Thread Sergey Sorokin
There is a duplicating code in AArch32 exception return implementation. The patch rearranges the code to avoid this. Signed-off-by: Sergey Sorokin --- target-arm/translate.c | 36 +--- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/target-arm

[Qemu-devel] [PATCH 0/2] Unify and fix exception return in AArch32 state

2016-04-19 Thread Sergey Sorokin
There is a duplicating code in AArch32 exception return implementation. Also there is a missed exception return on AArch32 instruction ADDS r15. The patches rearrange the code and fix these issues. Sergey Sorokin (2): target-arm: Unify AArch32 exception return generating functions target-arm

[Qemu-devel] [PATCH 2/2] target-arm: Fix an exception return on AArch32 instruction ADDS

2016-04-19 Thread Sergey Sorokin
In AArch32 instruction ADDS r15, ... is used for exception return. Signed-off-by: Sergey Sorokin --- target-arm/translate.c | 15 --- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/target-arm/translate.c b/target-arm/translate.c index 68671b7..3e64ba9 100644 --- a

[Qemu-devel] [PULL 01/20] target-arm: Give CPSR setting on 32-bit exception return its own helper

2016-02-26 Thread Peter Maydell
The rules for setting the CPSR on a 32-bit exception return are subtly different from those for setting the CPSR via an instruction like MSR or CPS. (In particular, in Hyp mode changing the mode bits is not valid via MSR or CPS.) Split the exception-return case into its own helper for setting CPSR

Re: [Qemu-devel] [PATCH 01/11] target-arm: Give CPSR setting on 32-bit exception return its own helper

2016-02-18 Thread Sergey Fedorov
On 15.02.2016 20:22, Peter Maydell wrote: > The rules for setting the CPSR on a 32-bit exception return are > subtly different from those for setting the CPSR via an instruction > like MSR or CPS. (In particular, in Hyp mode changing the mode bits > is not valid via MSR or CPS

[Qemu-devel] [PATCH 01/11] target-arm: Give CPSR setting on 32-bit exception return its own helper

2016-02-15 Thread Peter Maydell
The rules for setting the CPSR on a 32-bit exception return are subtly different from those for setting the CPSR via an instruction like MSR or CPS. (In particular, in Hyp mode changing the mode bits is not valid via MSR or CPS.) Split the exception-return case into its own helper for setting CPSR

Re: [Qemu-devel] [Qemu-arm] [PATCH 8/8] target-arm: ignore ELR_ELx[1] for exception return to 32-bit ARM mode

2016-01-29 Thread Sergey Fedorov
On 14.01.2016 21:34, Peter Maydell wrote: > The architecture requires that for an exception return to AArch32 the > low bits of ELR_ELx are ignored when the PC is set from them: > * if returning to Thumb mode, ignore ELR_ELx[0] > * if returning to ARM mode, ignore ELR_ELx[1:0] >

  1   2   >