Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp222882iob; Mon, 2 May 2022 17:41:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJze2xxX1Qehi0ZTDLDpsEWRnT1Vq85QBdNnV31GPUk+MzzjoAdVd2rKUt7cFjqE7qW3o06T X-Received: by 2002:a17:90b:4b01:b0:1dc:7405:dd62 with SMTP id lx1-20020a17090b4b0100b001dc7405dd62mr2005117pjb.160.1651538497828; Mon, 02 May 2022 17:41:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651538497; cv=none; d=google.com; s=arc-20160816; b=Hx8RiEpw7oiYRK52T3Dt2Qa0QNy7oEHkB0q6xok95FGJvG8rOCJxb/LHISDK2Lp64Q HFq3/+Shox817vQ0xcdR5c0mtpqWzlsmQtf3P/JC4nqDxhqZNupY3Ifp+PysVFdTYs05 ZzBngZhihXrKNVNtRC72R+FcvYESXC1fEwwDLVLGKEIy74wZ0hPJosM7XduN3Rop6cqh Mp2gFm2gl+C1MHuCbmYCzNPzJiaLb7qtML0ZiGUp7sxko0DSvC7ZNFbU4Yaq/NV0wRPb ijnrWAYe4sKLrmn27E6O1ARWjt1xV7wse6rBN/l42k9dm93ZX6WkMnhByp4+bj26UmTQ bnag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=s70MT6Y6b+EWzPq4TYtvjBhW+c7gKt8WCUmst+yWMcA=; b=OzFS+rpFFxvoe9MQ4dEtnM1LqPw52m9GxTjB2bFeqWqlyT3HlDIWLkqCa4aa17GS/L ZRoDc6i42vyISBLriRBHX7VQowXW4OiJ+9wzlZuiL3vm/r1PXhEak5khwX5OFNMYZt8V YNZj0CwaKqrOW4DgXGuUxhwsIsSYV9uZVsEn98Upj8wLpdmxOhrgX3plj2NuYEFo4A1O GPT3vSQExv8rHcN9xGXY1mWq3LsGjbVp96ZYqJ4LW0UiOwytRpIcQK6d2dyuhPqkVM+v LwymgG42l9PCDIDPiIlH4FyhBqwQg7X6CixJHN37vbZIlj8TFDpRSY3Bd0B+bxcaiPe4 N0WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NOoPok6F; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id i34-20020a635422000000b003ab9d94aaccsi15020266pgb.328.2022.05.02.17.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 17:41:37 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NOoPok6F; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 689643B298; Mon, 2 May 2022 17:31:53 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234025AbiEBQKt (ORCPT + 99 others); Mon, 2 May 2022 12:10:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240854AbiEBQKr (ORCPT ); Mon, 2 May 2022 12:10:47 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8E49EDE95 for ; Mon, 2 May 2022 09:07:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651507636; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s70MT6Y6b+EWzPq4TYtvjBhW+c7gKt8WCUmst+yWMcA=; b=NOoPok6F3YLUvVYVKt0qwJG6RoU5PWdXFGSPb9ePPBDnF6dxQn3TlXsrV4i0w/NbtB6mG6 +OHYXJTom6VrDI5UcXv0MxtAklLUkuXb6tgcBc3hFOe1xuxBvuh6eq80E3f76Cz0ieGcGQ +Raf/RLlEpAe0C5hcIlJSERBXN0UnZI= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-86-XKnsIJCBPLGUprwFo3Bohg-1; Mon, 02 May 2022 12:07:15 -0400 X-MC-Unique: XKnsIJCBPLGUprwFo3Bohg-1 Received: by mail-ej1-f71.google.com with SMTP id cw19-20020a170906479300b006f3e54b1dbcso4951204ejc.4 for ; Mon, 02 May 2022 09:07:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=s70MT6Y6b+EWzPq4TYtvjBhW+c7gKt8WCUmst+yWMcA=; b=qXGRC+Y/RdSA97IPrU6G1JKxZLy3ZWjUcPFVAUQ7SUG+W8o+dsUiCDd8nwToDp4gF+ p4cPJ2HADe8lnNYm/jiyHOonPjT2DW39Jrmrbq+lNcKh2UnMaM9VjKQn/AA0x+5gtoP5 mH39oTT7g+J0T8hdFBFPAkZxJBKUNuHWoRvD5KuQbBmhMYcGQW7xHAPE+Cshto2Plot+ 1+x5sUAV70MepUjV7TT25W3RBA1ApIYHJBaisW5hVA9C6KbL5iOebAOAl5VVQ0hNYtzf wmtYb4dW++RM6PeudlV6hBvk2ktuLwqbo0Hq+kjydI6bpgLtQ2djIf1iOomncyU1gb5r +tmA== X-Gm-Message-State: AOAM532Zc535wyI6+nQYemDJpR0eFhKRA4ntNNqyGcN/F5MGCcKAQZB6 E3bwlNWpYNnS/iWdssEcxXFNOKueiIlQbnMN5HtfRG71XpSOCVCqHnfu3JF3l3rUEs3r4v2eXlM 2PC0qxiU4lgyQZ5KQj1dC4g5j X-Received: by 2002:a17:907:72d4:b0:6f4:7b2:1dea with SMTP id du20-20020a17090772d400b006f407b21deamr12049351ejc.532.1651507634255; Mon, 02 May 2022 09:07:14 -0700 (PDT) X-Received: by 2002:a17:907:72d4:b0:6f4:7b2:1dea with SMTP id du20-20020a17090772d400b006f407b21deamr12049334ejc.532.1651507634023; Mon, 02 May 2022 09:07:14 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.googlemail.com with ESMTPSA id zp1-20020a17090684e100b006f3ef214df0sm3710399ejb.86.2022.05.02.09.07.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 02 May 2022 09:07:13 -0700 (PDT) Message-ID: Date: Mon, 2 May 2022 18:07:11 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH v9 8/9] KVM: x86: Allow userspace set maximum VCPU id for VM Content-Language: en-US To: Zeng Guang , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, Dave Hansen , Tony Luck , Kan Liang , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Kim Phillips , Jarkko Sakkinen , Jethro Beekman , Kai Huang Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Robert Hu , Gao Chao References: <20220419154444.11888-1-guang.zeng@intel.com> From: Paolo Bonzini In-Reply-To: <20220419154444.11888-1-guang.zeng@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/19/22 17:44, Zeng Guang wrote: > +Userspace is able to calculate the limit to APIC ID values from designated CPU > +topology. This capability allows userspace to specify maximum possible APIC ID > +assigned for current VM session prior to the creation of vCPUs. By design, it > +can set only once and doesn't accept change any more. KVM will manage memory > +allocation of VM-scope structures which depends on the value of APIC ID. > + > +Calling KVM_CHECK_EXTENSION for this capability returns the value of maximum APIC > +ID that KVM supports at runtime. It sets as KVM_MAX_VCPU_IDS by default. Better: This capability allows userspace to specify maximum possible APIC ID assigned for current VM session prior to the creation of vCPUs, saving memory for data structures indexed by the APIC ID. Userspace is able to calculate the limit to APIC ID values from designated CPU topology. The value can be changed only until KVM_ENABLE_CAP is set to a nonzero value or until a vCPU is created. Upon creation of the first vCPU, if the value was set to zero or KVM_ENABLE_CAP was not invoked, KVM uses the return value of KVM_CHECK_EXTENSION(KVM_CAP_MAX_VCPU_ID) as the maximum APIC ID. > case KVM_CAP_MAX_VCPU_ID: > - r = KVM_MAX_VCPU_IDS; > + if (!kvm->arch.max_vcpu_ids) > + r = KVM_MAX_VCPU_IDS; > + else > + r = kvm->arch.max_vcpu_ids; I think returning the constant KVM_CAP_MAX_VCPU_IDS is better. Paolo