From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: 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, linux-kernel@vger.kernel.org,
Eric Li <ercli@ucdavis.edu>, David Matlack <dmatlack@google.com>,
Oliver Upton <oupton@google.com>
Subject: [PATCH v5 14/15] KVM: selftests: Extend VMX MSRs test to cover CR4_FIXED1 (and its quirks)
Date: Tue, 7 Jun 2022 21:36:03 +0000 [thread overview]
Message-ID: <20220607213604.3346000-15-seanjc@google.com> (raw)
In-Reply-To: <20220607213604.3346000-1-seanjc@google.com>
Extend the VMX MSRs test to verify that KVM adheres to its established
quirky ABI for CR4_FIXED1 when VMX MSRS quirk is enabled, and that KV
doesn't touch CR4_FIXED1 when the quirk is disabled.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
.../selftests/kvm/include/x86_64/processor.h | 7 ++
.../selftests/kvm/x86_64/vmx_msrs_test.c | 65 +++++++++++++++++++
2 files changed, 72 insertions(+)
diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h
index 51cab9b080f7..716e72bc9163 100644
--- a/tools/testing/selftests/kvm/include/x86_64/processor.h
+++ b/tools/testing/selftests/kvm/include/x86_64/processor.h
@@ -87,9 +87,16 @@ struct kvm_x86_cpu_feature {
#define X86_FEATURE_XSAVE KVM_X86_CPU_FEATURE(0x1, 0, ECX, 26)
#define X86_FEATURE_OSXSAVE KVM_X86_CPU_FEATURE(0x1, 0, ECX, 27)
#define X86_FEATURE_RDRAND KVM_X86_CPU_FEATURE(0x1, 0, ECX, 30)
+#define X86_FEATURE_VME KVM_X86_CPU_FEATURE(0x1, 0, EDX, 1)
+#define X86_FEATURE_DE KVM_X86_CPU_FEATURE(0x1, 0, EDX, 2)
+#define X86_FEATURE_PSE KVM_X86_CPU_FEATURE(0x1, 0, EDX, 3)
+#define X86_FEATURE_TSC KVM_X86_CPU_FEATURE(0x1, 0, EDX, 4)
+#define X86_FEATURE_PAE KVM_X86_CPU_FEATURE(0x1, 0, EDX, 6)
#define X86_FEATURE_MCE KVM_X86_CPU_FEATURE(0x1, 0, EDX, 7)
#define X86_FEATURE_APIC KVM_X86_CPU_FEATURE(0x1, 0, EDX, 9)
+#define X86_FEATURE_PGE KVM_X86_CPU_FEATURE(0x1, 0, EDX, 13)
#define X86_FEATURE_CLFLUSH KVM_X86_CPU_FEATURE(0x1, 0, EDX, 19)
+#define X86_FEATURE_FXSR KVM_X86_CPU_FEATURE(0x1, 0, EDX, 24)
#define X86_FEATURE_XMM KVM_X86_CPU_FEATURE(0x1, 0, EDX, 25)
#define X86_FEATURE_XMM2 KVM_X86_CPU_FEATURE(0x1, 0, EDX, 26)
#define X86_FEATURE_FSGSBASE KVM_X86_CPU_FEATURE(0x7, 0, EBX, 0)
diff --git a/tools/testing/selftests/kvm/x86_64/vmx_msrs_test.c b/tools/testing/selftests/kvm/x86_64/vmx_msrs_test.c
index 9be2c2e3acf1..c0c4252a6a03 100644
--- a/tools/testing/selftests/kvm/x86_64/vmx_msrs_test.c
+++ b/tools/testing/selftests/kvm/x86_64/vmx_msrs_test.c
@@ -143,6 +143,70 @@ static void load_and_clear_bndcfgs_test(struct kvm_vm *vm, struct kvm_vcpu *vcpu
test_vmx_ctrls(vm, vcpu, VM_ENTRY_LOAD_BNDCFGS, VM_EXIT_CLEAR_BNDCFGS);
}
+static void cr4_reserved_bit_test(struct kvm_vm *vm, struct kvm_vcpu *vcpu,
+ uint64_t cr4_bit,
+ struct kvm_x86_cpu_feature feature)
+{
+ uint64_t val;
+ int r;
+
+ if (!kvm_cpu_has(feature))
+ return;
+
+ vcpu_set_cpuid_feature(vcpu, feature);
+ val = vcpu_get_msr(vcpu, MSR_IA32_VMX_CR4_FIXED1);
+ TEST_ASSERT(val & cr4_bit,
+ "KVM should set CR4 bit when quirk and feature are enabled");
+
+ vcpu_clear_cpuid_feature(vcpu, feature);
+ val = vcpu_get_msr(vcpu, MSR_IA32_VMX_CR4_FIXED1);
+ TEST_ASSERT(!(val & cr4_bit),
+ "KVM should clear CR4 bit when quirk and feature are enabled");
+
+ r = _vcpu_set_msr(vcpu, MSR_IA32_VMX_CR4_FIXED1, val);
+ TEST_ASSERT(r == 0, "Writing CR4_FIXED1 should fail when quirk is enabled");
+
+ vm_enable_cap(vm, KVM_CAP_DISABLE_QUIRKS2, KVM_X86_QUIRK_TWEAK_VMX_MSRS);
+
+ val &= ~cr4_bit;
+ vcpu_set_msr(vcpu, MSR_IA32_VMX_CR4_FIXED1, val);
+
+ vcpu_set_cpuid_feature(vcpu, feature);
+ TEST_ASSERT(!(val & cr4_bit),
+ "KVM shouldn't set CR4 bit when quirk is disabled");
+
+ val |= cr4_bit;
+ vcpu_clear_cpuid_feature(vcpu, feature);
+ TEST_ASSERT(val & cr4_bit,
+ "KVM shouldn't clear CR4 bit when quirk is disabled");
+
+ vm_enable_cap(vm, KVM_CAP_DISABLE_QUIRKS2, 0);
+}
+
+static void cr4_reserved_bits_test(struct kvm_vm *vm, struct kvm_vcpu *vcpu)
+{
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_VME, X86_FEATURE_VME);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_PVI, X86_FEATURE_VME);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_TSD, X86_FEATURE_TSC);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_DE, X86_FEATURE_DE);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_PSE, X86_FEATURE_PSE);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_PAE, X86_FEATURE_PAE);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_MCE, X86_FEATURE_MCE);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_PGE, X86_FEATURE_PGE);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_OSFXSR, X86_FEATURE_FXSR);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_OSXMMEXCPT, X86_FEATURE_XMM);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_VMXE, X86_FEATURE_VMX);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_SMXE, X86_FEATURE_SMX);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_PCIDE, X86_FEATURE_PCID);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_OSXSAVE, X86_FEATURE_XSAVE);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_FSGSBASE, X86_FEATURE_FSGSBASE);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_SMEP, X86_FEATURE_SMEP);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_SMAP, X86_FEATURE_SMAP);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_PKE, X86_FEATURE_PKU);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_UMIP, X86_FEATURE_UMIP);
+ cr4_reserved_bit_test(vm, vcpu, X86_CR4_LA57, X86_FEATURE_LA57);
+}
+
int main(void)
{
struct kvm_vcpu *vcpu;
@@ -156,6 +220,7 @@ int main(void)
load_perf_global_ctrl_test(vm, vcpu);
load_and_clear_bndcfgs_test(vm, vcpu);
+ cr4_reserved_bits_test(vm, vcpu);
kvm_vm_free(vm);
}
--
2.36.1.255.ge46751e96f-goog
next prev parent reply other threads:[~2022-06-08 1:54 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-07 21:35 [PATCH v5 00/15] KVM: nVMX: VMX MSR quirk+fixes, CR4 fixes Sean Christopherson
2022-06-07 21:35 ` [PATCH v5 01/15] KVM: x86: Split kvm_is_valid_cr4() and export only the non-vendor bits Sean Christopherson
2022-06-07 21:35 ` [PATCH v5 02/15] KVM: nVMX: Account for KVM reserved CR4 bits in consistency checks Sean Christopherson
2022-06-07 21:35 ` [PATCH v5 03/15] KVM: nVMX: Inject #UD if VMXON is attempted with incompatible CR0/CR4 Sean Christopherson
2022-06-07 21:35 ` [PATCH v5 04/15] KVM: nVMX: Rename handle_vm{on,off}() to handle_vmx{on,off}() Sean Christopherson
2022-06-07 21:35 ` [PATCH v5 05/15] KVM: nVMX: Let userspace set nVMX MSR to any _host_ supported value Sean Christopherson
2022-10-31 16:39 ` Yu Zhang
2022-10-31 17:11 ` Sean Christopherson
2022-11-01 10:18 ` Yu Zhang
2022-11-01 17:58 ` Sean Christopherson
2022-11-02 8:54 ` Yu Zhang
2022-11-03 16:53 ` Sean Christopherson
2022-11-07 8:28 ` Yu Zhang
2022-11-07 15:06 ` Sean Christopherson
2022-11-08 10:21 ` Yu Zhang
2022-11-08 18:35 ` Sean Christopherson
2022-11-10 8:44 ` Yu Zhang
2022-11-10 16:08 ` Sean Christopherson
2022-06-07 21:35 ` [PATCH v5 06/15] KVM: nVMX: Keep KVM updates to BNDCFGS ctrl bits across MSR write Sean Christopherson
2022-07-22 9:06 ` Paolo Bonzini
2022-06-07 21:35 ` [PATCH v5 07/15] KVM: VMX: Add helper to check if the guest PMU has PERF_GLOBAL_CTRL Sean Christopherson
2022-06-07 21:35 ` [PATCH v5 08/15] KVM: nVMX: Keep KVM updates to PERF_GLOBAL_CTRL ctrl bits across MSR write Sean Christopherson
2022-06-07 21:35 ` [PATCH v5 09/15] KVM: nVMX: Drop nested_vmx_pmu_refresh() Sean Christopherson
2022-06-07 21:35 ` [PATCH v5 10/15] KVM: nVMX: Add a quirk for KVM tweaks to VMX MSRs Sean Christopherson
2022-06-07 21:36 ` [PATCH v5 11/15] KVM: nVMX: Set UMIP bit CR4_FIXED1 MSR when emulating UMIP Sean Christopherson
2022-07-22 9:49 ` Paolo Bonzini
2022-06-07 21:36 ` [PATCH v5 12/15] KVM: nVMX: Extend VMX MSRs quirk to CR0/4 fixed1 bits Sean Christopherson
2022-07-22 9:50 ` Paolo Bonzini
2022-06-07 21:36 ` [PATCH v5 13/15] KVM: selftests: Add test to verify KVM's VMX MSRs quirk for controls Sean Christopherson
2022-06-07 21:36 ` Sean Christopherson [this message]
2022-06-07 21:36 ` [PATCH v5 15/15] KVM: selftests: Verify VMX MSRs can be restored to KVM-supported values 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=20220607213604.3346000-15-seanjc@google.com \
--to=seanjc@google.com \
--cc=dmatlack@google.com \
--cc=ercli@ucdavis.edu \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oupton@google.com \
--cc=pbonzini@redhat.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
all inboxes | Powered by JetHome®