vmbase: Support 16KiB MMIO_GUARD granule
Now that the MMIO_GUARD sharing/unsharing is decoupled from the page
tables, add support for 16KiB (and possibly beyond) by getting rid of
the hard-coded assumption that MMIO_GUARD happens with 4KiB granularity
by expecting potentially more than one page fault per MMIO_GUARD region
with MMIO lazy mapping.
Address the special case of the UART separately (see comment there).
Remove the now-obsolete hard-coded MMIO_GUARD_GRANULE_SIZE.
Bug: 336563593
Test: m libpvmfw libvmbase_example librialto
Change-Id: I5d8e169d9c2ad022208de3d33f346f5034d13393
diff --git a/vmbase/src/entry.rs b/vmbase/src/entry.rs
index 892dc9f..bb5ccef 100644
--- a/vmbase/src/entry.rs
+++ b/vmbase/src/entry.rs
@@ -15,13 +15,13 @@
//! Rust entry point.
use crate::{
- bionic, console, heap,
- hyp::{self, MMIO_GUARD_GRANULE_SIZE},
- logger,
+ bionic, console, heap, hyp, logger,
+ memory::{page_4kb_of, SIZE_16KB, SIZE_4KB},
power::{reboot, shutdown},
rand,
};
use core::mem::size_of;
+use static_assertions::const_assert_eq;
fn try_console_init() -> Result<(), hyp::Error> {
console::init();
@@ -31,8 +31,19 @@
// TODO(ptosi): Use MmioSharer::share() to properly track this MMIO_GUARD_MAP.
//
- // MmioSharer only supports MMIO_GUARD_GRANULE_SIZE so fail early here if needed.
- assert_eq!(mmio_guard.granule()?, MMIO_GUARD_GRANULE_SIZE);
+ // The following call shares the UART but also anything else present in 0..granule.
+ //
+ // For 4KiB, that's only the UARTs. For 16KiB, it also covers the RTC and watchdog but, as
+ // neither is used by vmbase clients (and as both are outside of the UART page), they
+ // will never have valid stage-1 mappings to those devices. As a result, this
+ // MMIO_GUARD_MAP isn't affected by the granule size in any visible way. Larger granule
+ // sizes will need to be checked separately, if needed.
+ assert!({
+ let granule = mmio_guard.granule()?;
+ granule == SIZE_4KB || granule == SIZE_16KB
+ });
+ // Validate the assumption above by ensuring that the UART is not moved to another page:
+ const_assert_eq!(page_4kb_of(console::BASE_ADDRESS), 0);
mmio_guard.map(console::BASE_ADDRESS)?;
}