Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2619367rdg; Mon, 16 Oct 2023 09:33:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgeTPBMnjkKY1wYthvIGwFq3G4vz0vHCG3m26uZeBIkz0cReO0BBOSVk5dhCtlUf7GVb9m X-Received: by 2002:a17:903:41d2:b0:1ca:86a9:cace with SMTP id u18-20020a17090341d200b001ca86a9cacemr2352960ple.2.1697474027415; Mon, 16 Oct 2023 09:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697474027; cv=none; d=google.com; s=arc-20160816; b=Wp0rG6imyCBvJ7KQ5A1rhXZr63xecOLQmdmiPvARgD+o9DvjtXtzpexDpOWBTZn/GL UofAsGUxINQoJ4FJ9+53Fbu0Mg9Cwrm2hJOdpYoodBC2SU7wdevBaPsVLLSKf7uHSN+z eScSJMldq7Wr847MhT7bTWohthFyxtyxUAKd56Cd+Cy/Ux++uRG8pm5WflDLmuZsins4 d2ImEpgDQB/V00xyYQweXMV7kpEJNJFjb+q+Pq8KhUyz6QPL5WL3zWzYQzkoJ/yoGbZT v7KHRRey5zVhGP5pGAgB60nDYzojNjNl/wcevCSPwdioLCPnQvx/vqYWPJYya/QXY6my oEQw== 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=xj1gz9PlbihXNhqwM1oVYOf1W8ADhTTVrm5xyxDA2Xo=; fh=1qqCD8f/2PWY8gKQyqEdrZpvrXuOBl26Gwpa86mu760=; b=Qij0Q2EK7EjbR3cpOdGWJz5fEYJm2vMDJP6mXgAcqExF1hk5kiGEDh5BpmLXz9kJYW OSAYcKDP5gyGBklMq9VJP9mvhQrkSPBbqTBE02f57xBSB0HxIwzI2Liv3r2i3CAOwsvQ mi8fjn86yAHft7NdnVvelpbDvxQxgRP0xmPjRYYAyXyuvQCRnnLn4sTxreiyg1Dvxc1n 6S+XhTHTXvt27Y3+xqTK2V/RHIMpXVslVUT4hI7PtlpsBAGEDsQp71+egsiZN3bpHIme lgPITT3NFA3nP+OU4RcK1Z8W/gK2z93NrTqawzhNNw00qEOtQtckNJOnmVJKgpXQFDt+ ZaoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=K7A+CE39; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id u6-20020a170902b28600b001bdc10170casi10947591plr.36.2023.10.16.09.33.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:33:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=K7A+CE39; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 2D00F808BD8B; Mon, 16 Oct 2023 09:33:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234150AbjJPQcr (ORCPT + 99 others); Mon, 16 Oct 2023 12:32:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232845AbjJPQcJ (ORCPT ); Mon, 16 Oct 2023 12:32:09 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 296C34499; Mon, 16 Oct 2023 09:19:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697473197; x=1729009197; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rWXAJsBXvldwnJdPf0k5N9icvjGGM79jJW+iAC1XCxs=; b=K7A+CE39uH2sTwy5qJ/8M9Q1XAty2u4OhuKl7ZTlj+iVVSRNQs++MRaT gkZKod2Qmr3NrqOj58VWC0X1YPSJi4TGx7C2EUHiBWZzRBewnJIuh084b 5RJqpFn7CDt9r2uzw+KZ7Z5Rsvc15XRSgY1i5i8mzg3RsXBxo2OJZZbmf bABiubG/TjxnkxbOngyiEtZIGPTWiBJVl5J2Dig7sDGWrbr8bol254R5C BMFanGYxL57PDRJvrV5tkOw13mHynya+OOqiKB1gKL4SGWNlB6BEhczjU DUWt5Ytev3GCeloWA/TV4cf1palG6REYDbNwzMLEsXTjd1FYgUgwZDIeW Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="364921992" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="364921992" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:16:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="846448264" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="846448264" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:16:00 -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 , Kai Huang , Zhi Wang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Yao Yuan Subject: [PATCH v16 083/116] KVM: TDX: Handle vmentry failure for INTEL TD guest Date: Mon, 16 Oct 2023 09:14:35 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 16 Oct 2023 09:33:40 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email From: Yao Yuan TDX module passes control back to VMM if it failed to vmentry for a TD, use same exit reason to notify user space, align with VMX. If VMM corrupted TD VMCS, machine check during entry can happens. vm exit reason will be EXIT_REASON_MCE_DURING_VMENTRY. If VMM corrupted TD VMCS with debug TD by TDH.VP.WR, the exit reason would be EXIT_REASON_INVALID_STATE or EXIT_REASON_MSR_LOAD_FAIL. Signed-off-by: Yao Yuan --- arch/x86/kvm/vmx/tdx.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index be73b8322a66..306d555dda35 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1314,6 +1314,28 @@ int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t fastpath) goto unhandled_exit; } + /* + * When TDX module saw VMEXIT_REASON_FAILED_VMENTER_MC etc, TDH.VP.ENTER + * returns with TDX_SUCCESS | exit_reason with failed_vmentry = 1. + * Because TDX module maintains TD VMCS correctness, usually vmentry + * failure shouldn't happen. In some corner cases it can happen. For + * example + * - machine check during entry: EXIT_REASON_MCE_DURING_VMENTRY + * - TDH.VP.WR with debug TD. VMM can corrupt TD VMCS + * - EXIT_REASON_INVALID_STATE + * - EXIT_REASON_MSR_LOAD_FAIL + */ + if (unlikely(exit_reason.failed_vmentry)) { + pr_err("TDExit: exit_reason 0x%016llx qualification=%016lx ext_qualification=%016lx\n", + exit_reason.full, tdexit_exit_qual(vcpu), tdexit_ext_exit_qual(vcpu)); + vcpu->run->exit_reason = KVM_EXIT_FAIL_ENTRY; + vcpu->run->fail_entry.hardware_entry_failure_reason + = exit_reason.full; + vcpu->run->fail_entry.cpu = vcpu->arch.last_vmentry_cpu; + + return 0; + } + WARN_ON_ONCE(fastpath != EXIT_FASTPATH_NONE); switch (exit_reason.basic) { -- 2.25.1