Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3405031iog; Mon, 27 Jun 2022 15:38:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sYgExYoo7ly6J9vl+EiAwD8tLA1992j3ggD8SN4q23iu1PQE3lrWnluS4hcpam/3uvkB6X X-Received: by 2002:a17:906:49d4:b0:6d6:e5ec:9a23 with SMTP id w20-20020a17090649d400b006d6e5ec9a23mr15643865ejv.79.1656369481857; Mon, 27 Jun 2022 15:38:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656369481; cv=none; d=google.com; s=arc-20160816; b=LvnkMvuvqMYdNVdSCp2G8axnFzTc4fIzz35srMHTCekNrVaf9QZv5/E9eAIqUxAYB0 ayt6HV8SD/OZdFtD+QwKPknXUpBSd+OC8YkfC8xaEnJm5xmxmeD3yRQyEjYb5F7AgA2a iKZgif8Kzp10OlSjz3NwKOFeZHWlvB3m3IsIqQooGaAzGIc2zbirh9wJpYkvnSc1wm3U viimrcfkI7Xb4gK66gBkZFEzu/Hs6mu1nSuAwOUlDxIagRAPPQAVBq0twlab+x+oKJfM 54FCobuec22re2YoXiOTFfd1ouWVAar2pn8dlpr7NiAjaBecbOfY39n7v8DQ/rrqz2SX 7mNw== 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=sU6mf/NaZqZqbnbmAQO30Y20LKWOd6VVMoqMoJHvl4k=; b=NMd8IOadbWpRS1PAXfeLPlFFmjaOymndKLnsqjmJXWwp6ggpUINkt5rwB6YD8GbDuV dmrR5Yj/9IqY6VORb3wHtLL/b2KUe5EYEydAyutGzOVAfywFT3/VRy8dKuTyktt41WTp SLLvqLV5S5cx+orxnf53wrRZHLxv5GT1MN8zRp3l430oSlbgel25XCEFhuAdhrmcE/1D 9OnNwlqvIwsZ6+Fx+WcQHUQxGqp3Z7Pqd+0N1Epfu7fULqI7FmO4A5hMtT6K1o3htnKZ FRGUCXs2BovSuPvob1320CqtGcTr7RseU+U4YOQGPzFLauFdV1+UQZd2fuGUArCSTOB7 hWAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NKnZluTI; 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 dt5-20020a170907728500b00711c832d377si15063180ejc.17.2022.06.27.15.37.36; Mon, 27 Jun 2022 15:38: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=NKnZluTI; 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 S241782AbiF0V4p (ORCPT + 99 others); Mon, 27 Jun 2022 17:56:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241368AbiF0Vy6 (ORCPT ); Mon, 27 Jun 2022 17:54:58 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27A3263D5; Mon, 27 Jun 2022 14:54:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656366896; x=1687902896; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CQmog2ttJcoHhAh9OiiLQQ5rhSR/GzRAHoEUrfSqJf0=; b=NKnZluTIM0AQ6PV9+X4/oDSyj6SW8PqpkfBToZAt0FMWWGxRk3ZoO2WY MaiIARmth3bbEWcuxob6RDodIIDRaG+/Y8vd8FLR7AKb+b3lwSnmq8bk8 s9IeVNLhAEM1YqG/iJQTG+MhJnO7bNfncfWuboTYayrQJxVH80A0XZKeW rtToCgJ8malk9cv4IasO9f5wOCSCOxWE20DWZvPIdWqroP/O+ZE3XA7nH yOqlPf2YhdLiJF7+RgsEw76LbvwBXKhN8Y+Kl4Jp/004twxWmaLF/bXvJ lsrXMfeKKQJpqIRM5/YUbcz0l7ufEf86bjXkXS34t5IM0q3t6HQx5OIhY g==; X-IronPort-AV: E=McAfee;i="6400,9594,10391"; a="281609527" X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="281609527" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:54:51 -0700 X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="657863528" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:54:51 -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 Subject: [PATCH v7 029/102] KVM: TDX: allocate/free TDX vcpu structure Date: Mon, 27 Jun 2022 14:53:21 -0700 Message-Id: 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=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 The next step of TDX guest creation is to create vcpu. Allocate TDX vcpu structures, initialize it. Allocate pages of TDX vcpu for the TDX module. In the case of the conventional case, cpuid is empty at the initialization. and cpuid is configured after the vcpu initialization. Because TDX supports only X2APIC mode, cpuid is forcibly initialized to support X2APIC on the vcpu initialization. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/main.c | 40 ++++++++++++++++++++++++++++++++++---- arch/x86/kvm/vmx/x86_ops.h | 8 ++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c index 067f5de56c53..4f4ed4ad65a7 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -73,6 +73,38 @@ static void vt_vm_free(struct kvm *kvm) return tdx_vm_free(kvm); } +static int vt_vcpu_precreate(struct kvm *kvm) +{ + if (is_td(kvm)) + return 0; + + return vmx_vcpu_precreate(kvm); +} + +static int vt_vcpu_create(struct kvm_vcpu *vcpu) +{ + if (is_td_vcpu(vcpu)) + return tdx_vcpu_create(vcpu); + + return vmx_vcpu_create(vcpu); +} + +static void vt_vcpu_free(struct kvm_vcpu *vcpu) +{ + if (is_td_vcpu(vcpu)) + return tdx_vcpu_free(vcpu); + + return vmx_vcpu_free(vcpu); +} + +static void vt_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) +{ + if (is_td_vcpu(vcpu)) + return tdx_vcpu_reset(vcpu, init_event); + + return vmx_vcpu_reset(vcpu, init_event); +} + static int vt_mem_enc_ioctl(struct kvm *kvm, void __user *argp) { if (!is_td(kvm)) @@ -98,10 +130,10 @@ struct kvm_x86_ops vt_x86_ops __initdata = { .vm_destroy = vt_vm_destroy, .vm_free = vt_vm_free, - .vcpu_precreate = vmx_vcpu_precreate, - .vcpu_create = vmx_vcpu_create, - .vcpu_free = vmx_vcpu_free, - .vcpu_reset = vmx_vcpu_reset, + .vcpu_precreate = vt_vcpu_precreate, + .vcpu_create = vt_vcpu_create, + .vcpu_free = vt_vcpu_free, + .vcpu_reset = vt_vcpu_reset, .prepare_switch_to_guest = vmx_prepare_switch_to_guest, .vcpu_load = vmx_vcpu_load, diff --git a/arch/x86/kvm/vmx/x86_ops.h b/arch/x86/kvm/vmx/x86_ops.h index ef6115ae0e88..42b634971544 100644 --- a/arch/x86/kvm/vmx/x86_ops.h +++ b/arch/x86/kvm/vmx/x86_ops.h @@ -138,6 +138,10 @@ int tdx_vm_init(struct kvm *kvm); void tdx_mmu_release_hkid(struct kvm *kvm); void tdx_vm_free(struct kvm *kvm); +int tdx_vcpu_create(struct kvm_vcpu *vcpu); +void tdx_vcpu_free(struct kvm_vcpu *vcpu); +void tdx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event); + int tdx_vm_ioctl(struct kvm *kvm, void __user *argp); #else static inline int tdx_hardware_setup(struct kvm_x86_ops *x86_ops) { return 0; } @@ -150,6 +154,10 @@ static inline void tdx_mmu_release_hkid(struct kvm *kvm) {} static inline void tdx_flush_shadow_all_private(struct kvm *kvm) {} static inline void tdx_vm_free(struct kvm *kvm) {} +static inline int tdx_vcpu_create(struct kvm_vcpu *vcpu) { return -EOPNOTSUPP; } +static inline void tdx_vcpu_free(struct kvm_vcpu *vcpu) {} +static inline void tdx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) {} + static inline int tdx_vm_ioctl(struct kvm *kvm, void __user *argp) { return -EOPNOTSUPP; } #endif -- 2.25.1