Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Virtual machine's guest memory crate

License

NotificationsYou must be signed in to change notification settings

roypat/vm-memory

 
 

Repository files navigation

crates.iodocs.rs

Design

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.

Platform Support

  • Arch: x86_64, ARM64, RISCV64
  • OS: Linux/Unix/Windows

Xen support

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.

Usage

Addvm-memory as a dependency inCargo.toml

[dependencies]vm-memory ="*"

Then addextern crate vm-memory; to your crate root.

Examples

  • Creating a VM physical memory object in hypervisor specific ways using theGuestMemoryMmap implementation of theGuestMemory trait:
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);}

License

This project is licensed under either of

About

Virtual machine's guest memory crate

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust100.0%

[8]ページ先頭

©2009-2025 Movatter.jp