diff mbox series

[v2,1/6] KVM: arm64: Cap KVM_CAP_NR_VCPUS by kvm_arm_default_max_vcpus()

Message ID 20211116163443.88707-2-vkuznets@redhat.com (mailing list archive)
State Not Applicable
Headers show
Series KVM: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS and re-purpose it on x86 | expand

Commit Message

Vitaly Kuznetsov Nov. 16, 2021, 4:34 p.m. UTC
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(-)

Comments

Marc Zyngier Nov. 17, 2021, 9:13 a.m. UTC | #1
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.
Paolo Bonzini Nov. 17, 2021, 12:07 p.m. UTC | #2
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());
diff mbox series

Patch

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: