Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7474371rwb; Wed, 23 Nov 2022 07:02:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf70tOaU+qKRqUF01Yrq0fFHJfKC7ND8bQ7kxb0bwW4eJRgyAtP3KokzL9IB4gh4tg2AuyZ+ X-Received: by 2002:a65:5b47:0:b0:477:4eb4:4b6a with SMTP id y7-20020a655b47000000b004774eb44b6amr7878597pgr.531.1669215749178; Wed, 23 Nov 2022 07:02:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669215749; cv=none; d=google.com; s=arc-20160816; b=fodftGNY72qZqbIzStiqcLFVnhaCfT/u3Iasr5VC1JIWRDu3oZo7YIZHWm5zSEXApV wo+Z0JOKUJ6Jxca3ZIOxpBYv+d3AJV64Bm5ff5WOtgZwlfsy8xqRLMoBr+jkyCx5tBbj Ti897d8jDm0ugrX3pLfS6BQkRvowh/rGBb5sXaef0MsOZy8pvwGdG1+lj7IMQvDpg3ZT cvCyBlDf5tDZJhUt0jJAr2TXbr88UlosEZ+ESJcqdpD1SVvtWpFYw6h08X2H92Jzxdgs TASF4yf4JGXZCBHUBB7uTwhHuRB0QkFOWbTzLHb5d8GNYeWdZOAGlAvKqKdxz/MeZgAM D6LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=13RtgOf1u3tJP+UQUphATG/1RDRvnwfBaQ1ZsG/Sf04=; b=mfkFsy9kr9uxUCtk83rh1Wbr/OEB9HI9PayvmuTwwh7cHjdy+BWzP855SvNHxzTMyN PASE+tjrTG604tnV3ab4RcRkkHhqDDEw/KGkUw32XIbpYuQ7m0eGNGVDFxEQjtq/umEP e6Gt5lBcFc0gvDpyMjPlE3wuKPViNvt1faPC58hq4EecOtuyD6VjUuiHoehBBMimY35b ih3IGqHlx0ZRfHcDxZoq3LG+T9/7mQw9cUQYMrQ6ATx/xOfEemeD7DeoJPkXfw8xlxdB Yw0BQoPKeI3dU9F2HrvxpeNE+0bQf+pLN6pJ7elPsjYTydXv+g3v9iG3lHz/W3Fd2D4P UBEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XuzY5LWo; 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 i18-20020a170902c95200b00174eef66680si18814096pla.120.2022.11.23.07.02.14; Wed, 23 Nov 2022 07:02:29 -0800 (PST) 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=XuzY5LWo; 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 S236308AbiKWOsG (ORCPT + 89 others); Wed, 23 Nov 2022 09:48:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237215AbiKWOr7 (ORCPT ); Wed, 23 Nov 2022 09:47:59 -0500 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8BFB64563; Wed, 23 Nov 2022 06:47:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669214878; x=1700750878; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=a+8IwRRWnlMenj05niCZLxI+GsQk8uB7E1I3p8nlM2A=; b=XuzY5LWo8gvjvvN8sC0BcdXyj+7hCB+OcMPmIPYxCs6aixedUyI6t5wy JAbe+hscn4M8T3nqx99WuM+rfaTdVzXpgaI2jPnPHtUjeUgw0Rx0xSZqU hMFt7Fvj1qpNTkGqi0pWbumS28ZnvPnGiQ3ktXJ0tcP6XtcLFx14afMo7 1ekLNb817ksOzEzqb55F8yEksKpdr3Q8es/YFsSflOvYbEGyWWYP0aAVl wpgF24cPpt2o0noTHjuqg1BDVHuFbIS284GKj1v13cQU+Dw3+oxFjofkk XvxOYlodTivbnolU4augWefPW3fuVe5EZKUpr0isF8MbCf3LuzXqccVAR w==; X-IronPort-AV: E=McAfee;i="6500,9779,10540"; a="340959168" X-IronPort-AV: E=Sophos;i="5.96,187,1665471600"; d="scan'208";a="340959168" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2022 06:47:58 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10540"; a="730803960" X-IronPort-AV: E=Sophos;i="5.96,187,1665471600"; d="scan'208";a="730803960" Received: from binbinwu-mobl.ccr.corp.intel.com (HELO [10.249.168.208]) ([10.249.168.208]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2022 06:47:56 -0800 Message-ID: <731bcbc7-67dd-44d1-4e19-2ae165f16beb@linux.intel.com> Date: Wed, 23 Nov 2022 22:47:54 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH v10 100/108] KVM: TDX: Handle TDX PV report fatal error hypercall To: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack References: <82671e3e811ab5ad423e125186c050f46621dd86.1667110240.git.isaku.yamahata@intel.com> From: Binbin Wu In-Reply-To: <82671e3e811ab5ad423e125186c050f46621dd86.1667110240.git.isaku.yamahata@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,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 On 10/30/2022 2:23 PM, isaku.yamahata@intel.com wrote: > 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 e3062c245e70..16f168f4f21a 100644 > --- a/arch/x86/kvm/vmx/tdx.c > +++ b/arch/x86/kvm/vmx/tdx.c > @@ -1068,6 +1068,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 panicking > , returning an error to guerst typo, guest > 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)) > @@ -1086,6 +1104,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 49386e4de8b8..504a8f73284b 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 {