From b09cbb849323d437442ba5d0643d32acbf392410 Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Mon, 29 Nov 2021 07:16:03 +0000 Subject: [PATCH] vmm: Add constant SGX_PAGE_SIZE in memory_manager.rs Purpose: Do not directly use 0x1000 but use predefined constant value. Signed-off-by: Ziye Yang --- vmm/src/memory_manager.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/vmm/src/memory_manager.rs b/vmm/src/memory_manager.rs index 38774a3cd..f7e93986b 100644 --- a/vmm/src/memory_manager.rs +++ b/vmm/src/memory_manager.rs @@ -56,6 +56,9 @@ const SNAPSHOT_FILENAME: &str = "memory-ranges"; #[cfg(target_arch = "x86_64")] const X86_64_IRQ_BASE: u32 = 5; +#[cfg(target_arch = "x86_64")] +const SGX_PAGE_SIZE: u64 = 1 << 12; + const HOTPLUG_COUNT: usize = 8; // Memory policy constants @@ -1617,7 +1620,7 @@ impl MemoryManager { if epc_section.size == 0 { return Err(Error::EpcSectionSizeInvalid); } - if epc_section.size & 0x0fff != 0 { + if epc_section.size & (SGX_PAGE_SIZE - 1) != 0 { return Err(Error::EpcSectionSizeInvalid); } @@ -1625,8 +1628,10 @@ impl MemoryManager { } // Place the SGX EPC region on a 4k boundary between the RAM and the device area - let epc_region_start = - GuestAddress(((self.start_of_device_area.0 + 0xfff) / 0x1000) * 0x1000); + let epc_region_start = GuestAddress( + ((self.start_of_device_area.0 + SGX_PAGE_SIZE - 1) / SGX_PAGE_SIZE) * SGX_PAGE_SIZE, + ); + self.start_of_device_area = epc_region_start .checked_add(epc_region_size) .ok_or(Error::GuestAddressOverFlow)?;