From patchwork Sun Oct 30 06:22:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 12845 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1665701wru; Sat, 29 Oct 2022 23:27:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4veyeWOBAJwiOojo8xYv397hAhO/+/Tpvdg+tW7TCfUuW+xMPKSnEXYiGCMsEbNpVhVi7k X-Received: by 2002:a17:907:6e1a:b0:7ad:ba0b:538c with SMTP id sd26-20020a1709076e1a00b007adba0b538cmr3631826ejc.111.1667111221172; Sat, 29 Oct 2022 23:27:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667111221; cv=none; d=google.com; s=arc-20160816; b=0N5i+7GqEA6gTQjb4+QtbQdzhVuDhv7PHjJ3CwijFe8kL3cLUow96vKrRklLmpCVOb A+Av0KX1dFBgHmx92X2g3P/Y08levIx8F4UsD9EgHCV3396vy3gj/lLLKmUp7rKGv3sp ocnArymRhjT0FOIVI/MRRpcWx3MnseqHuMiIndjecn7hsXBUSSjJ4ddtM9Ki+Kxh0sFq UAlDXn3gavn+Kv2WbtfgWExwWJ/WDxhFT6AScMN6A89XpsCIfX4JLIxRAC5CcC1N7/uz 45ApKN8WXG4JMbjX80JE/drZSY4vj5ZSdgXuJAi3gv0lUwbESiOpLgcfT6/Jp4W1q1l9 bT0g== 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=qzTr3NdQov4sMJWKch2uHRZu/nSWnCpkdRYhqz5JPhg=; b=T3NFZdoJuHgEP6w7PxiUThqczr5IGZPENDeiwSMWmErGz+TQT4M6RJa2IKOC/GRpwq jwNKwx7IYfp99ORWFzS+tso032ZdyJmVh/tCTLfT+q9e/jfbn0YTLgn+7uW0WRqFNQGv J77BSd3Kr5fcP1Qmc7NtPQN6+X66CuKdBluovPwXjJnb7oXvtN1nlzxowuxhf76/eNez TEIr13b3gwX1lfIRTyMgYD/DgSR757El4EcEY4ueIpjwtokyZLLRsxSQbWxQVNyCQIxO pLU514nFEVP1UDr0SC/zzfaP+hVzvZMyAyh7rNgz8E04dX8970+XplDIlYatPkKVujAe Wk9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ggxUr75B; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l7-20020a170906644700b0078da99ecbdbsi2884292ejn.673.2022.10.29.23.26.35; Sat, 29 Oct 2022 23:27:01 -0700 (PDT) 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=ggxUr75B; 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 S229949AbiJ3GZR (ORCPT + 99 others); Sun, 30 Oct 2022 02:25:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229833AbiJ3GYF (ORCPT ); Sun, 30 Oct 2022 02:24:05 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADDD0DE; Sat, 29 Oct 2022 23:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667111044; x=1698647044; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1K4yf7A4XzVtLVElMggRuvYNfU2q/PlhFY/Ez4kSMlc=; b=ggxUr75BvmJfou7PeGA5nR8RHFENjYai2Lo8fCCdG8Jg1Py+3IKzcR2o 9QtatENnwj2cT3xGHmquVP1FFR+jZDpYZuTZaRC35RXkVNKZy1Rqjk6tk AsQVZxIGa37mXadDL3MZAd9sb1v41cTolI38PzsRcVBl40EGZSQtVp0yT HD+5uI0p40eSp0+1WauBUMFwim3qsXIFir/O0Shh0yAwpIJK7oVkkmUnZ 5oue1Zlw8UtWwvfaJqtjllOXY18JPaoL2DMRNv+rv/8vFD8CGAyhxqZKA Japto/os3+BUG/xTiQd7s9inTveEr0ur/4+ZTF++O2rPNytBZGXvT+bIK w==; X-IronPort-AV: E=McAfee;i="6500,9779,10515"; a="395037132" X-IronPort-AV: E=Sophos;i="5.95,225,1661842800"; d="scan'208";a="395037132" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2022 23:24:00 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10515"; a="878392891" X-IronPort-AV: E=Sophos;i="5.95,225,1661842800"; d="scan'208";a="878392891" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2022 23:23:59 -0700 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 v10 020/108] KVM: Support KVM_CAP_MAX_VCPUS for KVM_ENABLE_CAP Date: Sat, 29 Oct 2022 23:22:21 -0700 Message-Id: <07daa8dbe1e3d6fec8db47a3ff3422a9bc460548.1667110240.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-4.9 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748092815893717761?= X-GMAIL-MSGID: =?utf-8?q?1748092815893717761?= 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 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index b9c270f97c88..3b05a3396f89 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -4967,6 +4967,27 @@ static int kvm_vm_ioctl_enable_cap_generic(struct kvm *kvm, case KVM_CAP_DIRTY_LOG_RING: case KVM_CAP_DIRTY_LOG_RING_ACQ_REL: return kvm_vm_ioctl_enable_dirty_log_ring(kvm, cap->args[0]); + 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: return kvm_vm_ioctl_enable_cap(kvm, cap); }