summary refs log tree commit diff
path: root/crosvm_plugin
diff options
context:
space:
mode:
authorMatt Delco <delco@chromium.org>2020-02-13 14:08:04 -0800
committerCommit Bot <commit-bot@chromium.org>2020-02-20 02:12:03 +0000
commite73414db487afd4bebd2fb60ca80693ee6349cf5 (patch)
treeadf53724c2db3f7c21e7d85ba9df6b6354ca327a /crosvm_plugin
parentc469580e6c9b83172ba58e8305c6e5c11acfe186 (diff)
downloadcrosvm-e73414db487afd4bebd2fb60ca80693ee6349cf5.tar
crosvm-e73414db487afd4bebd2fb60ca80693ee6349cf5.tar.gz
crosvm-e73414db487afd4bebd2fb60ca80693ee6349cf5.tar.bz2
crosvm-e73414db487afd4bebd2fb60ca80693ee6349cf5.tar.lz
crosvm-e73414db487afd4bebd2fb60ca80693ee6349cf5.tar.xz
crosvm-e73414db487afd4bebd2fb60ca80693ee6349cf5.tar.zst
crosvm-e73414db487afd4bebd2fb60ca80693ee6349cf5.zip
crosvm: add ability to enable caps on vcpu
This change primarily adds functionality to allow kvm features to be
enabled on a vcpu (most of the current infra only supporst the ioctl for
the vm fd).

BUG=b:144746965
TEST=ran 'build_test' and verified that the added tests passed.

Change-Id: I30c00b6f462377c21d477602ceba5853df953b37
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2055883
Tested-by: Matt Delco <delco@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Matt Delco <delco@chromium.org>
Diffstat (limited to 'crosvm_plugin')
-rw-r--r--crosvm_plugin/crosvm.h19
-rw-r--r--crosvm_plugin/src/lib.rs39
2 files changed, 57 insertions, 1 deletions
diff --git a/crosvm_plugin/crosvm.h b/crosvm_plugin/crosvm.h
index ef7759d..db824b9 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 20
+#define CROSVM_API_MINOR 21
 #define CROSVM_API_PATCH 0
 
 enum crosvm_address_space {
@@ -115,6 +115,14 @@ int crosvm_check_extension(struct crosvm*, uint32_t __extension,
                            bool *has_extension);
 
 /*
+ * Enable an extended capability for the VM.  Currently |__flags| and
+ * |__args| must be zero.  No values for |__capability| are supported,
+ * so all calls will fail.
+ */
+int crosvm_enable_capability(struct crosvm*, uint32_t __capability,
+                             uint32_t __flags, uint64_t __args[4]);
+
+/*
  * Queries x86 cpuid features which are supported by the hardware and
  * kvm.
  */
@@ -633,6 +641,15 @@ int crosvm_vcpu_set_msrs(struct crosvm_vcpu*, uint32_t __msr_count,
 int crosvm_vcpu_set_cpuid(struct crosvm_vcpu*, uint32_t __cpuid_count,
                           const struct kvm_cpuid_entry2 *__cpuid_entries);
 
+/*
+ * Enable an extended capability for a vcpu.  Currently |__flags| and
+ * |__args| must be zero.  The only permitted values for |__capability|
+ * are KVM_CAP_HYPERV_SYNIC or KVM_CAP_HYPERV_SYNIC2, though the latter
+ * also depends on kernel support.
+ */
+int crosvm_vcpu_enable_capability(struct crosvm_vcpu*, uint32_t __capability,
+                                  uint32_t __flags, uint64_t __args[4]);
+
 /* Gets state of LAPIC of the VCPU. */
 int crosvm_vcpu_get_lapic_state(struct crosvm_vcpu *,
                                 struct kvm_lapic_state *__lapic_state);
diff --git a/crosvm_plugin/src/lib.rs b/crosvm_plugin/src/lib.rs
index 13b3d9f..8695d41 100644
--- a/crosvm_plugin/src/lib.rs
+++ b/crosvm_plugin/src/lib.rs
@@ -166,6 +166,8 @@ pub enum Stat {
     DestroyConnection,
     GetShutdownEventFd,
     CheckExtentsion,
+    EnableVmCapability,
+    EnableVcpuCapability,
     GetSupportedCpuid,
     GetEmulatedCpuid,
     GetHypervCpuid,
@@ -1289,6 +1291,13 @@ impl crosvm_vcpu {
         self.vcpu_transaction(&r)?;
         Ok(())
     }
+
+    fn enable_capability(&mut self, capability: u32) -> result::Result<(), c_int> {
+        let mut r = VcpuRequest::new();
+        r.mut_enable_capability().capability = capability;
+        self.vcpu_transaction(&r)?;
+        Ok(())
+    }
 }
 
 // crosvm API signals success as 0 and errors as negative values
@@ -1371,6 +1380,17 @@ pub unsafe extern "C" fn crosvm_check_extension(
 }
 
 #[no_mangle]
+pub unsafe extern "C" fn crosvm_enable_capability(
+    _self_: *mut crosvm,
+    _capability: u32,
+    _flags: u32,
+    _args: *const u64,
+) -> c_int {
+    let _u = record(Stat::EnableVmCapability);
+    -EINVAL
+}
+
+#[no_mangle]
 pub unsafe extern "C" fn crosvm_get_supported_cpuid(
     this: *mut crosvm,
     entry_count: u32,
@@ -1896,6 +1916,25 @@ pub unsafe extern "C" fn crosvm_vcpu_set_cpuid(
 }
 
 #[no_mangle]
+pub unsafe extern "C" fn crosvm_vcpu_enable_capability(
+    this: *mut crosvm_vcpu,
+    capability: u32,
+    flags: u32,
+    args: *const u64,
+) -> c_int {
+    let _u = record(Stat::EnableVcpuCapability);
+    let this = &mut *this;
+    let args = slice::from_raw_parts(args, 4);
+
+    if flags != 0 || args.iter().any(|v| *v != 0) {
+        return -EINVAL;
+    }
+
+    let ret = this.enable_capability(capability);
+    to_crosvm_rc(ret)
+}
+
+#[no_mangle]
 pub unsafe extern "C" fn crosvm_vcpu_get_lapic_state(
     this: *mut crosvm_vcpu,
     state: *mut kvm_lapic_state,