summary refs log tree commit diff
path: root/crosvm_plugin
diff options
context:
space:
mode:
authorZach Reizner <zachr@google.com>2018-02-01 19:12:32 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-02-12 22:42:36 -0800
commit7a4d7b1f50d07e7f0ae350c27659c6e852da62c7 (patch)
tree5efb7e9cb9d7f32e90985a19b7875f9f6936470b /crosvm_plugin
parent53528e33eda615ef309915447b227d2dcacb2090 (diff)
downloadcrosvm-7a4d7b1f50d07e7f0ae350c27659c6e852da62c7.tar
crosvm-7a4d7b1f50d07e7f0ae350c27659c6e852da62c7.tar.gz
crosvm-7a4d7b1f50d07e7f0ae350c27659c6e852da62c7.tar.bz2
crosvm-7a4d7b1f50d07e7f0ae350c27659c6e852da62c7.tar.lz
crosvm-7a4d7b1f50d07e7f0ae350c27659c6e852da62c7.tar.xz
crosvm-7a4d7b1f50d07e7f0ae350c27659c6e852da62c7.tar.zst
crosvm-7a4d7b1f50d07e7f0ae350c27659c6e852da62c7.zip
add plugin support for model specific registers
The MSRs are useful for booting a full operating system that requires
them.

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

Change-Id: I817fbf3e6868c85b373808bd48e568b5b2b458eb
Reviewed-on: https://chromium-review.googlesource.com/897412
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'crosvm_plugin')
-rw-r--r--crosvm_plugin/Cargo.toml2
-rw-r--r--crosvm_plugin/crosvm.h9
-rw-r--r--crosvm_plugin/src/lib.rs70
3 files changed, 78 insertions, 3 deletions
diff --git a/crosvm_plugin/Cargo.toml b/crosvm_plugin/Cargo.toml
index 6b37961..5b6833a 100644
--- a/crosvm_plugin/Cargo.toml
+++ b/crosvm_plugin/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "crosvm_plugin"
-version = "0.6.0"
+version = "0.7.0"
 authors = ["The Chromium OS Authors"]
 
 [lib]
diff --git a/crosvm_plugin/crosvm.h b/crosvm_plugin/crosvm.h
index 16dc3a5..47f3eb9 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 6
+#define CROSVM_API_MINOR 7
 #define CROSVM_API_PATCH 0
 
 enum crosvm_address_space {
@@ -419,6 +419,13 @@ int crosvm_vcpu_get_debugregs(struct crosvm_vcpu*, struct kvm_debugregs*);
 /* Sets the state of the vcpu's debug registers */
 int crosvm_vcpu_set_debugregs(struct crosvm_vcpu*, const struct kvm_debugregs*);
 
+/* Gets the MSRs of the vcpu indicated by the index field of each entry. */
+int crosvm_vcpu_get_msrs(struct crosvm_vcpu*, uint32_t __msr_count,
+                         struct kvm_msr_entry *__msr_entries);
+/* Sets the MSRs of the vcpu indicated by the index field of each entry. */
+int crosvm_vcpu_set_msrs(struct crosvm_vcpu*, uint32_t __msr_count,
+                         const struct kvm_msr_entry *__msr_entries);
+
 #ifdef  __cplusplus
 }
 #endif
diff --git a/crosvm_plugin/src/lib.rs b/crosvm_plugin/src/lib.rs
index 1482853..91335d7 100644
--- a/crosvm_plugin/src/lib.rs
+++ b/crosvm_plugin/src/lib.rs
@@ -43,7 +43,7 @@ use sys_util::Scm;
 
 use kvm::dirty_log_bitmap_size;
 
-use kvm_sys::{kvm_regs, kvm_sregs, kvm_fpu, kvm_debugregs};
+use kvm_sys::{kvm_regs, kvm_sregs, kvm_fpu, kvm_debugregs, kvm_msr_entry};
 
 use plugin_proto::*;
 
@@ -692,6 +692,48 @@ impl crosvm_vcpu {
         self.vcpu_transaction(&r)?;
         Ok(())
     }
+
+    fn get_msrs(&mut self, msr_entries: &mut [kvm_msr_entry]) -> result::Result<(), c_int> {
+        let mut r = VcpuRequest::new();
+        {
+            let entry_indices: &mut Vec<u32> = r.mut_get_msrs().mut_entry_indices();
+            for entry in msr_entries.iter() {
+                entry_indices.push(entry.index);
+            }
+        }
+        let response = self.vcpu_transaction(&r)?;
+        if !response.has_get_msrs() {
+            return Err(-EPROTO);
+        }
+        let get_msrs: &VcpuResponse_GetMsrs = response.get_get_msrs();
+        if get_msrs.get_entry_data().len() != msr_entries.len() {
+            return Err(-EPROTO);
+        }
+        for (&msr_data, msr_entry) in
+            get_msrs
+                .get_entry_data()
+                .iter()
+                .zip(msr_entries.iter_mut()) {
+            msr_entry.data = msr_data;
+        }
+        Ok(())
+    }
+
+    fn set_msrs(&mut self, msr_entries: &[kvm_msr_entry]) -> result::Result<(), c_int> {
+        let mut r = VcpuRequest::new();
+        {
+            let set_msrs_entries: &mut RepeatedField<VcpuRequest_MsrEntry> = r.mut_set_msrs()
+                .mut_entries();
+            for msr_entry in msr_entries.iter() {
+                let mut entry = VcpuRequest_MsrEntry::new();
+                entry.index = msr_entry.index;
+                entry.data = msr_entry.data;
+                set_msrs_entries.push(entry);
+            }
+        }
+        self.vcpu_transaction(&r)?;
+        Ok(())
+    }
 }
 
 #[no_mangle]
@@ -935,3 +977,29 @@ pub unsafe extern "C" fn crosvm_vcpu_set_debugregs(this: *mut crosvm_vcpu,
         Err(e) => e,
     }
 }
+
+#[no_mangle]
+pub unsafe extern "C" fn crosvm_vcpu_get_msrs(this: *mut crosvm_vcpu,
+                                              msr_count: u32,
+                                              msr_entries: *mut kvm_msr_entry)
+                                              -> c_int {
+    let this = &mut *this;
+    let msr_entries = from_raw_parts_mut(msr_entries, msr_count as usize);
+    match this.get_msrs(msr_entries) {
+        Ok(_) => 0,
+        Err(e) => e,
+    }
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn crosvm_vcpu_set_msrs(this: *mut crosvm_vcpu,
+                                              msr_count: u32,
+                                              msr_entries: *const kvm_msr_entry)
+                                              -> c_int {
+    let this = &mut *this;
+    let msr_entries = from_raw_parts(msr_entries, msr_count as usize);
+    match this.set_msrs(msr_entries) {
+        Ok(_) => 0,
+        Err(e) => e,
+    }
+}