lib/hyp: Introduce MMIO_GUARD_GRANULE_SIZE

Our MMIO_GUARD implementation currently only supports 4KiB granules so
make this clear by using a dedicated (centralized) constant instead of
conflating it with the vmbase PAGE_SIZE.

Note: no functional change intended.

Test: m pvmfw_img
Change-Id: I17e5f5fc2713e667188933d4f92026e2103b1416
diff --git a/libs/hyp/src/hypervisor/common.rs b/libs/hyp/src/hypervisor/common.rs
index accef72..ec7d168 100644
--- a/libs/hyp/src/hypervisor/common.rs
+++ b/libs/hyp/src/hypervisor/common.rs
@@ -15,8 +15,12 @@
 //! This module regroups some common traits shared by all the hypervisors.
 
 use crate::error::Result;
+use crate::util::SIZE_4KB;
 use bitflags::bitflags;
 
+/// Expected MMIO guard granule size, validated during MMIO guard initialization.
+pub const MMIO_GUARD_GRANULE_SIZE: usize = SIZE_4KB;
+
 bitflags! {
     /// Capabilities that Hypervisor backends can declare support for.
     pub struct HypervisorCap: u32 {
diff --git a/libs/hyp/src/hypervisor/gunyah.rs b/libs/hyp/src/hypervisor/gunyah.rs
index b335c87..252430f 100644
--- a/libs/hyp/src/hypervisor/gunyah.rs
+++ b/libs/hyp/src/hypervisor/gunyah.rs
@@ -1,6 +1,5 @@
-use super::common::{Hypervisor, HypervisorCap};
+use super::common::{Hypervisor, HypervisorCap, MMIO_GUARD_GRANULE_SIZE};
 use crate::error::Result;
-use crate::util::SIZE_4KB;
 use uuid::{uuid, Uuid};
 
 pub(super) struct GunyahHypervisor;
@@ -31,7 +30,7 @@
     }
 
     fn memory_protection_granule(&self) -> Result<usize> {
-        Ok(SIZE_4KB)
+        Ok(MMIO_GUARD_GRANULE_SIZE)
     }
 
     fn has_cap(&self, _cap: HypervisorCap) -> bool {
diff --git a/libs/hyp/src/hypervisor/kvm.rs b/libs/hyp/src/hypervisor/kvm.rs
index 08eb891..a89f9b8 100644
--- a/libs/hyp/src/hypervisor/kvm.rs
+++ b/libs/hyp/src/hypervisor/kvm.rs
@@ -14,9 +14,9 @@
 
 //! Wrappers around calls to the KVM hypervisor.
 
-use super::common::{Hypervisor, HypervisorCap};
+use super::common::{Hypervisor, HypervisorCap, MMIO_GUARD_GRANULE_SIZE};
 use crate::error::{Error, Result};
-use crate::util::{page_address, SIZE_4KB};
+use crate::util::page_address;
 use core::fmt::{self, Display, Formatter};
 use smccc::{
     error::{positive_or_error_64, success_or_error_32, success_or_error_64},
@@ -83,7 +83,7 @@
     fn mmio_guard_init(&self) -> Result<()> {
         mmio_guard_enroll()?;
         let mmio_granule = mmio_guard_granule()?;
-        if mmio_granule != SIZE_4KB {
+        if mmio_granule != MMIO_GUARD_GRANULE_SIZE {
             return Err(Error::UnsupportedMmioGuardGranule(mmio_granule));
         }
         Ok(())
diff --git a/libs/hyp/src/hypervisor/mod.rs b/libs/hyp/src/hypervisor/mod.rs
index 394da2c..923a21d 100644
--- a/libs/hyp/src/hypervisor/mod.rs
+++ b/libs/hyp/src/hypervisor/mod.rs
@@ -24,6 +24,7 @@
 use alloc::boxed::Box;
 pub use common::Hypervisor;
 pub use common::HypervisorCap;
+pub use common::MMIO_GUARD_GRANULE_SIZE;
 use gunyah::GunyahHypervisor;
 pub use kvm::KvmError;
 use kvm::KvmHypervisor;
diff --git a/libs/hyp/src/lib.rs b/libs/hyp/src/lib.rs
index 694f957..2c2d1d6 100644
--- a/libs/hyp/src/lib.rs
+++ b/libs/hyp/src/lib.rs
@@ -21,4 +21,4 @@
 mod util;
 
 pub use error::{Error, Result};
-pub use hypervisor::{get_hypervisor, Hypervisor, HypervisorCap, KvmError};
+pub use hypervisor::{get_hypervisor, Hypervisor, HypervisorCap, KvmError, MMIO_GUARD_GRANULE_SIZE};
diff --git a/vmbase/src/memory/shared.rs b/vmbase/src/memory/shared.rs
index 568eb81..5284e30 100644
--- a/vmbase/src/memory/shared.rs
+++ b/vmbase/src/memory/shared.rs
@@ -15,7 +15,7 @@
 //! Shared memory management.
 
 use super::page_table::{is_leaf_pte, MMIO_LAZY_MAP_FLAG};
-use super::util::{virt_to_phys, PAGE_SIZE};
+use super::util::virt_to_phys;
 use aarch64_paging::paging::{Attributes, Descriptor, MemoryRegion as VaRange};
 use alloc::alloc::{alloc_zeroed, dealloc, handle_alloc_error};
 use alloc::vec::Vec;
@@ -23,7 +23,7 @@
 use core::alloc::Layout;
 use core::ptr::NonNull;
 use core::result;
-use hyp::get_hypervisor;
+use hyp::{get_hypervisor, MMIO_GUARD_GRANULE_SIZE};
 use log::{error, trace};
 
 /// Allocates memory on the heap and shares it with the host.
@@ -124,11 +124,11 @@
         );
         assert_eq!(
             va_range.len(),
-            PAGE_SIZE,
+            MMIO_GUARD_GRANULE_SIZE,
             "Failed to break down block mapping before MMIO guard mapping"
         );
         let page_base = va_range.start().0;
-        assert_eq!(page_base % PAGE_SIZE, 0);
+        assert_eq!(page_base % MMIO_GUARD_GRANULE_SIZE, 0);
         // Since mmio_guard_map takes IPAs, if pvmfw moves non-ID address mapping, page_base
         // should be converted to IPA. However, since 0x0 is a valid MMIO address, we don't use
         // virt_to_phys here, and just pass page_base instead.