summary refs log tree commit diff
path: root/kvm
diff options
context:
space:
mode:
authorUdam Saini <udam@google.com>2020-05-02 10:01:38 -0700
committerCommit Bot <commit-bot@chromium.org>2020-05-15 16:57:22 +0000
commit3730355406ed5fcc6505a35d55c683567159dd82 (patch)
tree6d7d16e9f588c682ce65e0b57f09db0e4c14edda /kvm
parentc569a579fe674773807b888f2eb65b23405c53b9 (diff)
downloadcrosvm-3730355406ed5fcc6505a35d55c683567159dd82.tar
crosvm-3730355406ed5fcc6505a35d55c683567159dd82.tar.gz
crosvm-3730355406ed5fcc6505a35d55c683567159dd82.tar.bz2
crosvm-3730355406ed5fcc6505a35d55c683567159dd82.tar.lz
crosvm-3730355406ed5fcc6505a35d55c683567159dd82.tar.xz
crosvm-3730355406ed5fcc6505a35d55c683567159dd82.tar.zst
crosvm-3730355406ed5fcc6505a35d55c683567159dd82.zip
Implements the Hypervisor trait for Kvm.
This adds the ability for getting both supported/emulated cpuids from
the kvm hypervisor. In addition, checking the available capabilities
for kvm is now implemented.

BUG=chromium:1077058
TEST=Added unit tests for each implemented function.

Change-Id: Ide4c2840b7bfa022deae835eb734ea97c1859169
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2177641
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Udam Saini <udam@google.com>
Diffstat (limited to 'kvm')
-rw-r--r--kvm/src/lib.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/kvm/src/lib.rs b/kvm/src/lib.rs
index 8b98b7c..1b06b39 100644
--- a/kvm/src/lib.rs
+++ b/kvm/src/lib.rs
@@ -2045,6 +2045,18 @@ impl CpuId {
         unsafe { self.kvm_cpuid[0].entries.as_mut_slice(nent) }
     }
 
+    /// Get the entries slice, for inspecting. To modify, use mut_entries_slice instead.
+    pub fn entries_slice(&self) -> &[kvm_cpuid_entry2] {
+        // Mapping the unsized array to a slice is unsafe because the length isn't known.  Using
+        // the length we originally allocated with eliminates the possibility of overflow.
+        let slice_size = if self.kvm_cpuid[0].nent as usize > self.allocated_len {
+            self.allocated_len
+        } else {
+            self.kvm_cpuid[0].nent as usize
+        };
+        unsafe { self.kvm_cpuid[0].entries.as_slice(slice_size) }
+    }
+
     /// Get a  pointer so it can be passed to the kernel.  Using this pointer is unsafe.
     pub fn as_ptr(&self) -> *const kvm_cpuid2 {
         &self.kvm_cpuid[0]