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

svsm_paging: Ensure page alignment during invalidation #572

Merged
merged 1 commit into from
Dec 17, 2024

Conversation

peterfang
Copy link
Contributor

Boot memory regions aren't always page-aligned. For example, kernel_fs_end cannot always be page-aligned because the size of the FS area has to match that of its original image exactly. Make sure the memory region always has a page-aligned size in
invalidate_boot_memory_region(). The starting address is always checked during page invalidation so just assume the caller will do the right thing.

kernel/src/svsm_paging.rs Outdated Show resolved Hide resolved
Copy link
Member

@joergroedel joergroedel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see why this change is needed. Question(s): Can it cause problems elsewhere when we only enforce the alignment at this one call-site? Or would it be better to align the addresses in the page_state_change() platform call-backs?

kernel/src/svsm_paging.rs Outdated Show resolved Hide resolved
@peterfang
Copy link
Contributor Author

peterfang commented Dec 17, 2024

I see why this change is needed. Question(s): Can it cause problems elsewhere when we only enforce the alignment at this one call-site? Or would it be better to align the addresses in the page_state_change() platform call-backs?

Hi Joerg,

I checked all of the call sites for validate_physical_page_range() and validate_virtual_page_range() and this function is the only place right now where memory regions could be unaligned. The only other case that could cause this is if someone overrode the SVSM kernel region in QEMU to some odd, unaligned location in non-IGVM mode, but that doesn't sound like a normal case to me. page_state_change() is called after validate_physical_page_range() so for an unaligned memory region, the panic would be hit first.

Boot memory regions aren't always page-aligned. For example,
kernel_fs_end cannot always be page-aligned because the size of the FS
area has to match that of its original image exactly. Make sure the
memory region always has a page-aligned size in
invalidate_boot_memory_region(). The starting address is always checked
during page invalidation so just assume the caller will do the right
thing.

Signed-off-by: Peter Fang <[email protected]>
@peterfang peterfang force-pushed the fix-bootmem-alignment branch from 492763b to 369da23 Compare December 17, 2024 07:43
Copy link
Member

@joergroedel joergroedel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good the me now.

@joergroedel joergroedel added the ready-to-merge PR is ready for merging into main branch label Dec 17, 2024
@joergroedel
Copy link
Member

Will merge this after #577 and #578

@joergroedel joergroedel merged commit 25d5f15 into coconut-svsm:main Dec 17, 2024
4 checks passed
@peterfang peterfang deleted the fix-bootmem-alignment branch December 17, 2024 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge PR is ready for merging into main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants