summary refs log tree commit diff
path: root/crosvm_plugin
diff options
context:
space:
mode:
authorZach Reizner <zachr@google.com>2018-02-06 20:50:07 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-02-12 22:42:38 -0800
commit7ca9f771e7f406ff95b5b554bbefacbc8f8d6e63 (patch)
treeb0cd9cf9353234b3d0bc2529e445b52ce28a8768 /crosvm_plugin
parentce8961d1fcba5724553ba21288fbec752b0c00bf (diff)
downloadcrosvm-7ca9f771e7f406ff95b5b554bbefacbc8f8d6e63.tar
crosvm-7ca9f771e7f406ff95b5b554bbefacbc8f8d6e63.tar.gz
crosvm-7ca9f771e7f406ff95b5b554bbefacbc8f8d6e63.tar.bz2
crosvm-7ca9f771e7f406ff95b5b554bbefacbc8f8d6e63.tar.lz
crosvm-7ca9f771e7f406ff95b5b554bbefacbc8f8d6e63.tar.xz
crosvm-7ca9f771e7f406ff95b5b554bbefacbc8f8d6e63.tar.zst
crosvm-7ca9f771e7f406ff95b5b554bbefacbc8f8d6e63.zip
add plugin support for configuring CPUID
The guest expects to be able to read the CPUID, so the plugin process
needs to specify what the CPUID for each VCPU will have.

TEST=cargo test --features plugin; ./build_test
BUG=chromium:800626

Change-Id: I9258540ab2501126c3d8cadbd09b7fc01d19f7a9
Reviewed-on: https://chromium-review.googlesource.com/906006
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'crosvm_plugin')
-rw-r--r--crosvm_plugin/Cargo.toml2
-rw-r--r--crosvm_plugin/crosvm.h6
-rw-r--r--crosvm_plugin/src/lib.rs36
3 files changed, 41 insertions, 3 deletions
diff --git a/crosvm_plugin/Cargo.toml b/crosvm_plugin/Cargo.toml
index b650f3a..f6aeb24 100644
--- a/crosvm_plugin/Cargo.toml
+++ b/crosvm_plugin/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "crosvm_plugin"
-version = "0.8.0"
+version = "0.9.0"
 authors = ["The Chromium OS Authors"]
 
 [lib]
diff --git a/crosvm_plugin/crosvm.h b/crosvm_plugin/crosvm.h
index d6eafb6..1bdcec6 100644
--- a/crosvm_plugin/crosvm.h
+++ b/crosvm_plugin/crosvm.h
@@ -47,7 +47,7 @@ extern "C" {
  * do not indicate anything about what version of crosvm is running.
  */
 #define CROSVM_API_MAJOR 0
-#define CROSVM_API_MINOR 8
+#define CROSVM_API_MINOR 9
 #define CROSVM_API_PATCH 0
 
 enum crosvm_address_space {
@@ -430,6 +430,10 @@ int crosvm_vcpu_get_msrs(struct crosvm_vcpu*, uint32_t __msr_count,
 int crosvm_vcpu_set_msrs(struct crosvm_vcpu*, uint32_t __msr_count,
                          const struct kvm_msr_entry *__msr_entries);
 
+/* Sets the responses to the cpuid instructions executed on this vcpu, */
+int crosvm_vcpu_set_cpuid(struct crosvm_vcpu*, uint32_t __cpuid_count,
+                          const struct kvm_cpuid_entry2 *__cpuid_entries);
+
 #ifdef  __cplusplus
 }
 #endif
diff --git a/crosvm_plugin/src/lib.rs b/crosvm_plugin/src/lib.rs
index e383a1b..102d129 100644
--- a/crosvm_plugin/src/lib.rs
+++ b/crosvm_plugin/src/lib.rs
@@ -43,7 +43,8 @@ use sys_util::Scm;
 
 use kvm::dirty_log_bitmap_size;
 
-use kvm_sys::{kvm_regs, kvm_sregs, kvm_fpu, kvm_debugregs, kvm_msr_entry};
+use kvm_sys::{kvm_regs, kvm_sregs, kvm_fpu, kvm_debugregs, kvm_msr_entry, kvm_cpuid_entry2,
+              KVM_CPUID_FLAG_SIGNIFCANT_INDEX};
 
 use plugin_proto::*;
 
@@ -736,6 +737,26 @@ impl crosvm_vcpu {
         self.vcpu_transaction(&r)?;
         Ok(())
     }
+
+    fn set_cpuid(&mut self, cpuid_entries: &[kvm_cpuid_entry2]) -> result::Result<(), c_int> {
+        let mut r = VcpuRequest::new();
+        {
+            let set_cpuid_entries: &mut RepeatedField<CpuidEntry> = r.mut_set_cpuid().mut_entries();
+            for cpuid_entry in cpuid_entries.iter() {
+                let mut entry = CpuidEntry::new();
+                entry.function = cpuid_entry.function;
+                entry.has_index = cpuid_entry.flags & KVM_CPUID_FLAG_SIGNIFCANT_INDEX != 0;
+                entry.index = cpuid_entry.index;
+                entry.eax = cpuid_entry.eax;
+                entry.ebx = cpuid_entry.ebx;
+                entry.ecx = cpuid_entry.ecx;
+                entry.edx = cpuid_entry.edx;
+                set_cpuid_entries.push(entry);
+            }
+        }
+        self.vcpu_transaction(&r)?;
+        Ok(())
+    }
 }
 
 #[no_mangle]
@@ -1005,3 +1026,16 @@ pub unsafe extern "C" fn crosvm_vcpu_set_msrs(this: *mut crosvm_vcpu,
         Err(e) => e,
     }
 }
+
+#[no_mangle]
+pub unsafe extern "C" fn crosvm_vcpu_set_cpuid(this: *mut crosvm_vcpu,
+                                               cpuid_count: u32,
+                                               cpuid_entries: *const kvm_cpuid_entry2)
+                                               -> c_int {
+    let this = &mut *this;
+    let cpuid_entries = from_raw_parts(cpuid_entries, cpuid_count as usize);
+    match this.set_cpuid(cpuid_entries) {
+        Ok(_) => 0,
+        Err(e) => e,
+    }
+}