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

tests/kernel/mem_protect/stackprot failure in frdm_k64f due to limited privilege stack size #13783

Closed
ioannisg opened this issue Feb 26, 2019 · 3 comments
Labels
area: ARM ARM (32-bit) Architecture area: Memory Protection bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug

Comments

@ioannisg
Copy link
Member

Describe the bug
stackprot test does not run properly on frdm_k64f, triggering a BusFault

To Reproduce
Steps to reproduce the behavior:

  1. mkdir build; cd build
  2. cmake -DBOARD=board\frdm_k64f ..
  3. make
  4. See error

Expected behavior
Test should pass.

Logs

***** Booting Zephyr OS v1.14.0-rc1-563-g51c8c550d8 *****
***** BUS FAULT *****
  Stacking error
  Imprecise data bus error
  NXP MPU error, port 3
    Mode: Supervisor, Data Address: 0x20002e08
    Type: Write, Master: 0, Regions: 0x8000
***** HARD FAULT *****
  Fault escalation (see below)
***** BUS FAULT *****
  Precise data bus error
  BFAR Address: 0x20002e08
  NXP MPU error, port 3
    Mode: Supervisor, Data Address: 0x20002e08
    Type: Read, Master: 0, Regions: 0x8000
***** Hardware exception *****
Current thread ID = 0x20000080
Faulting instruction address = 0x31b6
Fatal fault in ISR! Spinning...


Additional context
The test started failing after (45631c3). This commit forced the test to run on user mode. Alone, this is not a reason for the test to fail, but:

  • Running the test on user mode implies re-programming the MPU using (on ARM) the Privileged Stack, which has a limited default size (512 bytes)
  • Unfortunately, due to the re-work of MPU in Arch arm mpu re work #12817, the MPU re-programming uses, roughly, 250 bytes of stack memory
  • This test sets CONFIG_STACK_CANARIES=y, which, forces the compiler to embed more stuff into the stack frame(s).

Therefore, we are running out of privileged stack space, when re-programming the MPU, which causes a BusFault on accessing the Guard area.


Workaround:
Setting CONFIG_PRIVILEGED_STACK_SIZE=1024 makes the test pass.

While we do need to decrease the stack usage of MPU re-programming in ARM builds with User-mode, I believe, it is ok to have an increased size for privileged stack areas, when compiling with support for CANARIES, since, itself, that feature adds to the stack usage. That is, I propose:

config PRIVILEGED_STACK_SIZE
	int "Size of privileged stack"
	default 512 if MPU_STACK_GUARD || BUILTIN_STACK_GUARD
	default 512 if COVERAGE_GCOV
	default 384 if ARC
  >>>   default 1024 if ARM && STACK_CANARIES && (MPU_STACK_GUARD || BUILTIN_STACK_GUARD)
	default 256
	depends on ARCH_HAS_USERSPACE
@ioannisg ioannisg added bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug area: ARM ARM (32-bit) Architecture labels Feb 26, 2019
@andrewboie
Copy link
Contributor

This default is getting too complicated.
How was the original value of 256 arrived at?

@andrewboie
Copy link
Contributor

Based on discussion this morning we could perhaps just do:

config PRIVILEGED_STACK_SIZE
	int "Size of privileged stack"
	default 1024
	depends on ARCH_HAS_USERSPACE

@ioannisg
Copy link
Member Author

ioannisg commented Mar 7, 2019

#14090 fixes this one.

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 area: Memory Protection bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug
Projects
None yet
Development

No branches or pull requests

2 participants