Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp504274rwb; Thu, 12 Jan 2023 08:41:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXtTR9FMJ5mD9z68+uBsuzxGRmVm9JL5cUEbvXpqYLgs1QgtmHtZy/WdT6mlfp9W1f2/3c7f X-Received: by 2002:aa7:d61a:0:b0:499:376e:6b2d with SMTP id c26-20020aa7d61a000000b00499376e6b2dmr17947729edr.0.1673541697733; Thu, 12 Jan 2023 08:41:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673541697; cv=none; d=google.com; s=arc-20160816; b=Gw72wnnv3tYUBzatmF5oqULbPSO+Cz7zJvHj2fJpZnCOgqejsz96V0eRo7Nm9e2W7V jjQotSdm17A4fqX1vuV5ZJMIPYcLA2X3qFJukLBR7mqwPRRoPLDz3Sk4o8DD2mFdhark 587HFnBuR1OaknTFbhiNst7CK9yymJt7aa+zc+ISWip8LMVnQVFgWN7IIxO6ly3Oj8Hu ff9k0R63x7o/tssBKlgb7XCTL9jzfTQfdhYKTAozujVTYhjn1aFPrNOKcLBlwv4dDRxq lLM3gw7/5zMG61B4cPcaTt8Y+j9BVwvbqLvYS/AtHJfruo8n/9BWh8IUUiX9r+nDLkb7 Y4HA== 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=ToBtRFkof5iXxalu7F3Z/bRoQ3C1KeDSOxEmaJqUf74=; b=y5r5cmyTJO17pnh4mg/AQOCeOlF+2U48aENO4vGxDO5xHEYLQoWCzQ4AU6jCToFnJL MpWj7CwBQI/STB9oe+PIJ+7zR4KOBAxu8+akjAIs/EgHRjNyDfoW4d7xML7w+lMjIpaG 26g/UE5+5pFen99co4f/GlOnL4JpzcOy/4EIb6mM5FzHCwJyDyJOcLn3xu+oJLoxSD6q myCP8nkLE9ey/JQxoh3VULaHSYbqEIY56ns3LtkOXr5fgp5zf634powEqMEdrZGZrBRY VehPjBA2NRh4IO8w/dKj392MQpgNXvumBcyVDhvBlCAsBOC03xZ3VsOvwonUCuOMdSLI n7MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="T/F2Cq88"; 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 t32-20020a056402242000b0048b8e656038si18593862eda.383.2023.01.12.08.41.25; Thu, 12 Jan 2023 08:41:37 -0800 (PST) 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="T/F2Cq88"; 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 S239906AbjALQjP (ORCPT + 50 others); Thu, 12 Jan 2023 11:39:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233379AbjALQhT (ORCPT ); Thu, 12 Jan 2023 11:37:19 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4351211801; Thu, 12 Jan 2023 08:33:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673541222; x=1705077222; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4xQ5Cdyh5TMjyjeTraSH/Dt7a9+kiDlobGft6bkhYzY=; b=T/F2Cq88+bRnJ8v/E54xojzFIWrS0ai0uH0tVJTmcwQlagMRkn/jZtXw XAJPd2wHzbFtQP2PmWRWdCs3UGxuGKnzphGgE6P8GBqpNcowI76eu4HzI 6nKmShJ5mxMalufdbRdF6UAtUc6cwJlWy6FdLjhdRd7OF0Vf46LYma8T0 wIrgQ8AGuSF6EkY+I7MCu7RYCpFdhtExOuLS+/LydM4C5mu3+LgAORtur Z8mYHO1umuKoHyXNLqXerQ+lidtYTwF9iJhD94goekYwsig0pWVW5dEn2 wFEzvYN/tapoBW97I+nhn+0wicRIcZ4IEDrxCiHd6mmaBJeiqw8wLPirB Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="386089684" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="386089684" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:35 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="726372529" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="726372529" 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; 12 Jan 2023 08:33:34 -0800 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 , Yao Yuan Subject: [PATCH v11 085/113] KVM: TDX: Handle vmentry failure for INTEL TD guest Date: Thu, 12 Jan 2023 08:32:33 -0800 Message-Id: <93afacf52041d9a418a27b05f31031cf7676aa3f.1673539699.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=-4.4 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 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: 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 Signed-off-by: Isaku Yamahata --- 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 964154f7bc60..47ea12f23471 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1094,6 +1094,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