diff options
author | Sean Christopherson <seanjc@google.com> | 2024-12-11 04:33:00 +0300 |
---|---|---|
committer | Sean Christopherson <seanjc@google.com> | 2025-02-12 21:16:31 +0300 |
commit | 7e9f735e7ac4b95207e108ec67d04a9c4cb9cced (patch) | |
tree | 1839f067c39ca19fc85730a2163cd6d7c229ee5c | |
parent | aa93b6f96f6486fa1a78b7b92ebe43f49f35d8bf (diff) | |
download | linux-7e9f735e7ac4b95207e108ec67d04a9c4cb9cced.tar.xz |
KVM: x86: Apply TSX_CTRL_CPUID_CLEAR if and only if the vCPU has RTM or HLE
When emulating CPUID, retrieve MSR_IA32_TSX_CTRL.TSX_CTRL_CPUID_CLEAR if
and only if RTM and/or HLE feature bits need to be cleared. Getting the
MSR value is unnecessary if neither bit is set, and avoiding the lookup
saves ~80 cycles for vCPUs without RTM or HLE.
Cc: Jim Mattson <jmattson@google.com>
Reviewed-by: Jim Mattson <jmattson@google.com>
Link: https://lore.kernel.org/r/20241211013302.1347853-4-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
-rw-r--r-- | arch/x86/kvm/cpuid.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index a57fa0123c77..0de3f581ef12 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -1999,7 +1999,8 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, *edx = entry->edx; if (function == 7 && index == 0) { u64 data; - if (!__kvm_get_msr(vcpu, MSR_IA32_TSX_CTRL, &data, true) && + if ((*ebx & (feature_bit(RTM) | feature_bit(HLE))) && + !__kvm_get_msr(vcpu, MSR_IA32_TSX_CTRL, &data, true) && (data & TSX_CTRL_CPUID_CLEAR)) *ebx &= ~(feature_bit(RTM) | feature_bit(HLE)); } else if (function == 0x80000007) { |