From patchwork Thu Jan 12 10:14:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 42350 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3801665wrt; Thu, 12 Jan 2023 02:16:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXtW+81daO4x+yvJLbVJX68DCk97o31Xn0w250syIme7h1q4UeoVgWPeqT7HX8LCIgC0cKCN X-Received: by 2002:a17:906:48d5:b0:84d:489b:ed8e with SMTP id d21-20020a17090648d500b0084d489bed8emr11452418ejt.5.1673518611478; Thu, 12 Jan 2023 02:16:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673518611; cv=none; d=google.com; s=arc-20160816; b=Ixultz7Gs6634laTV9eGmHiVb3VgE0FozIUl2pR+ciAH/5NXePB2bUR6z3/a+LRaMT vAtVnLuVczMfZejv971thaosbcv0KgOeAqHMM7s31xj8Z7D6GfWewo74DPLTE26nAM1f gPIBofGj2GO88vIg6ptdVv8tP1l2Px2Yt8hbltllIx6FoQvU0Evu3PKGhdsYmEyOsOF/ Qn39zukj3V9mg5ep0Cr+/kjvoh+nEWBW5hoGOr63uw7O8BV0PJ/ArAsVNJn6jZwH25WD /HTCc7fn8fCqtiW1SQseH3N7H+MfvQWRioTMjscsoJ9Azg8ClJv37N8whNEzeCbXeV8g kPwg== 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=IHxNNdb3DA1SGvH8jBEKX/e1Qr3pQHvGrYRnJwJPIJY=; b=hti04D1/+fZaozKrYBNX/2rWCgWz/h6E8uPok+sg0M1gKK18HizkUindj5cTksMMBz FrD9djD9hfBJ9Uzw7c1OKUNQbl9764hcoxOkPbux0+vYJfz17mfWnlXtLDnbdvuwgs8Y Uqf3tDjw6vY5Fw4hBurtplQCTj4GS4amoB9VqYZaK/f5vhG8gebIW8/mktEvwB+Udjh9 s3V5YnYBuYlaDdwmUnhJHzNGLTFeDcVH3UtSm5DD+q8TPaIk22jYmdtWyZ+tFCH/nzQE d9f+FOShJ7wTzgSqa55HKZmGs5XeYJee7mvuRJCR2BXuR11r1tMJKEmkOeIfckpy9N40 X3oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AdultxN9; 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 gs6-20020a1709072d0600b007c170f6b32bsi18394780ejc.266.2023.01.12.02.16.26; Thu, 12 Jan 2023 02:16:51 -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=AdultxN9; 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 S239981AbjALKQD (ORCPT + 99 others); Thu, 12 Jan 2023 05:16:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239871AbjALKPB (ORCPT ); Thu, 12 Jan 2023 05:15:01 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7E0362EC for ; Thu, 12 Jan 2023 02:14:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673518465; x=1705054465; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7okiIaj1mXjjqjJ5IKQzDQSQ9jvp5ruk3bnJVX6pMgw=; b=AdultxN9Xm61l6JCLZ94HprPLAjpGPsuG3cbxLcv1iKqS9+WILhp1/jN G1Pf5v7f+ACDaBknHCTplWRzE1LWMMNk9Gy2fgVV3hcjOUcL7qQKpUnD7 KMDemoVK01LNSX7LjzeOM0wTlZnvV5beeACdTuIFOV96LEUP2YnyiQRom XjSIbtJOBJQLdT0yFYoZ8CkkfGm6YyLa4ar7NN4l7iSPE8yvzogf5hV6W 64jMPJaIoJp5vnZf3tBNm04uIxjgZlBS+gbRwP4+CBkG9XX1y2UzcxYfo 3EnFxIhYEeAWKnuC8Bg0kR0EWjqFg8IISYc5yqOiEX1Bz+m8I5NJZJm0Y Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="324899419" X-IronPort-AV: E=Sophos;i="5.96,319,1665471600"; d="scan'208";a="324899419" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 02:14:24 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="903128291" X-IronPort-AV: E=Sophos;i="5.96,319,1665471600"; d="scan'208";a="903128291" Received: from glieseu-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.52.1]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 02:14:21 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id A551D109AF5; Thu, 12 Jan 2023 13:14:13 +0300 (+03) From: "Kirill A. Shutemov" To: Dave Hansen , Borislav Petkov , Andy Lutomirski Cc: Kuppuswamy Sathyanarayanan , Thomas Gleixner , Elena Reshetova , x86@kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv2 5/7] x86/tdx: Use ReportFatalError to report missing SEPT_VE_DISABLE Date: Thu, 12 Jan 2023 13:14:05 +0300 Message-Id: <20230112101407.24327-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.38.2 In-Reply-To: <20230112101407.24327-1-kirill.shutemov@linux.intel.com> References: <20230112101407.24327-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754811451982767964?= X-GMAIL-MSGID: =?utf-8?q?1754811451982767964?= Linux TDX guests require that the SEPT_VE_DISABLE "attribute" be set. If it is not set, the kernel is theoretically required to handle exceptions anywhere that kernel memory is accessed, including places like NMI handlers and in the syscall entry gap. Rather than even try to handle these exceptions, the kernel refuses to run if SEPT_VE_DISABLE is unset. However, the SEPT_VE_DISABLE detection and refusal code happens very early in boot, even before earlyprintk runs. Calling panic() will effectively just hang the system. Instead, call a TDX-specific panic() function. This makes a very simple TDVMCALL which gets a short error string out to the hypervisor without any console infrastructure. Use TDG.VP.VMCALL to report the error. The hypercall can encode message up to 64 bytes in eight registers. Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 669d9e4f2901..56accf653709 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -22,6 +22,7 @@ /* TDX hypercall Leaf IDs */ #define TDVMCALL_MAP_GPA 0x10001 +#define TDVMCALL_REPORT_FATAL_ERROR 0x10003 /* MMIO direction */ #define EPT_READ 0 @@ -140,6 +141,41 @@ int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport) } EXPORT_SYMBOL_GPL(tdx_mcall_get_report0); +static void __noreturn tdx_panic(const char *msg) +{ + struct tdx_hypercall_args args = { + .r10 = TDX_HYPERCALL_STANDARD, + .r11 = TDVMCALL_REPORT_FATAL_ERROR, + .r12 = 0, /* Error code: 0 is Panic */ + }; + union { + /* Define register order according to the GHCI */ + struct { u64 r14, r15, rbx, rdi, rsi, r8, r9, rdx; }; + + char str[64]; + } message; + + /* VMM assumes '\0' in byte 65, if the message took all 64 bytes */ + strncpy(message.str, msg, 64); + + args.r8 = message.r8; + args.r9 = message.r9; + args.r14 = message.r14; + args.r15 = message.r15; + args.rdi = message.rdi; + args.rsi = message.rsi; + args.rbx = message.rbx; + args.rdx = message.rdx; + + /* + * Keep calling the hypercall in case VMM did not terminated + * the TD as it must. + */ + while (1) { + __tdx_hypercall(&args, 0); + } +} + static void tdx_parse_tdinfo(u64 *cc_mask) { struct tdx_module_output out; @@ -172,7 +208,7 @@ static void tdx_parse_tdinfo(u64 *cc_mask) */ td_attr = out.rdx; if (!(td_attr & ATTR_SEPT_VE_DISABLE)) - panic("TD misconfiguration: SEPT_VE_DISABLE attibute must be set.\n"); + tdx_panic("TD misconfiguration: SEPT_VE_DISABLE attribute must be set."); } /*