Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp287330rwb; Tue, 25 Jul 2023 16:07:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlFt4cgq14yWDWP/EuCWesmZvSFe/4lxDFWH1tlZfp42lard1iVhshAhI2hamrBH3aBKmciu X-Received: by 2002:a17:906:221c:b0:997:ea90:96b4 with SMTP id s28-20020a170906221c00b00997ea9096b4mr203364ejs.61.1690326436922; Tue, 25 Jul 2023 16:07:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690326436; cv=none; d=google.com; s=arc-20160816; b=kY5cYyY7i87d5wihBxu6n4KBdPYaFvCg0Th4ANkCZ2pn+ehmyr8m2FneNFC760Oksr e0ZKmePgY/0WbrcxGeX0ZacBsbb2+VWnxUkNbtzn6krjEjYMZT5V21gEhpsWv/wP2DHD qD9TrFBgsfccU2seH/UXn2yUsPvQUPkAQUQyHrjcIjHejjmd6Qke3hzkpASRBtPBbKMu XgyJhuON9U1h17k5y8imV5VXUkhUo82E3SEWnNWP4lgwBR7w93TasQuoT21UtqNLB2RI 3s3D2x4b0Rx2Wyers+NMLaRz3aV9FGy1ppUrW8ixtfHW6nlR9ijIV+6U2k0L3e4+y4y0 lf/A== 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=vUeEO8ErVfT3Zi2LVhOH/q2WpnYjG265jOnNgcPd5MY=; fh=juxwNcA6iKwLISFgUCNwdoIYC0NKLUseq3xZdq25RR4=; b=1D1j3uLzRPtyQe3jWYFq4+efe76jlUnvfVxOQff9R4BShBPHKvIsPuJZbkV7q2TAvz 98opiq0V8JWJ9jY1EQdGxyjz8ebimvH/7oPudS6rBvSihKdNRCuiy4LwvRAYmLhdprVs 9AlKMocRhnD3Dn5T6e5O4Act/V6cJGYDqly/jV04ZdbJDPTL6sGdycLIiYMYBWmtnxXm S6NktEeEld6b8kGe5kNEWEbWktTz4wU21SKxCOwUtKcaaI2fzJP4T8/hk89I6NH+Vb/m BA1XBRnwaJhoeK9TrI8Wl+QDCbSor273zgGJIO3YXwGKgwHwND/MTrAOzMqmKGq/wfjG Wo8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TcR8N+XF; 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 n23-20020a170906379700b00988be9d8c53si8564994ejc.946.2023.07.25.16.06.52; Tue, 25 Jul 2023 16:07:16 -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=TcR8N+XF; 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 S232881AbjGYWYo (ORCPT + 99 others); Tue, 25 Jul 2023 18:24:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232741AbjGYWWf (ORCPT ); Tue, 25 Jul 2023 18:22:35 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 949D14ED8; Tue, 25 Jul 2023 15:17:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690323475; x=1721859475; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TyobtdtuH/YAqwgdKL24pQLPaZbJ8c3URiYLS/2JpXE=; b=TcR8N+XFJNBs/EU6I2QyvKNg3FyLVVSlwdzHYxkevqeeUXPDoCYoCDtK jAoUZfBw/H4pBH/uOMZ3Ucl7H5t8nA2GcxZpcjhDEF90tjqtXoobLJOpQ 5X1RZV2K+qUXFWbOdunxH2DXmiWZA+Teh4Fm4jNBFZisqT4v58S3jWpBd ztWJbtAD8qNRnX3hyO8mNL0svRu7g7QxMOp/LxAU/WQsUC6Kn0RCPGbXq QwhSX7bX2i91idmkLgQgbcS9qQyS9gLYKNrp2XzuKao+WQlBG5gBTxb6Q boTM2ivlP6aJ1olHlaUwHrQrPga1qFhKBeAg2U33DzlbhqdoNwGGWzWJD Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="367882675" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="367882675" 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:16:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="840001879" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="840001879" 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:16:00 -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 Subject: [PATCH v15 087/115] KVM: TDX: handle EXCEPTION_NMI and EXTERNAL_INTERRUPT Date: Tue, 25 Jul 2023 15:14:38 -0700 Message-Id: <65e113025130e082a409d12b58f4282c2801d46b.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: 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 1a41e12f0942..45b521e05ceb 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -798,6 +798,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; @@ -1238,6 +1257,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