kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/6] KVM: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS and re-purpose it on x86
@ 2021-11-16 16:34 Vitaly Kuznetsov
  2021-11-16 16:34 ` [PATCH v2 1/6] KVM: arm64: Cap KVM_CAP_NR_VCPUS by kvm_arm_default_max_vcpus() Vitaly Kuznetsov
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Vitaly Kuznetsov @ 2021-11-16 16:34 UTC (permalink / raw)
  To: kvm, Paolo Bonzini
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, Eduardo Habkost,
	Marc Zyngier, Andrew Jones, Huacai Chen, Aleksandar Markovic,
	Anup Patel, Paul Mackerras, Michael Ellerman,
	Christian Borntraeger, Janosch Frank, kvm-ppc, linux-arm-kernel,
	linux-mips, kvm-riscv, linux-s390, linux-kernel

Changes since v1:
- PATCH6 for s390 added.
- On ARM64, do not make KVM_CAP_NR_VCPUS return value dependent on whether
  it is a system-wide ioctl or a per-VM one [Marc Zyngier].

Original description:

This is a continuation of "KVM: x86: Drop arbitraty KVM_SOFT_MAX_VCPUS"
(https://lore.kernel.org/kvm/20211111134733.86601-1-vkuznets@redhat.com/)
work.

1) Enforce KVM_CAP_NR_VCPUS <= KVM_CAP_MAX_VCPUS rule on all 
 architectures. [Sean Christopherson]
2) Make KVM_CAP_NR_VCPUS return num_online_cpus() and not an arbitrary
 value of '710' on x86.

Everything but x86 was only 'eyeball tested', the change is trivial
but sorry in advance if I screwed up)

Vitaly Kuznetsov (6):
  KVM: arm64: Cap KVM_CAP_NR_VCPUS by kvm_arm_default_max_vcpus()
  KVM: MIPS: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS
  KVM: PPC: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS
  KVM: RISC-V: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS
  KVM: s390: Cap KVM_CAP_NR_VCPUS by num_online_cpus()
  KVM: x86: Drop arbitraty KVM_SOFT_MAX_VCPUS

 arch/arm64/kvm/arm.c            | 9 ++++++++-
 arch/mips/kvm/mips.c            | 2 +-
 arch/powerpc/kvm/powerpc.c      | 4 ++--
 arch/riscv/kvm/vm.c             | 2 +-
 arch/s390/kvm/kvm-s390.c        | 2 ++
 arch/x86/include/asm/kvm_host.h | 1 -
 arch/x86/kvm/x86.c              | 2 +-
 7 files changed, 15 insertions(+), 7 deletions(-)

-- 
2.33.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 1/6] KVM: arm64: Cap KVM_CAP_NR_VCPUS by kvm_arm_default_max_vcpus()
  2021-11-16 16:34 [PATCH v2 0/6] KVM: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS and re-purpose it on x86 Vitaly Kuznetsov
@ 2021-11-16 16:34 ` Vitaly Kuznetsov
  2021-11-17  9:13   ` Marc Zyngier
  2021-11-17 12:07   ` Paolo Bonzini
  2021-11-16 16:34 ` [PATCH v2 2/6] KVM: MIPS: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS Vitaly Kuznetsov
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 12+ messages in thread
From: Vitaly Kuznetsov @ 2021-11-16 16:34 UTC (permalink / raw)
  To: kvm, Paolo Bonzini
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, Eduardo Habkost,
	Marc Zyngier, Andrew Jones, Huacai Chen, Aleksandar Markovic,
	Anup Patel, Paul Mackerras, Michael Ellerman,
	Christian Borntraeger, Janosch Frank, kvm-ppc, linux-arm-kernel,
	linux-mips, kvm-riscv, linux-s390, linux-kernel

Generally, it doesn't make sense to return the recommended maximum number
of vCPUs which exceeds the maximum possible number of vCPUs.

Note: ARM64 is special as the value returned by KVM_CAP_MAX_VCPUS differs
depending on whether it is a system-wide ioctl or a per-VM one. Previously,
KVM_CAP_NR_VCPUS didn't have this difference and it seems preferable to
keep the status quo. Cap KVM_CAP_NR_VCPUS by kvm_arm_default_max_vcpus()
which is what gets returned by system-wide KVM_CAP_MAX_VCPUS.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/arm64/kvm/arm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 7838e9fb693e..0690c76def5d 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -223,7 +223,14 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 		r = 1;
 		break;
 	case KVM_CAP_NR_VCPUS:
-		r = num_online_cpus();
+		/*
+		 * ARM64 treats KVM_CAP_NR_CPUS differently from all other
+		 * architectures, as it does not always bound it to
+		 * num_online_cpus(). It should not matter much because this
+		 * is just an advisory value.
+		 */
+		r = min_t(unsigned int, num_online_cpus(),
+			  kvm_arm_default_max_vcpus());
 		break;
 	case KVM_CAP_MAX_VCPUS:
 	case KVM_CAP_MAX_VCPU_ID:
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 2/6] KVM: MIPS: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS
  2021-11-16 16:34 [PATCH v2 0/6] KVM: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS and re-purpose it on x86 Vitaly Kuznetsov
  2021-11-16 16:34 ` [PATCH v2 1/6] KVM: arm64: Cap KVM_CAP_NR_VCPUS by kvm_arm_default_max_vcpus() Vitaly Kuznetsov
@ 2021-11-16 16:34 ` Vitaly Kuznetsov
  2021-11-16 16:34 ` [PATCH v2 3/6] KVM: PPC: " Vitaly Kuznetsov
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Vitaly Kuznetsov @ 2021-11-16 16:34 UTC (permalink / raw)
  To: kvm, Paolo Bonzini
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, Eduardo Habkost,
	Marc Zyngier, Andrew Jones, Huacai Chen, Aleksandar Markovic,
	Anup Patel, Paul Mackerras, Michael Ellerman,
	Christian Borntraeger, Janosch Frank, kvm-ppc, linux-arm-kernel,
	linux-mips, kvm-riscv, linux-s390, linux-kernel

It doesn't make sense to return the recommended maximum number of
vCPUs which exceeds the maximum possible number of vCPUs.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/mips/kvm/mips.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
index 562aa878b266..aa20d074d388 100644
--- a/arch/mips/kvm/mips.c
+++ b/arch/mips/kvm/mips.c
@@ -1067,7 +1067,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 		r = 1;
 		break;
 	case KVM_CAP_NR_VCPUS:
-		r = num_online_cpus();
+		r = min_t(unsigned int, num_online_cpus(), KVM_MAX_VCPUS);
 		break;
 	case KVM_CAP_MAX_VCPUS:
 		r = KVM_MAX_VCPUS;
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 3/6] KVM: PPC: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS
  2021-11-16 16:34 [PATCH v2 0/6] KVM: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS and re-purpose it on x86 Vitaly Kuznetsov
  2021-11-16 16:34 ` [PATCH v2 1/6] KVM: arm64: Cap KVM_CAP_NR_VCPUS by kvm_arm_default_max_vcpus() Vitaly Kuznetsov
  2021-11-16 16:34 ` [PATCH v2 2/6] KVM: MIPS: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS Vitaly Kuznetsov
@ 2021-11-16 16:34 ` Vitaly Kuznetsov
  2021-11-16 16:34 ` [PATCH v2 4/6] KVM: RISC-V: " Vitaly Kuznetsov
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Vitaly Kuznetsov @ 2021-11-16 16:34 UTC (permalink / raw)
  To: kvm, Paolo Bonzini
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, Eduardo Habkost,
	Marc Zyngier, Andrew Jones, Huacai Chen, Aleksandar Markovic,
	Anup Patel, Paul Mackerras, Michael Ellerman,
	Christian Borntraeger, Janosch Frank, kvm-ppc, linux-arm-kernel,
	linux-mips, kvm-riscv, linux-s390, linux-kernel

It doesn't make sense to return the recommended maximum number of
vCPUs which exceeds the maximum possible number of vCPUs.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/powerpc/kvm/powerpc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 8ab90ce8738f..ccac8d5686ff 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -641,9 +641,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 		 * implementations just count online CPUs.
 		 */
 		if (hv_enabled)
-			r = num_present_cpus();
+			r = min_t(unsigned int, num_present_cpus(), KVM_MAX_VCPUS);
 		else
-			r = num_online_cpus();
+			r = min_t(unsigned int, num_online_cpus(), KVM_MAX_VCPUS);
 		break;
 	case KVM_CAP_MAX_VCPUS:
 		r = KVM_MAX_VCPUS;
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 4/6] KVM: RISC-V: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS
  2021-11-16 16:34 [PATCH v2 0/6] KVM: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS and re-purpose it on x86 Vitaly Kuznetsov
                   ` (2 preceding siblings ...)
  2021-11-16 16:34 ` [PATCH v2 3/6] KVM: PPC: " Vitaly Kuznetsov
@ 2021-11-16 16:34 ` Vitaly Kuznetsov
  2021-11-17  5:02   ` Anup Patel
  2021-11-16 16:34 ` [PATCH v2 5/6] KVM: s390: Cap KVM_CAP_NR_VCPUS by num_online_cpus() Vitaly Kuznetsov
  2021-11-16 16:34 ` [PATCH v2 6/6] KVM: x86: Drop arbitraty KVM_SOFT_MAX_VCPUS Vitaly Kuznetsov
  5 siblings, 1 reply; 12+ messages in thread
From: Vitaly Kuznetsov @ 2021-11-16 16:34 UTC (permalink / raw)
  To: kvm, Paolo Bonzini
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, Eduardo Habkost,
	Marc Zyngier, Andrew Jones, Huacai Chen, Aleksandar Markovic,
	Anup Patel, Paul Mackerras, Michael Ellerman,
	Christian Borntraeger, Janosch Frank, kvm-ppc, linux-arm-kernel,
	linux-mips, kvm-riscv, linux-s390, linux-kernel

It doesn't make sense to return the recommended maximum number of
vCPUs which exceeds the maximum possible number of vCPUs.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/riscv/kvm/vm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/kvm/vm.c b/arch/riscv/kvm/vm.c
index 26399df15b63..fb18af34a4b5 100644
--- a/arch/riscv/kvm/vm.c
+++ b/arch/riscv/kvm/vm.c
@@ -74,7 +74,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 		r = 1;
 		break;
 	case KVM_CAP_NR_VCPUS:
-		r = num_online_cpus();
+		r = min_t(unsigned int, num_online_cpus(), KVM_MAX_VCPUS);
 		break;
 	case KVM_CAP_MAX_VCPUS:
 		r = KVM_MAX_VCPUS;
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 5/6] KVM: s390: Cap KVM_CAP_NR_VCPUS by num_online_cpus()
  2021-11-16 16:34 [PATCH v2 0/6] KVM: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS and re-purpose it on x86 Vitaly Kuznetsov
                   ` (3 preceding siblings ...)
  2021-11-16 16:34 ` [PATCH v2 4/6] KVM: RISC-V: " Vitaly Kuznetsov
@ 2021-11-16 16:34 ` Vitaly Kuznetsov
  2021-11-17  7:33   ` Christian Borntraeger
  2021-11-16 16:34 ` [PATCH v2 6/6] KVM: x86: Drop arbitraty KVM_SOFT_MAX_VCPUS Vitaly Kuznetsov
  5 siblings, 1 reply; 12+ messages in thread
From: Vitaly Kuznetsov @ 2021-11-16 16:34 UTC (permalink / raw)
  To: kvm, Paolo Bonzini
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, Eduardo Habkost,
	Marc Zyngier, Andrew Jones, Huacai Chen, Aleksandar Markovic,
	Anup Patel, Paul Mackerras, Michael Ellerman,
	Christian Borntraeger, Janosch Frank, kvm-ppc, linux-arm-kernel,
	linux-mips, kvm-riscv, linux-s390, linux-kernel

KVM_CAP_NR_VCPUS is a legacy advisory value which on other architectures
return num_online_cpus() caped by KVM_CAP_NR_VCPUS or something else
(ppc and arm64 are special cases). On s390, KVM_CAP_NR_VCPUS returns
the same as KVM_CAP_MAX_VCPUS and this may turn out to be a bad
'advice'. Switch s390 to returning caped num_online_cpus() too.

Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/s390/kvm/kvm-s390.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 6a6dd5e1daf6..1cfe36f6432e 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -585,6 +585,8 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 			r = KVM_MAX_VCPUS;
 		else if (sclp.has_esca && sclp.has_64bscao)
 			r = KVM_S390_ESCA_CPU_SLOTS;
+		if (ext == KVM_CAP_NR_VCPUS)
+			r = min_t(unsigned int, num_online_cpus(), r);
 		break;
 	case KVM_CAP_S390_COW:
 		r = MACHINE_HAS_ESOP;
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 6/6] KVM: x86: Drop arbitraty KVM_SOFT_MAX_VCPUS
  2021-11-16 16:34 [PATCH v2 0/6] KVM: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS and re-purpose it on x86 Vitaly Kuznetsov
                   ` (4 preceding siblings ...)
  2021-11-16 16:34 ` [PATCH v2 5/6] KVM: s390: Cap KVM_CAP_NR_VCPUS by num_online_cpus() Vitaly Kuznetsov
@ 2021-11-16 16:34 ` Vitaly Kuznetsov
  2021-11-17 12:12   ` Paolo Bonzini
  5 siblings, 1 reply; 12+ messages in thread
From: Vitaly Kuznetsov @ 2021-11-16 16:34 UTC (permalink / raw)
  To: kvm, Paolo Bonzini
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, Eduardo Habkost,
	Marc Zyngier, Andrew Jones, Huacai Chen, Aleksandar Markovic,
	Anup Patel, Paul Mackerras, Michael Ellerman,
	Christian Borntraeger, Janosch Frank, kvm-ppc, linux-arm-kernel,
	linux-mips, kvm-riscv, linux-s390, linux-kernel

KVM_CAP_NR_VCPUS is used to get the "recommended" maximum number of
VCPUs and arm64/mips/riscv report num_online_cpus(). Powerpc reports
either num_online_cpus() or num_present_cpus(), s390 has multiple
constants depending on hardware features. On x86, KVM reports an
arbitrary value of '710' which is supposed to be the maximum tested
value but it's possible to test all KVM_MAX_VCPUS even when there are
less physical CPUs available.

Drop the arbitrary '710' value and return num_online_cpus() on x86 as
well. The recommendation will match other architectures and will mean
'no CPU overcommit'.

For reference, QEMU only queries KVM_CAP_NR_VCPUS to print a warning
when the requested vCPU number exceeds it. The static limit of '710'
is quite weird as smaller systems with just a few physical CPUs should
certainly "recommend" less.

Suggested-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/x86/include/asm/kvm_host.h | 1 -
 arch/x86/kvm/x86.c              | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 88fce6ab4bbd..0232a00598f2 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -38,7 +38,6 @@
 #define __KVM_HAVE_ARCH_VCPU_DEBUGFS
 
 #define KVM_MAX_VCPUS 1024
-#define KVM_SOFT_MAX_VCPUS 710
 
 /*
  * In x86, the VCPU ID corresponds to the APIC ID, and APIC IDs
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index ac83d873d65b..18a00a7c23bc 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4137,7 +4137,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 		r = !static_call(kvm_x86_cpu_has_accelerated_tpr)();
 		break;
 	case KVM_CAP_NR_VCPUS:
-		r = KVM_SOFT_MAX_VCPUS;
+		r = min_t(unsigned int, num_online_cpus(), KVM_MAX_VCPUS);
 		break;
 	case KVM_CAP_MAX_VCPUS:
 		r = KVM_MAX_VCPUS;
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 4/6] KVM: RISC-V: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS
  2021-11-16 16:34 ` [PATCH v2 4/6] KVM: RISC-V: " Vitaly Kuznetsov
@ 2021-11-17  5:02   ` Anup Patel
  0 siblings, 0 replies; 12+ messages in thread
From: Anup Patel @ 2021-11-17  5:02 UTC (permalink / raw)
  To: Vitaly Kuznetsov
  Cc: KVM General, Paolo Bonzini, Sean Christopherson, Wanpeng Li,
	Jim Mattson, Eduardo Habkost, Marc Zyngier, Andrew Jones,
	Huacai Chen, Aleksandar Markovic, Anup Patel, Paul Mackerras,
	Michael Ellerman, Christian Borntraeger, Janosch Frank, kvm-ppc,
	linux-arm-kernel, linux-mips, kvm-riscv, linux-s390,
	linux-kernel@vger.kernel.org List

On Tue, Nov 16, 2021 at 10:05 PM Vitaly Kuznetsov <vkuznets@redhat.com> wrote:
>
> It doesn't make sense to return the recommended maximum number of
> vCPUs which exceeds the maximum possible number of vCPUs.
>
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>

Looks good to me.

For KVM RISC-V:
Acked-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>

Thanks,
Anup

> ---
>  arch/riscv/kvm/vm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kvm/vm.c b/arch/riscv/kvm/vm.c
> index 26399df15b63..fb18af34a4b5 100644
> --- a/arch/riscv/kvm/vm.c
> +++ b/arch/riscv/kvm/vm.c
> @@ -74,7 +74,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
>                 r = 1;
>                 break;
>         case KVM_CAP_NR_VCPUS:
> -               r = num_online_cpus();
> +               r = min_t(unsigned int, num_online_cpus(), KVM_MAX_VCPUS);
>                 break;
>         case KVM_CAP_MAX_VCPUS:
>                 r = KVM_MAX_VCPUS;
> --
> 2.33.1
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 5/6] KVM: s390: Cap KVM_CAP_NR_VCPUS by num_online_cpus()
  2021-11-16 16:34 ` [PATCH v2 5/6] KVM: s390: Cap KVM_CAP_NR_VCPUS by num_online_cpus() Vitaly Kuznetsov
@ 2021-11-17  7:33   ` Christian Borntraeger
  0 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2021-11-17  7:33 UTC (permalink / raw)
  To: Vitaly Kuznetsov, kvm, Paolo Bonzini
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, Eduardo Habkost,
	Marc Zyngier, Andrew Jones, Huacai Chen, Aleksandar Markovic,
	Anup Patel, Paul Mackerras, Michael Ellerman, Janosch Frank,
	kvm-ppc, linux-arm-kernel, linux-mips, kvm-riscv, linux-s390,
	linux-kernel

Am 16.11.21 um 17:34 schrieb Vitaly Kuznetsov:
> KVM_CAP_NR_VCPUS is a legacy advisory value which on other architectures
> return num_online_cpus() caped by KVM_CAP_NR_VCPUS or something else
> (ppc and arm64 are special cases). On s390, KVM_CAP_NR_VCPUS returns
> the same as KVM_CAP_MAX_VCPUS and this may turn out to be a bad
> 'advice'. Switch s390 to returning caped num_online_cpus() too.
> 
> Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>

you can also add
Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>

(yes I am changing my default address, but the other should continue to work)

> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>   arch/s390/kvm/kvm-s390.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
> index 6a6dd5e1daf6..1cfe36f6432e 100644
> --- a/arch/s390/kvm/kvm-s390.c
> +++ b/arch/s390/kvm/kvm-s390.c
> @@ -585,6 +585,8 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
>   			r = KVM_MAX_VCPUS;
>   		else if (sclp.has_esca && sclp.has_64bscao)
>   			r = KVM_S390_ESCA_CPU_SLOTS;
> +		if (ext == KVM_CAP_NR_VCPUS)
> +			r = min_t(unsigned int, num_online_cpus(), r);
>   		break;
>   	case KVM_CAP_S390_COW:
>   		r = MACHINE_HAS_ESOP;
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/6] KVM: arm64: Cap KVM_CAP_NR_VCPUS by kvm_arm_default_max_vcpus()
  2021-11-16 16:34 ` [PATCH v2 1/6] KVM: arm64: Cap KVM_CAP_NR_VCPUS by kvm_arm_default_max_vcpus() Vitaly Kuznetsov
@ 2021-11-17  9:13   ` Marc Zyngier
  2021-11-17 12:07   ` Paolo Bonzini
  1 sibling, 0 replies; 12+ messages in thread
From: Marc Zyngier @ 2021-11-17  9:13 UTC (permalink / raw)
  To: Vitaly Kuznetsov
  Cc: kvm, Paolo Bonzini, Sean Christopherson, Wanpeng Li, Jim Mattson,
	Eduardo Habkost, Andrew Jones, Huacai Chen, Aleksandar Markovic,
	Anup Patel, Paul Mackerras, Michael Ellerman,
	Christian Borntraeger, Janosch Frank, kvm-ppc, linux-arm-kernel,
	linux-mips, kvm-riscv, linux-s390, linux-kernel

On Tue, 16 Nov 2021 16:34:38 +0000,
Vitaly Kuznetsov <vkuznets@redhat.com> wrote:
> 
> Generally, it doesn't make sense to return the recommended maximum number
> of vCPUs which exceeds the maximum possible number of vCPUs.
> 
> Note: ARM64 is special as the value returned by KVM_CAP_MAX_VCPUS differs
> depending on whether it is a system-wide ioctl or a per-VM one. Previously,
> KVM_CAP_NR_VCPUS didn't have this difference and it seems preferable to
> keep the status quo. Cap KVM_CAP_NR_VCPUS by kvm_arm_default_max_vcpus()
> which is what gets returned by system-wide KVM_CAP_MAX_VCPUS.
> 
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>

Acked-by: Marc Zyngier <maz@kernel.org>

	M.

-- 
Without deviation from the norm, progress is not possible.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/6] KVM: arm64: Cap KVM_CAP_NR_VCPUS by kvm_arm_default_max_vcpus()
  2021-11-16 16:34 ` [PATCH v2 1/6] KVM: arm64: Cap KVM_CAP_NR_VCPUS by kvm_arm_default_max_vcpus() Vitaly Kuznetsov
  2021-11-17  9:13   ` Marc Zyngier
@ 2021-11-17 12:07   ` Paolo Bonzini
  1 sibling, 0 replies; 12+ messages in thread
From: Paolo Bonzini @ 2021-11-17 12:07 UTC (permalink / raw)
  To: Vitaly Kuznetsov, kvm
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, Eduardo Habkost,
	Marc Zyngier, Andrew Jones, Huacai Chen, Aleksandar Markovic,
	Anup Patel, Paul Mackerras, Michael Ellerman,
	Christian Borntraeger, Janosch Frank, kvm-ppc, linux-arm-kernel,
	linux-mips, kvm-riscv, linux-s390, linux-kernel

On 11/16/21 17:34, Vitaly Kuznetsov wrote:
> -		r = num_online_cpus();
> +		/*
> +		 * ARM64 treats KVM_CAP_NR_CPUS differently from all other
> +		 * architectures, as it does not always bound it to
> +		 * num_online_cpus(). It should not matter much because this
                   ^^^^^^^^^^^^^^^^^^

KVM_CAP_MAX_VCPUS (sorry for the typo in my suggestion).  I'll fix it 
when applying.

Paolo

> +		 * is just an advisory value.
> +		 */
> +		r = min_t(unsigned int, num_online_cpus(),
> +			  kvm_arm_default_max_vcpus());


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 6/6] KVM: x86: Drop arbitraty KVM_SOFT_MAX_VCPUS
  2021-11-16 16:34 ` [PATCH v2 6/6] KVM: x86: Drop arbitraty KVM_SOFT_MAX_VCPUS Vitaly Kuznetsov
@ 2021-11-17 12:12   ` Paolo Bonzini
  0 siblings, 0 replies; 12+ messages in thread
From: Paolo Bonzini @ 2021-11-17 12:12 UTC (permalink / raw)
  To: Vitaly Kuznetsov, kvm
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, Eduardo Habkost,
	Marc Zyngier, Andrew Jones, Huacai Chen, Aleksandar Markovic,
	Anup Patel, Paul Mackerras, Michael Ellerman,
	Christian Borntraeger, Janosch Frank, kvm-ppc, linux-arm-kernel,
	linux-mips, kvm-riscv, linux-s390, linux-kernel

On 11/16/21 17:34, Vitaly Kuznetsov wrote:
> KVM_CAP_NR_VCPUS is used to get the "recommended" maximum number of
> VCPUs and arm64/mips/riscv report num_online_cpus(). Powerpc reports
> either num_online_cpus() or num_present_cpus(), s390 has multiple
> constants depending on hardware features. On x86, KVM reports an
> arbitrary value of '710' which is supposed to be the maximum tested
> value but it's possible to test all KVM_MAX_VCPUS even when there are
> less physical CPUs available.
> 
> Drop the arbitrary '710' value and return num_online_cpus() on x86 as
> well. The recommendation will match other architectures and will mean
> 'no CPU overcommit'.
> 
> For reference, QEMU only queries KVM_CAP_NR_VCPUS to print a warning
> when the requested vCPU number exceeds it. The static limit of '710'
> is quite weird as smaller systems with just a few physical CPUs should
> certainly "recommend" less.
> 
> Suggested-by: Eduardo Habkost<ehabkost@redhat.com>
> Signed-off-by: Vitaly Kuznetsov<vkuznets@redhat.com>

Given that KVM_SOFT_MAX_VCPUS has already been dropped in 5.16, I 
changed the commit message to

     KVM: x86: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS

     It doesn't make sense to return the recommended maximum number of
     vCPUs which exceeds the maximum possible number of vCPUs.

Paolo


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-11-17 12:12 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-16 16:34 [PATCH v2 0/6] KVM: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS and re-purpose it on x86 Vitaly Kuznetsov
2021-11-16 16:34 ` [PATCH v2 1/6] KVM: arm64: Cap KVM_CAP_NR_VCPUS by kvm_arm_default_max_vcpus() Vitaly Kuznetsov
2021-11-17  9:13   ` Marc Zyngier
2021-11-17 12:07   ` Paolo Bonzini
2021-11-16 16:34 ` [PATCH v2 2/6] KVM: MIPS: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS Vitaly Kuznetsov
2021-11-16 16:34 ` [PATCH v2 3/6] KVM: PPC: " Vitaly Kuznetsov
2021-11-16 16:34 ` [PATCH v2 4/6] KVM: RISC-V: " Vitaly Kuznetsov
2021-11-17  5:02   ` Anup Patel
2021-11-16 16:34 ` [PATCH v2 5/6] KVM: s390: Cap KVM_CAP_NR_VCPUS by num_online_cpus() Vitaly Kuznetsov
2021-11-17  7:33   ` Christian Borntraeger
2021-11-16 16:34 ` [PATCH v2 6/6] KVM: x86: Drop arbitraty KVM_SOFT_MAX_VCPUS Vitaly Kuznetsov
2021-11-17 12:12   ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).