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

arch: riscv: stacktrace: user thread stack bound check is wrong #76398

Closed
ycsin opened this issue Jul 29, 2024 · 2 comments · Fixed by #75564 or #76380
Closed

arch: riscv: stacktrace: user thread stack bound check is wrong #76398

ycsin opened this issue Jul 29, 2024 · 2 comments · Fixed by #75564 or #76380
Assignees
Labels
bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug Stale

Comments

@ycsin
Copy link
Member

ycsin commented Jul 29, 2024

Describe the bug
The calculation of the stack bounds is wrong according to the riscv's arch.h:

 +------------+ <- thread.arch.priv_stack_start
 | Guard      | } Z_RISCV_STACK_GUARD_SIZE
 +------------+
 | Priv Stack | } CONFIG_PRIVILEGED_STACK_SIZE
 +------------+ <- thread.arch.priv_stack_start +
                   CONFIG_PRIVILEGED_STACK_SIZE +
                   Z_RISCV_STACK_GUARD_SIZE

The start of the privilege stack should be:

thread.arch.priv_stack_start + Z_RISCV_STACK_GUARD_SIZE

Instead of

thread.arch.priv_stack_start - CONFIG_PRIVILEGED_STACK_SIZE

This resulted in empty call trace when the exception happens in a userspace thread.

To Reproduce
Steps to reproduce the behavior:

  1. Check out v3.7.0
  2. west build -b qemu_riscv64 -p auto -t run -T zephyr/tests/kernel/mem_protect/userspace/kernel.memory_protection.userspace
  3. Exception message of test_unimplemented_syscall doesn't contain call traces:
START - test_unimplemented_syscall
E: Unimplemented system call
E: call trace:
E:
E: >>> ZEPHYR FATAL ERROR 3: Kernel oops on CPU 0
E: Current thread: 0x80020ba8 (test_unimplemented_syscall)
Caught system error -- reason 3
System error was expected
 PASS - test_unimplemented_syscall in 0.004 seconds

Expected behavior
There should be call traces:

START - test_unimplemented_syscall
E: Unimplemented system call
E: call trace:
E:       0: ra: 00000000800034b6
E:       1: ra: 00000000800005d0
E:       2: ra: 0000000080003660
E:       3: ra: 00000000800029e0
E:       4: ra: 00000000800029fa
E:       5: ra: 0000000080002b08
E:       6: ra: 0000000080002b16
E:       7: ra: 000000008000d51e
E:
E: >>> ZEPHYR FATAL ERROR 3: Kernel oops on CPU 0
E: Current thread: 0x80020ba8 (test_unimplemented_syscall)
Caught system error -- reason 3
System error was expected
 PASS - test_unimplemented_syscall in 0.006 seconds

Impact
No call traces in userspace

Environment (please complete the following information):

  • Commit SHA or Version used: Zephyr v3.7.0
@ycsin ycsin added the bug The issue is a bug, or the PR is fixing a bug label Jul 29, 2024
@ycsin ycsin linked a pull request Jul 29, 2024 that will close this issue
@ycsin ycsin self-assigned this Jul 29, 2024
@jhedberg jhedberg added the priority: medium Medium impact/importance bug label Jul 30, 2024
Copy link

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions bot added the Stale label Sep 29, 2024
@ycsin
Copy link
Member Author

ycsin commented Sep 30, 2024

Fixed in #75564 and backported in #76380

@ycsin ycsin closed this as completed Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug Stale
Projects
None yet
2 participants