-
Notifications
You must be signed in to change notification settings - Fork 3
Extend vmm-vcpu to Hypervisor crate #5
Comments
Hi @yisun-git, thank you for providing this additional detail on the VMM/hypervisor crates! Some thoughts:
You've created the issue here due to its connection to the Vcpu crate, but you can also feel free to move the discussion to the rust-vmm community issues to ensure that a larger audience sees it as well. |
Hi, @jennymankin, Thanks for your comments! The suggestion to convert dynamic dispatch to static dispatch is good. Let me have a try! For separate crate, there are dependencies I think. I.e. Hypervisor depends on Vm trait, Vm depends on Vcpu trait. Is that possible a concrete VMM (e.g. Firecracker/crosvm) only implements part of these traits but not all of them? So I am not sure if we should separate hypervisor/vm/vcpu traits. How do you think? Thanks a lot for your open mind on this issue! I will raise this issue to community to see if other guys have any comments. |
Hi @yisun-git, yup, you are correct that the Hypervisor crate would depend on the Vm crate, and the Vm crate on the Vcpu crate. But I can still see VMM implementations implementing lower-level traits but not the higher-level ones. For example, I would as a first pass convert the |
Moved this discussion over to rust-vmm/community#50! Thanks :) |
Hi, @jennymankin I did a quick test for "impl Trait" but it seems it cannot work for my requirements. First, I want to declare a field with generic type in struct Vmm. But this is not allowed with below error: Second, it seems the "impl Trait" cannot be used in trait definition. Error reported: Any suggestion? Thanks! |
Addressing the second error, since getting the Vm and Hypervisor abstractions working is a prerequisite for the Vmm crate (and I actually need to think more about the Vmm crate in general): Ah right, I forgot about the limitation about using an (Also note that each of these Trait definition:
Vm trait implementation for kvm-ioctls:
This works under the assumption that a given implementation of the Vm trait would only want to implement a single type of Vcpu--that a Vm trait implementation would not want to interchange different types of Vcpus. Without thinking too deeply, I think this is a reasonable assumption, in that a KVM Vm will want a KVM Vcpu, a Hyper-V Vm will want a Hyper-V Vcpu, etc. However, if something more generic is desired, there is a Rust RFC for expanding the (The comments/details toward the end of the PR drive home the syntax and use cases) |
Hi, @jennymankin Thanks for the ideas! But there is one problem not solved. In vmm/src/vstate.rs (firecracker), the struct Vcpu is declared as below. The VcpuFd is a kvm specific struct.
The main purpose of hypervisor abstraction is to make upper layer be hypervisor agnostic. So I re-design the struct Vcpu as below. Then, the Vmm crate only knows the Vcpu trait but not kvm specific VcpuFd so that Vmm crate does not need include kvm-ioctls crate.
Per your sample codes, I do not see how to avoid including kvm specific thing, i.e. VcpuFd. Maybe something I missed? |
I think you're right. To add a But I've stewed over this and I don't think a hypervisor-agnostic solution needs this extra The reason is that there's a difference between what the hypervisor-agnostic crates (like a VMM, VM, and VCPU) provide, and the implementation of each of those traits. For example, a KVM implementation of the traits vs. a Hyper-V implementation of the crates. And then at a level higher than those, you have a specific implementation of the whole stack, for example Firecracker. And this
So while the building blocks are present for a hypervisor-agnostic VMM/VM/VCPU are there, Firecracker adds its own layers. Since Firecracker itself is implementing the VMM, at some point in the hierarchy there is/was always going to have to be a declaration of a hard implementation of the traits. That is, Firecracker was going to have create to an instance of the KVM implementation of the VMM, VM, and VCPU traits. To support another hypervisor (say Hyper-V), this would have to be conditionally compiled, and Firecracker would also (for example) create an instance of the Hyper-V implementation of the VMM, VM, and VCPU crates. So I think it's fair to also have the Let me know if this is unclear, I'm not sure if I'm explaining clearly what I mean :) |
Proposal
vmm-vcpu has made Vcpu handling be hypervisor agnostic. But there are still
some works to do to make whole rust-vmm be hypervisor agnostic. So here is
a proposal to extend vmm-vcpu to Hypervisor crate to make rust-vmm be
hypervisor agnostic.
Short Description
Hypervisor crate abstracts different hypervisors interfaces (e.g. kvm ioctls) to
provide unified interfaces to upper layer. The concrete hypervisor (e.g. Kvm/
HyperV) implements the traits to provide hypervisor specific functions.
The upper layer (e.g. Vmm) creates Hypervisor instance which links to the
running hypervisor. Then, it calls running hypervisor interfaces through
Hypervisor instance to make the upper layer be hypervisor agnostic.
Why is this crate relevant to the rust-vmm project?
Rust-vmm should be workable for all hypervisors, e.g. KVM/HyperV/etc. So the
hypervisor abstraction crate is necessary to encapsulate the hypervisor specific
operations so that the upper layer can simplify the implementations to be
hypervisor agnostic.
Design
Relationships of crates
Compilation arguments
Create concrete hypervisor instance for Hypervisor users (e.g. Vmm) through
compilation argument. Because only one hypervisor is running for cloud scenario.
Hypervisor crate
This crate itself is simple to expose three public traits Hypervisor, Vm and Vcpu.
This crate is used by KVM/HyperV/etc. The interfaces defined below are used to
show the mechanism. They are got from Firecracker. They are more Kvm specific.
We may change them per requirements.
Note: The Vcpu part refers the [1] and [2] with some changes.
[1] While the data types themselves (VmmRegs, SpecialRegisters, etc) are
exposed via the trait with generic names, under the hood they can be
kvm_bindings data structures, which are also exposed from the same crate
via public redefinitions:
Sample codes to show how it works
Kvm crate
Below are sample codes in Kvm crate to show how to implement above traits.
Vmm crate
Below are sample codes in Vmm crate to show how to work with Hypervisor
crate.
When start Vmm, create concrete hypervisor instance according to compilation
argument. Then, set it to Vmm and start the flow: create guest vm -> create guest
vcpus -> run.
References:
[1] rust-vmm/community#40
[2] https://github.com/rust-vmm/vmm-vcpu
The text was updated successfully, but these errors were encountered: