In order to be able to have a single kernel for supporting even huge
numbers of vcpus per guest some arrays should be sized dynamically.
The easiest way to do that is to add boot parameters for the maximum
number of vcpus and to calculate the maximum vcpu-id from that using
either the host topology or a topology hint via another boot parameter.
This patch series is doing that for x86. The same scheme can be easily
adapted to other architectures, but I don't want to do that in the
first iteration.
In the long term I'd suggest to have a per-guest setting of the two
parameters allowing to spare some memory for smaller guests. OTOH this
would require new ioctl()s and respective qemu modifications, so I let
those away for now.
I've tested the series not to break normal guest operation and the new
parameters to be effective on x86. For Arm64 I did a compile test only.
Changes in V2:
- removed old patch 1, as already applied
- patch 1 (old patch 2) only for reference, as the patch is already in
the kvm tree
- switch patch 2 (old patch 3) to calculate vcpu-id
- added patch 4
Juergen Gross (6):
x86/kvm: remove non-x86 stuff from arch/x86/kvm/ioapic.h
x86/kvm: add boot parameter for adding vcpu-id bits
x86/kvm: introduce per cpu vcpu masks
kvm: use kvfree() in kvm_arch_free_vm()
kvm: allocate vcpu pointer array separately
x86/kvm: add boot parameter for setting max number of vcpus per guest
.../admin-guide/kernel-parameters.txt | 25 ++++++
arch/arm64/include/asm/kvm_host.h | 1 -
arch/arm64/kvm/arm.c | 23 ++++--
arch/x86/include/asm/kvm_host.h | 26 +++++--
arch/x86/kvm/hyperv.c | 25 ++++--
arch/x86/kvm/ioapic.c | 12 ++-
arch/x86/kvm/ioapic.h | 8 +-
arch/x86/kvm/irq_comm.c | 9 ++-
arch/x86/kvm/x86.c | 78 ++++++++++++++++++-
include/linux/kvm_host.h | 26 ++++++-
10 files changed, 198 insertions(+), 35 deletions(-)
--
2.26.2
Today the maximum vcpu-id of a kvm guest's vcpu on x86 systems is set
via a #define in a header file.
In order to support higher vcpu-ids without generally increasing the
memory consumption of guests on the host (some guest structures contain
arrays sized by KVM_MAX_VCPU_ID) add a boot parameter for adding some
bits to the vcpu-id. Additional bits are needed as the vcpu-id is
constructed via bit-wise concatenation of socket-id, core-id, etc.
As those ids maximum values are not always a power of 2, the vcpu-ids
are sparse.
The additional number of bits needed is basically the number of
topology levels with a non-power-of-2 maximum value, excluding the top
most level.
The default value of the new parameter will be to take the correct
setting from the host's topology.
Calculating the maximum vcpu-id dynamically requires to allocate the
arrays using KVM_MAX_VCPU_ID as the size dynamically.
Signed-of-by: Juergen Gross [off-list ref]
---
V2:
- switch to specifying additional bits (based on comment by Vitaly
Kuznetsov)
Signed-off-by: Juergen Gross <jgross@suse.com>
---
.../admin-guide/kernel-parameters.txt | 18 ++++++++++++
arch/x86/include/asm/kvm_host.h | 4 ++-
arch/x86/kvm/ioapic.c | 12 +++++++-
arch/x86/kvm/ioapic.h | 4 +--
arch/x86/kvm/x86.c | 29 +++++++++++++++++++
5 files changed, 63 insertions(+), 4 deletions(-)
@@ -2435,6 +2435,24 @@ feature (tagged TLBs) on capable Intel chips. Default is 1 (enabled)+ kvm.vcpu_id_add_bits=+ [KVM,X86] The vcpu-ids of guests are sparse, as they+ are constructed by bit-wise concatenation of the ids of+ the different topology levels (sockets, cores, threads).++ This parameter specifies how many additional bits the+ maximum vcpu-id needs compared to the maximum number of+ vcpus.++ Normally this value is the number of topology levels+ without the threads level and without the highest+ level.++ The special value -1 can be used to support guests+ with the same topology is the host.++ Default: -1+ l1d_flush= [X86,INTEL] Control mitigation for L1D based snooping vulnerability.
@@ -39,13 +39,13 @@ struct kvm_vcpu;structdest_map{/* vcpu bitmap where IRQ has been sent */-DECLARE_BITMAP(map,KVM_MAX_VCPU_ID+1);+unsignedlong*map;/**Vectorsenttoagivenvcpu,onlyvalidwhen*thevcpu'sbitinmapisset*/-u8vectors[KVM_MAX_VCPU_ID+1];+u8*vectors;};
@@ -184,6 +185,34 @@ module_param(force_emulation_prefix, bool, S_IRUGO);int__read_mostlypi_inject_timer=-1;module_param(pi_inject_timer,bint,S_IRUGO|S_IWUSR);+staticint__read_mostlyvcpu_id_add_bits=-1;+module_param(vcpu_id_add_bits,int,S_IRUGO);++unsignedintkvm_max_vcpu_id(void)+{+intn_bits=fls(KVM_MAX_VCPUS-1);++if(vcpu_id_add_bits<-1||vcpu_id_add_bits>(32-n_bits)){+pr_err("Invalid value of vcpu_id_add_bits=%d parameter!\n",+vcpu_id_add_bits);+vcpu_id_add_bits=-1;+}++if(vcpu_id_add_bits>=0){+n_bits+=vcpu_id_add_bits;+}else{+n_bits++;/* One additional bit for core level. */+if(topology_max_die_per_package()>1)+n_bits++;/* One additional bit for die level. */+}++if(!n_bits)+n_bits=1;++return(1U<<n_bits)-1;+}+EXPORT_SYMBOL_GPL(kvm_max_vcpu_id);+/**RestoringthehostvalueforMSRsthatareonlyconsumedwhenrunningin*usermode,e.g.SYSCALLMSRsandTSC_AUX,canbedeferreduntiltheCPU
Today the maximum number of vcpus of a kvm guest is set via a #define
in a header file.
In order to support higher vcpu numbers for guests without generally
increasing the memory consumption of guests on the host especially on
very large systems add a boot parameter for specifying the number of
allowed vcpus for guests.
The default will still be the current setting of 288. The value 0 has
the special meaning to limit the number of possible vcpus to the
number of possible cpus of the host.
Signed-off-by: Juergen Gross <jgross@suse.com>
---
Documentation/admin-guide/kernel-parameters.txt | 7 +++++++
arch/x86/include/asm/kvm_host.h | 5 ++++-
arch/x86/kvm/x86.c | 9 ++++++++-
3 files changed, 19 insertions(+), 2 deletions(-)
@@ -2435,6 +2435,13 @@ feature (tagged TLBs) on capable Intel chips. Default is 1 (enabled)+ kvm.max_vcpus= [KVM,X86] Set the maximum allowed numbers of vcpus per+ guest. The special value 0 sets the limit to the number+ of physical cpus possible on the host (including not+ yet hotplugged cpus). Higher values will result in+ slightly higher memory consumption per guest.+ Default: 288+ kvm.vcpu_id_add_bits= [KVM,X86] The vcpu-ids of guests are sparse, as they are constructed by bit-wise concatenation of the ids of
@@ -38,7 +38,8 @@#define __KVM_HAVE_ARCH_VCPU_DEBUGFS-#define KVM_MAX_VCPUS 288+#define KVM_DEFAULT_MAX_VCPUS 288+#define KVM_MAX_VCPUS max_vcpus#define KVM_SOFT_MAX_VCPUS 240#define KVM_MAX_VCPU_ID kvm_max_vcpu_id()/* memory slots that are not exposed to userspace */
@@ -1588,6 +1589,8 @@ extern u64 kvm_max_tsc_scaling_ratio;externu64kvm_default_tsc_scaling_ratio;/* bus lock detection supported? */externboolkvm_has_bus_lock_exit;+/* maximum number of vcpus per guest */+externunsignedintmax_vcpus;/* maximum vcpu-id */unsignedintkvm_max_vcpu_id(void);
Today the maximum vcpu-id of a kvm guest's vcpu on x86 systems is set
via a #define in a header file.
In order to support higher vcpu-ids without generally increasing the
memory consumption of guests on the host (some guest structures contain
arrays sized by KVM_MAX_VCPU_ID) add a boot parameter for adding some
bits to the vcpu-id. Additional bits are needed as the vcpu-id is
constructed via bit-wise concatenation of socket-id, core-id, etc.
As those ids maximum values are not always a power of 2, the vcpu-ids
are sparse.
The additional number of bits needed is basically the number of
topology levels with a non-power-of-2 maximum value, excluding the top
most level.
The default value of the new parameter will be to take the correct
setting from the host's topology.
Calculating the maximum vcpu-id dynamically requires to allocate the
arrays using KVM_MAX_VCPU_ID as the size dynamically.
Signed-of-by: Juergen Gross [off-list ref]
---
V2:
- switch to specifying additional bits (based on comment by Vitaly
Kuznetsov)
Signed-off-by: Juergen Gross <jgross@suse.com>
---
.../admin-guide/kernel-parameters.txt | 18 ++++++++++++
arch/x86/include/asm/kvm_host.h | 4 ++-
arch/x86/kvm/ioapic.c | 12 +++++++-
arch/x86/kvm/ioapic.h | 4 +--
arch/x86/kvm/x86.c | 29 +++++++++++++++++++
5 files changed, 63 insertions(+), 4 deletions(-)
@@ -2435,6 +2435,24 @@ feature (tagged TLBs) on capable Intel chips. Default is 1 (enabled)+ kvm.vcpu_id_add_bits=+ [KVM,X86] The vcpu-ids of guests are sparse, as they+ are constructed by bit-wise concatenation of the ids of+ the different topology levels (sockets, cores, threads).++ This parameter specifies how many additional bits the+ maximum vcpu-id needs compared to the maximum number of+ vcpus.++ Normally this value is the number of topology levels+ without the threads level and without the highest+ level.++ The special value -1 can be used to support guests+ with the same topology is the host.++ Default: -1+ l1d_flush= [X86,INTEL] Control mitigation for L1D based snooping vulnerability.
@@ -39,13 +39,13 @@ struct kvm_vcpu;structdest_map{/* vcpu bitmap where IRQ has been sent */-DECLARE_BITMAP(map,KVM_MAX_VCPU_ID+1);+unsignedlong*map;/**Vectorsenttoagivenvcpu,onlyvalidwhen*thevcpu'sbitinmapisset*/-u8vectors[KVM_MAX_VCPU_ID+1];+u8*vectors;};
@@ -184,6 +185,34 @@ module_param(force_emulation_prefix, bool, S_IRUGO);int__read_mostlypi_inject_timer=-1;module_param(pi_inject_timer,bint,S_IRUGO|S_IWUSR);+staticint__read_mostlyvcpu_id_add_bits=-1;+module_param(vcpu_id_add_bits,int,S_IRUGO);++unsignedintkvm_max_vcpu_id(void)+{+intn_bits=fls(KVM_MAX_VCPUS-1);++if(vcpu_id_add_bits<-1||vcpu_id_add_bits>(32-n_bits)){+pr_err("Invalid value of vcpu_id_add_bits=%d parameter!\n",+vcpu_id_add_bits);+vcpu_id_add_bits=-1;+}++if(vcpu_id_add_bits>=0){+n_bits+=vcpu_id_add_bits;+}else{+n_bits++;/* One additional bit for core level. */+if(topology_max_die_per_package()>1)+n_bits++;/* One additional bit for die level. */
This assumes topology_max_die_per_package() can not be greater than 2,
or 1 additional bit may not suffice, right?
+ }
+
+ if (!n_bits)
+ n_bits = 1;
Nitpick: AFAIU n_bits can't be zero here as KVM_MAX_VCPUS is still
static. The last patch of the series, however, makes it possible when
max_vcpus = 1 and vcpu_id_add_bits = 0. With this, I'd suggest to move
the check to the last patch.
+
+ return (1U << n_bits) - 1;
+}
+EXPORT_SYMBOL_GPL(kvm_max_vcpu_id);
+
/*
* Restoring the host value for MSRs that are only consumed when running in
* usermode, e.g. SYSCALL MSRs and TSC_AUX, can be deferred until the CPU
Today the maximum vcpu-id of a kvm guest's vcpu on x86 systems is set
via a #define in a header file.
In order to support higher vcpu-ids without generally increasing the
memory consumption of guests on the host (some guest structures contain
arrays sized by KVM_MAX_VCPU_ID) add a boot parameter for adding some
bits to the vcpu-id. Additional bits are needed as the vcpu-id is
constructed via bit-wise concatenation of socket-id, core-id, etc.
As those ids maximum values are not always a power of 2, the vcpu-ids
are sparse.
The additional number of bits needed is basically the number of
topology levels with a non-power-of-2 maximum value, excluding the top
most level.
The default value of the new parameter will be to take the correct
setting from the host's topology.
Calculating the maximum vcpu-id dynamically requires to allocate the
arrays using KVM_MAX_VCPU_ID as the size dynamically.
Signed-of-by: Juergen Gross [off-list ref]
---
V2:
- switch to specifying additional bits (based on comment by Vitaly
Kuznetsov)
Signed-off-by: Juergen Gross <jgross@suse.com>
---
.../admin-guide/kernel-parameters.txt | 18 ++++++++++++
arch/x86/include/asm/kvm_host.h | 4 ++-
arch/x86/kvm/ioapic.c | 12 +++++++-
arch/x86/kvm/ioapic.h | 4 +--
arch/x86/kvm/x86.c | 29 +++++++++++++++++++
5 files changed, 63 insertions(+), 4 deletions(-)
@@ -2435,6 +2435,24 @@ feature (tagged TLBs) on capable Intel chips. Default is 1 (enabled)+ kvm.vcpu_id_add_bits=+ [KVM,X86] The vcpu-ids of guests are sparse, as they+ are constructed by bit-wise concatenation of the ids of+ the different topology levels (sockets, cores, threads).++ This parameter specifies how many additional bits the+ maximum vcpu-id needs compared to the maximum number of+ vcpus.++ Normally this value is the number of topology levels+ without the threads level and without the highest+ level.++ The special value -1 can be used to support guests+ with the same topology is the host.++ Default: -1+ l1d_flush= [X86,INTEL] Control mitigation for L1D based snooping vulnerability.
@@ -39,13 +39,13 @@ struct kvm_vcpu;structdest_map{/* vcpu bitmap where IRQ has been sent */-DECLARE_BITMAP(map,KVM_MAX_VCPU_ID+1);+unsignedlong*map;/**Vectorsenttoagivenvcpu,onlyvalidwhen*thevcpu'sbitinmapisset*/-u8vectors[KVM_MAX_VCPU_ID+1];+u8*vectors;};
@@ -184,6 +185,34 @@ module_param(force_emulation_prefix, bool, S_IRUGO);int__read_mostlypi_inject_timer=-1;module_param(pi_inject_timer,bint,S_IRUGO|S_IWUSR);+staticint__read_mostlyvcpu_id_add_bits=-1;+module_param(vcpu_id_add_bits,int,S_IRUGO);++unsignedintkvm_max_vcpu_id(void)+{+intn_bits=fls(KVM_MAX_VCPUS-1);++if(vcpu_id_add_bits<-1||vcpu_id_add_bits>(32-n_bits)){+pr_err("Invalid value of vcpu_id_add_bits=%d parameter!\n",+vcpu_id_add_bits);+vcpu_id_add_bits=-1;+}++if(vcpu_id_add_bits>=0){+n_bits+=vcpu_id_add_bits;+}else{+n_bits++;/* One additional bit for core level. */+if(topology_max_die_per_package()>1)+n_bits++;/* One additional bit for die level. */
This assumes topology_max_die_per_package() can not be greater than 2,
or 1 additional bit may not suffice, right?
No. Each topology level can at least add one additional bit. This
mechanism assumes that each level consumes not more bits as
necessary, so with e.g. a core count of 18 per die 5 bits are used,
and not more.
quoted
+ }
+
+ if (!n_bits)
+ n_bits = 1;
Nitpick: AFAIU n_bits can't be zero here as KVM_MAX_VCPUS is still
static. The last patch of the series, however, makes it possible when
max_vcpus = 1 and vcpu_id_add_bits = 0. With this, I'd suggest to move
the check to the last patch.
This is true only if no downstream has a patch setting KVM_MAX_VCPUS to
1. I'd rather be safe than sorry here, especially as it would be very
easy to miss this dependency.
Juergen
On Fri, Sep 03, 2021 at 03:08:03PM +0200, Juergen Gross wrote:
Today the maximum vcpu-id of a kvm guest's vcpu on x86 systems is set
via a #define in a header file.
In order to support higher vcpu-ids without generally increasing the
memory consumption of guests on the host (some guest structures contain
arrays sized by KVM_MAX_VCPU_ID) add a boot parameter for adding some
bits to the vcpu-id. Additional bits are needed as the vcpu-id is
constructed via bit-wise concatenation of socket-id, core-id, etc.
As those ids maximum values are not always a power of 2, the vcpu-ids
are sparse.
The additional number of bits needed is basically the number of
topology levels with a non-power-of-2 maximum value, excluding the top
most level.
The default value of the new parameter will be to take the correct
setting from the host's topology.
Having the default depend on the host topology makes the host
behaviour unpredictable (which might be a problem when migrating
VMs from another host with a different topology). Can't we just
default to 2?
Calculating the maximum vcpu-id dynamically requires to allocate the
arrays using KVM_MAX_VCPU_ID as the size dynamically.
Signed-of-by: Juergen Gross [off-list ref]
---
V2:
- switch to specifying additional bits (based on comment by Vitaly
Kuznetsov)
Signed-off-by: Juergen Gross <jgross@suse.com>
---
+unsigned int kvm_max_vcpu_id(void)
+{
+ int n_bits = fls(KVM_MAX_VCPUS - 1);
+
+ if (vcpu_id_add_bits < -1 || vcpu_id_add_bits > (32 - n_bits)) {
+ pr_err("Invalid value of vcpu_id_add_bits=%d parameter!\n",
+ vcpu_id_add_bits);
+ vcpu_id_add_bits = -1;
+ }
+
+ if (vcpu_id_add_bits >= 0) {
+ n_bits += vcpu_id_add_bits;
+ } else {
+ n_bits++; /* One additional bit for core level. */
+ if (topology_max_die_per_package() > 1)
+ n_bits++; /* One additional bit for die level. */
+ }
+
+ if (!n_bits)
+ n_bits = 1;
+
+ return (1U << n_bits) - 1;
The largest possible VCPU ID is not KVM_MAX_VCPU_ID,
it's (KVM_MAX_VCPU_ID - 1). This is enforced by
kvm_vm_ioctl_create_vcpu().
That would mean KVM_MAX_VCPU_ID should be (1 << n_bits) instead
of ((1 << n_bits) - 1), wouldn't it?
+}
+EXPORT_SYMBOL_GPL(kvm_max_vcpu_id);
+
/*
* Restoring the host value for MSRs that are only consumed when running in
* usermode, e.g. SYSCALL MSRs and TSC_AUX, can be deferred until the CPU
--
2.26.2
On Fri, Sep 03, 2021 at 03:08:07PM +0200, Juergen Gross wrote:
quoted hunk
Today the maximum number of vcpus of a kvm guest is set via a #define
in a header file.
In order to support higher vcpu numbers for guests without generally
increasing the memory consumption of guests on the host especially on
very large systems add a boot parameter for specifying the number of
allowed vcpus for guests.
The default will still be the current setting of 288. The value 0 has
the special meaning to limit the number of possible vcpus to the
number of possible cpus of the host.
Signed-off-by: Juergen Gross <jgross@suse.com>
---
Documentation/admin-guide/kernel-parameters.txt | 7 +++++++
arch/x86/include/asm/kvm_host.h | 5 ++++-
arch/x86/kvm/x86.c | 9 ++++++++-
3 files changed, 19 insertions(+), 2 deletions(-)
@@ -2435,6 +2435,13 @@ feature (tagged TLBs) on capable Intel chips. Default is 1 (enabled)+ kvm.max_vcpus= [KVM,X86] Set the maximum allowed numbers of vcpus per+ guest. The special value 0 sets the limit to the number+ of physical cpus possible on the host (including not+ yet hotplugged cpus). Higher values will result in+ slightly higher memory consumption per guest.+ Default: 288+ kvm.vcpu_id_add_bits= [KVM,X86] The vcpu-ids of guests are sparse, as they are constructed by bit-wise concatenation of the ids of
@@ -38,7 +38,8 @@#define __KVM_HAVE_ARCH_VCPU_DEBUGFS-#define KVM_MAX_VCPUS 288+#define KVM_DEFAULT_MAX_VCPUS 288+#define KVM_MAX_VCPUS max_vcpus#define KVM_SOFT_MAX_VCPUS 240#define KVM_MAX_VCPU_ID kvm_max_vcpu_id()/* memory slots that are not exposed to userspace */
@@ -1588,6 +1589,8 @@ extern u64 kvm_max_tsc_scaling_ratio;externu64kvm_default_tsc_scaling_ratio;/* bus lock detection supported? */externboolkvm_has_bus_lock_exit;+/* maximum number of vcpus per guest */+externunsignedintmax_vcpus;/* maximum vcpu-id */unsignedintkvm_max_vcpu_id(void);
A quesintion here: the parameter "vcpu_id_add_bits" also depends
on the "max_vcpus", we can't calculate the "vcpu_id_add_bits" from
"max_vcpus" because KVM has no topologically knowledge to determine
bits needed for each socket/core/thread level, right?
quoted hunk
if (vcpu_id_add_bits < -1 || vcpu_id_add_bits > (32 - n_bits)) {
pr_err("Invalid value of vcpu_id_add_bits=%d parameter!\n",
@@ -11033,6 +11037,9 @@ int kvm_arch_hardware_setup(void *opaque) if (boot_cpu_has(X86_FEATURE_XSAVES)) rdmsrl(MSR_IA32_XSS, host_xss);+ if (max_vcpus == 0)+ max_vcpus = num_possible_cpus();+ kvm_pcpu_vcpu_mask = __alloc_percpu(KVM_VCPU_MASK_SZ, sizeof(unsigned long)); kvm_hv_vp_bitmap = __alloc_percpu(KVM_HV_VPMAP_SZ, sizeof(u64));--
On Fri, Sep 03, 2021 at 03:08:03PM +0200, Juergen Gross wrote:
quoted
Today the maximum vcpu-id of a kvm guest's vcpu on x86 systems is set
via a #define in a header file.
In order to support higher vcpu-ids without generally increasing the
memory consumption of guests on the host (some guest structures contain
arrays sized by KVM_MAX_VCPU_ID) add a boot parameter for adding some
bits to the vcpu-id. Additional bits are needed as the vcpu-id is
constructed via bit-wise concatenation of socket-id, core-id, etc.
As those ids maximum values are not always a power of 2, the vcpu-ids
are sparse.
The additional number of bits needed is basically the number of
topology levels with a non-power-of-2 maximum value, excluding the top
most level.
The default value of the new parameter will be to take the correct
setting from the host's topology.
Having the default depend on the host topology makes the host
behaviour unpredictable (which might be a problem when migrating
VMs from another host with a different topology). Can't we just
default to 2?
Okay, fine with me.
quoted
Calculating the maximum vcpu-id dynamically requires to allocate the
arrays using KVM_MAX_VCPU_ID as the size dynamically.
Signed-of-by: Juergen Gross [off-list ref]
---
V2:
- switch to specifying additional bits (based on comment by Vitaly
Kuznetsov)
Signed-off-by: Juergen Gross <jgross@suse.com>
---
+unsigned int kvm_max_vcpu_id(void)
+{
+ int n_bits = fls(KVM_MAX_VCPUS - 1);
+
+ if (vcpu_id_add_bits < -1 || vcpu_id_add_bits > (32 - n_bits)) {
+ pr_err("Invalid value of vcpu_id_add_bits=%d parameter!\n",
+ vcpu_id_add_bits);
+ vcpu_id_add_bits = -1;
+ }
+
+ if (vcpu_id_add_bits >= 0) {
+ n_bits += vcpu_id_add_bits;
+ } else {
+ n_bits++; /* One additional bit for core level. */
+ if (topology_max_die_per_package() > 1)
+ n_bits++; /* One additional bit for die level. */
+ }
+
+ if (!n_bits)
+ n_bits = 1;
+
+ return (1U << n_bits) - 1;
The largest possible VCPU ID is not KVM_MAX_VCPU_ID,
it's (KVM_MAX_VCPU_ID - 1). This is enforced by
kvm_vm_ioctl_create_vcpu().
That would mean KVM_MAX_VCPU_ID should be (1 << n_bits) instead
of ((1 << n_bits) - 1), wouldn't it?
Oh, indeed. I have been fooled by the IMO bad naming of this macro.
The current value 1023 suggests it is not only me having been fooled.
Shouldn't it be named "KVM_MAX_VCPU_IDS" instead?
Juergen
On Fri, Sep 03, 2021 at 03:08:07PM +0200, Juergen Gross wrote:
quoted
Today the maximum number of vcpus of a kvm guest is set via a #define
in a header file.
In order to support higher vcpu numbers for guests without generally
increasing the memory consumption of guests on the host especially on
very large systems add a boot parameter for specifying the number of
allowed vcpus for guests.
The default will still be the current setting of 288. The value 0 has
the special meaning to limit the number of possible vcpus to the
number of possible cpus of the host.
Signed-off-by: Juergen Gross <jgross@suse.com>
---
Documentation/admin-guide/kernel-parameters.txt | 7 +++++++
arch/x86/include/asm/kvm_host.h | 5 ++++-
arch/x86/kvm/x86.c | 9 ++++++++-
3 files changed, 19 insertions(+), 2 deletions(-)
@@ -2435,6 +2435,13 @@ feature (tagged TLBs) on capable Intel chips. Default is 1 (enabled)+ kvm.max_vcpus= [KVM,X86] Set the maximum allowed numbers of vcpus per+ guest. The special value 0 sets the limit to the number+ of physical cpus possible on the host (including not+ yet hotplugged cpus). Higher values will result in+ slightly higher memory consumption per guest.+ Default: 288+ kvm.vcpu_id_add_bits= [KVM,X86] The vcpu-ids of guests are sparse, as they are constructed by bit-wise concatenation of the ids of
@@ -38,7 +38,8 @@#define __KVM_HAVE_ARCH_VCPU_DEBUGFS-#define KVM_MAX_VCPUS 288+#define KVM_DEFAULT_MAX_VCPUS 288+#define KVM_MAX_VCPUS max_vcpus#define KVM_SOFT_MAX_VCPUS 240#define KVM_MAX_VCPU_ID kvm_max_vcpu_id()/* memory slots that are not exposed to userspace */
@@ -1588,6 +1589,8 @@ extern u64 kvm_max_tsc_scaling_ratio;externu64kvm_default_tsc_scaling_ratio;/* bus lock detection supported? */externboolkvm_has_bus_lock_exit;+/* maximum number of vcpus per guest */+externunsignedintmax_vcpus;/* maximum vcpu-id */unsignedintkvm_max_vcpu_id(void);
A quesintion here: the parameter "vcpu_id_add_bits" also depends
on the "max_vcpus", we can't calculate the "vcpu_id_add_bits" from
"max_vcpus" because KVM has no topologically knowledge to determine
bits needed for each socket/core/thread level, right?
From: Paolo Bonzini <pbonzini@redhat.com> Date: 2021-09-28 16:41:42
On 03/09/21 15:08, Juergen Gross wrote:
+ if (vcpu_id_add_bits >= 0) {
+ n_bits += vcpu_id_add_bits;
+ } else {
+ n_bits++; /* One additional bit for core level. */
+ if (topology_max_die_per_package() > 1)
+ n_bits++; /* One additional bit for die level. */
This needs to be unconditional since it is always possible to emulate a
multiple-die-per-package topology for a guest, even if the host has just
one.
Paolo