From c73d39052258a7c40417424ecadabccba6233041 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Thu, 22 Feb 2018 15:37:49 -0800 Subject: [PATCH] kvm: plumb in KVM_GET_EMULATED_CPUID This plumbs in KVM_GET_EMULATED_CPUID to allow userspace to figure out whether a certain feature(s) can be used or whether they are too expensive. TEST=cargo test --features plugin; cargo test -p kvm BUG=chromium:800626 Change-Id: I914415a311f40d079b1703efb5129fd91b0d24ad Signed-off-by: Dmitry Torokhov Reviewed-on: https://chromium-review.googlesource.com/933243 Reviewed-by: Zach Reizner --- kvm/src/lib.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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 {