From 7ca9f771e7f406ff95b5b554bbefacbc8f8d6e63 Mon Sep 17 00:00:00 2001 From: Zach Reizner Date: Tue, 6 Feb 2018 20:50:07 -0800 Subject: 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 Tested-by: Zach Reizner Reviewed-by: Dylan Reid --- crosvm_plugin/Cargo.toml | 2 +- crosvm_plugin/crosvm.h | 6 +++++- crosvm_plugin/src/lib.rs | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) (limited to 'crosvm_plugin') 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 = 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, + } +} -- cgit 1.4.1