-
Notifications
You must be signed in to change notification settings - Fork 74
Implement and export CpuId, MsrList and Msrs as FamStructWrappers #8
Conversation
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>
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. |
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 |
@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 CC: @dgreid @zachreizner |
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 |
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. |
Could we make the feature as default? |
@andreeaflorescu @jiangliu @sameo I've updated the PR to condition the safe-wrappers and the The |
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? |
@alexandruag I was not aware of the principle of least astonishment. 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)? |
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 It would be very interesting to know if there's an use case that's impacted by having features off by default. |
I changed my mind:) |
@andreeaflorescu @alexandruag @jiangliu I've removed the feature from the default list of features. It is now opt-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.
We should also update the readme to specify that we now have a new feature and describe why/how to use it.
Addressed all comments, please re-review. I will add a |
@sameo @jiangliu I've updated the |
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>
Description of changes
kvm_cpuid2
,kvm_msr_list
andkvm_msrs
each contain a flexible array member and are forcing users of them to work withunsafe
code.Implement and export
CpuId
,MsrList
andMsrs
as safe wrappers over them.