Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3417571iog; Mon, 27 Jun 2022 15:57:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uITGfHu+ntIqm38RuRKfujOae0L8GoQYGnXFXvhm+RsTsiZv05URgW5rwvdkAhy8f0rcqG X-Received: by 2002:a17:907:7678:b0:726:9d66:8f0a with SMTP id kk24-20020a170907767800b007269d668f0amr9263088ejc.76.1656370658276; Mon, 27 Jun 2022 15:57:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656370658; cv=none; d=google.com; s=arc-20160816; b=lkpeF85ssdAvSw3vip06PhyYloBSKf4ho64uchhfMSS4aDCD6ejvdZXxaQbQRMGEPD 9vqpAbBfp8/paqqkSUehAcMAYrPskOifPPtgsCHFGR+0KY0CT64ci3xa15FYFCSNJnMq xi6++GkcPwOmW0ceRiURTKV4qidMN/UTcBbdkUtst4EIevfhXLf+ZUcDHeM/ZHRcoQ5L lysLqp1Ds3hML5kdd6JUph+2zROLY0sHeDVUQl3POi6u3iQmI1A1XxD8FNBzHd3SgOzt kJ6q/dKporUNVPycl+y6ak5yImXVd+hBzKMtKaumgz4PGvFMLJZrxV5O2K3Ktlv4gwrL Bk1Q== 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=ZJHqws/Z/ZSLIqPX1ovCp2VjYjQoZ9BJSnayjIZpdSA=; b=W2g5RjRJJyE3vXdq0m4lue1tpk6s2pvP5J0lK8V7/OroQv8/VxkikmTASfdh2PyQon Ba8nBIRbHUF1rMohTneNlC3P1e37TDeV0hstdO67+zRSEYFhs1T8e2FnUeywQuoxboel fnqpznz2/w+AHY802yxjVyWhqsrXszIvF3geRwf3WvhLYvhKyekq/5iDez+p8DukHRtr MCTBgonQ4LKKXQynubfx0+bxGY94m7V1CnhI9M5txRI8A7XyKlO0u7rcmVHCK5wZrbGZ kgA7bSOkRy/cCGJieR9fTSena7zkhisGd78K6imFnfrocC4O3TjK6WKLjhBDVVrxmf3A 0Uvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QXMIfQv8; 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 l5-20020a170906794500b00711fd60fa17si15867672ejo.34.2022.06.27.15.57.13; Mon, 27 Jun 2022 15:57:38 -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=QXMIfQv8; 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 S241793AbiF0V55 (ORCPT + 99 others); Mon, 27 Jun 2022 17:57:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241425AbiF0VzK (ORCPT ); Mon, 27 Jun 2022 17:55:10 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DF2264E3; Mon, 27 Jun 2022 14:54:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656366898; x=1687902898; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EC6h1CioZsI+mMSdyjItyFQrWi0GAr2Rq308o2RvncA=; b=QXMIfQv8u/NFtCjsOoyZhUH8bsMRBtVI2YhatXp5kZRPKuJlU7fOz+r5 9GYsmsMs9mC47Z+Ays0AR5gptDc/ul8GGXurbQwupVLF1cg37ZWJo39/q ynXMFkAVwsDkKqffnM09EzgbkGQWJ5jNQcCXk+EJDT5UzHbzOLTOvs1O0 JiFk/Y1ig13nf3DmotWCnHCqflcSEt21JtoWpegkVpFMZ8AdqR43oXXdE WQSxi4aoh8YcQaFIgssscXWFodexirnyQ5dsstzRALRbUFgsvfunLnKbI C5o1TQ/xZCM4HqLQzhteeJzJzCA/bSoKJCw/jyPAC+UWfpwAHPyfMRofL Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10391"; a="279116099" X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="279116099" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:54:56 -0700 X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="657863633" 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:56 -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 061/102] KVM: TDX: Finalize VM initialization Date: Mon, 27 Jun 2022 14:53:53 -0700 Message-Id: <9982a3c968df2a3bba85b4373b0b41203ecfbaa4.1656366338.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=-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 To protect the initial contents of the guest TD, the TDX module measures the guest TD during the build process as SHA-384 measurement. The measurement of the guest TD contents needs to be completed to make the guest TD ready to run. Add a new subcommand, KVM_TDX_FINALIZE_VM, for VM-scoped KVM_MEMORY_ENCRYPT_OP to finalize the measurement and mark the TDX VM ready to run. Signed-off-by: Isaku Yamahata --- arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/vmx/tdx.c | 21 +++++++++++++++++++++ tools/arch/x86/include/uapi/asm/kvm.h | 1 + 3 files changed, 23 insertions(+) diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h index cb2b0701f0d9..2fe4cc497bc2 100644 --- a/arch/x86/include/uapi/asm/kvm.h +++ b/arch/x86/include/uapi/asm/kvm.h @@ -540,6 +540,7 @@ enum kvm_tdx_cmd_id { KVM_TDX_INIT_VM, KVM_TDX_INIT_VCPU, KVM_TDX_INIT_MEM_REGION, + KVM_TDX_FINALIZE_VM, KVM_TDX_CMD_NR_MAX, }; diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 69550a1ea1d0..d2688bb8e5fa 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1230,6 +1230,24 @@ static int tdx_init_mem_region(struct kvm *kvm, struct kvm_tdx_cmd *cmd) return ret; } +static int tdx_td_finalizemr(struct kvm *kvm) +{ + struct kvm_tdx *kvm_tdx = to_kvm_tdx(kvm); + u64 err; + + if (!is_td_initialized(kvm) || is_td_finalized(kvm_tdx)) + return -EINVAL; + + err = tdh_mr_finalize(kvm_tdx->tdr.pa); + if (WARN_ON_ONCE(err)) { + pr_tdx_error(TDH_MR_FINALIZE, err, NULL); + return -EIO; + } + + kvm_tdx->finalized = true; + return 0; +} + int tdx_vm_ioctl(struct kvm *kvm, void __user *argp) { struct kvm_tdx_cmd tdx_cmd; @@ -1249,6 +1267,9 @@ int tdx_vm_ioctl(struct kvm *kvm, void __user *argp) case KVM_TDX_INIT_MEM_REGION: r = tdx_init_mem_region(kvm, &tdx_cmd); break; + case KVM_TDX_FINALIZE_VM: + r = tdx_td_finalizemr(kvm); + break; default: r = -EINVAL; goto out; diff --git a/tools/arch/x86/include/uapi/asm/kvm.h b/tools/arch/x86/include/uapi/asm/kvm.h index af39f3adc179..7f5eb5536ec5 100644 --- a/tools/arch/x86/include/uapi/asm/kvm.h +++ b/tools/arch/x86/include/uapi/asm/kvm.h @@ -534,6 +534,7 @@ enum kvm_tdx_cmd_id { KVM_TDX_INIT_VM, KVM_TDX_INIT_VCPU, KVM_TDX_INIT_MEM_REGION, + KVM_TDX_FINALIZE_VM, KVM_TDX_CMD_NR_MAX, }; -- 2.25.1