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};