diff --git a/kernel/src/platform/native.rs b/kernel/src/platform/native.rs index c8542089b..efa2d00b6 100644 --- a/kernel/src/platform/native.rs +++ b/kernel/src/platform/native.rs @@ -18,6 +18,9 @@ use crate::types::PageSize; use crate::utils::immut_after_init::ImmutAfterInitCell; use crate::utils::MemoryRegion; +#[cfg(debug_assertions)] +use crate::mm::virt_to_phys; + static CONSOLE_IO: NativeIOPort = NativeIOPort::new(); static CONSOLE_SERIAL: ImmutAfterInitCell> = ImmutAfterInitCell::uninit(); @@ -108,6 +111,18 @@ impl SvsmPlatform for NativePlatform { _region: MemoryRegion, _op: PageValidateOp, ) -> Result<(), SvsmError> { + #[cfg(debug_assertions)] + { + // Ensure that it is possible to translate this virtual address to + // a physical address. This is not necessary for correctness + // here, but since other platformss may rely on virtual-to-physical + // translation, it is helpful to force a translation here for + // debugging purposes just to help catch potential errors when + // testing on native. + for va in _region.iter_pages(PageSize::Regular) { + let _ = virt_to_phys(va); + } + } Ok(()) } diff --git a/kernel/src/platform/snp.rs b/kernel/src/platform/snp.rs index 42c60aea4..3ce5dd65d 100644 --- a/kernel/src/platform/snp.rs +++ b/kernel/src/platform/snp.rs @@ -25,6 +25,9 @@ use crate::types::PageSize; use crate::utils::immut_after_init::ImmutAfterInitCell; use crate::utils::MemoryRegion; +#[cfg(debug_assertions)] +use crate::mm::virt_to_phys; + use core::sync::atomic::{AtomicU32, Ordering}; static CONSOLE_IO: SVSMIOPort = SVSMIOPort::new(); @@ -182,6 +185,18 @@ impl SvsmPlatform for SnpPlatform { region: MemoryRegion, op: PageValidateOp, ) -> Result<(), SvsmError> { + #[cfg(debug_assertions)] + { + // Ensure that it is possible to translate this virtual address to + // a physical address. This is not necessary for correctness + // here, but since other platformss may rely on virtual-to-physical + // translation, it is helpful to force a translation here for + // debugging purposes just to help catch potential errors when + // testing on SNP. + for va in region.iter_pages(PageSize::Regular) { + let _ = virt_to_phys(va); + } + } pvalidate_range(region, PvalidateOp::from(op)) }