From 9786573e07992d43bfd5304ca7490a35aca2c61f Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Mon, 26 Feb 2018 15:17:53 -0800 Subject: allow plugin to query KVM for supported/emulated CPUIDs This plumbs calls to KVM_GET_SUPPORTED_CPUID and KVM_GET_EMULATED_CPUID to be available to plugins. TEST=cargo test --features plugin; cargo test -p kvm BUG=chromium:800626 Change-Id: I98879599b5f970c6c2720772658689a505d8abe1 Signed-off-by: Dmitry Torokhov Reviewed-on: https://chromium-review.googlesource.com/938674 Reviewed-by: Zach Reizner --- src/plugin/mod.rs | 4 ++-- src/plugin/process.rs | 30 +++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) (limited to 'src/plugin') diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index 44cba39..4d164a4 100644 --- a/src/plugin/mod.rs +++ b/src/plugin/mod.rs @@ -405,7 +405,7 @@ pub fn run_config(cfg: Config) -> Result<()> { let kvm = Kvm::new().map_err(Error::CreateKvm)?; let mut vm = Vm::new(&kvm, mem).map_err(Error::CreateVm)?; vm.create_irq_chip().map_err(Error::CreateIrqChip)?; - let mut plugin = Process::new(vcpu_count, &mut vm, plugin_path, &plugin_args, jail)?; + let mut plugin = Process::new(vcpu_count, &kvm, &mut vm, plugin_path, &plugin_args, jail)?; let mut res = Ok(()); // If Some, we will exit after enough time is passed to shutdown cleanly. @@ -530,7 +530,7 @@ pub fn run_config(cfg: Config) -> Result<()> { } t if t >= PLUGIN_BASE && t < PLUGIN_BASE + (plugin.sockets().len() as u32) => { let socket_index = (t - PLUGIN_BASE) as usize; - match plugin.handle_socket(socket_index, &mut vm, &vcpu_handles) { + match plugin.handle_socket(socket_index, &kvm, &mut vm, &vcpu_handles) { Ok(_) => {} // A HUP is an expected event for a socket, so don't bother warning about // it. diff --git a/src/plugin/process.rs b/src/plugin/process.rs index aa4a907..89c201c 100644 --- a/src/plugin/process.rs +++ b/src/plugin/process.rs @@ -73,6 +73,7 @@ impl Process { /// Due to an API limitation in libminijail necessitating that this function set an environment /// variable, this function is not thread-safe. pub fn new(cpu_count: u32, + kvm: &Kvm, vm: &mut Vm, cmd: &Path, args: &[&str], @@ -125,13 +126,13 @@ impl Process { response_buffer: Vec::new(), }; - plugin.run_until_started(vm)?; + plugin.run_until_started(kvm, vm)?; Ok(plugin) } - fn run_until_started(&mut self, vm: &mut Vm) -> Result<()> { + fn run_until_started(&mut self, kvm: &Kvm, vm: &mut Vm) -> Result<()> { let mut sockets_to_drop = Vec::new(); let mut poller = Poller::new(1); while !self.started { @@ -150,7 +151,7 @@ impl Process { }; for &token in tokens { - match self.handle_socket(token as usize, vm, &[]) { + match self.handle_socket(token as usize, kvm, vm, &[]) { Ok(_) => {} Err(Error::PluginSocketHup) => sockets_to_drop.push(token as usize), r => return r, @@ -388,6 +389,7 @@ impl Process { /// interrupt a VCPU thread currently running in the VM if the socket request it. pub fn handle_socket(&mut self, index: usize, + kvm: &Kvm, vm: &mut Vm, vcpu_handles: &[JoinHandle<()>]) -> Result<()> { @@ -533,6 +535,28 @@ impl Process { } _ => Err(SysError::new(-ENOENT)), } + } else if request.has_get_supported_cpuid() { + let cpuid_response = &mut response.mut_get_supported_cpuid().entries; + match kvm.get_supported_cpuid() { + Ok(mut cpuid) => { + for entry in cpuid.mut_entries_slice() { + cpuid_response.push(cpuid_kvm_to_proto(entry)); + } + Ok(()) + } + Err(e) => Err(e) + } + } else if request.has_get_emulated_cpuid() { + let cpuid_response = &mut response.mut_get_emulated_cpuid().entries; + match kvm.get_emulated_cpuid() { + Ok(mut cpuid) => { + for entry in cpuid.mut_entries_slice() { + cpuid_response.push(cpuid_kvm_to_proto(entry)); + } + Ok(()) + } + Err(e) => Err(e) + } } else { Err(SysError::new(-ENOTTY)) }; -- cgit 1.4.1