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

Commit c545742

Browse files
acatangiuSamuel Ortiz
authored and
Samuel Ortiz
committed
implement Msrs as a FamStructWrapper over kvm_msrs
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 <[email protected]>
1 parent bbb2b52 commit c545742

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/x86/fam_wrappers.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ use super::bindings_v4_20_0::*;
1717
/// See arch/x86/include/asm/kvm_host.h
1818
pub const KVM_MAX_CPUID_ENTRIES: usize = 80;
1919

20+
/// Maximum number of MSRs KVM supports (See arch/x86/kvm/x86.c).
21+
pub const KVM_MAX_MSR_ENTRIES: usize = 256;
22+
2023
// Implement the FamStruct trait for kvm_cpuid2.
2124
generate_fam_struct_impl!(
2225
kvm_cpuid2,
@@ -35,3 +38,22 @@ generate_fam_struct_impl!(
3538
/// the array elements, this type is implemented using
3639
/// [FamStructWrapper](../vmm_sys_util/fam/struct.FamStructWrapper.html).
3740
pub type CpuId = FamStructWrapper<kvm_cpuid2>;
41+
42+
// Implement the FamStruct trait for kvm_msrs.
43+
generate_fam_struct_impl!(
44+
kvm_msrs,
45+
kvm_msr_entry,
46+
entries,
47+
u32,
48+
nmsrs,
49+
KVM_MAX_MSR_ENTRIES
50+
);
51+
52+
/// Wrapper over the `kvm_msrs` structure.
53+
///
54+
/// The `kvm_msrs` structure contains a flexible array member. For details check the
55+
/// [KVM API](https://www.kernel.org/doc/Documentation/virtual/kvm/api.txt)
56+
/// documentation on `kvm_msrs`. To provide safe access to
57+
/// the array elements, this type is implemented using
58+
/// [FamStructWrapper](../vmm_sys_util/fam/struct.FamStructWrapper.html).
59+
pub type Msrs = FamStructWrapper<kvm_msrs>;

0 commit comments

Comments
 (0)