Skip to contentSkip to conversation

LoongArch: KVM: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS

PATCH Applied Qiang Ma 3 participants 3 messages Apr 28 – Apr 29

Subsystems (3)
lore
Share & tools
lore

Qiang Ma

author
#0 lore raw

PATCH v2 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")

---
 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 v2 1/1
#1 lore raw
Quoted 17 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")

---
  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;
maintainer Applied
#2 lore raw
Quoted 13 lines · Bibo Mao
Quoted 11 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")

---
  arch/loongarch/kvm/vm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
Quoted 6 lines
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;

Applied, thanks.

Huacai

Quoted 1 line