Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp291561rwb; Tue, 25 Jul 2023 16:11:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlFh+KMevtikbO2X78DufEwFFjN4f1zoo6NU54q05Ho1eJ6GRkLPwI8AkLsbS7ncgwBZnlpD X-Received: by 2002:a05:6a20:3d87:b0:126:5459:25d9 with SMTP id s7-20020a056a203d8700b00126545925d9mr688398pzi.29.1690326700628; Tue, 25 Jul 2023 16:11:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690326700; cv=none; d=google.com; s=arc-20160816; b=kBH/QB8KAAewTHh4wqfq7qVyw3pxcJF166XIIwgqRXGtQnghbp5iPa8v8FJ8rMuoqr PrLxlsdPSJtWXA5JPYVr5G+X3YdsTAapWnIkoy3U9EVyCq23RYwAZhGHFZd8Jd9jXYTH w0aFUZwx8BiodjpvFLqWiY65XfOLVX4q/fh42hZsDCiuDuD8uiPzgZia0v6/47Y9gPpw qe2IDOgenP6Ap79hEKW77TrkcfDWVajfAtRfRe/QHF7yDN4z1TniVyN/6ClBWQsJHz62 Q/ikh6EejQRGZBz7XJDpCNKtoukRvWEs6T75uzByP/LguFpTsz2qXoDfFPuLmQdRMOjL DWaA== 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=mk50fHx1Rev3lCUznCj5mwWHKEy0WLGm0XaYr/4oEvA=; fh=jZMBRv2NRWteSV/mkgrfqFq0j5jxLZE/wGHnJY0d7js=; b=v8846k484FJ9G8g+SOqAlJ+Bflr6f52KCN+RhHChD5I4Ak7fQp9+Z5aFB3vRu2eGfT nUMbniqCfUzKdywdP+5QD9/KfYmcc50uaMtwRIcdM9nRxKmrBkNbkTn9vUEPXQVRS/wr xCCkcH/KV9IRxxPDBpp+VUSEr1XqF5EMORYHX9Ev7VmOKqO2pXgfmakfymwHDXi4qtkH 8swYiTWDIXyPhjo9wJK1wdbZnRQB0N/jNH1BpHuPiK665+tsKoakZy/TEUZSsZFiGH6x Sd104Z8LQE2PabWB4/mpY7tnaiWxVFXW6cRCTfoRsXK0HoOBhs6JJz35mw8HHODFBcJv fh7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YlBRuxUW; 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 be3-20020a656e43000000b0051f869d7089si12368648pgb.74.2023.07.25.16.11.28; Tue, 25 Jul 2023 16:11: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=YlBRuxUW; 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 S232734AbjGYWYa (ORCPT + 99 others); Tue, 25 Jul 2023 18:24:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230407AbjGYWWT (ORCPT ); Tue, 25 Jul 2023 18:22:19 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61E304C3A; Tue, 25 Jul 2023 15:17:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690323465; x=1721859465; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OBXugoeG43vdHjZJrGLYTbh1iSwz4x9BVpSGJUSumzA=; b=YlBRuxUWchhJ3vQRm49EZySMhox0lJ+MpGbRgRjDW0AT7U3nRlQAZebd 8+xndJfEB3s45Cp/5/2vwV+0bGZOnOUeCv0HKDwqFmx6HAbHSjMWnUH6T l5Asy/iX1ZcC6l4x6/hmL2XNTbZnpEf8evruWWxK60rO2Vb1+94q+DTM2 V89vOSvvR7CT8hOlQQZ+pL4UV9R8AS+oBS5UJLwVoa12qwrJvXdHo91Bo +jv4FAOWtqagUFwl0jri34E+qBXzUpLB1ulmWibCO9myps4aKsCHwmZky H9e4lrphMs2U2m9uHxaR0Lhu9LqRGXz67wqjn8gRNGHBeczZ+74yD7CVO w==; X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="367882661" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="367882661" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:15:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="840001868" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="840001868" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:15:59 -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 v15 084/115] KVM: TDX: Handle vmentry failure for INTEL TD guest Date: Tue, 25 Jul 2023 15:14:35 -0700 Message-Id: <4e1b23fd3a7d4ccb3543d5420b15741d0bd63499.1690322424.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,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 865d7ae30813..0dfd6ea07aa0 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1171,6 +1171,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