rust-vmm / vm-memory

Virtual machine's guest memory crate
Apache License 2.0
299 stars 97 forks source link

Xen/mmapv3 #241

Closed vireshk closed 1 year ago

vireshk commented 1 year ago

Add support for Xen specific memory mapping

Xen allows two memory mapping mechanisms:

Both these mechanisms required additional mapping support, for example an ioctl() needs to be issued (with arguments passed from backend), along with mmap().

Also for grant memory mapping, the mapping may or may not be done in advance and may be required to be done on-demand.

Add memory mapping support for both these cases, under a new feature "xen".

We can't use the existing as_ptr() API, as the memory may not be mapped already. Mark the existing API available to non-xen implementations only.

Also add new implementations, ptr_guard() and ptr_guard_mut(), for both xen and non-xen platforms, which can be used to map memory and then get a pointer to it, work on it, and unmap the memory automatically.

This also adds few custom buidkite testcases to test Xen based implementation.

Signed-off-by: Viresh Kumar viresh.kumar@linaro.org

jiangliu commented 1 year ago

Really hope GrantTable is available for kvm too:)

vireshk commented 1 year ago

Really hope GrantTable is available for kvm too:)

:)

I haven't really followed the pKvm discussions, since it is going to be about secure guests, they will surely need something similar. Either something exactly like Xen, or they may fix the mappable areas somewhere (which may have penalties in form on no ZeroCopy).

vireshk commented 1 year ago

Looks good! I didn't really look too deeply into the mmap_xen.rs code because I'm lacking Xen expertise, but everything else I'm happy with approving! It's just missing a Changelog entry for what's added (Xen support, the new API for accessing pointers to volatile slices is all I think?) and we should be good to go :)

Thanks. I have updated the changelog and also added two documentation examples (for foreign and grant mappings) in Xen's MmapRegion::from_range() helper.

roypat commented 1 year ago

Looks good! I didn't really look too deeply into the mmap_xen.rs code because I'm lacking Xen expertise, but everything else I'm happy with approving! It's just missing a Changelog entry for what's added (Xen support, the new API for accessing pointers to volatile slices is all I think?) and we should be good to go :)

Thanks. I have updated the changelog and also added two documentation examples (for foreign and grant mappings) in Xen's MmapRegion::from_range() helper.

I think you might have forgotten to push the changes? :sweat_smile:

vireshk commented 1 year ago

I think you might have forgotten to push the changes? sweat_smile

Maybe not :)

https://github.com/rust-vmm/vm-memory/pull/241/commits/65f2c8dc481fd1b3af4778025e35df9579b71c14

roypat commented 1 year ago

I think you might have forgotten to push the changes? sweat_smile

Maybe not :)

65f2c8d

ah whoops missed that, so sorry! Am still not seeing the changelog though :thinking:

vireshk commented 1 year ago

ah whoops missed that, so sorry! Am still not seeing the changelog though thinking

My mistake. I though you were asking me to update the Pull request's commit message :(, only now realized you meant CHANGELOG.md :)

Done now.

Ablu commented 1 year ago

/me is still investigating some test failures with virtiofsd. May very likely be in my setup. Will report once I figured it out.

Ablu commented 1 year ago

Tested OK with virtiofsd + small patch [1] on Xen [2] with grant mappings [3] on 6.1 series kernel [4].

Errors were my own.

[1] https://gitlab.com/ablu/virtiofsd/-/commit/9466396862dde30f3b692c6e9eacbc89044eb874 [2] https://github.com/vireshk/xen/commit/acb25f01ba63877eb960aed711fb08ed667d8314 [3] virtio = [ "type=virtio,device26,transport=mmio,grant_usage=1" ] [4] 6.1.24-yocto-standard

vireshk commented 1 year ago

Tested OK with virtiofsd + small patch [1] on Xen [2] with grant mappings [3] on 6.1 series kernel [4].

Thanks Erik.