diff options
author | Steven Richman <srichman@google.com> | 2020-05-01 17:30:24 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-05-09 06:23:33 +0000 |
commit | e1f8d9187d3f16e31d0c1304030ad412cf43b2bf (patch) | |
tree | 45b8606c4d9fb31a4d4d335d8e0ea3bb31a6d9c2 /hypervisor/src/x86_64.rs | |
parent | a7469062a2b25541cfe887f55441284553659ea0 (diff) | |
download | crosvm-e1f8d9187d3f16e31d0c1304030ad412cf43b2bf.tar crosvm-e1f8d9187d3f16e31d0c1304030ad412cf43b2bf.tar.gz crosvm-e1f8d9187d3f16e31d0c1304030ad412cf43b2bf.tar.bz2 crosvm-e1f8d9187d3f16e31d0c1304030ad412cf43b2bf.tar.lz crosvm-e1f8d9187d3f16e31d0c1304030ad412cf43b2bf.tar.xz crosvm-e1f8d9187d3f16e31d0c1304030ad412cf43b2bf.tar.zst crosvm-e1f8d9187d3f16e31d0c1304030ad412cf43b2bf.zip |
hypervisor: add Vm/Vcpu traits and Kvm impls
Add arch-agnostic traits Vm and Vcpu. Add arch-specific traits HypervisorXXX, VmXXX, VcpuXXX, with impls for KVM. BUG=chromium:1077058 TEST=added test for functions and structs interacting with the traits Change-Id: I809f42f32a558c7835831c90e24fca82ce7744ab Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2176562 Reviewed-by: Udam Saini <udam@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Steven Richman <srichman@google.com>
Diffstat (limited to 'hypervisor/src/x86_64.rs')
-rw-r--r-- | hypervisor/src/x86_64.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/hypervisor/src/x86_64.rs b/hypervisor/src/x86_64.rs new file mode 100644 index 0000000..e05335c --- /dev/null +++ b/hypervisor/src/x86_64.rs @@ -0,0 +1,40 @@ +// Copyright 2020 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +use kvm_sys::kvm_cpuid_entry2; +use sys_util::Result; + +use crate::{Hypervisor, Vcpu, Vm}; + +pub type CpuIdEntry = kvm_cpuid_entry2; + +/// A trait for managing cpuids for an x86_64 hypervisor and for checking its capabilities. +pub trait HypervisorX86_64: Hypervisor { + /// Get the system supported CPUID values. + fn get_supported_cpuid(&self) -> Result<CpuId>; + + /// Get the system emulated CPUID values. + fn get_emulated_cpuid(&self) -> Result<CpuId>; +} + +/// A wrapper for using a VM on x86_64 and getting/setting its state. +pub trait VmX86_64: Vm { + type Vcpu: VcpuX86_64; + + /// Create a Vcpu with the specified Vcpu ID. + fn create_vcpu(&self, id: usize) -> Result<Self::Vcpu>; +} + +/// A wrapper around creating and using a VCPU on x86_64. +pub trait VcpuX86_64: Vcpu { + /// Gets the VCPU registers. + fn get_regs(&self) -> Result<Regs>; +} + +pub struct CpuId { + _cpu_id_entries: Vec<CpuIdEntry>, +} + +/// The state of a vcpu's general-purpose registers. +pub struct Regs {} |