Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HardFault regression detected on Cortex-M0+ following Cortex-R introduction #38421

Closed
ABOSTM opened this issue Sep 9, 2021 · 1 comment · Fixed by #38422
Closed

HardFault regression detected on Cortex-M0+ following Cortex-R introduction #38421

ABOSTM opened this issue Sep 9, 2021 · 1 comment · Fixed by #38422
Assignees
Labels
area: ARM ARM (32-bit) Architecture bug The issue is a bug, or the PR is fixing a bug

Comments

@ABOSTM
Copy link
Collaborator

ABOSTM commented Sep 9, 2021

Describe the bug
A bunch of tests are now reported failed on Cortex-M0+ based board (nucleo_g071rb, nucleo_l073rz).
Regression occurs since merge of Cortex-R PR: #28231

To Reproduce
Steps to reproduce the behavior:

  1. west build -p auto -b nucleo_g071rb tests/kernel/mutex/mutex_api/
  2. west flash
  3. See error

Logs and console output

*** Booting Zephyr OS build zephyr-v2.6.0-2072-gb055054d417b  ***
Running test suite mutex_api
===================================================================
START - test_mutex_lock_unlock
E: ***** HARD FAULT *****

Environment (please complete the following information):

  • OS: both. Linux and Windows
  • Toolchain Zephyr SDK
  • Commit SHA : 4ffb90f202f832c7a6f1eca0fedb030354583946d
@ABOSTM ABOSTM added bug The issue is a bug, or the PR is fixing a bug area: ARM ARM (32-bit) Architecture labels Sep 9, 2021
@ABOSTM ABOSTM self-assigned this Sep 9, 2021
@ABOSTM
Copy link
Collaborator Author

ABOSTM commented Sep 9, 2021

Analysis
Regression has been introduced in arch\arm\core\aarch32\userspace.S
by e0bed3b "arch: arm: cortex_r: Add MPU and USERSPACE support"
(PR #28231)

It introuced unintended ASM instruction " msr PSP, ip" for CONFIG_ARMV6_M_ARMV8_M_BASELINE:
code :

#if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE)
    /* set stack back to unprivileged stack */
    mov ip, r0
    mov r0, sp
    ldr r0, [r0,#12]
    msr PSP, r0
    /* Restore r0 */
    mov r0, ip

#elif defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE) \
    || defined(CONFIG_CPU_CORTEX_R)
    /* set stack back to unprivileged stack */
    ldr ip, [sp,#12]
#endif

#if defined(CONFIG_CPU_CORTEX_R)
    mov sp, ip
#else
    msr PSP, ip
#endif

as been replaced by

#if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE)
    /* set stack back to unprivileged stack */
    mov ip, r0
    mov r0, sp
    ldr r0, [r0,#12]
    msr PSP, r0
    /* Restore r0 */
    mov r0, ip

#elif defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE) \
    || defined(CONFIG_CPU_CORTEX_R)
    /* set stack back to unprivileged stack */
    ldr ip, [sp,#12]
#endif

#if defined(CONFIG_CPU_CORTEX_R)
    mov sp, ip
#else
    msr PSP, ip
#endif

Thus "msr PSP, ip" is present to all arch expect cortex-R whereas it was initially not present for ARMV6_M_ARMV8_M_BASELINE

ABOSTM added a commit to ABOSTM/zephyr that referenced this issue Sep 9, 2021
Regression introduced on ARMV6_M_ARMV8_M_BASELINE by Cortex-R PR zephyrproject-rtos#28231
Fixes zephyrproject-rtos#38421

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
nashif pushed a commit that referenced this issue Sep 9, 2021
Regression introduced on ARMV6_M_ARMV8_M_BASELINE by Cortex-R PR #28231
Fixes #38421

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ARM ARM (32-bit) Architecture bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant