Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1182586rbb; Mon, 26 Feb 2024 01:01:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVu7UQgiyfkgyexb2QVmZJhP73Yf2ZZ8v8EcB8VmDHmL4t3bUZe+p761ppuT5PfSySHNY/Bjjc4JyrrEfd6Jx0NebRQGId/UB2JLFVDZw== X-Google-Smtp-Source: AGHT+IHiRcz/G2eo16knc8gnHGCRAL0+6ulRJViYQEUEiCJUvcM4Kdu7FVF+o5bQ+EZdHcRDekit X-Received: by 2002:aa7:c0d6:0:b0:565:e610:c358 with SMTP id j22-20020aa7c0d6000000b00565e610c358mr1476415edp.38.1708938069303; Mon, 26 Feb 2024 01:01:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708938069; cv=pass; d=google.com; s=arc-20160816; b=NMVc12QC+gpWfHG4xGROuPwI+XTFU53FfGst0my/SuCcizDTb27wJiQz4kEKEIqaVn kKBYX8gd1rm0kdHrn8rOwtfU9RFSvB3QLtGt3JD+S1CLKahngaFFFMiQWjUv0iR1NRpq gdQboUxmKo9SQQzHc4PNxlJq0Eu4uRz43Qv6iB0RwyRH+RNq1meho69527H3nvSVxolU isE/GH/HkY3oMZHfYLtumDbWs989I44VjJPAZkxqUPqCkRg8dlGWwvrhZk7ej97rGfYy qD0TB5ettIhzRp/V9GTBx+foUI1Jb1sCcwdh+iEerrneT8bw03VuQoQ+GnPR2ZxwL4GB xouA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=bOysvaROIYqC6+3s5PjBggkkhOY0SYlh0w5cKdmsPtk=; fh=ot30+jBq02FczD4ZFzFr88ZsOwdP5t57J1+GmQOOi0w=; b=W6P2fgR7uOVvjMPb473Rud/ObewdLaktZorlEio4i5oSl1x2c2j/vJIEO36/4+6kZS +8GagKBcPnhUJssktljcqxNzoQ5jTV9WMU4eXl+sivcCIPT/3jPskqPS0t1nREhK7l6T 8VAGa+KAanSRnKbDaC6HFV0FpNFMZY+2yFBZASBHRu+I3ANXXv4v0iQheYj5vazJWJ45 UEH3jEzIhhmQwysOgA/p6DJN5kJ631PcCLdcdoYOZL7XS1h2ia76FgFioNhiweQ0q46o NeynLEq4NAVqZlEEqCaxjjQVLdjd5qvOL2vypbsHNI13zPoZvpzXiYsU4wW+2NyPMH35 n3Yg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MxDdlcdF; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-80862-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80862-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id k15-20020a508acf000000b00561d43bb5f2si1821725edk.387.2024.02.26.01.01.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:01:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80862-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MxDdlcdF; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-80862-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80862-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 142131F23890 for ; Mon, 26 Feb 2024 09:01:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A6D87FBDA; Mon, 26 Feb 2024 08:29:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MxDdlcdF" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 812EF7E56A; Mon, 26 Feb 2024 08:28:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936139; cv=none; b=TQZB2cztTHg2BhDTnvoKtOVW8SWB9CIg248vcgINPBna3xb2E0tmYXXV0oc50Vyya9xEdRe1ErRlCaLTYezMOSOhUGZXUiAe822IHb4X+zwKMy7w7o7dISSRmLaPbfkDI/ZEWrNL71uCkG7HVGUzIBIcxvVhjWHI4A8cAOko2x0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936139; c=relaxed/simple; bh=PfEUloIaN0+m6wTf244BqhPSXX4Whs3+DiuXu81jwnY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Clw63XQhANY6jLE0cSWiSwTxbAG63lote0dCpEWr2ROnvCj5eLjdwLtSQ3ZBQEQSCZlDBYRLVc6BkTXD+NFSweMOAK/nbe1M2uOqxQq0dGD4Y26OYtwwOT5pHwffPJ5hasKqfT2Yh1W980KmVPUCyA+Pu2MEub7G1oFG3lgWzZ8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=MxDdlcdF; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708936138; x=1740472138; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PfEUloIaN0+m6wTf244BqhPSXX4Whs3+DiuXu81jwnY=; b=MxDdlcdF+bIgSdhb00qqJOR6KPF+ODMX6dEGSgrzZ8tBSLqCqClTp1CV p41JWNiW4BerETvy6iPVJLjrK0r7fAkU/i2mxMc+QRYqzGlXUGdzrJ9uK gOc1O8UbBPowm2A5/vvurj/4e6ciN+MGY4RZecVV9AizduLZ9XfIsAoLd eeJjAjsVdRiHfjbyzgAbQ2D6gv+zQP/Sy8Nxx05RRSvVfascv7wQGFXMY 8bjx7Z6VcH/VU9XG8fzkLI8xcRsh5djnes575qoV03cmpSqNMhKiAs71o PU1/3PZ4r4awSbx5PraR6ef4z1Tbex1xYDatuvnS8muGSUSNidZ1rIENB g==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="3069592" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="3069592" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:28:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="11272680" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:28:57 -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 , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Yao Yuan Subject: [PATCH v19 099/130] KVM: TDX: Handle vmentry failure for INTEL TD guest Date: Mon, 26 Feb 2024 00:26:41 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 71ab48cf72ba..cba0fd5029be 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1320,6 +1320,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