Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2681295rwd; Sun, 28 May 2023 22:05:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ViYMvucCwFeloxF3/0ukaf2EYvawjK6YvVQL/zP47X4DvYRNRq9OWWjKRlZS36jZyNmp+ X-Received: by 2002:a05:6a20:a108:b0:10c:6956:a23c with SMTP id q8-20020a056a20a10800b0010c6956a23cmr6549031pzk.25.1685336740600; Sun, 28 May 2023 22:05:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685336740; cv=none; d=google.com; s=arc-20160816; b=Uopz0TCe6Q1nnhNOymEydguXHbKJeiaum/LnltH/5DVPu8p+aIQb2CZC3g8hPbmBni kNhfh5Ki/8dVHYu+Zh5m2yqVFa5+PB/ZNWeFPtwVwHrd8Clj5lL+P+80GXvQowt29JrD a8B2Q965k3DyZyYlkqVtOivNHyzOxKIJ8/QHHvtsd1bbKuo6havyf10RFSn48RoiF7+3 qIoZZDNIW03McqJAMVoEsmQxsptNubTGHDDf1CpKmI0GjQvciBf1irRdeLWFG6lnlYci EdXUhzFtE/rEP7o15auaT4GX38vHvsiVIqBYV2DEOtYDxNhFSlSjEN2GbAuAF3ReydU1 qZog== 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=KY1XMlrtiZm7JfjN40DVy05R2vPhFevzmaWyi+Ofjtc=; b=thtqjhLLorUs/JiEy009voG5uKQtxu3pLXIcq/6Ldsu++U3ZIVuRFegAQCCcWFbFX4 pOp5pLISS0vpIKQfPG1MKfnVIMj6nW0mZ4w9hzeiLu76wsX8QjLdw3Ix0jqkwoRQK39m hRt5wOYDkydkxmzUoZn/x28TDn4oOcwDDM6ev0CY54Hr8uXfDi+9HTk4mNvU65NwLc8s 28NlmdEaWpr0Y2quOZW1Cpx2DnRMNO37HVy+uIIF8escdQKiBMIlM/DtLEAZ3MyfIr5O KAZAWNfg5G4XbcX8TNKMYk820Hff62bvVYvGzQLj6jCl+jQv/x7WSewBoTYsuL4FnS72 mQfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iqfNH3g7; 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 24-20020a631258000000b005307b843a98si8793970pgs.53.2023.05.28.22.05.28; Sun, 28 May 2023 22:05:40 -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=iqfNH3g7; 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 S232351AbjE2Ee0 (ORCPT + 99 others); Mon, 29 May 2023 00:34:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232311AbjE2E3u (ORCPT ); Mon, 29 May 2023 00:29:50 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 891371BD4; Sun, 28 May 2023 21:25:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685334352; x=1716870352; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LT16rYMF6YoQy4vShQHZagKMgfDXxwybINz3LOjnB+E=; b=iqfNH3g7E2RNGKHGUb5SFkUnr93mxr4oPQczdsz3W9NB0ELEFVYKXac7 59B4Ptd0/BrsBpu+uBg6RSls5bJLhZoyr7/bpFr4vkvk7c+WwO+tuixls ltTJzgVU/4waHik+p2Er7y3IzNLPReJRIU1ufu+j2oEvXAOtXJ6s64JIW aqDzgkvZUKLEoGJW8XxDb2jS0YdhLlV7Nas0zWiQ+P1XgKqzJAtgDcZV6 /cojreFw8497uKm1wUgQwAhMZbDn8rd2MrlYvD52EPmY3cXjJ8dJPfVrb RY+qXhCI7+lsmAnOl3lBxTPM5sRww9KABEk969boLOAo/Bb1pO9WnmiV7 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="334966252" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="334966252" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="775784520" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="775784520" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:35 -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, Yao Yuan Subject: [PATCH v14 084/113] KVM: TDX: Handle vmentry failure for INTEL TD guest Date: Sun, 28 May 2023 21:20:06 -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.6 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: 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 8fbf68f6bfcd..685724c06c34 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1169,6 +1169,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