summary refs log tree commit diff
path: root/kvm/src
diff options
context:
space:
mode:
authorSonny Rao <sonnyrao@chromium.org>2018-02-26 17:27:40 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-04-03 12:50:37 -0700
commit2ffa0cbe5bb41beea81fd2d14a7f781747bb955e (patch)
tree928cfcc64f50576b9a70d02ea11a4b11991f8498 /kvm/src
parent5d586b73a4c78f4118b97e65a229cbb7e99bf963 (diff)
downloadcrosvm-2ffa0cbe5bb41beea81fd2d14a7f781747bb955e.tar
crosvm-2ffa0cbe5bb41beea81fd2d14a7f781747bb955e.tar.gz
crosvm-2ffa0cbe5bb41beea81fd2d14a7f781747bb955e.tar.bz2
crosvm-2ffa0cbe5bb41beea81fd2d14a7f781747bb955e.tar.lz
crosvm-2ffa0cbe5bb41beea81fd2d14a7f781747bb955e.tar.xz
crosvm-2ffa0cbe5bb41beea81fd2d14a7f781747bb955e.tar.zst
crosvm-2ffa0cbe5bb41beea81fd2d14a7f781747bb955e.zip
crosvm: aarch64 guest support
- removes old ARMv7a (32-bit) bindings as we're only supporting aarch64
  guests right now
- switches both ARMv7 and aarch64 builds to use aarch64 kvm bindings
- adds support for ARMv8 Linux guest with dynamic flattened-device-tree

CQ-DEPEND=990894
BUG=chromium:797868
TEST=./build_test passes on all architectures
TEST=crosvm runs on caroline
TEST=crosvm runs on kevin built with USE="kvm_host"

Change-Id: I7fc4fc4017ed87fd23a1bc50e3ebb05377040006
Reviewed-on: https://chromium-review.googlesource.com/969987
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'kvm/src')
-rw-r--r--kvm/src/lib.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/kvm/src/lib.rs b/kvm/src/lib.rs
index 2bf2677..a76c018 100644
--- a/kvm/src/lib.rs
+++ b/kvm/src/lib.rs
@@ -708,6 +708,16 @@ impl Vm {
             errno_result()
         }
     }
+
+    /// Does KVM_CREATE_DEVICE for a generic device.
+    pub fn create_device(&self, device: &mut kvm_create_device) -> Result<()> {
+        let ret = unsafe { sys_util::ioctl_with_ref(self, KVM_CREATE_DEVICE(), device) };
+        if ret == 0 {
+            Ok(())
+        } else {
+            errno_result()
+        }
+    }
 }
 
 impl AsRawFd for Vm {
@@ -1157,6 +1167,35 @@ impl Vcpu {
         }
         Ok(())
     }
+
+    /// Sets the value of one register on this VCPU.  The id of the register is
+    /// encoded as specified in the kernel documentation for KVM_SET_ONE_REG.
+    #[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
+    pub fn set_one_reg(&self, reg_id: u64, data: u64) -> Result<()> {
+        let data_ref = &data as *const u64;
+        let onereg = kvm_one_reg { id: reg_id,
+                                   addr: data_ref as u64};
+        // safe becuase we allocated the struct and we know the kernel will read
+        // exactly the size of the struct
+        let ret = unsafe { ioctl_with_ref(self, KVM_SET_ONE_REG(), &onereg) };
+        if ret < 0 {
+            return errno_result();
+        }
+        Ok(())
+    }
+
+    /// This initializes an ARM VCPU to the specified type with the specified features
+    /// and resets the values of all of its registers to defaults.
+    #[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
+    pub fn arm_vcpu_init(&self, kvi: &kvm_vcpu_init) -> Result<()> {
+        // safe becuase we allocated the struct and we know the kernel will read
+        // exactly the size of the struct
+        let ret = unsafe { ioctl_with_ref(self, KVM_ARM_VCPU_INIT(), kvi) };
+        if ret < 0 {
+            return errno_result();
+        }
+        Ok(())
+    }
 }
 
 impl AsRawFd for Vcpu {