Skip to content
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
12 changes: 12 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ time = "0.3"
tun-tap = { version = "0.1.3", default-features = false }
uhyve-interface = { version = "0.1.4", path = "uhyve-interface", features = ["std"] }
virtio-bindings = { version = "0.2", features = ["virtio-v4_14_0"] }
vm-memory = { version = "0.18", features = ["backend-mmap"] }
rftrace = { version = "0.3", optional = true }
rftrace-frontend = { version = "0.3", optional = true }
rand = "0.9"
Expand Down
2 changes: 1 addition & 1 deletion src/arch/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn is_valid_address(virtual_address: GuestVirtAddr) -> bool {
}

/// Converts a virtual address in the guest to a physical address in the guest
pub fn virt_to_phys(
pub(crate) fn virt_to_phys(
addr: GuestVirtAddr,
mem: &MmapMemory,
pgt: GuestPhysAddr,
Expand Down
4 changes: 2 additions & 2 deletions src/arch/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(crate) fn generate_address(object_mem_size: usize) -> GuestPhysAddr {
}

/// Converts a virtual address in the guest to a physical address in the guest
pub fn virt_to_phys(
pub(crate) fn virt_to_phys(
addr: GuestVirtAddr,
mem: &MmapMemory,
pml4: GuestPhysAddr,
Expand Down Expand Up @@ -95,7 +95,7 @@ mod tests {

let guest_address = GuestPhysAddr::new(0x11111000);

let mem = MmapMemory::new(0, MIN_PHYSMEM_SIZE * 2, guest_address, true, true);
let mem = MmapMemory::new(MIN_PHYSMEM_SIZE * 2, guest_address, true, true);
println!("mmap memory created {mem:x?}");

init_guest_mem(
Expand Down
7 changes: 5 additions & 2 deletions src/arch/x86_64/paging/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ pub fn initialize_pagetables(
// TODO: deprecate the legacy_mapping option once hermit pre 0.10.0 isn't a thing anymore.
legacy_mapping: bool,
) {
assert!(mem.len() >= MIN_PHYSMEM_SIZE);
assert!(
mem.len() >= PAGETABLES_OFFSET as usize + 2 * PAGE_SIZE,
"Insufficient memory for at least a single three-level pagetable mapping"
);
let mem_addr = std::ptr::addr_of_mut!(mem[0]);

let (gdt_entry, pml4);
Expand Down Expand Up @@ -186,7 +189,7 @@ mod tests {
for &guest_address in gaddrs.iter() {
println!("\n\n---------------------------------------");
println!("testing guest address {guest_address:?}");
let mem = MmapMemory::new(0, MIN_PHYSMEM_SIZE * 2, guest_address, true, true);
let mem = MmapMemory::new(MIN_PHYSMEM_SIZE * 2, guest_address, true, true);
initialize_pagetables(
unsafe {
mem.slice_at_mut(guest_address, MIN_PHYSMEM_SIZE * 2)
Expand Down
39 changes: 19 additions & 20 deletions src/linux/x86_64/kvm_cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,27 @@ impl VirtualizationBackendInternal for KvmVm {
) -> HypervisorResult<Self> {
let vm = KVM.create_vm().unwrap();

let sz = std::cmp::min(peripherals.mem.memory_size, KVM_32BIT_GAP_START);
let sz = std::cmp::min(peripherals.mem.size(), KVM_32BIT_GAP_START);

let kvm_mem = kvm_userspace_memory_region {
slot: 0,
flags: peripherals.mem.flags,
flags: 0, // Can be KVM_MEM_LOG_DIRTY_PAGES and KVM_MEM_READONLY
memory_size: sz as u64,
guest_phys_addr: peripherals.mem.guest_address.as_u64(),
userspace_addr: peripherals.mem.host_address as u64,
guest_phys_addr: peripherals.mem.guest_addr().as_u64(),
userspace_addr: peripherals.mem.host_start() as u64,
};

unsafe { vm.set_user_memory_region(kvm_mem) }?;

if peripherals.mem.memory_size > KVM_32BIT_GAP_START + KVM_32BIT_GAP_SIZE {
if peripherals.mem.size() > KVM_32BIT_GAP_START + KVM_32BIT_GAP_SIZE {
let kvm_mem = kvm_userspace_memory_region {
slot: 1,
flags: peripherals.mem.flags,
memory_size: (peripherals.mem.memory_size
- KVM_32BIT_GAP_START
- KVM_32BIT_GAP_SIZE) as u64,
guest_phys_addr: peripherals.mem.guest_address.as_u64()
flags: 0, // Can be KVM_MEM_LOG_DIRTY_PAGES and KVM_MEM_READONLY
memory_size: (peripherals.mem.size() - KVM_32BIT_GAP_START - KVM_32BIT_GAP_SIZE)
as u64,
guest_phys_addr: peripherals.mem.guest_addr().as_u64()
+ (KVM_32BIT_GAP_START + KVM_32BIT_GAP_SIZE) as u64,
userspace_addr: (peripherals.mem.host_address as usize
userspace_addr: (peripherals.mem.host_start() as usize
+ KVM_32BIT_GAP_START
+ KVM_32BIT_GAP_SIZE) as u64,
};
Expand Down Expand Up @@ -520,15 +519,15 @@ impl VirtualCPU for KvmCpu {
Hypercall::SerialWriteBuffer(sysserialwrite) => {
// safety: as this buffer is only read and not used afterwards, we don't create multiple aliasing
let buf = unsafe {
self
.peripherals
.mem
.slice_at(sysserialwrite.buf, sysserialwrite.len)
.unwrap_or_else(|e| {
panic!(
"Error {e}: Systemcall parameters for SerialWriteBuffer are invalid: {sysserialwrite:?}"
)
})
self.peripherals.mem.slice_at(
sysserialwrite.buf,
sysserialwrite.len,
)
.unwrap_or_else(|e| {
panic!(
"Error {e}: Systemcall parameters for SerialWriteBuffer are invalid: {sysserialwrite:?}"
)
})
};

self.peripherals
Expand Down
Loading