Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4119017rwb; Sun, 7 Aug 2022 15:35:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR6V7VLidmstGSXgJPKWO0Y9WZxpIyEBJ8Kg3cFr1wpLFrs5eF4w2OPYZ+jh6ypbL+c46h9D X-Received: by 2002:a17:90b:3944:b0:1f5:4cc8:d46 with SMTP id oe4-20020a17090b394400b001f54cc80d46mr17663168pjb.95.1659911733450; Sun, 07 Aug 2022 15:35:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659911733; cv=none; d=google.com; s=arc-20160816; b=Tftxtoxf8YWOd44uXgnuktixN05u9TvhFIMltEhKRI+aOipxofIByOYb2J685nZvJ0 MX3j1d1yxzBBAw4lqgPF69+QyIwYYdFXfHgixkUH1swbTgfUHzZtKUdFurkeU+L7+i9k 3M6AI5UrW6itumNzbhj0lHBhUz3A6FxDVC9jB0Y9bFW89T1SgesemLpyX7xdduZDWZWl ZOQeYBXwIUlAIQZhNJ/hU31UF7HfbN2tFuBI0MsOpg/ed9c3VvmzDx8dbxtP5Rx+cyYb Iydc8RzIqJDnvrYBYis5hzaxVHSalLbt471XumkJZMCgiBoKvjJqw0zE9kMyjaMNdK/L cexw== 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=FXEVMby4o/7qo7drcrLCPKh3UOWsduZIzVnfbYvbamw=; b=sWk0cXLbO5aecvortJ0PKE9AwGiW8nPbJ3IxiLABAg4+Lt+ypyQSgEP/V1szKk+gLl CMndNEkMWvEDAagyf9JGVwXs9iBGzsOBk01rjs4to7/nECfxZ+HgJFSFFY1gJEjMijeO fUjMusijak5t5Y6SDc+io12L8BWjY3BtgyMBlE4nF0XG7q2wQGmxTcIMNNCzNOKBu242 bcOFqnunG1bq0dqAG4P3sQY8wvbO3zp4kMJ/4MPfTDejthqfd9y/TW5npxpELCKnC/KM 1lUGisdv7wffUR8FxJ+d0e6+F+wAEEds25tUyCOqj9oO/rB/NkCx+HmOLu+4HPelBiZn oSLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ORspSPGb; 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 l185-20020a6391c2000000b004117951a3c9si9559135pge.537.2022.08.07.15.35.20; Sun, 07 Aug 2022 15:35:33 -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=ORspSPGb; 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 S241880AbiHGWHT (ORCPT + 99 others); Sun, 7 Aug 2022 18:07:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235132AbiHGWDJ (ORCPT ); Sun, 7 Aug 2022 18:03:09 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 577BD9FFB; Sun, 7 Aug 2022 15:02:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659909763; x=1691445763; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sBVEBvsiXpGhRktIyqHD6URD/GZwHPTPIZHkhUKR5DE=; b=ORspSPGbZz1FyXEChPqEFgpwbESEWxdLLOQtfqFWyXPu7b3Fxb6QETLS zkkCx/RgEsn72C4TneqZ1tMbIl7+wfeA3yW95DAD3hmbbo5e9lkLosOyS ek89LZwvbDiCgkt+heqvQdtFoHG0e5lKpBvbI+3ag49tzbbwUdhEqESN8 sHVUQQJ+GSzSZTB7j5geYGJoemARCmnI2R1SBnaqXtwbpU2e03t6Cek6y tW1Xy6QWsAP98wA3XOR6B4D1JtX5/TnXDILRTsZVEu6ADyhLTC8HzKPi0 qR7JU71xm8wLnUmVZLrthKnQfdWf9GvtvZdJXBDP+gXwGyUCTXbUxZsra A==; X-IronPort-AV: E=McAfee;i="6400,9594,10432"; a="354465753" X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="354465753" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2022 15:02:38 -0700 X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="663682645" 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; 07 Aug 2022 15:02:38 -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 v8 061/103] KVM: TDX: Finalize VM initialization Date: Sun, 7 Aug 2022 15:01:46 -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=-5.0 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,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 787644687586..bee5957a583a 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 7970a2cfa909..8400388b8ddf 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1221,6 +1221,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; @@ -1240,6 +1258,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 f6d6da7515bf..2eb46f5dcc0a 100644 --- a/tools/arch/x86/include/uapi/asm/kvm.h +++ b/tools/arch/x86/include/uapi/asm/kvm.h @@ -535,6 +535,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