Skip to content

Commit 24879a4

Browse files
author
Lai Jiangshan
committed
KVM: x86/pvm: Remove KVM_CPUID_VENDOR_FEATURES
PVM is the only variant that places the guest kernel in a state where the underlying IF == 1 and underlying CS == 3, no vendor leaf needed. Signed-off-by: Lai Jiangshan <jiangshan.ljs@antgroup.com>
1 parent 47672e6 commit 24879a4

5 files changed

Lines changed: 5 additions & 46 deletions

File tree

arch/x86/include/uapi/asm/kvm_para.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
#include <linux/types.h>
66

77
/* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It
8-
* should be used to determine that a VM is running under KVM. And it
9-
* returns KVM_CPUID_FEATURES in eax if vendor feature is not enabled,
10-
* otherwise KVM_CPUID_VENDOR_FEATURES.
8+
* should be used to determine that a VM is running under KVM.
119
*/
1210
#define KVM_CPUID_SIGNATURE 0x40000000
1311
#define KVM_SIGNATURE "KVMKVMKVM\0\0\0"
@@ -18,10 +16,6 @@
1816
* in edx.
1917
*/
2018
#define KVM_CPUID_FEATURES 0x40000001
21-
/* This CPUID returns the vendor feature bitmaps in eax and the vendor
22-
* signature in ebx.
23-
*/
24-
#define KVM_CPUID_VENDOR_FEATURES 0x40000002
2519
#define KVM_FEATURE_CLOCKSOURCE 0
2620
#define KVM_FEATURE_NOP_IO_DELAY 1
2721
#define KVM_FEATURE_MMU_OP 2

arch/x86/include/uapi/asm/pvm_para.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
#include <linux/const.h>
66

77
/*
8-
* The CPUID instruction in PVM guest can't be trapped and emulated,
8+
* The CPUID instruction in PVM guest might not be trapped and emulated,
99
* so PVM guest should use the following two instructions instead:
1010
* "invlpg 0xffffffffff4d5650; cpuid;"
1111
*
12-
* PVM_SYNTHETIC_CPUID is supposed to not trigger any trap in the real or
13-
* virtual x86 kernel mode and is also guaranteed to trigger a trap in the
12+
* PVM_SYNTHETIC_CPUID is supposed to not trigger any trap in the real or any
13+
* paravirtual x86 kernel mode and is also guaranteed to trigger a trap in the
1414
* underlying hardware user mode for the hypervisor emulating it. The
1515
* hypervisor emulates both of the basic instructions, while the INVLPG is
1616
* often emulated as an NOP since 0xffffffffff4d5650 is normally out of the
@@ -20,12 +20,6 @@
2020
0x56,0x4d,0xff,0x0f,0xa2
2121
#define PVM_SYNTHETIC_CPUID_ADDRESS 0xffffffffff4d5650
2222

23-
/*
24-
* The vendor signature 'PVM' is returned in ebx. It should be used to
25-
* determine that a VM is running under PVM.
26-
*/
27-
#define PVM_CPUID_SIGNATURE 0x4d5650
28-
2923
/*
3024
* PVM virtual MSRS falls in the range 0x4b564df0-0x4b564dff, and it should not
3125
* conflict with KVM, see arch/x86/include/uapi/asm/kvm_para.h

arch/x86/kvm/cpuid.c

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,6 @@
3636
u32 kvm_cpu_caps[NR_KVM_CPU_CAPS] __read_mostly;
3737
EXPORT_SYMBOL_GPL(kvm_cpu_caps);
3838

39-
u32 kvm_cpuid_vendor_features;
40-
EXPORT_SYMBOL_GPL(kvm_cpuid_vendor_features);
41-
u32 kvm_cpuid_vendor_signature;
42-
EXPORT_SYMBOL_GPL(kvm_cpuid_vendor_signature);
43-
44-
static inline bool has_kvm_cpuid_vendor_features(void)
45-
{
46-
return !!kvm_cpuid_vendor_signature;
47-
}
48-
4939
u32 xstate_required_size(u64 xstate_bv, bool compacted)
5040
{
5141
int feature_bit = 0;
@@ -1142,10 +1132,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
11421132
break;
11431133
case KVM_CPUID_SIGNATURE: {
11441134
const u32 *sigptr = (const u32 *)KVM_SIGNATURE;
1145-
if (!has_kvm_cpuid_vendor_features())
1146-
entry->eax = KVM_CPUID_FEATURES;
1147-
else
1148-
entry->eax = KVM_CPUID_VENDOR_FEATURES;
1135+
entry->eax = KVM_CPUID_FEATURES;
11491136
entry->ebx = sigptr[0];
11501137
entry->ecx = sigptr[1];
11511138
entry->edx = sigptr[2];
@@ -1173,17 +1160,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
11731160
entry->ecx = 0;
11741161
entry->edx = 0;
11751162
break;
1176-
case KVM_CPUID_VENDOR_FEATURES:
1177-
if (!has_kvm_cpuid_vendor_features()) {
1178-
entry->eax = 0;
1179-
entry->ebx = 0;
1180-
} else {
1181-
entry->eax = kvm_cpuid_vendor_features;
1182-
entry->ebx = kvm_cpuid_vendor_signature;
1183-
}
1184-
entry->ecx = 0;
1185-
entry->edx = 0;
1186-
break;
11871163
case 0x80000000:
11881164
entry->eax = min(entry->eax, 0x80000022);
11891165
/*

arch/x86/kvm/cpuid.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
#include <asm/processor.h>
99
#include <uapi/asm/kvm_para.h>
1010

11-
extern u32 kvm_cpuid_vendor_features;
12-
extern u32 kvm_cpuid_vendor_signature;
13-
1411
extern u32 kvm_cpu_caps[NR_KVM_CPU_CAPS] __read_mostly;
1512
void kvm_set_cpu_caps(void);
1613

arch/x86/kvm/pvm/pvm.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3265,7 +3265,6 @@ static void pvm_exit(void)
32653265
kvm_x86_vendor_exit();
32663266
host_mmu_destroy();
32673267
allow_smaller_maxphyaddr = false;
3268-
kvm_cpuid_vendor_signature = 0;
32693268
}
32703269
module_exit(pvm_exit);
32713270

@@ -3330,7 +3329,6 @@ static int __init pvm_init(void)
33303329
goto exit_vendor;
33313330

33323331
allow_smaller_maxphyaddr = true;
3333-
kvm_cpuid_vendor_signature = PVM_CPUID_SIGNATURE;
33343332

33353333
return 0;
33363334

0 commit comments

Comments
 (0)