Skip to content
This repository was archived by the owner on Nov 6, 2024. It is now read-only.

Implement and export CpuId, MsrList and Msrs as FamStructWrappers #8

Merged
merged 4 commits into from
Nov 6, 2019
Merged

Implement and export CpuId, MsrList and Msrs as FamStructWrappers #8

merged 4 commits into from
Nov 6, 2019

Conversation

acatangiu
Copy link
Contributor

Description of changes

kvm_cpuid2, kvm_msr_list and kvm_msrs each contain a flexible array member and are forcing users of them to work with unsafe code.
Implement and export CpuId, MsrList and Msrs as safe wrappers over them.

jiangliu
jiangliu previously approved these changes Oct 22, 2019
Since kvm_cpuid2 contains a flexible array member, we can implement
CpuId as a FamStructWrapper<kvm_cpuid2>. This allows users of
kvm-ioctls to work with safe code even when dealing with kvm_cpuid2.

Signed-off-by: Adrian Catangiu <acatan@amazon.com>
Since kvm_msrs contains a flexible array member, we can implement
Msrs as a FamStructWrapper<kvm_msrs>. This allows users of kvm-ioctls
to work with safe code even when dealing with kvm_msrs structures.

Signed-off-by: Adrian Catangiu <acatan@amazon.com>
Since kvm_msr_list contains a flexible array member, we can implement
MsrList as a FamStructWrapper<kvm_msr_list>. This allows users of
kvm-ioctls to work with safe code even when dealing with kvm_msr_list.

Signed-off-by: Adrian Catangiu <acatan@amazon.com>
jiangliu
jiangliu previously approved these changes Oct 23, 2019
@sameo
Copy link

sameo commented Oct 24, 2019

Although I'm not a big fan of mixing autogenerated code with manually crafted one, I still prefer to have all the structure definitions (And I consider the FAM implementations to be a structure definition) in the same place.
So, approving that one...

sameo
sameo previously approved these changes Oct 24, 2019
@andreeaflorescu
Copy link
Member

andreeaflorescu commented Oct 25, 2019

Let's put merging this PR a bit on hold. I am mainly concerned about the dependency on vmm-sys-util. During the rust-vmm meetup we discussed with CrosVM about consuming rust-vmm crates and kvm-bindings was one of the low hanging fruits. As they have a different process for consuming crates, we should double check with them if they still want to use this crate and if adding a vmm-sys-util dependency is fine with them.

CC: @dgreid @zachreizner

@acatangiu
Copy link
Contributor Author

acatangiu commented Oct 29, 2019

Let's put merging this PR a bit on hold. I am mainly concerned about the dependency on vmm-sys-util. During the rust-vmm meetup we discussed with CrosVM about consuming rust-vmm crates and kvm-bindings was one of the low hanging fruits. As they have a different process for consuming crates, we should double check with them if they still want to use this crate and if adding a vmm-sys-util dependency is fine with them.

@andreeaflorescu I don't think this is a good principle to apply to decisions regarding the rust-vmm crates design/features. I believe we should strive to do what's best for the crate and the rust-vmm project in general, even when that might make things harder for a particular consumer because of their internal/private process of consuming crates. We should aim for maximizing the collective gain.

Regarding CrosVM in particular, I believe that vmm-sys-util is also a low hanging fruit for an useful crate they can consume from rust-vmm.

CC: @dgreid @zachreizner

@alexandruag
Copy link
Contributor

I think we shouldn't dismiss dependency management so easily. Besides, it seems straightforward to add a feature to gate the inclusion of the FAM wrappers (and the vmm-sys-util dependency). How about we do just that for now?

@andreeaflorescu
Copy link
Member

Is the plan to update the PR and make the dependency optional?

@acatangiu
Copy link
Contributor Author

Is the plan to update the PR and make the dependency optional?

That’s a good idea to solve the dependency problem if there ever was one, still waiting on feedback.

@jiangliu
Copy link
Member

Could we make the feature as default?

@acatangiu acatangiu dismissed stale reviews from sameo and jiangliu via 35373e2 October 31, 2019 09:22
@acatangiu
Copy link
Contributor Author

acatangiu commented Oct 31, 2019

@andreeaflorescu @jiangliu @sameo I've updated the PR to condition the safe-wrappers and the vmm-sys-util dependency on a crate feature.

The safe-wrappers feature is enabled by default. Any consumers of kvm-bindings who do not want the wrappers or do not want the vmm-sys-util dependency can opt-out and disable both.

jiangliu
jiangliu previously approved these changes Oct 31, 2019
@alexandruag
Copy link
Contributor

From what I've seen so far, features should be opt-in unless there's a good reason to do otherwise. This follows the principle of least astonishment, as it prevents users from unknowingly pulling unnecessary code/dependencies either directly or via transitive dependencies.

@jiangliu, I was just wondering, does having this feature on by default enable any use case that becomes difficult or inconvenient otherwise?

@acatangiu
Copy link
Contributor Author

acatangiu commented Nov 4, 2019

@alexandruag I was not aware of the principle of least astonishment.
I did, however, look at the top downloaded crates on crates.io and saw that most come with a default list of features. Some examples from the top 10 most downloaded crates:

Therefore, I'm not sure what is the canonic path we should take. I made a judgement-call of including the safe wrappers by default, but I don't see that as a blocker, both ways work and I can update the PR to not have them by default.

@aghecenco @andreeaflorescu @sameo @jiangliu what is your view (tagging the code-owners of this crate)?

@alexandruag
Copy link
Contributor

There's no absolute rule here, but I think making people "opt-in" into things they want/need to use instead of surprising them with a default configuration of features is a very sound design principle, especially because it means the least amount of additions are present by default (in most cases).

To give an example, let's say crate A has some features which are enabled by default, and crate B uses crate A without needing any of the features, but doesn't disable any of them either. If I would like to use crate B in my project, I kinda have to deal with all those dependencies/code coming from A via features, even though they're not necessary.

It would be very interesting to know if there's an use case that's impacted by having features off by default.

@jiangliu
Copy link
Member

jiangliu commented Nov 4, 2019

I changed my mind:)
Letting users to explicitly opt-in features may be a good choice for rust-vmm because we want to control all external dependencies.

@acatangiu
Copy link
Contributor Author

@andreeaflorescu @alexandruag @jiangliu I've removed the feature from the default list of features. It is now opt-in.

jiangliu
jiangliu previously approved these changes Nov 5, 2019
Copy link
Member

@andreeaflorescu andreeaflorescu left a comment

Choose a reason for hiding this comment

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

We should also update the readme to specify that we now have a new feature and describe why/how to use it.

@acatangiu
Copy link
Contributor Author

acatangiu commented Nov 6, 2019

Addressed all comments, please re-review.

I will add a CHANGELOG entry in a following PR where I'll also do the version bump.

sameo
sameo previously approved these changes Nov 6, 2019
@acatangiu
Copy link
Contributor Author

@sameo @jiangliu I've updated the Readme at @andreeaflorescu's suggestion. Please take another look.

The FamStructWrappers definitions as well as the vmm-sys-util
dependency are now gated by an opt-in `fam-wrappers` feature.

Signed-off-by: Adrian Catangiu <acatan@amazon.com>
@sameo sameo merged commit 0c1c171 into rust-vmm:master Nov 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants