Skip to content

Commit 31272ab

Browse files
committed
KVM: SVM: Advertise TSA CPUID bits to guests
Synthesize the TSA CPUID feature bits for guests. Set TSA_{SQ,L1}_NO on unaffected machines. Signed-off-by: Borislav Petkov (AMD) <[email protected]>
1 parent d8010d4 commit 31272ab

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ enum kvm_only_cpuid_leafs {
764764
CPUID_8000_0022_EAX,
765765
CPUID_7_2_EDX,
766766
CPUID_24_0_EBX,
767+
CPUID_8000_0021_ECX,
767768
NR_KVM_CPU_CAPS,
768769

769770
NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS,

arch/x86/kvm/cpuid.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,8 @@ void kvm_set_cpu_caps(void)
11651165
*/
11661166
SYNTHESIZED_F(LFENCE_RDTSC),
11671167
/* SmmPgCfgLock */
1168+
/* 4: Resv */
1169+
SYNTHESIZED_F(VERW_CLEAR),
11681170
F(NULL_SEL_CLR_BASE),
11691171
/* UpperAddressIgnore */
11701172
F(AUTOIBRS),
@@ -1179,6 +1181,11 @@ void kvm_set_cpu_caps(void)
11791181
F(SRSO_USER_KERNEL_NO),
11801182
);
11811183

1184+
kvm_cpu_cap_init(CPUID_8000_0021_ECX,
1185+
SYNTHESIZED_F(TSA_SQ_NO),
1186+
SYNTHESIZED_F(TSA_L1_NO),
1187+
);
1188+
11821189
kvm_cpu_cap_init(CPUID_8000_0022_EAX,
11831190
F(PERFMON_V2),
11841191
);
@@ -1748,8 +1755,9 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
17481755
entry->eax = entry->ebx = entry->ecx = entry->edx = 0;
17491756
break;
17501757
case 0x80000021:
1751-
entry->ebx = entry->ecx = entry->edx = 0;
1758+
entry->ebx = entry->edx = 0;
17521759
cpuid_entry_override(entry, CPUID_8000_0021_EAX);
1760+
cpuid_entry_override(entry, CPUID_8000_0021_ECX);
17531761
break;
17541762
/* AMD Extended Performance Monitoring and Debug */
17551763
case 0x80000022: {

arch/x86/kvm/reverse_cpuid.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
/* CPUID level 0x80000022 (EAX) */
5353
#define KVM_X86_FEATURE_PERFMON_V2 KVM_X86_FEATURE(CPUID_8000_0022_EAX, 0)
5454

55+
/* CPUID level 0x80000021 (ECX) */
56+
#define KVM_X86_FEATURE_TSA_SQ_NO KVM_X86_FEATURE(CPUID_8000_0021_ECX, 1)
57+
#define KVM_X86_FEATURE_TSA_L1_NO KVM_X86_FEATURE(CPUID_8000_0021_ECX, 2)
58+
5559
struct cpuid_reg {
5660
u32 function;
5761
u32 index;
@@ -82,6 +86,7 @@ static const struct cpuid_reg reverse_cpuid[] = {
8286
[CPUID_8000_0022_EAX] = {0x80000022, 0, CPUID_EAX},
8387
[CPUID_7_2_EDX] = { 7, 2, CPUID_EDX},
8488
[CPUID_24_0_EBX] = { 0x24, 0, CPUID_EBX},
89+
[CPUID_8000_0021_ECX] = {0x80000021, 0, CPUID_ECX},
8590
};
8691

8792
/*
@@ -121,6 +126,8 @@ static __always_inline u32 __feature_translate(int x86_feature)
121126
KVM_X86_TRANSLATE_FEATURE(PERFMON_V2);
122127
KVM_X86_TRANSLATE_FEATURE(RRSBA_CTRL);
123128
KVM_X86_TRANSLATE_FEATURE(BHI_CTRL);
129+
KVM_X86_TRANSLATE_FEATURE(TSA_SQ_NO);
130+
KVM_X86_TRANSLATE_FEATURE(TSA_L1_NO);
124131
default:
125132
return x86_feature;
126133
}

0 commit comments

Comments
 (0)