-
Notifications
You must be signed in to change notification settings - Fork 103
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/reorg #235
Mmap/reorg #235
Conversation
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.
just some minor comments. People with deeper code knowledge will have to comment on the architecture :).
d585fe1
to
cebaa62
Compare
67c2ce1
to
cb5acf0
Compare
On volatile_memory: Remove redundant unsafe blocks while the lint name doesn't spring to my mind immediately I beleive there is a lint for checking for |
@epilys did mention about another lint which can be of use here: rust-lang/rust#71668 I couldn't find a lint which will warn if |
@JonathanWoollett-Light @vireshk the lint for nested |
The opposite is what rustc will require in the feature (unsafe actions in unsafe fn bodies will require unsafe blocks) I mixed up the RFC name with the lint name, it appears the lint is actually stable since 1.52: https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unsafe-op-in-unsafe-fn |
e668e10
to
6cfe417
Compare
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.
Alright, I've gone through all the commits. 075e37c is fine, but for the others I have some high level questions/comments.
- 57693f1: As others have already pointed out, there is https://rust-lang.github.io/rfcs/2585-unsafe-block-in-unsafe-fn.html, which is an accepted rust-lang RFC and means that going forwards, not having the unsafe blocks will be at the very least a warning. We should maybe consider enabling this lint ahead of time for this crate, but that's out of scope here. Having the unsafe blocks even inside unsafe functions is quite valuable imo, because it immediately tells you what parts of a function is actually performing unsafe operations, and also forces you to accurately document the safety invariants (by means of
#![deny(clippy::undocumented_unsafe_blocks)]
). In that sense, I don't think this commit is a change we want to do. - 4d73f17: The call stack of these methods is starting to be very deep, which makes understanding the code pretty complex (this is already a big problem in this crate, but I'd like to not make it worse). In this PR all the new methods have exactly one call-site. I think the context for these changes is that in the follow up, you'll want to call these from different cfg'd contexts. However, as Andreea noted on that PR, you can mark individual lines of code with
#[cfg(...)]
instead of whole methods. With that, the number of call-sites should stay at 1 I think, and these functions can be re-inlined, so this commit isn't necessary. - f3a9fc5: The changes in this commit are not motivated in the commit message. I'm not sure why this is required, and it adds cognitive similar complexity as the previous commit. I see that in the follow up PR, it is this structure that VolatileSlice gains a reference to, but why can't we just reuse
MmapRegion
there? The type parameter shouldn't cause problems, since VolatileSlice has it, too. - 6cfe417: I understand that this is based on a concern Andreea had on the follow up PR. My main concern is the same as the previous two commits, that we start introducing too many layers of abstraction here. The structures added here are a new layer on top of MmapRegionBuilder. The diff of this commit touches mostly on test code, so I think what happened at some point in the past is that someone did not want to use the builder in test code, so they added the tuple-based construction methods as shortcuts. Any actual new information that is used during construction of MmapRegions should be integrated with the MmapRegionBuilder (e.g. the two new Xen fields from the follow up PR should become #[cfg(xen)] fields in the build, with associated setters). Outside of test code, the builder should always be used to construct mmap regions. In that sense, I think the implementation how it was previous to this commit is fine (it should probabl be moved into a test module, but I'd like to keep breaking changes to the public API to a minimum). However, this problem will resurface when it comes to testing the Xen code, as using builders is probably overly verbose. I propose we revisit when it comes to that point, and then add a subset of the changes introduced in this commit (having a struct that encapsules the fields of the tuple, and a utility method that uses the build to construct a GuestMmapRegion from the tuple-struct) in the Xen test module. The existing methods can be then marked as
#[cfg(not(xen))]
.
Sorry if this is a lot (or if I got some things wrong - cross-referencing with the other PR was difficult at time). The main themes in my feedback are keeping hierarchies flat, and keeping the changes to the public API for non-xen users minimal. Before I do another of this PR/the follow up, could you try addressing @andreeaflorescu's comment in the other PR about minimizing the scope of cfg blocks? I think that will make review a lot easier, and should bring down the size of the diffs quite a bit too. Thanks!
Add separate helpers to copy from and to the volatile slice. This allows the real logic to be present at a single place, which can be easily updated for special cases later on. For example extra memory mapping for systems where the regions can't be mapped in advance, like in case of Xen's Grant mappings. Signed-off-by: Viresh Kumar <[email protected]>
Add a separate structure to represent the memory mapped with mmap(), which can be freed automatically from drop(). Also move MmapRegion creation code to MmapRegionBuilder::build_region(). Signed-off-by: Viresh Kumar <[email protected]>
Thanks for the review Patrick, really appreciate it !
Dropped.
It may look messy without that, but I am okay with dropping it. Dropped.
I am not sure I understood that.
There are a couple of reasons for that:
Yeah, this is exactly what I have done for
Hmm, not really I guess.
I am fine with whatever changes I need to make to get over with this work. I just want to get over this soon :)
Sure.
Hmm, I already did a lot of that and the diff is really small now comparatively (from where I started). Since there is a lot of code to review here, I would really prefer to get this pull request merged before we start reviewing the other one, which introduces Xen based stuff. I understand that you had to look at the other pull requests too, to get an insight on how things are getting used eventually and it is not super easy. My idea behind this separate pull request was to try and make the review process easier and shorter and merge code that is already reviewed, instead of waiting for the rest of it to be ready as well. I have repushed this branch now after removing the two commits and making the bitmap change you suggested. Thanks. |
The list of (similar) arguments for various structures used for memory mapping is getting long and that leads to a wide variety of functions with different signatures. Simplify the same with the help of two new structures: MmapRange and GuestMmapRange. This also allows the structures to be incrementally updated for different memory mapping models later on, like Xen, without updating the signature of the methods anymore. Signed-off-by: Viresh Kumar <[email protected]>
Now that I have rebased xen/mmapv2 over the new changes (and pushed), it doesn't look that messy afterall. :) |
I meant that the commit message only explains what the commit is doing, but not why. Got it now though, thanks for the explanation!
Ah, I think this is actually a pretty common pattern in rust. All the structures that take ownership over raw file descriptors (e.g. File::from_raw_fd) come to mind :)
Okay, but for unix, we don't need anything extra in
Mh, yeah, right now it is, but it doesnt have to stay that way. Instead of adding shared abstraction on top of it, we can just extend the builder to cover both xen and unix, with setters/fields being appropriately cfg'd and then maybe different .build methods. Because right now, what used to be
Right, yeah, this was my main problem - I needed to cross-ref between two git checkouts, which was a bit tedious at times xP
|
For unix we used to have For xen, I need a new parameter to all the |
This is already done in my other patchset. We have a method named The problem is that we need something for
I can merge the The new structure
Right.
This is bound to happen when the code is required to do more and handle more complex cases, I don't how this can be avoided. I am sure that initially we won't have wanted to keep separate files like
This call stack provides extra information, i.e.
We do use it :)
This new strucuture is really useful to free the resources ( |
Replaced by: #241 |
This reorganizes some code in the vm-memory crate, which will later be used by:
#231