Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3463776rwb; Fri, 30 Sep 2022 04:06:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4gcqN3Q1Rfjj/+870FXpsqASCOnIDuvwULCmvqj9rgcPs1xTyHeVIxkuPu6wSDgw2uyjjM X-Received: by 2002:a17:906:cc13:b0:77d:46c2:f37c with SMTP id ml19-20020a170906cc1300b0077d46c2f37cmr6107804ejb.45.1664536011723; Fri, 30 Sep 2022 04:06:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664536011; cv=none; d=google.com; s=arc-20160816; b=WA3r0OTJbuK++5SRjkSkrAISBEbT7I0FGCl+NRqEbxl+7W3lZ+r2bqLgTVqQ7kO6cS v7kyOrNx8b3zDhOMC164dQ4Qw3gG+UdR2JWeQ2aSEzXzmut4yIjP3879qYIBDXYqghVL b/bP+nuL11LYgNBjTL64JCpmRVUdvoBgOF1euyWLD7EfoYtNMG9g380mPNlOXoszPCpD 3H/6NBwGh0jAj65LR887cL/BdVEu8Lr5+QHNsrnyBEH6w08kjJ7vgHVoH7K895qmRfYB ScbZ3ZyrPSi40IOsmip96qnrs9WHaTKrtvdD5gc3UYv11Tu51XUoKHzOAI3VszRXnrfo EpaA== 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=jvJrvucPOyMsCM0WnKtmEcspnNTNJXMT+ZEigEf/XHc=; b=wIO4qMdt9WS/+OjP+NoTADqq0kDq8MiE0fW1MYFKCJKx+/7ZW6LNqm5r619w/FNME7 U9waRl+9rhXEqotSUjfXUfs40y5csDBkawXiw7fKIJ59s7GbHYjrByAzIt/pmcy971Oe C/8wyCgLi7i9iA7d3dPra4iIuZ1DgMQzQG1drmmqWY8k8i5EEOipW9e5PNYt9cyNIi3O /VdkttZacb18hJy2QQwZuuJru7Wz6hVjY4MEYl11vL/pZ4Da6xmD7T9JSkJ0pY7w10HS FZK0Gsvw2I/eztLmizHlBUhl/AA34IqNWeKRWFB9AaahyLM9xCIFVLyCrls7m4U2/9ja 9UYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GXDzskt+; 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 e6-20020a056402190600b0043ccb3ed80asi2198060edz.18.2022.09.30.04.06.25; Fri, 30 Sep 2022 04:06:51 -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=GXDzskt+; 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 S232620AbiI3K0x (ORCPT + 99 others); Fri, 30 Sep 2022 06:26:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232046AbiI3KVl (ORCPT ); Fri, 30 Sep 2022 06:21:41 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABE2F15AB6E; Fri, 30 Sep 2022 03:19:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664533165; x=1696069165; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L4Y4+HfgPTiRbb6pNrZHfFkDdcGSHG+6n0iBguwwcdQ=; b=GXDzskt+R1ODqDKwoqhfZpLib1AE0g12RQuoRYubao31BD8eKP0eszyW AxuvGPQzKG/+EO8o0MDomAfdHh9FFoTl2Mg10W4SGrgMuPMRKtq2iHt96 DkCmnp1tPCw862XmClafutLpBENfg/3fFwf1dqJqRqah18DnKXdxLITEV jsy8NmWnKig2Np845n5Z4/UM/P3NV7R25BfZPgTTpAYRlJ7fctn9kjd5Y GjYrH8/qarChkzkmxhi49z0DtELRHZIsgb+ZHO0iGmLMI4YRZx31zJgVM oAdRx7Ser+wwJ3B05/rUuhc/5R6N7zk+s1F3vYkiuId9N9960DqIMWtd+ g==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="281870127" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="281870127" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 03:19:02 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="726807705" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="726807705" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 03:19:01 -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 Subject: [PATCH v9 062/105] KVM: TDX: Finalize VM initialization Date: Fri, 30 Sep 2022 03:17:56 -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=-4.5 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_PASS,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 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 af91a7d27bd2..e409247739a4 100644 --- a/arch/x86/include/uapi/asm/kvm.h +++ b/arch/x86/include/uapi/asm/kvm.h @@ -541,6 +541,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 0bd0f5945788..6c1730443497 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1214,6 +1214,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; @@ -1233,6 +1251,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 37e713ffab72..0aeb4639be89 100644 --- a/tools/arch/x86/include/uapi/asm/kvm.h +++ b/tools/arch/x86/include/uapi/asm/kvm.h @@ -541,6 +541,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