Skip to contentSkip to conversation

LoongArch: KVM: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS

PATCH Superseded Qiang Ma 2 participants 3 messages Apr 28

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Qiang Ma

author
#0 lore raw

PATCH 1/1 LoongArch: KVM: 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.

Other architectures have already done this, such as Commit 57a2e13ebdda ("KVM: MIPS: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS")

Fixes 482795cb62aa ("LoongArch: KVM: Implement VM related functions")
---
 arch/loongarch/kvm/vm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/loongarch/kvm/vm.c +1 -1
index 8cc5ee1c53ef..1317c718f896 100644
@@ -125,7 +125,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;
Signature · 1 line
2.20.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Qiang Ma

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

Other architectures have already done this, such as Commit 57a2e13ebdda ("KVM: MIPS: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS")

Fixes 482795cb62aa ("LoongArch: KVM: Implement VM related functions")
---
  arch/loongarch/kvm/vm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/loongarch/kvm/vm.c +0 -0
index 8cc5ee1c53ef..1317c718f896 100644

arch/loongarch/kvm/vm.c int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) · line 131

Quoted 8 lines
arch/loongarch/kvm/vm.c +1 -1
@@ -125,7 +125,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;

Hi Qiang,

yes, this is better.

Though value of CONFIG_NR_CPUS is 2048, currently max CPU number of host hardware is 256 still because of limitation of AVEC and extioi HW irqchip.

If there is HW machine in future which supports more than 256 CPUs, the max online CPU is no more than 256 with existing kernel version. So I think that the "Fixes" tag is not necessary.

author
#2 lore raw
Quoted 33 lines · Bibo Mao
Quoted 21 lines · Qiang Ma

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

Other architectures have already done this, such as Commit 57a2e13ebdda ("KVM: MIPS: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS")

Fixes 482795cb62aa ("LoongArch: KVM: Implement VM related functions")

---
  arch/loongarch/kvm/vm.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
arch/loongarch/kvm/vm.c +0 -0
index 8cc5ee1c53ef..1317c718f896 100644
@@ -125,7 +125,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, 
 long ext)
           r = 1;
           break;
Quoted 7 lines

      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;

Hi Qiang,

Quoted 5 lines

yes, this is better.

Though value of CONFIG_NR_CPUS is 2048, currently max CPU number of host hardware is 256 still because of limitation of AVEC and extioi HW irqchip.

If there is HW machine in future which supports more than 256 CPUs, the max online CPU is no more than 256 with existing kernel version. So I think that the "Fixes" tag is not necessary.

That makes sense. Let's remove the "Fixes" tag and send out the v2 version.

Quoted 4 lines