Skip to content

Commit f10a570

Browse files
Kyle Meyersean-jc
authored andcommitted
KVM: x86: Add CONFIG_KVM_MAX_NR_VCPUS to allow up to 4096 vCPUs
Add a Kconfig entry to set the maximum number of vCPUs per KVM guest and set the default value to 4096 when MAXSMP is enabled, as there are use cases that want to create more than the currently allowed 1024 vCPUs and are more than happy to eat the memory overhead. The Hyper-V TLFS doesn't allow more than 64 sparse banks, i.e. allows a maximum of 4096 virtual CPUs. Cap KVM's maximum number of virtual CPUs to 4096 to avoid exceeding Hyper-V's limit as KVM support for Hyper-V is unconditional, and alternatives like dynamically disabling Hyper-V enlightenments that rely on sparse banks would require non-trivial code changes. Suggested-by: Sean Christopherson <[email protected]> Signed-off-by: Kyle Meyer <[email protected]> Link: https://lore.kernel.org/r/[email protected] [sean: massage changelog with --verbose, document #ifdef mess] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 4346db6 commit f10a570

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 8 additions & 0 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

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

0 commit comments

Comments
 (0)