Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4118054rwb; Sun, 7 Aug 2022 15:33:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR5edzUfo6qjpUmOVVhIHJxtUraiGIFwqXUJLpbJRF5vYj60PLN+XMPj5PwI9pABxmCJ7dfm X-Received: by 2002:a17:90a:e295:b0:1f3:2ddb:9c53 with SMTP id d21-20020a17090ae29500b001f32ddb9c53mr26101968pjz.129.1659911636838; Sun, 07 Aug 2022 15:33:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659911636; cv=none; d=google.com; s=arc-20160816; b=Mrwv2k8+FImIJUu7WJN5aRwJKymsadZmdDyM9xbCiFNG5Na70xez8+60wmWqtBqyhl Eq5RrvR4YWZdQgwqSPj55gBprGS3tFe0GjJjgXefEh/iZtkHjRsniVn9jUX7hFE7XStm +JVJ5dxFYi7vRdGcZ+hj8kRTlglpiIIFoQoci9s8R74kEoOdqqut94e2PQPjw2v4ObPK 22sLEHAYM19V5P2tHaSYhuFl7l6jMeluNflJO7C4aYef6ih9IJlaDiBtyqiDWREQBM2e 3WI2P5+ZbnGA/VAd5QlVdA4rAY5QQnVtP2eGx5KAdrhewFO4c64uDcfM+Mn5si3Z6ire lb0Q== 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=KjfbMAWgtuF56wfzIvT2zO54YIP32qTVEnX3QH0EzSI=; b=Y2qX4tdfnmQtMOeT1Kie+0XIH0KqrfpshOjEszMB/vDcicb/ucRGjz8sp8bHa+5ak5 gN7rodw0HkuI2DB6TvtFUkmNLhf1Vo95xziNdUFOMAfUeIB9rBP+LJCdi3gx7KsPsZU9 toXEh6ltnYM3sCTl75fYmlH3yMZpUBE2ZUDI1CUDHDC7KxpEJTISFZqfhvcCpKke79ci GphNfh2/24cdmZJUxn3vcU3sjTHKY3mg7xD4k1dl/bk3bUfzoNwenFJsQacTDm7T0ANz poxDmolvULE0OYfFuYbgJCWO7MztngX7p5G9MYcuGOD6JsVbNhf9gMM6yC7FM7LQ6Am4 6MkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iHmV9F3N; 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 ls12-20020a17090b350c00b001f4ebb0992esi13032784pjb.77.2022.08.07.15.33.42; Sun, 07 Aug 2022 15:33:56 -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=iHmV9F3N; 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 S242766AbiHGWMG (ORCPT + 99 others); Sun, 7 Aug 2022 18:12:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241831AbiHGWIg (ORCPT ); Sun, 7 Aug 2022 18:08:36 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F63CBE09; Sun, 7 Aug 2022 15:03:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659909807; x=1691445807; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MGgM0RBlGR2hvJdAn8x8PwFYCCMcHY0Fqh+KEXssNLk=; b=iHmV9F3NUWgb40lvMmBv1QZ5QaNdKePvVeElNYm1xFAV6e+aAqhTpkUG fxW4Ma1Xz/ee1SHVcGeBMEMMkX+fKuYseQ4RwClTkh1rv63EXSB+IPYFa hBehUwdGM8/uw3rD/PRGOtuhtLoWor6If+tB1tRRZirfJ/5YMiLZExXiw zLH8V7r/04DjzZT1cvTlkfOjvNulMCPmu4lvlRVBucu3b3nIrkV9ulNEO yZy7oM3/rdW/4Vv2uZ/kvz48vaz1k+jVjfTcV1ekw9h0ow2ZicGv9h9uw 2n+AQmJbjdEw0dYxDShOqZfEkTgMNtpeCqhVk0pn3sJcrb0RD7o1ObVHi Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10432"; a="270240414" X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="270240414" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2022 15:02:44 -0700 X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="663682761" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2022 15:02:44 -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 v8 096/103] KVM: TDX: Handle TDX PV report fatal error hypercall Date: Sun, 7 Aug 2022 15:02:21 -0700 Message-Id: <87febc543d133186c0e650732471a1be50e996f6.1659854791.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=-5.0 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,T_SCC_BODY_TEXT_LINE 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 fdd0609bd01b..6131be42c721 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1192,6 +1192,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)) @@ -1210,6 +1228,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 13ebb26b3be2..4ee7052542ee 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -448,6 +448,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