Skip to content

Commit dbd6127

Browse files
sean-jcbonzini
authored andcommitted
KVM: SVM: Clear MSR_TSC_AUX[63:32] on write
Force clear bits 63:32 of MSR_TSC_AUX on write to emulate current AMD CPUs, which completely ignore the upper 32 bits, including dropping them on write. Emulating AMD hardware will also allow migrating a vCPU from AMD hardware to Intel hardware without requiring userspace to manually clear the upper bits, which are reserved on Intel hardware. Presumably, MSR_TSC_AUX[63:32] are intended to be reserved on AMD, but sadly the APM doesn't say _anything_ about those bits in the context of MSR access. The RDTSCP entry simply states that RCX contains bits 31:0 of the MSR, zero extended. And even worse is that the RDPID description implies that it can consume all 64 bits of the MSR: RDPID reads the value of TSC_AUX MSR used by the RDTSCP instruction into the specified destination register. Normal operand size prefixes do not apply and the update is either 32 bit or 64 bit based on the current mode. Emulate current hardware behavior to give KVM the best odds of playing nice with whatever the behavior of future AMD CPUs happens to be. Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> [Fix broken patch. - Paolo] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 6f2b296 commit dbd6127

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2899,13 +2899,23 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
28992899
!guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP))
29002900
return 1;
29012901

2902+
/*
2903+
* Per Intel's SDM, bits 63:32 are reserved, but AMD's APM has
2904+
* incomplete and conflicting architectural behavior. Current
2905+
* AMD CPUs completely ignore bits 63:32, i.e. they aren't
2906+
* reserved and always read as zeros. Emulate AMD CPU behavior
2907+
* to avoid explosions if the vCPU is migrated from an AMD host
2908+
* to an Intel host.
2909+
*/
2910+
data = (u32)data;
2911+
29022912
/*
29032913
* This is rare, so we update the MSR here instead of using
29042914
* direct_access_msrs. Doing that would require a rdmsr in
29052915
* svm_vcpu_put.
29062916
*/
2917+
wrmsrl(MSR_TSC_AUX, data);
29072918
svm->tsc_aux = data;
2908-
wrmsrl(MSR_TSC_AUX, svm->tsc_aux);
29092919
break;
29102920
case MSR_IA32_DEBUGCTLMSR:
29112921
if (!boot_cpu_has(X86_FEATURE_LBRV)) {

0 commit comments

Comments
 (0)