diff options
author | Matt Delco <delco@chromium.org> | 2020-02-13 14:08:04 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-02-20 02:12:03 +0000 |
commit | e73414db487afd4bebd2fb60ca80693ee6349cf5 (patch) | |
tree | adf53724c2db3f7c21e7d85ba9df6b6354ca327a /tests | |
parent | c469580e6c9b83172ba58e8305c6e5c11acfe186 (diff) | |
download | crosvm-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 'tests')
-rw-r--r-- | tests/plugin_enable_cap.c | 65 | ||||
-rw-r--r-- | tests/plugins.rs | 5 |
2 files changed, 70 insertions, 0 deletions
diff --git a/tests/plugin_enable_cap.c b/tests/plugin_enable_cap.c new file mode 100644 index 0000000..60977ef --- /dev/null +++ b/tests/plugin_enable_cap.c @@ -0,0 +1,65 @@ +/* + * 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. + */ + +#include <errno.h> +#include <linux/kvm.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "crosvm.h" + +int main(int argc, char** argv) { + struct crosvm* crosvm = NULL; + uint64_t cap_args[4] = {0}; + + int ret = crosvm_connect(&crosvm); + if (ret) { + fprintf(stderr, "failed to connect to crosvm: %d\n", ret); + return 1; + } + + struct crosvm_vcpu* vcpu = NULL; + ret = crosvm_get_vcpu(crosvm, 0, &vcpu); + if (ret) { + fprintf(stderr, "failed to get vcpu #0: %d\n", ret); + return 1; + } + + ret = crosvm_start(crosvm); + if (ret) { + fprintf(stderr, "failed to start vm: %d\n", ret); + return 1; + } + + struct crosvm_vcpu_event evt = {0}; + ret = crosvm_vcpu_wait(vcpu, &evt); + if (ret) { + fprintf(stderr, "failed to wait for vm start: %d\n", ret); + return 1; + } + if (evt.kind != CROSVM_VCPU_EVENT_KIND_INIT) { + fprintf(stderr, "Got unexpected exit type: %d\n", evt.kind); + return 1; + } + + ret = crosvm_enable_capability(crosvm, 0, 0, cap_args); + if (ret != -EINVAL) { + fprintf(stderr, "Unexpected crosvm_enable_capability result: %d\n", + ret); + return 1; + } + + ret = crosvm_vcpu_enable_capability(vcpu, KVM_CAP_HYPERV_SYNIC, 0, + cap_args); + if (ret) { + fprintf(stderr, "crosvm_vcpu_enable_capability() failed: %d\n", ret); + return 1; + } + + return 0; +} diff --git a/tests/plugins.rs b/tests/plugins.rs index d56f4ce..c45096f 100644 --- a/tests/plugins.rs +++ b/tests/plugins.rs @@ -261,6 +261,11 @@ fn test_supported_cpuid() { } #[test] +fn test_enable_cap() { + test_plugin(include_str!("plugin_enable_cap.c")); +} + +#[test] fn test_msr_index_list() { test_plugin(include_str!("plugin_msr_index_list.c")); } |