Skip to content

vmm: drop use of rangemap crate #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion src/vmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ libc = ">=0.2.39"
linux-loader = { version = "0.13.0", features = ["bzimage", "elf", "pe"] }
log = "0.4.0"
vm-memory = { version = ">=0.13", features = ["backend-mmap"] }
rangemap = "1.5.1"

arch = { path = "../arch" }
devices = { path = "../devices" }
Expand Down
18 changes: 11 additions & 7 deletions src/vmm/src/linux/vstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use libc::{c_int, c_void, siginfo_t};
use std::cell::Cell;
use std::fmt::{Display, Formatter};
use std::io;
use std::ops::Range;

use std::os::unix::io::RawFd;

Expand Down Expand Up @@ -57,8 +58,6 @@ use vm_memory::{
GuestRegionMmap,
};

use rangemap::RangeMap;

#[cfg(feature = "amd-sev")]
use sev::launch::snp;

Expand Down Expand Up @@ -457,7 +456,7 @@ pub struct Vm {
#[cfg(feature = "amd-sev")]
pub tee_config: Tee,

pub guest_memfds: RangeMap<u64, (RawFd, u64)>,
pub guest_memfds: Vec<(Range<u64>, RawFd)>,
}

impl Vm {
Expand All @@ -482,7 +481,7 @@ impl Vm {
supported_cpuid,
#[cfg(target_arch = "x86_64")]
supported_msrs,
guest_memfds: RangeMap::new(),
guest_memfds: Vec::new(),
})
}

Expand Down Expand Up @@ -521,7 +520,7 @@ impl Vm {
supported_msrs,
tee,
tee_config: tee_config.tee,
guest_memfds: RangeMap::new(),
guest_memfds: Vec::new(),
})
}

Expand Down Expand Up @@ -560,7 +559,12 @@ impl Vm {
}

pub fn guest_memfd_get(&self, gpa: u64) -> Option<(RawFd, u64)> {
self.guest_memfds.get(&gpa).copied()
for (range, rawfd) in self.guest_memfds.iter() {
if range.contains(&gpa) {
return Some((*rawfd, range.start));
}
}
None
}

#[allow(unused_mut)]
Expand Down Expand Up @@ -631,7 +635,7 @@ impl Vm {
.set_memory_attributes(attr)
.map_err(Error::SetMemoryAttributes)?;

self.guest_memfds.insert(start..end, (guest_memfd, start));
self.guest_memfds.push((Range { start, end }, guest_memfd));
}

self.next_mem_slot += 1;
Expand Down
Loading