Skip to content

Commit edef5c3

Browse files
committed
KVM: x86: implement MSR_IA32_TSX_CTRL effect on CPUID
Because KVM always emulates CPUID, the CPUID clear bit (bit 1) of MSR_IA32_TSX_CTRL must be emulated "manually" by the hypervisor when performing said emulation. Right now neither kvm-intel.ko nor kvm-amd.ko implement MSR_IA32_TSX_CTRL but this will change in the next patch. Reviewed-by: Jim Mattson <[email protected]> Tested-by: Jim Mattson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent de1fca5 commit edef5c3

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,7 @@ int kvm_emulate_instruction_from_buffer(struct kvm_vcpu *vcpu,
13571357

13581358
void kvm_enable_efer_bits(u64);
13591359
bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
1360+
int __kvm_get_msr(struct kvm_vcpu *vcpu, u32 index, u64 *data, bool host_initiated);
13601361
int kvm_get_msr(struct kvm_vcpu *vcpu, u32 index, u64 *data);
13611362
int kvm_set_msr(struct kvm_vcpu *vcpu, u32 index, u64 data);
13621363
int kvm_emulate_rdmsr(struct kvm_vcpu *vcpu);

arch/x86/kvm/cpuid.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,6 @@ static int do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 func,
816816
return __do_cpuid_func(entry, func, nent, maxnent);
817817
}
818818

819-
#undef F
820-
821819
struct kvm_cpuid_param {
822820
u32 func;
823821
bool (*qualifier)(const struct kvm_cpuid_param *param);
@@ -1015,6 +1013,12 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
10151013
*ebx = entry->ebx;
10161014
*ecx = entry->ecx;
10171015
*edx = entry->edx;
1016+
if (function == 7 && index == 0) {
1017+
u64 data;
1018+
if (!__kvm_get_msr(vcpu, MSR_IA32_TSX_CTRL, &data, true) &&
1019+
(data & TSX_CTRL_CPUID_CLEAR))
1020+
*ebx &= ~(F(RTM) | F(HLE));
1021+
}
10181022
} else {
10191023
*eax = *ebx = *ecx = *edx = 0;
10201024
/*

arch/x86/kvm/x86.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,8 +1484,8 @@ static int __kvm_set_msr(struct kvm_vcpu *vcpu, u32 index, u64 data,
14841484
* Returns 0 on success, non-0 otherwise.
14851485
* Assumes vcpu_load() was already called.
14861486
*/
1487-
static int __kvm_get_msr(struct kvm_vcpu *vcpu, u32 index, u64 *data,
1488-
bool host_initiated)
1487+
int __kvm_get_msr(struct kvm_vcpu *vcpu, u32 index, u64 *data,
1488+
bool host_initiated)
14891489
{
14901490
struct msr_data msr;
14911491
int ret;

0 commit comments

Comments
 (0)