Skip to content

Conversation

@jiangliu
Copy link
Member

Fix #8

alexandruag
alexandruag previously approved these changes Apr 2, 2019
Copy link
Collaborator

@alexandruag alexandruag left a comment

Choose a reason for hiding this comment

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

Looks good to me! I have some comments on error handling for GuestMemory in general, but I'll put those in the comment PR/RFC I'm still trying to write :(

Copy link
Member

@bonzini bonzini left a comment

Choose a reason for hiding this comment

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

Is this needed, or is it just a cleanup? Even if it is only used by mmap-related code, it can be useful in general.

Copy link
Member

@bonzini bonzini left a comment

Choose a reason for hiding this comment

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

Can you also look into removing map_and_fold(), and replacing it with iter()?

@jiangliu
Copy link
Member Author

jiangliu commented Apr 3, 2019 via email

@bonzini
Copy link
Member

bonzini commented Apr 3, 2019

Nice! Can you add some comments explaining the reason for the PhantomData?

@bonzini
Copy link
Member

bonzini commented Apr 4, 2019

Hey people, I placed my initial attempt at converting firecracker at https://github.com/bonzini/firecracker branch master.

A more sensible way to do it would be to split like:

  • Rename memory-model classes to the vm-memory equivalents
  • Rename memory-model methods to the vm-memory (especially Bytes) equivalents
  • Add "type GuestUsize = u32;" to memory-model, fix compilation
  • Finally switch to vm-memory and add the new traits uses.

The vm-memory is not properly vendored, it's hacked to add the mmap feature to Cargo.toml. And so on... still if it saves you a couple hours, all for the best.

@andreeaflorescu
Copy link
Member

Hey @bonzini, thanks. I will open an issue in the Firecracker repository to switch to vm-memory and link the commit from your fork.

We will wait for the vm-memory to be published to crates.io before using it. Before doing the switch we want to make sure we have good code coverage and the necessary mechanisms in place to ensure that future PRs won't decrease it. I will open issues in vm-memory for the other things that I'll find.

jiangliu added 2 commits April 5, 2019 22:33
Add an iterator interface to the GuestMemory trait, so the with_regions()
and with_regions_mut() methods could be removed later.

Signed-off-by: Liu Jiang <[email protected]>
Now we have iterator for the GuestMemory trait, so remove with_regions(),
with_regions_mut() and map_and_fold().

Signed-off-by: Liu Jiang <[email protected]>
@jiangliu
Copy link
Member Author

I have tried to migrate the vhost crate in firecracker to the vm-memory crate, it works with one more patch upon this PR.

@jiangliu jiangliu requested a review from bonzini April 11, 2019 08:26
@andreeaflorescu
Copy link
Member

@jiangliu we are currently trying to move away from vhost. See this RFC with the design doc: firecracker-microvm/firecracker#1044

@jiangliu
Copy link
Member Author

Thanks @andreeaflorescu , happy to see the progress on support of vsock. I will keep current firecracker's vsock implementation as an example:)

jiangliu added 2 commits May 7, 2019 13:32
Some guest memory consumers, such as in-kernel vhost driver, boot loader
etc, need to access the guest memory by pointers. So add method
get_host_address() to the GuestMemory and GuestMemoryRegion traits,
otherwise those guest memory consumers will explicitly depend on the
GuestMemoryMmap struct.

Signed-off-by: Liu Jiang <[email protected]>
Enhance the GuestMemory trait to support Clone, so guest memory consumers
could hold a local guest memory object by calling guest_memory.clone().

Signed-off-by: Liu Jiang <[email protected]>
@andreeaflorescu
Copy link
Member

@jiangliu what is the status here? Do we still want to merge this one?

}

impl GuestMemoryRegion for GuestRegionMmap {
const DIRECT_ACCESS: bool = true;
Copy link
Member

Choose a reason for hiding this comment

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

Why is DIRECT_ACCESS useful?

/// Convert an absolute address in an address space (GuestMemory) to a host pointer,
/// or return None if it is out of bounds. It always returns None when `DIRECT_ACCESS` is false.
/// The returned pointer may be used for ioctls etc.
fn get_host_address(&self, addr: MemoryRegionAddress) -> Option<*mut u8>;
Copy link
Member

Choose a reason for hiding this comment

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

This can be implemented in terms of as_mut_slice(). Also please make the result Option<NonNull<u8>>.

@jiangliu
Copy link
Member Author

@jiangliu what is the status here? Do we still want to merge this one?

Hi Paolo,
The rust GAT(Generic Associated Type) feature is still unstable. Merging this patch will force all clients to carry on an extra lifetime parameter, which is a little heavy. So suggest to wait until that the GAT feature gets stable.

@bonzini
Copy link
Member

bonzini commented Jul 29, 2019

Agreed.

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.

Add GuestMemory method to return an Iterator

4 participants