Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4766396iob; Mon, 9 May 2022 00:43:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzhyWcmP7/ZERlzaLT0ICt0QbegldRVEJZt7DRKQAZ0NF9J6/WMlS3TPihZjswcEERG+bZ X-Received: by 2002:a65:6d09:0:b0:3aa:1ecf:8848 with SMTP id bf9-20020a656d09000000b003aa1ecf8848mr12358109pgb.55.1652082201055; Mon, 09 May 2022 00:43:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652082201; cv=none; d=google.com; s=arc-20160816; b=azwglD5EcJecP5RVA2cHC83l2EzWVvWuOZA9jlu6/xOAkFZOGRZTWP+ngERDHlR3xC wj0ts4g9ez3M75wNNj7ZtNkatqjsWL/LzGWvqax4v3AJxfNI/URIq65Owzzb+0baHOnV l8rDdhLtFnHZwSeVozKHIcCQ5Jt52XT680IGtJR7ZacFw4sXJjZKmD3XHZUGrVTSN9d9 Vg6rVs1tpmBsCWlnZEmLB1/Fsyc1cjfkaF0BeHYT1M29yCgbWdKVmsO4q9O4hLfuMXKr 6FpD4CB3nS42AUCLzZkgTtCQKvfZSy5M6+lk/oarJImkBbKZ02uJn6b5ZItbrS/Okb/7 /cMQ== 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=xUeKmLG6mNet2ObXXVvXhkZmJp1rML82ojhcF+m/vNg=; b=lzKEykt0Tm4bqqaDIBHM6xPi+mTLw/awix/6hg7cueS+/j+RPVPA4M44d1z+jyKEvm 5zjbf8osHltwTEkqfnFUjtfVAEvyDZRpqnpPinO31nLraKaJCUztryUFGItDJTztk3o5 eI3B5993VBFj/Dpw9a9Es5QGqGJucycq30ZPfkJUpIOzIVXPbTKK3YamZQ6BkNoXw9E3 +e8OMVDBMMVjtDhEl4QO85RxTZ9k+W8iTEe3trH7WfmXNO81z82/ltAgXx25LdcIpERD bO1tJpUozoHAbGql4T3s69JNckSBwBq1iVg7htCItEhZGYTL4AbecomjFrlpyMS4r8Dn Gzhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Qe02oA3H; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id y22-20020a63fa16000000b003c511f50338si13366488pgh.848.2022.05.09.00.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 00:43:21 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Qe02oA3H; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 08ACD186292; Mon, 9 May 2022 00:37:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384744AbiEESYk (ORCPT + 99 others); Thu, 5 May 2022 14:24:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383273AbiEESTo (ORCPT ); Thu, 5 May 2022 14:19:44 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAC605DA6D; Thu, 5 May 2022 11:15:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651774558; x=1683310558; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5gKEBATWdi7brsOaUqd9Sxn2b02OlGwx2H6cEqgaWQU=; b=Qe02oA3Hxdk5tamuLi064gGfQzUVVXL4ZArhXrF1I2/jaJNYw9WKJ24w 266q5VAO5suDwwIZYP0rfHa0QyzKEm5ati93odo8WwAXgnBC2zT6rY8+T MHzuSakX0/wiCetypb+jQ7ruQY8ptR9b9KIRlSbYdg5u1t088uqrYbmS6 yAMrbdABgE/mEwBnn4nTyZ0kCBk7n77VyAjb8CDdS6rsTlNRqdOWkRY7k RMIoTWXUkmQz6TTR3cb19RSYtCndnZEWZrwRgcl7h26E9W654dQe9J9Uu kNs0RmhoCjydCc4P7igEp3+SBWvIVw+eujJpHXDGsjOdGnstrqikqlpDy g==; X-IronPort-AV: E=McAfee;i="6400,9594,10338"; a="268097119" X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="268097119" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 11:15:55 -0700 X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="665083491" 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; 05 May 2022 11:15:55 -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: [RFC PATCH v6 096/104] KVM: TDX: Handle TDX PV report fatal error hypercall Date: Thu, 5 May 2022 11:15:30 -0700 Message-Id: <6bb829189d8d94c64fb42db2d84f7519b7d29359.1651774251.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=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 | 21 +++++++++++++++++++++ include/uapi/linux/kvm.h | 1 + 2 files changed, 22 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 1518a8c310d6..ee83539d5228 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1202,6 +1202,25 @@ 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 | KVM_SYSTEM_EVENT_NDATA_VALID; + 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)) @@ -1220,6 +1239,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 9a3fd7b41fc5..df1b89ffdac6 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -445,6 +445,7 @@ struct kvm_run { #define KVM_SYSTEM_EVENT_RESET 2 #define KVM_SYSTEM_EVENT_CRASH 3 #define KVM_SYSTEM_EVENT_SEV_TERM 4 +#define KVM_SYSTEM_EVENT_TDX 5 #define KVM_SYSTEM_EVENT_NDATA_VALID (1u << 31) __u32 type; __u32 ndata; -- 2.25.1