From patchwork Sun Oct 30 06:23:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 12881 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1666337wru; Sat, 29 Oct 2022 23:29:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM74SCtK1MbLqQa0zuzmknsZz/8GXSSEu1nu+46/72yLQjJPh8EklxaeOiz/xD5jXP1ZeIoI X-Received: by 2002:a17:90a:ec04:b0:213:60bf:e6f7 with SMTP id l4-20020a17090aec0400b0021360bfe6f7mr22818682pjy.211.1667111390906; Sat, 29 Oct 2022 23:29:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667111390; cv=none; d=google.com; s=arc-20160816; b=qUoC7RUEXDSMF6e03XN0uLov+w3TEENBYrOEJ+6l/afoZ+XYhuqu54+9ha+wJJUl5j A0mRRnZKzvci4OKgHJ3/oTPEKWTYwcKlR91xNY7eXyjPEd5ZduPoaPiJ7rXSKGhvGBNr M6Mcc+8So55TSMDQTR48w3q8CZgo9+hN5uCz5WIpXq40AKssIrBIDjb6oqcGoH7bsyTo LUnmGSSeGQesuauoj5Van0XiDqTTUJiVx0xfbHQKpNIqz8Tu9Zl/O7cX5ARvakQ8bZeh RvHHUhw99FaBf4JyzQzeaMRMkgv9GH8E/EASePsqPnZDITmC4p1QZMaS35bYQH1J/nMm b2sg== 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=2a2e7nI4DndrU64CojP8GWx/BpwQ2l2ruGd0xC2PBac=; b=HmpAShT0nAfh11N7St7UE/zFJB0QiTXK50EDv85kq+CiY7o4iHORsmAntE7N8sf+jT jxrQi7KDuu+VakH/J5NkSFXptHf+2XUycQip1ktdaK/RoVvbuHLd4v1eCaRgyiMknwAx 3DPhjv7W5TORnh9wZ+TQ4rYGrcP8IfZTlo3/vsot2ofbYFbvYh+kMaxTFvKlPHMFenXX 68K/I5ozX0pJ/T+bh3Gk2ed4G3I8lo03eu1cffmhzKkG7qE8SObk5hlkuiuSVUFtbSKn oLe5vajYdx67LJytqYxrixmRgtly7tbdjTkeLYDIhBG0FB1dRnN72Jn7dBK/RzvCIItZ pjjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mx9Rtyaa; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b6-20020a170903228600b0016f5e7d0febsi5173471plh.244.2022.10.29.23.29.39; Sat, 29 Oct 2022 23:29:50 -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=mx9Rtyaa; 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 S231139AbiJ3G2t (ORCPT + 99 others); Sun, 30 Oct 2022 02:28:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230128AbiJ3GZP (ORCPT ); Sun, 30 Oct 2022 02:25:15 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D72A0209; Sat, 29 Oct 2022 23:24:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667111054; x=1698647054; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MDrBeEVg3cc7h0tcvmuzjVL0AqXKibnPzzkP01NyP5o=; b=mx9Rtyaa2pH6qBlmHvJJKuuera43ZdJ4MQ+h3nQnjfzc9kp9NsFgv1sF 4H+9vzlXHblYbzNIyARXNkHfR2xXIJFnHnH0B0axrrHWsvKNqOlDdlErV 541ZcDQTmUCInM95Fkzm3JTkVftCkOueSLT7Wb1hd254y9GGj42m5Qqg8 lgUNyJjL3Vnb740kCZfI67IviOxxThUBaeCAvqzxwzNK0Kv0DU6By6E/O W0HTMrZJ4iiPrpCZB9tL/ePgJKSmd0m9+v/2ElifjP5Cf0mWG1BNYtNn5 WbiU6Msya+9hGvlD4Xfn7taOPlSZ1nzL3alcrk4ZlXKP5aLAp3rK+2GX0 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10515"; a="288435993" X-IronPort-AV: E=Sophos;i="5.95,225,1661842800"; d="scan'208";a="288435993" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2022 23:24:14 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10515"; a="878393162" X-IronPort-AV: E=Sophos;i="5.95,225,1661842800"; d="scan'208";a="878393162" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2022 23:24:14 -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 Subject: [PATCH v10 100/108] KVM: TDX: Handle TDX PV report fatal error hypercall Date: Sat, 29 Oct 2022 23:23:41 -0700 Message-Id: <82671e3e811ab5ad423e125186c050f46621dd86.1667110240.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-4.9 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_PASS,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748092994080509013?= X-GMAIL-MSGID: =?utf-8?q?1748092994080509013?= 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, 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)) @@ -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 {