From patchwork Mon Feb 26 08:26:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 206433 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1948677dyb; Mon, 26 Feb 2024 01:02:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXGRCG73VHbKnex7CzYOq1wnSaqOLem+FqdhpgqsWlIUHmayAwRKb2NXGt09/fbCRdpzPg8Hl5/kLItKj6h+PJDEFyX9A== X-Google-Smtp-Source: AGHT+IFfrfEEzjQnBCEAthopeaLS6LzcDByAMb6IZeFJKFM71dmf7XAKpH5rPNlzMA27sm0CqI/h X-Received: by 2002:a05:6a20:9598:b0:1a0:e234:bc79 with SMTP id iu24-20020a056a20959800b001a0e234bc79mr6092420pzb.0.1708938131788; Mon, 26 Feb 2024 01:02:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708938131; cv=pass; d=google.com; s=arc-20160816; b=TXeYBw+O6T/4mTKgv0HV7b16Czc1ZMtbP2vdcQjo9mQ5aF/HML6UTJ4glwRwDFP1wz tf1ULXiPptxuWW8F1fzN6cohJhheideGZ7tPITDIILXewyQYMr6spabRpmUgqfr5daTj NJhS+7bMg8SMHW1tzshaX/7/+4s4uiaWuLC1MvTi6XFgBjD18TJEMSLAcB9FQ5Rd1Be1 3ldif9Sa6oKUAnjrjfQ9ikhzUlz2fqSY28sdwgI+KiXFA2UreYvKoSV3AJrm3LWnUh9i a7qsrvMPpKEJpdN3sBxSKyqrNLy3Z9tzL3R+N3p+/2RPwWfwW7D41N0YKrI52nQPYAac +YdA== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80862-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u9-20020a634549000000b005d8bf0a91besi3376575pgk.276.2024.02.26.01.02.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:02:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80862-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80862-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9C810283FBA for ; Mon, 26 Feb 2024 09:02:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 63AE78529F; Mon, 26 Feb 2024 08:29:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791951510236751673 X-GMAIL-MSGID: 1791951510236751673 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) {