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 <[email protected]>
  • Loading branch information
tylerfanelli committed Oct 23, 2024
1 parent b78d6af commit 5bb801d
Showing 1 changed file with 12 additions and 36 deletions.
48 changes: 12 additions & 36 deletions src/vmm/src/linux/tee/amdsnp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,43 +287,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 mut buf = vec![0u8; region.size];
bytes.read_slice(&mut buf, region.size).unwrap();

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

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

0 comments on commit 5bb801d

Please sign in to comment.