Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2661400rwd; Sun, 28 May 2023 21:36:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4SNSaZCUaaHbyXGgUcKxmkDIZN3AI9dZsf7cd+S7ZP3j5xIkR2x2/QZMEhOLzs4J1HwhTi X-Received: by 2002:a05:6a20:d48d:b0:105:6d0e:c046 with SMTP id im13-20020a056a20d48d00b001056d0ec046mr7313819pzb.26.1685335004992; Sun, 28 May 2023 21:36:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685335004; cv=none; d=google.com; s=arc-20160816; b=N0ZVJgY1A6yYZAlDULLK6Ce2w/4AfPrF1eN2gjLSz7CdSvmft4FRH/JNOQuQow4+wF eDxaHnz0n61qKnIYBDpCiSLG4s3z3mq+Ih7t6VVJgvMDG6w6Nl51jdbhOoPB5UgnSaA5 Cfja0FoFIzDdZxJhTByFB8R9ad9xlTshcu30Q25D6FMKX1xZgn+RLTGXKelbdF107wFI KnRQgTiLuUTfm28lzy5YbWUTcIQjLvijiL15dEgPO0dy+4d3zrJT1miK2Yc6Eiy/Z6h2 wX23K5hco6TLz+yqdRmpxqQL1RQzI1H+EfV7+W37vUuLk58HfWhNDAC8IeQKgMARoMQ6 IyWg== 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=LdBzhgmeur/lTQLbDdjavNk5pTRdIa/w1pAmTut0fok=; b=lSkOuGB5ejWABEhoQfK+QUdcvtfymKSzwz6AsQn/Nc0omox9cIeMyw4VJqgKWMpmgS RDzsHIn5IJQwUA6H+EntLOkP10rv1FPOaQqbLojBoK4qoewk4NL3fXYHnHI9SeGAvMbU NXAIAH/SZOVjZ/ypB4xfc9D6j/yIVTea0byWxFZ3Ep1yLJscpH+CLgMTN6hftdYnSFic TIcXu7ePwus3Yoc7EDGlmOnpFrdYUOZI1/1G0ch7iDxZXHOEnowdjK1wzapFrCLDkaqS N7HRILfmtB13bGhPokebbiY0U5Q3zOAwgXeFJrVAbGfcMA1cO5r+R5KaMNhGHS6hKn0U OPBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="P2KWk/yz"; 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 bk13-20020a056a02028d00b0053f2601e5aasi825390pgb.195.2023.05.28.21.36.30; Sun, 28 May 2023 21:36:44 -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="P2KWk/yz"; 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 S232300AbjE2EeN (ORCPT + 99 others); Mon, 29 May 2023 00:34:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232372AbjE2E3z (ORCPT ); Mon, 29 May 2023 00:29:55 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2317C126; Sun, 28 May 2023 21:26:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685334360; x=1716870360; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ub9vW1oqyvQQF8PM2p5iFINwVub4GVdRoGSzWRAdwCw=; b=P2KWk/yz9A9sqJkS/eG1gMcU7v0VOowszhMeff6vKSh59LaXO7OkXxHi YL4lEV0dG2K8R0jlYLzfgOs+XOHieltJvrGSJMl+iMjKkW5+jJYM0oRTe BIfjZRWsxs5bnYX2y0i1jSHeslwVSXG2++H48L08gh26hVnn1veQx2oDI CfhKafkQJKBGU4Dc5nPmjcIfK31nd8yIsYA60TR7KXHY2QS+DAfwBRS8i nz9uUe5FWeMnpoXAkr6k1ArJCJvXCW7bjtTey4F0adnnT/SgPCILBXkVr HFlkkQeDqRpFOyzziWM4yc52OyWo5OOO7jKYCUnDWJOpMT3E9DJfxvdoX Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="334966277" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="334966277" 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:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="775784531" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="775784531" 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:37 -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 Subject: [PATCH v14 087/113] KVM: TDX: handle EXCEPTION_NMI and EXTERNAL_INTERRUPT Date: Sun, 28 May 2023 21:20:09 -0700 Message-Id: <7d7744c17b49657e5ad82f5c09c7186848ff128a.1685333728.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.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: Isaku Yamahata Because guest TD state is protected, exceptions in guest TDs can't be intercepted. TDX VMM doesn't need to handle exceptions. tdx_handle_exit_irqoff() handles NMI and machine check. Ignore NMI and machine check and continue guest TD execution. For external interrupt, increment stats same to the VMX case. Signed-off-by: Isaku Yamahata Reviewed-by: Paolo Bonzini --- arch/x86/kvm/vmx/tdx.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index f8adea0394d6..605165f8f31d 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -801,6 +801,25 @@ void tdx_handle_exit_irqoff(struct kvm_vcpu *vcpu) vmx_handle_exception_irqoff(vcpu, tdexit_intr_info(vcpu)); } +static int tdx_handle_exception(struct kvm_vcpu *vcpu) +{ + u32 intr_info = tdexit_intr_info(vcpu); + + if (is_nmi(intr_info) || is_machine_check(intr_info)) + return 1; + + kvm_pr_unimpl("unexpected exception 0x%x(exit_reason 0x%llx qual 0x%lx)\n", + intr_info, + to_tdx(vcpu)->exit_reason.full, tdexit_exit_qual(vcpu)); + return -EFAULT; +} + +static int tdx_handle_external_interrupt(struct kvm_vcpu *vcpu) +{ + ++vcpu->stat.irq_exits; + return 1; +} + static int tdx_handle_triple_fault(struct kvm_vcpu *vcpu) { vcpu->run->exit_reason = KVM_EXIT_SHUTDOWN; @@ -1236,6 +1255,10 @@ int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t fastpath) WARN_ON_ONCE(fastpath != EXIT_FASTPATH_NONE); switch (exit_reason.basic) { + case EXIT_REASON_EXCEPTION_NMI: + return tdx_handle_exception(vcpu); + case EXIT_REASON_EXTERNAL_INTERRUPT: + return tdx_handle_external_interrupt(vcpu); case EXIT_REASON_EPT_VIOLATION: return tdx_handle_ept_violation(vcpu); case EXIT_REASON_EPT_MISCONFIG: -- 2.25.1