Draft: Verify page allocator #116
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the changes
This WIP MR verifies the page allocator implementation.
In the process, this refactors some parts of the functions in minor ways, most notably by pulling out parts of
add_memory_regioninto a separate functionfind_largest_page_size.This also fixes two potential bugs that were caught while verifying the implementation:
MemoryLayout::confidential_address_at_offset_boundeddoes not correctly check the upper bound (https://github.com/IBM/ACE-RISCV/blob/main/security-monitor/src/core/memory_layout/mod.rs#L161); interestingly, when I wrote it's specification, I didn't catch that; the spec correctly abstracts the incorrect code, but contradicts the pre-existing comment describing the intended behaviourPotential impact:
PageAllocator::add_memory_regionuses the check in this method for checking whether it exceeds the given memory regions. If there was another confidential memory region after the page token region, we would create overlapping memory regions. Currently not an issue, aspage_allocator_end = confidential_memory_end, but could be critical in combination with other bugs or with future changes.In the second loop inside
PageAllocator::add_memory_region(https://github.com/IBM/ACE-RISCV/blob/main/security-monitor/src/core/page_allocator/allocator.rs#L182), now inPageAllocator::find_largest_page_size, the condition is slightly wrong, leading us to not decrease the page size to allocate at in some cases.Potential impact: the tail part of the memory region is potentially wasted when it could be allocated.
Type of change
How to test this PR?
The changes to the implementation should be tested by checking that the security monitor is still able to spin up a VM.
The verification CI will currently fail; I will fix this as this MR progresses.