Skip to content

Commit d5d66e3

Browse files
bp3tk0vgregkh
authored andcommitted
KVM: SVM: Advertise TSA CPUID bits to guests
Commit 31272ab upstream. Synthesize the TSA CPUID feature bits for guests. Set TSA_{SQ,L1}_NO on unaffected machines. Signed-off-by: Borislav Petkov (AMD) <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7a0395f commit d5d66e3

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ void kvm_set_cpu_caps(void)
814814

815815
kvm_cpu_cap_mask(CPUID_8000_0021_EAX,
816816
F(NO_NESTED_DATA_BP) | F(LFENCE_RDTSC) | 0 /* SmmPgCfgLock */ |
817+
F(VERW_CLEAR) |
817818
F(NULL_SEL_CLR_BASE) | F(AUTOIBRS) | 0 /* PrefetchCtlMsr */ |
818819
F(WRMSR_XX_BASE_NS)
819820
);
@@ -826,6 +827,10 @@ void kvm_set_cpu_caps(void)
826827
F(PERFMON_V2)
827828
);
828829

830+
kvm_cpu_cap_init_kvm_defined(CPUID_8000_0021_ECX,
831+
F(TSA_SQ_NO) | F(TSA_L1_NO)
832+
);
833+
829834
/*
830835
* Synthesize "LFENCE is serializing" into the AMD-defined entry in
831836
* KVM's supported CPUID if the feature is reported as supported by the
@@ -1376,8 +1381,9 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
13761381
entry->eax = entry->ebx = entry->ecx = entry->edx = 0;
13771382
break;
13781383
case 0x80000021:
1379-
entry->ebx = entry->ecx = entry->edx = 0;
1384+
entry->ebx = entry->edx = 0;
13801385
cpuid_entry_override(entry, CPUID_8000_0021_EAX);
1386+
cpuid_entry_override(entry, CPUID_8000_0021_ECX);
13811387
break;
13821388
/* AMD Extended Performance Monitoring and Debug */
13831389
case 0x80000022: {

arch/x86/kvm/reverse_cpuid.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum kvm_only_cpuid_leafs {
1818
CPUID_8000_0022_EAX,
1919
CPUID_7_2_EDX,
2020
CPUID_24_0_EBX,
21+
CPUID_8000_0021_ECX,
2122
NR_KVM_CPU_CAPS,
2223

2324
NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS,
@@ -68,6 +69,10 @@ enum kvm_only_cpuid_leafs {
6869
/* CPUID level 0x80000022 (EAX) */
6970
#define KVM_X86_FEATURE_PERFMON_V2 KVM_X86_FEATURE(CPUID_8000_0022_EAX, 0)
7071

72+
/* CPUID level 0x80000021 (ECX) */
73+
#define KVM_X86_FEATURE_TSA_SQ_NO KVM_X86_FEATURE(CPUID_8000_0021_ECX, 1)
74+
#define KVM_X86_FEATURE_TSA_L1_NO KVM_X86_FEATURE(CPUID_8000_0021_ECX, 2)
75+
7176
struct cpuid_reg {
7277
u32 function;
7378
u32 index;
@@ -98,6 +103,7 @@ static const struct cpuid_reg reverse_cpuid[] = {
98103
[CPUID_8000_0022_EAX] = {0x80000022, 0, CPUID_EAX},
99104
[CPUID_7_2_EDX] = { 7, 2, CPUID_EDX},
100105
[CPUID_24_0_EBX] = { 0x24, 0, CPUID_EBX},
106+
[CPUID_8000_0021_ECX] = {0x80000021, 0, CPUID_ECX},
101107
};
102108

103109
/*
@@ -137,6 +143,8 @@ static __always_inline u32 __feature_translate(int x86_feature)
137143
KVM_X86_TRANSLATE_FEATURE(PERFMON_V2);
138144
KVM_X86_TRANSLATE_FEATURE(RRSBA_CTRL);
139145
KVM_X86_TRANSLATE_FEATURE(BHI_CTRL);
146+
KVM_X86_TRANSLATE_FEATURE(TSA_SQ_NO);
147+
KVM_X86_TRANSLATE_FEATURE(TSA_L1_NO);
140148
default:
141149
return x86_feature;
142150
}

0 commit comments

Comments
 (0)