diff mbox series

[v2] KVM: x86: Increase KVM_MAX_VCPUS to 4096

Message ID 20220629203824.150259-1-kyle.meyer@hpe.com (mailing list archive)
State New, archived
Headers show
Series [v2] KVM: x86: Increase KVM_MAX_VCPUS to 4096 | expand

Commit Message

Kyle Meyer June 29, 2022, 8:38 p.m. UTC
Increase KVM_MAX_VCPUS to 4096 when the maximum number of supported CPUs
(NR_CPUS) is greater than 1024.

The Hyper-V TLFS doesn't allow more than 64 sparse banks, which allows a
maximum of 4096 virtual CPUs. Limit KVM's maximum number of virtual CPUs
to 4096 to avoid exceeding that limit.

Notable changes:

* KVM_MAX_VCPU_IDS will increase from 4096 to 16384.
* KVM_HV_MAX_SPARSE_VCPU_SET_BITS will increase from 16 to 64.

* CPUID[HYPERV_CPUID_IMPLEMENT_LIMITS (00x40000005)].EAX will now be 4096.

* struct kvm will increase from 40336 B to 40720 B.
* struct kvm_ioapic will increase from 5240 B to 19064 B.

* vcpu_mask in kvm_hv_flush_tlb will increase from 128 B to 512 B.
* vcpu_bitmap in ioapic_write_indirect will increase from 128 B to 512 B.
* vp_bitmap in sparse_set_to_vcpu_mask will increase from 128 B to 512 B.

Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
---
 arch/x86/include/asm/kvm_host.h | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Vitaly Kuznetsov June 30, 2022, 8:09 a.m. UTC | #1
Kyle Meyer <kyle.meyer@hpe.com> writes:

> Increase KVM_MAX_VCPUS to 4096 when the maximum number of supported CPUs
> (NR_CPUS) is greater than 1024.
>
> The Hyper-V TLFS doesn't allow more than 64 sparse banks, which allows a
> maximum of 4096 virtual CPUs. Limit KVM's maximum number of virtual CPUs
> to 4096 to avoid exceeding that limit.

In theory, it's just TLB flush and IPI hypercalls which have this
limitation. Strictly speaking, guest can have more than 4096 vCPUs,
it'll just have to do IPIs/TLB flush in a different way.

>
> Notable changes:
>
> * KVM_MAX_VCPU_IDS will increase from 4096 to 16384.
> * KVM_HV_MAX_SPARSE_VCPU_SET_BITS will increase from 16 to 64.
>
> * CPUID[HYPERV_CPUID_IMPLEMENT_LIMITS (00x40000005)].EAX will now be 4096.

	redundant leading zero		 ^^

>
> * struct kvm will increase from 40336 B to 40720 B.
> * struct kvm_ioapic will increase from 5240 B to 19064 B.
>
> * vcpu_mask in kvm_hv_flush_tlb will increase from 128 B to 512 B.
> * vcpu_bitmap in ioapic_write_indirect will increase from 128 B to 512 B.
> * vp_bitmap in sparse_set_to_vcpu_mask will increase from 128 B to 512 B.
>
> Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
> ---
>  arch/x86/include/asm/kvm_host.h | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 9217bd6cf0d1..867a945f0152 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -38,7 +38,11 @@
>  
>  #define __KVM_HAVE_ARCH_VCPU_DEBUGFS
>  
> +#if NR_CPUS < 1024
>  #define KVM_MAX_VCPUS 1024
> +#else
> +#define KVM_MAX_VCPUS 4096
> +#endif
>  
>  /*
>   * In x86, the VCPU ID corresponds to the APIC ID, and APIC IDs
Sean Christopherson July 7, 2022, 5:03 p.m. UTC | #2
On Thu, Jun 30, 2022, Vitaly Kuznetsov wrote:
> Kyle Meyer <kyle.meyer@hpe.com> writes:
> 
> > Increase KVM_MAX_VCPUS to 4096 when the maximum number of supported CPUs
> > (NR_CPUS) is greater than 1024.

Changelog says "greater than 1024", code says "at least 1024". 

> > The Hyper-V TLFS doesn't allow more than 64 sparse banks, which allows a
> > maximum of 4096 virtual CPUs. Limit KVM's maximum number of virtual CPUs
> > to 4096 to avoid exceeding that limit.
> 
> In theory, it's just TLB flush and IPI hypercalls which have this
> limitation. Strictly speaking, guest can have more than 4096 vCPUs,
> it'll just have to do IPIs/TLB flush in a different way.

Yeah, I don't see any reason to arbitrarily limit this to 4096.  And conversely,
I don't see any reason to force it to 4096 if NR_CPUS < 4096, it seems highly
unlikely that there's a use case for oversubscribing vCPUs in a single VM when
there are more than 1024 pCPUs.
diff mbox series

Patch

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 9217bd6cf0d1..867a945f0152 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -38,7 +38,11 @@ 
 
 #define __KVM_HAVE_ARCH_VCPU_DEBUGFS
 
+#if NR_CPUS < 1024
 #define KVM_MAX_VCPUS 1024
+#else
+#define KVM_MAX_VCPUS 4096
+#endif
 
 /*
  * In x86, the VCPU ID corresponds to the APIC ID, and APIC IDs