Skip to content

Commit 296d5a1

Browse files
babumogerbonzini
authored andcommitted
KVM: SEV-ES: Use V_TSC_AUX if available instead of RDTSC/MSR_TSC_AUX intercepts
The TSC_AUX virtualization feature allows AMD SEV-ES guests to securely use TSC_AUX (auxiliary time stamp counter data) in the RDTSCP and RDPID instructions. The TSC_AUX value is set using the WRMSR instruction to the TSC_AUX MSR (0xC0000103). It is read by the RDMSR, RDTSCP and RDPID instructions. If the read/write of the TSC_AUX MSR is intercepted, then RDTSCP and RDPID must also be intercepted when TSC_AUX virtualization is present. However, the RDPID instruction can't be intercepted. This means that when TSC_AUX virtualization is present, RDTSCP and TSC_AUX MSR read/write must not be intercepted for SEV-ES (or SEV-SNP) guests. Signed-off-by: Babu Moger <[email protected]> Message-Id: <165040164424.1399644.13833277687385156344.stgit@bmoger-ubuntu> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent f309033 commit 296d5a1

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@
405405
#define X86_FEATURE_SEV (19*32+ 1) /* AMD Secure Encrypted Virtualization */
406406
#define X86_FEATURE_VM_PAGE_FLUSH (19*32+ 2) /* "" VM Page Flush MSR is supported */
407407
#define X86_FEATURE_SEV_ES (19*32+ 3) /* AMD Secure Encrypted Virtualization - Encrypted State */
408-
#define X86_FEATURE_V_TSC_AUX (19*32+ 9) /* Virtual TSC_AUX */
408+
#define X86_FEATURE_V_TSC_AUX (19*32+ 9) /* "" Virtual TSC_AUX */
409409
#define X86_FEATURE_SME_COHERENT (19*32+10) /* "" AMD hardware-enforced cache coherency */
410410

411411
/*

arch/x86/kvm/svm/sev.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,6 +2926,14 @@ void sev_es_init_vmcb(struct vcpu_svm *svm)
29262926
set_msr_interception(vcpu, svm->msrpm, MSR_IA32_LASTBRANCHTOIP, 1, 1);
29272927
set_msr_interception(vcpu, svm->msrpm, MSR_IA32_LASTINTFROMIP, 1, 1);
29282928
set_msr_interception(vcpu, svm->msrpm, MSR_IA32_LASTINTTOIP, 1, 1);
2929+
2930+
if (boot_cpu_has(X86_FEATURE_V_TSC_AUX) &&
2931+
(guest_cpuid_has(&svm->vcpu, X86_FEATURE_RDTSCP) ||
2932+
guest_cpuid_has(&svm->vcpu, X86_FEATURE_RDPID))) {
2933+
set_msr_interception(vcpu, svm->msrpm, MSR_TSC_AUX, 1, 1);
2934+
if (guest_cpuid_has(&svm->vcpu, X86_FEATURE_RDTSCP))
2935+
svm_clr_intercept(svm, INTERCEPT_RDTSCP);
2936+
}
29292937
}
29302938

29312939
void sev_es_vcpu_reset(struct vcpu_svm *svm)

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ static const struct svm_direct_access_msrs {
9999
{ .index = MSR_EFER, .always = false },
100100
{ .index = MSR_IA32_CR_PAT, .always = false },
101101
{ .index = MSR_AMD64_SEV_ES_GHCB, .always = true },
102+
{ .index = MSR_TSC_AUX, .always = false },
102103
{ .index = MSR_INVALID, .always = false },
103104
};
104105

arch/x86/kvm/svm/svm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#define IOPM_SIZE PAGE_SIZE * 3
3030
#define MSRPM_SIZE PAGE_SIZE * 2
3131

32-
#define MAX_DIRECT_ACCESS_MSRS 20
32+
#define MAX_DIRECT_ACCESS_MSRS 21
3333
#define MSRPM_OFFSETS 16
3434
extern u32 msrpm_offsets[MSRPM_OFFSETS] __read_mostly;
3535
extern bool npt_enabled;

0 commit comments

Comments
 (0)