Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3430329rwb; Fri, 30 Sep 2022 03:34:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM44hSkqkoV748WYy6dUnwEgAElQAghtzXk338dSJv90vTSMZn2XXDA1sul0onO7pbcDd4Hu X-Received: by 2002:a17:907:6e17:b0:783:7839:ff3f with SMTP id sd23-20020a1709076e1700b007837839ff3fmr5953813ejc.300.1664534052619; Fri, 30 Sep 2022 03:34:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664534052; cv=none; d=google.com; s=arc-20160816; b=eZcQAreCT+f9XyDwPrWbdZYZzDW6vut5C6U7Os2QbgpGyRZ0nfzpmIFtTZzp0I/sMw 4lXVEf7apNSqi1rO5ZULKjsjghuSWwk7eOiOYY3YmECT0v92+hc6ZVME0ogdWfbT3+Wb vm2Ndae2Gb4N0sv9N9MTrZX0aw5m0jHpM4f98cLoFt2qdT+R+NWJ5Pw172FmKJmtGH+C 8TXmpSyJi49870NjqKa6/RjMCbrC9YPmjSjIcb4DVhtRk7qUXzrB6/lJ37wprGUhVMLd 0EcNxkPVsf2MGjXSCOZ0wCJgLap//fnMEA4H6B3u/MUHhxLkdDhxvpctt2q6wPhPtNdD mtLQ== 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=Lkje5Ac4a0e7s+3bkR1tjigtYRpAEu9chXSBxWs66WQ=; b=F14Hlh3ufw2dqn4rIvK/4UnxmHrk9RXtR2EC5bmiM5fh7KGXtN3YWgxLK5BmTKtF50 inzcJEK1Fs7WOaQkqZeKBNO1c2BkW6A8IEyobauzaXrRbbGD7WWqTagELFxQM8zh+/Z1 d6rk0hO0ebQx+roCa8I7eBr1eVpMOBs+uqpNLkT6Mm9WMYdiBAHrtypPiyU2WA1YcVr3 hBpj2wi78IaX8DTgEw8oQfBkobEoBAsJW3NhFtDiGBlQ2uUUBKtOMS0ln7Rvn/U5diHl iQ+RFzQlyEN8ZeFwRKX4XZddtq+t3D5Mx5IM3Hvx7xnPG60xw4OziRcriiLOH9dAmVVB K+8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HTgqNGZN; 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 h14-20020a17090619ce00b0072b40bc7412si1141161ejd.223.2022.09.30.03.33.42; Fri, 30 Sep 2022 03:34:12 -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=HTgqNGZN; 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 S232543AbiI3K1o (ORCPT + 99 others); Fri, 30 Sep 2022 06:27:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232302AbiI3KZE (ORCPT ); Fri, 30 Sep 2022 06:25:04 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAB3322B12; Fri, 30 Sep 2022 03:19:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664533198; x=1696069198; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pTAM5O5il6nt/65EYbq7evLkjZPVzO1QuMnGQ4g6lmg=; b=HTgqNGZNTvEXsgdbEQrOEcs4t+XHPjRYu24IgFjSHv7dKlOKqgL1VMvg GHJUNnTMFXmwhHLhD0TSvmHQqb44lRCEDvmiXgco/eF56vIJ+u/zxQ4Xs kNYR2y3rj4Uzazl2hDJlykwksNGpAlG8X+29/LJgHrvOUWtRqMHI2GTUm vd7y0zeVT17VswUvHyb4ZJO/uq/RgnuVr2la1jd+Tlveoci+4/h3A8WNd kOzAaV2nlshDVrim5Bi5ZYCIlrYGzANEahlPMK9U/4ASpmYvgn/8Xw6pB m9fB2UMDzT94TS8ioDnvPu44w32nUz5J3pTokEA3sHMif5YsbHwvHsEs1 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="328540177" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="328540177" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 03:19:08 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="726807822" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="726807822" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 03:19:07 -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 Subject: [PATCH v9 097/105] KVM: TDX: Handle TDX PV report fatal error hypercall Date: Fri, 30 Sep 2022 03:18:31 -0700 Message-Id: <58ea2a6ddcc53bfe1a5755c308e695c1343a8bd3.1664530908.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=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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 Wire up TDX PV report fatal error hypercall to KVM_SYSTEM_EVENT_CRASH KVM exit event. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/tdx.c | 20 ++++++++++++++++++++ include/uapi/linux/kvm.h | 1 + 2 files changed, 21 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 6cf18eca654a..a7cf08d60744 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1060,6 +1060,24 @@ static int tdx_emulate_wrmsr(struct kvm_vcpu *vcpu) return 1; } +static int tdx_report_fatal_error(struct kvm_vcpu *vcpu) +{ + /* + * Exit to userspace device model for teardown. + * Because guest TD is already panicing, returning an error to guerst TD + * doesn't make sense. No argument check is done. + */ + + vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT; + vcpu->run->system_event.type = KVM_SYSTEM_EVENT_TDX; + vcpu->run->system_event.ndata = 3; + vcpu->run->system_event.data[0] = TDG_VP_VMCALL_REPORT_FATAL_ERROR; + vcpu->run->system_event.data[1] = tdvmcall_a0_read(vcpu); + vcpu->run->system_event.data[2] = tdvmcall_a1_read(vcpu); + + return 0; +} + static int handle_tdvmcall(struct kvm_vcpu *vcpu) { if (tdvmcall_exit_type(vcpu)) @@ -1078,6 +1096,8 @@ static int handle_tdvmcall(struct kvm_vcpu *vcpu) return tdx_emulate_rdmsr(vcpu); case EXIT_REASON_MSR_WRITE: return tdx_emulate_wrmsr(vcpu); + case TDG_VP_VMCALL_REPORT_FATAL_ERROR: + return tdx_report_fatal_error(vcpu); default: break; } diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 47621588a792..498a2b92f2db 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -478,6 +478,7 @@ struct kvm_run { #define KVM_SYSTEM_EVENT_WAKEUP 4 #define KVM_SYSTEM_EVENT_SUSPEND 5 #define KVM_SYSTEM_EVENT_SEV_TERM 6 +#define KVM_SYSTEM_EVENT_TDX 7 __u32 type; __u32 ndata; union { -- 2.25.1