Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 637C4C433EF for ; Fri, 12 Nov 2021 10:39:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 40BDE60F70 for ; Fri, 12 Nov 2021 10:39:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234632AbhKLKlv (ORCPT ); Fri, 12 Nov 2021 05:41:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:33098 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231173AbhKLKlu (ORCPT ); Fri, 12 Nov 2021 05:41:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636713539; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=46oPanpNXibKa0tnHojCAVl1G+VIp/9kz1W1tOMUA/o=; b=M0+67PBx+32MkJT9SZ3mlGbApiNbQxG9CWOp69DkB4WXIjUctSt0SXIeMlLPdA3gWNAWvV QqloyOsOn0stHgkwsqOs+S+c0+Sb/cu3GzjiZPgHgT0Dyhxz/EN1f/aMoyH3aAfRUQdaGz tC4t8UXWEah8hQxBBplySiGMLEhvqzs= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-293-178sGGojOZyk9nD70X5FCg-1; Fri, 12 Nov 2021 05:38:56 -0500 X-MC-Unique: 178sGGojOZyk9nD70X5FCg-1 Received: by mail-ed1-f71.google.com with SMTP id x13-20020a05640226cd00b003e2bf805a02so7851711edd.23 for ; Fri, 12 Nov 2021 02:38:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=46oPanpNXibKa0tnHojCAVl1G+VIp/9kz1W1tOMUA/o=; b=UnETtZ3MWh1IF2i2anMIcVAjjyDBPuLN2R3OBvFz2uok1XcMIBhGYHI7bCovzCyN1s BzPWLaaEtxeTC315XPPy92kfLHVyRS2b3J3o6UEf7bCCPfLp7J055WzWL6KsXH4cuI1n Y+LH/t+LJNiHTDhQI5pOiED8rkViLi7m05fp1jNnzzbq7vq9FuojQByZEWJ9U/gQPZ53 0v0No/okLuTgzKqFD1/7ULi9P5nT/YNvwOGQtGpw93e2k1m8gwlewjds6vhhudhv4Rem FdDLWrmdwNADC2EdlVDO7Ql3rjPb/hjqxKoitEce4SAIJQEJF+4Zs+pa+hgsuKYoBUyu Be7A== X-Gm-Message-State: AOAM531+gL0ouYNo+75PKgtdyCOHnHh8mXrOM4GEBRD/xgI+Yd2/zRBx ScGtx+KXxfw6cLX06/AxAWjFriOs7zxlTRDJ5E26lh0KN1MLB3abUvdyJcXXBNj6co/dB1ZWnaV KhzSqPzjF3ikx6MD/Cc9X58dX X-Received: by 2002:aa7:d941:: with SMTP id l1mr11835619eds.85.1636713535287; Fri, 12 Nov 2021 02:38:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJw9layiD+6Vv4+AU3/Qy6m1v3qARXE9JoqZtCdClcHuoufFeEjkx3MDLgO30N9JpFidH7eEUw== X-Received: by 2002:aa7:d941:: with SMTP id l1mr11835576eds.85.1636713535102; Fri, 12 Nov 2021 02:38:55 -0800 (PST) Received: from gator.home (cst-prg-92-133.cust.vodafone.cz. [46.135.92.133]) by smtp.gmail.com with ESMTPSA id a15sm2912187edr.76.2021.11.12.02.38.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Nov 2021 02:38:54 -0800 (PST) Date: Fri, 12 Nov 2021 11:38:51 +0100 From: Andrew Jones To: Vitaly Kuznetsov Cc: Marc Zyngier , kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Wanpeng Li , Jim Mattson , Eduardo Habkost , Huacai Chen , Aleksandar Markovic , Anup Patel , Paul Mackerras , Michael Ellerman , kvm-ppc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/5] KVM: arm64: Cap KVM_CAP_NR_VCPUS by KVM_CAP_MAX_VCPUS Message-ID: <20211112103851.pmb35qf5bvcukjmg@gator.home> References: <20211111162746.100598-1-vkuznets@redhat.com> <20211111162746.100598-2-vkuznets@redhat.com> <875ysxg0s1.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <875ysxg0s1.fsf@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 12, 2021 at 10:51:10AM +0100, Vitaly Kuznetsov wrote: > Marc Zyngier writes: > > > Hi Vitaly, > > > > On 2021-11-11 16:27, Vitaly Kuznetsov wrote: > >> It doesn't make sense to return the recommended maximum number of > >> vCPUs which exceeds the maximum possible number of vCPUs. > >> > >> Signed-off-by: Vitaly Kuznetsov > >> --- > >> arch/arm64/kvm/arm.c | 7 ++++++- > >> 1 file changed, 6 insertions(+), 1 deletion(-) > >> > >> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > >> index 7838e9fb693e..391dc7a921d5 100644 > >> --- a/arch/arm64/kvm/arm.c > >> +++ b/arch/arm64/kvm/arm.c > >> @@ -223,7 +223,12 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, > >> long ext) > >> r = 1; > >> break; > >> case KVM_CAP_NR_VCPUS: > >> - r = num_online_cpus(); > >> + if (kvm) > >> + r = min_t(unsigned int, num_online_cpus(), > >> + kvm->arch.max_vcpus); > >> + else > >> + 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: > > > > This looks odd. This means that depending on the phase userspace is > > in while initialising the VM, KVM_CAP_NR_VCPUS can return one thing > > or the other. > > > > For example, I create a VM on a 32 CPU system, NR_VCPUS says 32. > > I create a GICv2 interrupt controller, it now says 8. > > > > That's a change in behaviour that is visible by userspace > > Yes, I realize this is a userspace visible change. The reason I suggest > it is that logically, it seems very odd that the maximum recommended > number of vCPUs (KVM_CAP_NR_VCPUS) can be higher, than the maximum > supported number of vCPUs (KVM_CAP_MAX_VCPUS). All userspaces which use > this information somehow should already contain some workaround for this > case. (maybe it's a rare one and nobody hit it yet or maybe there are no > userspaces using KVM_CAP_NR_VCPUS for anything besides complaining -- > like QEMU). > > I'd like KVM to be consistent across architectures and have the same > (similar) meaning for KVM_CAP_NR_VCPUS. KVM_CAP_NR_VCPUS seems pretty useless if we just want to tell userspace the same thing it can get with _SC_NPROCESSORS_ONLN. In fact, if userspace knows something we don't about the future onlining of some pcpus, then maybe userspace would prefer to check _SC_NPROCESSORS_CONF. > > > which I'm keen on avoiding. I'd rather have the kvm and !kvm cases > > return the same thing. > > Forgive me my (ARM?) ignorance but what would it be then? If we go for > min(num_online_cpus(), kvm_arm_default_max_vcpus()) in both cases, cat > this can still go above KVM_CAP_MAX_VCPUS after vGIC is created? So the GIC version case looks like the type of thing that could make KVM_CAP_NR_VCPUS useful, i.e. being able to tell userspace a maximum number of vcpus supported for a given configuration. However, even in that case the concept of "recommended" number doesn't make sense, because, for the GICv2 example, a VM cannot configure more than 8 VCPUs, so it's a real limit, not a recommendation. Maybe KVM_CAP_NR_VCPUS should just be left alone, but deprecated, and, if there's need, a new CAP could be created for a config-vcpu-max. Thanks, drew