Skip to content

Commit

Permalink
vmm/amdsnp: Remove deprecated as_slice() for guest memory
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
  • Loading branch information
tylerfanelli committed Oct 25, 2024
1 parent b78d6af commit 2474e50
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 40 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/smbios/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2021"

[dependencies]
vm-memory = { version = ">=0.13", features = ["backend-mmap"] }
vm-memory = { version = ">=0.13", features = ["backend-mmap"] }
53 changes: 16 additions & 37 deletions src/vmm/src/linux/tee/amdsnp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::os::unix::io::{AsRawFd, RawFd};
use std::{
os::unix::io::{AsRawFd, RawFd},
slice,
};

use crate::vstate::MeasuredRegion;
use arch::x86_64::layout::*;
Expand Down Expand Up @@ -287,43 +290,19 @@ impl AmdSnp {
* entire slice of a guest memory region.
*/
let gr: &GuestRegionMmap = guest_mem.find_region(ga).unwrap();
// TODO: Find the right way to replace this deprecated method.
#[allow(deprecated)]
let region_slice = unsafe { gr.as_slice().unwrap() };

/*
* The memory region we are currently looking to measure is
* represented simply as a guest address at the moment. Instead,
* we would like to obtain a slice of it. To do this, we must use
* the guest address as an OFFSET within the slice, and only take
* that subslice.
*/
let offset: usize = guest_mem
.to_region_addr(ga)
.unwrap()
.1
.0
.try_into()
.unwrap();

/*
* We know the size of the region to be measured from the
* MeasuredRegion.
*/
let count: usize = region.size;

/*
* We now have the start and end indexes of the slice, so use these
* indexes to take a subslice of the guest region (corresponding to
* the slice of bytes that we're looking to measure).
*/
let buf = &region_slice[offset..offset + count];

/*
* From that subslice, build an Update struct and call
* SNP_LAUNCH_UPDATE.
*/
let update = Update::new(region.guest_addr >> 12, buf, false, page_type, (dp, dp, dp));
let region_addr = gr.to_region_addr(ga).unwrap();
let bytes = gr.get_slice(region_addr, region.size).unwrap();
let ptr = bytes.ptr_guard().as_ptr();
let slice: &[u8] = unsafe { slice::from_raw_parts(ptr, region.size) };

let update = Update::new(
region.guest_addr >> 12,
slice,
false,
page_type,
(dp, dp, dp),
);

launcher.update_data(update).map_err(Error::LaunchUpdate)
}
Expand Down

0 comments on commit 2474e50

Please sign in to comment.