summary refs log tree commit diff
path: root/kvm/src/lib.rs
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor@chromium.org>2018-02-22 15:37:49 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-02-27 20:17:42 -0800
commitc73d39052258a7c40417424ecadabccba6233041 (patch)
treec533c711fb7996ab9bd7e780637fb98d9ba5df1d /kvm/src/lib.rs
parentae5878bef11d603c17e2b970816b8298d2f570ee (diff)
downloadcrosvm-c73d39052258a7c40417424ecadabccba6233041.tar
crosvm-c73d39052258a7c40417424ecadabccba6233041.tar.gz
crosvm-c73d39052258a7c40417424ecadabccba6233041.tar.bz2
crosvm-c73d39052258a7c40417424ecadabccba6233041.tar.lz
crosvm-c73d39052258a7c40417424ecadabccba6233041.tar.xz
crosvm-c73d39052258a7c40417424ecadabccba6233041.tar.zst
crosvm-c73d39052258a7c40417424ecadabccba6233041.zip
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 <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/933243
Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'kvm/src/lib.rs')
-rw-r--r--kvm/src/lib.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/kvm/src/lib.rs b/kvm/src/lib.rs
index 1c75010..d7af7b5 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<CpuId> {
+    fn get_cpuid(&self, kind: u64) -> Result<CpuId> {
         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<CpuId> {
+        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<CpuId> {
+        self.get_cpuid(KVM_GET_EMULATED_CPUID())
+    }
 }
 
 impl AsRawFd for Kvm {