Skip to content

Commit f292dc8

Browse files
committed
Merge tag 'kvm-x86-misc-6.7' of https://github.com/kvm-x86/linux into HEAD
KVM x86 misc changes for 6.7: - Add CONFIG_KVM_MAX_NR_VCPUS to allow supporting up to 4096 vCPUs without forcing more common use cases to eat the extra memory overhead. - Add IBPB and SBPB virtualization support. - Fix a bug where restoring a vCPU snapshot that was taken within 1 second of creating the original vCPU would cause KVM to try to synchronize the vCPU's TSC and thus clobber the correct TSC being set by userspace. - Compute guest wall clock using a single TSC read to avoid generating an inaccurate time, e.g. if the vCPU is preempted between multiple TSC reads. - "Virtualize" HWCR.TscFreqSel to make Linux guests happy, which complain about a "Firmware Bug" if the bit isn't set for select F/M/S combos. - Don't apply side effects to Hyper-V's synthetic timer on writes from userspace to fix an issue where the auto-enable behavior can trigger spurious interrupts, i.e. do auto-enabling only for guest writes. - Remove an unnecessary kick of all vCPUs when synchronizing the dirty log without PML enabled. - Advertise "support" for non-serializing FS/GS base MSR writes as appropriate. - Use octal notation for file permissions through KVM x86. - Fix a handful of typo fixes and warts.
2 parents fadaf57 + 2770d47 commit f292dc8

File tree

15 files changed

+251
-66
lines changed

15 files changed

+251
-66
lines changed

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@
443443

444444
/* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word 20 */
445445
#define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0) /* "" No Nested Data Breakpoints */
446+
#define X86_FEATURE_WRMSR_XX_BASE_NS (20*32+ 1) /* "" WRMSR to {FS,GS,KERNEL_GS}_BASE is non-serializing */
446447
#define X86_FEATURE_LFENCE_RDTSC (20*32+ 2) /* "" LFENCE always serializing / synchronizes RDTSC */
447448
#define X86_FEATURE_NULL_SEL_CLR_BASE (20*32+ 6) /* "" Null Selector Clears Base */
448449
#define X86_FEATURE_AUTOIBRS (20*32+ 8) /* "" Automatic IBRS */

arch/x86/include/asm/kvm_host.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@
3939

4040
#define __KVM_HAVE_ARCH_VCPU_DEBUGFS
4141

42+
/*
43+
* CONFIG_KVM_MAX_NR_VCPUS is defined iff CONFIG_KVM!=n, provide a dummy max if
44+
* KVM is disabled (arbitrarily use the default from CONFIG_KVM_MAX_NR_VCPUS).
45+
*/
46+
#ifdef CONFIG_KVM_MAX_NR_VCPUS
47+
#define KVM_MAX_VCPUS CONFIG_KVM_MAX_NR_VCPUS
48+
#else
4249
#define KVM_MAX_VCPUS 1024
50+
#endif
4351

4452
/*
4553
* In x86, the VCPU ID corresponds to the APIC ID, and APIC IDs
@@ -1275,7 +1283,6 @@ struct kvm_arch {
12751283
*/
12761284
spinlock_t mmu_unsync_pages_lock;
12771285

1278-
struct list_head assigned_dev_head;
12791286
struct iommu_domain *iommu_domain;
12801287
bool iommu_noncoherent;
12811288
#define __KVM_HAVE_ARCH_NONCOHERENT_DMA
@@ -1323,6 +1330,7 @@ struct kvm_arch {
13231330
int nr_vcpus_matched_tsc;
13241331

13251332
u32 default_tsc_khz;
1333+
bool user_set_tsc;
13261334

13271335
seqcount_raw_spinlock_t pvclock_sc;
13281336
bool use_master_clock;
@@ -1691,7 +1699,7 @@ struct kvm_x86_ops {
16911699

16921700
void (*request_immediate_exit)(struct kvm_vcpu *vcpu);
16931701

1694-
void (*sched_in)(struct kvm_vcpu *kvm, int cpu);
1702+
void (*sched_in)(struct kvm_vcpu *vcpu, int cpu);
16951703

16961704
/*
16971705
* Size of the CPU's dirty log buffer, i.e. VMX's PML buffer. A zero

arch/x86/include/asm/msr-index.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@
553553
#define MSR_AMD64_CPUID_FN_1 0xc0011004
554554
#define MSR_AMD64_LS_CFG 0xc0011020
555555
#define MSR_AMD64_DC_CFG 0xc0011022
556+
#define MSR_AMD64_TW_CFG 0xc0011023
556557

557558
#define MSR_AMD64_DE_CFG 0xc0011029
558559
#define MSR_AMD64_DE_CFG_LFENCE_SERIALIZE_BIT 1

arch/x86/kvm/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,15 @@ config KVM_PROVE_MMU
154154
config KVM_EXTERNAL_WRITE_TRACKING
155155
bool
156156

157+
config KVM_MAX_NR_VCPUS
158+
int "Maximum number of vCPUs per KVM guest"
159+
depends on KVM
160+
range 1024 4096
161+
default 4096 if MAXSMP
162+
default 1024
163+
help
164+
Set the maximum number of vCPUs per KVM guest. Larger values will increase
165+
the memory footprint of each KVM guest, regardless of how many vCPUs are
166+
created for a given VM.
167+
157168
endif # VIRTUALIZATION

arch/x86/kvm/cpuid.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,11 +753,13 @@ void kvm_set_cpu_caps(void)
753753

754754
kvm_cpu_cap_mask(CPUID_8000_0021_EAX,
755755
F(NO_NESTED_DATA_BP) | F(LFENCE_RDTSC) | 0 /* SmmPgCfgLock */ |
756-
F(NULL_SEL_CLR_BASE) | F(AUTOIBRS) | 0 /* PrefetchCtlMsr */
756+
F(NULL_SEL_CLR_BASE) | F(AUTOIBRS) | 0 /* PrefetchCtlMsr */ |
757+
F(WRMSR_XX_BASE_NS)
757758
);
758759

759-
if (cpu_feature_enabled(X86_FEATURE_SRSO_NO))
760-
kvm_cpu_cap_set(X86_FEATURE_SRSO_NO);
760+
kvm_cpu_cap_check_and_set(X86_FEATURE_SBPB);
761+
kvm_cpu_cap_check_and_set(X86_FEATURE_IBPB_BRTYPE);
762+
kvm_cpu_cap_check_and_set(X86_FEATURE_SRSO_NO);
761763

762764
kvm_cpu_cap_init_kvm_defined(CPUID_8000_0022_EAX,
763765
F(PERFMON_V2)

arch/x86/kvm/cpuid.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ static inline bool guest_has_spec_ctrl_msr(struct kvm_vcpu *vcpu)
174174
static inline bool guest_has_pred_cmd_msr(struct kvm_vcpu *vcpu)
175175
{
176176
return (guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL) ||
177-
guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBPB));
177+
guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBPB) ||
178+
guest_cpuid_has(vcpu, X86_FEATURE_SBPB));
178179
}
179180

180181
static inline bool supports_cpuid_fault(struct kvm_vcpu *vcpu)

arch/x86/kvm/hyperv.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,10 +727,12 @@ static int stimer_set_count(struct kvm_vcpu_hv_stimer *stimer, u64 count,
727727

728728
stimer_cleanup(stimer);
729729
stimer->count = count;
730-
if (stimer->count == 0)
731-
stimer->config.enable = 0;
732-
else if (stimer->config.auto_enable)
733-
stimer->config.enable = 1;
730+
if (!host) {
731+
if (stimer->count == 0)
732+
stimer->config.enable = 0;
733+
else if (stimer->config.auto_enable)
734+
stimer->config.enable = 1;
735+
}
734736

735737
if (stimer->config.enable)
736738
stimer_mark_pending(stimer, false);

arch/x86/kvm/smm.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ void enter_smm(struct kvm_vcpu *vcpu)
324324

325325
cr0 = vcpu->arch.cr0 & ~(X86_CR0_PE | X86_CR0_EM | X86_CR0_TS | X86_CR0_PG);
326326
static_call(kvm_x86_set_cr0)(vcpu, cr0);
327-
vcpu->arch.cr0 = cr0;
328327

329328
static_call(kvm_x86_set_cr4)(vcpu, 0);
330329

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ module_param_named(npt, npt_enabled, bool, 0444);
199199

200200
/* allow nested virtualization in KVM/SVM */
201201
static int nested = true;
202-
module_param(nested, int, S_IRUGO);
202+
module_param(nested, int, 0444);
203203

204204
/* enable/disable Next RIP Save */
205205
int nrips = true;

arch/x86/kvm/vmx/vmx.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,28 +82,28 @@ bool __read_mostly enable_vpid = 1;
8282
module_param_named(vpid, enable_vpid, bool, 0444);
8383

8484
static bool __read_mostly enable_vnmi = 1;
85-
module_param_named(vnmi, enable_vnmi, bool, S_IRUGO);
85+
module_param_named(vnmi, enable_vnmi, bool, 0444);
8686

8787
bool __read_mostly flexpriority_enabled = 1;
88-
module_param_named(flexpriority, flexpriority_enabled, bool, S_IRUGO);
88+
module_param_named(flexpriority, flexpriority_enabled, bool, 0444);
8989

9090
bool __read_mostly enable_ept = 1;
91-
module_param_named(ept, enable_ept, bool, S_IRUGO);
91+
module_param_named(ept, enable_ept, bool, 0444);
9292

9393
bool __read_mostly enable_unrestricted_guest = 1;
9494
module_param_named(unrestricted_guest,
95-
enable_unrestricted_guest, bool, S_IRUGO);
95+
enable_unrestricted_guest, bool, 0444);
9696

9797
bool __read_mostly enable_ept_ad_bits = 1;
98-
module_param_named(eptad, enable_ept_ad_bits, bool, S_IRUGO);
98+
module_param_named(eptad, enable_ept_ad_bits, bool, 0444);
9999

100100
static bool __read_mostly emulate_invalid_guest_state = true;
101-
module_param(emulate_invalid_guest_state, bool, S_IRUGO);
101+
module_param(emulate_invalid_guest_state, bool, 0444);
102102

103103
static bool __read_mostly fasteoi = 1;
104-
module_param(fasteoi, bool, S_IRUGO);
104+
module_param(fasteoi, bool, 0444);
105105

106-
module_param(enable_apicv, bool, S_IRUGO);
106+
module_param(enable_apicv, bool, 0444);
107107

108108
bool __read_mostly enable_ipiv = true;
109109
module_param(enable_ipiv, bool, 0444);
@@ -114,10 +114,10 @@ module_param(enable_ipiv, bool, 0444);
114114
* use VMX instructions.
115115
*/
116116
static bool __read_mostly nested = 1;
117-
module_param(nested, bool, S_IRUGO);
117+
module_param(nested, bool, 0444);
118118

119119
bool __read_mostly enable_pml = 1;
120-
module_param_named(pml, enable_pml, bool, S_IRUGO);
120+
module_param_named(pml, enable_pml, bool, 0444);
121121

122122
static bool __read_mostly error_on_inconsistent_vmcs_config = true;
123123
module_param(error_on_inconsistent_vmcs_config, bool, 0444);

0 commit comments

Comments
 (0)