From 4f6732e5769a633d8ab98c0f8b65c63ba72b01ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20L=C3=B3pez?= Date: Wed, 31 Jan 2024 14:55:01 +0100 Subject: [PATCH] sev/secrets_page: replace Box with GlobalBox MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the new fallible-allocation-aware GlobalBox type when allocating a new secrets page for the given VPML. Signed-off-by: Carlos López --- kernel/src/sev/secrets_page.rs | 11 +++++------ kernel/src/svsm.rs | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/kernel/src/sev/secrets_page.rs b/kernel/src/sev/secrets_page.rs index 7ad773ff19..afe24762f9 100644 --- a/kernel/src/sev/secrets_page.rs +++ b/kernel/src/sev/secrets_page.rs @@ -5,13 +5,12 @@ // Author: Joerg Roedel use crate::address::VirtAddr; +use crate::error::SvsmError; use crate::locking::{RWLock, ReadLockGuard, WriteLockGuard}; +use crate::mm::GlobalBox; use crate::sev::vmsa::VMPL_MAX; use crate::types::GUEST_VMPL; -extern crate alloc; -use alloc::boxed::Box; - pub const VMPCK_SIZE: usize = 32; #[derive(Copy, Clone, Debug)] @@ -73,13 +72,13 @@ impl SecretsPage { } } - pub fn copy_for_vmpl(&self, vmpl: usize) -> Box { - let mut sp = Box::new(*self); + pub fn copy_for_vmpl(&self, vmpl: usize) -> Result, SvsmError> { + let mut sp = GlobalBox::try_new(*self)?; for idx in 0..vmpl { sp.clear_vmpck(idx); } - sp + Ok(sp) } pub fn set_svsm_data(&mut self, base: u64, size: u64, caa_addr: u64) { diff --git a/kernel/src/svsm.rs b/kernel/src/svsm.rs index eb0516d7e1..92fff216cc 100755 --- a/kernel/src/svsm.rs +++ b/kernel/src/svsm.rs @@ -125,7 +125,7 @@ fn copy_secrets_page_to_fw(fw_addr: PhysAddr, caa_addr: PhysAddr) -> Result<(), zero_mem_region(start, start + PAGE_SIZE); // Copy secrets page - let mut fw_secrets_page = secrets_page().copy_for_vmpl(GUEST_VMPL); + let mut fw_secrets_page = secrets_page().copy_for_vmpl(GUEST_VMPL)?; let &li = &*LAUNCH_INFO;