arch/loongarch/kvm/vm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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")
Signed-off-by: Qiang Ma <maqianga@uniontech.com>
---
arch/loongarch/kvm/vm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/loongarch/kvm/vm.c b/arch/loongarch/kvm/vm.c
index 8cc5ee1c53ef..1317c718f896 100644
--- a/arch/loongarch/kvm/vm.c
+++ b/arch/loongarch/kvm/vm.c
@@ -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;
--
2.20.1
On 2026/4/28 下午8:18, Qiang Ma wrote:
> 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")
>
> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
> ---
> arch/loongarch/kvm/vm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/loongarch/kvm/vm.c b/arch/loongarch/kvm/vm.c
> index 8cc5ee1c53ef..1317c718f896 100644
> --- a/arch/loongarch/kvm/vm.c
> +++ b/arch/loongarch/kvm/vm.c
> @@ -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;
>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
On Tue, Apr 28, 2026 at 8:59 PM Bibo Mao <maobibo@loongson.cn> wrote:
>
> On 2026/4/28 下午8:18, Qiang Ma wrote:
> > 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")
> >
> > Signed-off-by: Qiang Ma <maqianga@uniontech.com>
> > ---
> > arch/loongarch/kvm/vm.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/loongarch/kvm/vm.c b/arch/loongarch/kvm/vm.c
> > index 8cc5ee1c53ef..1317c718f896 100644
> > --- a/arch/loongarch/kvm/vm.c
> > +++ b/arch/loongarch/kvm/vm.c
> > @@ -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;
> >
> Reviewed-by: Bibo Mao <maobibo@loongson.cn>
Applied, thanks.
Huacai
>
© 2016 - 2026 Red Hat, Inc.