Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp560848rwb; Thu, 12 Jan 2023 09:19:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXsijLWASZA7v4we+0YIs0p1ZRuq6cA543gEpzw5bS+fL5O39X/mhemme2ItGE6EZyMYqywe X-Received: by 2002:aa7:da0e:0:b0:49b:58ca:ebbc with SMTP id r14-20020aa7da0e000000b0049b58caebbcmr2887696eds.32.1673543981751; Thu, 12 Jan 2023 09:19:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673543981; cv=none; d=google.com; s=arc-20160816; b=vXgHGBl28qo6L0tpv1Hb/bJEfYc8SglUQFKwmn4m6OH9DCZy3MAxMzG9Sj824SC+pO y/kpdMpgJcKxQTeG2OUvMEo5yb22Ikxfx2ps3yBvkHaCtDsnWJbGScVnWu+2ZsNINHGh 5iNNVdS7sLCKXSczDxmz7rYQoPcfv9Kg0XiX0gV3clKnjLAlNBmUiaqwZykjMqHPWUJ1 0Ce4JI3f49H3fxOcqkAK483460ufsCleWHxcwEKtcSA5WrKdcAYmaaxDSGyD/Hi8qurc goCvAufcgbx/qm5FeOOhcs4F9vpiBXTCmhmTx+9B+HaojoLdqmKtVgEq5MX738liL3Ru /aYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Z1Vuofy0D4AG+mHk6d3G/UqeP0uiPoLA6gjwUJrwiwQ=; b=fHEz6N8dr9FjvhChbF5bvFycEM/tbhhfr4k+hFyMv5VUAi316gaK/V+ValU3WFc6Ya 1kBzv8qhsqYM8BBXPzjhAF2Whw09jRkqPOB0VtuyWAB7tAzRpKmLEgYxhfXqxLUvzTMr 27cetf/yOh1wRL42TcnHy2oAzhwYhu6Sn+dyxKodqC1acmEOcqi4vsP9AgVxLMKcZeU1 WNs96lfpdENi+PIUeI/euG48SN+YHCqRfHqswQadJY47cY6MfINoQFqQ3QPDZya8cG+h vmSbNdJdU/8Y4YeqmyFECMTDVa1CFgTcTjgEDQfJjpMIMzSePkUEjVXWK8CneaLy9i1w iSXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cQf8xKSd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z7-20020a50eb47000000b00483347f1b8esi17545260edp.402.2023.01.12.09.19.29; Thu, 12 Jan 2023 09:19:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cQf8xKSd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240883AbjALQnm (ORCPT + 50 others); Thu, 12 Jan 2023 11:43:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239713AbjALQhg (ORCPT ); Thu, 12 Jan 2023 11:37:36 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0008C15FC3; Thu, 12 Jan 2023 08:33:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673541234; x=1705077234; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dqYEULkH/OZWopqWd2YjxrOh4qpDuxImjqn9TYIIMZY=; b=cQf8xKSdZBBDBQqZiDYXjiku8AIGjW/wqnZicg44Gx5V9D38zXuJFnCy 03cAjI6c9cnV/gUB1mzs1nWEIvw1XoOe8DPXP8iKN+LEJwWG/Ws8fDhfA z43u0pxrTmnunYJB5WfqKU+l2DtLu9wFxQz8SqZh2YWiYJMFLY+jNzNg+ aPXcINNjefjfpLb7pPPz1Nbg3DN6cQqqPMTo0UI4jjpaT5iqMBXn+TiN4 ItigkvQkqsa8O2L4w4i27sjAZouQzy9kKGec8kQQatPmYXxYYzqmwo+DX Um6VAOTGgJRmh1hBj/yQFoQycotMuNW+VSa6pigUS/QSGYHTGWUpIusS+ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="323811724" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="323811724" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:22 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="721151680" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="721151680" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:22 -0800 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack Subject: [PATCH v11 017/113] KVM: Support KVM_CAP_MAX_VCPUS for KVM_ENABLE_CAP Date: Thu, 12 Jan 2023 08:31:25 -0800 Message-Id: <01e061779b88ce4d32bbe483ed2bd3224cd8e330.1673539699.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham 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 From: Isaku Yamahata TDX attestation includes the maximum number of vcpu that the guest can accommodate. For that, the maximum number of vcpu needs to be specified instead of constant, KVM_MAX_VCPUS. Make KVM_ENABLE_CAP support KVM_CAP_MAX_VCPUS. Suggested-by: Sagi Shahar Signed-off-by: Isaku Yamahata --- virt/kvm/kvm_main.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index a235b628b32f..1cfa7da92ad0 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -4945,7 +4945,27 @@ static int kvm_vm_ioctl_enable_cap_generic(struct kvm *kvm, } mutex_unlock(&kvm->slots_lock); + return r; + } + case KVM_CAP_MAX_VCPUS: { + int r; + if (cap->flags || cap->args[0] == 0) + return -EINVAL; + if (cap->args[0] > kvm_vm_ioctl_check_extension(kvm, KVM_CAP_MAX_VCPUS)) + return -E2BIG; + + mutex_lock(&kvm->lock); + /* Only decreasing is allowed. */ + if (cap->args[0] > kvm->max_vcpus) + r = -E2BIG; + else if (kvm->created_vcpus) + r = -EBUSY; + else { + kvm->max_vcpus = cap->args[0]; + r = 0; + } + mutex_unlock(&kvm->lock); return r; } default: -- 2.25.1