- Notifications
You must be signed in to change notification settings - Fork0
Virtual machine's guest memory crate
License
ELginas/vm-memory
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
In a typical Virtual Machine Monitor (VMM) there are several components, suchas boot loader, virtual device drivers, virtio backend drivers and vhostdrivers, that need to access the VM physical memory. Thevm-memory crateprovides a set of traits to decouple VM memory consumers from VM memoryproviders. Based on these traits, VM memory consumers can access the physicalmemory of the VM without knowing the implementation details of the VM memoryprovider. Thus VMM components based on these traits can be shared and reused bymultiple virtualization solutions.
The detailed design of thevm-memory crate can be foundhere.
- Arch: x86_64, ARM64, RISCV64
- OS: Linux/Unix/Windows
Supporting Xen requires special handling while mapping the guest memory andhence a separate feature is provided in the crate:xen. Mapping the guestmemory for Xen requires anioctl() to be issued along withmmap() for thememory area. The arguments for theioctl() are received via thevhost-userprotocol's memory region area.
Xen allows two different mapping models:Foreign andGrant.
InForeign mapping model, the entire guest address space is mapped at once, inadvance. InGrant mapping model, the memory for few regions, like thoserepresenting the virtqueues, is mapped in advance. The rest of the memoryregions are mapped (partially) only while accessing the buffers and the same isimmediately deallocated after the buffer is accessed. Hence, special handlingfor the same inVolatileMemory.rs.
In order to still support standard Unix memory regions, for special regions andtesting, the Xen specific implementation here allows a third mapping type:MmapXenFlags::UNIX. This performs standard Unix memory mapping and the same isused for all tests in this crate.
It was decided by therust-vmm maintainers to keep the interface simple andbuild the crate for either standard Unix memory mapping or Xen, and not both.
Xen is only supported for Unix platforms.
Addvm-memory as a dependency inCargo.toml
[dependencies]vm-memory ="*"
Then addextern crate vm-memory; to your crate root.
- Creating a VM physical memory object in hypervisor specific ways using the
GuestMemoryMmapimplementation of theGuestMemorytrait:
fnprovide_mem_to_virt_dev(){let gm =GuestMemoryMmap::from_ranges(&[(GuestAddress(0),0x1000),(GuestAddress(0x1000),0x1000)]).unwrap();virt_device_io(&gm);}
- Consumers accessing the VM's physical memory:
fnvirt_device_io<T:GuestMemory>(mem:&T){let sample_buf =&[1,2,3,4,5];assert_eq!(mem.write(sample_buf,GuestAddress(0xffc)).unwrap(),5);let buf =&mut[0u8;5];assert_eq!(mem.read(buf,GuestAddress(0xffc)).unwrap(),5);assert_eq!(buf, sample_buf);}
This project is licensed under either of
- Apache License, Version 2.0
- BSD-3-Clause License
About
Virtual machine's guest memory crate
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Languages
- Rust100.0%