Skip to content

Commit

Permalink
svsm_paging: Ensure page alignment during invalidation
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
peterfang committed Dec 17, 2024
1 parent 8b5bc8a commit 369da23
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions kernel/src/svsm_paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::mm::pagetable::{PTEntryFlags, PageTable};
use crate::mm::PageBox;
use crate::platform::{PageStateChangeOp, PageValidateOp, SvsmPlatform};
use crate::types::PageSize;
use crate::utils::MemoryRegion;
use crate::utils::{page_align_up, MemoryRegion};
use bootlib::kernel_launch::KernelLaunchInfo;

struct IgvmParamInfo<'a> {
Expand Down Expand Up @@ -100,17 +100,23 @@ fn invalidate_boot_memory_region(
config: &SvsmConfig<'_>,
region: MemoryRegion<PhysAddr>,
) -> Result<(), SvsmError> {
// Caller must ensure the memory region's starting address is page-aligned
let aligned_region = MemoryRegion::new(region.start(), page_align_up(region.len()));
log::info!(
"Invalidating boot region {:018x}-{:018x}",
region.start(),
region.end()
aligned_region.start(),
aligned_region.end()
);

if !region.is_empty() {
platform.validate_physical_page_range(region, PageValidateOp::Invalidate)?;
if !aligned_region.is_empty() {
platform.validate_physical_page_range(aligned_region, PageValidateOp::Invalidate)?;

if config.page_state_change_required() {
platform.page_state_change(region, PageSize::Regular, PageStateChangeOp::Shared)?;
platform.page_state_change(
aligned_region,
PageSize::Regular,
PageStateChangeOp::Shared,
)?;
}
}

Expand Down

0 comments on commit 369da23

Please sign in to comment.