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 93984C433FE for ; Fri, 12 Nov 2021 09:51:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D5A060F51 for ; Fri, 12 Nov 2021 09:51:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234827AbhKLJyL (ORCPT ); Fri, 12 Nov 2021 04:54:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:56464 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234793AbhKLJyK (ORCPT ); Fri, 12 Nov 2021 04:54:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636710679; 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=Q3tNE6PVDp1t883O718wrcDgXu0HBWeQVivnEf04yl8=; b=RkO3qVub/Trsy4BlS9rHaB1lpRaw7zBkJbbB8wb7OJVsi7FSN2IAu1qTQRVwDxKnCEYBEr Z4bZY6LxqGIHdWnRNwGp1oMIUrmnuUlaD2rYAoCiCHHowtkpfIWZojrYfVYIm/UD4GBCId FgB/XfwUoyJQkALDpUgsbnFKrmIVlIw= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-181-FtreiHwyM8yqtIqBQrQrhw-1; Fri, 12 Nov 2021 04:51:14 -0500 X-MC-Unique: FtreiHwyM8yqtIqBQrQrhw-1 Received: by mail-ed1-f69.google.com with SMTP id f4-20020a50e084000000b003db585bc274so7754091edl.17 for ; Fri, 12 Nov 2021 01:51:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=Q3tNE6PVDp1t883O718wrcDgXu0HBWeQVivnEf04yl8=; b=GRcOwpLZ4CWu557wwTOk6aC3izhiI5hrKwsCwHayUzQW+/8zIChGxczb50vgIojHVQ tadk8gbLI9Gd464GE/4V7bvBZ5W9PAJztgyddA5tKG1WDLBkKvfrq+TnvfgSK926JzQ9 iUMaaGWlbsTlJwyiZFHL64LTM7Qg1MHfmrQyKmPe9omCUHWgXsNoYWeHHfjmut0hWVhL I5DBt3DxbwSJeQIM/GPC2ADsCoOWVqP68uVKGays04VDuzz6dS8WpMbj5lWz5qJpfiT9 LDo3YaUvmy+cC8Qisj3tILt/VRPRh9UsbQTIvOW9Bo6VHa6n4znw8W6arZbN8ROfE2e9 4IqA== X-Gm-Message-State: AOAM532FxPA12XfyKObw0sbntL7HKXAf9DtbSp4JJfpHwFRmVNIg0op8 T6gQLe0fPy22F+Ng++TKkAIBHBJvma/G1da+ncwJuecM9EZ4icMk3Y0Lhv63PiZCbc6R6onC3UG ptwwvbY0XNnOKs2OOApX4n2s0iLCGSiqvSKItr4uq060m1NdnoOYgkSNL6OwBrlTQjvm3K3ZPRL /h X-Received: by 2002:a05:6402:27d3:: with SMTP id c19mr19433495ede.2.1636710672898; Fri, 12 Nov 2021 01:51:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzLDjahuFseIZ7e+RowWVF5yMybji+/f1TpttlCU7zwauHRgLTGqMPciQsWHxQYl16h4+En2Q== X-Received: by 2002:a05:6402:27d3:: with SMTP id c19mr19433437ede.2.1636710672630; Fri, 12 Nov 2021 01:51:12 -0800 (PST) Received: from fedora (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id q14sm2845328edj.42.2021.11.12.01.51.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Nov 2021 01:51:12 -0800 (PST) From: Vitaly Kuznetsov To: Marc Zyngier Cc: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Wanpeng Li , Jim Mattson , Eduardo Habkost , Andrew Jones , 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 In-Reply-To: References: <20211111162746.100598-1-vkuznets@redhat.com> <20211111162746.100598-2-vkuznets@redhat.com> Date: Fri, 12 Nov 2021 10:51:10 +0100 Message-ID: <875ysxg0s1.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > 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? Thanks for the feedback! -- Vitaly