-
Notifications
You must be signed in to change notification settings - Fork 28
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
Crate Addition Request: memory-model #22
Comments
@jiangliu I'm creating that issue so that we can create a |
Thanks, sameo! Will try implement a PoC by following @bonzini 's suggestion. |
Thanks @jiangliu |
LGTM @andreeaflorescu @zachreizner @aghecenco PTAL |
Can we do a bit of brainstorming for the name of this crate? In the context of crates.io memory-model doesn't say much in my opinion. |
True, maybe |
This crate deals with virtual machine memory, so how about vm-mem or vmmem? |
|
|
|
Design documentation for the memory-model crate (https://github.com/jiangliu/memory-model/tree/v2) memory-modelA library to manage and access virtual machine's physical memory. The On the other hand, this crate dosen't define the way how the underline mechanism is implemented to access guest's physical memory. For light-wieght hypervisors like crosvm and firecracker, they may make some assumptions about the structure of virtual machine's physical memory and implement a light-weight backend to access guest's memory. For hypervisors like qemu, a high performance and full functionality backend may be implemented with less assumptions. This crate is derived from two upstream projects:
To be hypervisor neutral, the high level abstraction has been heavily refactored. It could be divided into four parts as: Abstraction of Generic Address SpaceBuild generic abstractions to describe and access an address space as below:
To make the abstraction as generic as possible, all the core traits only define methods to access the address space are defined here, and they never define methods to manage (create, delete, insert, remove etc) address spaces. By this way, the address space consumers (virtio device drivers, vhost-user drivers and boot loaders etc) may be decoupled from the address space provider (typically a hypervisor). Specialization for Virtual Machine Physical Address SpaceThe generic address space crates are specialized to access guest's physical memory with following traits:
The virtual machine memory consumers, such as virtio device drivers, vhost drivers and boot loaders etc, should only rely on traits defined here to access guest's memory. A Sample and Default Backend Implementation Based on mmap()Provide a default and sample implementation of the GuestMemory trait by mmapping guest's memory into current process. Three data structures are introduced here:
One of the main responsibilities of the GuestMemoryMmap object is to handle the use cases where an access request crosses the memory region boundary. This scenario may be triggered when memory hotplug is supported. So there's a tradeoff between functionality code and complexity:
let guest_memory_mmap: GuestMemoryMmap = ...
let addr: GuestAddress = ...
let buf = &mut [0u8; 5];
let result = guest_memory_mmap.find_region(addr).unwrap().write_slice(buf, addr);
let guest_memory_mmap: GuestMemoryMmap = ...
let addr: GuestAddress = ...
let buf = &mut [0u8; 5];
let result = guest_memory_mmap.write_slice(buf, addr); Utilities and HelpersFollowing utility and helper traits/macros are imported from the crosvm project with minor changes:
Relationship among Traits and Structs
|
Nice! I tried to make some more simplifications at https://github.com/bonzini/memory-model/tree/v2 In particular, MmapRegion gets its I tried also moving GuestMemoryMmap's Also, it may be useful to place more methods (formerly in |
Thanks for quick review:) The key idea is to manage guest's physical memory as a dedicated object, and assign part of guest's memory to related components (vhost drivers, hypervisor workers etc) according to access rules. So we hope we could build a layered abstraction as: And the address space abstraction is the common abstraction for both GuestPhysicalMemory and GuestMemory. And to support above mentioned usages, the AddressRegion traits need to be enhanced to provide memory property/type information. Based on this design, it may help to address the security concern mentioned by @alexandruag . And it may also help to implement vIOMMU/vIOTLB in vhost-user drivers(more work needed to prove this claim). So the fundament question is:
|
Please refer to #16 for previous discussions. |
I have no objections to providing both, however I would start with a restricted implementation until it is clear what is common between the various users. In fact I don't have any problem with adding more information to I have pushed a new version that is nicely split into multiple commits and also adds a generic implementation of By the way, it might even be possible to make a separate crate for DataInit, Bytes, endian types and VolatileMemory. What do you think? |
On Feb 26, 2019, at 6:58 PM, Paolo Bonzini ***@***.*** ***@***.***>> wrote:
Should this crate provide traits to manage guest physical memory or only provide traits to access guest's memory?
I have no objections to providing both, however I would start with a restricted implementation until it is clear what is common between the various users.
In fact I don't have any problem with adding more information to AddressRegion or GuestMemoryRegion. All I am doing in my refactoring is making sure that the interface is as simple as possible, and the implementation is as generic as possible.
Great, so let's start small and add needed interfaces on demand.
I have pushed a new version that is nicely split into multiple commits and also adds a generic implementation of Bytes<GuestAddress>.
By the way, it might even be possible to make a separate crate for DataInit, Bytes, endian types and VolatileMemory. What do you think?
Seems reasonable because these traits have more generic usage scenarios than GuestMemory.
… You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#22 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AB14_Nj4VeWbuzrxR0HQm9RLva72Ps76ks5vRRMNgaJpZM4a98W8>.
|
Hi buddies, Note: as we have discussed, the 'memory-model' crate will be renamed as 'vm-memory'. |
@jiangliu This looks very good! I am looking forward to the future pull requests on the brand new |
@sameo This can be closed now |
Fixed with rust-vmm/vm-memory#1 |
Crate Name
memory-model
Short Description
Trying to summarize discussions at #16:
This crate will fundamentally allow for accessing guest memory and translating guest addresses into host memory mapping.
The crate APIs will allow for writing to and reading from the guest memory.
This API should be able to handle raw slices but also
DataInit
types, i.e. types that can be safely initialized from a byte array.Why is this crate relevant to the rust-vmm project?
Handling guest memory is a fundamental piece of a vmm...
The text was updated successfully, but these errors were encountered: