diff --git a/kvm/src/lib.rs b/kvm/src/lib.rs index 1c75010ea6..d7af7b56aa 100644 --- a/kvm/src/lib.rs +++ b/kvm/src/lib.rs @@ -133,16 +133,15 @@ impl Kvm { } } - /// X86 specific call to get the system supported CPUID values #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - pub fn get_supported_cpuid(&self) -> Result { + fn get_cpuid(&self, kind: u64) -> Result { let mut cpuid = CpuId::new(MAX_KVM_CPUID_ENTRIES); let ret = unsafe { // ioctl is unsafe. The kernel is trusted not to write beyond the bounds of the memory // allocated for the struct. The limit is read from nent, which is set to the allocated // size(MAX_KVM_CPUID_ENTRIES) above. - ioctl_with_mut_ptr(self, KVM_GET_SUPPORTED_CPUID(), cpuid.as_mut_ptr()) + ioctl_with_mut_ptr(self, kind, cpuid.as_mut_ptr()) }; if ret < 0 { return errno_result(); @@ -150,6 +149,18 @@ impl Kvm { Ok(cpuid) } + + /// X86 specific call to get the system supported CPUID values + #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] + pub fn get_supported_cpuid(&self) -> Result { + self.get_cpuid(KVM_GET_SUPPORTED_CPUID()) + } + + /// X86 specific call to get the system emulated CPUID values + #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] + pub fn get_emulated_cpuid(&self) -> Result { + self.get_cpuid(KVM_GET_EMULATED_CPUID()) + } } impl AsRawFd for Kvm {