-
Notifications
You must be signed in to change notification settings - Fork 102
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
mmap_unix: add support for externally managed mappings #109
Conversation
Hi! If possible, can you please share more details regarding the use case(s) for this change? Some of the usage examples I'm trying to think of can be accomplished via alternative means (for example, mapping the same |
@alexandruag In libkrun we need to create a MmapRegion for a section coming from a dynamically linked library that has been mapped by the linker. The file backing the library may no longer be accessible due to context changes (namespace manipulation). I acknowledge that our use case may be a bit particular, but I think the change we need in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation! libkrun
looks very interesting! Just left a minor comment, and it seems you also need to update the coverage value in coverage_config_x86_64
(more details on the CI results page).
src/mmap_unix.rs
Outdated
@@ -79,6 +79,7 @@ pub struct MmapRegion { | |||
file_offset: Option<FileOffset>, | |||
prot: i32, | |||
flags: i32, | |||
external: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
owned
might be a bit more suggestive here (+ reversing the significance of true/false
), WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me.
@alexandruag Thanks! I've updated the PR to replace |
Looks good! I just realized there are two points I forgot to mention in my previous comment, sorry about that :( While I don't think this is mentioned anywhere yet, we do effectively rely on regions having certain alignment and size restrictions. I guess it will be simplest to state at some point (and check) that a region is aligned to a page boundary and its size is a multiple of the page size. Does that hamper your use case in any way? Also, I forgot we have a changelog now :-s Can you please add an |
We do have some implicit assumption that the base address of a region is PAGE aligned. And on Linux, the mmap() syscall ensures that file offset and returned address are page aligned. Not sure about the behavior mmap on Windows. |
Sounds good, and shouldn't be a problem for libkrun. I've just added those checks and extended the test to ensure it also fails when expected. Could you please take a look?
Sure, no problem. I see all the existing entries refer to an issue, do I need to create one covering the goal of this PR? |
Hm... coverage has dropped by 0.30% now... will take a look at it tomorrow. |
Okay, so the coverage drop was caused by the newly added |
Thanks for the changes! Things look good. We'll document the alignment & such requirements after we polish the interface a bit more, and by then we should also figure out what the exact model & semantics are (regions being aligned looks mandatory, but the others might be relaxed). I think it's fine to use a reference to the PR itself in the change log as well, but just in case this contradicts some style guidelines we're trying to establish, do you mind if we wait just a bit more to see if others have a different opinion? |
No problem, we can wait a bit to see what's the consensus about that. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the changelog, since there is no associated issue with this PR, we can either create one, or link the PR. As @alexandruag said, we don';t really have any policy regarding this yet.
Also, sorry for jumping in with the review so late. Feel free to consider my comments nits and address them in a subsequent PR. They are mostly related to documenting the added functionality so that external users have an easier time :D
ceff87b
to
d4306e9
Compare
@andreeaflorescu I've rebased the commit and addressed your comments. PTAL, thanks! |
Add the unsafe MmapRegion::build_raw method to allow users to instance MmapRegion with externally managed mappings. Add also a field to indicate whether the mapping is owned by the MmapRegion instance or not, so we don't try to munmap it on MmapRegion::Drop. Signed-off-by: Sergio Lopez <[email protected]>
I've just noticed that I forgot to add the entry to |
Add the unsafe MmapRegion::build_raw method to allow users to instance
MmapRegion with externally managed mappings. Add also a field to
indicate whether the mapping is internal or external, so we don't try
to munmap it on MmapRegion::Drop.
Signed-off-by: Sergio Lopez [email protected]