From: Zeng Guang <guang.zeng@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
kvm@vger.kernel.org, Dave Hansen <dave.hansen@linux.intel.com>,
Tony Luck <tony.luck@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
"H. Peter Anvin" <hpa@zytor.com>,
Kim Phillips <kim.phillips@amd.com>,
Jarkko Sakkinen <jarkko@kernel.org>,
Jethro Beekman <jethro@fortanix.com>,
Kai Huang <kai.huang@intel.com>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
Robert Hu <robert.hu@intel.com>, Gao Chao <chao.gao@intel.com>,
Zeng Guang <guang.zeng@intel.com>
Subject: [PATCH v2] kvm: selftests: Add KVM_CAP_MAX_VCPU_ID cap test
Date: Tue, 3 May 2022 14:40:37 +0800 [thread overview]
Message-ID: <20220503064037.10822-1-guang.zeng@intel.com> (raw)
Basic test coverage of KVM_CAP_MAX_VCPU_ID cap.
This capability can be enabled before vCPU creation and only allowed
to set once. if assigned vcpu id is beyond KVM_CAP_MAX_VCPU_ID
capability, vCPU creation will fail.
Signed-off-by: Zeng Guang <guang.zeng@intel.com>
---
tools/testing/selftests/kvm/.gitignore | 1 +
tools/testing/selftests/kvm/Makefile | 1 +
.../kvm/x86_64/max_vcpuid_cap_test.c | 59 +++++++++++++++++++
3 files changed, 61 insertions(+)
create mode 100644 tools/testing/selftests/kvm/x86_64/max_vcpuid_cap_test.c
diff --git a/tools/testing/selftests/kvm/.gitignore b/tools/testing/selftests/kvm/.gitignore
index d1e8f5237469..b860dcfee920 100644
--- a/tools/testing/selftests/kvm/.gitignore
+++ b/tools/testing/selftests/kvm/.gitignore
@@ -22,6 +22,7 @@
/x86_64/hyperv_cpuid
/x86_64/hyperv_features
/x86_64/hyperv_svm_test
+/x86_64/max_vcpuid_cap_test
/x86_64/mmio_warning_test
/x86_64/mmu_role_test
/x86_64/platform_info_test
diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index 21c2dbd21a81..e92dc78de4d0 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -86,6 +86,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/xen_shinfo_test
TEST_GEN_PROGS_x86_64 += x86_64/xen_vmcall_test
TEST_GEN_PROGS_x86_64 += x86_64/sev_migrate_tests
TEST_GEN_PROGS_x86_64 += x86_64/amx_test
+TEST_GEN_PROGS_x86_64 += x86_64/max_vcpuid_cap_test
TEST_GEN_PROGS_x86_64 += access_tracking_perf_test
TEST_GEN_PROGS_x86_64 += demand_paging_test
TEST_GEN_PROGS_x86_64 += dirty_log_test
diff --git a/tools/testing/selftests/kvm/x86_64/max_vcpuid_cap_test.c b/tools/testing/selftests/kvm/x86_64/max_vcpuid_cap_test.c
new file mode 100644
index 000000000000..2e3d1d236ef0
--- /dev/null
+++ b/tools/testing/selftests/kvm/x86_64/max_vcpuid_cap_test.c
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * maximum APIC ID capability tests
+ *
+ * Copyright (C) 2022, Intel, Inc.
+ *
+ * Tests for getting/setting maximum APIC ID capability
+ */
+
+#include "kvm_util.h"
+#include "../lib/kvm_util_internal.h"
+
+#define MAX_VCPU_ID 2
+
+int main(int argc, char *argv[])
+{
+ struct kvm_vm *vm;
+ struct kvm_enable_cap cap = { 0 };
+ int ret;
+
+ vm = vm_create(VM_MODE_DEFAULT, 0, O_RDWR);
+
+ /* Get KVM_CAP_MAX_VCPU_ID cap supported in KVM */
+ ret = vm_check_cap(vm, KVM_CAP_MAX_VCPU_ID);
+
+ /* Check failure if set KVM_CAP_MAX_VCPU_ID beyond KVM cap */
+ cap.cap = KVM_CAP_MAX_VCPU_ID;
+ cap.args[0] = ret + 1;
+ ret = ioctl(vm->fd, KVM_ENABLE_CAP, &cap);
+ TEST_ASSERT(ret < 0,
+ "Unexpected success to enable KVM_CAP_MAX_VCPU_ID"
+ "beyond KVM cap!\n");
+
+ /* Check success if set KVM_CAP_MAX_VCPU_ID */
+ cap.args[0] = MAX_VCPU_ID;
+ ret = ioctl(vm->fd, KVM_ENABLE_CAP, &cap);
+ TEST_ASSERT(ret == 0,
+ "Unexpected failure to enable KVM_CAP_MAX_VCPU_ID!\n");
+
+ /* Check success if set KVM_CAP_MAX_VCPU_ID same value */
+ ret = ioctl(vm->fd, KVM_ENABLE_CAP, &cap);
+ TEST_ASSERT(ret == 0,
+ "Unexpected failure to set KVM_CAP_MAX_VCPU_ID same value\n");
+
+ /* Check failure if set KVM_CAP_MAX_VCPU_ID different value again */
+ cap.args[0] = MAX_VCPU_ID + 1;
+ ret = ioctl(vm->fd, KVM_ENABLE_CAP, &cap);
+ TEST_ASSERT(ret < 0,
+ "Unexpected success to enable KVM_CAP_MAX_VCPU_ID with"
+ "different value again\n");
+
+ /* Check failure if create vCPU with id beyond KVM_CAP_MAX_VCPU_ID cap*/
+ ret = ioctl(vm->fd, KVM_CREATE_VCPU, MAX_VCPU_ID);
+ TEST_ASSERT(ret < 0,
+ "Unexpected success in creating a vCPU with VCPU ID out of range\n");
+
+ kvm_vm_free(vm);
+ return 0;
+}
--
2.27.0
next reply other threads:[~2022-05-03 7:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-03 6:40 Zeng Guang [this message]
2022-05-13 1:03 ` [PATCH v2] kvm: selftests: Add KVM_CAP_MAX_VCPU_ID cap test Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220503064037.10822-1-guang.zeng@intel.com \
--to=guang.zeng@intel.com \
--cc=bp@alien8.de \
--cc=chao.gao@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jarkko@kernel.org \
--cc=jethro@fortanix.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kai.huang@intel.com \
--cc=kan.liang@linux.intel.com \
--cc=kim.phillips@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=robert.hu@intel.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox