Skip to content

Commit

Permalink
Merge pull request #572 from peterfang/fix-bootmem-alignment
Browse files Browse the repository at this point in the history
svsm_paging: Ensure page alignment during invalidation
  • Loading branch information
joergroedel authored Dec 17, 2024
2 parents 911877e + 369da23 commit 25d5f15
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 25d5f15

Please sign in to comment.