vmbase: Move MMIO_GUARD granule check out of ::hyp
Validate the granule where it's being used to prepare for non-4KiB
granule sizes.
Note: No functional change intended.
Test: m libpvmfw libvmbase_example librialto
Change-Id: Ic8af83b8565815412127c8bc881e3bc795ae2639
diff --git a/vmbase/src/memory/shared.rs b/vmbase/src/memory/shared.rs
index d44d58a..e3a5978 100644
--- a/vmbase/src/memory/shared.rs
+++ b/vmbase/src/memory/shared.rs
@@ -386,8 +386,7 @@
impl MmioSharer {
fn new() -> Result<Self> {
- let granule = MMIO_GUARD_GRANULE_SIZE;
- const_assert_eq!(MMIO_GUARD_GRANULE_SIZE, PAGE_SIZE); // For good measure.
+ let granule = Self::get_granule()?;
let frames = BTreeSet::new();
// Allows safely calling util::unchecked_align_down().
@@ -396,6 +395,17 @@
Ok(Self { granule, frames })
}
+ fn get_granule() -> Result<usize> {
+ const_assert_eq!(MMIO_GUARD_GRANULE_SIZE, PAGE_SIZE); // For good measure.
+ let Some(mmio_guard) = get_mmio_guard() else {
+ return Ok(PAGE_SIZE);
+ };
+ match mmio_guard.granule()? {
+ MMIO_GUARD_GRANULE_SIZE => Ok(MMIO_GUARD_GRANULE_SIZE),
+ granule => Err(MemoryTrackerError::UnsupportedMmioGuardGranule(granule)),
+ }
+ }
+
/// Share the MMIO region aligned to the granule size containing addr (not validated as MMIO).
fn share(&mut self, addr: VirtualAddress) -> Result<VaRange> {
// This can't use virt_to_phys() since 0x0 is a valid MMIO address and we are ID-mapped.