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

Create kernel stack with correct size and set up a guard page #335

Merged
merged 7 commits into from
Feb 6, 2023

Conversation

phil-opp
Copy link
Member

The last page of stack memory was not used before (see #294 ) because we initialized the stack pointer with the start address of the inclusive end page of the stack. This PR fixes this by initializing the stack pointer with the exact configured address, aligned to a 16-byte boundary. To verify that this works, I added a new min_stack test that tries booting with a kernel stack size of just 3000 bytes.

We also claimed in the docs that we set up a guard page for the kernel stack, but never actually did this. This PR fixes that issue too by allocating an extra page when creating the virtual kernel stack mapping. We then leave the first page of that allocation unmapped so that a page fault will occur when the kernel overflows its stack.

To ensure that user-configured addresses have the correct alignment, I also added an alignment check to the mapping_addr function. There is also a new convenience function for allocating page-aligned virtual regions.

Fixes #294

The last page of stack memory was not used before because we initialized the stack pointer with the start address of the inclusive end page of the stack. This commit fixes this by initializing the stack pointer with the exact configured address, aligned to a 16-byte boundary.
Also: Add a convenience function for allocating page-aligned mappings.
@phil-opp
Copy link
Member Author

cc @inhibitor1217 @tsoutsman

@phil-opp phil-opp merged commit 52a0a67 into main Feb 6, 2023
@phil-opp phil-opp deleted the kernel-stack-fixes branch February 6, 2023 10:08
@phil-opp phil-opp mentioned this pull request Mar 12, 2023
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.

Last page of stack memory is not used
1 participant