Skip to content

Commit

Permalink
sev/secrets_page: replace Box with GlobalBox
Browse files Browse the repository at this point in the history
Use the new fallible-allocation-aware GlobalBox type when allocating
a new secrets page for the given VPML.

Signed-off-by: Carlos López <[email protected]>
  • Loading branch information
00xc committed Feb 19, 2024
1 parent ef3e78c commit e69750a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions kernel/src/sev/secrets_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
// Author: Joerg Roedel <[email protected]>

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)]
Expand Down Expand Up @@ -73,13 +72,13 @@ impl SecretsPage {
}
}

pub fn copy_for_vmpl(&self, vmpl: usize) -> Box<SecretsPage> {
let mut sp = Box::new(*self);
pub fn copy_for_vmpl(&self, vmpl: usize) -> Result<GlobalBox<SecretsPage>, 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) {
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/svsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit e69750a

Please sign in to comment.