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

Privileged Task Call Stack Idea #5

Open
wants to merge 9 commits into
base: ARM_CRx_MPU
Choose a base branch
from

Conversation

Skptak
Copy link
Owner

@Skptak Skptak commented Dec 29, 2023

Description

Very lazy idea for how to move the privileged call stacks out of the TCBs

Test Steps

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Skptak and others added 5 commits February 26, 2024 11:01
* Apply git review patch created by @aggargr
* Add necessary changes to the CMakeLists.txt file to build the port
Update the comment for configKERNEL_INTERRUPT_PRIORITY in the template
FreeRTOSConfig.h.

It was reported here - https://forums.freertos.org/t/migration-from-v10-5-1-to-v11-0-1-fails-with-new-freertosconfig-h-file/19276/

Signed-off-by: Gaurav Aggarwal <[email protected]>
* pxIndex should only be used when selecting next task. Altering pxIndex
  of a ready list will cause the scheduler to be unable to select the
  right task to run. Using a for loop if traversing the list for trace
  utility is required.
* Not defining listGET_OWNER_OF_NEXT_ENTRY when using SMP scheduler

---------

Co-authored-by: Gaurav-Aggarwal-AWS <[email protected]>
@Skptak Skptak force-pushed the PrivilegedTaskStackIdea branch from 384621b to d95451d Compare March 6, 2024 18:46
Skptak added 4 commits March 7, 2024 10:53
Idea is to statically declare stacks that can then be turned into MPU regions.
In order to prevent accidental overflows/underflows an MPU region is set around the stack that does not allow privileged writes.
I then use MPU sub-regions to disable writing to the top and bottom 8th of the stack.
This way if an accidental overflow/underflow occurs it will hit the section that doesn't allow writes, causing a data abort.
However, in order to do this the task stack region has to be a higher priority region than portPRIVILEGED_RAM_REGION.
This is because if portPRIVILEGED_RAM_REGION is a higher numeric region, it would over-write the MPU region on the call stack that doesn't allow writes.
This commit has the code that performs this change wrapped in an if 0 block while I tested just changing portSTACK_REGION to be a higher priority region than portPRIVILEGED_RAM_REGION.
This commit also has a bit of a proof of concept for trying to do this with only two registers.
Idea is to use the LDREX and STREX instructions, which according to ARM replace the deprecated SWP instruction.
But going to leave that alone for now and work on just getting this to actually work before looking into that.
Save MPU Settings for the Call Stack as part of the struct.
Use subregions to not allow writes to the end and start of it.
Use scratch registers to load/save the MPU settings.
Could look into getting it to work without needing scratch registers, but think that leads to a much longer entrance/exit.
Add an additional check for the xPortIsAuthorizedToAccessBuffer() to look at the MPU settings saved in xSYSTEM_CALL_STACK_BUFFER if pulTaskStackPointer != NULL.
… it can build without a change to the demos FreeRTOSConfig files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants