-
Notifications
You must be signed in to change notification settings - Fork 8.4k
riscv: pmp: enable stackguard without multithreading #80546
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
riscv: pmp: enable stackguard without multithreading #80546
Conversation
3daae59 to
0cf9211
Compare
|
We need to have some guarantee that this code has test coverage. |
fkokosinski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code itself LGTM, but I agree with @cfriedt - we'd need to have some testing for this.
There're at least 3 places where we could add/modify a test:
tests/kernel/threads/no-multithreading- it's already enabled on RISC-V QEMU-based targets, but I'm not sure if this is the right place to add memory protection related tests. Probably not.tests/kernel/mem_protect/mem_protect- we could add a RISC-V specific no multithreading testcase here- we could add a separate arch-specific test in e.g.
tests/arch/riscv/pmp(ARM has one inzephyr/tests/arch/arm/arm_mem_protect).
It should probably be both 2 and 3.
Thank you for pointing in right direction, I'll work on extending the test cases in next commit. |
Without multithreading only two stacks present: ISR and main. As any stack they also could overflow, so it make sense to add stack guard for them also. Remove stack guard dependency on multithreading and mark `Z_RISCV_STACK_GUARD_SIZE` bytes at the beginning of stack as read-only region with PMP entry. Signed-off-by: Volodymyr Fialko <[email protected]>
0cf9211 to
d76fdd2
Compare
fkokosinski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for adding the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... but if we want to go this route, then I'd rather use EXTRA_CFLAGS here and change VIA_TWISTER to something sounding less generic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Test if PMP protected regions prevents write access. Signed-off-by: Volodymyr Fialko <[email protected]>
d76fdd2 to
2b13028
Compare
|
|
||
| tests: | ||
| arch.riscv.pmp.no-mt.isr-stack-guard: | ||
| extra_args: EXTRA_CFLAGS=-DPMP_TEST_FUNC_IDX=0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could have used Kconfig instead? i.e. CONFIG_TEST_ISR_STACK_GUARD / CONFIG_TEST_MAIN_STACK_GUARD, and enable it here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Kconfig option usually meant to allow user to tweak something.
Here it's already possible to select different tests by name, so I don't see benefits in using Kconfig.
|
Hi @f0rget-the-sad! To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge. Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁 |
|
Hi @f0rget-the-sad, unfortunately this PR broke the project CI run on main (https://github.com/zephyrproject-rtos/zephyr/actions/runs/11934344226), the fix is not obvious to me so I've opened a revert PR #81673. Would you be able to troubleshoot and re-submit a new version that works in CI? (or open a hotfix if that's obvious to you). Apologies for the extra work. |
|
This PR passed all checks triggered by CI: https://github.com/zephyrproject-rtos/zephyr/actions/runs/11893366338 |
Yeah the test sets can be different, you can get the list of failed tests from https://github.com/zephyrproject-rtos/zephyr/runs/33270031021 and run those manually, for example for $ west build -p -b qemu_riscv64/qemu_virt_riscv64 -T tests/kernel/fatal/no-multithreading/kernel.no-mt.arbitrary_reason
$ west build -t run
...
FAIL - test_fatal in 0.000 seconds
===================================================================
===================================================================
PROJECT EXECUTION FAILED |
|
Ok, I manually tested tests/kernel/fatal/no-multithreading, tests/kernel/threads/no-multithreading and tests/lib/multi_heap (seems like all failures reported by main CI)with this hotfix: #81676 |
|
@f0rget-the-sad thanks for the quick turnaround. |
Without multithreading only two stacks present: ISR and main. As any stack they also could overflow, so it make sense to add stack guard for them also.
Remove stack guard dependency on multithreading and mark
Z_RISCV_STACK_GUARD_SIZEbytes at the beginning of stack as read-only region with PMP entry.