Skip to content
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

Use wrapper types to encode Vm & VmPages state #98

Merged
merged 5 commits into from
Sep 16, 2022

Conversation

abrestic-rivos
Copy link
Collaborator

While encoding the state of the VM as a type parameter in Vm and VmPages creates clean separation between the APIs in each state, it means that transitions between states require consuming (and as a result, copying) these large structs. Introduce wrapper VmRef / VmPagesRef types which expose the appropriate functionality for the current state of the VM instead, which still gets us the nice API separation with an extra layer of indirection. This is a pre-requisite to #65, and will enable us to do in-place initialization of these structs.

Patches 1-3 are small cleanups which enable patch 4 (wrapper state types for VmPages) and patch 5 (wrapper state types for Vm).

src/vm_pages.rs Outdated Show resolved Hide resolved
@atulkharerivos
Copy link
Contributor

I will take a second look, but it looks good from an initial pass.

Copy link
Collaborator

@dgreid dgreid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, lgtm just a couple comment nits.

src/vm.rs Outdated Show resolved Hide resolved
src/vm_pages.rs Outdated Show resolved Hide resolved
PCI BAR memory will eventually need special treatment when compared to
ordinary confidential memory, e.g. when assigning a device to a TVM, so
give it its own region type. For now though it'll enable us to add some
type-safety to VmPagesMapper.

Signed-off-by: Andrew Bresticker <[email protected]>
Currently, once a VmPagesMapper is constructed, one can use any sort of
page with it regardless of the region type it was constructed in. Make
it type-safe by adding a type parameter indicating which type of mapper
it is and by having map_page() for that type only support the proper
PhysPage.

Signed-off-by: Andrew Bresticker <[email protected]>
Avoid this use of deref polymorphism and remove the Deref implementation.
We only used this ability inside of ActiveVmPages anyway.

Signed-off-by: Andrew Bresticker <[email protected]>
Instead of including the state as a type parameter for the VmPages struct
itself, introduce a wrapper VmPagesRef type which exposes the appropriate
functionality for the VmPages depending on the VM's state. This allows us
to transition between states without consuming (copying) the entire struct.

Signed-off-by: Andrew Bresticker <[email protected]>
Similar to VmPages, remove the state type argument from Vm and introduce
a VmRef type that serves as a reference to a Vm in a particular state.
The various VmRef types are then used to implement the appropriate
functionality for a VM in that state. This immediately enables a couple
of small cleanups: finalize() no longer needs to consume the Vm struct
and we can now implement drop() for Vm.

Signed-off-by: Andrew Bresticker <[email protected]>
@abrestic-rivos abrestic-rivos merged commit f26a400 into rivosinc:main Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants