Re: [PATCH v2] LoongArch: KVM: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS

From: Huacai Chen

Date: Wed Apr 29 2026 - 05:51:42 EST


On Tue, Apr 28, 2026 at 8:59 PM Bibo Mao <maobibo@xxxxxxxxxxx> 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@xxxxxxxxxxxxx>
> > ---
> > 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@xxxxxxxxxxx>
Applied, thanks.

Huacai
>