From: Oliver Upton <oupton@google.com>
To: kvm@vger.kernel.org
Cc: 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>,
Oliver Upton <oupton@google.com>
Subject: [PATCH 4/4] selftests: KVM: Add test case for "{load/clear} IA32_BNDCFGS" invariance
Date: Wed, 2 Feb 2022 23:04:33 +0000 [thread overview]
Message-ID: <20220202230433.2468479-5-oupton@google.com> (raw)
In-Reply-To: <20220202230433.2468479-1-oupton@google.com>
Assert that clearing the "{load/clear IA32_BNDCFGS" bits is preserved
across KVM_SET_CPUID2.
Signed-off-by: Oliver Upton <oupton@google.com>
---
.../selftests/kvm/include/x86_64/vmx.h | 2 +
.../kvm/x86_64/vmx_capability_msrs_test.c | 37 +++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/tools/testing/selftests/kvm/include/x86_64/vmx.h b/tools/testing/selftests/kvm/include/x86_64/vmx.h
index 583ceb0d1457..811c66d9be74 100644
--- a/tools/testing/selftests/kvm/include/x86_64/vmx.h
+++ b/tools/testing/selftests/kvm/include/x86_64/vmx.h
@@ -80,6 +80,7 @@
#define VM_EXIT_SAVE_IA32_EFER 0x00100000
#define VM_EXIT_LOAD_IA32_EFER 0x00200000
#define VM_EXIT_SAVE_VMX_PREEMPTION_TIMER 0x00400000
+#define VM_EXIT_CLEAR_BNDCFGS 0x00800000
#define VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR 0x00036dff
@@ -90,6 +91,7 @@
#define VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL 0x00002000
#define VM_ENTRY_LOAD_IA32_PAT 0x00004000
#define VM_ENTRY_LOAD_IA32_EFER 0x00008000
+#define VM_ENTRY_LOAD_BNDCFGS 0x00010000
#define VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR 0x000011ff
diff --git a/tools/testing/selftests/kvm/x86_64/vmx_capability_msrs_test.c b/tools/testing/selftests/kvm/x86_64/vmx_capability_msrs_test.c
index 8a1a545e658b..a0851b1224aa 100644
--- a/tools/testing/selftests/kvm/x86_64/vmx_capability_msrs_test.c
+++ b/tools/testing/selftests/kvm/x86_64/vmx_capability_msrs_test.c
@@ -67,6 +67,42 @@ static void load_perf_global_ctrl_test(struct kvm_vm *vm)
"\"load IA32_PERF_GLOBAL_CTRL\" VM-Exit bit set");
}
+/*
+ * Test to assert that clearing the "load IA32_BNDCFGS" and "clear IA32_BNDCFGS"
+ * control capability bits is preserved across a KVM_SET_CPUID2.
+ */
+static void bndcfgs_ctrl_test(struct kvm_vm *vm)
+{
+ uint32_t entry_low, entry_high, exit_low, exit_high;
+ struct kvm_cpuid2 *cpuid;
+
+ get_vmx_capability_msr(vm, MSR_IA32_VMX_TRUE_ENTRY_CTLS, &entry_low, &entry_high);
+ get_vmx_capability_msr(vm, MSR_IA32_VMX_TRUE_EXIT_CTLS, &exit_low, &exit_high);
+
+ if (!(entry_high & VM_ENTRY_LOAD_BNDCFGS) || !(exit_high & VM_EXIT_CLEAR_BNDCFGS)) {
+ print_skip("\"{load,clear} IA32_BNDCFGS\" controls not supported");
+ return;
+ }
+
+ entry_high &= ~VM_ENTRY_LOAD_BNDCFGS;
+ exit_high &= ~VM_EXIT_CLEAR_BNDCFGS;
+
+ set_vmx_capability_msr(vm, MSR_IA32_VMX_TRUE_ENTRY_CTLS, entry_low, entry_high);
+ set_vmx_capability_msr(vm, MSR_IA32_VMX_TRUE_EXIT_CTLS, exit_low, exit_high);
+
+ cpuid = kvm_get_supported_cpuid();
+ vcpu_set_cpuid(vm, VCPU_ID, cpuid);
+
+ get_vmx_capability_msr(vm, MSR_IA32_VMX_TRUE_ENTRY_CTLS, &entry_low, &entry_high);
+ get_vmx_capability_msr(vm, MSR_IA32_VMX_TRUE_EXIT_CTLS, &exit_low, &exit_high);
+
+ TEST_ASSERT(!(entry_high & VM_ENTRY_LOAD_BNDCFGS),
+ "\"load IA32_BNDCFGS\" VM-Entry bit set");
+ TEST_ASSERT(!(exit_high & VM_EXIT_CLEAR_BNDCFGS),
+ "\"clear IA32_BNDCFGS\" VM-Exit bit set");
+}
+
+
int main(void)
{
struct kvm_vm *vm;
@@ -77,6 +113,7 @@ int main(void)
vm = vm_create_default(VCPU_ID, 0, NULL);
load_perf_global_ctrl_test(vm);
+ bndcfgs_ctrl_test(vm);
kvm_vm_free(vm);
}
--
2.35.0.rc2.247.g8bbb082509-goog
next prev parent reply other threads:[~2022-02-02 23:04 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-02 23:04 [PATCH 0/4] KVM: nVMX: Fixes for VMX capability MSR invariance Oliver Upton
2022-02-02 23:04 ` [PATCH 1/4] KVM: nVMX: Don't change VM-{Entry,Exit} ctrl MSRs on PMU CPUID update Oliver Upton
2022-02-02 23:04 ` [PATCH 2/4] KVM: nVMX: Don't change VM-{Entry,Exit} ctrl MSRs on MPX " Oliver Upton
2022-02-02 23:04 ` [PATCH 3/4] selftests: KVM: Add test for "load IA32_PERF_GLOBAL_CTRL" invariance Oliver Upton
2022-02-02 23:04 ` Oliver Upton [this message]
2022-02-03 0:04 ` [PATCH 0/4] KVM: nVMX: Fixes for VMX capability MSR invariance Jim Mattson
2022-02-03 0:33 ` Sean Christopherson
2022-02-03 0:38 ` Jim Mattson
2022-02-03 0:44 ` Oliver Upton
2022-02-03 0:48 ` Sean Christopherson
2022-02-03 0:42 ` Oliver Upton
2022-02-03 0:55 ` Sean Christopherson
2022-02-03 1:05 ` Oliver Upton
2022-02-03 1:08 ` Jim Mattson
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=20220202230433.2468479-5-oupton@google.com \
--to=oupton@google.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
/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