Skip to content

Commit 16a5e2f

Browse files
authored
Remove unused blake3 hash from Snapshot (#1497)
The blake3 `hash` field on `Snapshot` and the `PartialEq` impl it backed are dead code on main. The field was added in 1846413 to back a fast-path in `MultiUseSandbox::restore()` that skipped re-applying the current snapshot. That fast-path no longer exists Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 2914d31 commit 16a5e2f

1 file changed

Lines changed: 0 additions & 54 deletions

File tree

  • src/hyperlight_host/src/sandbox/snapshot

src/hyperlight_host/src/sandbox/snapshot/mod.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use hyperlight_common::vmem::{
2525
};
2626
use tracing::{Span, instrument};
2727

28-
use crate::HyperlightError::MemoryRegionSizeMismatch;
2928
use crate::Result;
3029
use crate::hypervisor::regs::CommonSpecialRegisters;
3130
use crate::mem::exe::{ExeInfo, LoadInfo};
@@ -89,14 +88,6 @@ pub struct Snapshot {
8988
/// things like persisting a snapshot and reloading it are likely
9089
/// to destroy this information.
9190
load_info: LoadInfo,
92-
/// The hash of the other portions of the snapshot. Morally, this
93-
/// is just a memoization cache for [`hash`], below, but it is not
94-
/// a [`std::sync::OnceLock`] because it may be persisted to disk
95-
/// without being recomputed on load.
96-
///
97-
/// It is not a [`blake3::Hash`] because we do not presently
98-
/// require constant-time equality checking
99-
hash: [u8; 32],
10091
/// The address of the top of the guest stack
10192
stack_top_gva: u64,
10293

@@ -160,41 +151,6 @@ impl hyperlight_common::vmem::TableReadOps for Snapshot {
160151
}
161152
}
162153

163-
/// Compute a deterministic hash of a snapshot.
164-
///
165-
/// This does not include the load info from the snapshot, because
166-
/// that is only used for debugging builds.
167-
fn hash(memory: &[u8], regions: &[MemoryRegion]) -> Result<[u8; 32]> {
168-
let mut hasher = blake3::Hasher::new();
169-
hasher.update(memory);
170-
for rgn in regions {
171-
hasher.update(&usize::to_le_bytes(rgn.guest_region.start));
172-
let guest_len = rgn.guest_region.end - rgn.guest_region.start;
173-
#[allow(clippy::useless_conversion)]
174-
let host_start_addr: usize = rgn.host_region.start.into();
175-
#[allow(clippy::useless_conversion)]
176-
let host_end_addr: usize = rgn.host_region.end.into();
177-
hasher.update(&usize::to_le_bytes(host_start_addr));
178-
let host_len = host_end_addr - host_start_addr;
179-
if guest_len != host_len {
180-
return Err(MemoryRegionSizeMismatch(
181-
host_len,
182-
guest_len,
183-
format!("{:?}", rgn),
184-
));
185-
}
186-
// Ignore [`MemoryRegion::region_type`], since it is extra
187-
// information for debugging rather than a core part of the
188-
// identity of the snapshot/workload.
189-
hasher.update(&usize::to_le_bytes(guest_len));
190-
hasher.update(&u32::to_le_bytes(rgn.flags.bits()));
191-
}
192-
// Ignore [`load_info`], since it is extra information for
193-
// debugging rather than a core part of the identity of the
194-
// snapshot/workload.
195-
Ok(hasher.finalize().into())
196-
}
197-
198154
pub(crate) fn access_gpa<'a>(
199155
snap: &'a [u8],
200156
scratch: &'a [u8],
@@ -418,15 +374,13 @@ impl Snapshot {
418374
+ 1;
419375

420376
let extra_regions = Vec::new();
421-
let hash = hash(&memory, &extra_regions)?;
422377

423378
Ok(Self {
424379
sandbox_id: SANDBOX_CONFIGURATION_COUNTER.fetch_add(1, Ordering::Relaxed),
425380
memory: ReadonlySharedMemory::from_bytes(&memory)?,
426381
layout,
427382
regions: extra_regions,
428383
load_info,
429-
hash,
430384
stack_top_gva: exn_stack_top_gva,
431385
sregs: None,
432386
entrypoint: NextAction::Initialise(load_addr + entrypoint_va - base_va),
@@ -610,14 +564,12 @@ impl Snapshot {
610564
// PAs overlap the old region PAs.
611565
let regions: Vec<MemoryRegion> = Vec::new();
612566

613-
let hash = hash(&memory, &regions)?;
614567
Ok(Self {
615568
sandbox_id,
616569
layout,
617570
memory: ReadonlySharedMemory::from_bytes_with_mapped_size(&memory, guest_visible_size)?,
618571
regions,
619572
load_info,
620-
hash,
621573
stack_top_gva,
622574
sregs: Some(sregs),
623575
entrypoint,
@@ -737,12 +689,6 @@ impl Snapshot {
737689
}
738690
}
739691

740-
impl PartialEq for Snapshot {
741-
fn eq(&self, other: &Snapshot) -> bool {
742-
self.hash == other.hash
743-
}
744-
}
745-
746692
#[cfg(test)]
747693
#[cfg(not(feature = "i686-guest"))]
748694
mod tests {

0 commit comments

Comments
 (0)